101 lines
3.2 KiB
PHP
101 lines
3.2 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 作者:修缘 联系QQ:278896498 QQ群:1054861244
|
||
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
|
||
// | 另接php业务,网站制作、代理后台、gm后台、支付对接等
|
||
// +----------------------------------------------------------------------
|
||
// | 创建时间: 2022/1/5 22:18
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\admin\model\AgencyUser;
|
||
use think\Request;
|
||
use app\common\model\User;
|
||
use app\common\model\UserLevel;
|
||
|
||
use app\common\validate\UserValidate;
|
||
|
||
/**
|
||
* UserController
|
||
* Author:修缘
|
||
* 联系QQ:278896498
|
||
* Date: 2022/1/4 14:37
|
||
*/
|
||
class UserController extends Controller
|
||
{
|
||
|
||
protected function initialize(): void
|
||
{
|
||
parent::initialize(); // TODO: Change the autogenerated stub
|
||
$this->get_son_agency_account();
|
||
}
|
||
|
||
//列表
|
||
public function index(Request $request, User $model)
|
||
{
|
||
$param = $request->param();
|
||
$son_agency = $this->son_agency . ",{$this->user->username}";
|
||
$model = $model->withJoin([
|
||
'agency' => function($query) use ($son_agency) {
|
||
$query->whereIn('username', $son_agency);
|
||
}
|
||
])->scope('where', $param);
|
||
|
||
$data = $model->paginate($this->admin['per_page'], false, ['query' => $request->get()]);
|
||
// dump($data);
|
||
|
||
//关键词,排序等赋值
|
||
$this->assign($request->get());
|
||
|
||
$this->assign([
|
||
'data' => $data,
|
||
'page' => $data->render(),
|
||
'total' => $data->total(),
|
||
'agency' => AgencyUser::Progeny($this->user)->scope('role')->field('id,username,invite')->all(),
|
||
'user' => $this->user,
|
||
|
||
]);
|
||
return $this->fetch();
|
||
}
|
||
|
||
//删除
|
||
public function del($id, User $model)
|
||
{
|
||
if (count($model->noDeletionId) > 0) {
|
||
if (is_array($id)) {
|
||
if (array_intersect($model->noDeletionId, $id)) {
|
||
return admin_error('ID为' . implode(',', $model->noDeletionId) . '的数据无法删除');
|
||
}
|
||
} else if (in_array($id, $model->noDeletionId)) {
|
||
return admin_error('ID为' . $id . '的数据无法删除');
|
||
}
|
||
}
|
||
|
||
if ($model->softDelete) {
|
||
$result = $model->whereIn('id', $id)->useSoftDelete('delete_time', time())->delete();
|
||
} else {
|
||
$result = $model->whereIn('id', $id)->delete();
|
||
}
|
||
|
||
return $result ? admin_success(lang('delete_success'), URL_RELOAD) : admin_error(lang('delete_error'));
|
||
}
|
||
|
||
|
||
//启用
|
||
public function enable($id, User $model)
|
||
{
|
||
$result = $model->whereIn('accountid', $id)->update(['state' => 0]);
|
||
return $result ? admin_success(lang('status_update_success'), URL_RELOAD) : admin_error(lang('status_update_error'));
|
||
}
|
||
|
||
//禁用
|
||
public function disable($id, User $model)
|
||
{
|
||
$result = $model->whereIn('accountid', $id)->update(['state' => 1]);
|
||
return $result ? admin_success(lang('status_update_success'), URL_RELOAD) : admin_error(lang('status_update_error'));
|
||
}
|
||
|
||
|
||
}
|