コード例 #1
0
 /**
  * 使用优惠券
  * @param int $order_id
  * @param int $coupon_id
  */
 public function useCoupon($order_id, $coupon_id, $couponType)
 {
     if (!$couponType) {
         $couponType = 0;
     }
     $price = \Wechat\Logic\CouponLogic::getCouponPrice($coupon_id, $couponType);
     if ($price) {
         $orderInfo = D('TicketOrder')->getOrderInfo($order_id);
         if ($orderInfo['coupon_pay'] > 0) {
             return false;
         }
         if ($orderInfo['third_party_pay'] > $price) {
             $save['third_party_pay'] = $orderInfo['third_party_pay'] - $price;
         } else {
             $save['third_party_pay'] = 0;
         }
         $save['coupon_id'] = $coupon_id;
         $save['coupon_pay'] = $price;
         $saveResult = D('TicketOrder')->where(array('id' => $order_id))->save($save);
         //用户优惠券状态修改
         $cResult = \Wechat\Logic\CouponLogic::changeStatus($coupon_id, $couponType, $order_id);
         if ($saveResult && $cResult) {
             return true;
         }
     }
 }
コード例 #2
0
 public function releaseShareCouponAct()
 {
     if (IS_POST) {
         $openid = getOpenid();
         \Wechat\Logic\CouponLogic::publicShareCoupon($openid);
         return true;
     }
     return false;
 }
コード例 #3
0
 public function receiveAct()
 {
     $activity_id = I('get.id');
     $nowtime = time();
     $couponlist = D('activity_coupon')->where("activity_id={$activity_id} and stime<{$nowtime} and etime>{$nowtime}")->select();
     foreach ($couponlist as $coupon) {
         $isexist = D('user_activitycoupon')->where(array('open_id' => getOpenid(), 'activitycoupon_id' => $coupon['id']))->find();
         if ($isexist) {
             continue;
         }
         $info['open_id'] = getOpenid();
         $info['activitycoupon_id'] = $coupon['id'];
         $info['ctime'] = $nowtime;
         $info['status'] = 0;
         D('user_activitycoupon')->add($info);
         //小提示
         \Wechat\Logic\CouponLogic::ticketTip(getOpenid());
     }
     //设置提示
     \Wechat\Logic\PushLogic::pushTextMsg(getOpenid(), getSysConfig('coupon-text'));
     redirect(UC('/Wechat/Coupon/index'), 0, '页面跳转中...');
 }
コード例 #4
0
 public function reciveCouponAct()
 {
     $openid = getOpenid();
     $invate = I('get.invate');
     $userinfo = \Wechat\Logic\UserLogic::getUserinfo($openid);
     $this->assign('userinfo', $userinfo);
     //先领分享优惠券,然后判断是否已经领取了新人优惠券
     \Wechat\Logic\CouponLogic::receviceShareCoupon($openid, $invate);
     $receviCount = \Wechat\Logic\CouponLogic::countCoupon($openid, NewerCouponID);
     if ($receviCount > 0) {
         redirect('/Wechat/Coupon/index', 0, '页面跳转中...');
         return;
     }
     //再领新人优惠券
     if (IS_POST) {
         $phone = I('post.phone');
         if (preg_match("/1[3458]{1}\\d{9}\$/", $phone)) {
             if ($openid == $invate) {
                 $this->assign("msg", "本人不可领取");
             } else {
                 \Wechat\Logic\UserLogic::updateByOpenid($openid, array('phone' => $phone, 'inviter' => $invate));
                 //赠送优惠券
                 \Wechat\Logic\CouponLogic::giveCoupon($openid, NewerCouponID);
                 //给本人
                 \Wechat\Logic\CouponLogic::giveCoupon($invate, InviteCouponID1);
                 //给推荐者
                 $username = D('User')->where(array('open_id' => $openid))->getField('nickname');
                 $invatename = D('User')->where(array('open_id' => $invate))->getField('nickname');
                 \Wechat\Logic\PushLogic::pushTextMsg($invate, "非常感谢您的分享,您的好友@" . $username . "成功领取了一张魔乐城优惠劵。");
                 \Wechat\Logic\PushLogic::pushTextMsg($openid, getSysConfig('coupon-text'));
                 redirect('/Wechat/Coupon/index', 0, '页面跳转中...');
                 return;
             }
         } else {
             $this->assign("msg", "手机号码填写不正确");
         }
     }
     $this->display();
 }
コード例 #5
0
 public function testAllCouponAct()
 {
     echo getOpenid();
     $dd = \Wechat\Logic\CouponLogic::getAllCoupon(getOpenid());
     print_r($dd);
 }
コード例 #6
0
 public function notifyurlAct()
 {
     recordLog('异步通知开始', 'wechatPay');
     $wechatPay = new \Common\Lib\Pay\pay_wap_wechat\wap_wechat();
     $check = $wechatPay->serverCallback(C('WECHAT_PAY_KEY'));
     if ($check) {
         recordLog('验证成功', 'wechatPay');
         recordLog($check, 'wechatPay');
         $order_sn = $check['out_trade_no'];
         $checkOrder = D('TicketOrder')->where(array('sn' => $order_sn))->find();
         if ($checkOrder['status'] == 0) {
             $save['status'] = 1;
             $save['third_pay_id'] = $this->payType;
             $result = D('TicketOrder')->where(array('sn' => $order_sn))->save($save);
             if ($result) {
                 //调用取票sn接口
                 $this->addTicketSn($order_sn);
                 recordLog('订单修改状态成功', 'wechatPay');
                 //赠送支付人的推荐人优惠券
                 \Wechat\Logic\CouponLogic::givePayInvertCoupon($checkOrder['open_id']);
                 $wechatPay->notifyStop();
             }
         } else {
             recordLog('订单已经支付或取消', 'wechatPay');
         }
     } else {
         recordLog('验证失败', 'wechatPay');
     }
     recordLog('异步通知结束', 'wechatPay');
 }