public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$brokerInfo) {
         throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     //读取每日任务完成情况
     $currentTime = date("Ymd", time());
     if (Bll_Commsign::getDailySignedStatus($brokerId)) {
         Model_DailyQuest_DailyQuestStatus::insertDailySigned($brokerId);
     }
     $dailyQuestStatus = Model_DailyQuest_DailyQuestStatus::getDailyQuestStatusByBrokerId($brokerId, $currentTime);
     $questMsg = '完成任务,获得礼包,快去完成吧!';
     $signStatus = $dailyQuestStatus['signState'] ? $dailyQuestStatus['signState'] : 0;
     $shareStatus = $dailyQuestStatus['shareState'] ? $dailyQuestStatus['shareState'] : 0;
     $rewardStatus = $dailyQuestStatus['rewardState'] ? $dailyQuestStatus['rewardState'] : 0;
     $canGetReward = '0';
     //完成任务没领奖励
     if ($signStatus == '1' && $shareStatus == '1' && $rewardStatus == '0') {
         $questMsg = '恭喜您获得礼包,快去领奖吧!';
         $canGetReward = '1';
     }
     //完成任务已领取奖励
     if ($signStatus == '1' && $shareStatus == '1' && $rewardStatus == '1') {
         $questMsg = '您已完成任务获得抢客券一张!';
         $canGetReward = '0';
     }
     $data = array('brokerId' => $brokerId, 'signStatus' => $signStatus, 'shareStatus' => $shareStatus, 'canGetReward' => $canGetReward, 'questMsg' => $questMsg);
     return array('status' => 'ok', 'data' => $data);
 }
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$brokerInfo) {
         throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     $sendNumChangeDate = APF::get_instance()->get_config("customer_daily_mission_reward_num", "customer");
     if (time() >= strtotime($sendNumChangeDate)) {
         $sendNum = self::PRESENT_COUPON_NEW_NUM;
         $rewardMsg = APF::get_instance()->get_config("customer_daily_mission_reward_msg", "customer");
     } else {
         $sendNum = self::PRESENT_COUPON_NUM;
         $rewardMsg = "恭喜你,获得抢客券2张";
     }
     $data = array('brokerId' => $brokerId, 'rewardMsg' => $rewardMsg);
     $this->brokerId = $brokerId;
     // 获取活动劵类型数据
     $cityId = $brokerInfo['cityId'];
     $couponData = Bll_CustomerRush_Coupon::getInstance()->getCoupon($cityId, date("Ymd"), Model_Mobile_CustomerCoupon::TYPE_DAILYCOUPON_PRESENT);
     if (empty($couponData)) {
         return array('status' => 'error', 'message' => '不存在活动劵信息');
     }
     $this->couponId = $couponData['id'];
     $currentTime = date("Ymd", time());
     //验证是否可领取奖励
     if (Bll_Commsign::getAlreadyGetRewards($brokerId, $currentTime)) {
         return array('status' => 'error', 'message' => '已经领取过奖励');
     }
     $dailyQuestStatus = Model_DailyQuest_DailyQuestStatus::getDailyQuestStatusByBrokerId($brokerId, $currentTime);
     $signStatus = $dailyQuestStatus['signState'] ? $dailyQuestStatus['signState'] : 0;
     $shareStatus = $dailyQuestStatus['shareState'] ? $dailyQuestStatus['shareState'] : 0;
     $rewardStatus = $dailyQuestStatus['rewardState'] ? $dailyQuestStatus['rewardState'] : 0;
     if (!($signStatus == '1' && $shareStatus == '1' && $rewardStatus == '0')) {
         return array('status' => 'error', 'message' => '已经领取过奖励');
     }
     //赠送抢客劵
     for ($i = 0; $i < $sendNum; $i++) {
         // 插入经纪人劵表
         $arr = array('brokerId' => $this->brokerId, 'couponId' => $this->couponId, 'status' => Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE, 'totalNum' => $couponData['totalNum'], 'usedNum' => 0, 'updateTime' => date("Y-m-d H:i:s"), 'createTime' => time());
         $this->brokerCouponId = Bll_CustomerRush_Coupon::getInstance()->insertBrokerCoupon($arr);
         if ($this->brokerCouponId) {
             // 记录日志
             $this->_insertPresentCouponLog();
         } else {
             return array('status' => 'error', 'message' => '赠送失败');
         }
     }
     //更新已领取
     Bll_Commsign::alreadyGetRewards($brokerId, $currentTime);
     $status = Model_DailyQuest_DailyQuestStatus::updateGetReward($brokerId, $currentTime);
     if (!$status) {
         return array('status' => 'error', 'message' => '更新领取状态失败');
     }
     return array('status' => 'ok', 'data' => $data);
 }
 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()
 {
     $this->cursor = $this->getFlag();
     if (empty($this->cursor)) {
         $this->cursor['id'] = 0;
         $this->setFlag($this->cursor, "");
     }
     $SignStatistics = Model_Broker_CommunitySignStatistics::data_access()->filter_by_op('id', '>', $this->cursor['id'])->limit(50)->get_all();
     if (empty($SignStatistics)) {
         $this->setStop();
     }
     foreach ($SignStatistics as $key => $value) {
         Bll_Commsign::setSignStatistics($value['brokerId'], $value);
         $this->cursor['id'] = $value['id'];
     }
     $this->setFlag($this->cursor);
 }
 public static function insertDailySigned($brokerId)
 {
     $row = self::data_access(date("Ym", time()));
     $sql = "insert into daily_quest_" . date("Ym", time()) . "(broker_id,create_time,sign_state,sign_time)" . " values(" . $brokerId . "," . date("Ymd", time()) . ",1,'" . Bll_Commsign::getDailySignedTime($brokerId) . "') on duplicate key update sign_state=1,sign_time='" . Bll_Commsign::getDailySignedTime($brokerId) . "'";
     return $row->native_sql($sql, array(), false);
 }
 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);
 }
