Example #1
0
 /**
  * 获取空气质量指数
  */
 public function getaqiAction()
 {
     //获取当前小时
     $hour = date('H', $_SERVER['REQUEST_TIME']);
     $redisObj = new RedisLib($this->di);
     $redis = $redisObj->getRedis();
     $aqiInfo = $redis->get('app:aqi');
     $aqiRes = json_decode($aqiInfo['data'], true);
     if ($aqiInfo['time'] != $hour || empty($aqiRes)) {
         //如果一次获取不到,则继续获取;接口一个小时只能获取15次,
         for ($i = 0; $i < 15; $i++) {
             $newAqi['data'] = UserHelper::curlRequest('http://www.pm25.in/api/querys/aqi_ranking.json?&token=5Hx7pxpULLvULw6xMD5J');
             $res = json_decode($newAqi['data'], true);
             if (!empty($res) || is_array($res)) {
                 $i = 14;
             }
         }
         $newAqi['time'] = $hour;
         $redis->setex('app:aqi', 4000, $newAqi);
         exit(date('Y-m-d H:i:s', time()) . ':' . '完成获取最新的天气');
     } else {
         $redis->setex('app:aqi', 4000, $aqiInfo);
         exit(date('Y-m-d H:i:s', time()) . ':' . '获取最新的天气失败,使用的是早前的天气');
     }
 }
Example #2
0
 /**
  * [用户签到]
  * @param  [type] $uid   [用户id]
  * @param  [type] $level [用户当前等级]
  * @return [type]        [description]
  */
 public function userCheckin($uid, $level)
 {
     //第二天零点
     $tomorrow = strtotime(date('Y-m-d', strtotime('+1 day')));
     //第二天连续签到的最后时刻
     $finalSign = strtotime(date('Y-m-d', strtotime('+2 day'))) - 1;
     $nowtime = $_SERVER['REQUEST_TIME'];
     $redisObj = new RedisLib($this->di);
     $redis = $redisObj->getRedis();
     //用redis设置签到状态值,如果这个这key存在表示今天已经签到,不存在表示尚未签到
     $checkinStatus = sprintf($this->di['sysconfig']['checkinStatus'], $uid);
     if ($redis->get($checkinStatus)) {
         return self::HAVE_CHECKINED;
     }
     //redis签到的key
     $signKey = sprintf($this->di['sysconfig']['signcount'], $uid);
     //multi是否处理是否连续签到,连续+1,不连续值为1
     $redis->multi()->incr($signKey)->setTimeout($signKey, $finalSign - $nowtime)->exec();
     //获得连续签到天数
     $seriesCheckin = $redis->get($signKey);
     //签到奖励的云币数
     $coins = Common::checkinCoin($this->di, $seriesCheckin);
     if ($this->checkinlogs->addCheckin($uid, $nowtime, $coins) == 0) {
         return self::FAILED_CHECKIN;
     }
     //获取用户签到总天数
     $totalDays = $redis->get($uid . ':' . $this->di['sysconfig']['checkinTotal']);
     if ($totalDays == FALSE) {
         $totalDays = '0';
     }
     //计算用户升级到下一级所需总签到天数
     $needDays = UserHelper::levelCheck($level);
     $swoole = new SwooleUserClient($this->di['sysconfig']['swooleConfig']['ip'], $this->di['sysconfig']['swooleConfig']['port']);
     if ($totalDays <= 1050) {
         if ($totalDays > $needDays) {
             //更新用户等级
             $res = $swoole->updateLevel($uid);
             if ($res['data'] == 0) {
                 return self::FAILED_GET_DATA;
             }
             $level = $this->userInfo['level'] + 1;
         }
     }
     //发放奖励
     $res = $swoole->checkInReceive($uid, $coins);
     if ($res['data'] == 1) {
         //设置签到状态:置1表示已签到
         $redis->setex($checkinStatus, $tomorrow - $nowtime, '1');
         //用redis保存签到总天数
         $redis->set($uid . ':' . $this->di['sysconfig']['checkinTotal'], $totalDays + 1);
         return array('flag' => '1', 'checkindays' => (string) $seriesCheckin, 'coins' => (string) $coins, 'level' => (string) $level);
     } else {
         return self::FAILED_GET_COINS;
     }
 }
