seven 2 天之前
父节点
当前提交
28e77d85a5

+ 121 - 0
app/Constants/GameplayRuleEnum

@@ -0,0 +1,121 @@
+<?php
+
+namespace App\Constants;
+
+// 玩法枚举
+class GameplayRuleEnum 
+{
+    public static $RULES = [
+        '组合' => [
+            '单',
+            '双',
+            '大',
+            '小',
+            '大单',
+            '大双',
+            '小单',
+            '小双',
+            '极大',
+            '极小',
+            '0操',
+            '1操',
+            '2操',
+            '3操',
+            '4操',
+            '5操',
+            '6操',
+            '7操',
+            '8操',
+            '9操',
+            '10操',
+            '11操',
+            '12操',
+            '13操',
+            '14操',
+            '15操',
+            '16操',
+            '17操',
+            '18操',
+            '19操',
+            '20操',
+            '21操',
+            '22操',
+            '23操',
+            '24操',
+            '25操',
+            '26操',
+            '27操',
+        ],
+        '尾数' => [
+            '0尾',
+            '1尾',
+            '2尾',
+            '3尾',
+            '4尾',
+            '5尾',
+            '6尾',
+            '7尾',
+            '8尾',
+            '9尾',
+            '尾大',
+            '尾小',
+            '尾单',
+            '尾双',
+            '尾大单',
+            '尾大双',
+            '尾小单',
+            '尾小双',
+        ],
+        '个位球' => [
+            'A大',
+            'A小',
+            'A单',
+            'A双',
+            'B大',
+            'B小',
+            'B单',
+            'B双',
+            'C大',
+            'C小',
+            'C单',
+            'C双',
+            '0A',
+            '1A',
+            '2A',
+            '3A',
+            '4A',
+            '5A',
+            '6A',
+            '7A',
+            '8A',
+            '9A',
+            '0B',
+            '1B',
+            '2B',
+            '3B',
+            '4B',
+            '5B',
+            '6B',
+            '7B',
+            '8B',
+            '9B',
+            '0C',
+            '1C',
+            '2C',
+            '3C',
+            '4C',
+            '5C',
+            '6C',
+            '7C',
+            '8C',
+            '9C',
+        ],
+        '多段' => [
+            '一段',
+            '二段',
+            '三段',
+            '四段',
+        ]
+
+    ];
+}

+ 123 - 0
app/Http/Controllers/admin/GameplayRule.php

