Exemplo n.º 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' => '抢成功'));
 }
Exemplo n.º 2
0
 /**
  * @return array
  */
 public function handle_request_internal()
 {
     $brokerId = $this->_params['broker_id'];
     $deviceId = $this->_params['device_id'];
     // 升级提示
     $rushStartTime = APF::get_instance()->get_config('v2_rush_customer_consume_coupon_time', 'customer');
     if (time() >= strtotime($rushStartTime)) {
         return array('status' => 'error', 'message' => "抢客户功能大升级!快去最新版中体验吧!");
     }
     // 判断经纪人和客户之间关系是否存在(当日内)
     $relation = Model_Mobile_BrokerUserRelation::getBrokerCustomerTodayRelation($brokerId, $deviceId);
     if (!$relation) {
         throw new Exception_CustomerRush_RelationNotFound("BrokerId: {$brokerId}, CustomerId: {$deviceId}");
     }
     /** 判断经纪人和用户是否已经是有效的临时绑定关系 */
     if (Bll_Customer_BrokerUserRelation::checkBrokerUserRelationStatusIsBind($deviceId, $brokerId)) {
         return array('status' => 'ok', 'data' => array('success' => 1, 'description' => '经纪人和用户已经是锁定关系'));
     }
     if (false === Bll_Customer_Lock::checkBrokerCanBind($brokerId)) {
         return array('status' => 'ok', 'data' => array('success' => 0, 'description' => '经纪人锁定次数已经满3次了'));
     }
     if (false == Bll_Customer_Lock::checkUserCanBind($deviceId)) {
         return array('status' => 'ok', 'data' => array('success' => 0, 'description' => '用户锁定次数已经满3次了'));
     }
     /** 防并发 开始 */
     if (false === Bll_Customer_Parallel::lockBroker($brokerId)) {
         return array('status' => 'ok', 'data' => array('success' => 0, 'description' => '经纪人并发锁失败'));
     }
     if (false === Bll_Customer_Parallel::lockUser($deviceId)) {
         Bll_Customer_Parallel::unlockBroker($brokerId);
         return array('status' => 'ok', 'data' => array('success' => 0, 'description' => '用户并发锁失败'));
     }
     // 临时锁定,更新关系
     $relation->tempLock();
     // 临时锁定,更新锁定
     Model_Mobile_CustomerLock::tempLock($relation->id, $relation->uploadDt, $relation->brokerId, $relation->userDeviceId);
     Bll_Customer_Parallel::unlockBroker($brokerId);
     Bll_Customer_Parallel::unlockUser($deviceId);
     /** 防并发 结束 */
     $result = array('status' => 'ok', 'data' => array('success' => 1));
     return $result;
 }
Exemplo n.º 3
0
 /**
  * 更新经纪人和用户的关系为永久锁定,同时更新经纪人和用户的永久锁定次数做 +1 操作
  *
  * @param string $deviceId
  * @param int $brokerId
  * @return bool
  */
 private function lockCustomer($deviceId, $brokerId)
 {
     $relation = Model_Mobile_BrokerUserRelation::getBrokerCustomerTodayRelation($brokerId, $deviceId);
     if (!$relation) {
         return false;
     }
     // 更新关系,临时锁定->永久锁定
     $relation->foreverLock();
     // 更新锁定,临时锁定->永久锁定
     Model_Mobile_CustomerLock::foreverLock($relation->id, $relation->uploadDt, $relation->brokerId, $relation->userDeviceId);
     // 更新永久锁定,加1
     Bll_CustomerRush_Lock::incrForeverLockCount($brokerId, 1);
     return true;
 }