Example #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' => '抢成功'));
 }
Example #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;
 }
Example #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;
     }
     // 判断是否已经抢过(永久锁定)
     $lock = Bll_CustomerRush_Lock::getDataByBrokerIdAndCustomerId($brokerId, $customerId);
     if (!empty($lock)) {
         $result['message'] = '已经被抢过了';
         return $result;
     }
     // 判断是否有临时关系
     $date = date('Y-m-d', strtotime("-2 day"));
     $relation = Bll_CustomerRush_BrokerUserRelation::getInstance()->getLastRalationData($brokerId, $customerId, $date);
     if (!$this->_isTmpRelation($relation) || empty($relation)) {
         $result['message'] = '已超时,请重新抢我';
         return $result;
     }
     if (!$this->_isFree()) {
         // 获取最早的一张可用劵数据
         $coupon = Bll_CustomerRush_Coupon::getInstance()->getBrokerOldestCouponEx($brokerId);
         if (empty($coupon) || $coupon->totalNum <= $coupon->usedNum) {
             $result['message'] = '没有可抢次数';
             return $result;
         }
     }
     // 获取经纪人锁
     if (!Bll_Customer_Parallel::lockBroker($brokerId)) {
         $result['message'] = '锁经纪人异常';
         return $result;
     }
     /*
      * 兼容5.0版本 ,先判断coustomer_locks表中是否有临时性数据,如果有数据则更新,否则新增插入
      */
     $latestTryLock = Model_Mobile_CustomerLock::getV2BrokerCustomerLatestTempLock($brokerId, $customerId, $relation->uploadDt);
     if (empty($latestTryLock)) {
         // 插入永久锁定
         $insertCusomerLockData = array('uploadDt' => $relation->uploadDt, 'relationId' => $relation->brokerUserRelationId, 'brokerId' => $brokerId, 'userDeviceId' => $customerId, 'status' => 2, 'foreverLockTime' => date("Y-m-d H:i:s"), 'createTime' => date("Y-m-d H:i:s"), 'updateTime' => date("Y-m-d H:i:s"));
         Bll_CustomerRush_Lock::insertCustomerLock($insertCusomerLockData);
     } else {
         // 更新customer_locks表
         $latestTryLock->relationId = $relation->brokerUserRelationId;
         $latestTryLock->status = 2;
         $latestTryLock->foreverLockTime = date("Y-m-d H:i:s");
         $latestTryLock->updateTime = date("Y-m-d H:i:s");
         $latestTryLock->save();
     }
     if (!$this->_isFree()) {
         // 消耗劵
         $this->_updateBrokerCoupon($coupon);
     }
     // 更新永久锁定,加1
     Bll_CustomerRush_Lock::incrForeverLockCount($brokerId, 1);
     // 更新临时表的关系
     $relation->status = Model_Mobile_BrokerUserRelationSub::STATUS_FOREVER_LOCKED;
     $relation->updateTime = date("Y-m-d H:i:s");
     $relation->tempLockTime = '0000-00-00 00:00:00';
     $relation->tempLockExpireTime = '0000-00-00 00:00:00';
     $relation->save();
     // 释放经纪人锁
     Bll_Customer_Parallel::unlockBroker($brokerId);
     $result['status'] = 'ok';
     $result['message'] = '成功';
     return $result;
 }
Example #4
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;
 }
