Ken 1 هفته پیش
والد
کامیت
f04cb70167

+ 19 - 3
app/Http/Controllers/api/ActivityReward.php

@@ -23,19 +23,35 @@ class ActivityReward extends BaseController
             ]);
             $memberId = request()->input('member_id');
 
-            if (ActivityUser::where('member_id', $memberId)
-                ->where('status', 0)->exists()) {
+            if (ActivityUser::where('member_id', $memberId)->where('status', 0)->exists()) {
                 throw new Exception('完成活动才可以参与新活动', HttpStatus::CUSTOM_ERROR);
             }
             $activityId = request()->input('activity_id');
-            $time = time();
 
+            if (ActivityUser::where('member_id', $memberId)->where('activity_id', $activityId)->exists()) {
+                throw new Exception('已参与过此活动,每个活动仅可参加一次', HttpStatus::CUSTOM_ERROR);
+            }
+            $time = time();
             $activity = ActivityRewardService::findOne([
                 'start_time' => ['<=', $time],
                 'end_time' => ['>=', $time],
                 'status' => ActivityRewardModel::STATUS_UP,
                 'id' => $activityId
             ]);
+            if (!$activity) {
+                throw new Exception('活动不存在', HttpStatus::CUSTOM_ERROR);
+            }
+            ActivityUser::create([
+                'activity_id' => $activityId,
+                'title' => $activity->title,
+                'sub_title' => $activity->sub_title,
+                'start_time' => $activity->start_time,
+                'end_time' => $activity->end_time,
+                'detail_image' => $activity->detail_image,
+                'part_in_time' => $time,
+                'member_id' => $memberId,
+                'status' => 0
+            ]);
 
 
         } catch (ValidationException $e) {

+ 9 - 1
app/Models/ActivityReward.php

@@ -5,7 +5,15 @@ namespace App\Models;
 use App\Constants\Util;
 use Illuminate\Database\Eloquent\Relations\HasMany;
 
-
+/**
+ * @property string $title
+ * @property string sub_title
+ * @property string detail_image
+ * @property string start_time
+ * @property string end_time
+ * @property string status
+ *
+ */
 class ActivityReward extends BaseModel
 {
     const STATUS_UP = 1;

+ 18 - 2
database/migrations/2026_01_23_144045_update_activity_user.php

@@ -13,9 +13,25 @@ return new class extends Migration
      */
     public function up()
     {
-        Schema::table('activity_user', function (Blueprint $table) {
+        Schema::dropIfExists('activity_rewards');
+
+        Schema::create('activity_user', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
+            $table->id();
+            $table->integer('activity_id')->comment('活动ID');
+            $table->string('title', 150)->comment('活动名称');
+            $table->string('sub_title', 150)->comment('副标题');
+            $table->integer('start_time')->comment('开始时间');
+            $table->integer('end_time')->comment('结束时间');
+            $table->string('detail_image')->comment('活动详情图片');
+            $table->integer('part_in_time')->comment('参与时间');
+            $table->string('member_id')->comment('会员ID');
             $table->tinyInteger('status')->default(0)->comment('0互动进行中,1活动结束');
+            $table->timestamps();
         });
+
+
+
     }
 
     /**
@@ -25,6 +41,6 @@ return new class extends Migration
      */
     public function down()
     {
-        //
+        Schema::dropIfExists('activity_user');
     }
 };