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 1/2] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Evip=E6=97=A5?= =?UTF-8?q?=E5=BF=97=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' + ]; } From 5eb66a1c75fb2f422b4b1f7aa92f746c119980cc 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 22:57:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=98=8E?= =?UTF-8?q?=E7=BB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/api/v1/UserRewardController.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 app/controller/admin/api/v1/UserRewardController.php diff --git a/app/controller/admin/api/v1/UserRewardController.php b/app/controller/admin/api/v1/UserRewardController.php new file mode 100644 index 0000000..5e94619 --- /dev/null +++ b/app/controller/admin/api/v1/UserRewardController.php @@ -0,0 +1,55 @@ +post(); + + // 构建查询构造器 + $query = UserReward::query(); + + if (isset($data['updatedat']) && is_array($data['updatedat']) && count($data['updatedat']) == 2) { + // 直接从数组中获取开始和结束日期 + $startDate = $data['updatedat'][0]; + $endDate = $data['updatedat'][1]; + + if ($startDate === $endDate) { + // 如果开始日期和结束日期相同,则查询这一天的所有记录 + $query->whereDate('updated_at', '=', $startDate); + } else { + // 否则查询日期范围内的记录 + $query->whereBetween('updated_at', [$startDate . ' 00:00:00', $endDate . ' 23:59:59']); + } + } + + // 根据 username 进行模糊查询 + if (!empty($data['username'])) { + $query->where('username', 'like', '%' . $data['username'] . '%'); + } + $query->orderBy('id', 'desc'); + // 执行查询并返回数据 + $users = $query->paginate($data['pageSize'], ['*'], 'page', $data['current']); + + // 格式化结果为数组 + return ApiResponse::success(200, $users); + } +}