调整商品列表查询

This commit is contained in:
luofei 2024-02-26 16:48:59 +08:00
parent 651db69dcd
commit 8625c0aa0c
3 changed files with 19 additions and 15 deletions

View File

@ -54,6 +54,13 @@ class StoreCouponUserDao extends BaseDao
/** @var float $profitRate 商品毛利率 */ /** @var float $profitRate 商品毛利率 */
public $profitRate; public $profitRate;
const RATE_ARRAY = [
['profit_rate' => 10, 'use_rate' => 0.1],
['profit_rate' => 15, 'use_rate' => 0.2],
['profit_rate' => 20, 'use_rate' => 0.3],
['profit_rate' => 25, 'use_rate' => 0.4],
];
/** /**
* @return BaseModel * @return BaseModel
* @author xaboy * @author xaboy
@ -262,20 +269,13 @@ class StoreCouponUserDao extends BaseDao
*/ */
public function getRate($profitRate) public function getRate($profitRate)
{ {
$rateArray = [ foreach (self::RATE_ARRAY as $item) {
25 => 0.4, if ($profitRate >= $item['profit_rate']) {
20 => 0.3, $rate = $item['use_rate'];
15 => 0.2,
10 => 0.1,
];
$rate = 0;
foreach ($rateArray as $k => $item) {
if ($profitRate >= $k) {
$rate = $item;
break; break;
} }
} }
return $rate; return $rate ?? 0;
} }
/** /**

View File

@ -201,7 +201,11 @@ class SpuDao extends BaseDao
$query->where('svip_price_type','>',0)->where('mer_svip_status',1); $query->where('svip_price_type','>',0)->where('mer_svip_status',1);
}) })
->when(isset($where['deduction_rate']) && $where['deduction_rate'] !== '',function($query)use($where){ ->when(isset($where['deduction_rate']) && $where['deduction_rate'] !== '',function($query)use($where){
$productIds = ProductAttrValue::where('profit_rate', $where['deduction_rate'])->column('product_id'); $productIds = ProductAttrValue::when(isset($where['mer_id']) && $where['mer_id'] !== '', function($query) use ($where) {
$query->where('mer_id', $where['mer_id']);
})->where('profit_rate', '>=', $where['deduction_rate'])
->where('profit_rate', '<', ($where['deduction_rate'] + 5))
->column('product_id');
if (empty($productIds)) { if (empty($productIds)) {
$productIds = [0]; $productIds = [0];
} }

View File

@ -131,7 +131,7 @@ class Spu extends BaseModel
*/ */
public function getShowSvipInfoAttr($value, $data) public function getShowSvipInfoAttr($value, $data)
{ {
if ($this->product_type == 0) return $this->product->show_svip_info; if ($this->product_type == 0 && !empty($this->product->show_svip_info)) return $this->product->show_svip_info;
} }
/** /**
@ -142,12 +142,12 @@ class Spu extends BaseModel
*/ */
public function getSvipPriceAttr() public function getSvipPriceAttr()
{ {
if ($this->product_type == 0) return $this->product->svip_price; if ($this->product_type == 0 && !empty($this->product->svip_price)) return $this->product->svip_price;
} }
public function getIsSvipPriceAttr() public function getIsSvipPriceAttr()
{ {
if ($this->product_type == 0) return $this->product->is_svip_price; if ($this->product_type == 0 && !empty($this->product->is_svip_price)) return $this->product->is_svip_price;
} }
public function getMerLabelsDataAttr() public function getMerLabelsDataAttr()