From ff541c1804cc9af1c3f128e6ebf6d8a3d952edbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=8B=BC?= <2468023037@qq.com> Date: Fri, 28 Feb 2025 19:58:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Evip=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Vip_rewardController.php | 35 +++++++++++++++------ app/model/UserReceivesVipLog.php | 6 ++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/controller/api/Vip_rewardController.php b/app/controller/api/Vip_rewardController.php index 7dbbbd0..cdfc77e 100644 --- a/app/controller/api/Vip_rewardController.php +++ b/app/controller/api/Vip_rewardController.php @@ -13,6 +13,7 @@ use App\model\ProjectDetailed; use App\model\ProjectRegister; use App\model\Carouselad; use App\model\VipLevel; +use App\model\UserReceivesVipLog; use App\model\UserReward; use App\Utils\ApiResponseApp; use Tinywan\Jwt\JwtToken; @@ -206,14 +207,15 @@ class Vip_rewardController ] ]; //获取该用户今天的领奖记录 - $UserRewasrds = UserReward::where('user_id', $user_id) - ->whereDate('created_at', date('Y-m-d')) - ->where('memo', 'like', '%' . '等级奖励' . '%') - ->get(); + // $UserRewasrds = UserReward::where('user_id', $user_id) + // ->whereDate('created_at', date('Y-m-d')) + // ->where('memo', 'like', '%' . '等级奖励' . '%') + // ->get(); + $UserReceivesVipLogs = UserReceivesVipLog::where('user_id', $user_id)->whereDate('created_at', date('Y-m-d')); // 遍历每个用户记录并更新 status 字段 foreach ($datas as &$data) { - foreach ($UserRewasrds as $UserRewasrd) { - if (strpos($UserRewasrd->memo, $data['vip_id'].'等级奖励') !== false) { + foreach ($UserReceivesVipLogs as $UserReceivesVipLog) { + if (strpos($UserReceivesVipLog->vip_id, $data['vip_id']) !== false) { $data['status'] = 2; break; } @@ -241,7 +243,7 @@ class Vip_rewardController $input = $request->all(); $vip_id = $input['vip_id']; - + $user_id=$request->data['id']; // $user=User::find($user_id); @@ -302,14 +304,27 @@ class Vip_rewardController break; } } - $UserReward = UserReward::where('memo', '首次VIP'.$vip_id.'等级奖励')->where('user_id', $user_id)->get(); + // $UserReward = UserReward::where('memo', '首次VIP'.$vip_id.'等级奖励')->where('user_id', $user_id)->get(); + $UserReceivesVipLogs = UserReceivesVipLog::where('user_id', $user_id) + ->whereDate('created_at', date('Y-m-d')) + ->where('vip_id', $vip_id) + ->where('isfirst',1); // if() //判断是否有 - if ($UserReward->count() > 0) { + if ($UserReceivesVipLogs->count() > 0) { UserRewardDao::base($user_id, 6, $money, 'VIP'.$vip_id.'等级奖励'); + UserReceivesVipLog::create([ + 'user_id' => $user_id, + 'vip_id' => $vip_id, + 'isfirst' => 0, + ]); }else{ UserRewardDao::base($user_id, 6, $new_money, '首次VIP'.$vip_id.'等级奖励'); - + UserReceivesVipLog::create([ + 'user_id' => $user_id, + 'vip_id' => $vip_id, + 'isfirst' => 1, + ]); } return ApiResponseApp::success('领取成功'); diff --git a/app/model/UserReceivesVipLog.php b/app/model/UserReceivesVipLog.php index 21a3e8f..1e33cd1 100644 --- a/app/model/UserReceivesVipLog.php +++ b/app/model/UserReceivesVipLog.php @@ -19,4 +19,10 @@ class UserReceivesVipLog extends Model // 设置主键 protected $primaryKey = 'id'; + + protected $fillable = [ + 'user_id', + 'vip_id', + 'isfirst' + ]; }