优化购买产品优惠列表查询逻辑

- 移除冗余的用户ID设置代码
- 改用类属性存储用户ID,提高性能
- 修正查询条件,确保只查询用户相关数据
- 优化计数逻辑,无用户时返回0
This commit is contained in:
mkm 2024-10-10 16:36:57 +08:00
parent 00fb209800
commit 9da525af64
2 changed files with 5 additions and 8 deletions

View File

@ -26,7 +26,6 @@ class PurchaseProductOfferController extends BaseApiController
*/
public function lists()
{
$this->request->__set('uid',$this->userId);
return $this->dataLists(new PurchaseProductOfferLists());
}

View File

@ -18,7 +18,6 @@ use app\api\lists\BaseApiDataLists;
class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchInterface
{
public $userId;
/**
* @notes 设置搜索条件
* @return \string[][]
@ -44,9 +43,8 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI
*/
public function lists(): array
{
$uid=$this->request->__get('uid');
if($uid){
$this->searchWhere[]=['buyer_id','=',$uid];
if($this->userId>0){
$this->searchWhere[]=['buyer_id','=',$this->userId];
}else{
return [];
}
@ -87,10 +85,10 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI
*/
public function count(): int
{
if($this->userId){
return 0;
}else{
if($this->userId>0){
return PurchaseProductOffer::where($this->searchWhere)->count();
}else{
return 0;
}
}