Esempio n. 1
0
 public function handle_request_internal()
 {
     $this->brokerId = $this->_params['brokerId'];
     $this->operatorId = $this->_params['operatorId'] ? $this->_params['operatorId'] : 0;
     $this->operatorName = $this->_params['operatorName'] ? $this->_params['operatorName'] : '';
     $result = array('status' => 'error', 'message' => '');
     // 验证经纪人是否合法
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($this->brokerId);
     if (!$broker) {
         $result['message'] = '经纪人不合法';
         return $result;
     }
     // 获取活动劵类型数据
     $cityId = $broker['cityId'];
     $couponData = Bll_CustomerRush_Coupon::getInstance()->getCoupon($cityId, date("Ymd"), Model_Mobile_CustomerCoupon::TYPE_KCOUPON_PRESENT);
     if (empty($couponData)) {
         $result['message'] = '不存在活动劵信息';
         return $result;
     }
     $this->couponId = $couponData['id'];
     // 插入经纪人劵表
     $arr = array('brokerId' => $this->brokerId, 'couponId' => $this->couponId, 'status' => Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE, 'totalNum' => $couponData['totalNum'], 'usedNum' => 0, 'updateTime' => date("Y-m-d H:i:s"), 'createTime' => time());
     $this->brokerCouponId = Bll_CustomerRush_Coupon::getInstance()->insertBrokerCoupon($arr);
     if ($this->brokerCouponId) {
         // 记录日志
         $this->_insertPresentCouponLog();
         $result['status'] = 'ok';
         $result['message'] = '送劵完成';
     } else {
         $result['message'] = '赠送劵失败';
     }
     return $result;
 }
Esempio n. 2
0
 public static function &getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Esempio n. 3
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$brokerInfo) {
         throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     $sendNumChangeDate = APF::get_instance()->get_config("customer_daily_mission_reward_num", "customer");
     if (time() >= strtotime($sendNumChangeDate)) {
         $sendNum = self::PRESENT_COUPON_NEW_NUM;
         $rewardMsg = APF::get_instance()->get_config("customer_daily_mission_reward_msg", "customer");
     } else {
         $sendNum = self::PRESENT_COUPON_NUM;
         $rewardMsg = "恭喜你,获得抢客券2张";
     }
     $data = array('brokerId' => $brokerId, 'rewardMsg' => $rewardMsg);
     $this->brokerId = $brokerId;
     // 获取活动劵类型数据
     $cityId = $brokerInfo['cityId'];
     $couponData = Bll_CustomerRush_Coupon::getInstance()->getCoupon($cityId, date("Ymd"), Model_Mobile_CustomerCoupon::TYPE_DAILYCOUPON_PRESENT);
     if (empty($couponData)) {
         return array('status' => 'error', 'message' => '不存在活动劵信息');
     }
     $this->couponId = $couponData['id'];
     $currentTime = date("Ymd", time());
     //验证是否可领取奖励
     if (Bll_Commsign::getAlreadyGetRewards($brokerId, $currentTime)) {
         return array('status' => 'error', 'message' => '已经领取过奖励');
     }
     $dailyQuestStatus = Model_DailyQuest_DailyQuestStatus::getDailyQuestStatusByBrokerId($brokerId, $currentTime);
     $signStatus = $dailyQuestStatus['signState'] ? $dailyQuestStatus['signState'] : 0;
     $shareStatus = $dailyQuestStatus['shareState'] ? $dailyQuestStatus['shareState'] : 0;
     $rewardStatus = $dailyQuestStatus['rewardState'] ? $dailyQuestStatus['rewardState'] : 0;
     if (!($signStatus == '1' && $shareStatus == '1' && $rewardStatus == '0')) {
         return array('status' => 'error', 'message' => '已经领取过奖励');
     }
     //赠送抢客劵
     for ($i = 0; $i < $sendNum; $i++) {
         // 插入经纪人劵表
         $arr = array('brokerId' => $this->brokerId, 'couponId' => $this->couponId, 'status' => Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE, 'totalNum' => $couponData['totalNum'], 'usedNum' => 0, 'updateTime' => date("Y-m-d H:i:s"), 'createTime' => time());
         $this->brokerCouponId = Bll_CustomerRush_Coupon::getInstance()->insertBrokerCoupon($arr);
         if ($this->brokerCouponId) {
             // 记录日志
             $this->_insertPresentCouponLog();
         } else {
             return array('status' => 'error', 'message' => '赠送失败');
         }
     }
     //更新已领取
     Bll_Commsign::alreadyGetRewards($brokerId, $currentTime);
     $status = Model_DailyQuest_DailyQuestStatus::updateGetReward($brokerId, $currentTime);
     if (!$status) {
         return array('status' => 'error', 'message' => '更新领取状态失败');
     }
     return array('status' => 'ok', 'data' => $data);
 }
