$config]); if (!empty($getItem)) array_push($getList, $getItem); $sign = new Sign(); $sign->user_id = $userID; $sign->sign_time = $time; $sign->is_remedy = self::NOT_REMEDY; $sign->week = $week; $sign->day = $day; if (!$sign->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); //任务记录 DailyTaskUtil::addTaskCount($userID, DailyTaskUtil::TYPE_SIGN, null, 1); AchievementUtil::addCount($userID, AchievementUtil::ID_SIGN, 1); // //累积奖励 // $list = Sign::findAllByUserIDAndWeek($userID, $week, SORT_DESC); // $continueCount = 0; // $lastIndex = 0; // for ($i = 0; $i < count($list); $i++) { // $index = CommUtil::getWeekIndex($list[$i]->sign_time); // if ($i == 0) $lastIndex = $index; // // if ($lastIndex - $index > 1) break; // // $continueCount++; // } // // $config = GameConfigServices::getParamByPath('sign.' . $continueCount); // if (empty($config)) return $getList; // // $allGetList = MoneyUtil::parseAllItem($config['accumulation_id'], 1, true, $userID, SystemLogUtil::FROM_TYPE_SIGN_CONTINUE_GIFT, ['config' => $config]); // $getList = array_merge($getList, $allGetList); return $getList; }, [$userID], RedisKeyUtil::lockSign($userID)); }, [$userID]); } /** * 补签 * @param $userID * @throws StatusException */ public static function remedy($userID) { SafeUtil::dbOperate(function ($userID) { SafeUtil::redisLockOperate(function ($userID) { $week = CommUtil::getWeek(time()); //扣道具 $itemID = GameConfigServices::getItemIDByType2(ItemServices::ITEM_TYPE2_DEMEDY); $log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_ITEM, $itemID, -1, SystemLogUtil::FROM_TYPE_SIGN_DEMEDY, []); MoneyUtil::checkAndModifyNum($userID, $itemID, false, -1, $log); //补签 $list = Sign::findAllByUserIDAndWeek($userID, $week, SORT_DESC); $time = time() - 3600 * 24; $weekIndex = CommUtil::getWeekIndex($time); $hasRemedy = false; for ($i = 0; $i < count($list); $i++) { $index = CommUtil::getWeekIndex($list[$i]->sign_time); if ($index == CommUtil::getWeekIndex(time())) continue; if ($weekIndex == $index) { $weekIndex--; $time -= 3600 * 24;//减一天时间 continue; } break; } if ($weekIndex >= 0) { //补签 $sign = new Sign(); $sign->user_id = $userID; $sign->sign_time = $time; $sign->is_remedy = self::REMEDY; $sign->week = $week; $sign->day = CommUtil::dayStr($time); if (!$sign->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); $hasRemedy = true; } if (!$hasRemedy) throw new StatusException(ResultStatusServices::RS_SIGN_NOT_NEED_REMEDY); }, [$userID], RedisKeyUtil::lockSign($userID)); }, [$userID]); } /** * 领取连续签到奖励 * @param $userID * @return mixed */ public static function getContinueSignGift($userID, $count) { return SafeUtil::dbOperate(function ($userID, $count) { return SafeUtil::redisLockOperate(function ($userID, $count) { $count = (int)$count; if ($count <= 0) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR); $week = CommUtil::getWeek(time()); //累积奖励 $list = Sign::findAllByUserIDAndWeek($userID, $week, SORT_DESC); $continueCount = 0; $lastIndex = 0; for ($i = 0; $i < count($list); $i++) { $index = CommUtil::getWeekIndex($list[$i]->sign_time); if ($i == 0) $lastIndex = $index; if ($lastIndex - $index > 1) break; $lastIndex = $index; $continueCount++; } if ($count > $continueCount) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR); if (!empty(SignContinueGift::findByUserIDAndWeekAndCount($userID, $week, $count))) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR); $config = GameConfigServices::getParamByPath('sign.' . $count); if (empty($config)) throw new StatusException(ResultStatusServices::RS_NOT_FIND_IN_CONFIG); $signContinueGift = new SignContinueGift(); $signContinueGift->user_id = $userID; $signContinueGift->week = $week; $signContinueGift->count = $count; if (!$signContinueGift->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); $getList = MoneyUtil::parseAllItem($config['accumulation_id'], 1, true, $userID, SystemLogUtil::FROM_TYPE_SIGN_CONTINUE_GIFT, ['config' => $config]); return $getList; }, [$userID, $count], RedisKeyUtil::lockSign($userID)); }, [$userID, $count]); } }