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']; // 判断经纪人是否存在 $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (!$broker) { throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId); } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('count' => Bll_CustomerRush_Basic::getBrokerLatestPushCountValue($brokerId))); }
public function before() { $isDebugMode = false; if (isset($_GET['apiDebug']) && $_GET['apiDebug'] == 1) { $isDebugMode = true; } if (!$isDebugMode && Bll_CustomerRush_Basic::isMaintenanceMode()) { $data = array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => Const_APIStatus::E_CUSTOMER_RUSH_MAINTENANCE, 'message' => '抢客户功能维护中,预计花费1小时,请耐心等待。'); header('Content-Type: application/json; charset=utf-8'); echo json_encode($data); return self::STEP_EXIT; } return self::STEP_CONTINUE; }
public function handle_request_internal() { $brokerId = $this->_params['broker_id']; $result = array('status' => 'ok', 'data' => array('count' => Bll_CustomerRush_Basic::getBrokerLatestPushCountValue($brokerId))); return $result; }
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))); }
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))); }
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))); }