Example #3
0
 /**
  * 亲人列表
  *
  */
 public function listAction()
 {
     if ($famList = $this->family->showFamList($this->_sanReq['baby_id'], $this->_sanReq['count'])) {
         $userIds = array_map(function ($v) {
             return $v['u_id'];
         }, $famList);
         if (!empty($userIds)) {
             $res = $this->family->userInfoByIds(implode(',', $userIds));
             if (empty($res['data'])) {
                 $this->_showMsg(self::FAILED_GET_FAMILY_LIST, $this->di['flagmsg'][self::FAILED_GET_FAMILY_LIST]);
             }
             $userNicks = $res['data'];
             $num = sizeof($famList);
             $cou = sizeof($userNicks);
             for ($i = 0; $i < $num; $i++) {
                 unset($famList[$i]['praises']);
                 unset($famList[$i]['comments']);
                 unset($famList[$i]['actime']);
                 for ($j = 0; $j < $cou; $j++) {
                     if ($famList[$i]['u_id'] == $userNicks[$j]['u_id']) {
                         $famList[$i]['rel_pic'] = UserHelper::checkPic($this->di, $userNicks[$j]['u_pic']);
                         $famList[$i]['mobi'] = $userNicks[$j]['u_mobi'];
                         if ($userNicks[$j]['u_name'] == '') {
                             $famList[$i]['nick'] = $userNicks[$j]['u_mobi'];
                         } else {
                             $famList[$i]['nick'] = $userNicks[$j]['u_name'];
                         }
                         break;
                     } else {
                         $famList[$i]['rel_pic'] = '';
                         $famList[$i]['nick'] = '';
                     }
                 }
             }
         }
     }
     $redisObj = new RedisLib($this->di);
     $redis = $redisObj->getRedis();
     //获取虚拟的用户信息
     $unregUsers = $redis->get(sprintf($this->di['sysconfig']['unregUserByBid'], $this->_sanReq['baby_id']));
     if (!empty($unregUsers)) {
         foreach ($unregUsers as $mobi => $val) {
             $unregList[] = array('mobi' => (string) $mobi, 'nick' => $val['uname'], 'ishost' => (string) $val['relation'], 'u_id' => '', 'name' => '', 'rel_pic' => '');
         }
         $famList = array_merge($famList, $unregList);
     }
     $this->_returnResult(array('flag' => self::SUCCESS, 'familylist' => $famList));
 }
