Beispiel #1
0
 public static function &getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Beispiel #2
0
 public function getWechatPayKey($broker, $coupon, $amount, $payType, $source)
 {
     // 创建订单
     $brokerId = $broker['brokerId'];
     $ac = Bll_Customerrush_Payment_User::getInstance()->getUserAccountId($brokerId, $broker['userId']);
     // 获取订单信息
     $order = Bll_CustomerRush_Order::getInstance()->createOrder($brokerId, $ac, $coupon, $amount, $payType, $source);
     // 获取ack
     $tmpAckResult = Bll_Customerrush_Payment_Common::getInstance()->getAckValue($ac);
     $ack = $tmpAckResult['status'] ? $tmpAckResult['sessionkey'] : "";
     $am = $coupon['disPrice'] * $amount;
     $body = "安居客订单:" . $order['orderNo'];
     $notifyUrl = APF::get_instance()->get_config('customer_wechatpay_notify_url', 'customer');
     $bg = $notifyUrl . "?orderNo=" . $order['orderNo'];
     $cityId = $broker['cityId'];
     $or = $order['orderNo'];
     $pn = $broker['trueName'];
     $pt = $coupon['name'];
     $subject = "微信购买";
     $payKeyData = $this->requestAcenterWechatPayInitSerive($ac, $ack, $am, $body, $bg, $cityId, $or, $pn, $pt, $subject);
     if ($payKeyData['status'] == 'ok') {
         // 更新订单状态
         $order->status = Model_Mobile_CustomerOrder::STATUS_DOING;
         $order->updateTime = date("Y-m-d H:i:s");
         $order->save();
         $result = array('status' => 'ok', 'url' => $payKeyData['url'], 'order' => $order);
     } else {
         $result = array('status' => 'error', 'msg' => $payKeyData['msg']);
     }
     return $result;
 }
Beispiel #3
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;
 }