Exemple #7
0
 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()));
 }
Exemple #8
0
 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;
 }
 public function handle_request()
 {
     Bll_Commsign::WriteDB();
     Bll_Commsign::updateLocation();
 }
 private function getCommList($brokerId, $lat, $lng)
 {
     // 从缓存中读取数据
     $communities = Bll_Commsign::getCommList($brokerId);
     if (empty($communities)) {
         // 根据lat和lng获取1.5km内的小区列表
         $latLngRound = Util_Map::round($lat, $lng, 1500);
         $communities = Model_Community_AjkCommunity::data_access()->load_field(array('commId', 'commName', 'sosolng', 'sosolat'))->filter('typeFlag', 0)->filter_by_op_multi(array(array('sosolat', '>=', $latLngRound['minLat']), array('sosolat', '<=', $latLngRound['maxLat']), array('sosolng', '>=', $latLngRound['minLng']), array('sosolng', '<=', $latLngRound['maxLng'])))->limit(1000)->get_all();
         if (empty($communities)) {
             return array();
         }
         // 实现按距离排序 • 升序
         uasort($communities, function (&$a, &$b) use($lat, $lng) {
             // 计算坐标的距离
             $a['distance'] = Util_Map::distance($lat, $lng, $a['sosolat'], $a['sosolng']);
             $b['distance'] = Util_Map::distance($lat, $lng, $b['sosolat'], $b['sosolng']);
             // 比较两小区坐标
             if ($a['distance'] == $b['distance']) {
                 return 0;
             }
             return $a['distance'] < $b['distance'] ? -1 : 1;
         });
         $i = 0;
         $data = array();
         foreach ($communities as $community) {
             if (++$i > 300) {
                 break;
             }
             $row = array();
             $row['commId'] = $community['commId'];
             $row['commName'] = $community['commName'];
             $row['lng'] = $community['sosolng'];
             $row['lat'] = $community['sosolat'];
             $row['distance'] = $community['distance'];
             $data[] = $row;
         }
         // 缓存数据
         Bll_Commsign::setCommList($brokerId, $data);
         return $data;
     } else {
         if (is_array($communities)) {
             return $communities;
         } else {
             return array();
         }
     }
 }
Exemple #11
0
 public static function testRedis()
 {
     $redis = self::getRedisConnect();
     //测试程序/////////////////////////////////////////////////
     $currentSignRange = Bll_Broker_CommunitySign::getCurrentSignRange();
     $redis->flushDB();
     $SignStatistics = Model_Broker_CommunitySignStatistics::data_access()->filter_by_op('id', '>=', 0)->limit(500)->get_all();
     //var_dump($SignStatistics);die;
     $redis->select(1);
     $arr = $redis->keys(self::$SignStatistics . '*');
     foreach ($arr as $k) {
         //var_dump(self::getKey($k));
     }
     $redis->select(0);
     exit;
     $id = 100;
     for ($i = 1; $i <= 10; ++$i) {
         $brokerId = intval('1111' . $i);
         $commId = intval('200' . $i);
         $id = $id + 1;
         $sign = array('id' => $id, 'brokerId' => $brokerId, 'communityId' => $commId, 'lat' => floatval('31.' . $i), 'lng' => floatval('121.' . $i), 'signTime' => date('Y-m-d H:i:s'), 'sourceType' => Model_Broker_Location::SOURCE_TYPE_COMMUNITY_SIGN, 'updateTime' => date('Y-m-d H:i:s'), 'currentSignRange' => $currentSignRange[0]);
         Bll_Commsign::Signed($brokerId, $commId, $currentSignRange[0], $sign);
         //Bll_Commsign::setLocationInfo($brokerId,$sign);
     }
     //var_dump($redis->keys('*'));exit;
     //测试结束//////////////////////////////////////////////////////////////////
 }