购物车添加查询字段

This commit is contained in:
luofei 2024-03-15 13:39:15 +08:00
parent 5198b95428
commit fab06892d4
5 changed files with 17 additions and 4 deletions

View File

@ -134,9 +134,9 @@ class StoreCartDao extends BaseDao
* @return mixed * @return mixed
* @author Qinii * @author Qinii
*/ */
public function getCartCount(int $uid) public function getCartCount(int $uid, int $saleType)
{ {
$data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])->field('SUM(cart_num) as count')->select(); $data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0, 'sale_type' => $saleType])->field('SUM(cart_num) as count')->select();
$data[0]['count'] = $data[0]['count'] ? $data[0]['count'] : 0; $data[0]['count'] = $data[0]['count'] ? $data[0]['count'] : 0;
return $data; return $data;
} }

View File

@ -76,6 +76,9 @@ class SpuDao extends BaseDao
$saleType = $where['sale_type'] == Enum::SALE_TYPE_RETAIL ? [Enum::RETAIL_ONLY, Enum::RETAIL_WHOLESALE] : [Enum::WHOLESALE_ONLY, Enum::RETAIL_WHOLESALE]; $saleType = $where['sale_type'] == Enum::SALE_TYPE_RETAIL ? [Enum::RETAIL_ONLY, Enum::RETAIL_WHOLESALE] : [Enum::WHOLESALE_ONLY, Enum::RETAIL_WHOLESALE];
$merIds = Merchant::whereIn('wholesale', $saleType)->column('mer_id'); $merIds = Merchant::whereIn('wholesale', $saleType)->column('mer_id');
$query->whereIn('P.mer_id', $merIds); $query->whereIn('P.mer_id', $merIds);
if ($where['sale_type'] == Enum::SALE_TYPE_WHOLESALE) {
$query->join('StoreProductAttrValue PAV','S.product_id = PAV.product_id', 'left')->where('PAV.wholesale_price', '>', 0);
}
}) })
->when(isset($where['product_ids']) && $where['product_ids'] !== '',function($query)use($where){ ->when(isset($where['product_ids']) && $where['product_ids'] !== '',function($query)use($where){
$query->whereIn('P.product_id',$where['product_ids']); $query->whereIn('P.product_id',$where['product_ids']);
@ -112,6 +115,14 @@ class SpuDao extends BaseDao
$query->whereIn('P.mer_id',$merId); $query->whereIn('P.mer_id',$merId);
}) })
->when(isset($where['mer_type']) && $where['mer_type'] !== '',function($query)use($where){
$merId = Merchant::where('type_id', 22)->value('mer_id');
if ($where['mer_type'] == 1) {
$query->where('P.mer_id', $merId);
} elseif ($where['mer_type'] == 2) {
$query->where('P.mer_id', '<>', $merId);
}
})
->when(isset($where['cate_pid']) && $where['cate_pid'], function ($query) use ($where) { ->when(isset($where['cate_pid']) && $where['cate_pid'], function ($query) use ($where) {
$storeCategoryRepository = app()->make(StoreCategoryRepository::class); $storeCategoryRepository = app()->make(StoreCategoryRepository::class);
if (is_array($where['cate_pid'])) { if (is_array($where['cate_pid'])) {

View File

@ -34,7 +34,7 @@ class SpuRepository extends BaseRepository
{ {
public $dao; public $dao;
public $merchantFiled = 'mer_id,mer_name,mer_avatar,is_trader,mer_info,mer_keyword,type_id'; public $merchantFiled = 'mer_id,mer_name,mer_avatar,is_trader,mer_info,mer_keyword,type_id';
public $productFiled = 'P.product_id,S.store_name,S.image,activity_id,S.keyword,S.price,S.mer_id,spu_id,S.status,store_info,brand_id,cate_id,unit_name,S.star,S.rank,S.sort,sales,S.product_type,rate,reply_count,extension_type,S.sys_labels,S.mer_labels,P.delivery_way,P.delivery_free,S.ot_price,svip_price_type,stock,mer_svip_status'; public $productFiled = 'P.product_id,S.store_name,S.image,activity_id,S.keyword,S.price,S.mer_id,spu_id,S.status,store_info,brand_id,cate_id,unit_name,S.star,S.rank,S.sort,P.sales,S.product_type,rate,reply_count,extension_type,S.sys_labels,S.mer_labels,P.delivery_way,P.delivery_free,S.ot_price,svip_price_type,P.stock,mer_svip_status';
public function __construct(SpuDao $dao) public function __construct(SpuDao $dao)
{ {
$this->dao = $dao; $this->dao = $dao;

View File

@ -173,7 +173,8 @@ class StoreCart extends BaseController
*/ */
public function cartCount() public function cartCount()
{ {
return app('json')->success($this->repository->getCartCount($this->request->uid())); $saleType = $this->request->get('sale_type', 1);
return app('json')->success($this->repository->getCartCount($this->request->uid()), intval($saleType));
} }
/** /**

View File

@ -67,6 +67,7 @@ class StoreSpu extends BaseController
'type_code', 'type_code',
'category_id', 'category_id',
'label_name', 'label_name',
'mer_type',
]); ]);
if ($where['type_id'] || $where['type_code']) { if ($where['type_id'] || $where['type_code']) {
$query = Merchant::where(['status' => 1, 'mer_state' => 1, 'is_del' => 0]); $query = Merchant::where(['status' => 1, 'mer_state' => 1, 'is_del' => 0]);