isGet() == false) { $this->error('非法请求'); } // 处理中客诉 —— 按建档人 Sys_id 分组取不重复人员 // 已在 db_客诉流程 中存在“处理完毕”环节的客诉视为已关闭,不计入处理中 $personList = \db('db_客诉记录') ->whereRaw("UniqID NOT IN (SELECT RelationID FROM db_客诉流程 WHERE rtrim(处理环节) = '处理完毕')") ->where('Sys_id', '<>', '') ->group('Sys_id') ->field('rtrim(Sys_id) as Sys_id') ->order('Sys_id asc') ->select(); $children = []; foreach ($personList as $item) { $name = $item['Sys_id']; // 拆分 "admin/超级管理员" 格式 $parts = explode('/', $name); $code = isset($parts[0]) ? trim($parts[0]) : ''; $realName = isset($parts[1]) ? trim($parts[1]) : $name; $children[] = [ 'label' => $name, 'code' => $code, 'name' => $realName, 'type' => 'person', // 人员节点 ]; } // 处理中客诉 $treeData[] = [ 'label' => '处理中客诉', 'children' => $children, 'type' => 'group', ]; // 年度客诉统计 $treeData[] = [ 'label' => '年度客诉统计', 'type' => 'year_stat', ]; $this->success('请求成功', $treeData); } /** * 获取右侧表格数据 * @ApiMethod GET * @param string code 人员编号(可选) * @param string type 节点类型 person | year_stat(可选) * @return void */ public function getList() { if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); $field = 'rtrim(客诉单号) as 客诉单号,rtrim(客诉日期) as 客诉日期,rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,扣分,rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门,UniqID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq'; $nodeType = isset($params['type']) ? $params['type'] : ''; $code = isset($params['code']) ? trim($params['code']) : ''; $name = isset($params['name']) ? trim($params['name']) : ''; $query = \db('db_客诉记录')->field($field); // 已在 db_客诉流程 中存在“处理完毕”环节的客诉视为已关闭 $notDoneSql = "UniqID NOT IN (SELECT RelationID FROM db_客诉流程 WHERE rtrim(处理环节) = '处理完毕')"; if ($nodeType === 'person') { // 处理中客诉 —— 无处理完毕环节,且按建档人 Sys_id 过滤 $query->whereRaw($notDoneSql); if (!empty($name)) { $query->whereLike('Sys_id', '%' . $name . '%'); } } elseif ($nodeType === 'year_stat') { // 年度客诉统计 —— 查全部 } else { // 默认:全部处理中(无处理完毕环节) $query->whereRaw($notDoneSql); } $list = $query->order('客诉日期 desc')->select(); if (empty($list)) { $this->success('暂无数据', []); } $this->success('请求成功', $list); } /** * 新增客诉记录 * @ApiMethod POST * @return void */ public function add() { if (Request::instance()->isPost() == false) { $this->error('非法请求'); } $data = Request::instance()->post(); if (empty($data)) { $this->error('参数为空'); } // 自动生成 UniqID(取当前最大+1) $maxId = \db('db_客诉记录')->max('UniqID'); $data['UniqID'] = $maxId ? $maxId + 1 : 1; // 若客诉日期为空,填当天 if (empty($data['客诉日期'])) { $data['客诉日期'] = date('Y-m-d H:i:s'); } // 系统字段 $data['Sys_rq'] = date('Y-m-d H:i:s'); $data['Mod_rq'] = date('Y-m-d H:i:s'); $sql = \db('db_客诉记录')->fetchSql(true)->insert($data); $res = \db()->query($sql); if ($res === false) { $this->error('新增失败'); } $this->success('新增成功', ['UniqID' => $data['UniqID']]); } /** * 修改客诉记录 * @ApiMethod POST * @return void */ public function edit() { if (Request::instance()->isPost() == false) { $this->error('非法请求'); } $data = Request::instance()->post(); if (empty($data['UniqID'])) { $this->error('缺少 UniqID'); } $data['Mod_rq'] = date('Y-m-d H:i:s'); $uniqId = $data['UniqID']; unset($data['UniqID']); $sql = \db('db_客诉记录')->where('UniqID', $uniqId)->fetchSql(true)->update($data); $res = \db()->query($sql); if ($res === false) { $this->error('修改失败'); } $this->success('修改成功'); } /** * 删除客诉记录(支持批量) * @ApiMethod POST * @param UniqID 单个 UniqID 或者 UniqID 数组 * @return void */ public function del() { if (Request::instance()->isPost() == false) { $this->error('非法请求'); } $params = Request::instance()->post(); if (empty($params['UniqID']) && empty($params['ids'])) { $this->error('参数错误'); } if (!empty($params['ids'])) { // 批量删除 $ids = is_array($params['ids']) ? $params['ids'] : explode(',', $params['ids']); $res = \db('db_客诉记录')->whereIn('UniqID', $ids)->delete(); } else { $res = \db('db_客诉记录')->where('UniqID', $params['UniqID'])->delete(); } if ($res === false) { $this->error('删除失败'); } $this->success('删除成功'); } // ===================================================== // 以下为处理环节记录 (db_客诉流程) 和 相关整改附件 (db_客诉附件) 接口 // ===================================================== /** * 获取处理环节记录列表 * @ApiMethod GET * @param int RelationID 关联主表 UniqID * @return void */ public function getFlowList() { if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); if (empty($params['RelationID'])) { $this->error('缺少 RelationID'); } $field = 'rtrim(RelationID) as RelationID,rtrim(操作者) as 操作者,rtrim(处理环节) as 处理环节,rtrim(备注说明) as 备注说明,sys_id,sys_rq,mod_rq,UniqId'; $list = \db('db_客诉流程') ->where('RelationID', intval($params['RelationID'])) ->field($field) ->order('UniqId asc') ->select(); $this->success('请求成功', $list ?: []); } /** * 新增处理环节记录 * @ApiMethod POST * @return void */ public function addFlow() { if (Request::instance()->isPost() == false) { $this->error('非法请求'); } $data = Request::instance()->post(); if (empty($data['RelationID'])) { $this->error('缺少 RelationID'); } // 自动生成 UniqId $maxId = \db('db_客诉流程')->max('UniqId'); $data['UniqId'] = $maxId ? $maxId + 1 : 1; $data['sys_rq'] = date('Y-m-d H:i:s'); $data['mod_rq'] = date('Y-m-d H:i:s'); $sql = \db('db_客诉流程')->fetchSql(true)->insert($data); $res = \db()->query($sql); if ($res === false) { $this->error('新增处理环节失败'); } $this->success('新增成功', ['UniqId' => $data['UniqId']]); } /** * 删除处理环节记录 * @ApiMethod POST * @param int UniqId * @return void */ public function delFlow() { if (Request::instance()->isPost() == false) { $this->error('非法请求'); } $params = Request::instance()->post(); if (empty($params['UniqId'])) { $this->error('缺少 UniqId'); } $res = \db('db_客诉流程')->where('UniqId', intval($params['UniqId']))->delete(); if ($res === false) { $this->error('删除失败'); } $this->success('删除成功'); } /** * 获取整改附件列表 * @ApiMethod GET * @param int relationId 关联主表 UniqID * @return void */ public function getAttachmentList() { if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); if (empty($params['relationId'])) { $this->error('缺少 relationId'); } $field = 'relationId,名称及路径,修订日期,附件类型,sys_id,sys_rq,mod_rq,UniqId'; $list = \db('db_客诉附件') ->where('relationId', intval($params['relationId'])) ->field($field) ->order('UniqId asc') ->select(); $this->success('请求成功', $list ?: []); } /** * 新增整改附件 * @ApiMethod POST (FormData) * @return void */ public function addAttachment() { if (Request::instance()->isPost() == false) { $this->error('非法请求'); } $data = Request::instance()->post(); if (empty($data['relationId'])) { $this->error('缺少 relationId'); } if (empty($data['名称及路径'])) { $this->error('缺少 名称及路径'); } // 自动生成 UniqId $maxId = \db('db_客诉附件')->max('UniqId'); $data['UniqId'] = $maxId ? $maxId + 1 : 1; $data['修订日期'] = date('Y-m-d H:i:s'); $data['sys_rq'] = date('Y-m-d H:i:s'); $data['mod_rq'] = date('Y-m-d H:i:s'); // 附件内容是 base64,直接存入 longblob if (!empty($data['附件内容'])) { // 去掉 data:xxx;base64, 前缀 if (preg_match('/^data:[^;]+;base64,(.*)$/', $data['附件内容'], $m)) { $data['附件内容'] = base64_decode($m[1]); } } $sql = \db('db_客诉附件')->fetchSql(true)->insert($data); $res = \db()->query($sql); if ($res === false) { $this->error('新增附件失败'); } $this->success('新增成功', ['UniqId' => $data['UniqId']]); } /** * 删除整改附件 * @ApiMethod POST * @param int UniqId * @return void */ public function delAttachment() { if (Request::instance()->isPost() == false) { $this->error('非法请求'); } $params = Request::instance()->post(); if (empty($params['UniqId'])) { $this->error('缺少 UniqId'); } $res = \db('db_客诉附件')->where('UniqId', intval($params['UniqId']))->delete(); if ($res === false) { $this->error('删除失败'); } $this->success('删除成功'); } }