yijia-webman/app/model/SaleLog.php

53 lines
1.4 KiB
PHP

<?php
namespace app\model;
class SaleLog extends Base
{
protected $createTime = false;
protected $updateTime = false;
public static function getPageList($size = 20)
{
return self::alias('sl')
->join('goods g', 'g.id = sl.goods_id')
->order('sl.id desc')
->field('sl.*, g.name as goods_name')
->paginate([
'list_rows'=> $size,
'var_page' => 'page',
]);
}
//获取销售金额统计
public static function getSales($start, $end)
{
if(empty($start) || empty($end)){
return [];
}
return self::alias('sl')
->join('goods g', 'g.id = sl.goods_id')
->where('sl.sold_at', '>=', $start)
->where('sl.sold_at', '<=', $end)
->field('sl.sold_at, sum(sl.total_price) as total_sales')
->group('sl.sold_at')
->select();
}
public static function getSalesGoods($start, $end, $order = 'total_sales')
{
if(empty($start) || empty($end)){
return [];
}
return self::alias('sl')
->join('goods g', 'g.id = sl.goods_id')
->where('sl.sold_at', '>=', $start)
->where('sl.sold_at', '<=', $end)
->field('g.name as goods_name, sum(sl.total_price) as total_sales, sum(sl.num) as total_num, sum(sl.num_small) as total_num_small')
->order("{$order} asc")
->group('sl.goods_id')
->select();
}
}