Esempio n. 4
0
 public function getPrice($cityId, $userType)
 {
     $startDate = date("Ymd");
     $tmp = Bll_CustomerRush_Coupon::getInstance()->getCoupon($cityId, $startDate, Model_Mobile_CustomerCoupon::TYPE_KCOUPON, $userType);
     if (!$tmp) {
         $result = array('status' => 'error', 'message' => '该城市非套餐价格不存在');
         return $result;
     } else {
         $data = array('id' => $tmp['id'], 'customerNum' => $this->customerNum, 'expire' => $this->expire, 'price' => $tmp['price'] / 100, 'discount_price' => $tmp['disPrice'] / 100, 'number' => $tmp['totalNum'], 'name' => $tmp['name'], 'msg' => $tmp['msg'], 'unit' => "¥");
     }
     return array('status' => 'ok', 'data' => $data);
 }
 /**
  * 获取要跑的数据
  */
 public function getRequestData()
 {
     $list = Bll_CustomerRush_Coupon::getInstance()->getBrokerCouponByBiggerThanId($this->lastId, 'id', 'asc', 0, $this->limit);
     if (empty($list)) {
         $mailSubject = "抢客券45天后过期";
         $mailBody = "Job在" . date('Y-m-d H:i:s') . "执行结束,最后一个抢客券的ID为" . $this->lastId;
         Bll_Broker_ShowcaseCommon::getInstance()->sendMail($mailSubject, $mailBody, $this->mailArr);
         $this->textOutput('已经没有要处理的数据了', false);
         $this->setMyFlag(0, 'over');
         $this->setShStopFlag();
         return array();
     }
     return $list;
 }
Esempio n. 6
0
 public function handle_request_internal()
 {
     //$effectiveTime  = APF::get_instance()->get_config('customer_broker_coupon_effective_time', 'customer');
     //$expiringTime = APF::get_instance()->get_config('customer_broker_coupon_expiring_time', 'customer');
     $brokerId = $this->_params['brokerId'];
     $sinceId = $this->_params['sinceId'];
     $per = isset($this->_params['per']) ? $this->_params['per'] : self::PER;
     //获取抢客劵列表信息
     $brokerCouponList = Bll_CustomerRush_Coupon::getInstance()->getBrokerCouponList($brokerId, $sinceId, $per + 1);
     //更新是否已显示信息
     Model_Mobile_CustomerBrokerCoupon::getInstance()->updateDisplayStatus($brokerId);
     $haveNext = count($brokerCouponList) > $per ? 1 : 0;
     if ($haveNext) {
         array_pop($brokerCouponList);
     }
     $result = array('status' => 'ok', 'data' => array('list' => $brokerCouponList, 'have_next' => $haveNext));
     return $result;
 }
Esempio n. 7
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $iosPgBrokerId = APF::get_instance()->get_config('customer_ios_broker_id_pg', 'customer');
     $iosGaBrokerId = APF::get_instance()->get_config('customer_ios_broker_id_ga', 'customer');
     $data = Bll_CustomerRush_Coupon::getInstance()->getRushTime($brokerId, Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE);
     if (!empty($_SERVER['PG_TEST']) && in_array($brokerId, $iosPgBrokerId) || empty($_SERVER['PG_TEST']) && in_array($brokerId, $iosGaBrokerId)) {
         $result = array('status' => 'ok', 'data' => array('leftTime' => 0, 'iosNoDisplay' => 1, 'isFree' => 0, 'displayRed' => $data['displayRed']));
         if ($this->_isFree()) {
             $result['data']['isFree'] = 1;
         }
         return $result;
     }
     if ($data['status']) {
         $result = array('status' => 'ok', 'data' => array('leftTime' => $data['amount'], 'iosNoDisplay' => 0, 'isFree' => $this->_isFree() ? 1 : 0, 'displayRed' => $data['displayRed']));
     } else {
         $result = array('status' => 'error', 'message' => $data['msg']);
     }
     return $result;
 }
