protected function onInit_chkLogin() { $userIdentifier = \Sooh\Base\Session\Data::getInstance()->get('accountId'); if ($userIdentifier) { \Sooh\Base\Log\Data::getInstance()->userId = $userIdentifier; $this->user = \Prj\Data\User::getCopy($userIdentifier); } else { throw new \ErrorException(\Prj\ErrCode::errNotLogin, 401); } }
protected function onLogin($accountInfo) { $sess = \Sooh\Base\Session\Data::getInstance(); $sess->set('accountId', $accountInfo['accountId']); $sess->set('nickname', $accountInfo['nickname']); $this->_view->assign('account', array('accountId' => $accountInfo['accountId'], 'nickname' => $accountInfo['nickname'])); /** $userOrAccountId = $this->user; $checkinBook = \Lib\Services\CheckinBook::getInstance(); */ $userOrAccountId = $accountInfo['accountId']; $checkinBook = \Lib\Services\CheckinBook::getInstance($this->getRpcDefault('CheckinBook')); $this->_view->assign('checkinBook', $checkinBook->doGetTodayStatus(1, $userOrAccountId)['data']); $this->_view->assign('shopPoints', array('nleft' => 'todo', 'history' => array('todo'))); $user = \Prj\Data\User::getCopy($userOrAccountId); setcookie('nickname', $accountInfo['nickname'], 0, '/', \Sooh\Base\Ini::getInstance()->cookieDomain()); $user->load(); $dt = \Sooh\Base\Time::getInstance(); if ($user->exists() === false) { $user->setField('nickname', $accountInfo['nickname']); $user->setField('contractId', $accountInfo['contractId']); $user->setField('regYmd', $dt->YmdFull); $user->setField('regHHiiss', $dt->his); $user->setField('regClient', self::tmp_clientType); $user->setField('regIP', \Sooh\Base\Tools::remoteIP()); //$user->setField(self::fieldUser, array()); $user->update(); } else { $user->setField('nickname', $accountInfo['nickname']); $user->setField('lastDt', $dt->timestamp()); $user->setField('lastIP', \Sooh\Base\Tools::remoteIP()); $user->update(); } $sess->shutdown(); $this->returnOK(); }
/** * 签到 * @param boolean $withBonus 返回里是否带奖励物品列表 * @param \Prj\Data\User $userOrAccountId accountId 或 \Prj\Data\User * @return array */ public function doCheckIn($withBonus, $userOrAccountId) { if ($this->rpc !== null) { return $this->rpc->initArgs(array('withBonus' => $withBonus, 'userOrAccountId' => $userOrAccountId))->send(__FUNCTION__); } else { if (is_scalar($userOrAccountId)) { $userOrAccountId = \Prj\Data\User::getCopy($userOrAccountId); } $userOrAccountId->load(); if ($userOrAccountId->exists() === false) { $userOrAccountId->setField(self::fieldUser, array()); $userOrAccountId->update(); } $this->decode($userOrAccountId->getField(self::fieldUser, true)); if ($this->r['ymd'] == $this->today) { \Sooh\Base\Log\Data::getInstance()->ret = "checkin already"; return $this->errFound(self::errTodayDone, 400, $withBonus); } elseif (sizeof($this->r['checked']) >= self::maxMonth) { \Sooh\Base\Log\Data::getInstance()->ret = 'checkin of this month:all done'; return $this->errFound(self::errMonthDone, 400, $withBonus); } $accountId = $userOrAccountId->getAccountId(); $idCheckThisTime = array_sum($this->r['checked']); $bonusThisTime = $this->getBonusList()[$idCheckThisTime]; if (false === $userOrAccountId->lock('chkinBonus:' . http_build_query($bonusThisTime))) { \Sooh\Base\Log\Data::getInstance()->ret = "lock user for checkin failed"; \Prj\Loger::alarm('[LockFailed] user-table on checkin' . \Sooh\DB\Broker::lastCmd()); return $this->errFound(\Sooh\Base\ErrException::msgServerBusy, 500, $withBonus); } //\Lib\Items\Broker::iniForGiven('Voucher', array('iniDefaultForGive_a'=>60));// 如果有道具发放时有额外参数要设置(比如有效期不同) $givedThisTime = \Lib\Items\Broker::batchGive_pre($bonusThisTime, $accountId); if (sizeof($givedThisTime) == sizeof($bonusThisTime)) { if (\Lib\Items\Broker::batchGive_confirm($givedThisTime, $accountId)) { try { $this->r['checked'][$idCheckThisTime] = 1; $this->r['bonusGot'][$idCheckThisTime] = $bonusThisTime; $this->r['ymd'] = $this->today; $userOrAccountId->setField(self::fieldUser, $this->r); $userOrAccountId->update(); \Sooh\Base\Log\Data::getInstance()->ret = "done"; return $this->allDone(self::msgCheckinDone, $withBonus); } catch (\ErrorException $errOnUpdate) { \Prj\Loger::alarm('[CheckInFailed] on update user:'******'[GiveItemFailed] on checkin'); \Sooh\Base\Log\Data::getInstance()->ret = "give item failed"; } else { \Sooh\Base\Log\Data::getInstance()->ret = "update user failed"; } if (\Lib\Items\Broker::batchGive_rollback('GiveItemFailedOnCheckin', $givedThisTime, $accountId)) { $userOrAccountId->unlock(); return $this->errFound(\Sooh\Base\ErrException::msgServerBusy, 500, $withBonus); } else { return $this->errFound(\Sooh\Base\ErrException::msgServerBusy, 500, $withBonus); } } }