创建版本
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Form;
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class LogController extends DefaultController
|
||||
{
|
||||
public $permission = [];
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '系统日志',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'system_log',
|
||||
'master_table' => 'system_log',
|
||||
'create_btn' => 1,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'mail.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'type' => [
|
||||
'field' => 'type',
|
||||
'headerName' => '类型',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'user' => [
|
||||
'field' => 'remark',
|
||||
'headerName' => '备注',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 0,
|
||||
],
|
||||
'created_dt' => [
|
||||
'field' => 'created_dt',
|
||||
'headerName' => '操作时间',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'ip' => [
|
||||
'field' => 'ip',
|
||||
'headerName' => 'IP',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'browser' => [
|
||||
'field' => 'browser',
|
||||
'headerName' => '浏览器',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'device' => [
|
||||
'field' => 'device',
|
||||
'headerName' => '设备ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
/*
|
||||
'error_count' => [
|
||||
'field' => 'error_count',
|
||||
'headerName' => '错误次数',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
*/
|
||||
'level' => [
|
||||
'field' => 'level',
|
||||
'headerName' => '等级',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->orderBy('id', 'desc');
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$rows->transform(function($row) {
|
||||
if ($row['status'] == 1) {
|
||||
$row['status_name'] = '启用';
|
||||
} else {
|
||||
$row['status_name'] = '禁用';
|
||||
}
|
||||
return $row;
|
||||
});
|
||||
return $rows->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
DB::table('system_log')->whereIn('id', $id)->delete();
|
||||
return $this->json('操作完成。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Form;
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Index\Services\NotificationService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class MailController extends DefaultController
|
||||
{
|
||||
public $permission = ['test'];
|
||||
|
||||
/**
|
||||
* 邮件设置
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '邮件',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'mail',
|
||||
'master_table' => 'mail',
|
||||
'create_btn' => 0,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'mail.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-',
|
||||
'form_type' => 'text',
|
||||
'width' => 0,
|
||||
],
|
||||
'user' => [
|
||||
'field' => 'user',
|
||||
'headerName' => '邮箱帐号',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'smtp' => [
|
||||
'field' => 'smtp',
|
||||
'headerName' => 'SMTP服务器',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'port' => [
|
||||
'field' => 'port',
|
||||
'headerName' => '服务器端口',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'status_name' => [
|
||||
'field' => 'status_name',
|
||||
'headerName' => '状态',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'sort' => [
|
||||
'field' => 'sort',
|
||||
'headerName' => '排序',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]],
|
||||
'width' => 80,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$rows->transform(function($row) {
|
||||
if ($row['status'] == 1) {
|
||||
$row['status_name'] = '启用';
|
||||
} else {
|
||||
$row['status_name'] = '禁用';
|
||||
}
|
||||
return $row;
|
||||
});
|
||||
return $rows->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', 'icon' => 'fa-envelope-o', 'action' => 'test', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建邮箱帐号
|
||||
public function createAction()
|
||||
{
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
// 编辑邮箱帐号
|
||||
public function editAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$row = DB::table('mail')->where('id', $id)->first();
|
||||
return $this->render([
|
||||
'row' => $row,
|
||||
], 'edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
public function storeAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'smtp' => 'required',
|
||||
'user' => 'required',
|
||||
'password' => 'required',
|
||||
'port' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->json(join('<br>', $v->errors()->all()));
|
||||
|
||||
}
|
||||
if ($gets['id']) {
|
||||
DB::table('mail')->where('id', $gets['id'])->update($gets);
|
||||
} else {
|
||||
DB::table('mail')->insert($gets);
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
DB::table('mail')->whereIn('id', $id)->delete();
|
||||
return $this->json('操作完成。', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件测试
|
||||
*/
|
||||
public function testAction()
|
||||
{
|
||||
$mail_to = Request::get('mail_to');
|
||||
if (Request::method() == 'POST') {
|
||||
$send = NotificationService::mail('notification', [$mail_to], '测试邮件', '测试邮件内容');
|
||||
if ($send) {
|
||||
return $this->json('测试邮件已发送。', true);
|
||||
} else {
|
||||
return $this->json('发送失败,请检查邮件地址或SMTP配置。');
|
||||
}
|
||||
}
|
||||
return $this->render([
|
||||
'mail_to' => $mail_to
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use Session;
|
||||
use Request;
|
||||
use Validator;
|
||||
use DB;
|
||||
|
||||
use Gdoo\System\Models\Media;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class MediaController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog', 'qrcode', 'create', 'delete', 'download', 'folder'];
|
||||
|
||||
/**
|
||||
* 二维码上传
|
||||
*/
|
||||
public function qrcodeAction()
|
||||
{
|
||||
$key = Request::get('key');
|
||||
list($table, $field) = explode('.', $key);
|
||||
$model = DB::table('model')->where('table', $table)->first();
|
||||
$token = Request::get('x-auth-token');
|
||||
return $this->render([
|
||||
'model' => $model,
|
||||
'token' => $token,
|
||||
'key' => $key,
|
||||
], 'qrcode');
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建文件
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$folderId = Request::get('folder_id');
|
||||
$file = Request::file('Filedata');
|
||||
$rules = [
|
||||
'file' => 'mimes:'.$this->setting['upload_type'],
|
||||
];
|
||||
$v = Validator::make(['file' => $file], $rules);
|
||||
|
||||
if ($file->isValid() && $v->passes()) {
|
||||
// 获取上传uri第一个目录
|
||||
$path = 'media/'.date('Y/m');
|
||||
$upload_path = upload_path().'/'.$path;
|
||||
|
||||
// 文件后缀名
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
|
||||
// 文件新名字
|
||||
$filename = date('dhis_').str_random(4).'.'.$extension;
|
||||
$filename = mb_strtolower($filename);
|
||||
|
||||
$fileTypes = ['image/png', 'image/jpg', 'image/jpeg'];
|
||||
$mimeType = $file->getMimeType();
|
||||
|
||||
if ($file->move($upload_path, $filename)) {
|
||||
$data = [
|
||||
'name' => mb_strtolower($file->getClientOriginalName()),
|
||||
'path' => $path.'/'.$filename,
|
||||
'type' => $extension,
|
||||
'folder_id' => $folderId,
|
||||
'size' => $file->getClientSize(),
|
||||
];
|
||||
|
||||
if (in_array($mimeType, $fileTypes)) {
|
||||
thumb($upload_path.'/'.$filename, 420, 420);
|
||||
$path = pathinfo($path.'/'.$filename);
|
||||
$thumb = $path['dirname'].'/thumb-420-'.$path['basename'];
|
||||
$data['thumb'] = $thumb;
|
||||
}
|
||||
|
||||
$id = Media::insertGetId($data);
|
||||
if ($id) {
|
||||
$data['id'] = $id;
|
||||
return $this->json($data, true);
|
||||
} else {
|
||||
return $this->json('文件上传失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->json('文件上传失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件对话框
|
||||
*/
|
||||
public function dialogAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$folder = Request::get('folder');
|
||||
$folderId = Request::get('folder_id');
|
||||
$userId = auth()->id();
|
||||
|
||||
$model = Media::where('created_id', $userId);
|
||||
if ($folder == 1) {
|
||||
$model->whereRaw('folder = 1');
|
||||
} else {
|
||||
$model->whereRaw('isnull(folder, 0) = 0');
|
||||
if ($folderId) {
|
||||
$model->where('folder_id', $folderId);
|
||||
}
|
||||
}
|
||||
$rows = $model->orderBy('id', 'desc')->get()->toArray();
|
||||
foreach($rows as &$row) {
|
||||
if (in_array($row['type'], ['png', 'jpg', 'jpeg'])) {
|
||||
$file = $row['path'];
|
||||
$path = pathinfo($file);
|
||||
$thumb = $path['dirname'].'/thumb-420-'.$path['basename'];
|
||||
if (!is_file(upload_path().'/'.$thumb)) {
|
||||
thumb(upload_path().'/'.$file, 420, 420);
|
||||
}
|
||||
$row['path'] = $file;
|
||||
$row['thumb'] = $thumb;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建文件夹
|
||||
*/
|
||||
public function folderAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$gets['folder'] = 1;
|
||||
Media::insertGetId($gets);
|
||||
return $this->json('操作成功', true);
|
||||
}
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
public function downloadAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
if ($id) {
|
||||
$row = Media::where('id', $id)->first();
|
||||
$path = upload_path().'/'.$row['path'];
|
||||
return response()->download($path, $row['name']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
$id = (array)Request::get('id');
|
||||
if (empty($id)) {
|
||||
return $this->json('删除失败');
|
||||
}
|
||||
|
||||
$rows = Media::whereIn('id', $id)->get();
|
||||
foreach ($rows as $row) {
|
||||
$file = upload_path().'/'.$row['path'];
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
Media::whereIn('id', $id)->delete();
|
||||
return $this->json('删除成功', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\System\Models\Menu;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class MenuController extends DefaultController
|
||||
{
|
||||
// 菜单列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '模型',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'menu',
|
||||
'master_table' => 'menu',
|
||||
'create_btn' => 1,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'menu.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'text' => [
|
||||
'field' => 'text',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'url' => [
|
||||
'field' => 'url',
|
||||
'headerName' => 'URL',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 0,
|
||||
],
|
||||
'access' => [
|
||||
'field' => 'access',
|
||||
'headerName' => '认证',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'sort' => [
|
||||
'field' => 'sort',
|
||||
'headerName' => '排序',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'status_name' => [
|
||||
'field' => 'status_name',
|
||||
'headerName' => '状态',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'width' => 120,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]],
|
||||
'width' => 100,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = Menu::setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->orderBy('lft', 'asc');
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
|
||||
$rows->transform(function($row) {
|
||||
$row['access'] = $row['access'] == 1 ? '是' : '否';
|
||||
if ($row['status'] == 1) {
|
||||
$row['status_name'] = '启用';
|
||||
} else {
|
||||
$row['status_name'] = '禁用';
|
||||
}
|
||||
return $row;
|
||||
});
|
||||
|
||||
$items = $rows->items();
|
||||
array_nest($items);
|
||||
$rows->items($items);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
/*
|
||||
if (Request::method() == 'POST') {
|
||||
$sorts = Request::get('sort');
|
||||
foreach ($sorts as $id => $sort) {
|
||||
DB::table('menu')->where('id', $id)->update(['sort' => $sort]);
|
||||
}
|
||||
tree_rebuild('menu');
|
||||
return $this->success('index', '恭喜你,操作成功。');
|
||||
}
|
||||
|
||||
$search = search_form([
|
||||
'referer' => 1,
|
||||
], []);
|
||||
|
||||
$rows = DB::table('menu')
|
||||
->orderBy('lft', 'asc')
|
||||
->get();
|
||||
*/
|
||||
|
||||
/*
|
||||
$rows = DB::table('dict')->get();
|
||||
|
||||
foreach ($rows as $key => $row) {
|
||||
|
||||
$values = json_decode($row['value'], true);
|
||||
|
||||
//$data['parent_id'] = $row['id'];
|
||||
|
||||
$id = DB::table('option')->insertGetId([
|
||||
'parent_id' => 0,
|
||||
'name' => $row['name'],
|
||||
'value' => $row['key'],
|
||||
]);
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['parent_id'] = $id;
|
||||
|
||||
if($values) {
|
||||
|
||||
foreach ($values as $k => $v) {
|
||||
|
||||
$data['sort'] = $k;
|
||||
$data['value'] = ''.$v['id'].'';
|
||||
$data['name'] = ''.$v['name'].'';
|
||||
DB::table('option')->insert($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print_r($rows);
|
||||
exit;
|
||||
*/
|
||||
|
||||
//$rows = array_nest($rows);
|
||||
/*
|
||||
return $this->display([
|
||||
'rows' => $rows,
|
||||
]);
|
||||
*/
|
||||
}
|
||||
|
||||
// 新建菜单
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v)->withInput();
|
||||
}
|
||||
if ($gets['id']) {
|
||||
DB::table('menu')->where('id', $gets['id'])->update($gets);
|
||||
} else {
|
||||
DB::table('menu')->insert($gets);
|
||||
}
|
||||
tree_rebuild('menu');
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
$row = DB::table('menu')->where('id', $id)->first();
|
||||
$parents = DB::table('menu')->orderBy('lft', 'asc')->get();
|
||||
$parents = array_nest($parents);
|
||||
|
||||
return $this->render([
|
||||
'row' => $row,
|
||||
'parents' => $parents,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
public function editAction() {
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function storeAction()
|
||||
{
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
// 删除菜单
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
$count = DB::table('menu')->whereIn('parent_id', $id)->count();
|
||||
if ($count) {
|
||||
return $this->json('存在子菜单无法删除。');
|
||||
}
|
||||
DB::table('menu')->whereIn('id', $id)->delete();
|
||||
return $this->json('删除成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\System\Models\Option;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class OptionController extends DefaultController
|
||||
{
|
||||
public $permission = ['category'];
|
||||
|
||||
// 枚举列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '枚举',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'option',
|
||||
'master_table' => 'option',
|
||||
'create_btn' => 1,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
'parent_id' => 0,
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'option.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-',
|
||||
'form_type' => 'text',
|
||||
'width' => 0,
|
||||
],
|
||||
'value' => [
|
||||
'field' => 'value',
|
||||
'headerName' => '值',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'status_name' => [
|
||||
'field' => 'status_name',
|
||||
'headerName' => '状态',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'sort' => [
|
||||
'field' => 'sort',
|
||||
'headerName' => '排序',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]],
|
||||
'width' => 80,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->where('option.parent_id', $query['parent_id']);
|
||||
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$rows->transform(function($row) {
|
||||
if ($row['status'] == 1) {
|
||||
$row['status_name'] = '启用';
|
||||
} else {
|
||||
$row['status_name'] = '禁用';
|
||||
}
|
||||
return $row;
|
||||
});
|
||||
return $rows->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 新建字典
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$row = DB::table('option')->where('id', $id)->first();
|
||||
$parent_id = (int)Request::get('parent_id');
|
||||
$parents = Option::where('parent_id', 0)->orderBy('sort', 'asc')->orderBy('id', 'asc')->get();
|
||||
return $this->render([
|
||||
'row' => $row,
|
||||
'parents' => $parents,
|
||||
'parent_id' => $parent_id,
|
||||
], 'edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
public function storeAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'value' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v)->withInput();
|
||||
}
|
||||
|
||||
if ($gets['id']) {
|
||||
DB::table('option')->where('id', $gets['id'])->update($gets);
|
||||
} else {
|
||||
DB::table('option')->insert($gets);
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
}
|
||||
|
||||
public function categoryAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$rows = Option::where('parent_id', 0)->orderBy('sort', 'asc')->orderBy('id', 'asc')->get();
|
||||
$rows->prepend(['name' => '全部类别', 'id' => 0, 'parent_id' => 0]);
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除字典
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
|
||||
$count = DB::table('option')->whereIn('parent_id', $id)->count();
|
||||
if ($count > 0) {
|
||||
return $this->error('存在子选项无法删除。');
|
||||
}
|
||||
|
||||
DB::table('option')->whereIn('id', $id)->delete();
|
||||
return $this->back('删除成功。');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\System\Models\Region;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class RegionController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog', 'category'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'region',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => '', 'parent_id' => 0],
|
||||
'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->where('region.parent_id', $query['parent_id']);
|
||||
|
||||
$model->orderBy($header['sort'], $header['order']);
|
||||
|
||||
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'] = Region::$tabs;
|
||||
$header['bys'] = Region::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'region', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form([], [
|
||||
['text','region.name','名称'],
|
||||
['text','region.id','ID'],
|
||||
]);
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = Region::orderBy('id', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$rows = $model->get(['*', 'name as text']);
|
||||
$rows = array_nest($rows);
|
||||
|
||||
$json = [];
|
||||
foreach($rows as $row) {
|
||||
$row['text'] = $row['layer_space'].$row['name'];
|
||||
$json[] = $row;
|
||||
}
|
||||
return response()->json(['data' => $json]);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
'query' => $search['query']
|
||||
]);
|
||||
}
|
||||
|
||||
public function categoryAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$model = Region::orderBy('id', 'asc');
|
||||
$rows = $model->get(['*', 'name as text']);
|
||||
array_nest($rows);
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
$id = array_filter((array)$id);
|
||||
|
||||
if (empty($id)) {
|
||||
return $this->json('最少选择一行记录。');
|
||||
}
|
||||
|
||||
$types = Region::whereIn('id', $id)->get();
|
||||
foreach ($types as $type) {
|
||||
// 删除数据
|
||||
$type->delete();
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', url_referer('index'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\System\Models\Setting;
|
||||
use Gdoo\Index\Models\Notification;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class SettingController extends DefaultController
|
||||
{
|
||||
/**
|
||||
* 基本设置
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '系统设置',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'setting',
|
||||
'master_table' => 'setting',
|
||||
'create_btn' => 1,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '配置名称', 'field' => 'setting.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'key' => [
|
||||
'field' => 'key',
|
||||
'headerName' => 'Key',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'value' => [
|
||||
'field' => 'value',
|
||||
'headerName' => '值',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 260,
|
||||
],
|
||||
'type' => [
|
||||
'field' => 'type',
|
||||
'headerName' => '类型',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'remark' => [
|
||||
'field' => 'remark',
|
||||
'headerName' => '备注',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]],
|
||||
'width' => 80,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
return $rows->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
|
||||
return $this->display();
|
||||
}
|
||||
|
||||
// 新建邮箱帐号
|
||||
public function createAction()
|
||||
{
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
// 编辑邮箱帐号
|
||||
public function editAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$row = DB::table('setting')->where('id', $id)->first();
|
||||
return $this->render([
|
||||
'row' => $row,
|
||||
], 'edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传设置
|
||||
*/
|
||||
public function uploadAction()
|
||||
{
|
||||
// 扫描字体目录
|
||||
$paths = new \DirectoryIterator(public_path('assets/fonts'));
|
||||
$fonts = [];
|
||||
foreach ($paths as $file) {
|
||||
if ($file->isFile()) {
|
||||
$fonts[] = $file->getFilename();
|
||||
}
|
||||
}
|
||||
return $this->display([
|
||||
'fonts' => $fonts,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片设置
|
||||
*/
|
||||
public function imageAction()
|
||||
{
|
||||
// 扫描字体目录
|
||||
$paths = new \DirectoryIterator(public_path('assets/fonts'));
|
||||
$fonts = [];
|
||||
foreach ($paths as $file) {
|
||||
if ($file->isFile()) {
|
||||
$fonts[] = $file->getFilename();
|
||||
}
|
||||
}
|
||||
return $this->display([
|
||||
'fonts' => $fonts,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全设置
|
||||
*/
|
||||
public function securityAction()
|
||||
{
|
||||
return $this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期时间
|
||||
*/
|
||||
public function datetimeAction()
|
||||
{
|
||||
$lang = trans('setting');
|
||||
return $this->display(array(
|
||||
'lang' => $lang,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
public function storeAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'key' => 'required',
|
||||
'type' => 'required',
|
||||
'value' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->json(join('<br>', $v->errors()->all()));
|
||||
}
|
||||
if ($gets['id']) {
|
||||
DB::table('setting')->where('id', $gets['id'])->update($gets);
|
||||
} else {
|
||||
DB::table('setting')->insert($gets);
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
DB::table('setting')->whereIn('id', $id)->delete();
|
||||
return $this->json('删除成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Index\Services\NotificationService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class SmsController extends DefaultController
|
||||
{
|
||||
public $permission = ['test'];
|
||||
|
||||
/**
|
||||
* 短信设置
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '短信',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'sms',
|
||||
'master_table' => 'sms',
|
||||
'create_btn' => 0,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'sms.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'apikey' => [
|
||||
'field' => 'apikey',
|
||||
'headerName' => 'apikey',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 0,
|
||||
],
|
||||
'driver' => [
|
||||
'field' => 'driver',
|
||||
'headerName' => '服务商',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'status_name' => [
|
||||
'field' => 'status_name',
|
||||
'headerName' => '状态',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'sort' => [
|
||||
'field' => 'sort',
|
||||
'headerName' => '排序',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]],
|
||||
'width' => 80,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$rows->transform(function($row) {
|
||||
if ($row['status'] == 1) {
|
||||
$row['status_name'] = '启用';
|
||||
} else {
|
||||
$row['status_name'] = '禁用';
|
||||
}
|
||||
return $row;
|
||||
});
|
||||
return $rows->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', 'icon' => 'fa-comment-o', 'action' => 'test', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信保存
|
||||
*/
|
||||
public function storeAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'apikey' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->json(join('<br>', $v->errors()->all()));
|
||||
}
|
||||
if ($gets['id']) {
|
||||
DB::table('sms')->where('id', $gets['id'])->update($gets);
|
||||
} else {
|
||||
DB::table('sms')->insert($gets);
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
}
|
||||
|
||||
// 新建短信帐号
|
||||
public function createAction()
|
||||
{
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
// 编辑短信帐号
|
||||
public function editAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$row = DB::table('sms')->where('id', $id)->first();
|
||||
return $this->render([
|
||||
'row' => $row,
|
||||
], 'edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
DB::table('sms')->whereIn('id', $id)->delete();
|
||||
return $this->json('删除成功。', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信测试
|
||||
*/
|
||||
public function testAction()
|
||||
{
|
||||
$phone = Request::get('phone');
|
||||
if (Request::method() == 'POST') {
|
||||
$send = NotificationService::sms([$phone], '测试短信', '测试短信内容');
|
||||
if ($send) {
|
||||
return $this->json('测试短信已发送。', true);
|
||||
} else {
|
||||
return $this->json('发送失败,请检查短信配置。');
|
||||
}
|
||||
}
|
||||
return $this->render([
|
||||
'phone' => $phone
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class SmsLogController extends DefaultController
|
||||
{
|
||||
public $permission = [];
|
||||
|
||||
/**
|
||||
* 短信设置
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '短信记录',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'sms_log',
|
||||
'master_table' => 'sms_log',
|
||||
'create_btn' => 1,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'sms.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '服务商',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'content' => [
|
||||
'field' => 'content',
|
||||
'headerName' => '内容',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'data' => [
|
||||
'field' => 'data',
|
||||
'headerName' => '数据',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 0,
|
||||
],
|
||||
'phone' => [
|
||||
'field' => 'phone',
|
||||
'headerName' => '手机号',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'status_name' => [
|
||||
'field' => 'status_name',
|
||||
'headerName' => '状态',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'width' => 80,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->orderBy('id', 'desc');
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$rows->transform(function($row) {
|
||||
if ($row['status'] == 1) {
|
||||
$row['status_name'] = '成功';
|
||||
} else {
|
||||
$row['status_name'] = '失败';
|
||||
}
|
||||
return $row;
|
||||
});
|
||||
return $rows->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
DB::table('sms_log')->whereIn('id', $id)->delete();
|
||||
return $this->json('删除成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
<?php namespace Gdoo\System\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
use Gdoo\Model\Services\ModuleService;
|
||||
use Gdoo\System\Models\Widget;
|
||||
|
||||
class WidgetController extends DefaultController
|
||||
{
|
||||
public $permission = ['refresh'];
|
||||
|
||||
/**
|
||||
* 部件设置
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '部件',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'widget',
|
||||
'master_table' => 'widget',
|
||||
'create_btn' => 1,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'widget.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'code' => [
|
||||
'field' => 'code',
|
||||
'headerName' => '编码',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'url' => [
|
||||
'field' => 'url',
|
||||
'headerName' => 'URL',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'more_url' => [
|
||||
'field' => 'more_url',
|
||||
'headerName' => 'MoreURL',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'receive_name' => [
|
||||
'field' => 'receive_name',
|
||||
'headerName' => '授权范围',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'width' => 0,
|
||||
],
|
||||
'receive_name' => [
|
||||
'field' => 'receive_name',
|
||||
'headerName' => '授权范围',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'width' => 0,
|
||||
],
|
||||
'grid' => [
|
||||
'field' => 'grid',
|
||||
'headerName' => '位置',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'type' => [
|
||||
'field' => 'type',
|
||||
'headerName' => '类型',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'width' => 60,
|
||||
],
|
||||
'default' => [
|
||||
'field' => 'default',
|
||||
'headerName' => '全局',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'width' => 60,
|
||||
],
|
||||
'status' => [
|
||||
'field' => 'status',
|
||||
'headerName' => '状态',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 60,
|
||||
],
|
||||
'sort' => [
|
||||
'field' => 'sort',
|
||||
'headerName' => '排序',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 60,
|
||||
],
|
||||
'updated_dt' => [
|
||||
'field' => 'updated_dt',
|
||||
'headerName' => '操作时间',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]],
|
||||
'width' => 100,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table('widget')->setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->orderBy('sort', 'asc');
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
|
||||
$rows->transform(function($row) {
|
||||
$row['type'] = $row['type'] == 1 ? '部件' : '信息';
|
||||
$row['default'] = $row['default'] == 1 ? '是' : '否';
|
||||
$row['status'] = $row['status'] == 1 ? '启用' : '禁用';
|
||||
$row['grid'] = $row['grid'] == 8 ? '左' : '右';
|
||||
|
||||
$row['updated_dt'] = format_datetime($row['updated_at']);
|
||||
return $row;
|
||||
});
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$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', 'icon' => 'fa-refresh', 'action' => 'refresh', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建部件
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'url' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->json($v->errors()->first());
|
||||
}
|
||||
if ($gets['id']) {
|
||||
DB::table('widget')->where('id', $gets['id'])->update($gets);
|
||||
} else {
|
||||
DB::table('widget')->insert($gets);
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
$row = DB::table('widget')->where('id', $id)->first();
|
||||
return $this->render([
|
||||
'row' => $row
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 编辑部件
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function storeAction()
|
||||
{
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部件
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
Widget::whereIn('id', $id)->delete();
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部件列表
|
||||
*/
|
||||
public function refreshAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$widgets = ModuleService::widgets();
|
||||
foreach($widgets as $code => $widget) {
|
||||
$model = Widget::firstOrNew(['code' => $code]);
|
||||
$model->fill($widget);
|
||||
$model->save();
|
||||
}
|
||||
return $this->json('部件刷新完成。', true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user