@@ -0,0 +1,123 @@
+<?php
+
+
+namespace App\Http\Controllers\admin;
+
+use App\Constants\HttpStatus;
+use App\Http\Controllers\Controller;
+use App\Services\GameplayRuleService;
+use Exception;
+
+use Illuminate\Support\Facades\DB;
+use Illuminate\Validation\ValidationException;
+
+class GameplayRule extends Controller
+{
+
+
+    /**
+     * @api {get} /admin/role 角色列表
+     * @apiGroup 玩法规则管理
+     *
+     * @apiUse result
+     * @apiUse header
+     * @apiVersion 1.0.0
+     *
+     * @apiParam {int} [page=1]
+     * @apiParam {int} [limit=10]
+     * @apiParam {string} [display_name] 角色名称
+     *
+     * @apiSuccess (data) {Object} data
+     * @apiSuccess (data) {int} data.total 数量
+     * @apiSuccess (data) {Object[]} data.data 列表
+     * @apiSuccess (data) {int} data.data.id
+     * @apiSuccess (data) {string} data.data.display_name 角色名称(显示用)
+     * @apiSuccess (data) {string} data.data.description 角色描述
+     * @apiSuccess (data) {array} data.data.menus_ids 角色拥有的菜单
+     * @apiSuccess (data) {string} data.data.updated_at
+     * @apiSuccess (data) {string} data.data.created_at
+     */
+    public function index()
+    {
+        try {
+            request()->validate([
+                'title' => ['nullable', 'string'],
+                'permission_name' => ['nullable', 'string'],
+            ]);
+            $search = request()->all();
+            $result = GameplayRuleService::paginate($search);
+        } catch (ValidationException $e) {
+            return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
+        } catch (Exception $e) {
+            return $this->error(intval($e->getCode()));
+        }
+        return $this->success($result);
+    }
+
+
+    /**
+     * @api {post} /admin/role/submit 修改角色
+     * @apiGroup 玩法规则管理
+     *
+     * @apiUse result
+     * @apiUse header
+     * @apiVersion 1.0.0
+     *
+     * @apiParam {int} id 角色ID
+     * @apiParam {string} display_name 角色名称(显示用)
+     * @apiParam {string} description 角色描述
+     * @apiParam {array} [menus_ids] 角色菜单
+     */
+    public function store()
+    {
+        // try {
+            $params = request()->all();
+
+            $validator = [
+                'keywords' => 'required|string|max:50',
+                'group'    => 'required|string|max:50',
+                'maxinum'  => 'required|integer|min:1',
+                'mininum'  => 'required|integer|min:0',
+                'odds'     => 'required|numeric|min:0',
+            ];
+
+            request()->validate($validator);
+
+            $ret = GameplayRuleService::submit($params);
+            if ($ret['code'] == GameplayRuleService::NOT) {
+                return $this->error($ret['code'], $ret['msg']);
+            }
+        // } catch (ValidationException $e) {
+        //     return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
+        // } catch (Exception $e) {
+        //     return $this->error(intval($e->getCode()));
+        // }
+        return $this->success([], $ret['msg']);
+
+    }
+
+    /**
+     * @api {post} /admin/role/delete 删除角色
+     * @apiGroup 玩法规则管理
+     *
+     * @apiUse result
+     * @apiUse header
+     * @apiVersion 1.0.0
+     *
+     * @apiParam {int} id 角色ID
+     */
+    public function destroy()
+    {
+        $id = request()->post('id');
+        // 示例:通过 ID 删除菜单
+        $info = GameplayRuleService::findOne(['id' => $id]);
+        if (!$info) {
+            return $this->error(0, '角色不存在');
+        }
+
+        $info->delete();
+
+        return $this->success([], '删除成功');
+    }
+
+}

+ 32 - 0
app/Models/GameplayRule.php

@@ -0,0 +1,32 @@
+<?php
+
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Foundation\Auth\User as Authenticatable;
+use Illuminate\Notifications\Notifiable;
+use Laravel\Sanctum\HasApiTokens;
+
+/**
+ * @mixin Builder
+ * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
+ */
+class GameplayRule extends Authenticatable
+{
+    use HasApiTokens, Notifiable;
+
+    protected $table = 'gameplay_rules';
+    protected $hidden = ['created_at', 'updated_at'];
+
+
+    protected function getCreatedAtAttribute($value)
+    {
+        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
+    }
+
+    protected function getUpdatedAtAttribute($value)
+    {
+        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
+    }
+}

+ 154 - 0
app/Services/GameplayRuleService.php

