public function write($logData) { if ($this->rpc !== null) { return $this->rpc->initArgs(array('logData' => $logData))->send(__FUNCTION__); } else { $dt = \Sooh\Base\Time::getInstance(); \Sooh\DB\Broker::getInstance()->addLog('db_monitor.tb_error_log', array('ymd' => $dt->YmdFull, 'hhiiss' => $dt->his, 'msg' => $logData)); return 'done'; } }
/** * 签到 * @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); } } }
public function register($password, $arrLoginName = [], $customArgs = []) { if ($this->rpc !== null) { return $this->rpc->initArgs(array('password' => $password, 'arrLoginName' => $arrLoginName, 'customArgs' => $customArgs))->send(__FUNCTION__); } else { if ($arrLoginName !== null) { //生成AccountId for ($retry = 0; $retry < 10; $retry++) { try { $accountId = rand(10000, 99999) . sprintf('%05d', rand(0, 99999)) . sprintf('%04d', rand(0, 9999)); $this->setAccountStorage($accountId); if ($this->account->exists()) { throw new \Exception('account exists for registe'); } else { break; } } catch (\Exception $e) { error_log($e->getMessage() . "[try accountId:{$accountId}]"); } if ($retry == 9) { throw new \Sooh\Base\ErrException(self::errRetryLater, 400); } } //检查loginName是否存在 foreach ($arrLoginName as $_key => $_val) { if ($this->loginPrepare($accountId, $_val[0], $_val[1]) === false) { $this->loginRollback($arrLoginName, $_key); throw new \Sooh\Base\ErrException(self::errAccountExists, 400); } } } else { throw new \Sooh\Base\ErrException(self::errAccountEmpty, 400); } $this->account->load(); $passwdSalt = substr(uniqid(), -4); if (!empty($customArgs['nickname'])) { $nickname = $customArgs['nickname']; } else { $nickname = $accountId; } $this->account->setField('passwdSalt', $passwdSalt); $cmp = md5($password . $passwdSalt); $this->account->setField('passwd', $cmp); $this->account->setField('nickname', $nickname); $customArgs['regClient'] = $customArgs['clientType'] - 0; $customArgs['regYmd'] = \Sooh\Base\Time::getInstance()->YmdFull; $customArgs['regHHiiss'] = \Sooh\Base\Time::getInstance()->his; foreach ($customArgs as $k => $v) { $this->account->setField($k, $v); } $this->account->update(); $tmp = array('accountId' => $accountId, 'nickname' => $nickname); foreach ($customArgs as $k => $v) { $tmp[$k] = $v; } $this->loginCommit($arrLoginName); return $tmp; } }
/** * 删除过于久远的执行状态记录(默认半年) */ public function remoreCrondLogExpired($dayExpired = 190) { if ($this->rpc !== null) { return $this->rpc->initArgs(array('dayExpired' => $dayExpired))->send(__FUNCTION__); } else { $dt = \Sooh\Base\Time::getInstance()->getInstance()->timestamp(-$dayExpired); $this->getDB()->delRecords($this->tbname, array('ymdh<' => date('YmdH', $dt))); } }