|
|
@@ -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([], '删除成功');
|
|
|
+ }
|
|
|
+}
|