success('请求成功'); } /** * 获取其他常用字典 * @ApiMethod GET * */ public function getTab(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $list = db('erp_常用字典')->order('编号 asc')->column('trim(名称) as name'); // 分割字符串并合并相同项 $resultArray = []; foreach ($list as $item) { $parts = explode('_', $item); // 使用第一个部分作为一级键,第二个部分作为二级键 $firstKey = $parts[0]; $secondKey = $parts[1]; $thirdValue = $parts[2]; $resultArray[$firstKey][$secondKey][] = $thirdValue; } // 对废品分类下的数组进行升序排序 if (isset($resultArray['data']['废品分类'])) { foreach ($resultArray['data']['废品分类'] as &$category) { // 判断是关联数组(单凹等)还是索引数组(分切等) if (is_array($category) && !empty($category) && is_array(current($category))) { foreach ($category as &$subCategory) { ksort($subCategory); } } else { ksort($category); } } } $this->success('请求成功',$resultArray); } /** * 常用字典维护界面列表 * @ApiParams GET * @params string class * @params string search */ public function getEditList(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (empty($params['class'])){ $this->error('参数错误'); } $where = []; $where['分类'] = $params['class']; if (!empty($params['search'])){ $where['名称'] = array('like','%'.$params['search'].'%'); } $list = db('erp_常用字典')->where($where)->order('次序 desc,UniqId asc')->select(); $this->success('请求成功',$list); } /** * 常用字典维护修改 * @ApiMethod POST * @params string UniqId */ public function edit(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $params = Request::instance()->post(); if (!isset($params) || !isset($params[0]['UniqID'])){ $this->error('参数不能为空'); } $i = 0; foreach ($params as $key=>$value){ $data = []; if (!empty($value['编号'])){ $data['编号'] = $value['编号']; } if (!empty($value['名称'])){ $data['名称'] = $value['名称']; } if (!empty($value['状态'])){ $data['禁用状态'] = 1; }else{ $data['禁用状态'] = 0; } if (!empty($value['次序'])){ $data['次序'] = $value['次序']; } $sql = db('erp_常用字典')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data); $res = Db::query($sql); if ($res !== false){ $i++; } } if ($i !== 0){ $this->success('更新成功'); }else{ $this->error('更新失败'); } } }