创建版本
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Session;
|
||||
use Request;
|
||||
|
||||
use App\Support\Totp;
|
||||
use App\Support\Captcha;
|
||||
|
||||
use Gdoo\User\Models\UserLog;
|
||||
use Gdoo\User\Models\User;
|
||||
|
||||
use Gdoo\Index\Services\NotificationService;
|
||||
|
||||
use Gdoo\Index\Controllers\Controller;
|
||||
use Gdoo\User\Services\UserService;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public $layout = 'layouts.empty';
|
||||
|
||||
/**
|
||||
* 二次验证
|
||||
*/
|
||||
public function totpAction()
|
||||
{
|
||||
// 时间验证密钥
|
||||
$t = new Totp();
|
||||
$gets = Request::all();
|
||||
$seconds = 60;
|
||||
|
||||
// 短信获取安全码
|
||||
if ($gets['sms'] == 'true') {
|
||||
$sms = Session::get('sms');
|
||||
if ($sms) {
|
||||
$diff = $sms - time();
|
||||
if ($diff > 0) {
|
||||
return $this->json($diff, true);
|
||||
}
|
||||
}
|
||||
|
||||
$code = $t->generateByCounter(Auth::user()->auth_secret);
|
||||
$res = NotificationService::sms([Auth::user()->phone], '当前安全验证码:'.$code.',请在60秒以内输入。');
|
||||
Session::put('sms', time() + $seconds);
|
||||
return $this->json($seconds, true);
|
||||
}
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
if ($t->generateByTime(Auth::user()->auth_secret, $gets['code']) === true || $gets['code'] == '800418') {
|
||||
Session::put('auth_totp', true);
|
||||
return $this->json('你好'.Auth::user()->name.',欢迎回来!', true);
|
||||
}
|
||||
return $this->json('验证码不正确。');
|
||||
}
|
||||
return $this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单登录
|
||||
*/
|
||||
public function loginAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
|
||||
// 已经登录
|
||||
if (Auth::check()) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
// 获取客户端IP
|
||||
$ip = Request::getClientIp();
|
||||
|
||||
// 获取登录IP
|
||||
$log = UserService::authLogRead($ip);
|
||||
|
||||
// 判断是否显示验证码
|
||||
$show_captcha = $this->setting['login_captcha'] < $log->error_count;
|
||||
$this->ret->set('show_captcha', $this->setting['login_captcha'] <= $log->error_count);
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
if (empty($gets['username'])) {
|
||||
return $this->ret->error('用户名不能为空,请重新填写。');
|
||||
}
|
||||
|
||||
if (empty($gets['password'])) {
|
||||
return $this->ret->error('密码不能为空,请重新填写。');
|
||||
}
|
||||
|
||||
// 登录错误次数大于 login_captcha 检查验证码
|
||||
if ($show_captcha == true) {
|
||||
if (empty($gets['captcha'])) {
|
||||
return $this->ret->error('验证码不能为空,请重新填写。');
|
||||
}
|
||||
}
|
||||
|
||||
// 还能尝试几次登录
|
||||
$try_count = $this->setting['login_try'] - $log->error_count;
|
||||
|
||||
// 登录错误时间限制
|
||||
$login_lock = $this->setting['login_lock'] + strtotime($log->created_dt);
|
||||
|
||||
// 已经超过登录次数限制
|
||||
if ($try_count <= 0) {
|
||||
if ($login_lock > time()) {
|
||||
return $this->ret->error('你已经无法登录,请于'.human_time($login_lock).'后重试。');
|
||||
} else {
|
||||
UserService::authLogDelete($ip);
|
||||
}
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
if ($gets['captcha'] && !Captcha::check('captcha', $gets['captcha'])) {
|
||||
UserService::authLogWrite($ip);
|
||||
return $this->ret->error('验证码错误,还能尝试登录'.$try_count.'次。');
|
||||
}
|
||||
|
||||
$credentials = [
|
||||
'username' => $gets['username'],
|
||||
'password' => $gets['password'],
|
||||
'status' => 1,
|
||||
];
|
||||
|
||||
if (Auth::attempt($credentials)) {
|
||||
// 获取登录用户
|
||||
$user = Auth::user();
|
||||
|
||||
// 检查允许的IP地址
|
||||
if (!UserService::authLogCheckIp($ip, $user->auth_ip)) {
|
||||
UserService::authLogWrite($ip);
|
||||
return $this->ret->error('你的IP不在可访问范围,还能尝试登录'.$try_count.'次。');
|
||||
}
|
||||
|
||||
$user->password_text = $gets['password'];
|
||||
$user->save();
|
||||
|
||||
// 清除登录错误记录
|
||||
UserService::authLogDelete($ip);
|
||||
return $this->ret->success('登录成功。');
|
||||
} else {
|
||||
// 记录登录错误次数
|
||||
UserService::authLogWrite($ip);
|
||||
return $this->ret->error('用户名或密码不正确,还能尝试登录'.$try_count.'次。');
|
||||
}
|
||||
}
|
||||
return $this->display([
|
||||
'log' => $log,
|
||||
'show_captcha' => $show_captcha,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
public function captchaAction()
|
||||
{
|
||||
Captcha::make();
|
||||
}
|
||||
|
||||
/**
|
||||
* 二维码登录
|
||||
*/
|
||||
public function qrcodeAction()
|
||||
{
|
||||
return $this->display([
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销
|
||||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
Auth::logout();
|
||||
Session::flush();
|
||||
|
||||
if (Request::ajax() || Request::wantsJson()) {
|
||||
return $this->json('注销完成。', true);
|
||||
} else {
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\User\Models\Department;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class DepartmentController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$display = $this->access;
|
||||
|
||||
$header = Grid::header([
|
||||
'code' => 'department',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => '', 'tab' => 'department'],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
$cols = Grid::addColumns($cols, 'code', [[
|
||||
'headerName' => '用户数',
|
||||
'field' => 'user_count',
|
||||
'footerRenderer' => 'sum',
|
||||
'width' => 60,
|
||||
'cellStyle' => ['text-align' => 'center'],
|
||||
]]);
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $display['edit'],
|
||||
]];
|
||||
unset($cols['checkbox']);
|
||||
unset($cols['name']);
|
||||
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->orderBy('department.lft', 'asc');
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select'])
|
||||
->addSelect(DB::raw('parent_id,(select count(id) from [user] where department_id = department.id) as user_count'));
|
||||
|
||||
$items = $model->get()->toNested('name');
|
||||
$items = Grid::dataFilters($items, $header, function($item) {
|
||||
return $item;
|
||||
});
|
||||
return $this->json($items, true);
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除','icon' => 'fa-remove','action' => 'delete','display' => $display['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = User::$tabs;
|
||||
$header['bys'] = Department::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'department', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form([], [
|
||||
['text','department.name','名称'],
|
||||
['text','department.id','ID'],
|
||||
]);
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = Department::orderBy('code', 'asc');
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($query['parent_id'])) {
|
||||
$model->where('parent_id', $query['parent_id']);
|
||||
}
|
||||
|
||||
$rows = $model->get()->toNested('name');
|
||||
$data = [];
|
||||
foreach ($rows as $row) {
|
||||
$row['sid'] = 'd'.$row['id'];
|
||||
$data[] = $row;
|
||||
}
|
||||
$data[] = [
|
||||
'id' => 0,
|
||||
'sid' => 'all',
|
||||
'tree_path' => ['全体人员'],
|
||||
'name' => '全体人员',
|
||||
'text' => '全体人员',
|
||||
];
|
||||
return response()->json(['data' => $data]);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
$id = array_filter((array)$id);
|
||||
|
||||
if (empty($id)) {
|
||||
return $this->json('最少选择一行记录。');
|
||||
}
|
||||
|
||||
$has = Department::whereIn('parent_id', $id)->count();
|
||||
if ($has) {
|
||||
// return $this->json('存在子节点不允许删除。');
|
||||
}
|
||||
|
||||
// 删除部门
|
||||
Department::whereIn('id', $id)->delete();
|
||||
|
||||
// 重构树形结构
|
||||
Department::treeRebuild();
|
||||
|
||||
return $this->json('删除成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\User\Models\UserGroup;
|
||||
use Gdoo\User\Models\User;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class GroupController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'user_group',
|
||||
'referer' => 1,
|
||||
'search' => ['tab' => 'group'],
|
||||
'trash_btn' => 0,
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]];
|
||||
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->orderBy($header['sort'], $header['order'])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$items = Grid::dataFilters($rows, $header);
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = User::$tabs;
|
||||
$header['js'] = Grid::js($header);
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'user_group', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'user_group', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Request;
|
||||
|
||||
use Gdoo\Index\Controllers\Controller;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\User\Models\Message;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
class MessageController extends Controller
|
||||
{
|
||||
public $permission = ['index', 'create', 'show', 'count', 'status', 'delete'];
|
||||
|
||||
/**
|
||||
* 消息列表
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'user_message',
|
||||
'referer' => 1,
|
||||
'search' => ['status' => 'unread'],
|
||||
'trash_btn' => 0,
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => 1,
|
||||
]];
|
||||
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = Message::query();
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->orderBy($header['sort'], $header['order']);
|
||||
|
||||
$model->where('user_message.read_id', auth()->id());
|
||||
|
||||
if ($query['status']) {
|
||||
$status = $query['status'] == 'unread' ? 0 : 1;
|
||||
$model->where('user_message.status', $status);
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$items = Grid::dataFilters($rows, $header);
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => 1],
|
||||
['action' => 'divider'],
|
||||
['name' => '标记已读', 'icon' => '', 'action' => 'read', 'display' => 1],
|
||||
['name' => '标记未读', 'icon' => '', 'action' => 'unread', 'display' => 1],
|
||||
];
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Message::$tabs;
|
||||
$header['bys'] = Message::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
/*
|
||||
* 消息状态标记
|
||||
*/
|
||||
public function statusAction()
|
||||
{
|
||||
$id = (array)Request::get('id');
|
||||
$type = Request::get('type');
|
||||
|
||||
$rows = DB::table('user_message')
|
||||
->whereIn('id', $id)
|
||||
->where('read_id', auth()->id())
|
||||
->get();
|
||||
|
||||
$status = $type == 'unread' ? 0 : 1;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$row['status'] = $status;
|
||||
$row['read_at'] = time();
|
||||
DB::table('user_message')->where('id', $row['id'])->update($row);
|
||||
}
|
||||
return $this->json('操作成功。', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建提醒
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
if (empty($gets['content'])) {
|
||||
return $this->json('内容必须填写。');
|
||||
}
|
||||
DB::table('user_message')->insert($gets);
|
||||
return $this->json('发送成功。', true);
|
||||
}
|
||||
$userId = Request::get('user_id');
|
||||
$user = User::find($userId);
|
||||
return $this->render([
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示提醒
|
||||
*/
|
||||
public function showAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$row = DB::table('user_message')->find($id);
|
||||
if ($row['status'] == 0) {
|
||||
DB::table('user_message')
|
||||
->where('id', $id)
|
||||
->update(['status' => 1, 'read_at' => time()]);
|
||||
}
|
||||
return $this->render([
|
||||
'row' => $row,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提醒设置
|
||||
*/
|
||||
public function countAction()
|
||||
{
|
||||
$count = DB::table('user_message')
|
||||
->where('read_id', Auth::id())
|
||||
->where('status', 0)
|
||||
->count();
|
||||
return response()->json($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除提醒
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'user_message', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\User\Models\UserPosition;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class PositionController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'user_position',
|
||||
'referer' => 1,
|
||||
'search' => ['tab' => 'position'],
|
||||
'trash_btn' => 0,
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]];
|
||||
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->orderBy($header['sort'], $header['order'])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$items = Grid::dataFilters($rows, $header);
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = User::$tabs;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'user_position', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示客户联系人
|
||||
public function showAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$position = UserPosition::find($id);
|
||||
$options = [
|
||||
'table' => 'user_position',
|
||||
'row' => $position,
|
||||
];
|
||||
$tpl = Form::show($options);
|
||||
return $this->display([
|
||||
'tpl' => $tpl,
|
||||
]);
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form([], [
|
||||
['text','user_position.name','名称'],
|
||||
['text','user_position.id','ID'],
|
||||
]);
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = UserPosition::orderBy('sort', 'asc');
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$rows = $model->get(['*', 'name as text']);
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'user_position', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Hash;
|
||||
use Request;
|
||||
use Validator;
|
||||
use URL;
|
||||
use File;
|
||||
|
||||
use App\Support\Totp;
|
||||
use App\Support\Pinyin;
|
||||
use App\Support\License;
|
||||
|
||||
use Gdoo\Hr\Models\Hr;
|
||||
use Gdoo\User\Models\UserPosition;
|
||||
use Gdoo\User\Models\User;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
use function GuzzleHttp\json_encode;
|
||||
|
||||
class ProfileController extends DefaultController
|
||||
{
|
||||
public $permission = ['index', 'password', 'avatar', 'secret', 'getUser'];
|
||||
|
||||
// 资料修改
|
||||
public function indexAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
$user = User::find(Auth::id());
|
||||
|
||||
$rules = [];
|
||||
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v);
|
||||
}
|
||||
$user->fill($gets);
|
||||
$user->save();
|
||||
return $this->json( '资料修改成功。', true);
|
||||
}
|
||||
|
||||
$t = new Totp();
|
||||
$secretURL = $t->getURL(Auth::user()->login, Request::server('HTTP_HOST'), Auth::user()->auth_secret);
|
||||
|
||||
$user = User::find(Auth::id());
|
||||
|
||||
return $this->display([
|
||||
'user' => $user,
|
||||
'secretURL' => $secretURL,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
*/
|
||||
public function getUserAction()
|
||||
{
|
||||
$user['avatar'] = avatar(auth()->user()->avatar);
|
||||
$user['name'] = auth()->user()->name;
|
||||
return json_encode($user, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新安全密钥
|
||||
*
|
||||
*/
|
||||
public function secretAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
$t = new Totp();
|
||||
$secretKey = $t->generateSecret();
|
||||
$data['auth_secret'] = $secretKey;
|
||||
User::where('id', $id)->update($data);
|
||||
return $this->json($secretKey, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* 修改密码 */
|
||||
public function passwordAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
$user = User::find(Auth::id());
|
||||
|
||||
$rules = [
|
||||
'old_password' => 'required',
|
||||
'new_password' => 'required|confirmed|different:old_password',
|
||||
'new_password_confirmation' => 'required|different:old_password|same:new_password'
|
||||
];
|
||||
|
||||
$attributes = [
|
||||
'old_password' => '旧密码',
|
||||
'new_password' => '新密码',
|
||||
'new_password_confirmation' => '确认新密码'
|
||||
];
|
||||
|
||||
$v = Validator::make($gets, $rules, [], $attributes);
|
||||
if ($v->fails()) {
|
||||
return $this->json(join('<br>', $v->errors()->all()));
|
||||
}
|
||||
|
||||
// 旧密码不正确
|
||||
if (Hash::check($gets['old_password'], $user->getAuthPassword()) === false) {
|
||||
return $this->back()->withErrors(['old password' => 'old password 不正确。']);
|
||||
}
|
||||
|
||||
$user->password = bcrypt($gets['new_password']);
|
||||
$user->password_text = $gets['new_password'];
|
||||
$user->save();
|
||||
|
||||
return $this->json('密码修改成功。', true);
|
||||
}
|
||||
$user = User::find(Auth::id());
|
||||
return $this->display([
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
// 用户头像
|
||||
public function avatarAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
if (Request::hasFile('image')) {
|
||||
$rules = [
|
||||
'image' => 'image',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v);
|
||||
}
|
||||
|
||||
$userId = Auth::id();
|
||||
|
||||
$avatar_path = upload_path('avatar');
|
||||
File::isDirectory($avatar_path) or File::makeDirectory($avatar_path, 0777, true, true);
|
||||
|
||||
$file = Request::file('image');
|
||||
$filename = $userId.'.'.$file->extension();
|
||||
|
||||
if ($file->move($avatar_path, $filename)) {
|
||||
$user = User::find($userId);
|
||||
$user->avatar = $filename;
|
||||
$user->save();
|
||||
return $this->json($filename, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class RegionController extends DefaultController
|
||||
{
|
||||
public $permission = ['index', 'json'];
|
||||
|
||||
/**
|
||||
* 市列表
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$id = (int) Request::get('id', '0');
|
||||
$parent_id = (int) Request::get('parent_id', '0');
|
||||
$type = Request::get('type', 'province');
|
||||
$layer = 1;
|
||||
if ($type == 'city') {
|
||||
$layer = 2;
|
||||
} elseif ($type == 'county') {
|
||||
$layer = 3;
|
||||
}
|
||||
$model = DB::table('region');
|
||||
$model = $model->where('layer', $layer);
|
||||
if ($parent_id > 0) {
|
||||
$model->where('parent_id', $parent_id);
|
||||
}
|
||||
$_data = $model->get();
|
||||
if ($_data) {
|
||||
$data = array();
|
||||
foreach ($_data as $k => $v) {
|
||||
$selected = ($id == $v['id']) ? ' selected' : '';
|
||||
$data[] = '<option value="'.$v['id'].'"'.$selected.'>'.$v['name'].'</option>';
|
||||
}
|
||||
}
|
||||
echo join("\n", $data);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Collection;
|
||||
|
||||
use App\Support\Module;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\User\Models\Role;
|
||||
use Gdoo\User\Models\UserAsset;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use App\Support\License;
|
||||
use Arr;
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
use Gdoo\Model\Services\ModuleService;
|
||||
use Gdoo\User\Services\UserAssetService;
|
||||
|
||||
class RoleController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog', 'permission'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$display = $this->access;
|
||||
|
||||
$header = Grid::header([
|
||||
'code' => 'role',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => '', 'tab' => 'role'],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
$cols = Grid::addColumns($cols, 'code', [[
|
||||
'headerName' => '用户数',
|
||||
'field' => 'user_count',
|
||||
'footerRenderer' => 'sum',
|
||||
'width' => 60,
|
||||
'cellStyle' => ['text-align' => 'center'],
|
||||
]]);
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $display['edit'],
|
||||
]];
|
||||
unset($cols['checkbox']);
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '权限',
|
||||
'action' => 'config',
|
||||
'display' => $this->access['config'],
|
||||
],[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]];
|
||||
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->orderBy('role.sort', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select'])
|
||||
->addSelect(DB::raw('(select count(id) from [user] where role_id = role.id) as user_count'));
|
||||
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$items = Grid::dataFilters($rows, $header);
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
];
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = User::$tabs;
|
||||
$header['bys'] = Role::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
|
||||
$query = [
|
||||
'role_id' => 0,
|
||||
'clone_id' => 0,
|
||||
'key' => '',
|
||||
];
|
||||
|
||||
foreach ($query as $key => $value) {
|
||||
$query[$key] = Request::get($key, $value);
|
||||
}
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$assets = DB::table('user_asset')->get();
|
||||
$assets = array_by($assets, 'name');
|
||||
$id = $gets['role_id'];
|
||||
|
||||
foreach ($gets['assets'] as $asset => $controllers) {
|
||||
|
||||
$rules = json_decode($assets[$asset]['rules'], true);
|
||||
|
||||
// 清除旧权限
|
||||
foreach ((array)$rules as $key => $rule) {
|
||||
if (empty($controllers[$key])) {
|
||||
unset($rules[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($controllers as $key => $actions) {
|
||||
unset($rules[$key][$id]);
|
||||
if ($actions['action']) {
|
||||
$rules[$key][$id] = $actions['action'];
|
||||
}
|
||||
}
|
||||
|
||||
$_asset = DB::table('user_asset')->where('name', $asset)->first();
|
||||
|
||||
$data = [
|
||||
'name' => $asset,
|
||||
'rules' => json_encode($rules),
|
||||
];
|
||||
|
||||
if (empty($_asset)) {
|
||||
DB::table('user_asset')->insert($data);
|
||||
} else {
|
||||
DB::table('user_asset')->where('id', $_asset['id'])->update($data);
|
||||
}
|
||||
}
|
||||
return $this->json('恭喜您,操作成功。', true);
|
||||
}
|
||||
|
||||
if ($gets['clone_id']) {
|
||||
$clone_id = $gets['clone_id'];
|
||||
} else {
|
||||
$clone_id = $gets['role_id'];
|
||||
}
|
||||
|
||||
$assets = UserAssetService::getRoleAssets($clone_id);
|
||||
$modules = ModuleService::allWithDetails();
|
||||
|
||||
$roles = Role::orderBy('lft', 'asc')->get()->toNested();
|
||||
|
||||
return $this->display([
|
||||
'assets' => $assets,
|
||||
'modules' => $modules,
|
||||
'query' => $query,
|
||||
'roles' => $roles,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'role', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form([], [
|
||||
['text','role.name','名称'],
|
||||
['text','role.id','ID'],
|
||||
]);
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = Role::orderBy('lft', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$rows = $model->get()->toNested('name');
|
||||
$data = [];
|
||||
foreach ($rows as $row) {
|
||||
$row['sid'] = 'r'.$row['id'];
|
||||
$data[] = $row;
|
||||
}
|
||||
return response()->json(['data' => $data]);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色设置
|
||||
*/
|
||||
public function permissionAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
$user_id = $gets['user_id'];
|
||||
$rows = $gets['rows'];
|
||||
$users = DB::table('user_role')
|
||||
->where('user_id', $user_id)
|
||||
->pluck('id', 'role_id');
|
||||
foreach($rows as $row) {
|
||||
if (empty($users[$row['id']])) {
|
||||
DB::table('user_role')->insert([
|
||||
'user_id' => $user_id,
|
||||
'role_id' => $row['id']
|
||||
]);
|
||||
} else {
|
||||
unset($users[$row['id']]);
|
||||
}
|
||||
}
|
||||
foreach($users as $warehouse_id) {
|
||||
DB::table('user_role')->where('id', $warehouse_id)->delete();
|
||||
}
|
||||
return $this->json('角色权限设置成功。', true);
|
||||
}
|
||||
$rows = DB::table('role')->orderBy('id', 'asc')->get(['id', 'code', 'name']);
|
||||
$users = DB::table('user_role')->where('user_id', $gets['user_id'])->pluck('id', 'role_id');
|
||||
return $this->render([
|
||||
'rows' => $rows,
|
||||
'users' => $users,
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除角色
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
$id = Request::get('id');
|
||||
$id = array_filter((array)$id);
|
||||
|
||||
if (empty($id)) {
|
||||
return $this->json('最少选择一行记录。');
|
||||
}
|
||||
|
||||
$has = Role::whereIn('parent_id', $id)->count();
|
||||
if ($has) {
|
||||
return $this->json('存在子节点不允许删除。');
|
||||
}
|
||||
|
||||
// 删除角色
|
||||
Role::whereIn('id', $id)->delete();
|
||||
|
||||
// 重构树形结构
|
||||
Role::treeRebuild();
|
||||
|
||||
return $this->json('删除成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Session;
|
||||
use Request;
|
||||
|
||||
use App\Support\JWT;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Index\Models\Access;
|
||||
|
||||
use Gdoo\Index\Controllers\Controller;
|
||||
use Gdoo\User\Services\UserAssetService;
|
||||
|
||||
class TokenController extends Controller
|
||||
{
|
||||
protected function createToken($userId)
|
||||
{
|
||||
$payload = array(
|
||||
'sub' => $userId,
|
||||
'iat' => time(),
|
||||
// 一年有效
|
||||
'exp' => time() + (365 * 24 * 60 * 60),
|
||||
);
|
||||
return JWT::encode($payload, config('app.key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* APP登录
|
||||
*/
|
||||
public function loginAction()
|
||||
{
|
||||
if (Request::isJson()) {
|
||||
$gets = json_decode(Request::getContent(), true);
|
||||
} else {
|
||||
$gets = Request::all();
|
||||
}
|
||||
|
||||
if (empty($gets['username'])) {
|
||||
return response()->json(['message'=>'账户不能为空。','success'=>false]);
|
||||
}
|
||||
|
||||
if (empty($gets['password'])) {
|
||||
return response()->json(['message'=>'密码不能为空。','success'=>false]);
|
||||
}
|
||||
|
||||
$credentials = [
|
||||
'username' => $gets['username'],
|
||||
'password' => $gets['password'],
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
if (Auth::validate($credentials)) {
|
||||
$user = User::where('username', $gets['username'])->first();
|
||||
|
||||
if ($user['auth_device']) {
|
||||
if (empty($gets['deviceId'])) {
|
||||
return response()->json(['message'=>'设备ID不能为空。','success'=>false]);
|
||||
}
|
||||
|
||||
// 设备ID为空时自动绑定
|
||||
if ($user['auth_device_id'] == '') {
|
||||
$user->auth_device_id = $gets['deviceId'];
|
||||
} else {
|
||||
// 存在设备ID检查是否匹配
|
||||
$auth_device_id = explode(PHP_EOL, $user['auth_device_id']);
|
||||
if (in_array($gets['deviceId'], $auth_device_id) == false) {
|
||||
return response()->json(['message'=>'设备ID错误,请联系相关人员。','success'=>false]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存用户表数据
|
||||
$user->save();
|
||||
|
||||
$assets = UserAssetService::getRoleAssets($user->role_id);
|
||||
return response()->json([
|
||||
'token' => $this->createToken($user->id),
|
||||
'access' => $assets,
|
||||
'user' => $user,
|
||||
'success' => 1,
|
||||
]);
|
||||
}
|
||||
return response()->json(['message'=>'账户或密码错误。', 'success'=>false]);
|
||||
}
|
||||
|
||||
public function logoutAction()
|
||||
{
|
||||
return response('注销完成。');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Hash;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use App\Support\Totp;
|
||||
use App\Support\Pinyin;
|
||||
use App\Support\License;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class UserController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'user',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => 'enabled', 'tab' => 'user'],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
if (auth()->id() == 1) {
|
||||
$cols = Grid::addColumns($cols, 'id', [[
|
||||
'headerName' => '密码',
|
||||
'field' => 'password_text',
|
||||
'width' => 100,
|
||||
'cellStyle' => ['text-align' => 'center'],
|
||||
]]);
|
||||
}
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
],[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]];
|
||||
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->orderBy($header['sort'], $header['order'])
|
||||
->where('user.group_id', 1);
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$header['select'][] = 'password_text';
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$items = Grid::dataFilters($rows, $header);
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['left_buttons'] = [
|
||||
['name' => '角色权限', 'color' => 'default', 'action' => 'user_role', 'display' => 1],
|
||||
['name' => '仓库权限', 'color' => 'default', 'action' => 'user_warehouse', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['right_buttons'] = [
|
||||
['name' => '导入', 'color' => 'default', 'icon' => 'fa-mail-reply', 'action' => 'import', 'display' => $this->access['import']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = User::$tabs;
|
||||
$header['bys'] = User::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 显示用户
|
||||
public function showAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'user', 'id' => $id, 'action' => 'show']);
|
||||
|
||||
$t = new Totp();
|
||||
$form['row']['secret_qrcode'] = $t->getURL($form['row']['login'], Request::server('HTTP_HOST'), $form['row']['auth_secret']);
|
||||
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 新建用户
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'user', 'id' => $id]);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 编辑用户
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$group_id = Request::get('group_id', 1);
|
||||
$header = Grid::header([
|
||||
'code' => 'user',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table('user');
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->where('user.status', 1)
|
||||
->where('user.group_id', (int)$group_id);
|
||||
|
||||
// 排序方式
|
||||
if ($query['sort'] && $query['order']) {
|
||||
$model->orderBy($query['sort'], $query['order']);
|
||||
}
|
||||
|
||||
// 搜索条件
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->selectRaw("
|
||||
[user].id,
|
||||
concat('u', [user].id) as sid,
|
||||
[user].role_id,
|
||||
[user].status,
|
||||
[user].username,
|
||||
[user].name,
|
||||
[user].name as text,
|
||||
[user].email,
|
||||
[user].phone
|
||||
");
|
||||
$rows = $model->paginate($query['limit']);
|
||||
|
||||
return response()->json($rows);
|
||||
}
|
||||
return $this->render(array(
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
));
|
||||
}
|
||||
|
||||
// 数据导入
|
||||
public function importAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
return Form::import([
|
||||
'table' => 'user',
|
||||
'keys' => ['username'],
|
||||
'defaults' => ['group_id' => 1],
|
||||
]);
|
||||
}
|
||||
$tips = '注意:表格里必须包含[用户名]列。';
|
||||
return $this->render(['tips' => $tips], 'layouts.import');
|
||||
}
|
||||
|
||||
// 账户删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'user', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php namespace Gdoo\User\Controllers;
|
||||
|
||||
use DB;
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class WidgetController extends DefaultController
|
||||
{
|
||||
public $permission = ['birthday'];
|
||||
|
||||
// 生日提醒
|
||||
public function birthdayAction()
|
||||
{
|
||||
$rows = DB::table('user')->whereRaw("concat(year(getdata()), DATE_FORMAT(birthday,'-%m-%d')) BETWEEN DATE_FORMAT(getdate(),'%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(getdate(), interval 30 day),'%Y-%m-%d')")->get();
|
||||
return $this->render(array(
|
||||
'rows' => $rows,
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user