From 909e66b1f31876c2895624f2abc5684139c72018 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 9 Jun 2024 17:12:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(OrderList):=20=E4=BF=AE=E6=94=B9=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=88=97=E8=A1=A8=E9=80=BB=E8=BE=91=EF=BC=8C=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E5=95=86=E5=93=81=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=8E=E5=B1=95=E7=A4=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/order/OrderList.php | 52 ++++++++++++++++--------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/app/api/lists/order/OrderList.php b/app/api/lists/order/OrderList.php index 482b38719..e779a853d 100644 --- a/app/api/lists/order/OrderList.php +++ b/app/api/lists/order/OrderList.php @@ -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(); } - -} \ No newline at end of file +}