作者 刘朕
1 个管道 的构建 通过 耗费 13 秒

后台客户、设备、api功能调整,统计功能开发

... ... @@ -96,7 +96,7 @@ class Customer extends Backend
$params['salt'] = Random::alnum();
$params['password'] = md5(md5($params['password']) . $params['salt']);
$params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。
$params['code'] = $this->get_code(); // 获取编码随机数
// $params['code'] = $this->get_code(); // 获取编码随机数
$result = $this->model->validate('Admin.add')->save($params);
if ($result === false)
{
... ...
... ... @@ -250,7 +250,7 @@ class Equipment extends Backend
$kehu = $kehu_ids = [];
foreach ($kehu_list as $k=>$v) {
$kehu_ids[] = $v['id'];
$kehu[$v['id']] = $v['nickname'];
$kehu[$v['id']] = $v['kehu_name'];
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
... ... @@ -269,6 +269,7 @@ class Equipment extends Backend
$row->validateFailException(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::name('equipment_log')->where('number',$row->number)->update(['customer_id',$params['customer_id']]);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
... ...
<?php
namespace app\admin\controller;
use app\admin\model\AuthGroupAccess;
use app\admin\model\User;
use app\common\controller\Backend;
use think\Db;
use think\Session;
/**
* 统计
*
* @icon fa fa-circle-o
*/
class Statistics extends Backend
{
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Admin;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
$admin = Session::get('admin');
$auth_group_access = new AuthGroupAccess();
$group_id = $auth_group_access->where('uid',$admin['id'])->value('group_id');
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
$map = [
'AuthGroupAccess.group_id' => 2
];
if($group_id == 2) {
$map['admin.id'] = $admin['id'];
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['auth_group_access'])
->where($map)
->order($sort, $order)
->count();
$list = $this->model
->with(['auth_group_access'])
->where($map)
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
// 查询时间处理
$filter = $this->request->get("filter", '');
$filter = (array)json_decode($filter, true);
$filter = $filter ? $filter : [];
$array = [];
if($filter) {
$array = explode(' - ',$filter['time']);
foreach ($array as $k=>$v) {
$array[$k] = strtotime($v);
}
}
foreach ($list as $k=>$v) {
// 查询应用
$api_names = Db::name('api')->where('customer_id',$v['id'])->column('name');
$list[$k]['api_name'] = $api_names ? implode(',',$api_names) : '-';
// 查询设备数
$equipment_where = [
'customer_id' => $v['id']
];
if($array) {
$equipment_where['createtime'] = ['between',$array];
}
$list[$k]['equipment'] = Db::name('equipment')->where($equipment_where)->count();
// 查询数板次数
$equipment_count_where = [
'customer_id' => $v['id']
];
if($array) {
$equipment_count_where['createtime'] = ['between',$array];
}
$list[$k]['equipment_count'] = Db::name('equipment_log')->where($equipment_count_where)->count();
// 查询数管次数
$shuguan_count_where = [
's.customer_id' => $v['id']
];
if($array) {
$shuguan_count_where['s.createtime'] = ['between',$array];
}
$list[$k]['shuguan_count'] = Db::name('shuguan')->alias('s')
->join('__SHUGUAN_LOG__ sl','s.id=sl.shuguan_id')
->where($shuguan_count_where)->count();
}
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@
namespace app\admin\controller\api;
use app\admin\model\Admin;
use app\admin\model\Equipment;
use app\common\controller\Backend;
use think\Db;
... ... @@ -131,6 +132,82 @@ class Api extends Backend
}
$this->error(__('Parameter %s can not be empty', ''));
}
// 获取客户列表
$admin_model = new Admin();
$kehu_list = $admin_model->with('auth_group_access')
->where('AuthGroupAccess.group_id',2)
->select();
$kehu_list = collection($kehu_list)->toArray();
$kehu = $kehu_ids = [];
foreach ($kehu_list as $k=>$v) {
$kehu_ids[] = $v['id'];
$kehu[$v['id']] = $v['nickname'];
}
$this->view->assign('kehu',$kehu);
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
// 获取客户列表
$admin_model = new Admin();
$kehu_list = $admin_model->with('auth_group_access')
->where('AuthGroupAccess.group_id',2)
->select();
$kehu_list = collection($kehu_list)->toArray();
$kehu = $kehu_ids = [];
foreach ($kehu_list as $k=>$v) {
$kehu_ids[] = $v['id'];
$kehu[$v['id']] = $v['nickname'];
}
$this->view->assign('kehu',$kehu);
$this->view->assign("row", $row);
return $this->view->fetch();
}
... ...
<?php
return [
'Id' => '客户id',
'Kehu_name' => '客户名称',
'Api_name' => '应用程序名称',
'Equipment' => '设备数',
'Equipment_count' => '数板次数',
'Shuguan_count' => '数管次数',
'Time' => '日期'
];
... ...
... ... @@ -3,7 +3,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-customer_id" data-rule="required" data-source="customer/index" data-field="nickname" class="form-control selectpage" name="row[customer_id]" type="text" value="">
{:build_select('row[customer_id]', $kehu, null, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
... ...
... ... @@ -3,7 +3,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-customer_id" data-rule="required" data-source="customer/index" data-field="nickname" class="form-control selectpage" name="row[customer_id]" type="text" value="{$row.customer_id|htmlentities}">
{:build_select('row[customer_id]', $kehu, $row.customer_id, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit=""
data-operate-del=""
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -1098,7 +1098,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2019-09-05 10:43:07 </div>
Generated on 2019-09-05 13:40:02 </div>
<div class="col-md-6" align="right">
<a href="https://www.fastadmin.net" target="_blank">FastAdmin</a>
</div>
... ...
... ... @@ -32,7 +32,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'nickname', title: __('Nickname')},
{field: 'mobile', title: __('Mobile')},
{field: 'email', title: __('Email')},
{field: 'code', title: __('Code')},
{field: 'kehu_name', title: __('Kehu_name')},
{field: 'kehu_type', title: __('Kehu_type')},
{field: 'kehu_zhengjian', title: __('Kehu_zhengjian')},
... ...
... ... @@ -30,7 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'id', title: __('Id'), operate: false},
{field: 'number', title: __('Number')},
{field: 'type', title: __('Type'),formatter: Table.api.formatter.label,searchList: {0: __('数板仪')}},
{field: 'admin.nickname', title: __('Nickname')},
{field: 'admin.kehu_name', title: __('Nickname')},
{field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'),formatter: Table.api.formatter.status,searchList: {normal: __('Normal'),hidden: __('Hidden')}},
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'statistics/index' + location.search,
table: 'statistics',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'createtime',
showToggle: false,
showColumns: false,
showExport: false,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id'), operate: false},
{field: 'kehu_name', title: __('Kehu_name'), operate: false},
{field: 'api_name', title: __('Api_name'), operate: false},
{field: 'equipment', title: __('Equipment'), operate: false},
{field: 'equipment_count', title: __('Equipment_count'), operate: false},
{field: 'shuguan_count', title: __('Shuguan_count'), operate: false},
{field: 'time', title: __('Time'), visible:false, operate: 'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
}
};
return Controller;
});
\ No newline at end of file
... ...