|
|
@@ -8,6 +8,7 @@ use App\Models\Char\CharCashItem_OutputBox;
|
|
|
use App\Models\Char\CharItem;
|
|
|
use App\Models\Char\CharFellow;
|
|
|
use App\Models\Char\CharQuest;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class CharController extends Controller
|
|
|
{
|
|
|
@@ -312,6 +313,72 @@ class CharController extends Controller
|
|
|
return $this->_updateAndRespond($item, $data, 'Item successfully updated.');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Получение квеста персонажа по char_id и RecId.
|
|
|
+ *
|
|
|
+ * @param string $char_id
|
|
|
+ * @param string $rec_id
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ */
|
|
|
+ public function GetCharQuest(string $char_id, string $rec_id)
|
|
|
+ {
|
|
|
+ // Проверяем существование персонажа
|
|
|
+ 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();
|
|
|
+
|
|
|
+ if (!$quest) {
|
|
|
+ return response()->json([
|
|
|
+ 'code' => -3,
|
|
|
+ 'msg' => 'Quest not found for this character.',
|
|
|
+ ], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ return response()->json([
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => 'Quest successfully received.',
|
|
|
+ 'data' => $quest,
|
|
|
+ ], 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Обновление квеста персонажа по char_id и RecId.
|
|
|
+ *
|
|
|
+ * @param \Illuminate\Http\Request $request
|
|
|
+ * @param string $char_id
|
|
|
+ * @param string $rec_id
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ */
|
|
|
+ public function UpdateCharQuest(Request $request, string $char_id, string $rec_id)
|
|
|
+ {
|
|
|
+ // Проверяем существование персонажа
|
|
|
+ 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();
|
|
|
+
|
|
|
+ if (!$quest) {
|
|
|
+ return response()->json([
|
|
|
+ 'code' => -3,
|
|
|
+ 'msg' => 'Quest not found for this character.',
|
|
|
+ ], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Защищаем поля Owner и RecId от изменения
|
|
|
+ $protected = ['Owner', 'RecId'];
|
|
|
+ $data = $request->except($protected);
|
|
|
+
|
|
|
+ return $this->_updateAndRespond($quest, $data, 'Quest successfully updated.');
|
|
|
+ }
|
|
|
|
|
|
//------------------------------ ПРИВАТНЫЕ МЕТОДЫ -----------------------------------------
|
|
|
/**
|
|
|
@@ -335,7 +402,7 @@ class CharController extends Controller
|
|
|
'CharItem' => ['key' => 'Owner', 'model' => CharItem::class, 'pk' => 'CharItemID'],
|
|
|
'CharFellow' => ['key' => 'Owner', 'model' => CharFellow::class, 'pk' => 'FellowID'],
|
|
|
'CharCashItem_OutputBox' => ['key' => 'Owner', 'model' => CharCashItem_OutputBox::class, 'pk' => 'ItemDBIndex'],
|
|
|
- 'CharQuest' => ['key' => 'Owner', 'model' => CharQuest::class],
|
|
|
+ 'CharQuest' => ['key' => 'Owner', 'model' => CharQuest::class, 'pk' => 'RecId'],
|
|
|
];
|
|
|
|
|
|
|
|
|
@@ -375,6 +442,7 @@ class CharController extends Controller
|
|
|
try {
|
|
|
$ok = $model->update($filteredData);
|
|
|
} catch (\Throwable $e) {
|
|
|
+ Log::error('Database error while updating record:', ['error' => $e->getMessage()]);
|
|
|
return response()->json([
|
|
|
'code' => -7,
|
|
|
'msg' => 'Database error while updating record.',
|