public function handle_request_internal() { $this->debug = $this->isXRayMode(); $brokerId = $this->getParameter('broker_id'); $sinceId = (int) $this->getParameter('since_id'); $pageNum = (int) $this->getParameter('page_num'); $pageNum < 1 && ($pageNum = 1); // 获取客户列表 $customers = Bll_Mobile_UserList::getCustomerList($brokerId, $sinceId, $sinceId ? '<' : '>', 1000); if ($this->debug) { printf('获取客户列表:' . PHP_EOL); print_r($customers); } // 拼接额外信息 $customers = $this->buildCustomersWithExtra($brokerId, $customers); $listAll = $this->prepareOutPut($customers); // 重置新推客户数 Bll_CustomerRush_Basic::resetBrokerLatestPushCount($brokerId); // 按照分页截取返回 $pageTotal = ceil(count($listAll) / $this->num); $offset = ($pageNum - 1) * $this->num; $list = array_slice($listAll, $offset, $this->num); // 获取经纪人今日有效锁定客户数(未过期临时锁定 + 永久锁定) $remainRushCount = Const_CustomerRush::BROKER_MAX_RUSH_COUNT; $rushCount = Model_Mobile_BrokerUserRelation::getBrokerTodayLockTimes($brokerId); if ($rushCount >= Const_CustomerRush::BROKER_MAX_RUSH_COUNT) { $remainRushCount = 0; } else { $remainRushCount -= $rushCount; } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('count' => count($listAll), 'broker_rush_count' => $remainRushCount, 'is_next_page' => $pageTotal > $pageNum ? 1 : 0, 'list' => $list)); }
public function handle_request_internal() { $brokerId = $this->_params['brokerId']; $customerId = $this->_params['customerId']; $pushDate = $this->_params['pushDate']; // 判断经纪人是否存在 $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (!$broker) { throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId); } // 判断经纪人和客户之间关系是否存在(给定日期) $relation = Model_Mobile_BrokerUserRelation::getBrokerCustomerRelationWithDate($brokerId, $customerId, $pushDate); if (!$relation) { throw new Exception_CustomerRush_RelationNotFound("BrokerId: {$brokerId}; CustomerId: {$customerId}; Date: {$pushDate}"); } // 判断经纪人和客户是否已经有效锁定(未过期临时锁定 或 永久锁定) $status = intval($relation->isLocked()); if ($status) { if ($relation->isTempLocked()) { $statusMsg = '临时锁定'; } else { $statusMsg = '永久锁定'; } } else { $statusMsg = '客户失效了 重新抢吧'; } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('status' => $status, 'statusMsg' => $statusMsg)); }
public function handle_request_internal() { $brokerId = $this->_params['brokerId']; $customerId = $this->_params['customerId']; // 判断经纪人是否存在 $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (!$broker) { throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId); } // 获取客户最新信息 $relation = Model_Mobile_BrokerUserRelation::getBrokerCustomerMonthLatestRelation($brokerId, $customerId); if (!$relation) { $relation = Model_Mobile_BrokerUserRelation::getBrokerCustomerLatestTryLockRelation($brokerId, $customerId); if (!$relation) { throw new Exception_CustomerRush_RelationNotFound("BrokerId: {$brokerId}; CustomerId: {$customerId};"); } } switch ($relation->rentType) { case 1: $rentDesc = '整租'; break; case 2: $rentDesc = '合租'; break; default: $rentDesc = ''; } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('preferPrice' => $relation->pricePreference, 'preferHouseType' => $relation->houseTypePreference, 'preferCommunities' => explode(',', $relation->commPreferenceDesc), 'channelType' => $relation->channelType, 'channelDesc' => $relation->channelDesc, 'rentType' => $relation->rentType, 'rentDesc' => $rentDesc)); }
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' => '抢成功')); }
/** * @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; }
public function handle_request() { if ($this->request->is_post_method()) { $brokerId = $this->request->get_parameter('brokerId'); $deviceId = $this->request->get_parameter('deviceId'); //删除da_mobile_broker_find_user_upload表跟制定broker_id相关的数据 $brokerFindUserData = Model_Broker_BrokerFindUser::data_access()->filter('brokerId', $brokerId)->find(); foreach ($brokerFindUserData as $val) { $val->delete(); } //删除da_mobile_broker_find_user_upload表跟制定device_id相关的数据 $brokerFindUserData = Model_Broker_BrokerFindUser::data_access()->filter('userId', $deviceId)->find(); foreach ($brokerFindUserData as $val) { $val->delete(); } //删除broker_user_relation_XX表跟制定brokerId相关的数据 $brokerUserRelationData = Model_Mobile_BrokerUserRelation::data_access()->filter('brokerId', $brokerId)->find(); foreach ($brokerUserRelationData as $val) { $val->delete(); } //删除broker_user_relation_XX表跟制定user_device_id相关的数据 $brokerUserRelationData = Model_Mobile_BrokerUserRelation::data_access()->filter('userDeviceId', $deviceId)->find(); foreach ($brokerUserRelationData as $val) { $val->delete(); } //删除broker_bind表跟制定brokerId相关的数据 $brokerBindData = Model_Mobile_BrokerBind::data_access()->filter('brokerId', $brokerId)->find(); foreach ($brokerBindData as $val) { $val->delete(); } //删除user_bind表跟制定device_id相关的数据 $userBindData = Model_Mobile_UserBind::data_access()->filter('deviceId', $deviceId)->find(); foreach ($userBindData as $val) { $val->delete(); } $this->setAttribute('out', 1); } return 'Test_TruncateDataForCustomerRush'; }
public function handle_request_internal() { $brokerId = $this->_params['brokerId']; // 判断经纪人是否存在 $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (!$broker) { throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId); } // 获取经纪人今日有效锁定客户数(未过期临时锁定 + 永久锁定) $remainRushCount = Const_CustomerRush::BROKER_MAX_RUSH_COUNT; $rushCount = Model_Mobile_BrokerUserRelation::getBrokerTodayLockTimes($brokerId); if ($rushCount >= Const_CustomerRush::BROKER_MAX_RUSH_COUNT) { $remainRushCount = 0; } else { $remainRushCount -= $rushCount; } // 获取经纪人今日有效临时锁定客户数 $tempLockCountValue = Model_Mobile_BrokerUserRelation::getBrokerTodayTempLockTimes($brokerId); // 获取经纪人永久锁定客户数 $foreverLockCount = Bll_CustomerRush_Lock::getForeverLockCount($brokerId); $foreverLockCountValue = $foreverLockCount->count; $totalLockCountValue = $foreverLockCountValue + $tempLockCountValue; return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('remainRushCount' => $remainRushCount, 'totalLockCount' => $totalLockCountValue, 'tempLockCount' => $tempLockCountValue, 'foreverLockCount' => $foreverLockCountValue)); }
/** * 更新经纪人和用户的关系为永久锁定,同时更新经纪人和用户的永久锁定次数做 +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; }
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 string $deviceId * @param int $brokerId * @param string $date * @param string $splitSuffix * @return array */ public static function getCustomerRelation($deviceId, $brokerId, $date, $splitSuffix = '') { if (empty($splitSuffix)) { $splitSuffix = date('Ym'); } try { return Model_Mobile_BrokerUserRelation::data_access($splitSuffix)->filter('userDeviceId', $deviceId)->filter('brokerId', $brokerId)->filter('uploadDt', $date)->get_row(); } catch (Exception $e) { return array(); } }
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); } // 获取经纪人待抢客户列表 $relations = Model_Mobile_BrokerUserRelation::getPendingCustomers($brokerId, $sinceId, $per + 1); // 判断是否存在下一页数据 $hasNextPage = false; if (count($relations) > $per) { $hasNextPage = true; array_pop($relations); } $customers = array(); $customerIdChatIdMap = array(); $chatIdCustomerIdMap = array(); $devicePairs = array(); foreach ($relations as $relation) { /* @var Model_Mobile_BrokerUserRelation $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; $customer['status'] = Const_CustomerRush::RUSHABLE_YES; $customer['statusMsg'] = Const_CustomerRush::RUSHABLE_YES_MSG; $customer['chatId'] = $relation->chatId; $customer['channelType'] = $relation->channelType; $customer['channelDesc'] = $relation->channelDesc; $customer['rentType'] = $relation->rentType; switch ($relation->rentType) { case 1: $rentDesc = '整租'; break; case 2: $rentDesc = '合租'; break; default: $rentDesc = ''; } $customer['rentDesc'] = $rentDesc; $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; } // 微聊信息 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']; } } } // 通过用户开关判断可抢状态 $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) { // TODO 移除 Magic Number $customers[$customerId]['status'] = Const_CustomerRush::RUSHABLE_NO; $customers[$customerId]['statusMsg'] = Const_CustomerRush::RUSHABLE_NO_MSG; $customers[$customerId]['statusMemo'] = '用户禁用'; } } // 通过微聊好友关系判断可抢状态 $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::RUSHABLE_NO; $customer['statusMsg'] = Const_CustomerRush::RUSHABLE_NO_MSG; $customer['statusMemo'] = '微聊好友'; } // 移除不必要的 ChatId unset($customer['chatId']); } // 通过用户锁定总数判断可抢状态 if (!empty($customers)) { $lockTimes = Model_Mobile_BrokerUserRelation::getMultiCustomerTodayLockTimes(array_keys($customers)); if ($this->isXRayMode()) { echo '<pre> Today Lock Times: '; print_r($lockTimes); echo '</pre>'; } foreach ($lockTimes as $customerId => $lockTime) { if ($lockTime >= Const_CustomerRush::CUSTOMER_MAX_RUSHED_COUNT) { $customers[$customerId]['status'] = Const_CustomerRush::RUSHABLE_NO; $customers[$customerId]['statusMsg'] = Const_CustomerRush::RUSHABLE_NO_MSG; $customers[$customerId]['statusMemo'] = '今日已被抢' . Const_CustomerRush::CUSTOMER_MAX_RUSHED_COUNT . '次'; } } } // 重置新推客户数 Bll_CustomerRush_Basic::resetBrokerLatestPushCount($brokerId); return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('customers' => array_values($customers), 'hasNextPage' => intval($hasNextPage))); }
/** * 获取经纪人和客户今日推送的关系 * * @param $deviceId * @param $brokerId * @return Model_Mobile_BrokerUserRelation|null */ public function getUserBrokerTodayRelation($deviceId, $brokerId) { return Model_Mobile_BrokerUserRelation::data_access(date('Ym'))->filter('userDeviceId', $deviceId)->filter('brokerId', $brokerId)->filter('uploadDt', date('Y-m-d'))->sort('id')->find_only(); }
/** * 获取客户列表 * @param $brokerId * @param int $beginId * @param $option * @param int $limit * @return array */ public static function getCustomerList($brokerId, $beginId = 0, $option = '>', $limit = 20) { return Model_Mobile_BrokerUserRelation::getCustomerList($brokerId, $beginId, $option, $limit); }
private function getData() { $wheres['bi_id'] = array('op' => '>=', 'value' => $this->cursor['before_start_id']); return Model_Mobile_BrokerUserRelation::getGroupBrokerIdData($wheres, $this->limit); }
private function pushLastMsgNum($brokerId) { $thisPushLastMsgNum = Model_Mobile_CustomerLatestPushCount::data_access()->filter('brokerId', $brokerId)->filter('pushDate', date('Y-m-d', time()))->find_only(); if (!empty($thisPushLastMsgNum)) { $thisPushLastMsgNum->incrPushedCount(); } else { $insertData['brokerId'] = $brokerId; $insertData['pushDate'] = date('Y-m-d', time()); $insertData['count'] = 1; try { $MODEL = Model_Mobile_CustomerLatestPushCount::create($insertData); $MODEL::$enable_cache = false; $MODEL->save(); } catch (Exception $e) { Model_Mobile_BrokerUserRelation::data_access()->roll_back(); } } }
/** * 获取经纪人和用户的关系 * * @param $deviceId * @param $brokerId * @return array */ public static function getBrokerUserRelationInfo($deviceId, $brokerId) { return Model_Mobile_BrokerUserRelation::getCustomerRelation($deviceId, $brokerId, date('Y-m-d')); }
public static function isCustomerCanBeRushed($customerId) { $customerTodayLockTimes = Model_Mobile_BrokerUserRelation::getCustomerTodayLockTimes($customerId); return $customerTodayLockTimes < Const_CustomerRush::CUSTOMER_MAX_RUSHED_COUNT; }