95 lines
2.8 KiB
PHP
95 lines
2.8 KiB
PHP
![]() |
<?php
|
|||
|
|
|||
|
|
|||
|
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'));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|