success('产品_工艺资料库'); } /** * 新增产品工艺库(批量新增) */ public function ProcessAdd() { if (!Request::instance()->isPost()) { $this->error('非法请求'); } $params = Request::instance()->param(); // 接收前端传的 列表 + 操作人 $sys_id = $params['sys_id']; $process_list = $params['process_list']; // 校验数据 if (empty($process_list)) { $this->error('请传入工艺数据'); } // ========== 自动生成 GY 编号 ========== $lastCode = db('产品_工艺库') ->order('id desc') ->whereNull('mod_rq') ->value('gy_code'); if ($lastCode) { $num = intval(str_replace('GY', '', $lastCode)) + 1; } else { $num = 1; } // ========== 组装批量插入数据 ========== $insertData = []; foreach ($process_list as $item) { // 过滤空数据 if (empty($item['gy_name'])) continue; $insertData[] = [ 'gy_code' => 'GY' . str_pad($num, 6, '0', STR_PAD_LEFT), 'gy_name' => $item['gy_name'], 'big_process' => $item['big_process'], 'standard_hour' => $item['standard_hour'], 'standard_score' => $item['standard_score'], 'status' => 1, 'sys_id' => $sys_id, 'createtime' => date('Y-m-d H:i:s') ]; $num++; } if (empty($insertData)) { $this->error('无有效数据'); } $result = db('产品_工艺库')->insertAll($insertData); return $result ? $this->success('新增成功') : $this->error('新增失败'); } /** * 获取产品工艺库 */ public function ProcessList(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $where = []; if (!empty($params['search'])){ $where['gy_code|gy_name|big_process'] = array('like','%'.$params['search'].'%'); } if (!empty($params['code'])){ $where['big_process'] = array('like','%'.$params['code'].'%'); } $limit = $params['limit']; if (empty($limit)){ $limit = 30; } $pages = $params['page']; if (empty($pages)){ $pages = 1; } $list = Db::name('产品_工艺库') ->field(' id, gy_code, gy_name, big_process, standard_hour, standard_score, sys_id, createtime as 创建时间, updatetime as 修改时间 ') ->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->order('id desc')->select(); $total = Db::name('产品_工艺库')->whereNull('mod_rq')->where($where)->count(); $data['list'] = $list; $data['total'] = $total; $this->success('获取成功',$data); } /** * 修改产品工艺库 */ public function ProcessEdit(){ if (!Request::instance()->isPost()) { $this->error('非法请求'); } $params = Request::instance()->param(); if (empty($params['id'])) { $this->error('请选择要修改的数据'); } if (empty($params['gy_name'])) { $this->error('工序名称不能为空'); } //修改数据 $data = [ 'gy_name' => $params['gy_name'], 'big_process' => $params['big_process'], 'standard_hour' => $params['standard_hour'], 'standard_score' => $params['standard_score'], 'sys_id' => $params['sys_id'], 'updatetime' => date('Y-m-d H:i:s') ]; $result = db('产品_工艺库') ->where('id', $params['id']) ->whereNull('mod_rq') ->update($data); if ($result !== false) { $this->success('修改成功'); } else { $this->error('修改失败'); } } /** * 删除产品工艺库 */ public function ProcessDelete(){ if (!Request::instance()->isPost()) { $this->error('非法请求'); } $params = Request::instance()->param(); $ids = $params['id'] ?? ''; if (empty($ids)) { $this->error('请选择需要删除的数据'); } // 转成数组 $idArray = explode(',', $ids); $result = \db('产品_工艺库') ->where('id', 'in', $idArray) ->update(['mod_rq' => date('Y-m-d H:i:s')]); if ($result !== false) { $this->success('删除成功'); } else { $this->error('删除失败'); } } }