|
|
@@ -40,9 +40,44 @@ class GoodsSpecPriceLists extends BaseAdminDataLists implements ListsSearchInter
|
|
|
*/
|
|
|
public function setSearch(): array
|
|
|
{
|
|
|
- return array_intersect(array_keys($this->params), [
|
|
|
- 'bar_code', 'keyword', 'category_id', 'supplier_id', 'goods_type', 'status'
|
|
|
- ]);
|
|
|
+ $searchWhere = [];
|
|
|
+
|
|
|
+ // 条形码搜索
|
|
|
+ if (!empty($this->params['bar_code'])) {
|
|
|
+ $goodsIds = GoodsItem::where('bar_code', $this->params['bar_code'])->column('goods_id');
|
|
|
+ if ($goodsIds) {
|
|
|
+ $searchWhere[] = ['g.id', 'in', $goodsIds];
|
|
|
+ } else {
|
|
|
+ $searchWhere[] = ['g.id', '=', 0]; // 没有匹配的商品
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关键词搜索
|
|
|
+ if (!empty($this->params['keyword'])) {
|
|
|
+ $searchWhere[] = ['g.code|g.name', 'like', '%' . $this->params['keyword'] . '%'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分类搜索
|
|
|
+ if (!empty($this->params['category_id'])) {
|
|
|
+ $searchWhere[] = ['g.category_id', '=', $this->params['category_id']];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 供应商搜索
|
|
|
+ if (!empty($this->params['supplier_id'])) {
|
|
|
+ $searchWhere[] = ['g.supplier_id', '=', $this->params['supplier_id']];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 商品类型搜索
|
|
|
+ if (!empty($this->params['goods_type'])) {
|
|
|
+ $searchWhere[] = ['g.goods_type', '=', $this->params['goods_type']];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 状态搜索
|
|
|
+ if (isset($this->params['status']) && $this->params['status'] !== '') {
|
|
|
+ $searchWhere[] = ['g.status', '=', $this->params['status']];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $searchWhere;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -53,9 +88,10 @@ class GoodsSpecPriceLists extends BaseAdminDataLists implements ListsSearchInter
|
|
|
*/
|
|
|
public function lists(): array
|
|
|
{
|
|
|
+ $searchWhere = $this->setSearch();
|
|
|
$lists = Goods::alias('g')
|
|
|
->leftJoin('goods_item gi', 'g.id = gi.goods_id')
|
|
|
- ->withSearch($this->setSearch(), $this->params)
|
|
|
+ ->where($searchWhere)
|
|
|
->where('g.delete_time', null)
|
|
|
->field([
|
|
|
'g.id as goods_id',
|
|
|
@@ -86,9 +122,11 @@ class GoodsSpecPriceLists extends BaseAdminDataLists implements ListsSearchInter
|
|
|
*/
|
|
|
public function count(): int
|
|
|
{
|
|
|
+ $searchWhere = $this->setSearch();
|
|
|
+
|
|
|
return Goods::alias('g')
|
|
|
->leftJoin('goods_item gi', 'g.id = gi.goods_id')
|
|
|
- ->withSearch($this->setSearch(), $this->params)
|
|
|
+ ->where($searchWhere)
|
|
|
->where('g.delete_time', null)
|
|
|
->count();
|
|
|
}
|