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; } // 判断经纪人和客户之间关系是否存在(三日内) $date = date('Y-m-d', strtotime("-2 day")); $relation = Bll_CustomerRush_BrokerUserRelation::getInstance()->getLastRalationData($brokerId, $customerId, $date); if (empty($relation)) { $result['message'] = '不存在数据关系'; return $result; } // 检测用户是否屏蔽 if (!Bll_CustomerRush_BrokerUserRelation::getInstance()->isCustomerAllowRush($relation)) { $result['message'] = '用户已屏蔽'; return $result; } // 判断是否已经抢过(永久锁定) $lock = Bll_CustomerRush_Lock::getDataByBrokerIdAndCustomerId($brokerId, $customerId); if (!empty($lock)) { $result['message'] = '已经被抢过了'; return $result; } // 判断是否存在临时关系 if ($relation->status != Model_Mobile_BrokerUserRelationSub::STATUS_TEMP_LOCKED) { // 不存在临时关系,建立临时关系 // 判断是否已经满3次 $tmpDate = date("Ymd"); $rushedCountData = Bll_CustomerRush_Customer::getInstance()->getCustomerRushedCount($customerId, $tmpDate); $limit = APF::get_instance()->get_config('customer_day_rushed_limit', 'customer'); if (!empty($rushedCountData) && $rushedCountData[0]['num'] >= $limit) { $result['message'] = '已经被抢完了'; return $result; } // 获取经纪人锁 if (!Bll_Customer_Parallel::lockBroker($brokerId)) { $result['message'] = '锁经纪人异常'; return $result; } // 获取客户锁 if (!Bll_Customer_Parallel::lockUser($customerId)) { Bll_Customer_Parallel::unlockBroker($brokerId); $result['message'] = '锁客户异常'; return $result; } // 更新关系 $updateRelationSub = array('status' => Model_Mobile_BrokerUserRelationSub::STATUS_TEMP_LOCKED, 'tempLockTime' => date("Y-m-d H:i:s"), 'tempLockExpireTime' => date('Y-m-d H:i:s', strtotime('+' . Model_Mobile_BrokerUserRelationSub::TEMP_LOCK_PERIOD . ' mins')), 'updateTime' => date("Y-m-d H:i:s")); Bll_CustomerRush_BrokerUserRelation::getInstance()->updateBrokerUserRelationSub(array('id' => $relation->id), $updateRelationSub); // 每日被抢加+1 Bll_CustomerRush_Customer::getInstance()->addCustomerRushedCount($customerId); // 释放客户锁 Bll_Customer_Parallel::unlockUser($customerId); // 释放经纪人锁 Bll_Customer_Parallel::unlockBroker($brokerId); } // 创建支付中心账户id Bll_Customerrush_Payment_User::getInstance()->getUserAccountId($brokerId, $broker['userId']); // 查询有无未激活的活动劵 $activeCoupon = Bll_CustomerRush_Coupon::getInstance()->getActiveCouponByBrokerId($brokerId, Model_Mobile_CustomerBrokerCouponActivity::STATUS_CREATE); if (!empty($activeCoupon) && $this->_isActivity()) { // 获取劵信息 $coupon = Bll_CustomerRush_Coupon::getInstance()->getCouponById($activeCoupon['couponId']); $result['data']['unActiveCouponNum'] = !empty($coupon) ? $coupon[0]['totalNum'] : 0; } else { $result['data']['unActiveCouponNum'] = 0; } // 查询可抢次数 $rushTimedata = Bll_CustomerRush_Coupon::getInstance()->getRushTime($brokerId, Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE); if ($rushTimedata['status'] == 'ok') { $result['data']['canRushTime'] = $rushTimedata['amount']; } else { $result['data']['canRushTime'] = 0; } $result['data']['useCouponNum'] = 1; $result['data']['relation'] = 1; $baseActiveUrl = APF::get_instance()->get_config('activity_coupon_active_url', 'customer'); $result['data']['activeUrl'] = $baseActiveUrl . "?brokerid=" . $brokerId; $result['status'] = 'ok'; $result['message'] = '建立临时性关系'; $result['data']['customerId'] = $customerId; // 收费开关配置 if ($this->_isFree()) { $result['data']['status'] = 1; // 免费 } else { if ($result['data']['useCouponNum'] <= $result['data']['canRushTime']) { $result['data']['status'] = 2; // 有劵,去消耗劵 } else { $result['data']['status'] = 3; // 劵剩余不足 } } return $result; }
/** * 添加代理新盘 * @param $brokerId * @param $newCommunityData * @return bool */ protected function doNewCommunity($brokerId, $newCommunityData) { $newCommunityList = Model_Mobile_CustomerNewPropRange::getBrokerIdRange($brokerId); $newCommunity = array(); if (!empty($newCommunityList)) { foreach ($newCommunityList as $key => $val) { $newCommunity[$val['loupanId']] = $val; } } $insertData = array(); if (!empty($newCommunityData) && is_array($newCommunityData)) { if (count($newCommunityData) > 10) { array_splice($newCommunityData, 10); } foreach ($newCommunityData as $key => $val) { if ($newCommunity[$val['loupanId']]) { //unset已经存在的,剩余数据删除 unset($newCommunity[$val['loupanId']]); } else { //插入数据 $insertData[] = $val; } } } if (!empty($newCommunity)) { $deleteDataId = array(); foreach ($newCommunity as $key => $val) { $deleteDataId[] = $val['id']; } } if (!empty($deleteDataId)) { Model_Mobile_CustomerNewPropRange::delRangeByBrokerId($brokerId, $deleteDataId); } $flag = true; foreach ($insertData as $val) { $data = array(); $data['loupanId'] = $val['loupanId']; $data['loupanName'] = $val['loupanName']; $data['cityId'] = $this->cityId; $data['brokerId'] = $brokerId; $data['createTime'] = time(); $rs = Bll_CustomerRush_Customer::getInstance()->insertCustomerNewCommunityRange($data); if (!$rs) { $flag = false; } } return $flag; }
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))); }