Esempio n. 8
0
 public static function presentExtraQuestCoupon($brokerId)
 {
     $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     // 获取活动劵类型数据
     $cityId = $brokerInfo['cityId'];
     $couponData = Bll_CustomerRush_Coupon::getInstance()->getCoupon($cityId, date("Ymd"), Model_Mobile_CustomerCoupon::TYPE_DAILYCOUPON_PRESENT);
     if (empty($couponData)) {
         return false;
     }
     $couponId = $couponData['id'];
     // 插入经纪人劵表
     $arr = array('brokerId' => $brokerId, 'couponId' => $couponId, 'status' => Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE, 'totalNum' => $couponData['totalNum'], 'usedNum' => 0, 'updateTime' => date("Y-m-d H:i:s"), 'createTime' => time());
     $brokerCouponId = Bll_CustomerRush_Coupon::getInstance()->insertBrokerCoupon($arr);
     if ($brokerCouponId) {
         // 记录日志
         $data = array('brokerId' => $brokerId, 'couponId' => $couponId, 'brokerCouponId' => $brokerCouponId, 'operatorName' => self::EXTRA_PRESENT_OPERATOR_NAME, 'createTime' => date("Y-m-d H:i:s"));
         Model_Mobile_CustomerPresentCouponLog::getInstance()->insertData($data);
     } else {
         return false;
     }
     return true;
 }
 public function handle_request_internal()
 {
     $this->brokerId = $this->_params['brokerId'];
     $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($this->brokerId);
     if (!$brokerInfo) {
         throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     $msg = '';
     $presentStatus = '0';
     //判断经纪人是否满足赠送条件,满足则赠送抢客劵
     $canPresent = Model_DailyQuest_InconformityToNewCoupon::getRowCountByBrokerId($this->brokerId);
     if (!$canPresent) {
         // 获取活动劵类型数据
         $cityId = $brokerInfo['cityId'];
         $couponData = Bll_CustomerRush_Coupon::getInstance()->getCoupon($cityId, date("Ymd"), Model_Mobile_CustomerCoupon::TYPE_KCOUPON_PRESENT);
         if (empty($couponData)) {
             return array('status' => 'error', 'message' => '不存在活动劵信息');
         }
         $this->couponId = $couponData['id'];
         // 插入经纪人劵表
         $arr = array('brokerId' => $this->brokerId, 'couponId' => $this->couponId, 'status' => Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE, 'totalNum' => $couponData['totalNum'], 'usedNum' => 0, 'updateTime' => date("Y-m-d H:i:s"), 'createTime' => time());
         $this->brokerCouponId = Bll_CustomerRush_Coupon::getInstance()->insertBrokerCoupon($arr);
         if ($this->brokerCouponId) {
             // 记录日志
             $this->_insertPresentCouponLog();
         } else {
             return array('status' => 'error', 'message' => '赠送失败');
         }
         $msg = '恭喜你获得10张抢客券,点击去查看';
         try {
             Model_DailyQuest_InconformityToNewCoupon::insertBrokerRecord($this->brokerId);
         } catch (Exception $e) {
             return array('status' => 'error', 'message' => '不满足赠送条件或已经赠送过');
         }
         $presentStatus = '1';
     }
     $data = array('brokerId' => $this->brokerId, 'presentMsg' => $msg, 'presentStatus' => $presentStatus, 'couponSum' => self::PRESENT_COUPON_NUM);
     return array('status' => 'ok', 'data' => $data);
 }
Esempio n. 10
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $orderNo = $this->_params['orderNo'];
     $result = array('status' => 'error');
     // 获取数据
     $order = Bll_CustomerRush_Order::getInstance()->getDataByOrderNo($orderNo);
     if (empty($order) || $order[0]['brokerId'] != $brokerId) {
         $result['message'] = '查无订单';
         return $result;
     }
     $coupon = Bll_CustomerRush_Coupon::getInstance()->getCouponById($order[0]['couponId']);
     if (empty($coupon)) {
         $result['message'] = '查无客劵信息';
         return $result;
     }
     $result['status'] = 'ok';
     $effectiveTime = APF::get_instance()->get_config('customer_broker_coupon_effective_time', 'customer');
     $startDate = date("Y-m-d", $order[0]['createTime']);
     $tmpEndDate = strtotime($startDate) + $effectiveTime * 24 * 60 * 60 - 1;
     $result['data'] = array('orderStatus' => $order[0]['status'], 'startDate' => $startDate, 'endDate' => date('Y-m-d', $tmpEndDate), 'amount' => $coupon[0]['totalNum'] * $order[0]['num'], 'orderNo' => $orderNo);
     return $result;
 }
