예제 #1
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $customerId = $this->_params['customerId'];
     // 升级提示
     $rushStartTime = APF::get_instance()->get_config('v2_rush_customer_consume_coupon_time', 'customer');
     if (time() >= strtotime($rushStartTime)) {
         return array('status' => 'error', 'message' => "抢客户功能大升级!快去最新版本移动经纪人APP中体验吧!");
     }
     // 判断经纪人是否存在
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$broker) {
         throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId);
     }
     // 判断经纪人和客户之间关系是否存在(当日内)
     $relation = Model_Mobile_BrokerUserRelation::getBrokerCustomerTodayRelation($brokerId, $customerId);
     if (!$relation) {
         throw new Exception_CustomerRush_RelationNotFound("BrokerId: {$brokerId}, CustomerId: {$customerId}");
     }
     // 判断经纪人和客户是否已经有效锁定(未过期临时锁定 或 永久锁定)
     if ($relation->isLocked()) {
         throw new Exception_CustomerRush_IsLocked("BrokerId: {$brokerId}; CustomerId: {$customerId}; RelationId: {$relation->id}; Status: {$relation->status}; TempLockExpireTime: {$relation->tempLockExpireTime}");
     }
     // 判断经纪人是否可抢
     $brokerTodayLockTimes = Model_Mobile_BrokerUserRelation::getBrokerTodayLockTimes($brokerId);
     if ($brokerTodayLockTimes >= Const_CustomerRush::BROKER_MAX_RUSH_COUNT) {
         throw new Exception_CustomerRush_BrokerChanceUsedUp("BrokerId: {$brokerId};");
     }
     // 检测用户是否屏蔽
     if (!$relation->isCustomerAllowRush()) {
         throw new Exception_CustomerRush_CustomerNotAllowRush("BrokerId: {$brokerId}, CustomerId: {$customerId}");
     }
     // 判断用户是否可抢
     $customerTodayLockTimes = Model_Mobile_BrokerUserRelation::getCustomerTodayLockTimes($customerId);
     if ($customerTodayLockTimes >= Const_CustomerRush::CUSTOMER_MAX_RUSHED_COUNT) {
         throw new Exception_CustomerRush_CustomerChanceUsedUp("CustomerId: {$customerId};");
     }
     // 获取经纪人锁
     if (!Bll_Customer_Parallel::lockBroker($brokerId)) {
         throw new Exception_CustomerRush_LockBrokerFailed("BrokerId: {$brokerId}; CustomerId: {$customerId}; RelationId: {$relation->id};");
     }
     // 获取客户锁
     if (!Bll_Customer_Parallel::lockUser($customerId)) {
         Bll_Customer_Parallel::unlockBroker($brokerId);
         throw new Exception_CustomerRush_LockCustomerFailed("BrokerId: {$brokerId}; CustomerId: {$customerId}; RelationId: {$relation->id};");
     }
     // 临时锁定,更新关系
     $relation->tempLock();
     // 临时锁定,更新锁定
     Model_Mobile_CustomerLock::tempLock($relation->id, $relation->uploadDt, $relation->brokerId, $relation->userDeviceId);
     // 释放客户锁
     Bll_Customer_Parallel::unlockUser($customerId);
     // 释放经纪人锁
     Bll_Customer_Parallel::unlockBroker($brokerId);
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('status' => 1, 'statusMsg' => '抢成功'));
 }
예제 #2
0
 public static function isCustomerCanBeRushed($customerId)
 {
     $customerTodayLockTimes = Model_Mobile_BrokerUserRelation::getCustomerTodayLockTimes($customerId);
     return $customerTodayLockTimes < Const_CustomerRush::CUSTOMER_MAX_RUSHED_COUNT;
 }