作者 chencheng

kq-0620-2

... ... @@ -475,11 +475,56 @@ class Wechat extends Api
$this->grant_red_packets($pid,$order_id);
}else{
//属于普通用户 则领取礼品券
$this->send_gift_certificate($pid,$verification_coupon_ids,$order_id,$time);
//$this->send_gift_certificate($pid,$verification_coupon_ids,$order_id,$time);
//卡券发放规则
$this->send_gift_certificate_url($pid,$verification_coupon_ids,$order_id,$time);
}
}
//发放 对应活动的礼品券
public function send_gift_certificate_url($pid,$order_id,$time){
$order_info = Db::name('verification_order')->where(['id'=>$order_id])->find();
$store = Db::name('verification_store')->where(['id'=>$order_info['verification_store_id']])->find();
$activity = Db::name('verification_activity')->where(['id'=>$order_info['verification_activity_id']])->find();
//获取门店下的礼品券
if(!empty($activity['verification_coupon_ids'])){
//判断当前父级的所有下级的订单数,是否满足 send_rule_limit 的规则
$subIds = Db::name('user')->where(['pid'=>$pid])->column('id');
$subOrderCount = Db::name('verification_order')->where(['user_id'=>['in',$subIds],'type'=>['>','0']])->count();
//获取卡券
//当前活动对应的所有券
$coupon = Db::name('verification_coupon')->where(['id'=>['in',$activity['verification_coupon_ids']],'type'=>1,'send_rule_limit'=>$subOrderCount])->find();
if(!empty($coupon)){
//发送给pid用户
$save = [];
$save['verification_coupon_id'] = $store['verification_coupon_id'];
$save['verification_store_id'] = $store['id'];
$save['user_id'] = $pid;
$save['type'] = 0;//使用情况
$save['closetime'] = $coupon['closetime'];
$save['receive_no'] = time().rand(1000,9999);
$res = (new \app\api\controller\v1\Index())->build($save['receive_no']);
$save['qr_code'] = $res;//二维码
$save['createtime'] = $time;
$save['verification_order_id'] = $order_id;
$save['coupon_type'] = $coupon['type'];
Db::name('verification_receive')->insert($save);
}
}
}
public function test_rule(){
$pid = 23;
$order_id = '223';
$time = time();
$this->send_gift_certificate_url($pid,$order_id,$time);
}
//发放 对应活动的礼品券
public function send_gift_certificate($pid,$verification_coupon_ids,$order_id,$time){
$order_info = Db::name('verification_order')->where(['id'=>$order_id])->find();
$store = Db::name('verification_store')->where(['id'=>$order_info['verification_store_id']])->find();
... ...