@@ -0,0 +1,154 @@
+<?php
+
+
+namespace App\Services;
+
+use App\Services\BaseService;
+use App\Models\GameplayRule;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
+use App\Services\BalanceLogService;
+use App\Constants\GameplayRuleEnum;
+
+/**
+ * 玩法规则服务类
+*/
+class GameplayRuleService extends BaseService 
+{
+    const CACHE_KEY = 'gameplay_rules_';
+
+    /**
+     * @description: 模型
+     * @return {string}
+     */    
+    public static function model() :string
+    {
+        return GameplayRule::class;
+    }
+
+    /**
+     * @description: 枚举
+     * @return {*}
+     */    
+    public static function enum() :string
+    {
+        return GameplayRuleEnum::class;
+    }
+
+    /**
+     * @description: 获取查询条件
+     * @param {array} $search 查询内容
+     * @return {array}
+     */    
+    public static function getWhere(array $search = []) :array
+    {
+        $where = [];
+        if(isset($search['group']) && !empty($search['group'])){
+            $where[] = ['group', '=', $search['group']];
+        }
+        if(isset($search['keywords']) && !empty($search['keywords'])){
+            $where[] = ['keywords', '=', $search['keywords']];
+        }
+        if(isset($search['id']) && !empty($search['id'])){
+            $where[] = ['id', '=', $search['id']];
+        }
+    
+        return $where;
+    }
+
+     /**
+     * @description: 查询单条数据
+     * @param array $search
+     * @return \App\Models\Coin|null
+     */
+    public static function findOne(array $search): ?GameplayRule
+    {
+        return self::model()::where(self::getWhere($search))->first();
+    }
+
+    /**
+     * @description: 查询所有数据
+     * @param array $search
+     * @return \Illuminate\Database\Eloquent\Collection
+     */
+    public static function findAll(array $search = [])
+    {
+        return self::model()::where(self::getWhere($search))->get();
+    }
+
+    /**
+     * @description: 分页查询
+     * @param array $search
+     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
+     */
+    public static function paginate(array $search = [])
+    {
+        $limit = isset($search['limit'])?$search['limit']:15;
+        $paginator = self::model()::where(self::getWhere($search))->paginate($limit);
+        return ['total' => $paginator->total(), 'data' => $paginator->items()];
+    }
+
+    /**
+     * @description: 
+     * @param {*} $params
+     * @return {*}
+     */    
+    public static function submit($params = [])
+    {
+        $result = false;
+        $msg['code'] = self::NOT;
+        $msg['msg'] = '';
+        
+        // 2. 判断是否是更新
+        if (!empty($params['id'])) {
+            // 更新
+            $info = self::findOne(['id'=>$params['id']] );
+            if (!$info) {
+                $msg['msg'] = '规则不存在!';
+            }else{
+                $result = $info->update($params);
+                $id = $params['id'];
+            }
+
+        } else {
+            // 创建
+            $result = $info = self::model()::create($params);
+            $id = $result->id;
+        }
+        
+       
+        if($result){
+           $msg['code'] = self::YES;
+           $msg['msg'] = '设置成功';
+        }else{
+            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
+        }
+
+        return $msg;
+    }
+
+    /**
+     * @description: 获取玩法规则
+     * @param string $keywords
+     * @return *
+     */
+    public static function getGameplayRules($keywords)
+    {
+        $cacheKey = self::CACHE_KEY . $keywords;
+        if (Cache::has($cacheKey)) {
+            return Cache::get($cacheKey);
+        }
+
+        $rules = self::model()::where('keywords', $keywords)->first();
+        if (!$rules) {
+            return null;
+        }
+
+        $rulesArray = $rules->toArray();
+        Cache::put($cacheKey, $rulesArray, 3600); // 缓存1小时
+
+        return $rulesArray;
+    }
+}

+ 17 - 0
sql/sql_prod.sql

@@ -410,5 +410,22 @@ CREATE TABLE `bot_user_game`  (
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
 
+
+-- ----------------------------
+-- Table structure for bot_gameplay_rules
+-- ----------------------------
+DROP TABLE IF EXISTS `bot_gameplay_rules`;
+CREATE TABLE `bot_gameplay_rules` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `maxinum` bigint(20) DEFAULT '0' COMMENT '最高',
+  `mininum` bigint(20) DEFAULT '0' COMMENT '最低',
+  `odds` decimal(10,2) DEFAULT '1.00' COMMENT '赔率',
+  `group` varchar(50) DEFAULT NULL COMMENT '规则分组',
+  `keywords` varchar(50) DEFAULT NULL COMMENT '玩法关键字',
+  `created_at` datetime DEFAULT NULL,
+  `updated_at` datetime DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='玩法规则';
+
 SET FOREIGN_KEY_CHECKS = 1;