/** * 道具发放回滚 * @param 原因说明 $msg * @param array $givedThisTime * @param string $accountId * @param \Lib\Items\Interfaces $_ignore_ * @return boolean */ public static function batchGive_rollback($msg, $givedThisTime, $accountId, $_ignore_ = null) { $allOk = true; foreach ($givedThisTime as $_ignore_) { if (false === $_ignore_->giveToUser_rollback($msg)) { \Prj\Loger::alarm('give ' . $_ignore_ . ' ToUser(' . $accountId . ')_rollback failed'); $allOk = false; } } return $allOk; }
/** * 签到 * @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); } } }