Ken 1 Minggu lalu
induk
melakukan
e944befbb9

+ 3 - 2
app/Http/Controllers/Controller.php

@@ -6,6 +6,7 @@ use App\Constants\HttpStatus;
 use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 use Illuminate\Foundation\Bus\DispatchesJobs;
 use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Http\JsonResponse;
 use Illuminate\Routing\Controller as BaseController;
 use Illuminate\Support\Facades\App;
 
@@ -93,7 +94,7 @@ class Controller extends BaseController
         $this->lang = $lang;
     }
 
-    protected function success($data = [], $msg = '')
+    protected function success($data = [], $msg = ''): JsonResponse
     {
         return response()->json([
             'code' => HttpStatus::OK,
@@ -104,7 +105,7 @@ class Controller extends BaseController
         ]);
     }
 
-    protected function error($code, string $msg = '', $data = [])
+    protected function error($code, string $msg = '', $data = []): JsonResponse
     {
         $code = intval($code);
         if ($code === 0) $code = -1;

+ 89 - 0
app/Http/Controllers/admin/ActivityReward.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace App\Http\Controllers\admin;
+
+use App\Constants\HttpStatus;
+use App\Http\Controllers\Controller;
+use App\Services\ActivityRewardService;
+use App\Services\RoleService;
+use Illuminate\Http\JsonResponse;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Validation\ValidationException;
+use Exception;
+use App\Models\ActivityReward as ActivityRewardModel;
+
+class ActivityReward extends Controller
+{
+    public function index(): JsonResponse
+    {
+        try {
+            $params = request()->validate([
+                'page' => ['required', 'integer', 'min:1'],
+                'limit' => ['required', 'integer', 'min:1'],
+                'title' => ['nullable', 'string'],
+            ]);
+            $page = request()->input('page', 1);
+            $limit = request()->input('limit', 10);
+            $where = ActivityRewardService::getWhere($params);
+            $query = ActivityRewardModel::where($where);
+
+            $count = $query->count();
+            $list = $query->orderByDesc('id')
+                ->forPage($page, $limit)->get()->toArray();
+
+            $result = ['total' => $count, 'data' => $list];
+        } catch (ValidationException $e) {
+            return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
+        } catch (Exception $e) {
+            return $this->error($e->getCode(), $e->getMessage());
+        }
+        return $this->success($result);
+    }
+
+
+    public function store()
+    {
+        DB::beginTransaction();
+        try {
+            $params = request()->validate([
+                'id' => ['nullable', 'integer', 'min:1'],
+                'title' => ['required', 'string', 'min:1', 'max:140'],
+                'gift_amount' => ['required', 'numeric', 'min:0.01', 'regex:/^\d+(\.\d{1,2})?$/'],
+                'flow_amount' => ['required', 'numeric', 'min:0', 'regex:/^\d+(\.\d{1,2})?$/'],
+                'participant_count' => ['required', 'integer', 'min:0'],
+                'activity_total' => ['required', 'integer', 'min:-1'],
+                'maximum_participation' => ['required', 'integer', 'min:0'],
+                'start_time' => ['required', 'date', 'date_format:Y-m-d'],
+                'end_time' => ['required', 'date', 'date_format:Y-m-d'],
+            ]);
+            ActivityRewardService::submit($params);
+            DB::commit();
+        } catch (ValidationException $e) {
+            DB::rollBack();
+            return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
+        } catch (Exception $e) {
+            DB::rollBack();
+            return $this->error($e->getCode(), $e->getMessage());
+        }
+        return $this->success();
+    }
+
+    public function destroy()
+    {
+        try {
+            request()->validate([
+                'id' => ['required', 'integer', 'min:1'],
+            ]);
+            $id = request()->input('id');
+            ActivityRewardService::deleteAll(['id' => $id]);
+            DB::commit();
+        } catch (ValidationException $e) {
+            DB::rollBack();
+            return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
+        } catch (Exception $e) {
+            DB::rollBack();
+            return $this->error($e->getCode(), $e->getMessage());
+        }
+        return $this->success([], '删除成功');
+    }
+}

+ 1 - 1
app/Http/Controllers/admin/Balance.php

@@ -47,7 +47,7 @@ class Balance extends Controller
         } catch (ValidationException $e) {
             return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
         } catch (Exception $e) {
-            return $this->error(intval($e->getCode()));
+            return $this->error($e->getCode(),$e->getMessage());
         }
         return $this->success($data);
     }

