webman/app/controller/api/Vip_rewardController.php

319 lines
8.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\controller\api;
use app\model\User;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Carousel;
use App\model\Project;
use App\model\ProjectDetailed;
use App\model\ProjectRegister;
use App\model\Carouselad;
use App\model\VipLevel;
use App\model\UserReward;
use App\Utils\ApiResponseApp;
use Tinywan\Jwt\JwtToken;
use App\dao\UserRewardDao;
use hg\apidoc\annotation as Apidoc;
use support\Db;
/**
* @Apidoc\Title("用户vip控制器不确定是干什么的")
*/
class Vip_rewardController
{
protected $noNeedLogin = [''];
/**
* @Apidoc\Title("1.0 获取vip等级赠送积分")
* @Apidoc\Url("api/vip_reward/product")
* @Apidoc\Method("POST")
*/
public function product(Request $request)
{
$data = [
[
"id" => 1,
"name" => "1",
"user_count" => 3,
"first_amount" => 1500,
"gift_amount" => 150,
"createtime" => 0
],
[
"id" => 2,
"name" => "2",
"user_count" => 5,
"first_amount" => 4000,
"gift_amount" => 380,
"createtime" => 0
],
[
"id" => 3,
"name" => "3",
"user_count" => 10,
"first_amount" => 6000,
"gift_amount" => 580,
"createtime" => 0
],
[
"id" => 4,
"name" => "4",
"user_count" => 20,
"first_amount" => 15000,
"gift_amount" => 1080,
"createtime" => 0
],
[
"id" => 5,
"name" => "5",
"user_count" => 40,
"first_amount" => 40000,
"gift_amount" => 2080,
"createtime" => 0
],
[
"id" => 6,
"name" => "6",
"user_count" => 70,
"first_amount" => 75000,
"gift_amount" => 3800,
"createtime" => 0
],
[
"id" => 7,
"name" => "7",
"user_count" => 200,
"first_amount" => 75000,
"gift_amount" => 10800,
"createtime" => 0
],
[
"id" => 8,
"name" => "8",
"user_count" => 500,
"first_amount" => 75000,
"gift_amount" => 28000,
"createtime" => 0
],
[
"id" => 9,
"name" => "9",
"user_count" => 1000,
"first_amount" => 75000,
"gift_amount" => 58000,
"createtime" => 0
]
];
return ApiResponseApp::success($data);
}
/**
* @Apidoc\Title("1.0 查询当前用户积分")
* @Apidoc\Url("api/vip_reward/need_score")
* @Apidoc\Method("POST")
*/
public function need_score(Request $request)
{
// $user_id = $request->data['id'];
// $user = User::find($user_id);
// $res['score'] = $user->money;
$res=[
"score"=>80
];
return ApiResponseApp::success($res);
}
/**
* @Apidoc\Title("1.0 获取当前用户vip等级")
* @Apidoc\Url("api/vip_reward/user_count")
* @Apidoc\Method("POST")
*/
public function user_count(Request $request)
{
$user_id=$request->data['id'];
$user=User::find($user_id);
return ApiResponseApp::success(['user_count'=>$user->today_num]);
}
/**
* @Apidoc\Title("1.0 获取当前用户vip等级")
* @Apidoc\Url("api/vip_reward/check_status")
* @Apidoc\Method("POST")
*/
public function check_status(Request $request)
{
//获取当前用户
$user_id=$request->data['id'];
$user=User::find($user_id);
$datas = [
[
"vip_id" => 1,
"status" => 0,
'$userCount' => 0,
"user_count" => 3
],
[
"vip_id" => 2,
"status" => 0,
'$userCount' => 0,
"user_count" => 5
],
[
"vip_id" => 3,
"status" => 0,
'$userCount' => 0,
"user_count" => 10
],
[
"vip_id" => 4,
"status" => 0,
'$userCount' => 0,
"user_count" => 20
],
[
"vip_id" => 5,
"status" => 0,
'$userCount' => 0,
"user_count" => 40
],
[
"vip_id" => 6,
"status" => 0,
'$userCount' => 0,
"user_count" => 70
],
[
"vip_id" => 7,
"status" => 0,
'$userCount' => 0,
"user_count" => 200
],
[
"vip_id" => 8,
"status" => 0,
'$userCount' => 0,
"user_count" => 500
],
[
"vip_id" => 9,
"status" => 0,
'$userCount' => 0,
"user_count" => 1000
]
];
//获取该用户今天的领奖记录
$UserRewasrds = UserReward::where('user_id', $user_id)
->whereDate('created_at', date('Y-m-d'))
->where('memo', 'like', '%' . '等级奖励' . '%')
->get();
// 遍历每个用户记录并更新 status 字段
foreach ($datas as &$data) {
foreach ($UserRewasrds as $UserRewasrd) {
if (strpos($UserRewasrd->memo, $data['vip_id'].'等级奖励') !== false) {
$data['status'] = 2;
break;
}
}
if ($data['status'] == 2) {
continue;
}
if ($user->today_num >= $data['user_count']) {
$data['status'] = 1; // 满足条件时设置状态为1
} else {
$data['status'] = 0; // 不满足条件时设置状态为0
}
}
return ApiResponseApp::success($datas);
}
/**
* @Apidoc\Title("1.0 领取等级奖励")
* @Apidoc\Url("api/vip_reward/receive")
* @Apidoc\Method("GET")
*/
public function receive(Request $request)
{
// 输出所有请求参数以进行调试
$input = $request->all();
$vip_id = $input['vip_id'];
$user_id=$request->data['id'];
// $user=User::find($user_id);
$datas = [
[
"vip_id" => 1,
"money" => 150,
'new_money' => 1500,
],
[
"vip_id" => 2,
"money" => 380,
'new_money' => 4000,
],
[
"vip_id" => 3,
"money" => 580,
'new_money' => 6000,
],
[
"vip_id" => 4,
"money" => 1080,
'new_money' => 15000,
],
[
"vip_id" => 5,
"money" => 2080,
'new_money' => 40000,
],
[
"vip_id" => 6,
"money" => 3800,
'new_money' => 75000,
],
[
"vip_id" => 7,
"money" => 10800,
'new_money' => 75000,
],
[
"vip_id" => 8,
"money" => 28000,
'new_money' => 75000,
],
[
"vip_id" => 9,
"money" => 58000,
'new_money' => 75000,
],
];
$money = null;
$new_money = null;
foreach ($datas as $data) {
if ($data['vip_id'] == $vip_id) {
$money = $data['money'];
$new_money = $data['new_money'];
break;
}
}
$UserReward = UserReward::where('memo', '首次VIP'.$vip_id.'等级奖励')->where('user_id', $user_id)->get();
// if
//判断是否有
if ($UserReward->count() > 0) {
UserRewardDao::base($user_id, 6, $money, 'VIP'.$vip_id.'等级奖励');
}else{
UserRewardDao::base($user_id, 6, $new_money, '首次VIP'.$vip_id.'等级奖励');
}
return ApiResponseApp::success('领取成功');
}
}