/** * [用户签到] * @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 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; }
/** * 发放任务奖励 * @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; } }