public function handle_request_internal() { /** * 00:00 * 获取前一天20:00 以后 * 10:00 * 获取10:00 以后 * 15:00 * 获取15:00 以后 * 20:00 * 获取20:00 以后 * */ // 获取参数; $commId = $this->_params['commId']; // 根据ID获取小区 $community = Bll_Community_APIComm::getInstance()->getInfoByIdMapping($commId, 2); if (!$community || !$community['sosolat'] || !$community['sosolng']) { throw new Exception('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS); } $data = array(); if (Bll_Broker_CommunitySign::isTopSignerActivityOngoing()) { $hour = intval(date('H')); if ($hour >= 0 && $hour < 10) { $theSignRange = array(date('Y-m-d 20:00:00', strtotime('-1 day')), date('Y-m-d 23:59:59', strtotime('-1 day'))); } elseif ($hour >= 10 && $hour < 15) { $theSignRange = array(date('Y-m-d 10:00:00'), date('Y-m-d 14:59:59')); } elseif ($hour >= 15 && $hour < 20) { $theSignRange = array(date('Y-m-d 15:00:00'), date('Y-m-d 19:59:59')); } else { $theSignRange = array(date('Y-m-d 20:00:00'), date('Y-m-d 23:59:59')); } $brokerInfos = Bll_Commsign::getFirstThr($commId, $theSignRange[0]); //var_dump($data);exit; $data = array(); if (!empty($brokerInfos)) { foreach ($brokerInfos as $k => $v) { $brokerTmp = Bll_Commsign::getBrokerInfo($v['brokerId']); if (!$brokerTmp) { $broker = Model_Broker_AjkBrokerExtend::data_access()->filter('brokerId', $v['brokerId'])->find_only(); $broker_photo = Util_ImageUtils::get_broker_photo_url($broker['userPhoto'], '200x200'); $brokerTmp = array('brokerId' => $broker['brokerId'], 'username' => $broker['trueName'], 'userPhoto' => $broker_photo, 'cityId' => $broker['cityId']); Bll_Commsign::redisBrokerInfo($v['brokerId'], $brokerTmp); } if (empty($brokerTmp['userPhoto'])) { $brokerTmp['userPhoto'] = PageHelper::pure_static_url('/img/bknoimg.gif'); } $dataTmp = array('brokerId' => $brokerTmp['brokerId'], 'brokerTrueName' => $brokerTmp['username'], 'brokerPhoto' => $brokerTmp['userPhoto']); $data[] = $dataTmp; } } } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data); }
public function handle_request_internal() { /** * 签到小区详情 * * - 验证参数 * * * - 获取经纪人 * * - 获取小区(AjkCommunity) * - * * - 获取小区签到人数 * * - 判断经纪人是否可签到(经纪人是否已签到、当前是否在签到时间段) * - 校验小区坐标和lat、lng的距离5公里,超出不可签到(如小区无坐标,不可签到) * * - 计算距离下一时间点的签到倒计时(单位:s) * * - 获取小区各个时间段签到前3名 * * - 返回数据 */ // 获取参数 $brokerId = $this->_params['brokerId']; $commId = $this->_params['commId']; $lat = $this->_params['lat']; $lng = $this->_params['lng']; // 根据ID获取经纪人 $broker = Bll_Commsign::getBrokerInfo($brokerId); if (!$broker) { $broker = Model_Broker_AjkBrokerExtend::data_access()->filter('brokerId', $brokerId)->find_only(); if (!$broker) { throw new Exception('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS); } $broker_photo = Util_ImageUtils::get_broker_photo_url($broker['userPhoto'], '200x200'); $brokerInfo = array('brokerId' => $broker['brokerId'], 'username' => $broker['trueName'], 'userPhoto' => $broker_photo, 'cityId' => $broker['cityId']); Bll_Commsign::redisBrokerInfo($brokerId, $brokerInfo); } // 根据ID获取小区 $community = Bll_Commsign::getCommInfo($commId); if (empty($community)) { $community = Bll_Community_APIComm::getInstance()->getInfoByIdMapping($commId, 2); $commInfo = array(); $commInfo['commId'] = $community['commId']; $commInfo['commName'] = $community['commName']; $commInfo['sosolng'] = $community['sosolng']; $commInfo['sosolat'] = $community['sosolat']; Bll_Commsign::setCommInfo($commId, $commInfo); } if (!$community || !$community['sosolat'] || !$community['sosolng']) { throw new Exception('小区不存在', Const_APIStatus::E_COMMUNITY_NOT_EXISTS); } // 获取小区签到人数 $communitySignCount = Bll_Commsign::getCommCount($commId); // 判断经纪人是否可签到 $signAble = true; $currentSignRange = Bll_Broker_CommunitySign::getCurrentSignRange(); if (!$currentSignRange) { $signAble = false; } else { // 经纪人是否已经签过到 if (Bll_Commsign::isSignedAlready($brokerId, $commId, $currentSignRange[0])) { $signAble = false; } } // 对比小区坐标和参数坐标两点的距离(5km) $distance = Util_Map::distance($lat, $lng, $community['sosolat'], $community['sosolng']); if ($distance > 5000) { $signAble = false; } $data = array(); $data['signAble'] = intval($signAble); $data['signCount'] = $communitySignCount; $data['countDown'] = $signAble ? 0 : Bll_Broker_CommunitySign::nextSignCountDown(); $data['signList'] = array(); // 获取各时间段签到前三名 if (Bll_Broker_CommunitySign::isTopSignerActivityOngoing()) { $data['signList'] = array(array('hour' => '10:00', 'brokers' => array()), array('hour' => '15:00', 'brokers' => array()), array('hour' => '20:00', 'brokers' => array())); foreach ($data['signList'] as &$theSignList) { $theHour = intval($theSignList['hour']); $hour = intval(date('H')); if ($hour >= 0 && $hour < 10) { break; } elseif ($hour >= 10 && $hour < 20) { if ($theHour > $hour) { continue; } } $theSignRange = array(); switch ($theHour) { case 10: $theSignRange = array(date('Y-m-d 10:00:00'), date('Y-m-d 14:59:59')); break; case 15: $theSignRange = array(date('Y-m-d 15:00:00'), date('Y-m-d 19:59:59')); break; case 20: $theSignRange = array(date('Y-m-d 20:00:00'), date('Y-m-d 23:59:59')); break; } $theSignList['brokers'] = Bll_Commsign::getFirstThr($commId, $theSignRange[0]); if (empty($theSignList['brokers'])) { $theSignList['brokers'] = Model_Broker_CommunitySign::data_access(date('Ym', strtotime($currentSignRange[0])))->filter('communityId', $commId)->filter_by_op_multi(array(array('signTime', '>=', $theSignRange[0]), array('signTime', '<=', $theSignRange[1])))->sort('signTime', 'asc')->limit(3)->get_all(); } $tmp = array(); if (!empty($theSignList['brokers'])) { foreach ($theSignList['brokers'] as $k => $v) { $brokerTmp = Bll_Commsign::getBrokerInfo($v['brokerId']); if (!$brokerTmp) { $broker = Model_Broker_AjkBrokerExtend::data_access()->filter('brokerId', $v['brokerId'])->find_only(); $broker_photo = Util_ImageUtils::get_broker_photo_url($broker['userPhoto'], '200x200'); $brokerTmp = array('brokerId' => $broker['brokerId'], 'username' => $broker['trueName'], 'userPhoto' => $broker_photo, 'cityId' => $broker['cityId']); Bll_Commsign::redisBrokerInfo($v['brokerId'], $brokerTmp); } if (empty($brokerTmp['userPhoto'])) { $brokerTmp['userPhoto'] = PageHelper::pure_static_url('/img/bknoimg.gif'); } $dataTmp = array('brokerId' => $brokerTmp['brokerId'], 'brokerTrueName' => $brokerTmp['username'], 'brokerPhoto' => $brokerTmp['userPhoto']); $tmp[] = $dataTmp; } $theSignList['brokers'] = $tmp; } } } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data); }
public function handle_request_internal() { /** * 小区签到逻辑 * * - 验证参数 * * - 获取经纪人 * * - 获取小区(AjkCommunity) * - 校验小区坐标和lat、lng的距离5公里(如小区无坐标,直接拒绝) * * - 添加签到记录 * - 添加签到记录 * - 更新签到按日统计信息(incr) * * - 更新经纪人坐标 * - 添加经纪人坐标日志 * - 更新经纪人坐标 * * - 返回数据 */ $result = array('status' => 'error', 'errcode' => '', 'message' => ''); // 获取参数 $brokerId = $this->_params['brokerId']; $commId = $this->_params['commId']; $lat = $this->_params['lat']; $lng = $this->_params['lng']; if (empty($lat) || empty($lng)) { $result['message'] = '获取定位数据失败,请重新定位'; return $result; } // 根据ID获取经纪人 $broker = Bll_Commsign::getBrokerInfo($brokerId); if (!$broker) { $broker = Model_Broker_AjkBrokerExtend::data_access()->filter('brokerId', $brokerId)->find_only(); if (!$broker) { throw new Exception('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS); } $broker_photo = Util_ImageUtils::get_broker_photo_url($broker['userPhoto'], '200x200'); $brokerInfo = array('brokerId' => $broker['brokerId'], 'username' => $broker['trueName'], 'userPhoto' => $broker_photo, 'cityId' => $broker['cityId']); Bll_Commsign::redisBrokerInfo($brokerId, $brokerInfo); } // 根据ID获取小区 $community = Bll_Commsign::getCommInfo($commId); if (empty($community)) { $community = Bll_Community_APIComm::getInstance()->getInfoByIdMapping($commId, 2); $commInfo = array(); $commInfo['commId'] = $community['commId']; $commInfo['commName'] = $community['commName']; $commInfo['sosolng'] = $community['sosolng']; $commInfo['sosolat'] = $community['sosolat']; Bll_Commsign::setCommInfo($commId, $commInfo); } // 小区不存在或小区经纬租表不存在时,返回小区不存在 if (!$community || !$community['sosolat'] || !$community['sosolng']) { $result['errcode'] = Const_APIStatus::E_COMMUNITY_NOT_EXISTS; $result['message'] = '小区暂未开通签到功能'; return $result; } // 对比小区坐标和参数坐标两点的距离(5km) $distance = Util_Map::distance($lat, $lng, $community['sosolat'], $community['sosolng']); if ($distance > 5000) { $result['errcode'] = Const_APIStatus::E_BROKER_COMMSIGN_FAR_AWAY; $result['message'] = '签到失败!你跑得太远了,请返回重新定位'; return $result; } // 获取当前所处签到时间(10:00 15:00 20:00) $currentSignRange = Bll_Broker_CommunitySign::getCurrentSignRange(); if (!$currentSignRange) { $result['errcode'] = Const_APIStatus::E_BROKER_COMMSIGN_NOT_IN_RANGE; $result['message'] = '不在签到时间范围'; return $result; } // 判断是否已经签到 if (Bll_Commsign::isSigned($brokerId, $commId, $currentSignRange[0])) { $result['errcode'] = Const_APIStatus::E_BROKER_COMMSIGN_ALREADY_SIGNED; $result['message'] = '已经签到!'; return $result; } try { // 新建签到, $sign = array('brokerId' => $brokerId, 'communityId' => $commId, 'lat' => $lat, 'lng' => $lng, 'signTime' => date('Y-m-d H:i:s'), 'currentSignRange' => $currentSignRange[0]); Bll_Commsign::Signed($brokerId, $commId, $currentSignRange[0], $sign); //缓存‘签到信息’到同步数据库的redis中 Bll_RedisToDb::writeBrokerCommunitySign($sign); // 缓存经纪人位置 $locationInfo = array('brokerId' => $brokerId, 'lng' => $lng, 'lat' => $lat, 'updateTime' => date('Y-m-d H:i:s')); Bll_Commsign::setLocationInfo($brokerId, $locationInfo); //缓存‘位置信息’到同步数据库的redis中 Bll_RedisToDb::writeBrokerLocation($locationInfo); //记录每日签到情况 Bll_Commsign::dailySignedRecord($brokerId); // 获取签到排名 $rank = Bll_Commsign::getSignRank($commId, $currentSignRange[0]); //连续签到统计 $SignStatistics = Bll_Commsign::getSignStatistics($brokerId); $sendFlag = false; if ($SignStatistics) { if (date('Y-m-d', strtotime($SignStatistics['updateTime'])) == date('Y-m-d', strtotime('yesterday'))) { $SignStatistics['signCount'] = $SignStatistics['signCount'] + 1; $sendFlag = true; } elseif (date('Y-m-d', strtotime($SignStatistics['updateTime'])) == date('Y-m-d', time())) { } else { $SignStatistics['signCount'] = 1; $sendFlag = true; } if ($SignStatistics['signCount'] > $SignStatistics['maxSignCount']) { $SignStatistics['maxSignCount'] = $SignStatistics['signCount']; } $SignStatistics['updateTime'] = date('Y-m-d H:i:s'); Bll_Commsign::setSignStatistics($brokerId, $SignStatistics); //缓存‘签到统计信息’到同步数据库的redis中 $SignStatistics = array_merge($SignStatistics, array('sendFlag' => $sendFlag)); Bll_RedisToDb::writeCommSignStatistics($SignStatistics); } else { $SignStatistics = array('brokerId' => $brokerId, 'signCount' => 1, 'maxSignCount' => 1, 'createTime' => date('Y-m-d H:i:s')); Bll_Commsign::setSignStatistics($brokerId, $SignStatistics); $sendFlag = true; //缓存‘签到统计信息’到同步数据库的redis中 $SignStatistics = array_merge($SignStatistics, array('sendFlag' => $sendFlag)); Bll_RedisToDb::writeCommSignStatistics($SignStatistics); } } catch (Exception $e) { $result['message'] = '签到人太多,系统繁忙,请稍后再试~'; return $result; } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('signRank' => $rank, 'countDown' => Bll_Broker_CommunitySign::nextSignCountDown())); }
public function handle_request_internal() { $params["j_username"] = trim($this->_params["username"]); $params["j_password"] = trim($this->_params["password"]); $params["channel"] = 3; $api_url = '/service-internal/rest/brokers/login'; $broker = Util_CallAPI::get_data_from_java_api($api_url, $params); if ($broker['data']['status'] != 'ok') { if ($broker['data']['code'] == 398213) { return Util_MobileAPI::error(Const_APIStatus::E_BROKER_USERPWD_ERR); } else { return Util_MobileAPI::error(Const_APIStatus::E_CALL_API_ERROR); } } $broker_id = $broker['data']['broker']['brokerId']; //获取经纪人信息 $api_url = "/service-internal/rest/brokers/{$broker_id}"; $broker_info = Util_CallAPI::get_data_from_java_api($api_url); if (empty($broker_info)) { $broker_info = array(); } if ($broker_info['data']['status'] == 'error') { return Util_MobileAPI::error(Const_APIStatus::E_CALL_API_ERROR); } $broker_info = $broker_info['data']; $cityId = isset($broker_info['broker']['cityId']) ? $broker_info['broker']['cityId'] : ""; if ($cityId > 229) { return array('status' => 'error', 'errcode' => "", 'message' => "您所在的城市暂不支持APP服务"); } $broker_return = array('id' => isset($broker_info['broker']['brokerId']) ? $broker_info['broker']['brokerId'] : "", 'city_id' => isset($broker_info['broker']['cityId']) ? $broker_info['broker']['cityId'] : "", 'email' => isset($broker_info['broker']['userEmail']) ? $broker_info['broker']['userEmail'] : "", 'last_log_date' => isset($broker_info['broker']['lastLogDate']) ? $broker_info['broker']['lastLogDate'] : "", 'name' => isset($broker_info['broker']['trueName']) ? $broker_info['broker']['trueName'] : "", 'username' => isset($broker_info['broker']['userName']) ? $broker_info['broker']['userName'] : "", 'phone' => isset($broker_info['broker']['userMobile']) ? $broker_info['broker']['userMobile'] : "", 'use_photo' => isset($broker_info['broker']['userPhoto']) ? $broker_info['broker']['userPhoto'] : "", 'user_type' => isset($broker_info['broker']['userType']) ? $broker_info['broker']['userType'] : "", 'user_id' => isset($broker_info['broker']['userId']) ? $broker_info['broker']['userId'] : ""); $sid = APF::get_instance()->get_config("sid", "login"); //单点登录 $registerBll = new Bll_Register(); $registerBll->singleSignon($broker_return['user_id'], $broker_return['username'], $sid, $broker_return['user_type']); // 生成token $token = self::createToken(array($broker_return["id"], $broker_return['username'], time())); $broker_return['use_photo'] = Util_ImageUtils::get_broker_photo_url($broker_return['use_photo']); $insert_data["token"] = $token; $insert_data["user_id"] = $broker_return["id"]; $insert_data["expired"] = Bll_TokenBiz::get_instance()->get_expire_time(); $insert_data["app"] = APF::get_instance()->get_config('java_api_from'); Bll_TokenBiz::get_instance()->insert($insert_data); $device_data = array(); $device_data["user_id"] = $broker_return["id"]; $device_data["app"] = APF::get_instance()->get_config('java_api_from'); $device_data["device"] = ""; $device_data["ismi"] = trim(@$this->_params["imsi"]); $device_data["ip"] = APF::get_instance()->get_request()->get_client_ip(); $device_data["i"] = ""; $device_data["m"] = ""; $device_data["o"] = ""; $device_data["v"] = ""; $device_data["cv"] = ""; $device_data["cid"] = ""; $device_data["pm"] = ""; $device_data["created"] = date("Y-m-d H:i:s"); Bll_DeviceBiz::get_instance()->save($device_data); $dwStatsBiz = new Bll_DwStatsBiz(); if (!empty($this->_params["macid"])) { $guid = md5(trim($this->_params["macid"])); $dwStatsBiz->saveGuid($guid); } if (!empty($this->_params["uuid"])) { $guid = md5(trim($this->_params["uuid"])); $dwStatsBiz->saveGuid($guid); } if (!empty($this->_params["i"])) { $guid = md5(trim($this->_params["i"])); $dwStatsBiz->saveGuid($guid); } if (!empty($this->_params["uuid2"])) { //ios7兼容 $guid = md5(trim($this->_params["uuid2"])); $dwStatsBiz->saveGuid($guid); } if (!empty($this->_params["udid2"])) { //ios7兼容 $guid = md5(trim($this->_params["udid2"])); $dwStatsBiz->saveGuid($guid); } $return = array(); $return["status"] = "ok"; $return['data']["token"] = $token; $return['data']['broker'] = $broker_return; //缓存信息到redis $redisInfo = array('brokerId' => $broker_info['broker']['brokerId'], 'username' => $broker_info['broker']['trueName'], 'userPhoto' => $broker_return['use_photo'], 'cityId' => $broker_info['broker']['cityId']); Bll_Commsign::redisBrokerInfo($broker_info['broker']['brokerId'], $redisInfo); return $return; }