Example #4
0
 /**
  * [返回用户登录数据]
  * @param  [string] $mobi        [用户手机号]
  * @param  [string] $deviceToken [用户手机的设备标签]
  * @param  [string] $type [1-ios 3-android]
  * @return [type]              [description]
  */
 protected function _showLoginData($mobi, $deviceToken, $type = '')
 {
     //执行免登录操作,将新注册的用户信息存到redis
     $swoole = new \Appserver\Utils\SwooleUserClient($this->di['sysconfig']['swooleConfig']['ip'], $this->di['sysconfig']['swooleConfig']['port']);
     $row = $swoole->getUserInfoByMobi($mobi);
     if (empty($row['data'])) {
         return self::NON_EXIST_MOBILE;
     }
     if (empty($deviceToken)) {
         $disturb = '1';
     } else {
         //获取用户的免打扰状态
         $RedisObj = new \Appserver\Utils\RedisLib($this->di);
         $redis = $RedisObj::getRedis();
         $disturbInfo = $redis->get('disturb:' . $row['data']['u_id']);
         if (!$disturbInfo) {
             $disturb = '3';
             //默认为3:关闭免打扰
             $start = '';
             $end = '';
         } else {
             $disturb = $disturbInfo['disturb'];
             $start = $disturbInfo['start'];
             $end = $disturbInfo['end'];
         }
     }
     $userInfo['qqUid'] = $row['data']['u_qq_uid'];
     $userInfo['wbUid'] = $row['data']['u_wb_uid'];
     $userInfo['uid'] = $row['data']['u_id'];
     $userInfo['mobi'] = $row['data']['u_mobi'];
     $userInfo['pic'] = $row['data']['u_pic'] ? UserHelper::checkPic($this->di, $row['data']['u_pic']) : '';
     $userInfo['uname'] = $row['data']['u_name'];
     $userInfo['level'] = $row['data']['u_level'];
     $userInfo['regtime'] = $row['data']['u_regtime'];
     //设置tokenflag,表示是正常的token
     $userInfo['tokenFlag'] = '1';
     $userInfo['wb_status'] = $row['data']['u_wb_uid'] ? '1' : '';
     $userInfo['qq_status'] = $row['data']['u_qq_uid'] ? '1' : '';
     $RedisObj = new RedisLib($this->di);
     $redis = $RedisObj->getRedis();
     //获取用户连续签到次数
     $checkinCount = $redis->get(sprintf($this->di['sysconfig']['signcount'], $userInfo['uid']));
     if ($checkinCount == false) {
         $checkinCount = '0';
     }
     //获取用户当前云币数量
     $coins = $swoole->coinsInfo($userInfo['uid']);
     //当发现用户未创建钱包时,未其创建一个
     if (empty($coins['data'])) {
         if ($swoole->createWallet($userInfo['uid'])['data'] == '1') {
             $coins['data']['uw_coins'] = '0';
         } else {
             return self::FAILED_CREATE_WALLET;
         }
     }
     //保存一个login:uid的redis并产生用户token,用来限制一个用户只能在一台手机上登录
     $token = UserHelper::setToken($this->di, $userInfo, $type, $deviceToken);
     return array('flag' => '1', 'token' => $token, 'u_id' => $userInfo['uid'], 'mobi' => $userInfo['mobi'], 'u_pic' => $userInfo['pic'], 'u_name' => $userInfo['uname'], 'coins' => $coins['data']['uw_coins'], 'level' => $userInfo['level'], 'checkindays' => (string) $checkinCount, 'wb_status' => $userInfo['wb_status'], 'qq_status' => $userInfo['qq_status'], 'user_qr' => UserHelper::makeUserQr($userInfo['uid'], $userInfo['mobi'], $userInfo['regtime']), 'disturb' => $disturb);
 }
Example #5
0
 /**
  * 亲人列表
  *
  */
 public function listAction()
 {
     if ($famList = $this->family->showFamList($this->_sanReq['baby_id'], $this->_sanReq['count'])) {
         $userIds = array_map(function ($v) {
             return $v['u_id'];
         }, $famList);
         if (!empty($userIds)) {
             $res = $this->family->userInfoByIds(implode(',', $userIds));
             if (empty($res['data'])) {
                 $this->_showMsg(self::FAILED_GET_FAMILY_LIST, $this->di['flagmsg'][self::FAILED_GET_FAMILY_LIST]);
             }
             $userNicks = $res['data'];
             $num = sizeof($famList);
             $cou = sizeof($userNicks);
             for ($i = 0; $i < $num; $i++) {
                 for ($j = 0; $j < $cou; $j++) {
                     if ($famList[$i]['u_id'] == $userNicks[$j]['u_id']) {
                         $famList[$i]['rel_pic'] = UserHelper::checkPic($this->di, $userNicks[$j]['u_pic']);
                         if ($userNicks[$j]['u_name'] == '') {
                             $famList[$i]['nick'] = $userNicks[$j]['u_mobi'];
                         } else {
                             $famList[$i]['nick'] = $userNicks[$j]['u_name'];
                         }
                         break;
                     } else {
                         $famList[$i]['rel_pic'] = '';
                         $famList[$i]['nick'] = '';
                     }
                 }
             }
         }
     }
     $this->_returnResult(array('flag' => self::SUCCESS, 'familylist' => $famList));
 }
