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