|
|
@@ -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) {
|