exp += $exp; while (true) { if ($vip->level == GameConfigServices::getMaxVipLevel()) { if (!$vip->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); return $vip; } $config = GameConfigServices::getParamByPath('vip_list.' . ($vip->level + 1)); if (empty($config)) throw new StatusException(ResultStatusServices::RS_NOT_FIND_IN_CONFIG); $needExp = (int)$config['recharge_amount']; if ($vip->exp >= $needExp) { //升级 $vip->level++; $vip->exp = $vip->exp - $needExp; if ($vip->exp < 0) $vip->exp = 0; //清除领取记录 $vip->is_get_fix_gift = VipUtil::NOT_GET_GIFT; $vip->is_get_week_gift = VipUtil::NOT_GET_GIFT; $vip->last_get_week_gift_time = 0; } else { break; } } if (!$vip->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); return $vip; }, [$userID, $exp], RedisKeyUtil::lockVip($userID)); }, [$userID, $exp]); } public static function getGift($userID) { SafeUtil::dbOperate(function ($userID) { SafeUtil::redisLockOperate(function ($userID) { $vip = Vip::findByUserID($userID); $change = false; //固定礼包 if ($vip->is_get_fix_gift == VipUtil::NOT_GET_GIFT && $vip->level > 0) { $config = GameConfigServices::getParamByPath('vip_list.' . $vip->level); if (empty($config)) throw new StatusException(ResultStatusServices::RS_NOT_FIND_IN_CONFIG); MoneyUtil::parseItem($config['fixed_reward_id'], 1, true, $userID, SystemLogUtil::FROM_TYPE_VIP_FIX_GIFT, ['config' => $config]); $vip->is_get_fix_gift = VipUtil::GET_GIFT; $change = true; } //周礼包 if (CommUtil::getWeek(time()) != CommUtil::getWeek($vip->last_get_week_gift_time)) $vip->is_get_week_gift = VipUtil::NOT_GET_GIFT; if ($vip->is_get_week_gift == VipUtil::NOT_GET_GIFT && $vip->level > 0) { $config = GameConfigServices::getParamByPath('vip_list.' . $vip->level); if (empty($config)) throw new StatusException(ResultStatusServices::RS_NOT_FIND_IN_CONFIG); //领取物品 for ($i = 1; $i <= 3; $i++) { if (!isset($config['cycle_bonus_id' . $i])) continue; MoneyUtil::parseItem($config['cycle_bonus_id' . $i], 1, true, $userID, SystemLogUtil::FROM_TYPE_VIP_WEEK_GIFT, ['config' => $config]); } $vip->is_get_week_gift = VipUtil::GET_GIFT; $vip->last_get_week_gift_time = time(); $change = true; } if ($change && !$vip->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); }, [$userID], RedisKeyUtil::lockVip($userID)); }, [$userID]); } public static function getFixGift($userID) { SafeUtil::dbOperate(function ($userID) { SafeUtil::redisLockOperate(function ($userID) { $vip = Vip::findByUserID($userID); if ($vip->level == 0 || $vip->is_get_fix_gift == VipUtil::GET_GIFT) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR); $config = GameConfigServices::getParamByPath('vip_list.' . $vip->level); if (empty($config)) throw new StatusException(ResultStatusServices::RS_NOT_FIND_IN_CONFIG); MoneyUtil::parseItem($config['fixed_reward_id'], 1, true, $userID, SystemLogUtil::FROM_TYPE_VIP_FIX_GIFT, ['config' => $config]); $vip->is_get_fix_gift = VipUtil::GET_GIFT; if (!$vip->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); }, [$userID], RedisKeyUtil::lockVip($userID)); }, [$userID]); } public static function getWeekGift($userID) { SafeUtil::dbOperate(function ($userID) { SafeUtil::redisLockOperate(function ($userID) { $vip = Vip::findByUserID($userID); if ($vip->level == 0) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR); if (CommUtil::getWeek(time()) != CommUtil::getWeek($vip->last_get_week_gift_time)) $vip->is_get_week_gift = VipUtil::NOT_GET_GIFT; if ($vip->is_get_week_gift == VipUtil::GET_GIFT) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR); $config = GameConfigServices::getParamByPath('vip_list.' . $vip->level); if (empty($config)) throw new StatusException(ResultStatusServices::RS_NOT_FIND_IN_CONFIG); //领取物品 for ($i = 1; $i <= 3; $i++) { if (!isset($config['cycle_bonus_id' . $i])) continue; MoneyUtil::parseItem($config['cycle_bonus_id' . $i], 1, true, $userID, SystemLogUtil::FROM_TYPE_VIP_WEEK_GIFT, ['config' => $config]); } $vip->is_get_week_gift = VipUtil::GET_GIFT; $vip->last_get_week_gift_time = time(); if (!$vip->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); }, [$userID], RedisKeyUtil::lockVip($userID)); }, [$userID]); } }