FastMovieAI AI短剧创作平台 二开基线
- 源码: xhadmincn/FastMovieAI (Apache 2.0) - 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION - vendor/示例资源已gitignore
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"title": "User",
|
||||
"icon": "User",
|
||||
"path": "/app/user/admin",
|
||||
"sort": 1000,
|
||||
"children": [
|
||||
{
|
||||
"title": "User List",
|
||||
"icon": "User",
|
||||
"path": "/app/user/admin/User/index",
|
||||
"component": "table",
|
||||
"children": [
|
||||
{
|
||||
"title": "Create User",
|
||||
"path": "/app/user/admin/User/create",
|
||||
"show": false,
|
||||
"component": "form"
|
||||
},
|
||||
{
|
||||
"title": "Edit User",
|
||||
"show": false,
|
||||
"path": "/app/user/admin/User/update",
|
||||
"component": "form"
|
||||
},
|
||||
{
|
||||
"title": "Update Status",
|
||||
"show": false,
|
||||
"path": "/app/user/admin/User/indexUpdateState",
|
||||
"component": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"title": "Settings",
|
||||
"icon": "Setting",
|
||||
"path": "/app/user/admin/Setting/basic",
|
||||
"show": false,
|
||||
"component": "form"
|
||||
},
|
||||
{
|
||||
"title": "余额账单",
|
||||
"icon": "User",
|
||||
"path": "/app/user/admin/Balance/index",
|
||||
"component": "table"
|
||||
},
|
||||
{
|
||||
"title": "积分账单",
|
||||
"icon": "User",
|
||||
"path": "/app/user/admin/Points/index",
|
||||
"component": "table"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\api;
|
||||
|
||||
use plugin\control\expose\api\Control as ApiControl;
|
||||
|
||||
class Control
|
||||
{
|
||||
use ApiControl;
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = __DIR__;
|
||||
$this->plugin = 'user';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\api;
|
||||
|
||||
use app\expose\api\Install as ApiInstall;
|
||||
|
||||
class Install
|
||||
{
|
||||
use ApiInstall;
|
||||
public function __construct()
|
||||
{
|
||||
$this->plugin='user';
|
||||
$this->path = __DIR__;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\api\admin;
|
||||
|
||||
use app\expose\build\builder\DataboardBuilder;
|
||||
use app\expose\build\builder\databoardBuilder\component\Statistic;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
|
||||
class IndexController
|
||||
{
|
||||
public function control(DataboardBuilder $builder)
|
||||
{
|
||||
$today = PluginUser::whereDay('create_time')->count();
|
||||
$yesterday = PluginUser::whereDay('create_time', 'yesterday')->count();
|
||||
$statistic = new Statistic;
|
||||
$statistic->setLabel('今日新注册用户')
|
||||
->setUnit('人')
|
||||
->setData([
|
||||
'today' => $today,
|
||||
'yesterday' => $yesterday,
|
||||
'growth_rate' => $yesterday ? round(($today - $yesterday) / $yesterday * 100, 2) : 0
|
||||
])
|
||||
->setClass('p-6');
|
||||
$builder->add($statistic, [
|
||||
'xs' => 24,
|
||||
'sm' => 12,
|
||||
'md' => 6,
|
||||
'lg' => 4,
|
||||
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\admin\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
use plugin\user\app\model\PluginUserBill;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use support\Request;
|
||||
|
||||
class BalanceController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginUserBill();
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder;
|
||||
$channelList = PluginChannelsUser::options();
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('channels_uid', '渠道', 'select', '', [
|
||||
'options' => $channelList,
|
||||
'props' => [
|
||||
'placeholder' => '渠道搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('nickname', '昵称', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '昵称搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('username', '账号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '账号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('email', '邮箱', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '邮箱搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', 'UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => 'UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('action', '变化类型', 'select', '', [
|
||||
'options' => MoneyAction::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '变化类型搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('channels', '渠道', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'channels.nickname',
|
||||
'avatar' => 'channels,headimg',
|
||||
'info' => 'channels.mobile',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'channels_uid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('userinfo', '用户', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'username',
|
||||
'nicknameTags' => [
|
||||
[
|
||||
'field' => 'new_text',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'week_text',
|
||||
'props' => [
|
||||
'type' => 'warning',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'month_text',
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
|
||||
$builder->add('contact', '联系方式', [
|
||||
'props' => [
|
||||
'width' => '280px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'mobile',
|
||||
'label' => '手机号'
|
||||
],
|
||||
[
|
||||
'field' => 'email',
|
||||
'label' => '邮箱'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('num', '变化金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('before', '变化前金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('after', '变化后金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('remarks', '备注', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('action', '变化类型', [
|
||||
'props' => [
|
||||
'width' => '120px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => MoneyAction::getOptions()
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '创建时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$channels_uid = $request->get('channels');
|
||||
if ($channels_uid) {
|
||||
$where[] = ['ub.channels_uid', '=', $channels_uid];
|
||||
}
|
||||
$username = $request->get('username');
|
||||
if ($username) {
|
||||
$where[] = ['u.username', 'like', "%{$username}%"];
|
||||
}
|
||||
$mobile = $request->get('mobile');
|
||||
if ($mobile) {
|
||||
$where[] = ['u.mobile', 'like', "%{$mobile}%"];
|
||||
}
|
||||
$email = $request->get('email');
|
||||
if ($email) {
|
||||
$where[] = ['u.email', 'like', "%{$email}%"];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['u.id', '=', $uid];
|
||||
}
|
||||
$list = PluginUserBill::alias('ub')
|
||||
->with(['channels' => function ($query) {
|
||||
$query->field('id,nickname,headimg,mobile');
|
||||
}])
|
||||
->join('plugin_user u', 'ub.uid = u.id')
|
||||
->field('ub.*,u.nickname,u.headimg,u.username,u.mobile,u.email')
|
||||
->where($where)
|
||||
->order('ub.id desc')
|
||||
->paginate($limit);
|
||||
return $this->resData($list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\admin\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\app\model\PluginUserPointsBill;
|
||||
use plugin\user\expose\helper\User as HelperUser;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use support\Request;
|
||||
|
||||
class PointsController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginUserPointsBill();
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder;
|
||||
$channelList = PluginChannelsUser::options();
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('channels_uid', '渠道', 'select', '', [
|
||||
'options' => $channelList,
|
||||
'props' => [
|
||||
'placeholder' => '渠道搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('nickname', '昵称', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '昵称搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('username', '账号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '账号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('email', '邮箱', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '邮箱搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', 'UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => 'UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('action', '变化类型', 'select', '', [
|
||||
'options' => MoneyAction::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '变化类型搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('channels', '渠道', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'channels.nickname',
|
||||
'avatar' => 'channels,headimg',
|
||||
'info' => 'channels.mobile',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'channels_uid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('userinfo', '用户', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'username',
|
||||
'nicknameTags' => [
|
||||
[
|
||||
'field' => 'new_text',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'week_text',
|
||||
'props' => [
|
||||
'type' => 'warning',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'month_text',
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
|
||||
$builder->add('contact', '联系方式', [
|
||||
'props' => [
|
||||
'width' => '280px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'mobile',
|
||||
'label' => '手机号'
|
||||
],
|
||||
[
|
||||
'field' => 'email',
|
||||
'label' => '邮箱'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('num', '变化金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('before', '变化前金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('after', '变化后金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('remarks', '备注', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('action', '变化类型', [
|
||||
'props' => [
|
||||
'width' => '120px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => MoneyAction::getOptions()
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '创建时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$channels_uid = $request->get('channels_uid');
|
||||
if ($channels_uid) {
|
||||
$where[] = ['ub.channels_uid', '=', $channels_uid];
|
||||
}
|
||||
$username = $request->get('username');
|
||||
if ($username) {
|
||||
$where[] = ['u.username', 'like', "%{$username}%"];
|
||||
}
|
||||
$mobile = $request->get('mobile');
|
||||
if ($mobile) {
|
||||
$where[] = ['u.mobile', 'like', "%{$mobile}%"];
|
||||
}
|
||||
$email = $request->get('email');
|
||||
if ($email) {
|
||||
$where[] = ['u.email', 'like', "%{$email}%"];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['u.id', '=', $uid];
|
||||
}
|
||||
$list = PluginUserPointsBill::alias('ub')
|
||||
->with(['channels' => function ($query) {
|
||||
$query->field('id,nickname,headimg,mobile');
|
||||
}])
|
||||
->join('plugin_user u', 'ub.uid = u.id')
|
||||
->field('ub.*,u.nickname,u.headimg,u.username,u.mobile,u.email')
|
||||
->where($where)
|
||||
->order('ub.id desc')
|
||||
->paginate($limit);
|
||||
return $this->resData($list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\admin\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\trait\Config;
|
||||
|
||||
class SettingController extends Basic
|
||||
{
|
||||
use Config;
|
||||
public function basic()
|
||||
{
|
||||
return $this->builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\admin\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\expose\helper\User as HelperUser;
|
||||
use support\Request;
|
||||
|
||||
class UserController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginUser;
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder;
|
||||
$channelList = PluginChannelsUser::options();
|
||||
// $builder->addAction('操作', [
|
||||
// 'width' => '100px',
|
||||
// 'fixed' => 'right'
|
||||
// ]);
|
||||
// $builder->addTableAction('编辑', [
|
||||
// 'model' => Action::DIALOG['value'],
|
||||
// 'path' => '/app/user/admin/User/update',
|
||||
// 'props' => [
|
||||
// 'title' => '编辑《ID:{id}》用户'
|
||||
// ],
|
||||
// 'component' => [
|
||||
// 'name' => 'button',
|
||||
// 'props' => [
|
||||
// 'type' => 'primary',
|
||||
// 'size' => 'small'
|
||||
// ]
|
||||
// ]
|
||||
// ]);
|
||||
// $builder->addHeader();
|
||||
// $builder->addHeaderAction('创建用户', [
|
||||
// 'model' => Action::DIALOG['value'],
|
||||
// 'path' => '/app/user/admin/User/create',
|
||||
// 'props' => [
|
||||
// 'title' => '创建用户'
|
||||
// ],
|
||||
// 'component' => [
|
||||
// 'name' => 'button',
|
||||
// 'props' => [
|
||||
// 'type' => 'success'
|
||||
// ]
|
||||
// ]
|
||||
// ]);
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('channels_uid', '渠道', 'select', '', [
|
||||
'options' => $channelList,
|
||||
'props' => [
|
||||
'placeholder' => '渠道搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('nickname', '昵称', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '昵称搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('username', '账号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '账号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('email', '邮箱', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '邮箱搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', 'UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => 'UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('puid', '上级UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '上级UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('channels', '渠道', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'channels.nickname',
|
||||
'avatar' => 'channels,headimg',
|
||||
'info' => 'channels.mobile',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'channels_uid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('userinfo', '用户', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'username',
|
||||
'nicknameTags' => [
|
||||
[
|
||||
'field' => 'new_text',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'week_text',
|
||||
'props' => [
|
||||
'type' => 'warning',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'month_text',
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('puserinfo', '上级', [
|
||||
'where' => [
|
||||
['puid', '!=', null]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'parent.nickname',
|
||||
'avatar' => 'parent,headimg',
|
||||
'info' => 'parent.mobile',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'puid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('contact', '联系方式', [
|
||||
'props' => [
|
||||
'width' => '280px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'mobile',
|
||||
'label' => '手机号'
|
||||
],
|
||||
[
|
||||
'field' => 'email',
|
||||
'label' => '邮箱'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$builder->add('state', '状态', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => State::getOptions(),
|
||||
],
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('online_time', '活动', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'activation_time',
|
||||
'label' => '激活'
|
||||
],
|
||||
[
|
||||
'field' => 'login_time',
|
||||
'label' => '登录'
|
||||
],
|
||||
[
|
||||
'component' => 'tag',
|
||||
'field' => 'login_ip',
|
||||
'label' => '登录IP',
|
||||
'props' => [
|
||||
'size' => 'small',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'create_time',
|
||||
'label' => '创建'
|
||||
],
|
||||
[
|
||||
'field' => 'update_time',
|
||||
'label' => '更新'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function query(Request $request)
|
||||
{
|
||||
$query = $request->post('query');
|
||||
if (empty($query)) {
|
||||
return $this->resData([]);
|
||||
}
|
||||
$where = [];
|
||||
$where[] = ['nickname|username|mobile|email', 'like', "%{$query}%"];
|
||||
return $this->resData(PluginUser::options($where));
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$channels_uid = $request->get('channels_uid');
|
||||
if ($channels_uid) {
|
||||
$where[] = ['channels_uid', '=', $channels_uid];
|
||||
}
|
||||
$username = $request->get('username');
|
||||
if ($username) {
|
||||
$where[] = ['username', 'like', "%{$username}%"];
|
||||
}
|
||||
$mobile = $request->get('mobile');
|
||||
if ($mobile) {
|
||||
$where[] = ['mobile', 'like', "%{$mobile}%"];
|
||||
}
|
||||
$email = $request->get('email');
|
||||
if ($email) {
|
||||
$where[] = ['email', 'like', "%{$email}%"];
|
||||
}
|
||||
$puid = $request->get('puid');
|
||||
if ($puid) {
|
||||
$where[] = ['puid', '=', $puid];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['id', '=', $uid];
|
||||
}
|
||||
$list = PluginUser::where($where)->with(['parent' => function ($query) {
|
||||
$query->field('id,nickname,headimg,mobile');
|
||||
}, 'channels' => function ($query) {
|
||||
$query->field('id,nickname,headimg,mobile');
|
||||
}])
|
||||
->order('id desc')->paginate($limit)->each(function ($item) {
|
||||
// 三天以内创建的
|
||||
$create_time = strtotime($item->create_time);
|
||||
$create_time = time() - $create_time;
|
||||
if ($create_time < 3 * 24 * 60 * 60) {
|
||||
$item->new_text = '新用户';
|
||||
} elseif ($create_time < 7 * 24 * 60 * 60) {
|
||||
$item->week_text = '一周内';
|
||||
} elseif ($create_time < 30 * 24 * 60 * 60) {
|
||||
$item->month_text = '30天内';
|
||||
}
|
||||
});
|
||||
return $this->resData($list);
|
||||
}
|
||||
public function create(Request $request)
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
$D = $request->post();
|
||||
try {
|
||||
HelperUser::create($D);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('创建成功');
|
||||
}
|
||||
$builder = $this->getFormBuilder();
|
||||
$Component = new ComponentBuilder;
|
||||
$builder->add('activation_time', '激活时间', 'date-picker', null, [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '不选择时间则不激活,由用户前台登录后自动激活'], ['type' => 'info', 'size' => 'small'])
|
||||
->builder()
|
||||
],
|
||||
'props' => [
|
||||
'placeholder' => '选择激活时间',
|
||||
'type' => 'datetime',
|
||||
'format' => 'YYYY-MM-DD HH:mm:ss',
|
||||
'value-format' => 'YYYY-MM-DD HH:mm:ss'
|
||||
]
|
||||
]);
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function update(Request $request)
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
$D = $request->post();
|
||||
try {
|
||||
HelperUser::update($D['id'], $D);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('更新成功');
|
||||
}
|
||||
$id = $request->get('id');
|
||||
$User = PluginUser::where(['id' => $id])->withoutField('password')->find();
|
||||
$builder = $this->getFormBuilder();
|
||||
$builder->setData($User->toArray());
|
||||
return $this->resData($builder);
|
||||
}
|
||||
private function getFormBuilder()
|
||||
{
|
||||
$builder = new FormBuilder(null, null, [
|
||||
'labelPosition' => 'right',
|
||||
'label-width' => "200px",
|
||||
'class' => 'w-80 mx-auto',
|
||||
'size' => 'large',
|
||||
]);
|
||||
$Component = new ComponentBuilder;
|
||||
$builder->add('nickname', '昵称', 'input', '', [
|
||||
'required' => true,
|
||||
'maxlength' => 30,
|
||||
'show-word-limit' => true
|
||||
]);
|
||||
$builder->add('headimg', '头像', 'bundle', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '支持jpg、png、jpeg格式,大小不超过2M'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'accept' => 'image/jpeg,image/png,image/jpg',
|
||||
'multiple' => 1,
|
||||
'size' => 2
|
||||
]
|
||||
]);
|
||||
$builder->add('username', '账号', 'input', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '支持字母、数字、下划线,长度不超过30个字符'], ['type' => 'info', 'size' => 'small'])->builder(),
|
||||
$Component->add('text', ['default' => '可用于账号登录'], ['type' => 'success', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'maxlength' => 30,
|
||||
'show-word-limit' => true
|
||||
]
|
||||
]);
|
||||
$builder->add('mobile', '手机号', 'input', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '中国大陆11位手机号'], ['type' => 'info', 'size' => 'small'])->builder(),
|
||||
$Component->add('text', ['default' => '可用于账号,短信验证码登录'], ['type' => 'success', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'maxlength' => 11,
|
||||
'show-word-limit' => true
|
||||
]
|
||||
]);
|
||||
$builder->add('email', '邮箱', 'input', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '可用于账号,邮箱验证码登录'], ['type' => 'success', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'maxlength' => 100,
|
||||
'show-word-limit' => true
|
||||
]
|
||||
]);
|
||||
$builder->add('password', '密码', 'input', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '不修改密码请留空'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'placeholder' => '不修改密码请留空',
|
||||
'maxlength' => 30,
|
||||
'show-word-limit' => true
|
||||
]
|
||||
]);
|
||||
return $builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
use plugin\user\app\model\PluginUserPointsBill;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use support\Request;
|
||||
|
||||
class BillController extends Basic
|
||||
{
|
||||
public function getPointsBill(Request $request)
|
||||
{
|
||||
$type = $request->get('type', 'all');
|
||||
|
||||
$uid = $request->uid;
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$where[] = ['uid', '=', $uid];
|
||||
if ($type != 'all') {
|
||||
if ($type == 'consume') {
|
||||
$where[] = ['action', '=', MoneyAction::DECREASE['value']];
|
||||
}
|
||||
if ($type == 'gain') {
|
||||
$where[] = ['action', '=', MoneyAction::INCREASE['value']];
|
||||
}
|
||||
if ($type == 'recharge') {
|
||||
$where[] = ['scene', '=', PointsBillScene::RECHARGE['value']];
|
||||
}
|
||||
}
|
||||
$PluginFinanceBill = PluginUserPointsBill::where($where)->order('create_time', 'desc')->paginate($limit);
|
||||
|
||||
return $this->resData($PluginFinanceBill);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\enum\ResponseCode;
|
||||
use app\expose\enum\ResponseEvent;
|
||||
use app\expose\exception\Exception;
|
||||
use plugin\control\expose\helper\Wechat;
|
||||
use plugin\user\app\model\PluginUserWechat;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
|
||||
class BindThirdPartyController extends Basic
|
||||
{
|
||||
public function wechat(Request $request)
|
||||
{
|
||||
if ($request->twofa_state) {
|
||||
$time = time() - (10 * 60);
|
||||
if ($request->twofa['time'] < $time) {
|
||||
return $this->fail('请验证你的身份', [
|
||||
'code' => ResponseCode::NEED_TWOFA,
|
||||
'action' => 'stop'
|
||||
]);
|
||||
}
|
||||
}
|
||||
if ($request->isWehcatBrowser) {
|
||||
} else {
|
||||
try {
|
||||
$res = Wechat::createQrCode(Wechat::QR_STR_SCENE, 600, [
|
||||
'plugin\user\expose\helper\WechatOfficialAccount',
|
||||
'bind',
|
||||
[
|
||||
'uid' => $request->uid,
|
||||
'channels_uid' => $request->channels_uid,
|
||||
]
|
||||
]);
|
||||
return $this->resData(['qrcode' => $res['url'], 'id' => $res['id'], 'expire' => strtotime("+" . $res['expire_seconds'] . " seconds")]);
|
||||
} catch (Exception $e) {
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
try {
|
||||
$res = Wechat::createQrCode(Wechat::QR_SCENE, 600, [
|
||||
'plugin\user\expose\helper\WechatOfficialAccount',
|
||||
'scan',
|
||||
[
|
||||
'uid' => $request->uid,
|
||||
'channels_uid' => $request->channels_uid,
|
||||
]
|
||||
]);
|
||||
return $this->resData(['qrcode' => $res['url'], 'id' => $res['id'], 'expire' => strtotime("+" . $res['expire_seconds'] . " seconds")]);
|
||||
} catch (Exception $e) {
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
/* $auth_url='';
|
||||
return $this->code(ResponseCode::OPEN_NEW_WINDOW, '请在微信中打开', [
|
||||
'url' => $auth_url
|
||||
]); */
|
||||
return $this->fail('无可用的微信服务,请联系客服');
|
||||
}
|
||||
}
|
||||
public function checkWechat(Request $request)
|
||||
{
|
||||
$PluginUserWechat = PluginUserWechat::where('uid', $request->uid)->find();
|
||||
if ($PluginUserWechat) {
|
||||
return $this->code(ResponseCode::SUCCESS_EVENT_PUSH, '绑定成功', [
|
||||
'event' => ResponseEvent::UPDATE_USERINFO
|
||||
]);
|
||||
}
|
||||
$id = $request->post('id');
|
||||
if(!$id){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$Scene = Redis::get($id);
|
||||
if (!$Scene) {
|
||||
return $this->fail('二维码已过期');
|
||||
}
|
||||
$res = Redis::get($id.'.bind');
|
||||
if($res){
|
||||
$res = json_decode($res,true);
|
||||
if($res['status'] == 'fail'){
|
||||
return $this->fail($res['message']);
|
||||
}
|
||||
}
|
||||
return $this->code(ResponseCode::WAIT,'等待微信扫码');
|
||||
}
|
||||
public function unbindWechat(Request $request)
|
||||
{
|
||||
if ($request->twofa_state) {
|
||||
$time = time() - (10 * 60);
|
||||
if ($request->twofa['time'] < $time) {
|
||||
return $this->fail('请验证你的身份', [
|
||||
'code' => ResponseCode::NEED_TWOFA,
|
||||
'action' => 'stop'
|
||||
]);
|
||||
}
|
||||
}
|
||||
$PluginUserWechat = PluginUserWechat::where('uid', $request->uid)->find();
|
||||
if ($PluginUserWechat) {
|
||||
$PluginUserWechat->uid=null;
|
||||
$PluginUserWechat->save();
|
||||
}
|
||||
return $this->code(ResponseCode::SUCCESS_EVENT_PUSH, '解绑成功', [
|
||||
'event' => ResponseEvent::UPDATE_USERINFO
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\enum\State;
|
||||
use app\expose\helper\Captcha;
|
||||
use app\expose\utils\Password;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use support\Request;
|
||||
|
||||
class CaptchaController extends Basic
|
||||
{
|
||||
protected $notNeedLoginAll = true;
|
||||
public function captcha(Request $request)
|
||||
{
|
||||
$builder = Captcha::create();
|
||||
$img_content = $builder->get();
|
||||
$request->session()->set('captcha', [
|
||||
'captcha' => strtolower($builder->getPhrase()),
|
||||
'expire' => time() + 60 * 5
|
||||
]);
|
||||
// 输出验证码二进制数据
|
||||
return response($img_content, 200, ['Content-Type' => 'image/jpeg']);
|
||||
}
|
||||
public function captcha_base64(Request $request)
|
||||
{
|
||||
return Captcha::captcha();
|
||||
}
|
||||
public function captcha_json(Request $request)
|
||||
{
|
||||
return $this->resData(Captcha::captchaCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\enum\ResponseCode;
|
||||
use app\expose\enum\State;
|
||||
use app\expose\exception\Exception;
|
||||
use app\expose\helper\Captcha;
|
||||
use app\expose\helper\Config;
|
||||
use plugin\control\expose\helper\Vcode;
|
||||
use app\expose\utils\Password;
|
||||
use plugin\control\expose\helper\Wechat;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\app\model\PluginUserInvitationCode;
|
||||
use plugin\user\expose\helper\User;
|
||||
use plugin\user\utils\enum\VcodeScene;
|
||||
use support\Log;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
use think\facade\Db;
|
||||
|
||||
class LoginController extends Basic
|
||||
{
|
||||
protected $notNeedLoginAll = true;
|
||||
public function login(Request $request)
|
||||
{
|
||||
$D = $request->post();
|
||||
$where = [];
|
||||
# 判断$D['username']是用户名,11位手机号,邮箱
|
||||
if (empty($D['username'])) {
|
||||
return $this->fail('请输入用户名|手机号|邮箱');
|
||||
}
|
||||
$username = $D['username'];
|
||||
if (preg_match('/^\d{11}$/', $username)) {
|
||||
// 11位手机号
|
||||
$where[] = ['mobile', '=', $username];
|
||||
} elseif (filter_var($username, FILTER_VALIDATE_EMAIL)) {
|
||||
// 邮箱
|
||||
$where[] = ['email', '=', $username];
|
||||
} else {
|
||||
// 用户名
|
||||
$where[] = ['username', '=', $username];
|
||||
}
|
||||
$where[] = ['channels_uid', '=', $request->channels_uid];
|
||||
$user = PluginUser::where($where)->find();
|
||||
if (!$user) {
|
||||
return $this->fail('用户不存在');
|
||||
}
|
||||
// 验证登录密码
|
||||
if (!Password::verify((string) $D['password'], (string) $user->password)) {
|
||||
return $this->fail('密码错误');
|
||||
}
|
||||
if ($user->state == State::NO['value']) {
|
||||
return $this->fail('用户状态异常');
|
||||
}
|
||||
$captcha_state = Config::get('captcha', 'state');
|
||||
// 检验图像验证码
|
||||
if ($captcha_state) {
|
||||
if (empty($D['captcha'])) {
|
||||
return $this->fail('请输入验证码');
|
||||
}
|
||||
$token = $D['token'] ?? null;
|
||||
if (!Captcha::check($D['captcha'], $token)) {
|
||||
return $this->fail('验证码错误');
|
||||
}
|
||||
}
|
||||
|
||||
// 更新登录信息
|
||||
$ip = $request->getRealIp();
|
||||
$user->login_ip = $ip;
|
||||
$user->login_time = date('Y-m-d H:i:s');
|
||||
if ($user->save() === false) {
|
||||
return $this->fail('登录失败');
|
||||
}
|
||||
$info = PluginUser::getTokenInfo($user);
|
||||
return $this->resData($info);
|
||||
}
|
||||
public function vcode(Request $request)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$username = $request->post('username');
|
||||
$vcode = $request->post('vcode');
|
||||
$token = $request->post('token');
|
||||
$code = $request->header('X-Icode') ?? null;
|
||||
Vcode::check($username, $vcode, VcodeScene::SIGNUP['value'], $token);
|
||||
$PluginUserInvitationCode = null;
|
||||
if ($code) {
|
||||
$PluginUserInvitationCode = PluginUserInvitationCode::where(['code' => $code])->find();
|
||||
if (!$PluginUserInvitationCode) {
|
||||
$PluginUserInvitationCode = null;
|
||||
}
|
||||
if ($PluginUserInvitationCode->status != 'unused') {
|
||||
$PluginUserInvitationCode = null;
|
||||
}
|
||||
if($PluginUserInvitationCode->uid == $request->uid){
|
||||
$PluginUserInvitationCode = null;
|
||||
}
|
||||
if($PluginUserInvitationCode->state != State::YES['value']){
|
||||
$PluginUserInvitationCode = null;
|
||||
}
|
||||
}
|
||||
$user = PluginUser::where('mobile', $username)->find();
|
||||
if (!$user) {
|
||||
$data = [
|
||||
'channels_uid' => $request->channels_uid,
|
||||
'mobile' => $username,
|
||||
'state' => State::YES['value'],
|
||||
];
|
||||
if ($PluginUserInvitationCode != null) {
|
||||
$data['puid'] = $PluginUserInvitationCode->uid;
|
||||
$data['activation_time'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
$user = new PluginUser();
|
||||
$user->save($data);
|
||||
}
|
||||
if ($user->state == State::NO['value']) {
|
||||
throw new Exception('用户状态异常');
|
||||
}
|
||||
// 更新登录信息
|
||||
$ip = $request->getRealIp();
|
||||
$user->login_ip = $ip;
|
||||
$user->login_time = date('Y-m-d H:i:s');
|
||||
if ($PluginUserInvitationCode != null) {
|
||||
$PluginUserInvitationCode->status = 'used';
|
||||
$PluginUserInvitationCode->use_uid = $user->id;
|
||||
$PluginUserInvitationCode->use_time = date('Y-m-d H:i:s');
|
||||
$PluginUserInvitationCode->save();
|
||||
}
|
||||
if ($user->save() === false) {
|
||||
throw new Exception('登录失败');
|
||||
}
|
||||
$info = PluginUser::getTokenInfo($user);
|
||||
Db::commit();
|
||||
return $this->resData($info);
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
return $this->exception($th);
|
||||
}
|
||||
}
|
||||
public function qrcode(Request $request)
|
||||
{
|
||||
return $this->wechat($request);
|
||||
}
|
||||
public function wechat(Request $request)
|
||||
{
|
||||
if ($request->isWehcatBrowser && $request->isMobile) {
|
||||
} else {
|
||||
if (!empty($request->uid)) {
|
||||
try {
|
||||
$code = $request->header('X-Icode') ?? null;
|
||||
$res = Wechat::createQrCode(Wechat::QR_STR_SCENE, 600, [
|
||||
'plugin\user\expose\helper\WechatOfficialAccount',
|
||||
'bind',
|
||||
[
|
||||
'channels_uid' => $request->channels_uid,
|
||||
'code' => $code,
|
||||
'uid' => $request->uid,
|
||||
]
|
||||
]);
|
||||
return $this->resData(['qrcode' => $res['url'], 'id' => $res['id'], 'expire' => strtotime("+" . $res['expire_seconds'] . " seconds")]);
|
||||
} catch (Exception $e) {
|
||||
p($e->getMessage());
|
||||
Log::info($e->getMessage(), $e->getTrace());
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
}
|
||||
try {
|
||||
$code = $request->header('X-Icode') ?? null;
|
||||
$res = Wechat::createQrCode(Wechat::QR_STR_SCENE, 600, [
|
||||
'plugin\user\expose\helper\WechatOfficialAccount',
|
||||
'login',
|
||||
[
|
||||
'channels_uid' => $request->channels_uid,
|
||||
'code' => $code,
|
||||
]
|
||||
]);
|
||||
return $this->resData(['qrcode' => $res['url'], 'id' => $res['id'], 'expire' => strtotime("+" . $res['expire_seconds'] . " seconds")]);
|
||||
} catch (Exception $e) {
|
||||
p($e->getMessage());
|
||||
Log::info($e->getMessage(), $e->getTrace());
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
try {
|
||||
$res = Wechat::createQrCode(Wechat::QR_SCENE, 600, [
|
||||
'plugin\user\expose\helper\WechatOfficialAccount',
|
||||
'scan',
|
||||
[
|
||||
'channels_uid' => $request->channels_uid,
|
||||
'code' => $code,
|
||||
]
|
||||
]);
|
||||
return $this->resData(['qrcode' => $res['url'], 'id' => $res['id'], 'expire' => strtotime("+" . $res['expire_seconds'] . " seconds")]);
|
||||
} catch (Exception $e) {
|
||||
Log::info($e->getMessage(), $e->getTrace());
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
/* $auth_url='';
|
||||
return $this->code(ResponseCode::OPEN_NEW_WINDOW, '请在微信中打开', [
|
||||
'url' => $auth_url
|
||||
]); */
|
||||
return $this->fail('无可用的微信服务,请联系客服');
|
||||
}
|
||||
}
|
||||
public function checkQrcode(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
if (!$id) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$Scene = Redis::get($id);
|
||||
if (!$Scene) {
|
||||
return $this->fail('二维码已过期');
|
||||
}
|
||||
$res = Redis::get($id . '.login');
|
||||
if ($res) {
|
||||
$res = json_decode($res, true);
|
||||
if ($res['status'] == 'success') {
|
||||
$user = PluginUser::where('id', $res['uid'])->find();
|
||||
if ($user) {
|
||||
// 更新登录信息
|
||||
$ip = $request->getRealIp();
|
||||
$user->login_ip = $ip;
|
||||
$user->login_time = date('Y-m-d H:i:s');
|
||||
if ($user->save() === false) {
|
||||
return $this->fail('登录失败');
|
||||
}
|
||||
$info = PluginUser::getTokenInfo($user);
|
||||
return $this->resData($info);
|
||||
} else {
|
||||
return $this->fail('登录失败');
|
||||
}
|
||||
} else {
|
||||
return $this->fail($res['message']);
|
||||
}
|
||||
}
|
||||
return $this->code(ResponseCode::WAIT, '等待微信扫码');
|
||||
}
|
||||
|
||||
public function checkBind(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
if (!$id) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$Scene = Redis::get($id);
|
||||
if (!$Scene) {
|
||||
return $this->fail('二维码已过期');
|
||||
}
|
||||
$res = Redis::get($id . '.bind');
|
||||
if ($res) {
|
||||
$res = json_decode($res, true);
|
||||
if ($res['status'] == 'success') {
|
||||
return $this->resData(['status' => 'success']);
|
||||
} else {
|
||||
return $this->fail($res['message']);
|
||||
}
|
||||
}
|
||||
return $this->code(ResponseCode::WAIT, '等待微信扫码');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\enum\State;
|
||||
use plugin\control\expose\helper\Vcode;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\expose\helper\User;
|
||||
use plugin\user\utils\enum\VcodeScene;
|
||||
use support\Request;
|
||||
|
||||
class SignupController extends Basic
|
||||
{
|
||||
protected $notNeedLoginAll = true;
|
||||
protected $notVerificationSourceAll = true;
|
||||
public function index(Request $request)
|
||||
{
|
||||
$D = $request->post();
|
||||
Vcode::check($D['username'],$D['vcode'],VcodeScene::SIGNUP['value'],$D['token']);
|
||||
try {
|
||||
$UserModel = User::create([
|
||||
'mobile' => $D['username'],
|
||||
]);
|
||||
$user =PluginUser::where('id',$UserModel->id)->find();
|
||||
if(!$user){
|
||||
return $this->fail('用户不存在');
|
||||
}
|
||||
if($user->state == State::NO['value']){
|
||||
return $this->fail('用户状态异常');
|
||||
}
|
||||
|
||||
// 更新登录信息
|
||||
$ip = $request->getRealIp();
|
||||
$user->login_ip = $ip;
|
||||
$user->login_time = date('Y-m-d H:i:s');
|
||||
if ($user->save() === false) {
|
||||
return $this->fail('登录失败');
|
||||
}
|
||||
$info = PluginUser::getTokenInfo($user);
|
||||
return $this->resData($info);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\trait\Uploads;
|
||||
|
||||
class UploadsController extends Basic
|
||||
{
|
||||
use Uploads;
|
||||
public function __construct()
|
||||
{
|
||||
$this->uid = request()->uid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use plugin\finance\utils\enum\BillScene;
|
||||
use plugin\user\app\model\PluginUserBill;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use support\Request;
|
||||
|
||||
class UserBillController extends Basic
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$uid = $request->uid;
|
||||
$limit=$request->get('limit',10);
|
||||
$where=[
|
||||
['uid','=',$uid]
|
||||
];
|
||||
$action=$request->get('action','all');
|
||||
if($action&&$action!='all'){
|
||||
$where[]=['action','=',$action];
|
||||
}
|
||||
$scene=$request->get('scene','all');
|
||||
if($scene&&$scene!='all'){
|
||||
$where[]=['scene','=',$scene];
|
||||
}
|
||||
$start_time=$request->get('start_time');
|
||||
$end_time=$request->get('end_time');
|
||||
if($start_time&&$end_time){
|
||||
$where[]=['create_time','between',[$start_time,$end_time]];
|
||||
}elseif($start_time){
|
||||
$where[]=['create_time','>=',$start_time];
|
||||
}elseif($end_time){
|
||||
$where[]=['create_time','<=',$end_time];
|
||||
}
|
||||
$PluginUserBill = PluginUserBill::where($where)->order('create_time', 'desc')->paginate($limit)->each(function($item){
|
||||
$item->action_text=MoneyAction::get($item->action);
|
||||
$item->scene_text=BillScene::get($item->scene);
|
||||
});
|
||||
if($PluginUserBill->isEmpty()){
|
||||
return $this->fail();
|
||||
}
|
||||
return $this->resData($PluginUserBill->scene('external'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,445 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\enum\ResponseCode;
|
||||
use app\expose\enum\ResponseEvent;
|
||||
use app\expose\enum\State;
|
||||
use plugin\control\expose\helper\Vcode;
|
||||
use app\expose\utils\TwofaAuthenticator;
|
||||
use app\model\Uploads;
|
||||
use app\model\UploadsClassify;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\app\model\PluginUserInvitationCode;
|
||||
use plugin\user\app\model\PluginUserTwofaSecret;
|
||||
use plugin\user\app\model\PluginUserWechat;
|
||||
use plugin\user\expose\helper\User;
|
||||
use plugin\user\utils\enum\TotpApp;
|
||||
use plugin\user\utils\enum\VcodeScene;
|
||||
use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
use support\Request;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserController extends Basic
|
||||
{
|
||||
protected $notNeedTwofa = ['getTwofaList', 'refreshTwofaSecret'];
|
||||
protected $notNeedLogin = ['checkInvitationCode'];
|
||||
public function info(Request $request)
|
||||
{
|
||||
$user = PluginUser::where(['id' => $request->uid])->find();
|
||||
if (!$user) {
|
||||
return $this->fail('用户不存在');
|
||||
}
|
||||
$info = PluginUser::getTokenInfo($user, $request->twofa);
|
||||
$count = PluginUserInvitationCode::where(['uid' => $request->uid])->where('state', State::YES['value'])->where('status', 'unused')->count();
|
||||
$info->invitation_code_count = $count;
|
||||
return $this->resData($info);
|
||||
}
|
||||
public function update(Request $request)
|
||||
{
|
||||
$D = $request->post();
|
||||
try {
|
||||
if ($request->twofa_state) {
|
||||
$time = time() - (10 * 60);
|
||||
if ($request->twofa['time'] < $time) {
|
||||
return $this->fail('请验证你的身份', [
|
||||
'code' => ResponseCode::NEED_TWOFA,
|
||||
'action' => 'stop'
|
||||
]);
|
||||
}
|
||||
switch (true) {
|
||||
case isset($D['username']):
|
||||
$PluginUser = PluginUser::where(['id' => $request->uid])->find();
|
||||
$username_time = $PluginUser->username_time ? 30 - ceil((time() - strtotime($PluginUser->username_time)) / 86400) : 0;
|
||||
if ($username_time > 0) {
|
||||
return $this->fail('30天内仅支持修改一次');
|
||||
}
|
||||
break;
|
||||
case isset($D['mobile']):
|
||||
Vcode::check($D['mobile'], $D['vcode'], VcodeScene::BIND_MOBILE['value'], $D['token']);
|
||||
break;
|
||||
case isset($D['email']):
|
||||
Vcode::check($D['email'], $D['vcode'], VcodeScene::BIND_EMAIL['value'], $D['token']);
|
||||
break;
|
||||
case isset($D['password']):
|
||||
if (empty($D['vpassword'])) {
|
||||
return $this->fail('两次输入的密码不一致');
|
||||
}
|
||||
if ($D['password'] != $D['vpassword']) {
|
||||
return $this->fail('两次输入的密码不一致');
|
||||
}
|
||||
Vcode::check($D['username'], $D['vcode'], VcodeScene::SET_PASSWORD['value'], $D['token'] ?? null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$D['channels_uid'] = $request->channels_uid;
|
||||
User::update($request->uid, $D);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->code(ResponseCode::SUCCESS_EVENT_PUSH, '更新成功', [
|
||||
'event' => ResponseEvent::UPDATE_USERINFO
|
||||
]);
|
||||
}
|
||||
public function checkUsername(Request $request)
|
||||
{
|
||||
$username = $request->post('username');
|
||||
$user = PluginUser::where(['username' => $username])->find();
|
||||
if ($user && $user->id != $request->uid) {
|
||||
return $this->fail('用户名已存在');
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
public function checkMobile(Request $request)
|
||||
{
|
||||
$mobile = $request->post('mobile');
|
||||
$user = PluginUser::where(['mobile' => $mobile])->find();
|
||||
if ($user) {
|
||||
if ($user->id == $request->uid) {
|
||||
return $this->fail('和原手机号一致');
|
||||
}
|
||||
return $this->fail('手机号已存在');
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
public function checkEmail(Request $request)
|
||||
{
|
||||
$email = $request->post('email');
|
||||
$user = PluginUser::where(['email' => $email])->find();
|
||||
if ($user) {
|
||||
if ($user->id == $request->uid) {
|
||||
return $this->fail('和原邮箱一致');
|
||||
}
|
||||
return $this->fail('邮箱已存在');
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
public function checkTwofa(Request $request)
|
||||
{
|
||||
if (!$request->twofa_state) {
|
||||
return $this->success();
|
||||
}
|
||||
$time = time() - (10 * 60);
|
||||
if ($request->twofa['time'] < $time) {
|
||||
return $this->fail('请验证你的身份', [
|
||||
'code' => ResponseCode::NEED_TWOFA,
|
||||
'action' => 'stop'
|
||||
]);
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
public function uploadHeadimg(Request $request)
|
||||
{
|
||||
$default_channels = config('plugin.shopwwi.filesystem.app.default');
|
||||
$UploadsClassify = UploadsClassify::where(['dir_name' => 'uploads/default', 'is_system' => 1, 'channels' => $default_channels])->find();
|
||||
if (!$UploadsClassify) {
|
||||
return $this->fail('分类不存在');
|
||||
}
|
||||
$date_path = date('Ymd');
|
||||
//单文件上传
|
||||
$file = $request->file('file');
|
||||
try {
|
||||
$result = Storage::adapter($UploadsClassify->channels)->path($UploadsClassify->dir_name . '/' . $date_path)->upload($file);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
try {
|
||||
$Uploads = new Uploads();
|
||||
$Uploads->uid = $request->uid;
|
||||
$Uploads->classify_id = $UploadsClassify->id;
|
||||
$Uploads->filename = $result->origin_name;
|
||||
$Uploads->path = $result->file_name;
|
||||
$Uploads->ext = $result->extension;
|
||||
$Uploads->mime = $result->mime_type;
|
||||
$Uploads->size = $result->size;
|
||||
$Uploads->channels = $UploadsClassify->channels;
|
||||
$Uploads->save();
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
$user = PluginUser::where(['id' => $request->uid])->find();
|
||||
$user->headimg = $result->file_url;
|
||||
$user->save();
|
||||
return $this->code(ResponseCode::SUCCESS_EVENT_PUSH, '保存成功', [
|
||||
'event' => ResponseEvent::UPDATE_USERINFO
|
||||
]);
|
||||
}
|
||||
public function outLogin(Request $request)
|
||||
{
|
||||
return $this->success();
|
||||
}
|
||||
/**
|
||||
* 获取两步验证密钥
|
||||
*/
|
||||
public function getTwofaSecret(Request $request)
|
||||
{
|
||||
try {
|
||||
$ga = new TwofaAuthenticator();
|
||||
$secret = $ga->createSecret();
|
||||
$PluginUser = PluginUser::where(['id' => $request->uid])->find();
|
||||
|
||||
// 生成 otpauth URL
|
||||
$appName = "XH";
|
||||
$accountName = $PluginUser->nickname;
|
||||
$qrCodeUrl = $ga->getQRCode($appName . ':' . $accountName, $secret, $appName);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
|
||||
return $this->resData([
|
||||
'secret' => $secret,
|
||||
'qrcode' => $qrCodeUrl
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证两步验证密钥
|
||||
*/
|
||||
public function verifyTwofaSecret(Request $request)
|
||||
{
|
||||
$code = $request->post('code');
|
||||
$secret = $request->post('secret');
|
||||
$totp_app = $request->post('totp_app');
|
||||
$ga = new TwofaAuthenticator();
|
||||
|
||||
$isValid = $ga->verifyCode($secret, $code, 2); // 1 = 30 秒容差
|
||||
|
||||
if ($isValid) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
$PluginUser = PluginUser::where(['id' => $request->uid])->find();
|
||||
$PluginUser->twofa_state = State::YES['value'];
|
||||
$PluginUser->save();
|
||||
$PluginUserTwofaSecret = new PluginUserTwofaSecret();
|
||||
$PluginUserTwofaSecret->uid = $request->uid;
|
||||
$PluginUserTwofaSecret->secret = $secret;
|
||||
$PluginUserTwofaSecret->totp_app = $totp_app;
|
||||
$PluginUserTwofaSecret->is_default = PluginUserTwofaSecret::where(['uid' => $request->uid])->count() == 0 ? 1 : 0;
|
||||
$PluginUserTwofaSecret->save();
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('验证成功');
|
||||
} else {
|
||||
return $this->fail('验证码错误');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 刷新账户两步验证时效
|
||||
*/
|
||||
public function refreshTwofaSecret(Request $request)
|
||||
{
|
||||
$code = $request->post('code');
|
||||
$totp_app = $request->post('totp_app');
|
||||
$ga = new TwofaAuthenticator();
|
||||
$PluginUserTwofaSecret = PluginUserTwofaSecret::where(['uid' => $request->uid, 'id' => $totp_app])->find();
|
||||
if (!$PluginUserTwofaSecret) {
|
||||
return $this->fail('两步验证密钥不存在');
|
||||
}
|
||||
$secret = $PluginUserTwofaSecret->secret;
|
||||
$isValid = $ga->verifyCode($secret, $code, 2); // 1 = 30 秒容差
|
||||
|
||||
if ($isValid) {
|
||||
$user = PluginUser::where(['id' => $request->uid])->find();
|
||||
if (!$user) {
|
||||
return $this->fail('用户不存在');
|
||||
}
|
||||
$info = PluginUser::getTokenInfo($user, true);
|
||||
return $this->resData($info);
|
||||
} else {
|
||||
return $this->fail('验证码错误');
|
||||
}
|
||||
}
|
||||
public function getTwofaList(Request $request)
|
||||
{
|
||||
$PluginUserTwofaSecret = PluginUserTwofaSecret::where(['uid' => $request->uid])->order('is_default desc,id desc')->select()->scene('external')->each(function ($item) {
|
||||
$item->totp_app_text = TotpApp::get($item->totp_app);
|
||||
});
|
||||
return $this->resData($PluginUserTwofaSecret);
|
||||
}
|
||||
public function setDefaultTwofa(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$PluginUserTwofaSecret = PluginUserTwofaSecret::where(['uid' => $request->uid, 'id' => $id])->find();
|
||||
if (!$PluginUserTwofaSecret) {
|
||||
return $this->fail('两步验证密钥不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
PluginUserTwofaSecret::where(['uid' => $request->uid])->update(['is_default' => 0]);
|
||||
$PluginUserTwofaSecret->is_default = 1;
|
||||
$PluginUserTwofaSecret->save();
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('设置成功');
|
||||
}
|
||||
public function deleteTwofa(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$PluginUserTwofaSecret = PluginUserTwofaSecret::where(['uid' => $request->uid, 'id' => $id])->find();
|
||||
if (!$PluginUserTwofaSecret) {
|
||||
return $this->fail('两步验证密钥不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 判断是否还有其它两步验证密钥
|
||||
$PluginUserTwofaSecretOther = PluginUserTwofaSecret::where(['uid' => $request->uid])->where('id', '<>', $id)->order('id desc')->find();
|
||||
if ($PluginUserTwofaSecretOther) {
|
||||
if ($PluginUserTwofaSecret->is_default == 1) {
|
||||
$PluginUserTwofaSecretOther->is_default = 1;
|
||||
$PluginUserTwofaSecretOther->save();
|
||||
}
|
||||
} else {
|
||||
$PluginUser = PluginUser::where(['id' => $request->uid])->find();
|
||||
$PluginUser->twofa_state = State::NO['value'];
|
||||
$PluginUser->save();
|
||||
}
|
||||
$PluginUserTwofaSecret->delete();
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
/**
|
||||
* 获取用户未使用的邀请码
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2026-01-07
|
||||
*/
|
||||
public function getUnusedInvitationCode(Request $request)
|
||||
{
|
||||
$PluginUserInvitationCode = PluginUserInvitationCode::where(['uid' => $request->uid])
|
||||
->with(['useUser'])
|
||||
->where('channels_uid', $request->channels_uid)
|
||||
->where('state', State::YES['value'])
|
||||
->select();
|
||||
return $this->resData($PluginUserInvitationCode);
|
||||
}
|
||||
/**
|
||||
* 用户绑定邀请码
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2026-01-15
|
||||
*/
|
||||
public function bindInvitationCode(Request $request)
|
||||
{
|
||||
$code = $request->post('code');
|
||||
$PluginUserInvitationCode = PluginUserInvitationCode::where(['code' => $code])->find();
|
||||
if (!$PluginUserInvitationCode) {
|
||||
return $this->fail('邀请码不存在');
|
||||
}
|
||||
if ($PluginUserInvitationCode->uid == $request->uid) {
|
||||
return $this->fail('不能邀请自己');
|
||||
}
|
||||
if (!empty($PluginUserInvitationCode->use_uid)) {
|
||||
return $this->fail('邀请码已使用');
|
||||
}
|
||||
if ($PluginUserInvitationCode->status != 'unused') {
|
||||
return $this->fail('邀请码已使用');
|
||||
}
|
||||
if ($PluginUserInvitationCode->state != State::YES['value']) {
|
||||
return $this->fail('邀请码已失效');
|
||||
}
|
||||
$PluginUserInvitationCode->status = 'used';
|
||||
$PluginUserInvitationCode->use_uid = $request->uid;
|
||||
$PluginUserInvitationCode->use_time = date('Y-m-d H:i:s');
|
||||
$PluginUserInvitationCode->save();
|
||||
$PluginUser = PluginUser::where(['id' => $request->uid])->find();
|
||||
$PluginUser->activation_time = date('Y-m-d H:i:s');
|
||||
$PluginUser->puid = $PluginUserInvitationCode->uid;
|
||||
$PluginUser->save();
|
||||
return $this->success('绑定成功');
|
||||
}
|
||||
/**
|
||||
* 用户绑定电话
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2026-01-15
|
||||
*/
|
||||
public function bindMobile(Request $request)
|
||||
{
|
||||
$mobile = $request->post('username');
|
||||
$username = $request->post('username');
|
||||
$vcode = $request->post('vcode');
|
||||
$token = $request->post('token');
|
||||
if (empty($username) || empty($vcode) || empty($token)) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
Vcode::check($username, $vcode, VcodeScene::BIND_MOBILE['value'], $token);
|
||||
$PluginUser = PluginUser::where(['mobile' => $mobile, 'channels_uid' => $request->channels_uid])->find();
|
||||
if ($PluginUser) {
|
||||
PluginUser::where(['id' => $request->uid])->update(['username' => '']);
|
||||
$wechat = PluginUserWechat::where(['uid' => $request->uid])->find();
|
||||
$wechat->uid = $PluginUser->id;
|
||||
$wechat->save();
|
||||
return $this->resData(PluginUser::getTokenInfo($PluginUser, true));
|
||||
}
|
||||
$PluginUser = PluginUser::where(['id' => $request->uid])->find();
|
||||
if ($PluginUser->mobile) {
|
||||
return $this->fail('电话已绑定');
|
||||
}
|
||||
$PluginUser->mobile = $mobile;
|
||||
$PluginUser->save();
|
||||
return $this->resData(PluginUser::getTokenInfo($PluginUser, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2026-01-17
|
||||
*/
|
||||
public function setPassword(Request $request)
|
||||
{
|
||||
$password = $request->post('password');
|
||||
$token = $request->post('token');
|
||||
$vcode = $request->post('vcode');
|
||||
$username = $request->post('username');
|
||||
if (empty($password) || empty($token) || empty($vcode) || empty($username)) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
Vcode::check($username, $vcode, VcodeScene::BIND_MOBILE['value'], $token);
|
||||
$PluginUser = PluginUser::where(['id' => $request->uid])->find();
|
||||
$PluginUser->password = $password;
|
||||
$PluginUser->save();
|
||||
return $this->success('修改成功');
|
||||
}
|
||||
|
||||
public function wallet(Request $request)
|
||||
{
|
||||
$wallet = PluginFinanceWallet::where(['uid' => $request->uid])->find();
|
||||
if (!$wallet) {
|
||||
return $this->fail('钱包不存在');
|
||||
}
|
||||
return $this->resData($wallet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证邀请码是否被使用
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2026-01-26
|
||||
*/
|
||||
public function checkInvitationCode(Request $request)
|
||||
{
|
||||
$code = $request->post('code');
|
||||
$PluginUserInvitationCode = PluginUserInvitationCode::where(['code' => $code])->find();
|
||||
if (!$PluginUserInvitationCode) {
|
||||
return $this->fail('邀请码不存在');
|
||||
}
|
||||
if ($PluginUserInvitationCode->uid == $request->uid) {
|
||||
return $this->fail('不能邀请自己');
|
||||
}
|
||||
if (!empty($PluginUserInvitationCode->use_uid)) {
|
||||
return $this->fail('邀请码已使用');
|
||||
}
|
||||
if ($PluginUserInvitationCode->status != 'unused') {
|
||||
return $this->fail('邀请码已使用');
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use plugin\finance\utils\enum\BillScene;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\app\model\PluginUserBill;
|
||||
use plugin\user\expose\helper\User as HelperUser;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use support\Request;
|
||||
|
||||
class BalanceController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginUserBill();
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder;
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('nickname', '昵称', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '昵称搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('username', '账号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '账号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('email', '邮箱', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '邮箱搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', 'UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => 'UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('action', '变化类型', 'select', '', [
|
||||
'options' => MoneyAction::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '变化类型搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('userinfo', '用户', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'username',
|
||||
'nicknameTags' => [
|
||||
[
|
||||
'field' => 'new_text',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'week_text',
|
||||
'props' => [
|
||||
'type' => 'warning',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'month_text',
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
|
||||
$builder->add('contact', '联系方式', [
|
||||
'props' => [
|
||||
'width' => '280px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'mobile',
|
||||
'label' => '手机号'
|
||||
],
|
||||
[
|
||||
'field' => 'email',
|
||||
'label' => '邮箱'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('num', '变化金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('before', '变化前金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('after', '变化后金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('remarks', '备注', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('action', '变化类型', [
|
||||
'props' => [
|
||||
'width' => '120px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => MoneyAction::getOptions()
|
||||
]
|
||||
]);
|
||||
$builder->add('scene', '触发场景', [
|
||||
'props' => [
|
||||
'width' => '120px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => BillScene::getOptions()
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '创建时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$where[] = ['ub.channels_uid', '=', $request->channels_uid];
|
||||
$username = $request->get('username');
|
||||
if ($username) {
|
||||
$where[] = ['u.username', 'like', "%{$username}%"];
|
||||
}
|
||||
$mobile = $request->get('mobile');
|
||||
if ($mobile) {
|
||||
$where[] = ['u.mobile', 'like', "%{$mobile}%"];
|
||||
}
|
||||
$email = $request->get('email');
|
||||
if ($email) {
|
||||
$where[] = ['u.email', 'like', "%{$email}%"];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['u.id', '=', $uid];
|
||||
}
|
||||
$list = PluginUserBill::alias('ub')->join('plugin_user u', 'ub.uid = u.id')
|
||||
->field('ub.*,u.nickname,u.headimg,u.username,u.mobile,u.email')
|
||||
->where($where)
|
||||
->order('ub.id desc')
|
||||
->paginate($limit);
|
||||
return $this->resData($list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use plugin\user\app\model\PluginUserInvitationCode;
|
||||
use support\Request;
|
||||
|
||||
class InvitationCodeController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginUserInvitationCode();
|
||||
}
|
||||
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder();
|
||||
$builder->addHeader();
|
||||
$builder->addHeaderAction('生成邀请码', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/user/control/InvitationCode/create',
|
||||
'props' => [
|
||||
'title' => '生成邀请码'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('code', '邀请码', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '邀请码搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', '创建者', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '创建者搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('use_uid', '使用者', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '使用者搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('status', '状态', 'select', '', [
|
||||
'options' => [
|
||||
['label' => '未使用', 'value' => 'unused'],
|
||||
['label' => '已使用', 'value' => 'used']
|
||||
],
|
||||
'props' => [
|
||||
'placeholder' => '状态搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('state', '启用状态', 'select', '', [
|
||||
'options' => State::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '启用状态搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
]);
|
||||
$builder->add('code', '邀请码', [
|
||||
]);
|
||||
$builder->add('userinfo', '创建者', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'user.nickname',
|
||||
'avatar' => 'user.headimg',
|
||||
'info' => 'user.username',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'uid',
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('status', '使用状态', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => [
|
||||
[
|
||||
'label' => '未使用',
|
||||
'value' => 'unused',
|
||||
'props' => [
|
||||
'type' => 'info'
|
||||
]
|
||||
],
|
||||
[
|
||||
'label' => '已使用',
|
||||
'value' => 'used',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('use_userinfo', '使用用户', [
|
||||
'props' => [
|
||||
'width' => '300px'
|
||||
],
|
||||
'where' => [
|
||||
['status', '=', 'used']
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'useUser.nickname',
|
||||
'avatar' => 'useUser.headimg',
|
||||
'info' => 'useUser.username',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'use_uid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('use_time', '使用时间', [
|
||||
'where' => [
|
||||
['status', '=', 'used']
|
||||
],
|
||||
'props' => [
|
||||
'width' => '180px'
|
||||
]
|
||||
]);
|
||||
$builder->add('state', '启用状态', [
|
||||
'component' => [
|
||||
'name' => 'switch',
|
||||
'api' => '/app/user/control/InvitationCode/indexUpdateState',
|
||||
'props' => [
|
||||
'active-value' => State::YES['value'],
|
||||
'inactive-value' => State::NO['value']
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'create_time',
|
||||
'label' => '创建'
|
||||
],
|
||||
[
|
||||
'field' => 'use_time',
|
||||
'label' => '使用'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$where[] = ['channels_uid', '=', $request->channels_uid];
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['uid', '=', $uid];
|
||||
}
|
||||
$use_uid = $request->get('use_uid');
|
||||
if ($use_uid) {
|
||||
$where[] = ['use_uid', '=', $use_uid];
|
||||
}
|
||||
$code = $request->get('code');
|
||||
if ($code) {
|
||||
$where[] = ['code', 'like', "%{$code}%"];
|
||||
}
|
||||
|
||||
$status = $request->get('status');
|
||||
if ($status) {
|
||||
$where[] = ['status', '=', $status];
|
||||
}
|
||||
|
||||
$state = $request->get('state');
|
||||
if ($state !== null && $state !== '') {
|
||||
$where[] = ['state', '=', $state];
|
||||
}
|
||||
|
||||
$list = PluginUserInvitationCode::alias('ic')
|
||||
->where($where)
|
||||
->with([
|
||||
'user' => function ($query) {
|
||||
$query->field('id,nickname,headimg,username,channels_uid');
|
||||
},
|
||||
'useUser' => function ($query) {
|
||||
$query->field('id,nickname,headimg,username,channels_uid');
|
||||
}
|
||||
])
|
||||
->order('ic.id desc')
|
||||
->paginate($limit);
|
||||
|
||||
return $this->resData($list);
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
$D = $request->post();
|
||||
$num = isset($D['num']) ? intval($D['num']) : 1;
|
||||
// 如果不选择用户或为空,默认为0(平台创建)
|
||||
$uid = isset($D['uid']) && $D['uid'] !== '' && $D['uid'] !== null ? intval($D['uid']) : 0;
|
||||
|
||||
if ($num < 1 || $num > 100) {
|
||||
return $this->fail('生成数量必须在1-100之间');
|
||||
}
|
||||
|
||||
try {
|
||||
PluginUserInvitationCode::addCode($uid, $num, $request->channels_uid);
|
||||
return $this->success('生成成功');
|
||||
} catch (\Throwable $th) {
|
||||
return $this->fail($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$builder = new FormBuilder(null, null, [
|
||||
'size' => 'large',
|
||||
'labelPosition' => 'right',
|
||||
'label-width' => '120px'
|
||||
]);
|
||||
|
||||
$Component = new ComponentBuilder;
|
||||
$builder->add('uid', '创建者', 'select', '', [
|
||||
'remote' => [
|
||||
'url' => '/app/user/control/User/query',
|
||||
],
|
||||
'props' => [
|
||||
'clearable' => true,
|
||||
'filterable' => true,
|
||||
'remote' => true,
|
||||
'placeholder' => '不选择则默认为平台创建'
|
||||
],
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '不选择创建者则默认为平台创建(uid=0)'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
]
|
||||
]);
|
||||
$builder->add('num', '生成数量', 'input-number', 1, [
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'min' => 1,
|
||||
'max' => 100,
|
||||
'controls' => true
|
||||
],
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '一次最多生成100个邀请码'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
]
|
||||
]);
|
||||
|
||||
return $this->resData($builder);
|
||||
}
|
||||
|
||||
public function indexUpdateState(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$field = $request->post('field');
|
||||
$value = $request->post('value');
|
||||
$model = $this->model->where(['id' => $id])->find();
|
||||
if (!$model) {
|
||||
return $this->fail('数据不存在');
|
||||
}
|
||||
$model->{$field} = $value;
|
||||
if ($model->save()) {
|
||||
return $this->success();
|
||||
}
|
||||
return $this->fail('操作失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\app\model\PluginUserPointsBill;
|
||||
use plugin\user\expose\helper\User as HelperUser;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use support\Request;
|
||||
|
||||
class PointsController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginUserPointsBill();
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder;
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('nickname', '昵称', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '昵称搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('username', '账号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '账号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('email', '邮箱', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '邮箱搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', 'UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => 'UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('action', '变化类型', 'select', '', [
|
||||
'options' => MoneyAction::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '变化类型搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('time', '时间', 'date-picker', '', [
|
||||
'props' => [
|
||||
'value-format' => "YYYY-MM-DD",
|
||||
'format' => "YYYY-MM-DD",
|
||||
'type' => 'daterange',
|
||||
'placeholder' => '时间范围搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('userinfo', '用户', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'username',
|
||||
'nicknameTags' => [
|
||||
[
|
||||
'field' => 'new_text',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'week_text',
|
||||
'props' => [
|
||||
'type' => 'warning',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'month_text',
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
|
||||
$builder->add('contact', '联系方式', [
|
||||
'props' => [
|
||||
'width' => '280px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'mobile',
|
||||
'label' => '手机号'
|
||||
],
|
||||
[
|
||||
'field' => 'email',
|
||||
'label' => '邮箱'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('num', '变化金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('before', '变化前金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('after', '变化后金额', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('remarks', '备注', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('action', '变化类型', [
|
||||
'props' => [
|
||||
'width' => '120px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => MoneyAction::getOptions()
|
||||
]
|
||||
]);
|
||||
$builder->add('scene', '触发场景', [
|
||||
'props' => [
|
||||
'width' => '120px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => PointsBillScene::getOptions()
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '创建时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$where[] = ['ub.channels_uid', '=', $request->channels_uid];
|
||||
$username = $request->get('username');
|
||||
if ($username) {
|
||||
$where[] = ['u.username', 'like', "%{$username}%"];
|
||||
}
|
||||
$mobile = $request->get('mobile');
|
||||
if ($mobile) {
|
||||
$where[] = ['u.mobile', 'like', "%{$mobile}%"];
|
||||
}
|
||||
$email = $request->get('email');
|
||||
if ($email) {
|
||||
$where[] = ['u.email', 'like', "%{$email}%"];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['u.id', '=', $uid];
|
||||
}
|
||||
$time = $request->get('time');
|
||||
if ($time) {
|
||||
$where[] = ['ub.create_time', 'between', $time];
|
||||
}
|
||||
$list = PluginUserPointsBill::alias('ub')->join('plugin_user u', 'ub.uid = u.id')
|
||||
->field('ub.*,u.nickname,u.headimg,u.username,u.mobile,u.email')
|
||||
->where($where)
|
||||
->order('ub.id desc')
|
||||
->paginate($limit);
|
||||
return $this->resData($list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\trait\Config;
|
||||
|
||||
class SettingController extends Basic
|
||||
{
|
||||
use Config;
|
||||
public function basic()
|
||||
{
|
||||
return $this->builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\enum\Filesystem;
|
||||
use app\expose\enum\SubmitEvent;
|
||||
use app\expose\trait\Config;
|
||||
use app\model\Config as ModelConfig;
|
||||
use support\Request;
|
||||
|
||||
class SystemController extends Basic
|
||||
{
|
||||
use Config;
|
||||
public function register(Request $request)
|
||||
{
|
||||
$this->channels_uid = $request->channels_uid;
|
||||
return $this->builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\expose\helper\User as HelperUser;
|
||||
use support\Request;
|
||||
|
||||
class UserController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginUser;
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder;
|
||||
$builder->addAction('操作', [
|
||||
'width' => '100px',
|
||||
'fixed' => 'right'
|
||||
]);
|
||||
$builder->addTableAction('编辑', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/user/control/User/update',
|
||||
'props' => [
|
||||
'title' => '编辑《ID:{id}》用户'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addHeader();
|
||||
$builder->addHeaderAction('创建用户', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/user/control/User/create',
|
||||
'props' => [
|
||||
'title' => '创建用户'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('nickname', '昵称', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '昵称搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('username', '账号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '账号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('email', '邮箱', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '邮箱搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', 'UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => 'UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('puid', '上级UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '上级UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('userinfo', '用户', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'username',
|
||||
'nicknameTags' => [
|
||||
[
|
||||
'field' => 'new_text',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'week_text',
|
||||
'props' => [
|
||||
'type' => 'warning',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'month_text',
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('puserinfo', '上级', [
|
||||
'where' => [
|
||||
['puid', '!=', null]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'parent.nickname',
|
||||
'avatar' => 'parent,headimg',
|
||||
'info' => 'parent.mobile',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'puid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('contact', '联系方式', [
|
||||
'props' => [
|
||||
'width' => '280px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'mobile',
|
||||
'label' => '手机号'
|
||||
],
|
||||
[
|
||||
'field' => 'email',
|
||||
'label' => '邮箱'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('state', '状态', [
|
||||
'component' => [
|
||||
'name' => 'switch',
|
||||
'api' => '/app/user/control/User/indexUpdateState',
|
||||
'props' => [
|
||||
'active-value' => State::YES['value'],
|
||||
'inactive-value' => State::NO['value']
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('online_time', '活动', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'activation_time',
|
||||
'label' => '激活'
|
||||
],
|
||||
[
|
||||
'field' => 'login_time',
|
||||
'label' => '登录'
|
||||
],
|
||||
[
|
||||
'component' => 'tag',
|
||||
'field' => 'login_ip',
|
||||
'label' => '登录IP',
|
||||
'props' => [
|
||||
'size' => 'small',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'create_time',
|
||||
'label' => '创建'
|
||||
],
|
||||
[
|
||||
'field' => 'update_time',
|
||||
'label' => '更新'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function query(Request $request)
|
||||
{
|
||||
$query = $request->post('query');
|
||||
if (empty($query)) {
|
||||
return $this->resData([]);
|
||||
}
|
||||
$where = [];
|
||||
$where[] = ['nickname|username|mobile|email', 'like', "%{$query}%"];
|
||||
return $this->resData(PluginUser::options($where));
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$where[] = ['channels_uid', '=', $request->channels_uid];
|
||||
$username = $request->get('username');
|
||||
if ($username) {
|
||||
$where[] = ['username', 'like', "%{$username}%"];
|
||||
}
|
||||
$mobile = $request->get('mobile');
|
||||
if ($mobile) {
|
||||
$where[] = ['mobile', 'like', "%{$mobile}%"];
|
||||
}
|
||||
$email = $request->get('email');
|
||||
if ($email) {
|
||||
$where[] = ['email', 'like', "%{$email}%"];
|
||||
}
|
||||
$puid = $request->get('puid');
|
||||
if ($puid) {
|
||||
$where[] = ['puid', '=', $puid];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['id', '=', $uid];
|
||||
}
|
||||
$list = PluginUser::where($where)->with(['parent' => function ($query) {
|
||||
$query->field('id,nickname,headimg,mobile');
|
||||
}])
|
||||
->order('id desc')->paginate($limit)->each(function ($item) {
|
||||
// 三天以内创建的
|
||||
$create_time = strtotime($item->create_time);
|
||||
$create_time = time() - $create_time;
|
||||
if ($create_time < 3 * 24 * 60 * 60) {
|
||||
$item->new_text = '新用户';
|
||||
} elseif ($create_time < 7 * 24 * 60 * 60) {
|
||||
$item->week_text = '一周内';
|
||||
} elseif ($create_time < 30 * 24 * 60 * 60) {
|
||||
$item->month_text = '30天内';
|
||||
}
|
||||
});
|
||||
return $this->resData($list);
|
||||
}
|
||||
public function create(Request $request)
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
$D = $request->post();
|
||||
try {
|
||||
$D['channels_uid'] = $request->channels_uid;
|
||||
HelperUser::create($D);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('创建成功');
|
||||
}
|
||||
$builder = $this->getFormBuilder();
|
||||
$Component = new ComponentBuilder;
|
||||
$builder->add('activation_time', '激活时间', 'date-picker', null, [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '不选择时间则不激活,由用户前台登录后自动激活'], ['type' => 'info', 'size' => 'small'])
|
||||
->builder()
|
||||
],
|
||||
'props' => [
|
||||
'placeholder' => '选择激活时间',
|
||||
'type' => 'datetime',
|
||||
'format' => 'YYYY-MM-DD HH:mm:ss',
|
||||
'value-format' => 'YYYY-MM-DD HH:mm:ss'
|
||||
]
|
||||
]);
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function update(Request $request)
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
$D = $request->post();
|
||||
try {
|
||||
$D['channels_uid'] = $request->channels_uid;
|
||||
HelperUser::update($D['id'], $D);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('更新成功');
|
||||
}
|
||||
$id = $request->get('id');
|
||||
$User = PluginUser::where(['id' => $id])->withoutField('password')->find();
|
||||
$builder = $this->getFormBuilder();
|
||||
$builder->setData($User->toArray());
|
||||
return $this->resData($builder);
|
||||
}
|
||||
private function getFormBuilder()
|
||||
{
|
||||
$builder = new FormBuilder(null, null, [
|
||||
'labelPosition' => 'right',
|
||||
'label-width' => "200px",
|
||||
'class' => 'w-80 mx-auto',
|
||||
'size' => 'large',
|
||||
]);
|
||||
$Component = new ComponentBuilder;
|
||||
$builder->add('nickname', '昵称', 'input', '', [
|
||||
'required' => true,
|
||||
'maxlength' => 30,
|
||||
'show-word-limit' => true
|
||||
]);
|
||||
$builder->add('headimg', '头像', 'bundle', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '支持jpg、png、jpeg格式,大小不超过2M'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'accept' => 'image/jpeg,image/png,image/jpg',
|
||||
'multiple' => 1,
|
||||
'size' => 2
|
||||
]
|
||||
]);
|
||||
$builder->add('username', '账号', 'input', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '支持字母、数字、下划线,长度不超过30个字符'], ['type' => 'info', 'size' => 'small'])->builder(),
|
||||
$Component->add('text', ['default' => '可用于账号登录'], ['type' => 'success', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'maxlength' => 30,
|
||||
'show-word-limit' => true
|
||||
]
|
||||
]);
|
||||
$builder->add('mobile', '手机号', 'input', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '中国大陆11位手机号'], ['type' => 'info', 'size' => 'small'])->builder(),
|
||||
$Component->add('text', ['default' => '可用于账号,短信验证码登录'], ['type' => 'success', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'maxlength' => 11,
|
||||
'show-word-limit' => true
|
||||
]
|
||||
]);
|
||||
$builder->add('email', '邮箱', 'input', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '可用于账号,邮箱验证码登录'], ['type' => 'success', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'maxlength' => 100,
|
||||
'show-word-limit' => true
|
||||
]
|
||||
]);
|
||||
$builder->add('password', '密码', 'input', '', [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '不修改密码请留空'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'placeholder' => '不修改密码请留空',
|
||||
'maxlength' => 30,
|
||||
'show-word-limit' => true
|
||||
]
|
||||
]);
|
||||
return $builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Here is your custom functions.
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\expose\enum\EventName;
|
||||
use app\expose\utils\Password;
|
||||
use app\expose\utils\Rsa;
|
||||
use app\expose\utils\Str;
|
||||
use app\model\Basic;
|
||||
use loong\oauth\facade\Auth;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
use plugin\control\expose\helper\Uploads;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use plugin\user\utils\enum\UserPermission;
|
||||
use Webman\Event\Event;
|
||||
|
||||
class PluginUser extends Basic
|
||||
{
|
||||
public function channels()
|
||||
{
|
||||
return $this->hasOne(PluginChannelsUser::class, 'id', 'channels_uid');
|
||||
}
|
||||
public function parent()
|
||||
{
|
||||
return $this->hasOne(PluginUser::class, 'id', 'puid');
|
||||
}
|
||||
public function wallet()
|
||||
{
|
||||
return $this->hasOne(PluginFinanceWallet::class, 'uid', 'id');
|
||||
}
|
||||
public function getHeadimgAttr($value, $data)
|
||||
{
|
||||
if(empty($value)){
|
||||
return '';
|
||||
}
|
||||
return Uploads::url($data['channels_uid'], $value);
|
||||
}
|
||||
public function setHeadimgAttr($value, $data)
|
||||
{
|
||||
return Uploads::path($data['channels_uid'], $value);
|
||||
}
|
||||
public function setPasswordAttr($value)
|
||||
{
|
||||
return $value ? Password::encrypt($value) : $value;
|
||||
}
|
||||
public static function options($where = [])
|
||||
{
|
||||
$models = self::where($where)->field('id,nickname,mobile')->select();
|
||||
$data = [];
|
||||
foreach ($models as $item) {
|
||||
$data[] = [
|
||||
'label' => $item->nickname,
|
||||
'value' => $item->id,
|
||||
'tips' => "UID:{$item->id},M:{$item->mobile}"
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
public static function genUser($id)
|
||||
{
|
||||
$id = (int)$id;
|
||||
return str_replace(['+', '/'], ['-', '_'], Rsa::encryptNumber($id));
|
||||
}
|
||||
public static function getUidByUser($user)
|
||||
{
|
||||
return Rsa::decryptNumber(str_replace(['-', '_'], ['+', '/'], $user));
|
||||
}
|
||||
public static function getTokenInfo($model, $twofa = false)
|
||||
{
|
||||
$request = request();
|
||||
/* 重组用户信息 */
|
||||
$User = new \stdClass;
|
||||
$User->user = self::genUser($model->id);
|
||||
$User->nickname = $model->nickname;
|
||||
$User->headimg = $model->headimg;
|
||||
$User->id = $model->id;
|
||||
$User->username = $model->username;
|
||||
$User->username_time = $model->username_time ? 30 - ceil((time() - strtotime($model->username_time)) / 86400) : 0;
|
||||
$User->mobile = Str::mask($model->mobile);
|
||||
$User->email = Str::mask($model->email);
|
||||
$User->password = $model->password ? 1 : 0;
|
||||
$User->create_time = $model->create_time;
|
||||
$User->last_login_time = $model->login_time;
|
||||
$User->last_login_ip = $model->login_ip;
|
||||
$User->twofa_state = $model->twofa_state;
|
||||
$User->activation_time = $model->activation_time;
|
||||
$PluginUserWechat = PluginUserWechat::where(['uid' => $model->id])->field('openid,unionid,mp_openid,nickname,headimg,subscribe')->find();
|
||||
if ($PluginUserWechat) {
|
||||
$User->wechat = $PluginUserWechat;
|
||||
}
|
||||
$User->permissions = [];
|
||||
if ($model->mobile) {
|
||||
$User->permissions[] = UserPermission::MOBILE['value'];
|
||||
}
|
||||
if ($model->email) {
|
||||
$User->permissions[] = UserPermission::EMAIL['value'];
|
||||
}
|
||||
if ($model->twofa_state) {
|
||||
$User->permissions[] = UserPermission::TWOFA['value'];
|
||||
}
|
||||
if ($model->username) {
|
||||
$User->permissions[] = UserPermission::USERNAME['value'];
|
||||
}
|
||||
if ($model->password) {
|
||||
$User->permissions[] = UserPermission::PASSWORD['value'];
|
||||
}
|
||||
if ($model->realname) {
|
||||
$User->permissions[] = UserPermission::REALNAME['value'];
|
||||
}
|
||||
if ($model->mobile && $model->realname) {
|
||||
$User->permissions[] = UserPermission::BUY['value'];
|
||||
}
|
||||
$pluginConfig = glob(base_path("plugin/*/api/{$request->app}/PublicController.php"));
|
||||
foreach ($pluginConfig as $path) {
|
||||
$plugin_name = basename(dirname(dirname(dirname($path))));
|
||||
if ($plugin_name == 'user') {
|
||||
continue;
|
||||
}
|
||||
$class = 'plugin\\' . $plugin_name . "\\api\\{$request->app}\\PublicController";
|
||||
if (!class_exists($class)) {
|
||||
continue;
|
||||
}
|
||||
$plugin = new $class;
|
||||
if (method_exists($plugin, 'appendUserInfo')) {
|
||||
$plugin->appendUserInfo($User, $model);
|
||||
}
|
||||
}
|
||||
/* 生成token */
|
||||
$data = new \stdClass;
|
||||
$data->uid = $model->id;
|
||||
$data->channels_uid = $model->channels_uid;
|
||||
$data->username = $model->username;
|
||||
$data->mobile = $model->mobile;
|
||||
$data->email = $model->email;
|
||||
$data->twofa_state = $model->twofa_state;
|
||||
if ($twofa) {
|
||||
if ($twofa === true) {
|
||||
$data->twofa = [
|
||||
'expire' => time() + (config('oauth.expire') / 2),
|
||||
'time' => time(),
|
||||
];
|
||||
} else {
|
||||
$data->twofa = $twofa;
|
||||
}
|
||||
}
|
||||
$User->token = Auth::setPrefix('CONTROL')->encrypt($data);
|
||||
if ($request->token) {
|
||||
Auth::setPrefix('CONTROL')->refresh($request->token, 60);
|
||||
}
|
||||
return $User;
|
||||
}
|
||||
public static function onAfterRead($model)
|
||||
{
|
||||
if (empty($model->nickname)) {
|
||||
if (!empty($model->mobile)) {
|
||||
$model->nickname = 'FM-' . substr($model->mobile, -4);
|
||||
} else {
|
||||
$model->nickname = '未命名的用户';
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function onBeforeWrite($model)
|
||||
{
|
||||
if (empty($model->nickname)) {
|
||||
if (!empty($model->mobile)) {
|
||||
$model->nickname = 'FM-' . substr($model->mobile, -4);
|
||||
} else {
|
||||
$model->nickname = 'FM-' . Str::random();
|
||||
}
|
||||
} else {
|
||||
$model->nickname = iconv('UTF-8', 'UTF-8//IGNORE', $model->nickname);
|
||||
}
|
||||
}
|
||||
public static function onAfterInsert($model)
|
||||
{
|
||||
$PluginFinanceWallet = new PluginFinanceWallet;
|
||||
$PluginFinanceWallet->channels_uid = $model->channels_uid;
|
||||
$PluginFinanceWallet->uid = $model->id;
|
||||
$PluginFinanceWallet->save();
|
||||
Event::emit(EventName::USER_REGISTER['value'], $model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
use plugin\finance\utils\enum\BillScene;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use think\facade\Db;
|
||||
|
||||
class PluginUserBill extends Basic
|
||||
{
|
||||
public function channels()
|
||||
{
|
||||
return $this->hasOne(PluginChannelsUser::class, 'id', 'channels_uid');
|
||||
}
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'type' => [
|
||||
'num' => 'float',
|
||||
'before' => 'float',
|
||||
'after' => 'float',
|
||||
],
|
||||
];
|
||||
}
|
||||
public static function consume($order)
|
||||
{
|
||||
$uid = $order->uid;
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
if ($wallet->balance < $order->money) {
|
||||
throw new \Exception('余额不足');
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'form_id' => $order->id,
|
||||
'num' => $order->money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance - $order->money,
|
||||
'remarks' => $order->title . ' 订单号:' . $order->trade_no,
|
||||
'action' => MoneyAction::DECREASE['value'],
|
||||
'scene' => $order->type,
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance - ' . $order->money);
|
||||
$wallet->balance_used = Db::raw('balance_used + ' . $order->money);
|
||||
$wallet->save();
|
||||
}
|
||||
public static function expend($uid, $money, $title)
|
||||
{
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'num' => $money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance - $money,
|
||||
'remarks' => $title,
|
||||
'action' => MoneyAction::DECREASE['value'],
|
||||
'scene' => BillScene::ADMIN['value'],
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance - ' . $money);
|
||||
$wallet->balance_sum = Db::raw('balance_sum - ' . $money);
|
||||
$wallet->save();
|
||||
}
|
||||
public static function income($uid, $money, $title)
|
||||
{
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'num' => $money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance + $money,
|
||||
'remarks' => $title,
|
||||
'action' => MoneyAction::INCREASE['value'],
|
||||
'scene' => BillScene::ADMIN['value'],
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance + ' . $money);
|
||||
$wallet->balance_sum = Db::raw('balance_sum + ' . $money);
|
||||
$wallet->save();
|
||||
}
|
||||
protected function sceneExternal()
|
||||
{
|
||||
return $this->visible(['id', 'create_time', 'num', 'before', 'after', 'remarks', 'action', 'scene', 'action_text', 'scene_text']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\expose\helper\Config;
|
||||
use app\expose\utils\Str;
|
||||
use app\model\Basic;
|
||||
use loong\oauth\utils\Str as UtilsStr;
|
||||
use plugin\finance\expose\helper\Account;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
|
||||
class PluginUserInvitationCode extends Basic
|
||||
{
|
||||
// 关联创建者用户
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(PluginUser::class, 'id', 'uid');
|
||||
}
|
||||
|
||||
// 关联使用邀请码的用户
|
||||
public function useUser()
|
||||
{
|
||||
return $this->hasOne(PluginUser::class, 'id', 'use_uid');
|
||||
}
|
||||
|
||||
public static function addCode($uid, $num = 1, $channels_uid = 0)
|
||||
{
|
||||
$needNum = $num;
|
||||
$finalCodes = [];
|
||||
while ($needNum > 0) {
|
||||
$codes = [];
|
||||
for ($i = 0; $i < $needNum * 2; $i++) {
|
||||
$code = UtilsStr::random(6);
|
||||
//转大写
|
||||
$codes[] = strtoupper($code);
|
||||
}
|
||||
$codes = array_unique($codes);
|
||||
$exists = self::whereIn('code', $codes)
|
||||
->column('code');
|
||||
$available = array_values(array_diff($codes, $exists));
|
||||
$take = array_slice($available, 0, $needNum);
|
||||
$finalCodes = array_merge($finalCodes, $take);
|
||||
$needNum -= count($take);
|
||||
}
|
||||
$insertData = [];
|
||||
foreach ($finalCodes as $code) {
|
||||
$insertData[] = [
|
||||
'uid' => $uid,
|
||||
'code' => $code,
|
||||
'channels_uid' => $channels_uid,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
self::insertAll($insertData);
|
||||
return $finalCodes;
|
||||
}
|
||||
|
||||
|
||||
public function onAfterUpdate($model)
|
||||
{
|
||||
if ($model->status == 'used') {
|
||||
$register = new Config('register', 'user', $model->channels_uid);
|
||||
if ($register->invite_reward_points) {
|
||||
Account::incPoints($model->uid, $model->channels_uid, $register->invite_reward_points, PointsBillScene::INVITE['value'], 0, '邀请奖励积分');
|
||||
}
|
||||
PluginUserInvitationCode::where('id', $model->id)->update(['points' => $register->invite_reward_points]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginUserPoints extends Basic
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
|
||||
class PluginUserPointsBill extends Basic
|
||||
{
|
||||
public function channels()
|
||||
{
|
||||
return $this->hasOne(PluginChannelsUser::class, 'id', 'channels_uid');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginUserTwofaSecret extends Basic
|
||||
{
|
||||
protected function sceneExternal()
|
||||
{
|
||||
return $this->visible(['id','totp_app','is_default','create_time','totp_app_text']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginUserVip extends Basic
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginUserWechat extends Basic
|
||||
{
|
||||
public static function onBeforeWrite($model)
|
||||
{
|
||||
if(!empty($model->nickname)){
|
||||
$model->nickname= iconv('UTF-8', 'UTF-8//IGNORE', $model->nickname);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
use support\Request;
|
||||
|
||||
return [
|
||||
'debug' => true,
|
||||
'controller_suffix' => 'Controller',
|
||||
'controller_reuse' => false
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'files' => [
|
||||
base_path() . '/plugin/user/app/functions.php',
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return new Webman\Container;
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use app\expose\enum\EventName;
|
||||
|
||||
return [
|
||||
EventName::WECHAT_OFFICIAL_ACCOUNT_SUBSCRLBE['value'] => [
|
||||
[\plugin\user\event\WECHAT_OFFICIAL_ACCOUNT::class, 'subscribe']
|
||||
],
|
||||
EventName::WECHAT_OFFICIAL_ACCOUNT_UNSUBSCRLBE['value'] => [
|
||||
[\plugin\user\event\WECHAT_OFFICIAL_ACCOUNT::class, 'unsubscribe']
|
||||
],
|
||||
EventName::USER_REGISTER['value'] => [
|
||||
[\plugin\user\event\User::class, 'code'],
|
||||
[\plugin\user\event\User::class, 'points'],
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'' => app\exception\Handler::class,
|
||||
];
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'handlers' => [
|
||||
[
|
||||
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/user.log',
|
||||
7,
|
||||
\Monolog\Level::Debug,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [null, 'Y-m-d H:i:s', true],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'' => [
|
||||
app\expose\middleware\Platform::class
|
||||
],
|
||||
'admin' => [
|
||||
app\expose\middleware\AdminAuth::class
|
||||
],
|
||||
'control' => [
|
||||
plugin\control\expose\middleware\ControlAuth::class
|
||||
],
|
||||
'api' => [
|
||||
plugin\control\expose\middleware\DomainMapping::class,
|
||||
plugin\user\expose\middleware\UserAuth::class,
|
||||
plugin\user\expose\middleware\Twofa::class,
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return [];
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
|
||||
$Component = new ComponentBuilder;
|
||||
return [
|
||||
[
|
||||
'title' => '变更站点付费比例',
|
||||
'field' => 'site_change_fee_ratio',
|
||||
'value' => 50,
|
||||
'component' => 'input-number',
|
||||
#配置项额外属性
|
||||
'extra' => [
|
||||
#是否必填
|
||||
'required' => true,
|
||||
#提示
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '当用户变更站点授权域名和IP时,编辑次数不足,需要支付的站点费用比例,范围0-100,默认50'], ['type' => 'info', 'size' => 'small'])
|
||||
->builder()
|
||||
],
|
||||
'props' => [
|
||||
'min' => 0,
|
||||
'max' => 100,
|
||||
'step' => 1,
|
||||
'precision' => 0,
|
||||
'controls' => false
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
|
||||
$Component = new ComponentBuilder;
|
||||
return [
|
||||
[
|
||||
'title' => '注册邀请码数量',
|
||||
'field' => 'register_invitation_code_num',
|
||||
'value' => 4,
|
||||
'component' => 'input-number',
|
||||
'extra' => [
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
'precision' => 0,
|
||||
'controls' => false
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => '注册赠送积分',
|
||||
'field' => 'register_give_points',
|
||||
'value' => 100,
|
||||
'component' => 'input-number',
|
||||
'extra' => [
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
'precision' => 0,
|
||||
'controls' => false
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => '邀请奖励积分',
|
||||
'field' => 'invite_reward_points',
|
||||
'value' => 100,
|
||||
'component' => 'input-number',
|
||||
'extra' => [
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
'precision' => 0,
|
||||
'controls' => false
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Multilingual configuration
|
||||
*/
|
||||
return [
|
||||
// Default language
|
||||
'locale' => 'zh_CN',
|
||||
// Fallback language
|
||||
'fallback_locale' => ['zh_CN', 'en'],
|
||||
// Folder where language files are stored
|
||||
'path' => base_path() . '/plugin/user/resource/translations',
|
||||
];
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
use support\view\Raw;
|
||||
use support\view\Twig;
|
||||
use support\view\Blade;
|
||||
// use support\view\ThinkPHP;
|
||||
use support\ThinkPHP;
|
||||
|
||||
return [
|
||||
'handler' => ThinkPHP::class,
|
||||
];
|
||||
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"title": "User",
|
||||
"icon": "User",
|
||||
"path": "/app/user/control",
|
||||
"sort": 1,
|
||||
"children": [
|
||||
{
|
||||
"title": "User List",
|
||||
"icon": "User",
|
||||
"path": "/app/user/control/User/index",
|
||||
"component": "table",
|
||||
"children": [
|
||||
{
|
||||
"title": "Create User",
|
||||
"path": "/app/user/control/User/create",
|
||||
"show": false,
|
||||
"component": "form"
|
||||
},
|
||||
{
|
||||
"title": "Edit User",
|
||||
"show": false,
|
||||
"path": "/app/user/control/User/update",
|
||||
"component": "form"
|
||||
},
|
||||
{
|
||||
"title": "Update Status",
|
||||
"show": false,
|
||||
"path": "/app/user/control/User/indexUpdateState",
|
||||
"component": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "用户钱包",
|
||||
"icon": "ShoppingCart",
|
||||
"path": "/app/finance/control/Wallet/index",
|
||||
"component": "table",
|
||||
"children": [
|
||||
{
|
||||
"title": "余额充值",
|
||||
"path": "/app/finance/control/Wallet/recharge",
|
||||
"component": "form",
|
||||
"show": false
|
||||
},
|
||||
{
|
||||
"title": "积分充值",
|
||||
"path": "/app/finance/control/Wallet/rechargePoints",
|
||||
"component": "form",
|
||||
"show": false
|
||||
},
|
||||
{
|
||||
"title": "临时积分充值",
|
||||
"path": "/app/finance/control/Wallet/rechargeTmpPoints",
|
||||
"component": "form",
|
||||
"show": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "余额账单",
|
||||
"icon": "User",
|
||||
"path": "/app/user/control/Balance/index",
|
||||
"component": "table"
|
||||
},
|
||||
{
|
||||
"title": "积分账单",
|
||||
"icon": "User",
|
||||
"path": "/app/user/control/Points/index",
|
||||
"component": "table"
|
||||
},
|
||||
{
|
||||
"title": "注册设置",
|
||||
"icon": "Setting",
|
||||
"path": "/app/user/control/System/register",
|
||||
"component": "form"
|
||||
},
|
||||
{
|
||||
"title": "邀请码",
|
||||
"icon": "User",
|
||||
"path": "/app/user/control/InvitationCode/index",
|
||||
"component": "table",
|
||||
"children": [
|
||||
{
|
||||
"title": "创建邀请码",
|
||||
"path": "/app/user/control/InvitationCode/create",
|
||||
"component": "form",
|
||||
"show": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\event;
|
||||
|
||||
use app\expose\helper\Config;
|
||||
use plugin\user\app\model\PluginUserInvitationCode;
|
||||
|
||||
class InvitationCode
|
||||
{
|
||||
public function handle($event)
|
||||
{
|
||||
$uid = $event->id;
|
||||
$register = new Config('register', 'user', $event->channels_uid);
|
||||
if ($register->register_invitation_code_num) {
|
||||
PluginUserInvitationCode::addCode($uid, $register->register_invitation_code_num,$event->channels_uid );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\event;
|
||||
|
||||
use app\expose\helper\Config;
|
||||
use plugin\finance\expose\helper\Account;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
use plugin\user\app\model\PluginUserInvitationCode;
|
||||
|
||||
class User
|
||||
{
|
||||
public function code($event)
|
||||
{
|
||||
$uid = $event->id;
|
||||
$register = new Config('register', 'user', $event->channels_uid);
|
||||
if ($register->register_invitation_code_num) {
|
||||
PluginUserInvitationCode::addCode($uid, $register->register_invitation_code_num, $event->channels_uid);
|
||||
}
|
||||
}
|
||||
public function points($event)
|
||||
{
|
||||
$uid = $event->id;
|
||||
$register = new Config('register', 'user', $event->channels_uid);
|
||||
if ($register->register_give_points) {
|
||||
Account::incPoints($uid, $event->channels_uid, $register->register_give_points, PointsBillScene::REGISTER['value'], 0, '注册赠送积分');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\event;
|
||||
|
||||
use app\expose\enum\State;
|
||||
use plugin\user\app\model\PluginUserWechat;
|
||||
|
||||
class WECHAT_OFFICIAL_ACCOUNT
|
||||
{
|
||||
public function subscribe(mixed $data)
|
||||
{
|
||||
$UserWechat = PluginUserWechat::where('openid', $data['FromUserName'])->find();
|
||||
if ($UserWechat) {
|
||||
$UserWechat->subscribe = State::YES['value'];
|
||||
$UserWechat->save();
|
||||
} else {
|
||||
$UserWechat = new PluginUserWechat();
|
||||
$UserWechat->channels_uid = $data['channels_uid'];
|
||||
$UserWechat->openid = $data['FromUserName'];
|
||||
$UserWechat->subscribe = State::YES['value'];
|
||||
$UserWechat->save();
|
||||
}
|
||||
}
|
||||
public function unsubscribe(mixed $data)
|
||||
{
|
||||
$UserWechat = PluginUserWechat::where('openid', $data['FromUserName'])->find();
|
||||
if ($UserWechat) {
|
||||
$UserWechat->subscribe = State::NO['value'];
|
||||
$UserWechat->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\expose\helper;
|
||||
|
||||
use app\expose\enum\EventName;
|
||||
use app\expose\utils\Rsa;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use Webman\Event\Event;
|
||||
|
||||
/**
|
||||
* 用户助手类
|
||||
*
|
||||
* Class User
|
||||
* @package app\helper
|
||||
*
|
||||
* @method static PluginUser create(array $data)
|
||||
* @method static PluginUser register(array $data)
|
||||
* @method static PluginUser login(array $data)
|
||||
* @method static PluginUser update(int $uid, array $data)
|
||||
* @method static PluginUser info(int $uid)
|
||||
* @method static string getIcode(int $uid)
|
||||
* @method static int getUidByIcode(string $icode)
|
||||
*
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* 创建用户
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $data['username'] 用户名(唯一性),可登录
|
||||
* @param string $data['mobile'] 手机号(唯一性),可登录
|
||||
* @param string $data['email'] 邮箱
|
||||
* @param string $data['password'] 密码
|
||||
* @param string $data['activation_time'] 激活时间
|
||||
*
|
||||
* @return PluginUser
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$insterData = [];
|
||||
if (empty($data['channels_uid'])) {
|
||||
throw new \Exception('渠道用户ID不能为空');
|
||||
}
|
||||
$insterData['channels_uid'] = $data['channels_uid'];
|
||||
if (!empty($data['icode'])) {
|
||||
$insterData['puid'] = self::getUidByIcode($data['icode']);
|
||||
}
|
||||
if (empty($data['username']) && empty($data['mobile'])) {
|
||||
throw new \Exception('用户名、手机号至少填写一项');
|
||||
}
|
||||
if (!empty($data['username'])) {
|
||||
$Find = PluginUser::where(['username' => $data['username']])->find();
|
||||
if ($Find) {
|
||||
return $Find;
|
||||
}
|
||||
$insterData['username'] = $data['username'];
|
||||
}
|
||||
if (!empty($data['mobile'])) {
|
||||
$Find = PluginUser::where(['mobile' => $data['mobile']])->find();
|
||||
if ($Find) {
|
||||
return $Find;
|
||||
}
|
||||
$insterData['mobile'] = $data['mobile'];
|
||||
}
|
||||
if (!empty($data['email'])) {
|
||||
$insterData['email'] = $data['email'];
|
||||
}
|
||||
if (!empty($data['password'])) {
|
||||
$insterData['password'] = $data['password'];
|
||||
}
|
||||
if (!empty($data['activation_time'])) {
|
||||
$insterData['activation_time'] = $data['activation_time'];
|
||||
}
|
||||
if (!empty($data['nickname'])) {
|
||||
$insterData['nickname'] = $data['nickname'];
|
||||
}
|
||||
if (!empty($data['headimg'])) {
|
||||
$insterData['headimg'] = $data['headimg'];
|
||||
}
|
||||
$model = new PluginUser();
|
||||
$model->save($insterData);
|
||||
// Event::emit(EventName::USER_REGISTER['value'], $model);
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* 注册
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $data['icode'] 邀请码
|
||||
* @param string $data['username'] 用户名(唯一性),可登录
|
||||
* @param string $data['mobile'] 手机号(唯一性),可登录
|
||||
* @param string $data['email'] 邮箱
|
||||
* @param string $data['password'] 密码
|
||||
*
|
||||
* @return PluginUser
|
||||
*/
|
||||
public static function register($data)
|
||||
{
|
||||
$request = request();
|
||||
if ($request->icode) {
|
||||
$data['icode'] = $request->icode;
|
||||
}
|
||||
return self::create($data);
|
||||
}
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param array $data 更新数据
|
||||
* @param string $data['username'] 用户名
|
||||
* @param string $data['mobile'] 手机号
|
||||
* @param string $data['email'] 邮箱
|
||||
* @return PluginUser
|
||||
*/
|
||||
public static function update($uid, $data)
|
||||
{
|
||||
$user = PluginUser::where(['id' => $uid, 'channels_uid' => $data['channels_uid']])->find();
|
||||
if (!$user) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
if (!empty($data['password'])) {
|
||||
$user->password = $data['password'];
|
||||
}
|
||||
if (!empty($data['username'])) {
|
||||
$Find = PluginUser::where(['username' => $data['username']])->find();
|
||||
if ($Find && $Find->id != $uid) {
|
||||
throw new \Exception('用户名已存在');
|
||||
}
|
||||
$user->username = $data['username'];
|
||||
$user->username_time = date('Y-m-d H:i:s');
|
||||
}
|
||||
if (!empty($data['mobile'])) {
|
||||
$Find = PluginUser::where(['mobile' => $data['mobile']])->find();
|
||||
if ($Find && $Find->id != $uid) {
|
||||
throw new \Exception('手机号已存在');
|
||||
}
|
||||
$user->mobile = $data['mobile'];
|
||||
}
|
||||
if (!empty($data['email'])) {
|
||||
$user->email = $data['email'];
|
||||
}
|
||||
if (!empty($data['nickname'])) {
|
||||
$user->nickname = $data['nickname'];
|
||||
}
|
||||
if (!empty($data['headimg'])) {
|
||||
$user->headimg = $data['headimg'];
|
||||
}
|
||||
$user->save();
|
||||
Event::emit(EventName::USER_UPDATE['value'], $user);
|
||||
return $user;
|
||||
}
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @return PluginUser
|
||||
*/
|
||||
public static function info($uid)
|
||||
{
|
||||
$Find = PluginUser::where(['id' => $uid])->find();
|
||||
if (!$Find) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
return $Find;
|
||||
}
|
||||
/**
|
||||
* 获取邀请码
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @return string
|
||||
*/
|
||||
public static function getIcode($uid)
|
||||
{
|
||||
$user = PluginUser::where(['id' => $uid])->find();
|
||||
return Rsa::encryptNumber($user->id);
|
||||
}
|
||||
/**
|
||||
* 邀请码换取用户ID
|
||||
*
|
||||
* @param string $icode 邀请码
|
||||
* @return int
|
||||
*/
|
||||
public static function getUidByIcode($icode)
|
||||
{
|
||||
return Rsa::decryptNumber($icode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\expose\helper;
|
||||
|
||||
use app\expose\enum\State;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\app\model\PluginUserInvitationCode;
|
||||
use plugin\user\app\model\PluginUserWechat;
|
||||
use support\Redis;
|
||||
|
||||
class WechatOfficialAccount
|
||||
{
|
||||
public $FromUserName;
|
||||
public $ToUserName;
|
||||
public $MsgType;
|
||||
public $Event;
|
||||
public $EventKey;
|
||||
public $data;
|
||||
public function bind($params)
|
||||
{
|
||||
$PluginUserWechat = PluginUserWechat::where('openid', $this->FromUserName)->find();
|
||||
if ($PluginUserWechat) {
|
||||
if ($PluginUserWechat->uid && $PluginUserWechat->uid != $params['uid']) {
|
||||
Redis::set($this->EventKey . '.bind', json_encode([
|
||||
'status' => 'fail',
|
||||
'message' => '当前微信已绑定其他账号'
|
||||
]), 'EX', 60);
|
||||
throw new \Exception('当前微信已绑定其他账号');
|
||||
}
|
||||
} else {
|
||||
$PluginUserWechat = new PluginUserWechat();
|
||||
$PluginUserWechat->openid = $this->FromUserName;
|
||||
}
|
||||
$PluginUserWechat->uid = $params['uid'];
|
||||
$PluginUserWechat->subscribe = State::YES['value'];
|
||||
$PluginUserWechat->channels_uid = $params['channels_uid'];
|
||||
$PluginUserWechat->save();
|
||||
Redis::set($this->EventKey . '.bind', json_encode([
|
||||
'status' => 'success',
|
||||
'uid' => $params['uid']
|
||||
]), 'EX', 60);
|
||||
return '绑定成功';
|
||||
}
|
||||
public function login($params)
|
||||
{
|
||||
try {
|
||||
$PluginUserInvitationCode = null;
|
||||
if (!empty($params['code'])) {
|
||||
$PluginUserInvitationCode = PluginUserInvitationCode::where(['code' => $params['code']])->find();
|
||||
if (!$PluginUserInvitationCode) {
|
||||
$PluginUserInvitationCode = null;
|
||||
}
|
||||
if ($PluginUserInvitationCode->status != 'unused') {
|
||||
$PluginUserInvitationCode = null;
|
||||
}
|
||||
if ($PluginUserInvitationCode->state != State::YES['value']) {
|
||||
$PluginUserInvitationCode = null;
|
||||
}
|
||||
}
|
||||
|
||||
$PluginUserWechat = PluginUserWechat::where('openid', $this->FromUserName)->find();
|
||||
if ($PluginUserWechat) {
|
||||
if ($PluginUserWechat->uid) {
|
||||
Redis::set($this->EventKey . '.login', json_encode([
|
||||
'status' => 'success',
|
||||
'uid' => $PluginUserWechat->uid,
|
||||
]), 'EX', 60);
|
||||
return '登录成功';
|
||||
}
|
||||
} else {
|
||||
$PluginUserWechat = new PluginUserWechat();
|
||||
$PluginUserWechat->openid = $this->FromUserName;
|
||||
$PluginUserWechat->subscribe = State::YES['value'];
|
||||
$PluginUserWechat->channels_uid = $params['channels_uid'];
|
||||
}
|
||||
$data = [
|
||||
'channels_uid' => $params['channels_uid'],
|
||||
'username' => $this->FromUserName,
|
||||
'state' => State::YES['value'],
|
||||
];
|
||||
|
||||
if ($PluginUserInvitationCode != null) {
|
||||
$data['puid'] = $PluginUserInvitationCode->uid;
|
||||
$data['activation_time'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
$UserModel = new PluginUser();
|
||||
$UserModel->save($data);
|
||||
|
||||
if ($PluginUserInvitationCode != null) {
|
||||
$PluginUserInvitationCode->status = 'used';
|
||||
$PluginUserInvitationCode->use_uid = $UserModel->id;
|
||||
$PluginUserInvitationCode->use_time = date('Y-m-d H:i:s');
|
||||
$PluginUserInvitationCode->save();
|
||||
}
|
||||
$PluginUserWechat->uid = $UserModel->id;
|
||||
$PluginUserWechat->save();
|
||||
Redis::set($this->EventKey . '.login', json_encode([
|
||||
'status' => 'success',
|
||||
'id' => $PluginUserWechat->id,
|
||||
'uid' => $UserModel->id
|
||||
]), 'EX', 60);
|
||||
return '登录成功';
|
||||
} catch (\Throwable $th) {
|
||||
Redis::set($this->EventKey . '.login', json_encode([
|
||||
'status' => 'fail',
|
||||
'message' => $th->getMessage()
|
||||
]), 'EX', 60);
|
||||
return $th->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\expose\middleware;
|
||||
|
||||
use app\expose\enum\ResponseCode;
|
||||
use app\expose\trait\Json;
|
||||
use Webman\MiddlewareInterface;
|
||||
use Webman\Http\Response;
|
||||
use Webman\Http\Request;
|
||||
use app\expose\exception\Exception;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
* 前台应用必须引用此中间件,否者无法验证用户两步验证
|
||||
*/
|
||||
class Twofa implements MiddlewareInterface
|
||||
{
|
||||
use Json;
|
||||
public function process(Request $request, callable $next): Response
|
||||
{
|
||||
if ($request->method() == 'OPTIONS') {
|
||||
return response('', 204);
|
||||
}
|
||||
// 鉴权检测
|
||||
try {
|
||||
$this->Authorization($request);
|
||||
$response = $next($request);
|
||||
} catch (\Throwable $th) {
|
||||
if ($request->expectsJson()) {
|
||||
$response = $this->exception($th);
|
||||
} else {
|
||||
if (config('app.debug')) {
|
||||
Log::error($th->getTraceAsString());
|
||||
throw $th;
|
||||
} else {
|
||||
$response = response($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
public function Authorization(Request $request)
|
||||
{
|
||||
# 无控制器地址
|
||||
if (!$request->controller) {
|
||||
return true;
|
||||
}
|
||||
# 获取控制器鉴权信息
|
||||
$controller = new \ReflectionClass($request->controller);
|
||||
$properties = $controller->getDefaultProperties();
|
||||
$notNeedLogin = $properties['notNeedLogin'] ?? [];
|
||||
$notNeedTwofa = array_merge($notNeedLogin, $properties['notNeedTwofa'] ?? []);
|
||||
$notNeedTwofaAll = $properties['notNeedTwofaAll'] ?? false;
|
||||
if ($notNeedTwofaAll) {
|
||||
$notNeedTwofa = array_merge($notNeedTwofa, [$request->action]);
|
||||
}
|
||||
# 是否强制登录
|
||||
if (in_array($request->action, $notNeedTwofa)) {
|
||||
return true;
|
||||
}
|
||||
if ($request->source === 'saas') {
|
||||
return true;
|
||||
}
|
||||
if (!$request->user) {
|
||||
return true;
|
||||
}
|
||||
if (empty($request->user['twofa_state'])) {
|
||||
return true;
|
||||
}
|
||||
if (empty($request->user['twofa']['expire'])) {
|
||||
throw new Exception('需要两步验证', ResponseCode::NEED_TWOFA,['action'=>'logout']);
|
||||
}
|
||||
if (time() > $request->user['twofa']['expire']) {
|
||||
throw new Exception('需要两步验证', ResponseCode::NEED_TWOFA,['action'=>'logout']);
|
||||
}
|
||||
$request->twofa_state = true;
|
||||
$request->twofa = $request->user['twofa'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\expose\middleware;
|
||||
|
||||
use app\expose\enum\ResponseCode;
|
||||
use app\expose\enum\State;
|
||||
use app\expose\trait\Json;
|
||||
use Exception;
|
||||
use loong\oauth\exception\LockException;
|
||||
use loong\oauth\exception\TokenExpireException;
|
||||
use Webman\MiddlewareInterface;
|
||||
use Webman\Http\Response;
|
||||
use Webman\Http\Request;
|
||||
use loong\oauth\facade\Auth;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
* 前台应用必须引用此中间件,否者无法获取用户信息
|
||||
*/
|
||||
class UserAuth implements MiddlewareInterface
|
||||
{
|
||||
use Json;
|
||||
public function process(Request $request, callable $next): Response
|
||||
{
|
||||
if ($request->method() == 'OPTIONS') {
|
||||
return response('', 204);
|
||||
}
|
||||
// 鉴权检测
|
||||
try {
|
||||
$this->Authorization($request);
|
||||
$response = $next($request);
|
||||
} catch (\Throwable $th) {
|
||||
if ($request->expectsJson()) {
|
||||
$response = $this->exception($th);
|
||||
} else {
|
||||
if (config('app.debug')) {
|
||||
Log::error($th->getTraceAsString());
|
||||
throw $th;
|
||||
} else {
|
||||
$response = response($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务逻辑
|
||||
* @author 贵州猿创科技有限公司
|
||||
* @Email unknown.renlong@gmail.com
|
||||
* @DateTime 2023-03-11
|
||||
*/
|
||||
public function Authorization(Request $request)
|
||||
{
|
||||
# 无控制器地址
|
||||
if (!$request->controller) {
|
||||
return true;
|
||||
}
|
||||
# 获取控制器鉴权信息
|
||||
$controller = new \ReflectionClass($request->controller);
|
||||
$properties = $controller->getDefaultProperties();
|
||||
# 无需登录方法
|
||||
$notNeedLogin = $properties['notNeedLogin'] ?? [];
|
||||
# 是否整个控制器都不需要登录
|
||||
$notNeedLoginAll = $properties['notNeedLoginAll'] ?? false;
|
||||
if ($notNeedLoginAll) {
|
||||
$notNeedLogin = array_merge($notNeedLogin, [$request->action]);
|
||||
}
|
||||
# 是否强制登录
|
||||
$isForceLogin = true;
|
||||
if (in_array($request->action, $notNeedLogin)) {
|
||||
$isForceLogin = false;
|
||||
}
|
||||
try {
|
||||
# 令牌验证
|
||||
$token = $request->header('authorization');
|
||||
if (!$token) {
|
||||
throw new Exception('请先登录', ResponseCode::NEED_LOGIN);
|
||||
}
|
||||
$user = Auth::setPrefix('CONTROL')->decrypt($token);
|
||||
if (!$user) {
|
||||
throw new TokenExpireException();
|
||||
}
|
||||
$request->token = $token;
|
||||
$request->user = $user;
|
||||
$request->channels_uid = $user['channels_uid'];
|
||||
$request->uid = $user['uid'];
|
||||
} catch (TokenExpireException $e) {
|
||||
if ($isForceLogin) {
|
||||
throw new Exception('登录已过期,请重新登录', ResponseCode::NEED_LOGIN);
|
||||
}
|
||||
} catch (LockException $e) {
|
||||
if ($isForceLogin) {
|
||||
throw new Exception($e->getMessage(), ResponseCode::LOCK);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
if ($isForceLogin) {
|
||||
throw new \Exception($th->getMessage(), ResponseCode::NEED_LOGIN);
|
||||
}
|
||||
}
|
||||
if ($request->uid) {
|
||||
$User = PluginUser::where('id', $request->uid)->find();
|
||||
if ($User->state != State::YES['value']) {
|
||||
throw new Exception("您的账号已被禁用", ResponseCode::NEED_LOGIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "interface-example",
|
||||
"title": "应用示例项目",
|
||||
"version": "0.0.1",
|
||||
"description": "应用市场",
|
||||
"author": {
|
||||
"name": "余心",
|
||||
"email": "unknown.renloong@gmail.com"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'User' => 'User',
|
||||
'User List' => 'User List',
|
||||
'Create User' => 'Create User',
|
||||
'Edit User' => 'Edit User',
|
||||
'form_basic_title'=>'Basic',
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'success' => 'Success',
|
||||
'fail' => 'Fail',
|
||||
];
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'User' => 'User',
|
||||
'User List' => 'User List',
|
||||
'Create User' => 'Create User',
|
||||
'Edit User' => 'Edit User',
|
||||
'form_basic_title'=>'Basic',
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'success' => 'Success',
|
||||
];
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'User' => '用户',
|
||||
'User List' => '用户列表',
|
||||
'Create User' => '创建用户',
|
||||
'Edit User' => '编辑用户',
|
||||
'form_basic_title'=>'基础信息',
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'success' => '成功',
|
||||
'fail' => '失败',
|
||||
];
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'User' => '用户',
|
||||
'User List' => '用户列表',
|
||||
'Create User' => '创建用户',
|
||||
'Edit User' => '编辑用户',
|
||||
'form_basic_title'=>'基础信息',
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'success' => '成功',
|
||||
];
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class CertificateType extends Enum
|
||||
{
|
||||
const ID_CARD = [
|
||||
'label' => '身份证',
|
||||
'value' => 'idcard',
|
||||
];
|
||||
const PASSPORT = [
|
||||
'label' => '护照',
|
||||
'value' => 'passport',
|
||||
];
|
||||
const HK_MC_PASSPORT = [
|
||||
'label' => '港澳通行证',
|
||||
'value' => 'hk_mc_passport',
|
||||
];
|
||||
const TW_PASSPORT = [
|
||||
'label' => '台湾通行证',
|
||||
'value' => 'tw_passport',
|
||||
];
|
||||
const TW_RETURN_PASSPORT = [
|
||||
'label' => '台胞证',
|
||||
'value' => 'tw_return_passport',
|
||||
];
|
||||
const HK_MC_RETURN_PASSPORT = [
|
||||
'label' => '返乡证',
|
||||
'value' => 'hk_mc_return_passport',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class MoneyAction extends Enum
|
||||
{
|
||||
const INCREASE = [
|
||||
'label' => '增加',
|
||||
'value' => 'increase',
|
||||
'props'=>[
|
||||
'type'=>'danger'
|
||||
]
|
||||
];
|
||||
const DECREASE = [
|
||||
'label' => '减少',
|
||||
'value' => 'decrease',
|
||||
'props'=>[
|
||||
'type'=>'success'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class PropsType extends Enum
|
||||
{
|
||||
const NORMAL = [
|
||||
'label' => '无',
|
||||
'value' => 'normal',
|
||||
'props'=>[
|
||||
'type'=>'default'
|
||||
]
|
||||
];
|
||||
const PRIMARY = [
|
||||
'label' => '主要',
|
||||
'value' => 'primary',
|
||||
'props'=>[
|
||||
'type'=>'primary'
|
||||
]
|
||||
];
|
||||
const SUCCESS = [
|
||||
'label' => '成功',
|
||||
'value' => 'success',
|
||||
'props'=>[
|
||||
'type'=>'success'
|
||||
]
|
||||
];
|
||||
const INFO = [
|
||||
'label' => '信息',
|
||||
'value' => 'info',
|
||||
'props'=>[
|
||||
'type'=>'info'
|
||||
]
|
||||
];
|
||||
const WARNING = [
|
||||
'label' => '警告',
|
||||
'value' => 'warning',
|
||||
'props'=>[
|
||||
'type'=>'warning'
|
||||
]
|
||||
];
|
||||
const DANGER = [
|
||||
'label' => '危险',
|
||||
'value' => 'danger',
|
||||
'props'=>[
|
||||
'type'=>'danger'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class TotpApp extends Enum
|
||||
{
|
||||
const ONE_PASSWORD = [
|
||||
'label' => '1Password',
|
||||
'value' => '1password'
|
||||
];
|
||||
const GOOGLE = [
|
||||
'label' => 'Google Authenticator',
|
||||
'value' => 'google'
|
||||
];
|
||||
const MICROSOFT = [
|
||||
'label' => 'Microsoft Authenticator',
|
||||
'value' => 'microsoft'
|
||||
];
|
||||
const AUTHY = [
|
||||
'label' => 'Authy',
|
||||
'value' => 'authy'
|
||||
];
|
||||
const DUO = [
|
||||
'label' => 'Duo Mobile',
|
||||
'value' => 'duo'
|
||||
];
|
||||
const LASTPASS = [
|
||||
'label' => 'LastPass Authenticator',
|
||||
'value' => 'lastpass'
|
||||
];
|
||||
const BITWARDEN = [
|
||||
'label' => 'Bitwarden Authenticator',
|
||||
'value' => 'bitwarden'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class UserPermission extends Enum
|
||||
{
|
||||
const MOBILE = [
|
||||
'label' => '已绑定手机号',
|
||||
'value' => 'mobile'
|
||||
];
|
||||
const EMAIL = [
|
||||
'label' => '已绑定邮箱',
|
||||
'value' => 'email'
|
||||
];
|
||||
const TWOFA = [
|
||||
'label' => '已开启两步验证',
|
||||
'value' => 'twofa'
|
||||
];
|
||||
const WECHAT = [
|
||||
'label' => '已绑定微信',
|
||||
'value' => 'wechat'
|
||||
];
|
||||
const USERNAME = [
|
||||
'label' => '已设置用户名',
|
||||
'value' => 'username'
|
||||
];
|
||||
const PASSWORD = [
|
||||
'label' => '已设置密码',
|
||||
'value' => 'password'
|
||||
];
|
||||
const REALNAME = [
|
||||
'label' => '已实名认证',
|
||||
'value' => 'realname'
|
||||
];
|
||||
const BUY = [
|
||||
'label' => '可以购买',
|
||||
'value' => 'buy'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class VcodeScene extends Enum
|
||||
{
|
||||
const LOGIN = [
|
||||
'label' => '登录',
|
||||
'value' => 'login',
|
||||
'variable' => ['code' => '验证码', 'expire' => '过期时间']
|
||||
];
|
||||
const SIGNUP = [
|
||||
'label' => '注册',
|
||||
'value' => 'signup',
|
||||
'variable' => ['code' => '验证码', 'expire' => '过期时间']
|
||||
];
|
||||
const BIND_MOBILE = [
|
||||
'label' => '绑定手机号',
|
||||
'value' => 'bind_mobile',
|
||||
'variable' => ['username' => '用户昵称', 'code' => '验证码', 'expire' => '过期时间']
|
||||
];
|
||||
const BIND_EMAIL = [
|
||||
'label' => '绑定邮箱',
|
||||
'value' => 'bind_email',
|
||||
'variable' => ['username' => '用户昵称', 'code' => '验证码', 'expire' => '过期时间']
|
||||
];
|
||||
const SET_PASSWORD = [
|
||||
'label' => '设置密码',
|
||||
'value' => 'set_password',
|
||||
'variable' => ['username' => '用户昵称', 'code' => '验证码', 'expire' => '过期时间','password' => '密码']
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user