/** * [返回用户登录数据] * @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); }
/** * [用户签到] * @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; } }
/** * 返回当前用户的云币数量和等级 */ public function getUserLevelInfo($di, $userInfo) { $swoole = new SwooleUserClient($di['sysconfig']['swooleConfig']['ip'], $di['sysconfig']['swooleConfig']['port']); $res = $swoole->getUserInfoByMobi($userInfo['mobi']); if (empty($res['data'])) { return self::NON_EXIST_MOBILE; } //获取用户当前云币数量 $coins = $swoole->coinsInfo($userInfo['uid']); if (empty($coins['data'])) { return self::NON_EXIST_MOBILE; } return array('flag' => '1', 'coins' => $coins['data']['uw_coins'], 'level' => $res['data']['u_level']); }
public function renewOperate($outTradeNo, $addTime, $tradeNo) { $renewInfo = $this->renew->getRenewByRono($outTradeNo); if (!$renewInfo) { return self::FAILED_OPERATE; } //获取设备原本到期时间和imei $shoeInfo = $this->devices->getBabyDevByShoeId($renewInfo['dev_id']); if (!$shoeInfo) { return self::FAILED_OPERATE; } //如果续费的时候设备尚未到期,则延长到期时间 if ($shoeInfo['dev_expires'] - $addTime > 0) { $expires = Common::expires($shoeInfo['dev_expires'], $renewInfo['ro_period']); } else { //如果已经到期,则从现在开始续费 $expires = Common::expires($addTime, $renewInfo['ro_period']); } //现在的日期 $today = getdate($addTime); //到期日 $deaddate = getdate($expires); $content = sprintf($this->di['sysconfig']['renewPushMsg']['success'], $renewInfo['ro_rolename'], $today['year'] . '年' . $today['mon'] . '月' . $today['mday'] . '日', $renewInfo['dev_imei'], $deaddate['year'] . '年' . $deaddate['mon'] . '月' . $deaddate['mday'] . '日'); $this->di['db']->begin(); if (!$this->devices->updateExpires($shoeInfo['dev_uuid'], $expires)) { $this->di['db']->rollback(); return self::FAILED_OPERATE; } if (!$this->devices->setExpiresByDevid($renewInfo['dev_id'], $expires)) { $this->di['db']->rollback(); return self::FAILED_OPERATE; } if (!$this->renew->addRenewLog($renewInfo['ro_id'], 3, $addTime)) { $this->di['db']->rollback(); return self::FAILED_OPERATE; } if (!$this->msg->insertMsg($renewInfo['baby_id'], $addTime, $content, 17)) { $this->di['db']->rollback(); return self::FAILED_OPERATE; } if (!$this->renew->setOrderStatus($outTradeNo, 3, $tradeNo)) { $this->di['db']->rollback(); return self::FAILED_OPERATE; } $this->di['db']->commit(); //赠送云币 $swoole = new SwooleUserClient($this->di['sysconfig']['swooleConfig']['ip'], $this->di['sysconfig']['swooleConfig']['port']); $res = $swoole->checkInReceive($renewInfo['u_id'], $renewInfo['ro_coins']); return self::SUCCESS; }
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); }
/** * 发放任务奖励 * @param unknown $uid * @param unknown $coin */ public function receive($uid, $coin) { $swoole = new SwooleUserClient($this->di['sysconfig']['swooleConfig']['ip'], $this->di['sysconfig']['swooleConfig']['port']); //发放奖励 $res = $swoole->checkInReceive($uid, $coin); }
/** * 发放任务奖励 * @param unknown $uid * @param unknown $coin */ public function receive($uid, $coin) { $swoole = new SwooleUserClient($this->di['sysconfig']['swooleConfig']['ip'], $this->di['sysconfig']['swooleConfig']['port']); //发放奖励 $res = $swoole->checkInReceive($uid, $coin); if ($res['data'] == 1) { return TRUE; } else { return FALSE; } }