From 9ac84ac72fc7768c55c972397c005bdac8f47c47 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 29 Jun 2024 17:16:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=AD=98=E5=82=A8=E5=88=97=E8=A1=A8=E7=B1=BB?= =?UTF-8?q?UserProductStorageLists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserProductStorageLists.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 app/api/lists/user_product_storage/UserProductStorageLists.php diff --git a/app/api/lists/user_product_storage/UserProductStorageLists.php b/app/api/lists/user_product_storage/UserProductStorageLists.php new file mode 100644 index 000000000..674f9e6e9 --- /dev/null +++ b/app/api/lists/user_product_storage/UserProductStorageLists.php @@ -0,0 +1,92 @@ + ['oid', 'product_id'], + 'between_time' => 'create_time', + ]; + } + + + /** + * @notes 获取用户商品储存列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/06/28 11:05 + */ + public function lists(): array + { + $status=$this->request->get('status',1); + if($status==1){ + $this->searchWhere[]=['status','=',1];//只显示正常状态的记录,不显示已出库完的记录 + $field='id,uid,oid,product_id,sum(nums) nums,status,create_time'; + $group='product_id'; + }else{ + $field='id,uid,oid,product_id,nums,status,create_time'; + $group=null; + } + $this->searchWhere[]=['uid','=',$this->userId]; + return UserProductStorage::where($this->searchWhere) + ->field($field) + ->group($group) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $user=User::where('id',$item['uid'])->field('nickname,real_name')->find(); + $item['nickname']=$user['real_name']?$user['real_name'].'|'.$item['uid']:$user['nickname'].'|'.$item['uid']; + $find=StoreProduct::where('id',$item['product_id'])->field('store_name,image,price')->find(); + $item['store_name']=$find['store_name']; + $item['image']=$find['image']; + $item['price']=$find['price']; + if($item['status']==1){ + $item['status_name']='正常'; + }else{ + $item['status_name']='已出库完'; + } + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取用户商品储存数量 + * @return int + * @author admin + * @date 2024/06/28 11:05 + */ + public function count(): int + { + return UserProductStorage::where($this->searchWhere)->count(); + } + +} \ No newline at end of file