+ 27 - 0
app/Models/ActivityReward.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Models;
+
+use Carbon\Carbon;
+
+class ActivityReward extends BaseModel
+{
+    protected $table = 'activity_rewards';
+    protected $fillable = [
+        'title', 'gift_amount', 'flow_amount', 'participant_count'
+        , 'activity_total', 'maximum_participation'
+        , 'start_time', 'end_time'
+        ,
+    ];
+
+    protected function getStartTimeAttribute($value): string
+    {
+        return date('Y-m-d', $value);
+    }
+
+    protected function getEndTimeAttribute($value): string
+    {
+        return date('Y-m-d', $value);
+    }
+
+}

+ 64 - 0
app/Services/ActivityRewardService.php

@@ -0,0 +1,64 @@
+<?php
+
+namespace App\Services;
+
+use App\Constants\HttpStatus;
+use App\Models\ActivityReward;
+use App\Models\Role;
+use Exception;
+
+class ActivityRewardService extends BaseService
+{
+
+    public static string $MODEL = ActivityReward::class;
+
+    /**
+     * @description: 查询单条数据
+     * @param array $search
+     * @return ActivityReward|null
+     */
+    public static function findOne(array $search): ActivityReward|null
+    {
+        return static::$MODEL::where(static::getWhere($search))->first();
+    }
+
+    public static function getWhere(array $search = []): array
+    {
+        $where = [];
+        if (isset($search['title']) && !empty($search['title'])) {
+            $where[] = ['title', 'like', "%{$search['title']}%"];
+        }
+        return $where;
+    }
+
+    public static function deleteAll(array $search = []): bool
+    {
+        $count = static::$MODEL::where(static::getWhere($search))->delete();
+        if ($count < 1) throw new Exception('删除失败',HttpStatus::CUSTOM_ERROR);
+        return true;
+    }
+
+    /**
+     * Update or create
+     * @param array $params
+     * @return bool
+     * @throws Exception
+     */
+    public static function submit(array $params = []): bool
+    {
+        if (isset($params['start_time']))
+            $params['start_time'] = strtotime($params['start_time'] . " 00:00:00");
+        if (isset($params['end_time']))
+            $params['end_time'] = strtotime($params['end_time'] . " 23:59:59");
+
+
+        if (!empty($params['id'])) {
+            $info = static::findOne(['id' => $params['id']]);
+            if (!$info) throw new Exception("操作失败",HttpStatus::CUSTOM_ERROR);
+            $info->update($params);
+        } else {
+            static::$MODEL::create($params);
+        }
+        return true;
+    }
+}

+ 1 - 1
app/Services/BalanceLogService.php

