Merge pull request 'feat: 添加根据产品ID或仓库名称搜索的功能' (#112) from dev into main
Reviewed-on: #112
This commit is contained in:
commit
673a77fde6
@ -19,6 +19,9 @@ use app\common\model\warehouse\Warehouse;
|
||||
class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
public $ids;
|
||||
public $product_id;
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
@ -45,6 +48,16 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
if($this->request->get('product_id')){
|
||||
$this->product_id=$this->request->get('product_id');
|
||||
$ids=StoreProduct::where('store_name','like','%'.$this->request->get('product_id').'%')->column('id');
|
||||
if($ids){
|
||||
$this->searchWhere[]=['product_id','in',$ids];
|
||||
}else{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return WarehouseProduct::where($this->searchWhere)
|
||||
->field(['id', 'admin_id','store_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price','purchase','cost', 'total_price', 'manufacture','expiration_date','status','mark','create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
@ -98,7 +111,15 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return WarehouseProduct::where($this->searchWhere)->count();
|
||||
if($this->product_id){
|
||||
if($this->ids){
|
||||
return WarehouseProduct::whereIn('id',$this->ids)->where($this->searchWhere)->count();
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
return WarehouseProduct::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,8 @@ use app\common\model\warehouse\Warehouse;
|
||||
*/
|
||||
class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
public $ids;
|
||||
public $store_name;
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
@ -45,14 +46,23 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
if ($this->request->get('store_name')) {
|
||||
$this->store_name = $this->request->get('store_name');
|
||||
$ids = StoreProduct::where('store_name', 'like', '%' . $this->request->get('store_name') . '%')->column('id');
|
||||
if ($ids) {
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return WarehouseProductStorege::where($this->searchWhere)
|
||||
->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item){
|
||||
$item->warehouse_name = Warehouse::where('id',$item->warehouse_id)->value('name');
|
||||
$find= StoreProduct::where('id',$item->product_id)->find();
|
||||
if($find){
|
||||
->select()->each(function ($item) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
|
||||
$find = StoreProduct::where('id', $item->product_id)->find();
|
||||
if ($find) {
|
||||
$item->store_name = $find->store_name;
|
||||
$item->image = $find->image;
|
||||
$item->bar_code = $find->bar_code;
|
||||
@ -64,9 +74,9 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name');
|
||||
}
|
||||
$item['stock']=$item['nums'];
|
||||
$item['stock'] = $item['nums'];
|
||||
return $item;
|
||||
})
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
@ -79,7 +89,14 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return WarehouseProductStorege::where($this->searchWhere)->count();
|
||||
if ($this->store_name) {
|
||||
if ($this->ids) {
|
||||
return WarehouseProductStorege::whereIn('id', $this->ids)->where($this->searchWhere)->count();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return WarehouseProductStorege::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user