增加后台发送优惠券
This commit is contained in:
@@ -136,17 +136,20 @@ class Product extends BaseController
|
||||
$where = [
|
||||
"(provinceId is null or cityId={$cityId})" => null,
|
||||
"seriesId" => $seriesId,
|
||||
"status" => Auto_product_model::STATUS_NORMAL,
|
||||
];
|
||||
$productList = $this->autoProduct->selectProduct($where, "", $page, $limit, 'id');
|
||||
print_r($productList);
|
||||
exit;
|
||||
// $coupons = $this->auto_product_coupon_model->select($where, 'id desc', $page, $lists);
|
||||
// foreach ($coupons as $item) {
|
||||
// $lists[] = [
|
||||
// 'id' => $item['id'],
|
||||
// 'title' => $item['title'],
|
||||
// ];
|
||||
// }
|
||||
$productList = $this->autoProduct->selectProduct($where, "", $page, $limit);
|
||||
$productIds = $productList ? implode(',', array_column($productList, 'id')) : 0;
|
||||
$where = [
|
||||
"product_id in ({$productIds})" => null,
|
||||
];
|
||||
$coupons = $this->auto_product_coupon_model->select($where, 'id desc', $page, $limit);
|
||||
foreach ($coupons as $item) {
|
||||
$lists[] = [
|
||||
'id' => $item['id'],
|
||||
'title' => $item['title'],
|
||||
];
|
||||
}
|
||||
$this->return_response_list($lists);
|
||||
}
|
||||
|
||||
|
||||
@@ -518,12 +518,23 @@ class Clues extends BaseController
|
||||
}
|
||||
$this->return_response();
|
||||
}
|
||||
|
||||
// 发放优惠券
|
||||
public function sendCoupon_post()
|
||||
{
|
||||
$brands = $this->input_param('brands');
|
||||
print_r($brands);exit;
|
||||
$this->return_response();
|
||||
$this->load->model('agent/auto_user_coupon_model');
|
||||
$params = $this->input_param();
|
||||
try {
|
||||
/** @var MyResponse $resutl */
|
||||
$resutl = $this->auto_user_coupon_model->sendCoupon($params['id'], $params['couponId']);
|
||||
if (!$resutl->isSuccess()) {
|
||||
throw new Exception($resutl->getMessage());
|
||||
}
|
||||
$this->return_response();
|
||||
} catch (Exception $e) {
|
||||
$this->return_json($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ class AutoUserCouponEntity
|
||||
$where = [
|
||||
'app_id' => Receiver_clues_model::APP_ID_ACTIVITY,
|
||||
'cf_uid' => $this->userId,
|
||||
'out_id' => $this->productId
|
||||
// 'out_id' => $this->productId
|
||||
];
|
||||
$clueRow = $this->ci->receiver_clues_model->get($where);
|
||||
$where = [
|
||||
|
||||
@@ -136,4 +136,67 @@ class Auto_user_coupon_model extends HD_Model
|
||||
return new MyResponse(EXIT_ERROR, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给指定线索发送优惠券
|
||||
* @param $cluesId
|
||||
* @param $couponId
|
||||
* @return MyResponse
|
||||
*/
|
||||
public function sendCoupon($cluesId, $couponId)
|
||||
{
|
||||
$this->load->model('agent/auto_product_model');
|
||||
$this->load->model('agent/auto_product_coupon_model');
|
||||
$this->load->model('receiver/receiver_enroll_model');
|
||||
$this->load->model('receiver/receiver_clues_model');
|
||||
$this->receiver_clues_model->set_db('ssdb');
|
||||
$this->receiver_enroll_model->set_db('ssdb');
|
||||
try {
|
||||
$cluesRow = $this->receiver_clues_model->get(['id' => $cluesId]);
|
||||
if (!$cluesRow) {
|
||||
throw new Exception('线索不存在');
|
||||
}
|
||||
$coupon = $this->auto_product_coupon_model->get(['id' => $couponId]);
|
||||
if (!$coupon) {
|
||||
throw new Exception('优惠券不存在');
|
||||
}
|
||||
$where = ['userId' => $cluesRow['cf_uid'], 'couponId' => $couponId];
|
||||
$row = $this->get($where);
|
||||
if ($row) {
|
||||
throw new Exception('优惠券已领取');
|
||||
}
|
||||
$sid = create_order_no($cluesRow['city_id'], 'pingan');
|
||||
$data = [
|
||||
'sid' => $sid,
|
||||
'userId' => $cluesRow['cf_uid'],
|
||||
'productId' => $coupon['product_id'],
|
||||
'couponId' => $couponId,
|
||||
'mobile' => $cluesRow['mobile'],
|
||||
'title' => $coupon['title'],
|
||||
'price' => $coupon['price'],
|
||||
'timeStart' => $coupon['timeStart'],
|
||||
'timeEnd' => $coupon['timeEnd'],
|
||||
];
|
||||
$res = $this->add($data);
|
||||
if (!$res) {
|
||||
throw new Exception('发送失败');
|
||||
}
|
||||
$product = $this->auto_product_model->get(['id' => $coupon['product_id']]);
|
||||
//增加留资记录
|
||||
$enrollData = [
|
||||
'sid' => $sid,
|
||||
'mobile' => $cluesRow['mobile'],
|
||||
'cf_id' => $cluesRow['cf_id'],
|
||||
'cf2_id' => $cluesRow['cf2_id'],
|
||||
'out_id' => $coupon['product_id'],
|
||||
'c_time' => time()
|
||||
];
|
||||
$enrollData['brand_id'] = $product['brandId'] ?: 0;
|
||||
$enrollData['series_id'] = $product['seriesId'] ?: 0;
|
||||
$this->receiver_enroll_model->add($enrollData);
|
||||
return new MyResponse(EXIT_SUCCESS, '操作成功');
|
||||
} catch (Exception $e) {
|
||||
return new MyResponse(EXIT_ERROR, $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user