Esempio n. 11
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $couponId = $this->_params['couponId'];
     $payType = $this->_params['type'];
     $amount = $this->_params['amount'];
     $source = $this->_params['source'];
     $result = array('status' => 'error');
     // 验证经纪人是否合法
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$broker) {
         $result['message'] = '经纪人不合法';
         return $result;
     }
     /*
             // 限制购买时间 3个小时之内不能重复购买
             if(time() < strtotime(APF::get_instance()->get_config("cancel_customer_coupon_buy_limit_date", "customer"))) {
                 $lastOrder = Bll_CustomerRush_Order::getInstance()->getLatestOrder($brokerId,Model_Mobile_CustomerOrder::STATUS_OK);
                 if($lastOrder && $lastOrder['createTime'] > time() - 3 * 60 * 60) {
                     $result['message'] = '购买过于频繁,请稍后再试';
                     $result['errcode'] = Const_APIStatus::E_CUSTOMER_RUSH_BUY_TIME_LIMIT;
                     return $result;
                 }
             } */
     // 获取抢客劵信息
     $tmpCoupon = Bll_CustomerRush_Coupon::getInstance()->getCouponById($couponId);
     if (!$tmpCoupon) {
         $result['message'] = '没有抢客劵信息';
         return $result;
     }
     $coupon = $tmpCoupon[0];
     if ($coupon['disPrice'] < 0) {
         $result['message'] = '抢客劵信息异常';
         return $result;
     }
     if ($payType == 1) {
         // 支付宝支付
         $tmp = Bll_CustomerRush_Payment_Pay::getInstance()->getAliPayKey($broker, $coupon, $amount, $payType, $source);
         if ($tmp['status'] == 'ok') {
             $result['status'] = 'ok';
             $result['data'] = array('url' => $tmp['url'], 'orderNo' => !empty($tmp['order']) ? $tmp['order']['orderNo'] : '');
         } else {
             $result['status'] = 'error';
             $result['message'] = $tmp['message'];
         }
     } elseif ($payType == 2) {
         // 微信支付
         $tmp = Bll_CustomerRush_Payment_Pay::getInstance()->getWechatPayKey($broker, $coupon, $amount, $payType, $source);
         if ($tmp['status'] == 'ok') {
             $result['status'] = 'ok';
             $result['data'] = array('url' => $tmp['url'], 'orderNo' => !empty($tmp['order']) ? $tmp['order']['orderNo'] : '');
         } else {
             $result['status'] = 'error';
             $result['message'] = $tmp['message'];
         }
     } elseif ($payType == 3) {
         // 安币支付
         $tmp = Bll_CustomerRush_Payment_Pay::getInstance()->buyCouponByAnbi($broker, $coupon, $amount, $payType, $source);
         if ($tmp['status'] == 'ok') {
             $result['status'] = 'ok';
             $order = $tmp['order'];
             $effectiveTime = APF::get_instance()->get_config('customer_broker_coupon_effective_time', 'customer');
             $startDate = date("Y-m-d", $order['createTime']);
             $tmpEndDate = strtotime($startDate) + $effectiveTime * 24 * 60 * 60 - 1;
             $result['data'] = array('orderStatus' => $order['status'], 'startDate' => $startDate, 'endDate' => date("Y-m-d", $tmpEndDate), 'amount' => $coupon['totalNum'] * $order['num'], 'orderNo' => $order['orderNo']);
         }
     } else {
         $result['message'] = '支付方式参数不正确';
     }
     return $result;
 }
