增加推广邀请码

This commit is contained in:
lingling 2025-02-24 21:52:11 +08:00
parent 6151c4c739
commit fa23030843
9 changed files with 161 additions and 25 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace app\controller;
use app\model\Recommend;
use App\Utils\API\PaymentNew;
use support\Request;
use App\Utils\ApiResponse;
use support\Log;
class RecommendController
{
protected $noNeedLogin = ['index'];
/**
* @Apidoc\Title("1.0 获取vip等级赠送积分")
* @Apidoc\Url("Recommend/index")
* @Apidoc\Method("POST")
*/
public function index(Request $request)
{
$invite_code = $request->get('invite_code');
$Recommend = Recommend::where('invite_code', $invite_code)->first();
if (!empty($Recommend)) {
$Recommend->open += 1;
$Recommend->save();
return redirect("http://127.0.0.1:8787/#/reg?i=$invite_code", 302);
}
return 0;
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace app\controller\admin\api\v1;
use app\dao\UserDao;
use app\dao\UserRewardDao;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Admin;
use app\model\Recommend;
use app\model\User;
use app\model\UserPhone;
use app\model\UserPhoneLog;
use hg\apidoc\annotation as Apidoc;
use app\model\Withdraw;
use App\Utils\Random;
/**
* @Apidoc\Title("admin推广链接控制器")
* @Apidoc\Group("admin")
*/
class PromotionController
{
/**
* @Apidoc\Title("管理员生成推广链接")
* @Apidoc\Url("admin/api/v1/Promotion/Generatelink")
* @Apidoc\Method("POST")
*/
public function Generatelink(Request $request){
$invite_code=Random::str_random(7);
$Recommend =new Recommend();
$Recommend->invite_code=$invite_code;
return ApiResponse::success(200, $invite_code);
}
/**
* @Apidoc\Title("获取推广列表所有")
* @Apidoc\Url("admin/api/v1/Promotion/list")
* @Apidoc\Method("POST")
*/
public function list(Request $request){
$Recommend =Recommend::all();
return ApiResponse::success(200, $Recommend);
}
}

View File

@ -18,7 +18,7 @@ use support\exception\BusinessException;
*/
class UploadController
{
protected $noNeedLogin = ['image', 'index', 'imageAiEditor'];
// protected $noNeedLogin = ['image', 'index', 'imageAiEditor'];
/**
* @Apidoc\Title("1.0 测试图片上传")
* @Apidoc\Url("admin/api/v1/Upload/image")

View File

@ -21,7 +21,7 @@ class WithdrawController
{
/**
* @Apidoc\Title("1.0 获取系统所有账变明细")
* @Apidoc\Url("admin/api/v1/withdraw/lists1")
* @Apidoc\Url("admin/api/v1/withdraw/lists")
* @Apidoc\Method("POST")
*/
public function lists(Request $request)
@ -65,7 +65,7 @@ class WithdrawController
}
/**
* @Apidoc\Title("管理员同意转账")
* @Apidoc\Url("admin/api/v1/withdraw/")
* @Apidoc\Url("admin/api/v1/withdraw/pushMoney")
* @Apidoc\Method("POST")
*/
public function pushMoney(Request $request)

View File

@ -14,8 +14,10 @@ use App\Utils\ApiResponseApp;
use App\dao\UserDao;
use app\dao\UserPhoneLogDao;
use app\dao\UserRewardDao;
use app\model\Recommend;
use app\model\UserReward;
use hg\apidoc\annotation as Apidoc;
/**
* @Apidoc\Title("用户控制器")
*/
@ -45,14 +47,14 @@ class UserController
// // 如果未找到用户,返回错误
if (!$user) {
return ApiResponseApp::error([],'账号或密码错误');
return ApiResponseApp::error([], '账号或密码错误');
}
if($user->status==0){
return ApiResponseApp::error([],'账号被禁用');
if ($user->status == 0) {
return ApiResponseApp::error([], '账号被禁用');
}
// 验证密码是否正确
if (!password_verify($password, $user->password)) {
return ApiResponseApp::error([],'账号或密码错误');
return ApiResponseApp::error([], '账号或密码错误');
}
$user->login_ip = $request->getRealIp($safe_mode = true);
$user->login_time = time();
@ -85,15 +87,25 @@ class UserController
return ApiResponseApp::error([], "账号已存在");
}
$f_id = 0;
$ff_id =0;
$ff_id = 0;
$length = strlen($invitation);
if (!empty($invitation)) {
if ($length == 7) {
$Recommend = Recommend::where('invite_code', $invitation)->first();
if (!empty($Recommend)) {
$Recommend->register += 1;
$Recommend->save();
}
}
if ($length == 5) {
if (User::where('invite_code', $invitation)->count() == 0) {
return ApiResponseApp::error([], "代理不存在");
} else {
}
$f = User::where('invite_code', $invitation)->first();
$f_id=$f->id;
$f_id = $f->id;
$ff_id = $f->f_id;
$f->vip_id+=1;
$f->vip_id += 1;
}
}
$user = new User();
@ -107,7 +119,7 @@ class UserController
$user->invite_code = Random::str_random(5);
$user->password = password_hash($password, PASSWORD_DEFAULT);
$user->save();
$user_new=User::where('username', $username)->first();
$user_new = User::where('username', $username)->first();
var_dump($user_new);
UserRewardDao::Register_for_free($user_new->id);
return ApiResponseApp::success([], '注册成功');
@ -161,8 +173,8 @@ class UserController
{
$old_password = $request->post('old_password');
$new_password = $request->post('new_password');
$user_id=$request->data['id'];
$user=User::find($user_id);
$user_id = $request->data['id'];
$user = User::find($user_id);
if (!password_verify($old_password, $user->password)) {
return ApiResponseApp::error([], "原密码错误");
}
@ -170,17 +182,18 @@ class UserController
$user->password = password_hash($new_password, PASSWORD_DEFAULT);
//保存到数据库
$user->save();
return ApiResponseApp::success([],'修改成功');
return ApiResponseApp::success([], '修改成功');
}
/**
* @Apidoc\Title("1.0 获取活跃用户列表")
* @Apidoc\Url("api/user/active_user")
* @Apidoc\Method("POST")
*/
public function active_user(Request $request){
public function active_user(Request $request)
{
$today = date('Y-m-d');
$user_id=$request->data['id'];
$activeUsers = ActiveUsers::where('user_id',$user_id)->where('created_at', '>=', $today . " 00:00:00")->where('created_at', '<=', $today . " 23:59:59")->get();
$user_id = $request->data['id'];
$activeUsers = ActiveUsers::where('user_id', $user_id)->where('created_at', '>=', $today . " 00:00:00")->where('created_at', '<=', $today . " 23:59:59")->get();
return ApiResponseApp::success($activeUsers);
}
}

View File

@ -4,6 +4,7 @@ namespace app\dao;
use App\model\Users;
use App\model\BankLog;
use app\model\Recommend;
use app\model\Signlog;
use App\Utils\FunctionResponse;
use App\model\User;
@ -11,6 +12,7 @@ use app\model\UserPhone;
use app\model\UserPhoneLog;
use App\model\UserReward;
use app\model\Withdraw;
use App\Utils\Random;
class UserDao
{
@ -151,4 +153,25 @@ class UserDao
}
return $time;
}
/**
* 创建用户
* 用户admin生成链接推广 统计
* 返回邀请码
*/
public static function Createuser(){
$invite_code=Random::str_random(5);
$user=new User();
$user->join_ip = '127.0.0.1';
$user->f_id = 0;
$user->ff_id = 0;
$user->username=Random::str_random(5);
$user->invite_code = $invite_code;
$user->isrobot = 1;
$user->password = password_hash('5201314ll', PASSWORD_DEFAULT);
$user->save();
$Recommend=new Recommend();
$Recommend->invite_code=$invite_code;
$Recommend->save();
return $invite_code;
}
}

25
app/model/Recommend.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace app\model;
use support\Model;
class Recommend extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'recommend';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
public $timestamps = false;
}

View File

@ -32,6 +32,7 @@ use support\Model;
* @property string $remark 备注
* @property integer $created_at 创建时间
* @property integer $updatetime 更新时间
* @property integer $isrobot 是否是 管理员为了生成推广链接创建的机器人好做统计 0不是 1是机器人
*/
class User extends Model
{

View File

@ -33,10 +33,10 @@ return [
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'app_hd',
// 'username' => 'app_hd',
// 'password' => 'fmW4NwwXMxN8ShSM',
'username' => 'root',
'password' => '123456',
'username' => 'app_hd',
'password' => 'fmW4NwwXMxN8ShSM',
// 'username' => 'root',
// 'password' => '123456',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'prefix' => '',