コード例 #1
0
 public function handle_request()
 {
     //删除
     $result = Model_Mobile_BrokerUserRelationSub::getCustomerExpireDelete($this->expire, $this->limit);
     if (empty($result)) {
         echo date("Y-m-d H:i:s") . "没有处理数据了.\n";
         $this->setShStopFlag();
     }
     $this->setLog(date('Y-m-d H:i:s') . ' 过期信息删除' . json_decode($result));
 }
コード例 #2
0
 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);
     }
     $customer = Model_Mobile_BrokerUserRelationSub::getStatusByCustomerIdBrokerId($brokerId, $customerId);
     if (empty($customer)) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => 'customerId不存在');
     }
     $rs = Model_Mobile_BrokerUserRelationSub::updateStatus($customer['brokerId'], $customer['userDeviceId']);
     if ($rs) {
         $date = date('Ymd');
         Model_Mobile_CustomerUserRushedCount::updateCustomerNum($customer['userDeviceId'], $date);
         return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('message' => '释放成功'));
     } elseif ($rs == 0) {
         return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('message' => '已经释放'));
     } else {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '释放失败');
     }
 }
コード例 #3
0
 public function handle_request()
 {
     // 获取
     $now = date('Y-m-d H:i:s');
     if ($this->time) {
         $tmpTime = $this->time;
     } else {
         $tmpTime = date('Y-m-d H:i:s', strtotime($now) - 3600);
     }
     //        $id = $this->getLastJobId();
     $customers = Model_Mobile_BrokerUserRelationSub::getBrokerUserRelationSubList($tmpTime, $now, $this->per);
     if (empty($customers)) {
         $this->setMyFlag(0, 'over');
         echo date("Y-m-d H:i:s") . '没有处理数据了' . "\n";
         exit;
     }
     // 筛选
     $ids = array();
     foreach ($customers as $val) {
         if ($val['status'] == 1) {
             $ids[] = array('id' => $val['id'], 'customerId' => $val['userDeviceId'], 'tempLockExpireTime' => $val['tempLockExpireTime']);
         }
     }
     // update
     if ($ids) {
         foreach ($ids as $key => $val) {
             Model_Mobile_BrokerUserRelationSub::updateBrokerUserRelationSub($val['id']);
             //update customer_user_rushed_count_201502分表
             $date = date('Ymd', strtotime($val['tempLockExpireTime']));
             $customerId = $val['customerId'];
             Model_Mobile_CustomerUserRushedCount::updateCustomerNum($customerId, $date);
             $this->setMyFlag($val['id']);
         }
         $this->log(sprintf("[%s] - Update (%d) rows - [%s]", date('Y-m-d H:i:s'), $this->per, json_encode($ids)));
     }
 }
コード例 #4
0
 /**
  * 数据push到broker_user_relation_temp临时表
  * @param $insertData
  */
 private function pushBrokerUserRelationToSub($insertData)
 {
     $result = Model_Mobile_BrokerUserRelationSub::checkIsExist($insertData['brokerId'], $insertData['userDeviceId']);
     if (!empty($result)) {
         $keyData = array('id' => $result['id']);
         unset($insertData['splitSuffix']);
         unset($insertData['cache_expire']);
         unset($insertData['isLoaded']);
         unset($insertData['status']);
         unset($insertData['biId']);
         unset($insertData['uploadTime']);
         //更新已经存在的经纪人信息
         Model_Mobile_BrokerUserRelationSub::getInstance()->updateData($keyData, $insertData);
     } else {
         unset($insertData['biId']);
         unset($insertData['uploadTime']);
         $MODEL = Model_Mobile_BrokerUserRelationSub::create($insertData);
         $MODEL::$enable_cache = false;
         $MODEL->save();
     }
 }
コード例 #5
0
 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)));
 }
コード例 #6
0
 public function updateBrokerUserRelationSub($keyData, $data)
 {
     return Model_Mobile_BrokerUserRelationSub::getInstance()->updateData($keyData, $data);
 }
コード例 #7
0
 /**
  * 获取要释放的数据
  * @param $tmpTime
  * @param $now
  * @param int $limit
  * @return array
  * @throws Exception
  */
 public static function getBrokerUserRelationSubList($tmpTime, $now, $limit = 10)
 {
     if (empty($now)) {
         return array();
     }
     $customers = Model_Mobile_BrokerUserRelationSub::data_access()->load_field('id')->load_field('userDeviceId')->load_field('tempLockExpireTime')->load_field('status')->filter('status', 1)->filter_by_op('tempLockExpireTime', '>', $tmpTime)->filter_by_op('tempLockExpireTime', '<', $now)->limit($limit)->find_all();
     return $customers;
 }