Esempio n. 12
0
 /**
  * 创建活动劵
  * @param $brokerId
  * @param $broker
  * @return array
  */
 private function _create($brokerId, $broker)
 {
     $result = array('status' => 'error', 'message' => '');
     // 判断是否已经存在
     $tmp = Bll_CustomerRush_Coupon::getInstance()->getActiveCouponByBrokerId($brokerId);
     if ($tmp) {
         $result['message'] = '已经存在';
         return $result;
     }
     // 获取活动劵类型数据
     $cityId = $broker['cityId'];
     $couponData = Bll_CustomerRush_Coupon::getInstance()->getCoupon($cityId, date("Ymd"), Model_Mobile_CustomerCoupon::TYPE_KCOUPON_ACTIVITY);
     if (empty($couponData)) {
         $result['message'] = '不存在活动劵信息';
         return $result;
     }
     $arr = array('brokerId' => $brokerId, 'couponId' => $couponData['id'], 'status' => 1, 'createTime' => time(), 'updateTime' => date("Y-m-d H:i:s"));
     if (Bll_CustomerRush_Coupon::getInstance()->insertCouponActive($arr)) {
         $result['status'] = 'ok';
         $result['message'] = '成功';
     } else {
         $result['message'] = '插入失败';
     }
     return $result;
 }
Esempio n. 13
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $customerId = $this->_params['customerId'];
     $result = array('status' => 'error', 'message' => '');
     // 验证经纪人是否合法
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$broker) {
         $result['message'] = '经纪人不合法';
         return $result;
     }
     // 判断经纪人和客户之间关系是否存在(三日内)
     $date = date('Y-m-d', strtotime("-2 day"));
     $relation = Bll_CustomerRush_BrokerUserRelation::getInstance()->getLastRalationData($brokerId, $customerId, $date);
     if (empty($relation)) {
         $result['message'] = '不存在数据关系';
         return $result;
     }
     // 检测用户是否屏蔽
     if (!Bll_CustomerRush_BrokerUserRelation::getInstance()->isCustomerAllowRush($relation)) {
         $result['message'] = '用户已屏蔽';
         return $result;
     }
     // 判断是否已经抢过(永久锁定)
     $lock = Bll_CustomerRush_Lock::getDataByBrokerIdAndCustomerId($brokerId, $customerId);
     if (!empty($lock)) {
         $result['message'] = '已经被抢过了';
         return $result;
     }
     // 判断是否存在临时关系
     if ($relation->status != Model_Mobile_BrokerUserRelationSub::STATUS_TEMP_LOCKED) {
         // 不存在临时关系,建立临时关系
         // 判断是否已经满3次
         $tmpDate = date("Ymd");
         $rushedCountData = Bll_CustomerRush_Customer::getInstance()->getCustomerRushedCount($customerId, $tmpDate);
         $limit = APF::get_instance()->get_config('customer_day_rushed_limit', 'customer');
         if (!empty($rushedCountData) && $rushedCountData[0]['num'] >= $limit) {
             $result['message'] = '已经被抢完了';
             return $result;
         }
         // 获取经纪人锁
         if (!Bll_Customer_Parallel::lockBroker($brokerId)) {
             $result['message'] = '锁经纪人异常';
             return $result;
         }
         // 获取客户锁
         if (!Bll_Customer_Parallel::lockUser($customerId)) {
             Bll_Customer_Parallel::unlockBroker($brokerId);
             $result['message'] = '锁客户异常';
             return $result;
         }
         // 更新关系
         $updateRelationSub = array('status' => Model_Mobile_BrokerUserRelationSub::STATUS_TEMP_LOCKED, 'tempLockTime' => date("Y-m-d H:i:s"), 'tempLockExpireTime' => date('Y-m-d H:i:s', strtotime('+' . Model_Mobile_BrokerUserRelationSub::TEMP_LOCK_PERIOD . ' mins')), 'updateTime' => date("Y-m-d H:i:s"));
         Bll_CustomerRush_BrokerUserRelation::getInstance()->updateBrokerUserRelationSub(array('id' => $relation->id), $updateRelationSub);
         // 每日被抢加+1
         Bll_CustomerRush_Customer::getInstance()->addCustomerRushedCount($customerId);
         // 释放客户锁
         Bll_Customer_Parallel::unlockUser($customerId);
         // 释放经纪人锁
         Bll_Customer_Parallel::unlockBroker($brokerId);
     }
     // 创建支付中心账户id
     Bll_Customerrush_Payment_User::getInstance()->getUserAccountId($brokerId, $broker['userId']);
     // 查询有无未激活的活动劵
     $activeCoupon = Bll_CustomerRush_Coupon::getInstance()->getActiveCouponByBrokerId($brokerId, Model_Mobile_CustomerBrokerCouponActivity::STATUS_CREATE);
     if (!empty($activeCoupon) && $this->_isActivity()) {
         // 获取劵信息
         $coupon = Bll_CustomerRush_Coupon::getInstance()->getCouponById($activeCoupon['couponId']);
         $result['data']['unActiveCouponNum'] = !empty($coupon) ? $coupon[0]['totalNum'] : 0;
     } else {
         $result['data']['unActiveCouponNum'] = 0;
     }
     // 查询可抢次数
     $rushTimedata = Bll_CustomerRush_Coupon::getInstance()->getRushTime($brokerId, Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE);
     if ($rushTimedata['status'] == 'ok') {
         $result['data']['canRushTime'] = $rushTimedata['amount'];
     } else {
         $result['data']['canRushTime'] = 0;
     }
     $result['data']['useCouponNum'] = 1;
     $result['data']['relation'] = 1;
     $baseActiveUrl = APF::get_instance()->get_config('activity_coupon_active_url', 'customer');
     $result['data']['activeUrl'] = $baseActiveUrl . "?brokerid=" . $brokerId;
     $result['status'] = 'ok';
     $result['message'] = '建立临时性关系';
     $result['data']['customerId'] = $customerId;
     // 收费开关配置
     if ($this->_isFree()) {
         $result['data']['status'] = 1;
         // 免费
     } else {
         if ($result['data']['useCouponNum'] <= $result['data']['canRushTime']) {
             $result['data']['status'] = 2;
             // 有劵,去消耗劵
         } else {
             $result['data']['status'] = 3;
             // 劵剩余不足
         }
     }
     return $result;
 }
