抽奖活动 每人每月至少一次抽奖机会
parent
8f28128f53
commit
0df36161d8
|
|
@ -10,6 +10,7 @@ use App\Models\DrawActivity;
|
||||||
use App\Models\DrawLog;
|
use App\Models\DrawLog;
|
||||||
use App\Models\DrawTicket;
|
use App\Models\DrawTicket;
|
||||||
use App\Services\DrawActivityService;
|
use App\Services\DrawActivityService;
|
||||||
|
use App\Services\DrawTicketService;
|
||||||
use Illuminate\Contracts\Cache\LockTimeoutException;
|
use Illuminate\Contracts\Cache\LockTimeoutException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
@ -29,16 +30,24 @@ class DrawActivityController extends Controller
|
||||||
|
|
||||||
if ($user = $request->user()) {
|
if ($user = $request->user()) {
|
||||||
// 当前用户的抽奖机会
|
// 当前用户的抽奖机会
|
||||||
$drawTicket = DrawTicket::where('draw_activity_id', $drawActivity->id)
|
$drawTicket = DrawTicket::where('draw_activity_id', $drawActivity->id)->where('user_id', $user->id)->first();
|
||||||
->where('user_id', $user->id)
|
|
||||||
->first();
|
// 保证每个用户, 每月至少一次 抽奖机会
|
||||||
|
if ($drawActivity->send_ticket_type == 2) {
|
||||||
|
$service = DrawTicketService::make();
|
||||||
|
if (!$drawTicket || ($drawTicket->updated_at->lt(now()->startOfMonth()) && $drawTicket->number <= 0)) {
|
||||||
|
$service->change($user, $drawActivity, 1, '活动赠送');
|
||||||
|
|
||||||
|
$drawTicket = DrawTicket::where('draw_activity_id', $drawActivity->id)->where('user_id', $user->id)->first();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 当前用户未填写收货地址的实物奖品
|
// 当前用户未填写收货地址的实物奖品
|
||||||
$drawLog = DrawLog::whereRelation('prize', 'type', DrawPrizeType::Goods->value)
|
// $drawLog = DrawLog::whereRelation('prize', 'type', DrawPrizeType::Goods->value)
|
||||||
->where('draw_activity_id', $drawActivity->id)
|
// ->where('draw_activity_id', $drawActivity->id)
|
||||||
->where('user_id', $user->id)
|
// ->where('user_id', $user->id)
|
||||||
->whereNull('consignee_name')
|
// ->whereNull('consignee_name')
|
||||||
->first();
|
// ->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@ use App\Models\User;
|
||||||
|
|
||||||
class DrawTicketService
|
class DrawTicketService
|
||||||
{
|
{
|
||||||
|
public static function make(...$params)
|
||||||
|
{
|
||||||
|
return new static(...$params);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加/扣除 用户在给定活动中的抽奖机会
|
* 增加/扣除 用户在给定活动中的抽奖机会
|
||||||
*
|
*
|
||||||
|
|
@ -21,7 +26,7 @@ class DrawTicketService
|
||||||
*
|
*
|
||||||
* @throws \App\Exceptions\BizException
|
* @throws \App\Exceptions\BizException
|
||||||
*/
|
*/
|
||||||
public function change(User $user, DrawActivity $drawActivity, int $number, ?string $remark = null): void
|
public function change(User $user, DrawActivity $drawActivity, int $number, ?string $remark = null)
|
||||||
{
|
{
|
||||||
if ($number === 0) {
|
if ($number === 0) {
|
||||||
throw new BizException('抽奖次数不能为 0');
|
throw new BizException('抽奖次数不能为 0');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue