作者 chencheng

kq-0620-2

@@ -475,11 +475,56 @@ class Wechat extends Api @@ -475,11 +475,56 @@ class Wechat extends Api
475 $this->grant_red_packets($pid,$order_id); 475 $this->grant_red_packets($pid,$order_id);
476 }else{ 476 }else{
477 //属于普通用户 则领取礼品券 477 //属于普通用户 则领取礼品券
478 - $this->send_gift_certificate($pid,$verification_coupon_ids,$order_id,$time); 478 + //$this->send_gift_certificate($pid,$verification_coupon_ids,$order_id,$time);
  479 + //卡券发放规则
  480 + $this->send_gift_certificate_url($pid,$verification_coupon_ids,$order_id,$time);
479 } 481 }
480 } 482 }
481 483
482 //发放 对应活动的礼品券 484 //发放 对应活动的礼品券
  485 + public function send_gift_certificate_url($pid,$order_id,$time){
  486 + $order_info = Db::name('verification_order')->where(['id'=>$order_id])->find();
  487 + $store = Db::name('verification_store')->where(['id'=>$order_info['verification_store_id']])->find();
  488 + $activity = Db::name('verification_activity')->where(['id'=>$order_info['verification_activity_id']])->find();
  489 + //获取门店下的礼品券
  490 + if(!empty($activity['verification_coupon_ids'])){
  491 +
  492 + //判断当前父级的所有下级的订单数,是否满足 send_rule_limit 的规则
  493 + $subIds = Db::name('user')->where(['pid'=>$pid])->column('id');
  494 + $subOrderCount = Db::name('verification_order')->where(['user_id'=>['in',$subIds],'type'=>['>','0']])->count();
  495 +
  496 + //获取卡券
  497 + //当前活动对应的所有券
  498 + $coupon = Db::name('verification_coupon')->where(['id'=>['in',$activity['verification_coupon_ids']],'type'=>1,'send_rule_limit'=>$subOrderCount])->find();
  499 +
  500 + if(!empty($coupon)){
  501 + //发送给pid用户
  502 + $save = [];
  503 + $save['verification_coupon_id'] = $store['verification_coupon_id'];
  504 + $save['verification_store_id'] = $store['id'];
  505 + $save['user_id'] = $pid;
  506 +
  507 + $save['type'] = 0;//使用情况
  508 + $save['closetime'] = $coupon['closetime'];
  509 + $save['receive_no'] = time().rand(1000,9999);
  510 + $res = (new \app\api\controller\v1\Index())->build($save['receive_no']);
  511 + $save['qr_code'] = $res;//二维码
  512 + $save['createtime'] = $time;
  513 + $save['verification_order_id'] = $order_id;
  514 + $save['coupon_type'] = $coupon['type'];
  515 + Db::name('verification_receive')->insert($save);
  516 + }
  517 + }
  518 + }
  519 +
  520 + public function test_rule(){
  521 + $pid = 23;
  522 + $order_id = '223';
  523 + $time = time();
  524 + $this->send_gift_certificate_url($pid,$order_id,$time);
  525 + }
  526 +
  527 + //发放 对应活动的礼品券
483 public function send_gift_certificate($pid,$verification_coupon_ids,$order_id,$time){ 528 public function send_gift_certificate($pid,$verification_coupon_ids,$order_id,$time){
484 $order_info = Db::name('verification_order')->where(['id'=>$order_id])->find(); 529 $order_info = Db::name('verification_order')->where(['id'=>$order_id])->find();
485 $store = Db::name('verification_store')->where(['id'=>$order_info['verification_store_id']])->find(); 530 $store = Db::name('verification_store')->where(['id'=>$order_info['verification_store_id']])->find();