Esempio n. 1
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $customerId = $this->_params['customerId'];
     $chatBody = $this->_params['chatBody'];
     $authToken = $this->_params['authToken'];
     // 判断经纪人是否存在
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$broker) {
         throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId);
     }
     // 判断是否已经抢过(永久锁定)
     $lock = Bll_CustomerRush_Lock::getDataByBrokerIdAndCustomerId($brokerId, $customerId);
     if (!$lock) {
         throw new Exception_CustomerRush_RelationNotFound("BrokerId: {$brokerId}, CustomerId: {$customerId}");
     }
     // 控制当日发送的微聊消息数量
     if (Bll_CustomerRush_Chat::isChatSendCountLimitEnabled()) {
         $chatCountDailyLimit = Bll_CustomerRush_Chat::getChatSendCountDailyLimit();
         $todayChatCount = Bll_CustomerRush_Chat::getTodayChatCount($brokerId, $customerId);
         if ($todayChatCount >= $chatCountDailyLimit) {
             throw new Exception_CustomerRush_TooManyChat("Today Count: {$todayChatCount}; Daily Limit: {$chatCountDailyLimit}");
         }
     }
     // 格式化输入的参数:chatBody
     if (!is_array($chatBody)) {
         $chatBody = json_decode($chatBody, true);
     }
     // 判断是否是第一次发送
     if (Bll_CustomerRush_Chat::isFirstChat($brokerId, $customerId)) {
         $chatBody['first_send'] = 1;
     }
     // 发送微聊消息
     $chatResponse = Bll_CustomerRush_Chat::sendAppMessage($authToken, $chatBody);
     // 保存微聊记录
     Bll_CustomerRush_Chat::saveChat($brokerId, $customerId, $chatBody);
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('status' => 1, 'statusMsg' => '成功', 'msgId' => $chatResponse['msg_id']));
 }
Esempio n. 2
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $customerId = $this->_params['customerId'];
     $chatBody = $this->_params['chatBody'];
     $authToken = $this->_params['authToken'];
     // 判断经纪人是否存在
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$broker) {
         throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId);
     }
     // 获取有效临时锁定存在
     $relation = Model_Mobile_BrokerUserRelation::getBrokerCustomerLatestTempLockRelation($brokerId, $customerId);
     if (!$relation) {
         // 如无临时锁定,获取有永久锁定存在
         $relation = Model_Mobile_BrokerUserRelation::getBrokerCustomerLatestForeverLockRelation($brokerId, $customerId);
         if (!$relation) {
             // 关系不存在时,提示:客户失效了 重新抢吧
             throw new Exception_CustomerRush_RelationNotFound("BrokerId: {$brokerId}, CustomerId: {$customerId}");
         }
     }
     // TODO 微聊好友(如何根据 DeviceId 和 BrokerId 判断好友关系,有接口吗?)
     // 如果客户禁止抢
     if (!$relation->isCustomerAllowRush()) {
         throw new Exception_CustomerRush_CustomerNotAllowRush("BrokerId: {$brokerId}, CustomerId: {$customerId}");
     }
     // 控制当日发送的微聊消息数量
     if (Bll_CustomerRush_Chat::isChatSendCountLimitEnabled()) {
         $chatCountDailyLimit = Bll_CustomerRush_Chat::getChatSendCountDailyLimit();
         $todayChatCount = Bll_CustomerRush_Chat::getTodayChatCount($brokerId, $customerId);
         if ($todayChatCount >= $chatCountDailyLimit) {
             throw new Exception_CustomerRush_TooManyChat("Today Count: {$todayChatCount}; Daily Limit: {$chatCountDailyLimit}");
         }
     }
     // 格式化输入的参数:chatBody
     if (!is_array($chatBody)) {
         $chatBody = json_decode($chatBody, true);
     }
     // 判断是否是第一次发送
     if (Bll_CustomerRush_Chat::isFirstChat($brokerId, $customerId)) {
         $chatBody['first_send'] = 1;
     }
     // 永久锁定,发消息即可
     if ($relation->isForeverLocked()) {
         // 发送微聊消息
         $chatResponse = Bll_CustomerRush_Chat::sendAppMessage($authToken, $chatBody);
         // 保存微聊记录
         Bll_CustomerRush_Chat::saveChat($brokerId, $customerId, $chatBody);
     } else {
         // 临时锁定,发消息,更新状态
         // 获取经纪人锁
         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};");
         }
         // 发送微聊消息
         $chatResponse = Bll_CustomerRush_Chat::sendAppMessage($authToken, $chatBody);
         // 保存微聊记录
         Bll_CustomerRush_Chat::saveChat($brokerId, $customerId, $chatBody);
         // 更新关系,临时锁定->永久锁定
         $relation->foreverLock();
         // 更新锁定,临时锁定->永久锁定
         Model_Mobile_CustomerLock::foreverLock($relation->id, $relation->uploadDt, $relation->brokerId, $relation->userDeviceId);
         // 更新永久锁定,加1
         Bll_CustomerRush_Lock::incrForeverLockCount($brokerId, 1);
         // 释放客户锁
         Bll_Customer_Parallel::unlockUser($customerId);
         // 释放经纪人锁
         Bll_Customer_Parallel::unlockBroker($brokerId);
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('status' => 1, 'statusMsg' => '成功', 'msgId' => $chatResponse['msg_id']));
 }