|
|
@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
|
|
|
use Illuminate\Http\Request;
|
|
|
use App\Models\Char\CharBase;
|
|
|
use App\Models\Char\CharCashItem_OutputBox;
|
|
|
+use App\Models\Char\CharItem;
|
|
|
+use App\Models\Char\CharFellow;
|
|
|
|
|
|
class CharController extends Controller
|
|
|
{
|
|
|
@@ -145,4 +147,46 @@ class CharController extends Controller
|
|
|
'msg' => 'Items successfully sent.'
|
|
|
], 200);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Получение всех данных персонажа из указанной таблицы.
|
|
|
+ *
|
|
|
+ * @param int $char_id
|
|
|
+ * @param string $table_name
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ */
|
|
|
+ public function GetCharacterData($char_id, $table_name)
|
|
|
+ {
|
|
|
+ // Белый список доступных моделей/таблиц
|
|
|
+ $allowed_tables = [
|
|
|
+ 'CharBase' => ['key' => 'DBKey', 'model' => CharBase::class],
|
|
|
+ 'CharItem' => ['key' => 'Owner', 'model' => CharItem::class],
|
|
|
+ 'CharFellow' => ['key' => 'Owner', 'model' => CharFellow::class],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (!array_key_exists($table_name, $allowed_tables)) {
|
|
|
+ return response()->json(['code' => -1, 'msg' => 'Table not allowed or does not exist.'], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $modelClass = $allowed_tables[$table_name]['model'];
|
|
|
+ $key = $allowed_tables[$table_name]['key'];
|
|
|
+
|
|
|
+ // Проверка, существует ли персонаж в CharBase
|
|
|
+ $character = CharBase::find($char_id);
|
|
|
+ if (!$character) {
|
|
|
+ return response()->json(['code' => -2, 'msg' => 'Character not found.'], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $modelClass::where($key, $char_id)->get();
|
|
|
+
|
|
|
+ if ($data->isEmpty()) {
|
|
|
+ return response()->json(['code' => -3, 'msg' => 'No data found for this character in the specified table.'], 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ return response()->json([
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => 'Data successfully received.',
|
|
|
+ 'data' => $data
|
|
|
+ ], 200);
|
|
|
+ }
|
|
|
}
|