Esempio n. 14
0
 /**
  * 安比购买抢客劵
  * @param $broker
  * @param $coupon
  * @param $amount
  * @param $payType
  * @param $source
  * @return array()
  */
 public function buyCouponByAnbi($broker, $coupon, $amount, $payType, $source)
 {
     $result = array('status' => 'error', 'msg' => '', 'order' => '');
     $brokerId = $broker['brokerId'];
     //查询账户余额是否足够
     $balance = Bll_Service_Payment::balance(Bll_Service_Payment::SITE_ANJUKE, array('userId' => $broker['userId']));
     if (empty($balance) || $balance['status'] != 'ok') {
         $result['msg'] = '查询余额失败,稍后再试';
         return $result;
     }
     $userAccountAll = $balance['data']['balance'];
     //账户余额
     $needAccount = $coupon['disPrice'] * $amount;
     // 待扣费金额
     if ($userAccountAll < $needAccount || $needAccount < 0) {
         $result['msg'] = '余额不足,请充值';
         return $result;
     }
     // 创建订单
     $order = Bll_CustomerRush_Order::getInstance()->createOrder($brokerId, "", $coupon, $amount, $payType, $source);
     //$requestId = Bll_Customerrush_Payment_Common::getInstance()->createRequsetId("charge",$order['id']);
     $requestId = Bll_Customerrush_Payment_Common::getInstance()->createChargeRequsetId($order['orderNo']);
     $order->msg = json_encode(array("requestId" => $requestId));
     // 保存requestId;
     $order->updateTime = date("Y-m-d H:i:s");
     $order->save();
     // 调用扣费接口
     $cusumeResult = Bll_Customerrush_Payment_Common::getInstance()->chargeMoneyByAnbi($brokerId, $broker['userId'], $requestId, $needAccount);
     if ($cusumeResult['status'] != 'ok') {
         $result['msg'] = '扣费失败,请稍后再试。';
         return $result;
     }
     // 记录扣费日志
     $log2 = array('brokerId' => $brokerId, 'accountId' => 0, 'price' => $needAccount, 'realPrice' => $needAccount, 'amount' => 0, 'requestId' => $requestId, 'type' => 2, 'createTime' => time());
     Bll_CustomerRush_Payment_Log::getInstance()->insertBrokerBalanceLog($log2);
     // 更新订单
     $order->status = Model_Mobile_CustomerOrder::STATUS_OK;
     $order->msg = json_encode(array("payInfo" => "success", "requestId" => $requestId));
     $order->updateTime = date("Y-m-d H:i:s");
     $order->save();
     // 给经纪人加劵
     for ($i = 0; $i < $order->num; $i++) {
         $addCoupon = array('brokerId' => $brokerId, 'couponId' => $order['couponId'], 'status' => Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE, 'totalNum' => $coupon['totalNum'], 'usedNum' => 0, 'updateTime' => date("Y-m-d H:i:s"), 'createTime' => time(), 'orderId' => $order['id']);
         Bll_CustomerRush_Coupon::getInstance()->insertBrokerCoupon($addCoupon);
     }
     $result['status'] = 'ok';
     $result['order'] = $order;
     return $result;
 }
 public function getBrokerCoupon($brokerId, $orderNum, $orderUpdateTime)
 {
     $brokerCoupon = Model_Mobile_CustomerBrokerCoupon::getInstance()->getDataByBrokerIdAndTotalNum($brokerId);
     $result = array();
     $i = 0;
     foreach ($brokerCoupon as $val) {
         if ($i >= $orderNum) {
             break;
         }
         // 确认劵是否购买
         $coupon = Bll_CustomerRush_Coupon::getInstance()->getCouponById($val['couponId']);
         if ($coupon[0]['type'] == 1 && $this->checkTime($val['createTime'], $orderUpdateTime)) {
             $result[] = $val;
             $i++;
         }
     }
     return $result;
 }
 private function _consumeCouponLog($brokerId, $brokerCouponId, $num)
 {
     $log = array('brokerId' => $brokerId, 'num' => $num, 'brokerCouponId' => $brokerCouponId, 'changeType' => 3, 'changeDesc' => '', 'createTime' => date("Y-m-d H:i:s"));
     Bll_CustomerRush_Coupon::getInstance()->insertBrokerCouponLog($log);
 }
