|
@@ -68,6 +68,36 @@ class PromoProduct extends Model
|
|
|
*
|
|
|
*/
|
|
|
public function getListByIds($productIds)
|
|
|
+ {
|
|
|
+ $time = time();
|
|
|
+ $where = [
|
|
|
+ ['promo.status','=','0'],
|
|
|
+ ['promo.start_time','<=',$time],
|
|
|
+ ['promo.end_time','>=',$time],
|
|
|
+ ['promo_product.status','=',0],
|
|
|
+ ];
|
|
|
+ $data = $this->query()
|
|
|
+ ->join('promo','promo.id','=','promo_product.promo_id')
|
|
|
+ ->where($where)
|
|
|
+ ->whereIn('promo_product.product_id',$productIds)
|
|
|
+ ->select('promo.*','promo_product.product_id','promo_product.id as promo_product_id')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ // 列表
|
|
|
+ $list = [];
|
|
|
+ // 循环处理
|
|
|
+ foreach ($data as $value) {
|
|
|
+ // 重组数据
|
|
|
+ $list[$value['product_id']]= $value;
|
|
|
+ }
|
|
|
+ // 返回结果
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 通过产品ids查询活动列表
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function getListByIds_new($productIds)
|
|
|
{
|
|
|
$time = time();
|
|
|
$where = [
|
|
@@ -124,7 +154,7 @@ class PromoProduct extends Model
|
|
|
// 如果有产品
|
|
|
if( !$productIds ) return ['is_used'=>0,'product_price'=>$productPrice,'rebate_product'=>[]];
|
|
|
// 获取产品活动
|
|
|
- $promoList = $this->getListByIds($productIds);
|
|
|
+ $promoList = $this->getListByIds_new($productIds);
|
|
|
$promoProductList = [];
|
|
|
foreach ($promoList as $promoListItem) {
|
|
|
foreach ($promoListItem as $promoInfo){
|
|
@@ -179,9 +209,9 @@ class PromoProduct extends Model
|
|
|
$rebateKey = 0;
|
|
|
foreach ($value as $v){
|
|
|
if($v['rebate']>$rebateValue){
|
|
|
+ unset($promoProductList[$rebateKey]);
|
|
|
$rebateValue = $v['rebate'];
|
|
|
$rebateKey = $v['promo_id'];
|
|
|
- unset($promoProductList[$rebateKey]);
|
|
|
}else{
|
|
|
unset($promoProductList[$v['promo_id']]);
|
|
|
}
|