This commit is contained in:
mkm 2024-06-21 16:57:04 +08:00
commit 20e3347b56
2 changed files with 43 additions and 17 deletions

View File

@ -151,22 +151,8 @@ class WorkbenchController extends BaseAdminController
// ] // ]
public function get_product_ranking() public function get_product_ranking()
{ {
// $params = $this->request->get();
$dateRange = $this->request->get('date'); $dateRange = $this->request->get('date');
// 拆分日期范围 $workbench = WorkbenchLogic::get_product_ranking(['create_time'=>$dateRange],$this->request->adminInfo['store_id']);
list($startDate, $endDate) = explode('-', $dateRange);
$startTime = str_replace('/', '-', $startDate);
$endTime = str_replace('/', '-', $endDate);
if (empty($startTime)) {
$startTime = strtotime(date('Y-m-d'));
$endTime = $startTime + 86400;
}
$where = [
['create_time', 'between', [$startTime, $endTime]],
['store_id','=',$this->request->adminInfo['store_id']]
];
$workbench = WorkbenchLogic::get_product_ranking($where);
return $this->data($workbench); return $this->data($workbench);
} }

View File

@ -28,6 +28,8 @@ use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_log\StoreProductLog;
use app\common\model\store_visit\StoreVisit; use app\common\model\store_visit\StoreVisit;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\model\user_recharge\UserRecharge; use app\common\model\user_recharge\UserRecharge;
@ -834,9 +836,47 @@ class WorkbenchLogic extends BaseLogic
/** /**
* 获取商品排名数据 * 获取商品排名数据
*/ */
public static function get_product_ranking($where) public static function get_product_ranking($where,$store_id)
{ {
return (new ProductStatisticLogic())->get_product_ranking($where); return self::product_ranking($where,$store_id);
}
public static function product_ranking($where,$store_id)
{
$time = explode('-', $where['create_time']);
$time = [strtotime($time[0]), strtotime($time[1])];
$list = StoreProductLog::whereBetweenTime('create_time',$time[0],$time[1])
->where('store_id',$store_id)
->field([
'store_id',
'product_id',
'SUM(visit_num) as visit',
'COUNT(distinct(uid)) as user',
'SUM(cart_num) as cart',
'SUM(order_num) as orders',
'SUM(pay_num) as pay',
'SUM(pay_price * pay_num) as price',
'SUM(cost_price) as cost',
'ROUND((SUM(pay_price)-SUM(cost_price))/SUM(pay_price),2) as profit',
'SUM(collect_num) as collect',
'ROUND((COUNT(distinct(pay_uid))-1)/COUNT(distinct(uid)),2) as changes',
'COUNT(distinct(pay_uid))-1 as repeats'
])->group('product_id')->order('pay' , ' desc')->limit(20)->select()->toArray();
foreach ($list as $key => &$item) {
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->find();
$item['store_name']=$find['store_name'];
$item['image']=$find['image'];
if ($item['profit'] == null) $item['profit'] = 0;
if ($item['changes'] == null) $item['changes'] = 0;
if ($item['repeats'] == null) {
$item['repeats'] = 0;
} else {
$item['repeats'] = bcdiv(count(StoreProductLog::where($where)->where('type', 'pay')->where('product_id', $item['product_id'])->where('store_id',$store_id)->field('count(pay_uid) as p')->group('pay_uid')->having('p>1')->select()), $item['repeats'], 2);
}
}
return array_merge($list);
} }