success('产品_基本资料'); } /** * 产品资料 */ /** * 新增产品资料 */ public function ProductAdd() { if (!Request::instance()->isPost()) { $this->error('非法请求'); } $params = Request::instance()->param(); // 自动生成产品编号:CP000001 $lastCode = \db('产品_基本资料')->order('id desc')->value('product_code'); if ($lastCode) { $num = intval(str_replace('CP', '', $lastCode)) + 1; } else { $num = 1; } $params['product_code'] = 'CP' . str_pad($num, 6, '0', STR_PAD_LEFT); $params['Sys_id'] = session('admin_id'); // 或写死 admin $params['Sys_rq'] = date('Y-m-d H:i:s'); $params['mod_rq'] = 0; $result = \db('产品_基本资料')->insert($params); if ($result) { $this->success('新增成功'); } else { $this->error('新增失败'); } } /** * 获取左侧菜单产品分类列表 * 按 product_type 分组 → 分类下显示对应产品 */ public function ProductTypeMenu() { if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); // 获取所有产品 $productList = \db('产品_基本资料')->whereNull('mod_rq') ->column('id,product_code,product_name,product_type'); $data = []; if ($productList) { foreach ($productList as $item) { $type = $item['product_type'] ?: '未分类'; // 分类 $data[$type]['name'] = $type; // 分类下的产品 $data[$type]['list'][] = [ 'id' => $item['id'], 'product_code' => $item['product_code'], 'product_name' => $item['product_name'] ]; } } // 转成索引数组返回 $result = array_values($data); $this->success('获取成功', $result); } /** * 获取产品资料列表 */ public function ProductList() { if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $where = []; if (!empty($params['search'])){ $where['product_code|product_name|product_type'] = array('like','%'.$params['search'].'%'); } $limit = $params['limit']; if (empty($limit)){ $limit = 30; } $pages = $params['page']; if (empty($pages)){ $pages = 1; } $list = \db('产品_基本资料')->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->order('id desc')->select(); $count = \db('产品_基本资料')->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->count(); $this->success('获取成功', ['list' => $list, 'count' => $count]); } /** * 修改产品资料 */ public function ProductEdit() { if (!Request::instance()->isPost()) { $this->error('非法请求'); } $params = Request::instance()->param(); if (empty($params['id'])) { $this->error('请选择数据'); } // 禁止修改编号 unset($params['product_code']); $result = \db('产品_基本资料') ->where('id', $params['id']) ->update($params); if ($result !== false) { $this->success('修改成功'); } else { $this->error('修改失败'); } } /** * 删除产品资料(软删除) */ public function ProductDelete() { if (!Request::instance()->isPost()) { $this->error('非法请求'); } $id = input('id'); if (empty($id)) { $this->error('请选择需要删除的数据'); } $ids = explode(',', $id); $result = \db('产品_基本资料') ->where('id', 'in', $ids) ->update(['mod_rq' => 1]); if ($result !== false) { $this->success('删除成功'); } else { $this->error('删除失败'); } } /** * 获取产品部件列表 */ public function ProductPartList() { if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $where = []; if (!empty($params['search'])){ $where['part_name'] = array('like','%'.$params['search'].'%'); } if (!empty($params['product_code'])){ $where['product_code'] = array('like','%'.$params['product_code'].'%'); } $limit = $params['limit']; if (empty($limit)){ $limit = 30; } $pages = $params['page']; if (empty($pages)){ $pages = 1; } $list = \db('产品_部件资料')->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->order('id desc')->select(); $count = \db('产品_部件资料')->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->count(); $this->success('获取成功', ['list' => $list, 'count' => $count]); } /** * 获取产品工艺列表 */ public function ProductGyList() { if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $where = []; if (!empty($params['search'])){ $where['gy_name'] = array('like','%'.$params['search'].'%'); } if (!empty($params['product_code'])){ $where['product_code'] = $params['product_code']; } $limit = $params['limit']; if (empty($limit)){ $limit = 30; } $pages = $params['page']; if (empty($pages)){ $pages = 1; } $list = \db('产品_工艺资料')->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->order('id desc')->select(); $count = \db('产品_工艺资料')->whereNull('mod_rq')->where($where)->page($pages)->limit($limit)->count(); $this->success('获取成功', ['list' => $list, 'count' => $count]); } }