|
|
@@ -9,6 +9,7 @@ use App\Models\Char\CharItem;
|
|
|
use App\Models\Char\CharFellow;
|
|
|
use App\Models\Char\CharQuest;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
+use App\Models\Char\CharQuest_History;
|
|
|
|
|
|
class CharController extends Controller
|
|
|
{
|
|
|
@@ -311,26 +312,41 @@ class CharController extends Controller
|
|
|
$data = $request->except($protected);
|
|
|
|
|
|
return $this->_updateAndRespond($item, $data, 'Item successfully updated.');
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Получение квеста персонажа по char_id и RecId.
|
|
|
+ * Поддерживается выбор таблицы (CharQuest или CharQuest_History) через опциональный параметр $table.
|
|
|
*
|
|
|
* @param string $char_id
|
|
|
* @param string $rec_id
|
|
|
+ * @param string|null $table
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
*/
|
|
|
- public function GetCharQuest(string $char_id, string $rec_id)
|
|
|
+
|
|
|
+ public function GetCharQuest(string $char_id, string $rec_id, ?string $table = null)
|
|
|
{
|
|
|
+ // По умолчанию используем CharQuest
|
|
|
+ $table = $table ?? 'CharQuest';
|
|
|
+
|
|
|
+ // Проверяем допустимость таблицы для данной операции
|
|
|
+ $allowedQuestTables = ['CharQuest', 'CharQuest_History'];
|
|
|
+ if (!in_array($table, $allowedQuestTables, true)) {
|
|
|
+ return response()->json(['code' => -1, 'msg' => 'Table not allowed for this operation.'], 400);
|
|
|
+ }
|
|
|
+
|
|
|
// Проверяем существование персонажа
|
|
|
if (!CharBase::find($char_id)) {
|
|
|
return response()->json(['code' => -2, 'msg' => 'Character not found.'], 404);
|
|
|
}
|
|
|
|
|
|
- // Ищем квест по Owner и RecId
|
|
|
- $quest = CharQuest::where('Owner', $char_id)
|
|
|
- ->where('RecId', $rec_id)
|
|
|
- ->first();
|
|
|
+ // Получаем конфиг модели по таблице и делаем выборку по Owner и RecId
|
|
|
+ $config = $this->resolveTable($table);
|
|
|
+ $modelClass = $config['model'];
|
|
|
+
|
|
|
+ $quest = $modelClass::where('Owner', $char_id)
|
|
|
+ ->where('RecId', $rec_id)
|
|
|
+ ->first();
|
|
|
|
|
|
if (!$quest) {
|
|
|
return response()->json([
|
|
|
@@ -348,23 +364,38 @@ class CharController extends Controller
|
|
|
|
|
|
/**
|
|
|
* Обновление квеста персонажа по char_id и RecId.
|
|
|
+ * Поддерживается выбор таблицы (CharQuest или CharQuest_History) через опциональный параметр $table.
|
|
|
*
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
* @param string $char_id
|
|
|
* @param string $rec_id
|
|
|
+ * @param string|null $table
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
*/
|
|
|
- public function UpdateCharQuest(Request $request, string $char_id, string $rec_id)
|
|
|
+
|
|
|
+ public function UpdateCharQuest(Request $request, string $char_id, string $rec_id, ?string $table = null)
|
|
|
{
|
|
|
+ // По умолчанию используем CharQuest
|
|
|
+ $table = $table ?? 'CharQuest';
|
|
|
+
|
|
|
+ // Проверяем допустимость таблицы для данной операции
|
|
|
+ $allowedQuestTables = ['CharQuest', 'CharQuest_History'];
|
|
|
+ if (!in_array($table, $allowedQuestTables, true)) {
|
|
|
+ return response()->json(['code' => -1, 'msg' => 'Table not allowed for this operation.'], 400);
|
|
|
+ }
|
|
|
+
|
|
|
// Проверяем существование персонажа
|
|
|
if (!CharBase::find($char_id)) {
|
|
|
return response()->json(['code' => -2, 'msg' => 'Character not found.'], 404);
|
|
|
}
|
|
|
|
|
|
- // Ищем квест по Owner и RecId
|
|
|
- $quest = CharQuest::where('Owner', $char_id)
|
|
|
- ->where('RecId', $rec_id)
|
|
|
- ->first();
|
|
|
+ // Получаем конфиг модели по таблице и делаем выборку по Owner и RecId
|
|
|
+ $config = $this->resolveTable($table);
|
|
|
+ $modelClass = $config['model'];
|
|
|
+
|
|
|
+ $quest = $modelClass::where('Owner', $char_id)
|
|
|
+ ->where('RecId', $rec_id)
|
|
|
+ ->first();
|
|
|
|
|
|
if (!$quest) {
|
|
|
return response()->json([
|
|
|
@@ -403,6 +434,7 @@ class CharController extends Controller
|
|
|
'CharFellow' => ['key' => 'Owner', 'model' => CharFellow::class, 'pk' => 'FellowID'],
|
|
|
'CharCashItem_OutputBox' => ['key' => 'Owner', 'model' => CharCashItem_OutputBox::class, 'pk' => 'ItemDBIndex'],
|
|
|
'CharQuest' => ['key' => 'Owner', 'model' => CharQuest::class, 'pk' => 'RecId'],
|
|
|
+ 'CharQuest_History' => ['key' => 'Owner', 'model' => CharQuest_History::class, 'pk' => 'RecId'],
|
|
|
];
|
|
|
|
|
|
|