public function _sentCouponForNewUser($openid, $parentId)
 {
     $active = new ActiveModel();
     $coupon = new CouponModel();
     if ($parentId != 0) {
         $customer = new CustomerModel();
         $parentCustomer = $customer->getCustomerInfoById($parentId);
         if ($parentCustomer != false) {
             $parentOpenid = $parentCustomer['openid'];
             $activeOld = $active->getOldCustomerSendCouponInfo();
             if ($activeOld['state'] == 0) {
                 $cover = $activeOld['cover'];
                 //面额
                 $duration = $activeOld['duration'];
                 $count = $activeOld['count'];
                 $coupon->sendCoupon($parentOpenid, $cover, $duration, $count);
             }
         }
     }
     $activeNew = $active->getNewCustomerSendCouponInfo();
     if ($activeNew['state'] == 0) {
         $cover = $activeNew['cover'];
         //面额
         $duration = $activeNew['duration'];
         $count = $activeNew['count'];
         $coupon->sendCoupon($openid, $cover, $duration, $count);
     }
 }
Exemplo n.º 2
0
 public function registeAction()
 {
     $customer = new CustomerModel();
     $openId = I('get.openid', '');
     $checkCode = I('get.checkcode', '');
     $weixinId = I('get.weixinid', '');
     if ($openId == '' || $checkCode == '' || $weixinId == '') {
         return false;
     }
     //取用户信息
     $customerInfo = get_customer_info($openId);
     if ($customerInfo == false) {
         $customer->setOpenid($openId);
         $customer->addCustomer();
         $customerInfo = get_customer_info($openId);
     }
     $customerType = $customerInfo['subscribe_state'];
     //判断用户类型
     if ((int) $customerType & 1 == 1) {
         echo "请务重复注册";
         return;
     }
     if ($checkCode != session($openId . 'checkCode')) {
         echo "验证码错语";
         return;
     }
     if (time() - session($openId . 'lastTime') > 300) {
         echo "验证码已过期,请重新获取";
         return;
     }
     //用户状态更新
     $customer->setWeixinId($weixinId);
     $customer->updateState();
     //调用关注送券活动
     $active = new ActiveModel();
     $active->setopenId($openId);
     $accessToken = get_access_token();
     $data = get_weichat_user_info($openId, $accessToken);
     //用出客户基本信息
     //
     $obj = get_postObj();
     if (isset($obj->EventKey)) {
         $pcid = (int) $obj->EventKey;
     } else {
         $pcid = 0;
     }
     $data['parentid'] = $pcid;
     $active->setParentId($pcid);
     $active->subscribe();
     //
     echo "success";
 }