@@ -7,7 +7,7 @@ use App\Models\BalanceLog;
 // 余额额变动记录
 class BalanceLogService extends BaseService
 {
-    public static $MODEL = BalanceLog::class;
+    public static string $MODEL = BalanceLog::class;
     public static array $manualRecharge = ['人工充值', '注册赠送', '优惠活动'];
     public static array $RW = [
         '充值', '人工充值', '三方充值', '注册赠送', '优惠活动',

+ 11 - 3
app/Services/BaseService.php

@@ -2,6 +2,7 @@
 
 namespace App\Services;
 
+use App\Models\ActivityReward;
 use Endroid\QrCode\Builder\Builder;
 use Endroid\QrCode\Writer\PngWriter;
 use Telegram\Bot\Api;
@@ -11,22 +12,29 @@ use Illuminate\Support\Facades\Log;
 use App\Jobs\SendTelegramMessageJob;
 use App\Jobs\SendTelegramGroupMessageJob;
 
-class BaseService
+abstract class BaseService
 {
     const YES = 1;
     const NOT = 0;
 
-    public static $MODEL = "";
+    public static string $MODEL = "";
 
     /**
      * @description: 模型
-     * @return {string}
+     * @return string
      */
     public static function model(): string
     {
         return static::$MODEL;
     }
 
+    /**
+     * @description: 获取查询条件
+     * @param array $search
+     * @return array
+     */
+    abstract public static function getWhere(array $search = []): array;
+
     /**
      * @description: 枚举
      * @return {*}

+ 1 - 5
app/Services/BetService.php

@@ -119,11 +119,7 @@ class BetService extends BaseService
         return '';
     }
 
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
+
     public static function getWhere(array $search = []): array
     {
         $where = [];

+ 7 - 2
app/Services/PcIssueService.php

@@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Log;
 
 class PcIssueService extends BaseService
 {
-    public static $MODEL = PcIssue::class;
+    public static string $MODEL = PcIssue::class;
 
 
     public static function index(): void
@@ -52,7 +52,7 @@ class PcIssueService extends BaseService
 
                     } else {
                         $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
-                        if ($maintenanceSwitch !=1 && $pc28Switch == 1) {
+                        if ($maintenanceSwitch != 1 && $pc28Switch == 1) {
                             self::asyncBettingGroupNotice($text, $buttons, $image);
                             Cache::put('issue_countdown_' . $info->issue_no, true, 60); // 缓存50秒,防止多次发送
                         }
@@ -407,4 +407,9 @@ class PcIssueService extends BaseService
     }
 
 
+    public static function getWhere(array $search = []): array
+    {
+        // TODO: Implement getWhere() method.
+        return [];
+    }
 }

+ 6 - 0
app/Services/PublicService.php

@@ -91,4 +91,10 @@ class PublicService extends BaseService
         $user->save();
         return $user;
     }
+
+    public static function getWhere(array $search = []): array
+    {
+        // TODO: Implement getWhere() method.
+        return [];
+    }
 }

+ 1 - 1
app/Services/RebateService.php

@@ -9,7 +9,7 @@ use Carbon\Carbon;
 class RebateService extends BaseService
 {
 
-    public static $MODEL = Rebate::class;
+    public static string $MODEL = Rebate::class;
 
     /**
      * @description: 获取查询条件

+ 41 - 0
database/migrations/2026_01_22_094348_create_activity_rewards.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('activity_rewards', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
+            $table->id();
+            $table->string('title', 150)->comment('活动名称');
+            $table->decimal('gift_amount', 10, 2)->comment('赠送金额');
+            $table->decimal('flow_amount', 10, 2)->comment('打码量');
+            $table->integer('participant_count')->default(0)->comment('已参与人数');
+            $table->integer('activity_total')->comment('活动总数量;-1表示不限量');
+            $table->integer('maximum_participation')->comment('每人最多可参与次数;0表示不限制');
+            $table->integer('start_time')->comment('开始时间');
+            $table->integer('end_time')->comment('结束时间');
+
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('activity_rewards');
+    }
+};

+ 4 - 0
lang/zh/validation.php

@@ -180,5 +180,9 @@ return [
         'price'                 => '售价',
         'start_time'            => '开始时间',
         'end_time'              => '结束时间',
+        'gift_amount'           => '赠送金额',
+        'flow_amount'           => '打码量',
+        'participant_count'     => '已参与人数',
+        'activity_total'        => '活动总数量',
     ],
 ];

+ 9 - 5
routes/admin.php

@@ -1,6 +1,7 @@
 <?php
 
 
+use App\Http\Controllers\admin\ActivityReward;
 use App\Http\Controllers\admin\Home;
 use Illuminate\Support\Facades\Route;
 use App\Http\Controllers\admin\Admin;
@@ -53,13 +54,20 @@ Route::middleware(['admin.jwt'])->group(function () {
         Route::get('/menu/tree', [Menu::class, 'tree']); // 菜单按钮树
 
 
+        Route::prefix('/ActivityReward')->group(function () {
+            Route::get('/', [ActivityReward::class, 'index']);
+            Route::post('/submit', [ActivityReward::class, 'store']);
+            Route::post('/delete', [ActivityReward::class, 'destroy']);
+        });
+
+
         Route::prefix('/pcIssue')->group(function () {
             Route::get('/', [PcIssue::class, 'index']);
             Route::post('/preDraw', [PcIssue::class, 'preDraw']);
         });
 
         Route::prefix('/home')->group(function () {
-            Route::get("/",[Home::class, 'index']);
+            Route::get("/", [Home::class, 'index']);
         });
 
         Route::prefix("/paymentOrder")->group(function () {
@@ -162,9 +170,6 @@ Route::middleware(['admin.jwt'])->group(function () {
             Route::post('/debiting', [Wallet::class, 'debiting']);
 
 
-
-
-
         });
 
         Route::prefix('/user')->group(function () {
@@ -175,7 +180,6 @@ Route::middleware(['admin.jwt'])->group(function () {
             Route::post('/banned', [User::class, 'banned']);
 
 
-
         });
 
         Route::prefix('/menu')->group(function () {