mirror of
https://gitee.com/liuxioabin/fengketrade.git
synced 2026-04-17 21:03:17 +08:00
92 lines
2.2 KiB
PHP
92 lines
2.2 KiB
PHP
<?php
|
|
namespace addons\shopro\controller;
|
|
|
|
use addons\shopro\library\InviteHelper;
|
|
use app\admin\model\shopro\user\User as UserModel;
|
|
|
|
class Invite extends Common
|
|
{
|
|
protected $noNeedLogin = ['*'];
|
|
protected $noNeedRight = ['*'];
|
|
|
|
/**
|
|
* 获取我的邀请码
|
|
*/
|
|
public function myCode()
|
|
{
|
|
$user = auth_user();
|
|
|
|
// 如果没有邀请码,自动生成
|
|
if (!$user->invite_code) {
|
|
$inviteCode = InviteHelper::generateCode($user->id);
|
|
} else {
|
|
$inviteCode = $user->invite_code;
|
|
}
|
|
|
|
// 统计邀请人数
|
|
$inviteCount = UserModel::where('parent_user_id', $user->id)->count();
|
|
|
|
$this->success('获取成功', [
|
|
'invite_code' => $inviteCode,
|
|
'invite_count' => $inviteCount,
|
|
'share_text' => "我的邀请码:{$inviteCode},下单时填写即可!"
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 验证邀请码
|
|
*/
|
|
public function checkCode()
|
|
{
|
|
$inviteCode = $this->request->param('invite_code', '');
|
|
|
|
if (empty($inviteCode)) {
|
|
$this->error('请输入邀请码');
|
|
}
|
|
|
|
$result = InviteHelper::validate($inviteCode);
|
|
|
|
if ($result['code'] != 1) {
|
|
$this->error($result['msg']);
|
|
}
|
|
|
|
$this->success('邀请码有效', $result['data']);
|
|
}
|
|
|
|
/**
|
|
* 绑定邀请码
|
|
*/
|
|
public function bind()
|
|
{
|
|
$user = auth_user();
|
|
$inviteCode = $this->request->param('invite_code', '');
|
|
|
|
if (empty($inviteCode)) {
|
|
$this->error('请输入邀请码');
|
|
}
|
|
|
|
$result = InviteHelper::bind($inviteCode, $user->id);
|
|
|
|
if ($result['code'] != 1) {
|
|
$this->error($result['msg']);
|
|
}
|
|
|
|
$this->success($result['msg'], $result['data']);
|
|
}
|
|
|
|
/**
|
|
* 我邀请的用户列表
|
|
*/
|
|
public function myInvites()
|
|
{
|
|
$user = auth_user();
|
|
|
|
$list = UserModel::where('parent_user_id', $user->id)
|
|
->field(['id', 'nickname', 'avatar', 'mobile', 'jointime', 'invite_code_used'])
|
|
->order('id desc')
|
|
->paginate($this->request->param('list_rows', 10));
|
|
|
|
$this->success('获取成功', $list);
|
|
}
|
|
}
|