feat(change_price_log): 优化价格变更记录列表接口

- 添加商品名称和会员组名称字段
- 优化 store_name 搜索条件
- 调整列表数据返回格式,增加创建时间和关联信息
This commit is contained in:
mkm 2025-01-10 17:50:29 +08:00
parent dbb7b9e4c8
commit b7f9a3b5ee

View File

@ -7,6 +7,7 @@ use app\common\lists\BaseDataLists;
use app\common\model\change_price_log\ChangePriceLog; use app\common\model\change_price_log\ChangePriceLog;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\user_ship\UserShip;
/** /**
* 价格变更记录列表 * 价格变更记录列表
@ -44,7 +45,7 @@ class ChangePriceLogLists extends BaseDataLists implements ListsSearchInterface
{ {
if ($this->request->get('store_name')) { if ($this->request->get('store_name')) {
$store_name = $this->request->get('store_name'); $store_name = $this->request->get('store_name');
$ids = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->where('status',1)->column('id'); $ids = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->where('status', 1)->column('id');
if ($ids) { if ($ids) {
$this->searchWhere[] = ['product_id', 'in', $ids]; $this->searchWhere[] = ['product_id', 'in', $ids];
$this->ids = $ids; $this->ids = $ids;
@ -53,10 +54,14 @@ class ChangePriceLogLists extends BaseDataLists implements ListsSearchInterface
} }
} }
return ChangePriceLog::where($this->searchWhere) return ChangePriceLog::where($this->searchWhere)
->field(['id', 'product_id', 'group_id', 'before_price', 'after_price']) ->field(['id', 'product_id', 'group_id', 'before_price', 'after_price','create_time'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()->each(function ($item) {
$store_name= StoreProduct::where('id', $item['product_id'])->value('store_name');
$item->store_name = $store_name;
$item->group_name=UserShip::where('id',$item['group_id'])->value('title');
})
->toArray(); ->toArray();
} }
@ -69,12 +74,11 @@ class ChangePriceLogLists extends BaseDataLists implements ListsSearchInterface
*/ */
public function count(): int public function count(): int
{ {
if($this->request->get('store_name')){ if ($this->request->get('store_name')) {
if($this->ids<=0){ if ($this->ids <= 0) {
return 0; return 0;
} }
} }
return ChangePriceLog::where($this->searchWhere)->count(); return ChangePriceLog::where($this->searchWhere)->count();
} }
}
}