feat: 修改订单列表和商品统计逻辑

This commit is contained in:
mkm 2024-06-22 15:27:39 +08:00
parent b21c74f103
commit d1b23d8709
2 changed files with 9 additions and 10 deletions

View File

@ -9,6 +9,7 @@ use app\common\enum\PayEnum;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
/** /**
* 订单列表列表 * 订单列表列表
@ -45,9 +46,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function lists(): array public function lists(): array
{ {
return StoreOrder::with(['user', 'staff', 'product' => function ($query) { return StoreOrder::with(['user', 'staff'])->where($this->searchWhere)
$query->field(['id', 'oid', 'product_id', 'cart_info']);
}])->where($this->searchWhere)
->when(!empty($this->request->adminInfo['store_id']), function ($query) { ->when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->request->adminInfo['store_id']); $query->where('store_id', $this->request->adminInfo['store_id']);
}) })
@ -68,13 +67,13 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
if ($item['paid'] == 0) { if ($item['paid'] == 0) {
$item['status_name'] = '待支付'; $item['status_name'] = '待支付';
} }
$product_count = count($item['product']) >= 3 ? 3 : count($item['product']); $product = StoreOrderCartInfo::where('oid', $item['id'])->field(['id', 'oid', 'product_id', 'cart_info'])
for ($i = 0; $i < $product_count; $i++) { ->limit(3)->select();
$find = StoreBranchProduct::where('product_id', $item['product'][$i]['product_id'])->field('store_name,image')->find(); foreach ($product as &$items) {
$item['product'][$i]['store_name'] = $find['store_name']; $items['store_name'] = $items['cart_info']['name'];
$item['product'][$i]['image'] = $find['image']; $items['image'] = $items['cart_info']['image'];
} }
$item['product'] = $product;
return $item; return $item;
}) })
->toArray(); ->toArray();

View File

@ -32,7 +32,7 @@ class ProductStatisticLogic extends BaseLogic
'SUM(collect_num) as collect', 'SUM(collect_num) as collect',
'ROUND((COUNT(distinct(pay_uid))-1)/COUNT(distinct(uid)),2) as changes', 'ROUND((COUNT(distinct(pay_uid))-1)/COUNT(distinct(uid)),2) as changes',
'COUNT(distinct(pay_uid))-1 as repeats' 'COUNT(distinct(pay_uid))-1 as repeats'
])->group('product_id')->order('pay'.' desc')->limit(20)->select()->toArray(); ])->group('product_id')->order('pay'.' desc')->limit(10)->select()->toArray();
foreach ($list as $key => &$item) { foreach ($list as $key => &$item) {
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->find(); $find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->find();
$item['store_name']=$find['store_name']; $item['store_name']=$find['store_name'];