FastMovieAI AI短剧创作平台 二开基线
- 源码: xhadmincn/FastMovieAI (Apache 2.0) - 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION - vendor/示例资源已gitignore
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user