Esempio n. 17
0
 private function _updateBrokerCoupon($coupon)
 {
     $coupon->usedNum += 1;
     $coupon->updateTime = date("Y-m-d H:i:s");
     if ($coupon->usedNum == $coupon->totalNum) {
         $coupon->status = Model_Mobile_CustomerBrokerCoupon::STATUS_OK_UNUSE;
     }
     $coupon->save();
     // 记录消耗劵日志
     $log = array('brokerId' => $coupon['brokerId'], 'num' => 1, 'brokerCouponId' => $coupon['id'], 'changeType' => 2, 'changeDesc' => '', 'createTime' => date("Y-m-d H:i:s"));
     Bll_CustomerRush_Coupon::getInstance()->insertBrokerCouponLog($log);
 }
 /**
  * 获取活动券类型
  * @param $brokerId
  * @return bool
  */
 public function getCouponData($brokerId)
 {
     $cityId = $this->getBrokerCityId($brokerId);
     if ($cityId) {
         $couponInfo = Bll_CustomerRush_Coupon::getInstance()->getCoupon($cityId, date("Ymd"), Model_Mobile_CustomerCoupon::TYPE_DAILYCOUPON_PRESENT);
         if (!empty($couponInfo)) {
             return $couponInfo;
         } else {
             $str = date("Y-m-d H:i:s") . " - brokerId: {$brokerId} - cityId: {$cityId} - customerCouponType: " . Model_Mobile_CustomerCoupon::TYPE_DAILYCOUPON_PRESENT . " 无该城市的此抢客券信息";
             $this->setMyLog($str, $this->sendLogName);
         }
     }
     return false;
 }