Example #5
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']));
 }
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $sinceId = isset($this->_params['sinceId']) ? $this->_params['sinceId'] : 0;
     $per = isset($this->_params['per']) ? $this->_params['per'] : 20;
     // 判断经纪人是否存在
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$broker) {
         throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId);
     }
     // 获取经纪人已抢客户列表
     $locks = Model_Mobile_CustomerLock::getV2RushedCustomerLocks($brokerId, $sinceId, $per + 1);
     // 判断是否存在下一页数据
     $hasNextPage = false;
     if (count($locks) > $per) {
         $hasNextPage = true;
         array_pop($locks);
     }
     if (empty($locks)) {
         return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('customers' => array(), 'hasNextPage' => intval($hasNextPage)));
     }
     // 获取关联的客户关系数据
     $relationIds = array();
     foreach ($locks as $lock) {
         /* @var Model_Mobile_CustomerLock $lock */
         $month = date('Ym', strtotime($lock->uploadDt));
         $relationIds[$month][] = $lock->relationId;
     }
     $relations = Model_Mobile_BrokerUserRelation::getV2CustomersWithIdsInMultiMonths($relationIds);
     if (empty($relations)) {
         return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('customers' => array(), 'hasNextPage' => intval($hasNextPage)));
     }
     $keyedRelations = array();
     foreach ($relations as $relation) {
         /* @var Model_Mobile_BrokerUserRelation $relation */
         $key = $relation->uploadDt . '_' . $relation->id;
         $keyedRelations[$key] = $relation;
     }
     $customers = array();
     $chatIdCustomerIdMap = array();
     $chatIdKeyMap = array();
     foreach ($locks as $lock) {
         $key = $lock->uploadDt . '_' . $lock->relationId;
         if (!isset($keyedRelations[$key])) {
             continue;
         }
         /* @var Model_Mobile_BrokerUserRelation $relation */
         $relation = $keyedRelations[$key];
         $customerId = $relation->userDeviceId;
         $customer = array();
         $customer['id'] = $lock->id;
         $customer['pushDate'] = $relation->uploadDt;
         $customer['customerId'] = $customerId;
         $customer['customerName'] = Bll_Mobile_UserList::getUserName('', '', $relation->userDeviceId);
         $customer['customerAvatarUrl'] = $relation->userPhoto;
         $customer['app'] = $relation->appName;
         $customer['udid2'] = $relation->userDeviceId2;
         $customer['guid'] = $relation->guid;
         $customer['macId'] = $relation->macId;
         $customer['recommendType'] = $relation->recommendType;
         $customer['recommendColor'] = Bll_CustomerRush_Basic::getRecommendColor($customer['recommendType']);
         $customer['recommendReason'] = $relation->recommendReason;
         $customer['preferPrice'] = $relation->pricePreference;
         $customer['preferHouseType'] = $relation->houseTypePreference;
         $customer['preferCommunities'] = explode(',', $relation->commPreferenceDesc);
         $customer['viewPropCount'] = $relation->viewPropNum;
         $customer['channelType'] = $relation->channelType;
         $customer['channelDesc'] = $relation->channelDesc;
         $customer['rentType'] = $relation->rentType;
         $customer['block'] = $relation->bankuaiPreferenceDesc;
         switch ($relation->rentType) {
             case 1:
                 $rentDesc = '整租';
                 break;
             case 2:
                 $rentDesc = '合租';
                 break;
             default:
                 $rentDesc = '';
         }
         $customer['rentDesc'] = $rentDesc;
         switch ($relation->channelType) {
             case 1:
             case 4:
             case 6:
                 $channelType = '2';
                 //售
                 break;
             case 2:
             case 3:
             case 5:
                 $channelType = '1';
                 //租
                 break;
             case 0:
                 $channelType = '';
                 break;
         }
         $customer['isRentOrSale'] = $channelType;
         $customers[$key] = $customer;
         // 记录有效的微聊号
         $chatId = $relation->chatId;
         if ($chatId >= Const_Chat::MIN_CHAT_ID) {
             $chatIdCustomerIdMap[$chatId] = $customerId;
             $chatIdKeyMap[$chatId] = $key;
         }
     }
     // 微聊信息
     if ($chatIdKeyMap) {
         $chatInfos = Bll_Mobile_ChatInfoBll::getInstance()->getMultiChatInfoWithChatIds(array_keys($chatIdKeyMap));
         foreach ($chatInfos as $chatInfo) {
             $chatId = $chatInfo['user_id'];
             $key = $chatIdKeyMap[$chatId];
             $customerId = $chatIdCustomerIdMap[$chatId];
             // customerName
             $customers[$key]['customerName'] = Bll_Mobile_UserList::getUserName(isset($chatInfo['nick_name']) ? $chatInfo['nick_name'] : '', isset($chatInfo['phone']) ? $chatInfo['phone'] : '', $customerId);
             // customerAvatarUrl
             if ($chatInfo['icon']) {
                 $customers[$key]['customerAvatarUrl'] = $chatInfo['icon'];
             }
         }
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('customers' => array_values($customers), 'hasNextPage' => intval($hasNextPage)));
 }
 /**
  * 抢客户第二版 • 获取经纪人和客户最新永久锁定关联的关系记录
  *
  * @param $brokerId
  * @param $deviceId
  *
  * @return Model_Mobile_BrokerUserRelation | null
  */
 public static function getBrokerCustomerLatestForeverLockRelation($brokerId, $deviceId)
 {
     $relation = null;
     $latestTryLock = Model_Mobile_CustomerLock::getBrokerCustomerLatestForeverLock($brokerId, $deviceId);
     if ($latestTryLock) {
         $suffix = date('Ym', strtotime($latestTryLock->uploadDt));
         $relation = self::data_access($suffix)->filter('id', $latestTryLock->relationId)->find_only();
     }
     return $relation;
 }
 public function handle_request_internal()
 {
     $limit = APF::get_instance()->get_config('customer_day_rushed_limit', 'customer');
     $brokerId = $this->_params['brokerId'];
     // 判断经纪人是否存在
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$broker) {
         throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId);
     }
     // 获取经纪人待抢客户列表
     $relations = Model_Mobile_BrokerUserRelationSub::getPendingCustomers($brokerId);
     if (empty($relations)) {
         return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('customers' => array()));
     }
     $customers = array();
     $customerIdChatIdMap = array();
     $chatIdCustomerIdMap = array();
     $customerStatus = array();
     $devicePairs = array();
     $customerIds = array();
     foreach ($relations as $relation) {
         $customerId = $relation->userDeviceId;
         $customer = array();
         $customer['id'] = $relation->id;
         $customer['pushDate'] = $relation->uploadDt;
         $customer['customerId'] = $customerId;
         $customer['customerName'] = Bll_Mobile_UserList::getUserName('', '', $relation->userDeviceId);
         $customer['customerAvatarUrl'] = $relation->userPhoto;
         $customer['app'] = $relation->appName;
         $customer['udid2'] = $relation->userDeviceId2;
         $customer['guid'] = $relation->guid;
         $customer['macId'] = $relation->macId;
         $customer['recommendType'] = $relation->recommendType;
         $customer['recommendColor'] = Bll_CustomerRush_Basic::getRecommendColor($customer['recommendType']);
         $customer['recommendReason'] = $relation->recommendReason;
         $customer['preferPrice'] = $relation->pricePreference;
         $customer['preferHouseType'] = $relation->houseTypePreference;
         $customer['preferCommunities'] = explode(',', $relation->commPreferenceDesc);
         $customer['viewPropCount'] = $relation->viewPropNum < 10 ? $relation->viewPropNum + 5 : $relation->viewPropNum;
         $customer['status'] = Const_CustomerRush::V2_RUSHABLE_YES;
         $customer['statusMsg'] = Const_CustomerRush::V2_RUSHABLE_YES_MSG;
         $customer['canRushedTime'] = $limit;
         $customer['chatId'] = $relation->chatId;
         $customer['channelType'] = $relation->channelType;
         $customer['channelDesc'] = $relation->channelDesc;
         $customer['rentType'] = $relation->rentType;
         $customer['block'] = $relation->bankuaiPreferenceDesc;
         switch ($relation->rentType) {
             case 1:
                 $rentDesc = '整租';
                 break;
             case 2:
                 $rentDesc = '合租';
                 break;
             default:
                 $rentDesc = '';
         }
         $customer['rentDesc'] = $rentDesc;
         switch ($relation->channelType) {
             case 1:
                 $channelType = '2';
                 //售
                 break;
             case 2:
                 $channelType = '1';
                 //租
                 break;
             case 3:
                 $channelType = '1';
                 break;
             case 4:
                 $channelType = '2';
                 break;
             case 5:
                 $channelType = '1';
                 break;
             case 6:
                 $channelType = '2';
                 break;
             case 0:
                 $channelType = '';
                 break;
         }
         $customer['isRentOrSale'] = $channelType;
         $customers[$customerId] = $customer;
         // 记录有效的微聊号
         $chatId = $relation->chatId;
         if ($chatId >= Const_Chat::MIN_CHAT_ID) {
             $customerIdChatIdMap[$customerId] = $chatId;
             $chatIdCustomerIdMap[$chatId] = $customerId;
         }
         // 记录设备号和来源 App 类型
         $devicePair = array('app' => $relation->appName);
         if ($relation->appName == 'i-ajk') {
             $devicePair['udid2'] = $relation->userDeviceId2;
         } else {
             // a-ajk
             $devicePair['i'] = $relation->guid;
             $devicePair['macid'] = $relation->macId;
         }
         $devicePairs[] = $devicePair;
         //记录status
         $customerStatus[$customerId] = $relation->status;
         //记录customerIds
         $customerIds[] = $customerId;
     }
     if ($this->isXRayMode()) {
         echo '<pre> CustomerIds: ';
         print_r($customerIds);
         echo '</pre>';
         echo '<pre> Customer status: ';
         print_r($customerStatus);
         echo '</pre>';
     }
     // 通过用户开关判断可抢状态
     $deviceSettings = Bll_Mobile_ChatInfoBll::getInstance()->getDeviceSettings($devicePairs);
     if ($this->isXRayMode()) {
         echo '<pre> API Return Device Settings: ';
         print_r($deviceSettings);
         echo '</pre>';
     }
     foreach ($deviceSettings as $deviceSetting) {
         if ($deviceSetting['app'] == 'a-ajk') {
             $customerId = $deviceSetting['i'] . $deviceSetting['macid'];
         } else {
             // i-ajk
             $customerId = $deviceSetting['udid2'];
         }
         $switch = $deviceSetting['recommend_switch'];
         if ($switch != 0 && !empty($customers[$customerId])) {
             // TODO 移除 Magic Number
             $customers[$customerId]['status'] = Const_CustomerRush::V2_RUSHABLE_NO;
             $customers[$customerId]['statusMsg'] = Const_CustomerRush::V2_RUSHABLE_NO_MSG;
             $customers[$customerId]['statusMemo'] = '用户禁用';
             //移除用户禁用
             unset($customers[$customerId]);
             unset($customerIdChatIdMap[$customerId]);
         }
     }
     //通过一个经纪人当天内只能抢3次判断可抢状态
     $date = date('Ymd');
     $customerRushedCounts = Bll_CustomerRush_Customer::getInstance()->getCustomerRushedCount($customerIds, $date);
     if (!empty($customerRushedCounts)) {
         foreach ($customerRushedCounts as $key => $customerRushedCount) {
             if ($customerRushedCount['num'] >= $limit && !empty($customers[$customerRushedCount['customerId']])) {
                 $customers[$customerRushedCount['customerId']]['status'] = Const_CustomerRush::V2_RUSHABLE_NO;
                 $customers[$customerRushedCount['customerId']]['statusMsg'] = Const_CustomerRush::V2_RUSHABLE_NO_MSG;
                 $customers[$customerRushedCount['customerId']]['canRushedTime'] = 0;
             } elseif ($customerRushedCount['num'] < $limit && !empty($customers[$customerRushedCount['customerId']])) {
                 $customers[$customerRushedCount['customerId']]['canRushedTime'] = $limit - $customerRushedCount['num'];
             }
         }
     }
     //如果该经纪人与该用户已经建立临时关系
     foreach ($customerStatus as $key => $val) {
         if ($val == 1) {
             $customers[$key]['status'] = Const_CustomerRush::V2_RUSHABLE_YES;
             $customers[$key]['statusMsg'] = Const_CustomerRush::V2_RUSHABLE_YES_MSG;
         }
     }
     //通过经纪人已抢列表判断可抢状态
     $customerLocked = Model_Mobile_CustomerLock::getLockedByCustomerId($brokerId, $customerIds);
     if (!empty($customerLocked)) {
         foreach ($customerLocked as $locked) {
             $customerId = $locked['userDeviceId'];
             if ($locked['status'] == 2 && !empty($customers[$customerId])) {
                 $customers[$customerId]['status'] = Const_CustomerRush::V2_RUSHABLE;
                 $customers[$customerId]['statusMsg'] = Const_CustomerRush::V2_RUSHABLE_MSG;
             }
         }
     }
     // 通过微聊好友关系判断可抢状态
     $friendChatIds = Bll_Mobile_ChatInfoBll::getInstance()->getChatFriendsWithBrokerId($brokerId);
     if ($this->isXRayMode()) {
         echo '<pre> API Return Friends: ';
         print_r($friendChatIds);
         echo '</pre>';
     }
     foreach ($customers as &$customer) {
         if (in_array($customer['chatId'], $friendChatIds)) {
             $customer['status'] = Const_CustomerRush::V2_RUSHABLE;
             $customer['statusMsg'] = Const_CustomerRush::V2_RUSHABLE_MSG;
         }
         // 移除不必要的 ChatId
         unset($customer['chatId']);
     }
     // 微聊信息
     if ($customerIdChatIdMap) {
         $chatInfos = Bll_Mobile_ChatInfoBll::getInstance()->getMultiChatInfoWithChatIds($customerIdChatIdMap);
         if ($this->isXRayMode()) {
             echo '<pre> CustomerId ChatId Map: ';
             print_r($customerIdChatIdMap);
             echo '</pre>';
             echo '<pre> ChatId CustomerId Map: ';
             print_r($chatIdCustomerIdMap);
             echo '</pre>';
             echo '<pre> API Return Chat Infos: ';
             print_r($chatInfos);
             echo '</pre>';
         }
         foreach ($chatInfos as $chatInfo) {
             $chatId = $chatInfo['user_id'];
             $customerId = $chatIdCustomerIdMap[$chatId];
             // customerName
             $customers[$customerId]['customerName'] = Bll_Mobile_UserList::getUserName(isset($chatInfo['nick_name']) ? $chatInfo['nick_name'] : '', isset($chatInfo['phone']) ? $chatInfo['phone'] : '', $customerId);
             // customerAvatarUrl
             if ($chatInfo['icon']) {
                 $customers[$customerId]['customerAvatarUrl'] = $chatInfo['icon'];
             }
         }
     }
     // 重置新推客户数
     Bll_CustomerRush_Basic::resetBrokerLatestPushCount($brokerId);
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('customers' => array_values($customers)));
 }
 private function isCustomerRush($brokerId, $userId)
 {
     $rushInfo = Model_Mobile_CustomerLock::data_access()->filter('brokerId', $brokerId)->filter('userDeviceId', $userId)->filter('status', 2)->get_row();
     if (!empty($rushInfo)) {
         return true;
     }
     return false;
 }
Example #10
0
 public static function insertCustomerLock($data)
 {
     $model = new Model_Mobile_CustomerLock();
     return $model->insertData($data);
 }