|
|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace app\workerapi\lists\shops;
|
|
|
|
|
|
|
|
|
@@ -28,7 +29,7 @@ class ShopCartLists extends BaseWorkerDataLists implements ListsSearchInterface
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public function querySearch():array
|
|
|
+ public function querySearch(): array
|
|
|
{
|
|
|
$where = [];
|
|
|
$where[] = ['worker_id', '=', $this->userId];
|
|
|
@@ -47,16 +48,20 @@ class ShopCartLists extends BaseWorkerDataLists implements ListsSearchInterface
|
|
|
public function lists(): array
|
|
|
{
|
|
|
$lists = ShopCart::with([
|
|
|
- 'goods' => function(Query $query){
|
|
|
- $query->field(['id','goods_name','delivery_type','shop_goods_type','goods_image','goods_status','specs_type','custom_attribute_items','company_name',])->append(['delivery_type_text','shop_goods_type_text']);
|
|
|
+ 'goods' => function (Query $query) {
|
|
|
+ $query->field(['id', 'goods_name', 'delivery_type', 'shop_goods_type', 'goods_image', 'goods_status', 'specs_type', 'custom_attribute_items', 'company_name',])->append(['delivery_type_text', 'shop_goods_type_text']);
|
|
|
},
|
|
|
- 'goodSpecsInventory' => function(Query $query) {
|
|
|
- $query->field(['id','remaining_inventory','specs','service_fee','service_total']);
|
|
|
+ 'goodSpecsInventory' => function (Query $query) {
|
|
|
+ $query->field(['id', 'remaining_inventory', 'specs', 'service_fee', 'service_total']);
|
|
|
}
|
|
|
- ])
|
|
|
+ ])->when(!empty($this->params['goods_name']), function ($query) {
|
|
|
+ $query->hasWhere('goods', function ($query) {
|
|
|
+ $query->where('goods_name', 'like', '%' . $this->params['goods_name'] . '%');
|
|
|
+ });
|
|
|
+ })
|
|
|
->where($this->searchWhere)
|
|
|
->where($this->querySearch())
|
|
|
- ->field(['id', 'shop_goods_id' ,'goods_specs_inventory_id', 'number'])
|
|
|
+ ->visible(['id', 'shop_goods_id', 'goods_specs_inventory_id', 'number'])
|
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
|
->select()
|
|
|
->toArray();
|
|
|
@@ -73,7 +78,12 @@ class ShopCartLists extends BaseWorkerDataLists implements ListsSearchInterface
|
|
|
*/
|
|
|
public function count(): int
|
|
|
{
|
|
|
- return ShopCart::where($this->searchWhere) ->where($this->querySearch())->count();
|
|
|
+ return ShopCart::where($this->searchWhere)->where($this->querySearch())
|
|
|
+ ->when(!empty($this->params['goods_name']), function (Query $query) {
|
|
|
+ $query->hasWhere('goods', function (Query $query) {
|
|
|
+ $query->where('goods_name', 'like', '%' . $this->params['goods_name'] . '%');
|
|
|
+ });
|
|
|
+ })->count();
|
|
|
}
|
|
|
|
|
|
}
|