feat: 创建用户商品存储列表类UserProductStorageLists

This commit is contained in:
mkm 2024-06-29 17:16:56 +08:00
parent bf958fcf75
commit 9ac84ac72f

View File

@ -0,0 +1,92 @@
<?php
namespace app\api\lists\user_product_storage;
use app\api\lists\BaseApiDataLists;
use app\common\model\user_product_storage\UserProductStorage;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
/**
* 用户商品储存列表
* Class UserProductStorageLists
* @package app\admin\listsuser_product_storage
*/
class UserProductStorageLists extends BaseApiDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/06/28 11:05
*/
public function setSearch(): array
{
return [
'=' => ['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();
}
}