Example #6
0
 public function getCommentList($locusId, $count, $maxId)
 {
     if ($maxId == '') {
         $commList = $this->commentModel->getCommentList($locusId, $count);
     } else {
         $commList = $this->commentModel->getCommentBymaxId($locusId, $maxId, $count);
     }
     //返回评论的数量
     $count = $this->locusModel->getCommentAndPraiseCount($locusId);
     if (!$count) {
         $comments = 0;
     } else {
         $comments = $count['comments'];
     }
     $userIds = array_map(function ($v) {
         return $v['u_id'];
     }, $commList);
     if (!empty($userIds)) {
         $swoole = new SwooleUserClient($this->di['sysconfig']['swooleConfig']['ip'], $this->di['sysconfig']['swooleConfig']['port']);
         $userInfos = $swoole->userInfoByIds(implode(',', $userIds))['data'];
         $listNum = sizeof($commList);
         $picNum = sizeof($userInfos);
         for ($i = 0; $i < $listNum; $i++) {
             for ($j = 0; $j < $picNum; $j++) {
                 if ($commList[$i]['u_id'] == $userInfos[$j]['u_id']) {
                     $commList[$i]['u_pic'] = UserHelper::checkPic($this->di, $userInfos[$j]['u_pic']);
                     if ($userInfos[$j]['u_name'] == '') {
                         $commList[$i]['u_name'] = $userInfos[$j]['u_mobi'];
                     } else {
                         $commList[$i]['u_name'] = $userInfos[$j]['u_name'];
                     }
                     break;
                 }
             }
         }
     }
     //将result重新排序,addtime较小的排在前面
     usort($commList, function ($a, $b) {
         return strcmp($a['time'], $b['time']);
     });
     return array('flag' => self::SUCCESS, 'commlist' => $commList, 'comments' => $comments);
 }
