lip 1 هفته پیش
والد
کامیت
77c35cb4d6
3فایلهای تغییر یافته به همراه146 افزوده شده و 1 حذف شده
  1. 121 0
      app/Http/Controllers/admin/Banner.php
  2. 24 0
      app/Models/Banner.php
  3. 1 1
      app/Models/GameplayRule.php

+ 121 - 0
app/Http/Controllers/admin/Banner.php

@@ -0,0 +1,121 @@
+<?php
+
+namespace App\Http\Controllers\admin;
+
+use App\Constants\HttpStatus;
+use App\Http\Controllers\Controller;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Validation\ValidationException;
+use Exception;
+use App\Models\Banner as BannerModel;
+
+class Banner extends Controller
+{
+
+    /**
+     * @api {get} /admin/banner 轮播图列表
+     * @apiGroup 轮播图管理
+     * @apiUse result
+     * @apiUse header
+     * @apiVersion 1.0.0
+     *
+     * @apiParam {int} [page=1]
+     * @apiParam {int} [limit=10]
+     *
+     */
+    function index()
+    {
+        try {
+            $page = request()->input('page', 1);
+            $limit = request()->input('limit', 15);
+            $query = new BannerModel();
+            $count = $query->count();
+            $list = $query
+                ->forPage($page, $limit)
+                ->orderByDesc('create_time')
+                ->get();
+        } catch (ValidationException $e) {
+            return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
+        } catch (Exception $e) {
+            return $this->error(intval($e->getCode()));
+        }
+        return $this->success(['total' => $count, 'data' => $list]);
+    }
+
+    /**
+     * @api {post} /admin/banner/update 修改
+     * @apiDescription 更新或者新增都用这个接口
+     * @apiGroup 轮播图管理
+     * @apiUse result
+     * @apiUse header
+     * @apiVersion 1.0.0
+     *
+     */
+    public function update()
+    {
+        DB::beginTransaction();
+        try {
+            $params = request()->validate([
+                'id' => ['required', 'integer', 'min:0', 'max:99999999'],
+                'title' => ['required'],
+                'image' => ['required'],
+                'link' => ['nullable'],
+                'type' => ['nullable'],
+                'sort' => ['nullable', 'integer', 'min:0', 'max:99999999'],
+            ]);
+            $id = request()->input('id', 0);
+
+            BannerModel::updateOrCreate(
+                ['id' => $id],
+                ['title' => $params['title']],
+                ['image' => $params['image']],
+                ['link' => $params['link']],
+                ['type' => $params['type']],
+                ['sort' => $params['sort']],
+            );
+            DB::commit();
+        } catch (ValidationException $e) {
+            DB::rollBack();
+            return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
+        } catch (Exception $e) {
+            DB::rollBack();
+            return $this->error(intval($e->getCode()), $e->getMessage());
+        }
+        return $this->success();
+    }
+
+
+    /**
+     * @api {post} /admin/banner/delete 删除
+     * @apiGroup 轮播图管理
+     * @apiUse result
+     * @apiUse header
+     * @apiVersion 1.0.0
+     *
+     * @apiParam {int} id 要删除的ID
+     *
+     */
+    function destroy()
+    {
+        DB::beginTransaction();
+        try {
+            request()->validate([
+                'id' => ['required', 'integer', 'min:1', 'max:99999999'],
+            ]);
+            $id = request()->input('id', 0);
+            $info = BannerModel::where('id', $id)->first();
+            if (!$info) throw new Exception("数据不存在", HttpStatus::CUSTOM_ERROR);
+            $info->delete();
+            DB::commit();
+        } catch (ValidationException $e) {
+            DB::rollBack();
+            return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
+        } catch (Exception $e) {
+            DB::rollBack();
+            return $this->error(intval($e->getCode()));
+        }
+        return $this->success();
+    }
+
+
+}

+ 24 - 0
app/Models/Banner.php

@@ -0,0 +1,24 @@
+<?php
+namespace App\Models;
+
+
+// 关键:导入正确的 Builder 类(Eloquent 构建器)
+use Illuminate\Database\Eloquent\Builder;
+
+class Banner extends BaseModel
+{
+    protected $fillable = ['title', 'image', 'link' ,'type' ,'sort' ,'cny_rate' ];
+    public function newQuery($excludeDeleted = true): Builder
+    {
+        // 1. 获取原生 Eloquent 查询构建器
+        $query = parent::newQuery($excludeDeleted);
+        
+        // 2. 强制清空当前连接的表前缀(从根源阻止拼接)
+        $this->getConnection()->setTablePrefix('');
+        
+        // 3. 强制指定查询的表名为 la_banner
+        $query->from('la_banner');
+        
+        return $query;
+    }
+}

+ 1 - 1
app/Models/GameplayRule.php

@@ -3,7 +3,7 @@
 namespace App\Models;
 class GameplayRule extends BaseModel
 {
-    protected $table = 'bot_gameplay_rules';
+    protected $table = 'gameplay_rules';
     protected $fillable = [
         'keywords',
         'groups',