['paid', 'status', 'is_writeoff'], 'between_time' => 'create_time', '%like%' => ['order_id'], ]; } /** * @notes 零售订单列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @date 2024/04/27 11:26 */ public function lists(): array { $userId = $this->request->userId; if (!$userId) return []; $data = StoreOrder::with(['store'])->where($this->searchWhere)->where(['uid'=>$userId]) ->whereIn('shipping_type',[1,2]) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->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,cart_info')->limit(3)->select() ->each(function ($v) use ($item) { $find = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $item['store_id'])->withTrashed()->find(); if(empty($find)){ $find = StoreProduct::where('id', $v['product_id'])->withTrashed()->find(); } $v['store_name'] = $find['store_name']; $v['image'] = $find['image']; // $v['price'] = $find['price']; $v['price'] = $v['cart_info']['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']); } if($item['verify_img']){ $item['verify_img'] = 'https://'.$this->request->host(true).$item['verify_img']; } }) ->toArray(); return $data; } /** * @notes 零售订单数量 * @return int * @date 2024/04/27 11:26 */ public function count(): int { $userId = $this->request->userId; return StoreOrder::where($this->searchWhere)->whereIn('shipping_type',[1,2])->where('uid', $userId)->count(); } }