Example #7
0
 /**
  * [获取天气预报信息]
  * @param  [type] $babyId [description]
  * @param  [type] $city   [description]
  * @return [type]         [description]
  */
 public function getFore($babyId, $city)
 {
     $babyInfo = $this->baby->getBabyName($babyId);
     try {
         $rpcConnect = new \Appserver\Utils\RpcService($this->di['sysconfig']['thriftConf']['ip'], $this->di['sysconfig']['thriftConf']['port']);
         $location = $rpcConnect->GetBabyLocation($babyId);
     } catch (\Exception $e) {
         continue;
     }
     //如果从babyid找不到地理位置,则根据请求的地理位置计算天气
     if (!empty($location)) {
         $location = json_decode($location, true);
         $city = $location['city'];
     }
     if ($city != '') {
         //获取地区编码
         $areaid = UserHelper::getAreaCode($this->di, $city);
         if (!$areaid) {
             $city = substr($city, 0, -3);
             $areaid = UserHelper::getAreaCode($this->di, $city);
         }
     }
     if ($city == '' || !$areaid) {
         return array('flag' => '1', 'area' => $city, 'aqi' => '', 'qlt' => '', 'h_temp' => '', 'l_temp' => '', 'weat_pic' => '', 'weather' => '', 'baby_pic' => '');
     }
     $redisObj = new RedisLib($this->di);
     $redis = $redisObj->getRedis();
     $weatherData = $redis->get($this->di['weatherConfig']['weatherData'] . $areaid);
     if (empty($weatherData)) {
         //缓存过期,重新获取数据
         $data = UserHelper::rollCurlRequest(array('aqi' => sprintf($this->di['weatherConfig']['pm25']['url'], urlencode($city)), 'fore' => sprintf($this->di['weatherConfig']['weatherConfig']['url'], urlencode($city))));
         if (empty($data) || !empty($data[0]['error']) || !empty($data[1]['error'])) {
             $flag = 0;
             $log = '查询天气:' . $city . '>>结果:aqi:' . $data[0]['error'] . '>>天气:' . $data[1]['error'];
         } else {
             $weather = json_decode($data['fore']['info'], true);
             $aqi = json_decode($data['aqi']['info'], true);
             if ($weather['error_code'] != '0' || $aqi['error_code'] != '0') {
                 $flag = 0;
             }
             $log = '查询天气:' . $city . '>>结果:aqi:' . $aqi['reason'] . '>>天气:' . $weather['reason'];
             //构造天气数据
             if ($weather['error_code'] == 0) {
                 $temp = explode('~', $weather['result']['today']['temperature']);
                 $ltemp = (string) $temp[0];
                 $htemp = (string) $temp[1];
                 //气象实况
                 $weath = $weather['result']['today']['fb'];
                 $forecast = $weather['result']['today']['weather'];
             } else {
                 $ltemp = '';
                 $htemp = '';
                 //气象实况,99-未知天气
                 $weath = '99';
                 $forecast = '';
                 $flag = 0;
                 $log = '查询天气:' . $city . '>>结果:' . $weather['reason'];
             }
             //构造aqi数据
             if ($aqi['error_code'] == 0) {
                 $pmAqi = (string) $aqi['result']['AQI'];
                 $qlt = (string) $aqi['result']['Quality'];
             } else {
                 $pmAqi = '';
                 $qlt = '';
                 $flag = 0;
                 $log = '查询aqi:' . $city . '>>结果:aqi:' . $aqi['reason'];
             }
             $weatherData['area'] = $city;
             $weatherData['aqi'] = $pmAqi;
             $weatherData['qlt'] = $qlt;
             $weatherData['h_temp'] = $htemp;
             $weatherData['l_temp'] = $ltemp;
             $weatherData['weather'] = $forecast;
             $weatherData['weatherCode'] = $weath;
             //存入缓存:如果数据不完整,则缓存半小时,若数据完整,则缓存8小时
             if (empty($weatherData['weather'])) {
                 $redis->setex($this->di['weatherConfig']['weatherData'] . $areaid, $this->di['weatherConfig']['weatherShortTime'], $weatherData);
             } else {
                 $redis->setex($this->di['weatherConfig']['weatherData'] . $areaid, $this->di['weatherConfig']['weatherTime'], $weatherData);
             }
         }
     }
     if (!empty($weatherData['weatherCode']) && !empty($weatherData['aqi']) && (!empty($weatherData['l_temp']) || !empty($weatherData['h_temp']))) {
         $res = UserHelper::getBabyWeatherPic($this->di, $babyInfo['baby_sex'], $weatherData['weatherCode'], $weatherData['aqi'], $weatherData['l_temp'], $weatherData['h_temp']);
         $weatherData['baby_pic'] = $res['baby_pic'];
         $weatherData['weat_pic'] = $res['weat_pic'];
     } else {
         $weatherData['baby_pic'] = '';
         $weatherData['weat_pic'] = '';
     }
     unset($weatherData['weatherCode']);
     $weatherData['flag'] = '1';
     return $weatherData;
 }
