diff --git a/app/controller/api/v1/Manager.php b/app/controller/api/v1/Manager.php index 80b9f58..df7cb18 100644 --- a/app/controller/api/v1/Manager.php +++ b/app/controller/api/v1/Manager.php @@ -804,7 +804,7 @@ class Manager extends Base $page = input('page/d', 1); $size = input('size/d', 20); $keyword = input('keyword/s'); - // $status = input('status/d', 0);//状态 0=待审核 1=已审核(包含1通过 -1不通过) + $status = input('status/d', 0);//状态 0=待审核 1=已审核(包含1通过 -1不通过) $accountId = $this->request->user['user_id'] ?? 0; @@ -822,11 +822,11 @@ class Manager extends Base $where[] = ['cl.real_name|cl.mobile', 'like', '%'.$keyword.'%']; } - // if ($status == 0) { - // $where[] = ['cl.status', '=', 0]; - // } else { - // $where[] = ['cl.status', 'in', [1, -1]]; - // } + if ($status == 0) { + $where[] = ['cl.status', '=', 0]; + } else { + $where[] = ['cl.status', 'in', [1, -1]]; + } // 负责工地 $worksiteIds = AccountWorksite::where('account_id', $accountId)->column('worksite_id'); diff --git a/app/controller/manager/ProjectLog.php b/app/controller/manager/ProjectLog.php new file mode 100644 index 0000000..340484e --- /dev/null +++ b/app/controller/manager/ProjectLog.php @@ -0,0 +1,216 @@ +request->isPost()) { + $params = input('searchParams/a'); + $page = input('page/d', 1); + $size = input('size/d', 20); + + $where = []; + + $worksiteId = input('worksite_id/d'); + $worksiteId = $worksiteId ?: 0; + if ($worksiteId) { + $where[] = ['worksite_id', '=', $worksiteId]; + } + if (!empty($params)) { + foreach ($params as $key => $param) { + $param = trim($param); + if ($key == 'keyword') { + $where[] = ['name', 'like', '%'.$param.'%']; + continue; + } + if ($param == '0' || !empty($param)) { + $where[] = [$key, 'like', '%'.$param.'%']; + } + } + } + + $query = \app\model\ProjectLog::where($where); + $total = $query->count(); + + $res = [ + 'total' => $total, + 'current' => $page ?: 1, + 'size' => $size ?: 20, + 'list' => new Collection(), + ]; + + if ($total > 0) { + $res['list'] = $query->page($page, $size)->order('sort', 'desc')->order('id', 'desc')->select(); + } + + return $this->json(0, 'success', $res); + } + + $this->data['worksiteId'] = $worksiteId; + return $this->view(); + } + + /** + * 添加 + * + * @return Json|View + */ + public function add() + { + $worksiteId = input('worksite_id/d'); + if ($this->request->isPost()) { + try { + $input = input('post.'); + if (!isset($input['name'])) { + return $this->json(4000, '参数错误'); + } + \app\model\ProjectLog::create([ + 'worksite_id' => $input['worksite_id'] ?? 0, + 'name' => $input['name'] ?? '', + 'content' => $input['content'] ?? '', + 'sort' => $input['sort'] ?? 0, + ]); + + return $this->json(); + } catch (Exception $e) { + return $this->json(4001, '添加失败'.$e->getMessage()); + } + } + + $this->data['worksite_id'] = $worksiteId; + return $this->view(); + } + + /** + * 编辑 + * + * @return \think\response\Json|\think\response\View + */ + public function edit() + { + $id = input('id'); + + //通过ID查询 + $item = \app\model\ProjectLog::where('id', (int) $id)->find(); + + if (empty($item)) { + return $this->json(4000, '没有相关记录!'); + } + + if ($this->request->isPost()) { + try { + $input = input('post.'); + if (!isset($input['name'])) { + return $this->json(4000, '参数错误'); + } + + $item->save([ + 'name' => $input['name'] ?? '', + 'content' => $input['content'] ?? '', + 'sort' => $input['sort'], + ]); + return $this->json(); + } catch (Exception $e) { + return $this->json(5000, $e->getMessage()); + } + } + + $this->data['item'] = $item; + $this->data['id'] = $id; + return $this->view(); + } + + /** + * 更新属性 + * + * @throws ModelNotFoundException + * @throws DbException + * @throws DataNotFoundException + * @throws Exception + */ + public function modify() + { + if (!$this->request->isPost()) { + return $this->json(4000, '非法请求'); + } + + $item = input('post.'); + $validate = $this->validateByApi($item, [ + 'field' => 'require', + 'value' => 'require', + ]); + + if ($validate !== true) { + return $validate; + } + + // 通过ID查询 + if (!$info = \app\model\ProjectLog::where('id', (int) $item['id'])->find()) { + return $this->json(4001, '记录不存在'); + } + + $update = [$item['field'] => $item['value']]; + + try { + $info->save($update); + return $this->json(); + } catch (ValidateException $e) { + return $this->json(4001, $e->getError()); + } catch (Exception $e) { + return $this->json(5000, '修改失败'); + } + } + + /** + * 删除 + * + * @return \think\response\Json + */ + public function del(): Json + { + if (!$this->request->isPost()) { + return $this->json(4000, '非法请求'); + } + + $ids = $this->request->param('ids/a', []); + if (empty($ids)) { + $ids[] = $this->request->param('id/d', 0); + $ids = array_filter($ids); + } + + try { + if (count($ids)) { + //删除逻辑 + \app\model\ProjectLog::whereIn('id', $ids)->delete(); + + Log::write(get_class(), 'del', '删除操作,涉及到的ID为:'.implode(',', $ids)); + } + } catch (Exception $e) { + return $this->json(5000, $e->getMessage()); + } + + return $this->json(); + } +} \ No newline at end of file diff --git a/app/model/ProjectLog.php b/app/model/ProjectLog.php new file mode 100644 index 0000000..526b022 --- /dev/null +++ b/app/model/ProjectLog.php @@ -0,0 +1,13 @@ + 0) { + miniTab.listen(); + + // 渲染表格 + let listUrl = $('#table-container').data('url'); + let insTb = table.render({ + elem: '#table-container', + title: '列表', + defaultToolbar: ['filter', 'exports', { + title: '搜索' //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可 + , layEvent: 'search' + , icon: 'layui-icon-search' + }], + toolbar: '#toolbar-tpl', + method: 'POST', + url: listUrl, + page: true, + limit: 20, + limits: [20,50,100,200,500,1000], + request: { + pageName: 'page', + limitName: 'size', + }, + parseData: function (res) { + return { + "code": res.code, //解析接口状态 + "msg": res.msg, //解析提示文本 + "count": res.data.total, //解析数据长度 + "data": res.data.list //解析数据列表 + }; + }, + cols: [[ + {type: 'checkbox'}, + {field: 'name', title: '名称', minWidth: 200}, + {field: 'created_at', title: '创建时间', minWidth: 200}, + // {field: 'sort', width: 150, align: 'center', title: '排序', edit: 'text'}, + {templet: '#row-operate', width: 280, align: 'center', title: '操作'} + ]], + done: function () { + Tools.setInsTb(insTb); + } + }); + + //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 + table.on('toolbar(table-container-filter)', function (obj) { + let layEvent = obj.event; + let insTb = Tools.getInsTb(); + let url = $($(this).context).data('href') + let title = $($(this).context).data('title') + let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; + let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; + + let checkStatus = table.checkStatus('table-container'); + let selected = checkStatus.data; + let ids = []; + + switch (layEvent) { + // toolbar 删除 + case 'del': + if (checkStatus.data.length <= 0) { + layer.msg('请先选择数据'); + return false; + } + // let selected = checkStatus.data; + // let ids = []; + + $.each(selected, function (index, val) { + ids.push(val.id); + }) + delRow(url, ids, insTb); + return false; + // toolbar 刷新 + case 'refresh': + refreshTab(insTb); + return false; + // toolbar 搜索 + case 'search': + let search = $('.table-search-fieldset'); + if (search.hasClass('div-show')) { + search.css('display', 'none').removeClass('div-show'); + } else { + search.css('display', 'block').addClass('div-show'); + } + return false; + // 其他 默认为打开弹出层 + default: + if (layEvent !== 'LAYTABLE_COLS' && layEvent !== 'LAYTABLE_EXPORT') { + openLayer(url, title, width, height); + return false; + } + } + }); + + //监听行工具条 + table.on('tool(table-container-filter)', function (obj) { + let data = obj.data; + let layEvent = obj.event; + let url = $($(this).context).data('href'); + let title = $($(this).context).data('title'); + let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; + let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; + let insTb = Tools.getInsTb(); + + switch (layEvent) { + // 行 删除 + case 'del': + let ids = [data.id]; + delRow(url, ids, insTb); + return false; + //其他 默认为打开弹出层 + default: + openLayer(url, title, width, height); + return false; + } + }); + + changeSwitch('changeSaleable');//监听上下架 + + let modifyUrl = $('#row-modify').data('url'); + + table.on('edit(table-container)', function (obj) { + let id = obj.data.id; + $.ajax(modifyUrl, { + data: {"id": id, "field": obj.field, "value": obj.value} + ,dataType : 'json' + ,type: 'POST' + }) + .done(function (res) { + if (res.code === 0) { + insTb.reload(); + } + }) + }); + + // switch变更 + function changeSwitch(filter) { + form.on('switch(' + filter + ')', function (obj) { + let val = obj.elem.checked ? 1 : 0; + $.post(modifyUrl, {id: this.value, field: this.name, value: val}, function (res) { + layer.msg(res.msg) + if (res.code !== 0) { + //操作不成功则刷新页面 + insTb.reload(); + } + }) + }); + } + + // 监听搜索操作 + form.on('submit(data-search-btn)', function (data) { + //执行搜索重载 + table.reload('table-container', { + page: {curr: 1} + , where: data.field + }, 'data'); + + return false; + }); + + } + /*** index end ***/ + + if ($('.location-operate-page').length > 0) { + let parentCategory = $('#parent-category'); + let categoryList = parentCategory.data('list') ? parentCategory.data('list') : []; + xmSelect.render({ + el: '#parent-category', + paging: false, + autoRow: true, + clickClose: true, + name: 'category_id', + tips: '请选择分类', + direction: 'auto', + height: 'auto', + model: { + icon: 'hidden', + }, + prop: { + name: 'title', + value: 'id', + }, + tree: { + show: true, + strict: false, + clickCheck: true, + expandedKeys: true, + clickExpand: false + }, + theme: { + color: '#1e84ff', + }, + data: categoryList + }); + + laydate.render({ + elem: '#published-at', + type: 'datetime', + }); + } +}); \ No newline at end of file diff --git a/view/manager/project_log/add.html b/view/manager/project_log/add.html new file mode 100644 index 0000000..fb2abc2 --- /dev/null +++ b/view/manager/project_log/add.html @@ -0,0 +1,21 @@ +{layout name="manager/layout" /} +
+
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/view/manager/project_log/edit.html b/view/manager/project_log/edit.html new file mode 100644 index 0000000..bec95e4 --- /dev/null +++ b/view/manager/project_log/edit.html @@ -0,0 +1,22 @@ +{layout name="manager/layout" /} +
+
+
+
+ +
+ +
+
+ +
+
+ + +
+
+
+
+
+ + \ No newline at end of file diff --git a/view/manager/project_log/index.html b/view/manager/project_log/index.html new file mode 100644 index 0000000..e69525f --- /dev/null +++ b/view/manager/project_log/index.html @@ -0,0 +1,52 @@ +{layout name="manager/layout" /} + +
+
+
+
+ +
+
+
+
+
+
+
+ + + + + + + + + + + + + \ No newline at end of file