修改解锁发券逻辑
This commit is contained in:
@@ -331,6 +331,7 @@ class Receiver_customers_model extends HD_Model
|
||||
$log_path = "customer_unlock.log";
|
||||
$this->load->model('receiver/receiver_clues_model');
|
||||
$this->load->model('agent/auto_user_coupon_model');
|
||||
$this->load->model('biz/biz_car_brand_model');
|
||||
$this->auto_user_coupon_model->set_db('agentdb');
|
||||
$this->db->trans_begin();
|
||||
$this->auto_user_coupon_model->db->trans_begin();
|
||||
@@ -356,11 +357,34 @@ class Receiver_customers_model extends HD_Model
|
||||
throw new Exception('您已解锁该线索');
|
||||
}
|
||||
$unLockBizIds[] = $row['biz_id'];
|
||||
$updateCoupon = [
|
||||
'unLockBizIds' => implode(',', $unLockBizIds),
|
||||
'status' => Auto_user_coupon_model::STATUS_NOT_USED
|
||||
];
|
||||
$res = $this->auto_user_coupon_model->update($updateCoupon, ['id' => $coupon['id']]);
|
||||
//获取门店的品牌
|
||||
$bizBrands = $this->biz_car_brand_model->select(['biz_id' => $row['biz_id']], '', '', '', 'brand_id');
|
||||
$bizBrandIds = $bizBrands ? array_column($bizBrands, 'brand_id') : [];
|
||||
$bizBrandIdString = $bizBrandIds ? implode(',', $bizBrandIds) : '';
|
||||
|
||||
if ($bizBrandIdString) {
|
||||
//按门店品牌发券
|
||||
$updateCoupon = [
|
||||
"unLockBizIds = IF(
|
||||
unLockBizIds IS NOT NULL AND unLockBizIds != '',
|
||||
CONCAT_WS(',',unLockBizIds, '{$row['biz_id']}'),
|
||||
'{$row['biz_id']}'
|
||||
)" => null,
|
||||
'status' => Auto_user_coupon_model::STATUS_NOT_USED
|
||||
];
|
||||
$where = [
|
||||
"productId in (select id from lc_auto_product where brandId in ({$bizBrandIdString}) and status =1)" => null,
|
||||
"status" => Auto_user_coupon_model::STATUS_AUDITING,
|
||||
'userId' => $coupon['userId']
|
||||
];
|
||||
$res = $this->auto_user_coupon_model->update($updateCoupon, $where);
|
||||
} else {
|
||||
$updateCoupon = [
|
||||
'unLockBizIds' => implode(',', $unLockBizIds),
|
||||
'status' => Auto_user_coupon_model::STATUS_NOT_USED
|
||||
];
|
||||
$res = $this->auto_user_coupon_model->update($updateCoupon, ['id' => $coupon['id']]);
|
||||
}
|
||||
if (!is_numeric($res)) {
|
||||
throw new Exception('更新优惠券状态失败');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user