Example #8
0
 /**
  * 编辑用户
  * @param  [string] $userInfo [存在用户token中的信息,方便重新构造token]
  * @param  [string] $newFile  [新的用户图片]
  * @return [type]           [description]
  */
 public function userEdit($token, $userInfo, $newname, $newFile)
 {
     //对修改的名字
     if ($newname != '' && $newname != $userInfo['uname']) {
         if (!UserHelper::nameCheck($newname)) {
             return self::ERROR_NAME;
         }
         $res = $this->swoole->checkUserName($newname, $userInfo['uid']);
         if ($res['data'] == '1') {
             return self::EXIST_NAME;
         }
     } else {
         $newname = $userInfo['uname'];
     }
     if (!empty($newFile)) {
         $picInfo = Common::makePath($this->di['sysconfig']['userPic'], $userInfo['mobi']);
         $pic = $picInfo['picUrl'];
     } else {
         $pic = $userInfo['pic'];
     }
     $res = $this->swoole->modifyUser($newname, $userInfo['uid'], $pic);
     if ($res['data'] == '1') {
         if (!empty($newFile)) {
             //上传图片
             if ($this->swoole->uploadAvatar($newFile['tmp_name'], filesize($newFile['tmp_name']), $picInfo['rename'], $picInfo['path'])) {
                 //更新用户的缓存头像
                 $userInfo['pic'] = $this->di['sysconfig']['userPicServer'] . $picInfo['picUrl'];
             } else {
                 return self::FAILED_UPLOAD;
             }
         }
         $redisObj = new RedisLib($this->di);
         $redis = $redisObj->getRedis();
         $redis->setex('token:' . $token, $this->di['sysconfig']['tokenTime'], $userInfo);
         return array('flag' => (string) self::SUCCESS, 'u_pic' => $userInfo['pic']);
     } else {
         return self::FAILED_UPDATE;
     }
 }
Example #9
0
 public function showPraisesList($locusId, $count, $sinceId, $maxId)
 {
     if ($sinceId == '' && $maxId == '') {
         $praList = $this->praisesmodel->getPraiseList($locusId, $count);
     } elseif ($sinceId && $maxId == '') {
         $praList = $this->praisesmodel->getPraisesBySinceId($locusId, $sinceId, $count);
     } else {
         $result = $this->praisesmodel->getPraiseList($locusId, $count);
         //拿最新数据的最后一条赞id和请求的maxId比较,如果最后一条赞id小于maxId,则返回最新的赞到maxId这段数据,反之则返回全部最新的数据
         if (!$result) {
             $num = sizeof($result) - 1;
             //如果最新的赞id等于请求的maxId,说明还没有新的赞生成
             if ($result['0']['lp_id'] == $maxId) {
                 $praList = array();
             } else {
                 if ($result[$num]['lp_id'] <= $maxId) {
                     $praList = $this->praisesmodel->getPraisesByMaxId($locusId, $maxId);
                 } else {
                     $praList = $result;
                 }
             }
         }
     }
     if (!empty($praList)) {
         //根据轨迹id获得宝贝id
         $babyId = $this->locusmodel->getBabyIdByLsId($locusId);
         //根据宝贝id获得宝贝昵称
         $babyName = $this->babymodel->getBabyInfoById($babyId['baby_id']);
         if ($babyName) {
             for ($i = 0; $i < sizeof($praList); $i++) {
                 $praList[$i]['baby_name'] = $babyName['baby_nick'];
             }
         }
         $uids = array_map(function ($v) {
             return $v['u_id'];
         }, $praList);
         $res = $this->swoole->userInfoByIds(implode(',', array_unique(array_filter($uids))));
         $pics = $res['data'];
         $cou = sizeof($pics);
         for ($i = 0; $i < sizeof($praList); $i++) {
             for ($j = 0; $j < $cou; $j++) {
                 if (empty($pics[$i])) {
                     $praList[$i]['u_pic'] = '';
                 } else {
                     if ($praList[$i]['u_id'] == $pics[$j]['u_id']) {
                         $praList[$i]['u_pic'] = UserHelper::checkPic($this->di, $pics[$j]['u_pic']);
                         break;
                     }
                 }
             }
         }
     }
     $count = $this->locusmodel->getCommentAndPraiseCount($locusId);
     //获取赞总数总数
     if ($count) {
         $praises = $count['praises'];
     } else {
         $praises = '0';
     }
     return array('flag' => '1', 'praiseslist' => $praList, 'praises' => $praises);
 }