feat(OrderList): 修改订单列表逻辑,重构商品信息获取与展示方式

This commit is contained in:
mkm 2024-06-09 17:12:01 +08:00
parent 9d2d78881a
commit 909e66b1f3

View File

@ -5,6 +5,7 @@ namespace app\api\lists\order;
use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product_unit\StoreProductUnit;
@ -26,7 +27,7 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['paid','status','is_writeoff'],
'=' => ['paid', 'status', 'is_writeoff'],
'between_time' => 'create_time',
'%like%' => ['order_id'],
];
@ -43,31 +44,33 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
*/
public function lists(): array
{
$userId=$this->request->userId;
if(!$userId) return [];
$data = StoreOrder::with(['store'])->where($this->searchWhere)->where('uid',$userId)
$userId = $this->request->userId;
if (!$userId) return [];
$data = StoreOrder::with(['store'])->where($this->searchWhere)->where('uid', $userId)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->each(function($item){
$item['goods_list']=StoreOrderCartInfo::where('oid',$item['id'])->with(['goodsName'=> function ($query) {
$query->withTrashed();
}])->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time,old_cart_id')->limit(3)->select();
$item['goods_count']=count(explode(',',$item['cart_id']));
->each(function ($item) {
$item['goods_list'] = StoreOrderCartInfo::where('oid', $item['id'])
->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time,old_cart_id')->limit(3)->select()
->each(function ($v) use ($item) {
$find = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $item['store_id'])->find();
$v['store_name'] = $find['store_name'];
$v['image'] = $find['image'];
$v['price'] = $find['price'];
$v['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? '';
});
$item['goods_count'] = count(explode(',', $item['cart_id']));
if ($item['refund_reason_time']) {
$item['refund_reason_time'] = date('Y-m-d H:i:s', $item['refund_reason_time']);
}
if ($item['pay_time']) {
$item['pay_time'] = date('Y-m-d H:i:s', $item['pay_time']);
}
})
->toArray();
foreach ($data as &$value){
if($value['refund_reason_time']){
$value['refund_reason_time'] = date('Y-m-d H:i:s',$value['refund_reason_time']);
}
if($value['pay_time']){
$value['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']);
}
foreach ($value['goods_list'] as &$vv){
$vv['unit'] =StoreProductUnit::where('id',$vv['unit'])->value('name')??'';
}
}
return $data;
return $data;
}
@ -78,8 +81,7 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
*/
public function count(): int
{
$userId=$this->request->userId;
return StoreOrder::where($this->searchWhere)->where('uid',$userId)->count();
$userId = $this->request->userId;
return StoreOrder::where($this->searchWhere)->where('uid', $userId)->count();
}
}
}