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); + } +} diff --git a/app/controller/api/Vip_rewardController.php b/app/controller/api/Vip_rewardController.php index 027cb67..bb42138 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,12 +304,27 @@ class Vip_rewardController break; } } - $UserReward = UserReward::where('memo', '首次VIP'.$vip_id.'等级奖励')->where('user_id', $user_id)->get(); - // if ($UserReward->count() > 0) { + // $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 ($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' + ]; }