Merge pull request 'feat: 添加根据产品ID或仓库名称搜索的功能' (#112) from dev into main

Reviewed-on: #112
This commit is contained in:
mkm 2024-08-07 16:17:28 +08:00
commit 673a77fde6
2 changed files with 49 additions and 11 deletions

View File

@ -19,6 +19,9 @@ use app\common\model\warehouse\Warehouse;
class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInterface class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInterface
{ {
public $ids;
public $product_id;
/** /**
* @notes 设置搜索条件 * @notes 设置搜索条件
@ -45,6 +48,16 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
*/ */
public function lists(): array 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) 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']) ->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) ->limit($this->limitOffset, $this->limitLength)
@ -98,7 +111,15 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
*/ */
public function count(): int public function count(): int
{ {
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(); return WarehouseProduct::where($this->searchWhere)->count();
} }
}
} }

View File

@ -18,7 +18,8 @@ use app\common\model\warehouse\Warehouse;
*/ */
class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface
{ {
public $ids;
public $store_name;
/** /**
* @notes 设置搜索条件 * @notes 设置搜索条件
@ -45,6 +46,15 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
*/ */
public function lists(): array 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) return WarehouseProductStorege::where($this->searchWhere)
->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status']) ->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
@ -79,7 +89,14 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
*/ */
public function count(): int public function count(): int
{ {
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(); return WarehouseProductStorege::where($this->searchWhere)->count();
} }
}
} }