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']; // 升级提示 $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' => '抢成功')); }
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)); }
public static function isBrokerCanRush($brokerId) { $brokerTodayLockTimes = Model_Mobile_BrokerUserRelation::getBrokerTodayLockTimes($brokerId); return $brokerTodayLockTimes < Const_CustomerRush::BROKER_MAX_RUSH_COUNT; }