修改解锁发券逻辑

This commit is contained in:
lccsw
2025-12-31 09:55:59 +08:00
parent 92fce6af3f
commit 6bf1d26d18
2 changed files with 31 additions and 7 deletions
+2 -2
View File
@@ -201,8 +201,8 @@ class Ucenter extends BaseController
{
$id = $this->get('id');
$userCoupon = $this->auto_user_coupon_model->get(['id' => $id, 'userId' => $this->userId]);
$product = $this->auto_product_model->get(['id'=>$userCoupon['productId']]);
$where = ['cf_uid' => $this->userId, 'app_id' => Receiver_clues_model::APP_ID_ACTIVITY, 'out_id' => $userCoupon['productId']];
$product = $this->auto_product_model->get(['id' => $userCoupon['productId']]);
$where = ['cf_uid' => $this->userId, 'app_id' => Receiver_clues_model::APP_ID_ACTIVITY];
$cluesRow = $this->clues_model->get($where);
$cityRow = $this->area_model->get(['city_id' => $cluesRow['city_id']]);
$brand = $this->auto_brand_model->get(['id' => $product['brand_id']], 'name');
@@ -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('更新优惠券状态失败');
}