liuhairui hace 3 semanas
padre
commit
1cf11a1316

+ 52 - 0
application/api/controller/PartLib.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use Monolog\Handler\IFTTTHandler;
+use Overtrue\Socialite\Providers\WeWorkProvider;
+use think\Db;
+use think\Request;
+use function fast\e;
+
+/**
+ *
+ * 产品部件库
+ */
+class PartLib extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    public function index(){
+        $this->success('产品_部件资料库');
+    }
+
+    /**
+     * 新增产品部件库
+     */
+    public function ParAdd(){
+
+    }
+
+    /**
+     * 获取产品部件库
+     */
+    public function ParList(){
+
+    }
+
+    /**
+     * 修改产品部件库
+     */
+    public function ParEdit(){
+
+    }
+
+    /**
+     * 删除产品部件库
+     */
+    public function ParDelete(){
+
+    }
+}

+ 169 - 0
application/api/controller/ProcessLib.php

@@ -0,0 +1,169 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use Monolog\Handler\IFTTTHandler;
+use Overtrue\Socialite\Providers\WeWorkProvider;
+use think\Db;
+use think\Request;
+use function fast\e;
+
+/**
+ * 产品_工艺库
+ */
+class ProcessLib extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    public function index(){
+        $this->success('产品_工艺资料库');
+    }
+
+    /**
+     * 新增产品工艺库
+     */
+    /**
+     * 新增产品工艺库
+     */
+    /**
+     * 新增产品工艺库
+     */
+    public function ProcessAdd(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+
+        $params = Request::instance()->param();
+
+        // 单条/多条统一处理
+        $insertData = [];
+        if (isset($params['gy_name'])) {
+            $insertData[] = $params;
+        } else {
+            $insertData = $params;
+        }
+
+        // ========== 自动生成 GX 编号 ==========
+        $lastCode = \db('产品_工艺库')->order('id desc')->whereNull('mod_rq')->value('gy_code');
+
+        if ($lastCode) {
+            $num = intval(str_replace('GX', '', $lastCode)) + 1;
+        } else {
+            $num = 1; // 空表从 1 开始
+        }
+
+        // 批量生成编号
+        foreach ($insertData as &$item) {
+            $item['gy_code'] = 'GX' . str_pad($num, 6, '0', STR_PAD_LEFT);
+            $item['status'] = 1;
+            $item['create_time'] = date('Y-m-d H:i:s');
+            $num++;
+        }
+
+//        echo "<pre>";
+//        print_r($insertData);
+//        echo "<pre>";die;
+        $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['工序编码|工序名称|生产工序'] = array('like','%'.$params['search'].'%');
+        }
+
+        $limit = $params['limit'];
+        if (empty($limit)){
+            $limit = 30;
+        }
+        $pages = $params['page'];
+        if (empty($pages)){
+            $pages = 1;
+        }
+        $list =  Db::name('产品_工艺库')->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('非法请求');
+        }
+
+        // 获取前端传参:必须带 id
+        $params = Request::instance()->param();
+
+        // 必传参数校验
+        if (empty($params['id'])) {
+            $this->error('请选择要修改的数据');
+        }
+
+        // 不允许修改的字段(如果不需要可以删掉)
+        unset($params['gy_code']);
+        unset($params['create_time']);
+
+        $params['updatetime'] = date('Y-m-d H:i:s');
+//        echo "<pre>";
+//        print_r($params);
+//        echo "<pre>";die;
+        // 执行更新
+        $result = \db('产品_工艺库')
+            ->where('id', $params['id'])
+            ->update($params);
+
+        if ($result !== false) {
+            $this->success('修改成功');
+        } else {
+            $this->error('修改失败');
+        }
+    }
+
+    /**
+     * 删除产品工艺库(软删除,修改mod_rq=1)
+     * 支持单条 / 多条删除,前端传 id 逗号分隔
+     */
+    public function ProcessDelete(){
+        if (!Request::instance()->isPost()) {
+            $this->error('非法请求');
+        }
+
+        $params = Request::instance()->param();
+
+        // 接收前端传的 id 字符串:1,2,3
+        $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('删除失败');
+        }
+    }
+
+}

+ 157 - 1069
application/api/controller/Product.php

@@ -9,7 +9,7 @@ use think\Cache;
 use function fast\e;
 
 /**
- * 产品管理接口
+ * 产品资料
  */
 class Product extends Api
 {
@@ -18,1143 +18,231 @@ class Product extends Api
 
     /**
      * 首页
-     *
      */
     public function index()
     {
-        $this->success('请求成功');
+        $this->success('产品_基本资料');
     }
-    /**
-     * 获取产品资料
-     *
-     * @ApiMethod GET
-     *@param string custom_code
-     *@param string limit
-     *@param string page
-    */
-    public function getProduct(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        $limit = $params['limit'];
-        $yjno = 10;
-        if (!isset($limit)){
-            $limit = 15;
-        }
-        if (!isset($params['page'])){
-            $pages = 0;
-        }else{
-            $pages = ((int)$params['page'] -1 ) * (int)$limit;
-        }
-        $total = 0;
-        if (isset($params['custom_code']) && !empty($params['custom_code'])){
-            $customCode  = $params['custom_code'];
-            $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
-                    rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
-                    FROM `产品_基本资料` WHERE `客户编号` = '{$customCode}' ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END, 
-                    `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
-            $total = db('产品_基本资料')->where('客户编号',$customCode)->count();
-        }else{
-            if (isset($params['search']) && !empty($params['search'])){
-                $search = $params['search'];
-                $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
-                    rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
-                    FROM `产品_基本资料` WHERE `产品名称` LIKE '%{$search}%' OR `产品编号` LIKE '%{$search}%' ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END, 
-                    `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
-                $total = db('产品_基本资料')->where('产品名称','like','%'.$search.'%')->count();
-            }else{
-                $sql = "SELECT rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,客户料号,rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,版本号,成品规格,
-                    rtrim(计量单位) as 计量单位,rtrim(产品类别) as 产品类别,生产类别,产品备注,投产日期,状态,U8UID,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqID
-                    FROM `产品_基本资料` ORDER BY CASE WHEN `状态` IS NULL THEN 0 ELSE 1 END, 
-                    `客户编号`ASC,`状态` ASC,`产品编号` DESC LIMIT {$limit} OFFSET {$pages}";
-                $total = db('产品_基本资料')->count();
-            }
-        }
-        $list = Db::query($sql);
-        foreach ($list as $key=>$value){
-            $code = trim($value['产品编号']);
-            $gd_sql = "SELECT `接单日期` FROM `工单_基本资料` WHERE `成品代号` = '{$code}' ORDER BY Uniqid DESC";
-            $gdRes = Db::query($gd_sql);
-            $list[$key]['receiveDate'] = '';
-            if (!empty($gdRes)){
-                $list[$key]['receiveDate']  = $gdRes[0]['接单日期'];
-            }
-            if (isset($params['sort'])){
-                $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}' AND Gy0_yjno >= '{$yjno}'";
-                $gyRes = Db::query($gy_sql);
-            }else{
-                $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}'";
-                $gyRes = Db::query($gy_sql);
-            }
-            $list[$key]['gyData'] = '';
-            if (empty($gyRes)){
-                $list[$key]['gyData'] = '缺';
-            }
-            if (isset($params['sort'])){
-                $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}' AND yj_yjno >= '{$yjno}'";
-                $yjRes = Db::query($yj_sql);
-            }else{
-                $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}'";
-                $yjRes = Db::query($yj_sql);
-            }
 
-            $list[$key]['yjData'] = '无';
-            if ($yjRes[0]['total'] > 0){
-                $list[$key]['yjData'] = $yjRes[0]['total'];
-            }
-        }
-        $data['data'] = $list;
-        $data['total'] = $total;
-        $this->success('请求成功',$data);
-    }
-    /**
-     * 获取产品基础数据
-     *
-     * @ApiMethod POST
-     *@param string product_code
-    */
-    public function getProductData(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        $code = $params['product_code'];
-        if (!isset($code)){
-            $this->error('参数不能为空');
-        }
-        if (isset($params['sort'])){
-            $PriWhere['yj_yjno'] = ['>=',10];
-            $proWhere['Gy0_yjno'] = ['>=',10];
-        }else{
-            $PriWhere['yj_yjno'] = ['<',10];
-            $proWhere['Gy0_yjno'] = ['<',10];
-        }
-        $num = config('product_code_digit');
-        //工艺资料
-        $option['a.Gy0_cpdh'] = $code;
-        $gy_field = 'rtrim(a.Gy0_方案) as 方案,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.gy0_gxmc) as gy0_gxmc,rtrim(a.Add_gxmc) as add_gxmc,a.Gy0_Ks,a.Gy0_ls,rtrim(a.工序备注) as 备注,
-        a.工价系数,a.损耗系数,a.Gy0_Ms,a.人工检_正品板,a.人工检_次品板,a.人工检_废检,a.机检_正品板,a.机检_次品板,a.机检_废检,rtrim(a.Gy0_sbmc) as Gy0_sbmc,rtrim(a.Sys_id) as Sys_id,
-        a.Sys_rq,a.Mod_rq,b.sys_rate0 as 基础损耗,b.sys_rate1 as 损耗率,a.UniqID';
-        $gyRes = db('产品_工艺资料')->alias('a')
-            ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
-            ->where($option)->where($proWhere)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
-        //印件资料
-        $where['yj_cpdh'] = $code;
-        $field = 'yj_yjno,rtrim(yj_yjdh) as yj_yjdh,yj_yjmc,rtrim(yj_zzdh) as yj_zzdh,rtrim(yj_zzmc) as yj_zzmc,rtrim(yj_tlgg) as yj_tlgg,
-        rtrim(yj_klgg) as yj_klgg,yj_ks,yj_ls,rtrim(yj_desc) as yj_desc,rtrim(sys_id) as sys_id,sys_rq,mod_rq,UniqId';
-        $yjRes = db('产品_印件资料')->where($where)->where($PriWhere)->field($field)->select();
-        //印版资料
-        $filter['a.YB_Cpdh'] = $code;
-        $yb_field = 'rtrim(a.YB_方案) as YB_方案,a.YB_Yjno,rtrim(a.存货编码) as 存货编码,a.考核印数,rtrim(a.Sys_id) as Sys_id,a.Mod_rq,rtrim(b.物料名称) as 印版名称,rtrim(c.名称) as 印版类别,a.UniqID';
-        $ybRes = db('产品_印版资料')->alias('a')
-            ->join('物料_存货编码 b','a.存货编码 = b.物料代码','left')
-            ->join('物料_存货结构 c','LEFT(a.存货编码,'.$num.') = c.编号','left')
-            ->where($filter)->field($yb_field)->order('a.YB_Yjno,a.存货编码')->select();
-        //技术附件
-        $jsRes = db('产品_技术附件')
-            ->where('关联产品','like','%'.$code.'%')
-            ->select();
-        foreach ($jsRes as $key=>&$value){
-            if(mb_detect_encoding($value['附件内容'])!='ASCII'){
-                $value['附件内容'] = '';
-            }
-        }
-        $list = [];
-        $list['yjData'] = $yjRes;
-        $list['gyData'] = $gyRes;
-        $list['ybData'] = $ybRes;
-        $list['jsData'] = $jsRes;
-        $this->success('请求成功',$list);
-    }
-    /**
-     * 4.获取单个工艺数据(排产参数调整)
-     *
-     * @ApiMethod GET
-     *@param string product_code
-    */
-    public function getProductGy(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        $code = $params['product_code'];
-        if (!isset($code)){
-            $this->error('参数不能为空');
-        }
-        $option['a.Gy0_cpdh'] = $code;
-        if (!empty($params['plan'])){
-            $option['a.Gy0_方案'] = $params['plan'];
-        }
-        $gy_field = 'rtrim(a.Gy0_方案) as programme,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.gy0_gxmc) as gy0_gxmc,a.A类产能 as A_power,rtrim(a.Gy0_shdh) as Gy0_shdh,rtrim(a.Gy0_sbbh) as Gy0_sbbh,
-        a.工价系数 as difficulty_coe,a.损耗系数 as loss_coe,a.Gy0_Ms as ms_coe,a.Gy0_Ks,a.Gy0_ls,rtrim(a.Gy0_site) as Gy0_site,rtrim(a.Add_gxmc) as Add_gxmc,a.UniqID,a.Gy0_辅助工时,
-        rtrim(a.工序备注) as remark,a.人工检_正品板 as artificial_zp,a.人工检_次品板 as artificial_cp,a.人工检_废检 as artificial_fj,a.机检_正品板 as machine_zp,a.机检_次品板 as machine_cp,
-        a.机检_废检 as machine_fj,rtrim(b.客户名称) as custom_name,rtrim(b.产品名称) as product_name,a.UniqId';
-        $gyRes = db('产品_工艺资料')->alias('a')
-            ->join('产品_基本资料 b','a.Gy0_cpdh = b.产品编号','left')
-            ->where($option)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
-        $this->success('请求成功',$gyRes);
-    }
-    /**
-     * 修改工艺参数
-     *
-     * @ApiMethod
-     * @params array data
-    */
-    public function editGy(){
-        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['A_power'])){
-                $data['A类产能'] = $value['A_power'];
-            }
-            if (!empty($value['shdh'])){
-                $data['Gy0_shdh'] = $value['shdh'];
-            }
-            if (!empty($value['machine'])){
-                $data['Gy0_sbbh'] = $value['machine'];
-            }
-            if (!empty($value['time'])){
-                $data['Gy0_辅助工时'] = $value['time'];
-            }
-            if (!empty($value['difficulty_coe'])){
-                $data['工价系数'] = $value['difficulty_coe'];
-            }
-            if (!empty($value['loss_coe'])){
-                $data['损耗系数'] = $value['loss_coe'];
-            }
-            if (!empty($value['ms_coe'])){
-                $data['Gy0_Ms'] = $value['ms_coe'];
-            }
-            $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
-            $res = Db::query($sql);
-            if ($res !== false){
-                $i++;
-            }
-        }
-        if ($i !== 0){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
-    /**
-     * 修改产品信息
-     *
-     * @ApiMethod POST
-     *
-     * @params object data
-    */
-    public function editProduct(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params)){
-            $this->error('参数不能为空');
-        }
-        if (!isset($params['印品代号'])){
-            $this->error('印品代号不能为空');
-        }
-        $code = $params['印品代号'];
-        unset($params['印品代号']);
-        $sql = db('产品_基本资料')->where('产品编号',$code)->fetchSql(true)->update($params);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
-    /**
-     * 设置产品状态
-     *
-     * @ApiMethod POST
-     * @params string status
-     * @params string code
-    */
-    public function setProductStatus(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['code']) || empty($params['status'])){
-            $this->error('参数不能为空');
-        }
-        $code = $params['code'];
-        $status = '';
-        if ($params['status'] == 2){
-            $status = '停产';
-        }
-        $sql = db('产品_基本资料')->where('产品编号',$code)->fetchSql(true)->setField('状态',$status);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
-    /**
-     * 获取产品工艺数量
-     *
-     * @ApiMethod GET
-     * @params string code
-    */
-    public function getGyTotal(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        $code = $params['code'];
-        if (!isset($code)){
-            $this->error('参数不能为空');
-        }
-        $res = db('产品_工艺资料')->where('Gy0_cpdh',$code)->distinct(true)->column('rtrim(Gy0_方案) as gy_plan');
-        $data['gy'] = $res;
-        $product = db('产品_基本资料')->where('产品编号',$code)->find();
-        $data['name'] = rtrim($product['产品名称']);
-        $this->success('请求成功',$data);
-    }
-    /**
-     * 复制产品工艺信息
-     *
-     * @ApiMethod POST
-     * @params string from_code
-     * @params string from_pro
-     * @params string to_code
-     * @params string to_pro
-     * @params int is_copy_gy
-    */
-    public function copyProductGy(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['from_code']) || empty($params['from_pro']) || empty($params['to_code']) ){
-            $this->error('参数不能为空');
-        }
-        if ($params['is_copy_gy'] == 1){
-            if (empty($params['to_pro'])){
-                $this->error('工艺方案不能为空');
-            }
-            //查出参考的工艺数据
-            $where['Gy0_cpdh'] = $params['from_code'];
-            $where['Gy0_方案'] = $params['from_pro'];
-            $gyList = db('产品_工艺资料')->where($where)->select();
-            if (empty($gyList)){
-                $this->error('参考产品无工艺资料数据');
-            }
-            $UniqID = db('产品_工艺资料')->order('UniqID desc')->value('UniqID');
-            foreach ($gyList as $key=>$value){
-                unset($gyList[$key]['UniqID']);
-                $UniqID ++;
-                $gyList[$key]['Gy0_方案'] = $params['to_pro'];
-                $gyList[$key]['Gy0_cpdh'] = $params['to_code'];
-                $gyList[$key]['UniqID'] = $UniqID;
-            }
-        }
-        if ($params['is_copy_yb'] == 1){
-            $UniqId = db('产品_印版资料')->order('UniqID desc')->value('UniqID');
-            $option['YB_Cpdh'] = $params['from_code'];
-            $ybList = db('产品_印版资料')->where($option)->select();
-            if (empty($ybList)){
-                $this->error('参考产品无印版资料数据');
-            }
-            foreach ($ybList as $key=>$value){
-                unset($ybList[$key]['UniqID']);
-                $UniqId++;
-                $ybList[$key]['YB_Cpdh'] = $params['to_code'];
-                $ybList[$key]['UniqID'] = $UniqId;
-            }
-        }
-        if ($params['is_copy_gy'] == 1 && $params['is_copy_yb'] == 1){
-            $gyResult = db('产品_工艺资料')->insertAll($gyList);
-            if (!$gyResult){
-                $this->error('复制产品工艺资料数据失败');
-            }
-            $ybResult = db('产品_印版资料')->insertAll($ybList);
-            if (!$ybResult){
-                $this->error('复制产品印版资料数据失败');
-            }
-        }elseif ($params['is_copy_gy'] == 1 && $params['is_copy_yb'] == 0){
-            $gyResult = db('产品_工艺资料')->insertAll($gyList);
-            if (!$gyResult){
-                $this->error('复制产品工艺资料数据失败');
-            }
-        }elseif ($params['is_copy_gy'] == 0 && $params['is_copy_yb'] == 1){
-            $ybResult = db('产品_印版资料')->insertAll($ybList);
-            if (!$ybResult){
-                $this->error('复制产品印版资料数据失败');
-            }
-        }else{
-            $this->success('工艺、印版至少选中一个');
-        }
-        $this->success('工艺复制成功');
-    }
-    /**
-     * 工艺方案更名
-     *
-     * @ApiMethod POST
-     * @params string code
-     * @params string name
-    */
-    public function editGyName(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params['code']) || empty($params['old_name']) || empty($params['new_name'])){
-            $this->error('参数不能为空');
-        }
-        $where['Gy0_cpdh'] = $params['code'];
-        $where['Gy0_方案'] = $params['old_name'];
-        $sql = db('产品_工艺资料')->where($where)->fetchSql(true)->setField('Gy0_方案',$params['new_name']);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
-    /**
-     * 工艺方案附加
-     *
-     * @ApiMethod POST
-     * @params object data
-    */
-    public function editGyNo(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params) || !isset($params[0]['UniqID'])){
-            $this->error('参数不能为空');
-        }
-        $i = 0;
-        foreach ($params as $key=>$value){
-            $data = [];
-            if (!empty($value['Gy0_yjno'])){
-                $data['Gy0_yjno'] = $value['Gy0_yjno'];
-            }
-            if (!empty($value['Gy0_gxh'])){
-                $data['Gy0_gxh'] = $value['Gy0_gxh'];
-            }
-            if (!empty($value['Gy0_Ks'])){
-                $data['Gy0_Ks'] = $value['Gy0_Ks'];
-            }
-            if (!empty($value['Gy0_ls'])){
-                $data['Gy0_ls'] = $value['Gy0_ls'];
-            }
-            $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
-            $res = Db::query($sql);
-            if ($res !== false){
-                $i++;
-            }
-        }
-        if ($i !== 0){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
     /**
-     * 计损色数修正
-     *
-     * @ApiMethod POST
-     * @params object data
-    */
-    public function editGyMs(){
-        if (Request::instance()->isPost() == false){
+     * 新增产品资料
+     */
+    public function ProductAdd()
+    {
+        if (!Request::instance()->isPost()) {
             $this->error('非法请求');
         }
-        $params = Request::instance()->post();
-        if (empty($params) || !isset($params[0]['UniqID'])){
-            $this->error('参数不能为空');
-        }
-        $i = 0;
-        foreach ($params as $key=>$value){
-            $data = [];
-            if (!empty($value['Gy0_Ms'])){
-                $data['Gy0_Ms'] = $value['Gy0_Ms'];
-            }
-            if (!empty($value['Gy0_Ks'])){
-                $data['Gy0_Ks'] = $value['Gy0_Ks'];
-            }
-            if (!empty($value['Gy0_ls'])){
-                $data['Gy0_ls'] = $value['Gy0_ls'];
-            }
-            $data['Add_gxmc'] = $value['Add_gxmc'];
-            $data['工序备注'] = $value['remark'];
 
-            $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
-            $res = Db::query($sql);
-            if ($res !== false){
-                $i++;
-            }
-        }
-        if ($i !== 0){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
-    /**
-     * 产品质检废品系数调整
-     *
-     * @ApiMethod POST
-     * @params object data
-    */
-    public function editGyWaste(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params) || !isset($params[0]['UniqID'])){
-            $this->error('参数不能为空');
-        }
-        $i = 0;
-        foreach ($params as $key=>$value){
-            $data = [];
-            if (!empty($value['artificial_zp'])){
-                $data['人工检_正品板'] = $value['artificial_zp'];
-            }
-            if (!empty($value['artificial_cp'])){
-                $data['人工检_次品板'] = $value['artificial_cp'];
-            }
-            if (!empty($value['artificial_fj'])){
-                $data['人工检_废检'] = $value['artificial_fj'];
-            }
-            if (!empty($value['machine_zp'])){
-                $data['机检_正品板'] = $value['machine_zp'];
-            }
-            if (!empty($value['machine_cp'])){
-                $data['机检_次品板'] = $value['machine_cp'];
-            }
-            if (!empty($value['machine_fj'])){
-                $data['机检_废检'] = $value['machine_fj'];
-            }
-            $sql = db('产品_工艺资料')->where('UniqID',$value['UniqID'])->fetchSql(true)->update($data);
-            $res = Db::query($sql);
-            if ($res !== false){
-                $i++;
-            }
-        }
-        if ($i !== 0){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
-    /**
-     * 获取产品印件资料
-     * @ApiMethod GET
-     * @params string UniqId
-    */
-    public function getProductYjInfo(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
         $params = Request::instance()->param();
-        if (empty($params['UniqId']) || empty($params['UniqId'])){
-            $this->error('参数错误');
-        }
-        $field = "yj_yjno,rtrim(yj_yjdh) as yj_yjdh,rtrim(yj_yjmc) as yj_yjmc,rtrim(yj_zzdh) as yj_zzdh,rtrim(yj_zzmc) as yj_zzmc,rtrim(yj_zzdh1) as yj_zzdh1,rtrim(yj_zzdh2) as yj_zzdh2,
-        rtrim(yj_zzdh3) as yj_zzdh3,rtrim(yj_zzdh4) as yj_zzdh4,rtrim(yj_zzmc1) as yj_zzmc1,rtrim(yj_zzmc2) as yj_zzmc2,rtrim(yj_zzmc3) as yj_zzmc3,
-        rtrim(yj_zzmc4) as yj_zzmc4,rtrim(yj_tlgg) as yj_tlgg,rtrim(yj_klgg) as yj_klgg,yj_ks,yj_ls,KgToPages,rtrim(yj_desc) as yj_desc,UniqId";
-        $list = \db('产品_印件资料')->where('UniqId',$params['UniqId'])->field($field)->select();
-        $this->success('请求成功',$list);
-    }
-    /**
-     * 修改产品印件资料
-     * @ApiMethod POST
-     * @params array data
-    */
-    public function editProductYjInfo(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params) || !isset($params['UniqId'])){
-            $this->error('参数不能为空');
-        }
-        $UniqId = $params['UniqId'];
-        unset($params['UniqId']);
-        $res = \db('产品_印件资料')->where('UniqId',$UniqId)->update($params);
-        if ($res !== false){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
-    /**
-     * 新增产品印件资料
-     * @ApiMethod POST
-     * @params array data
-    */
-    public function addProductYjInfo(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        $UniqId = \db('产品_印件资料')->order('UniqId desc')->value('UniqId');
-        if ($UniqId < 2000000){
-            $UniqId = 2000000;
-        }else{
-            $UniqId = $UniqId + 1;
-        }
-        $params['UniqId'] = $UniqId;
-        $params['sys_rq'] = date('Y-m-d H:i:s');
-        $res = \db('产品_印件资料')->insert($params);
-        if ($res !== false){
+
+        // 自动生成产品编号: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{
+        } else {
             $this->error('新增失败');
         }
     }
+
     /**
-     * 获取印件代码及名称
-     * @ApiMethod GET
-     *
-    */
-    public function getProductYjList(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->get();
-        $search = $params['search'];
-        $num = config('product_code_digit');
-        if (!empty($search)){
-            $sql = "SELECT DISTINCT rtrim(a.`物料代码`) AS `物料代码`,rtrim(a.`物料名称`) AS `物料名称`,rtrim(b.`客户编号`) AS `客户编号`,rtrim(b.`客户名称`) AS `客户名称` FROM
-                    `物料_存货编码` a
-                    JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
-                    WHERE  (a.`物料名称` LIKE '%{$search}%' or a.物料代码 LIKE '%{$search}%') 
-                    ORDER BY a.`物料代码` ASC";
-        }else{
-            $sql = "SELECT DISTINCT rtrim(a.`物料代码`) as `物料代码`, rtrim(a.`物料名称`) as `物料名称`,rtrim(b.客户编号) as 客户编号,rtrim(b.客户名称) as 客户名称
-                FROM `物料_存货编码` a
-                JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
-               
-                ORDER BY a.`物料代码` ASC";
-        }
-        $data = Db::query($sql);
-        // 初始化一个关联数组,用于存储相同客户编号的数据
-        $groupedData = [];
-        foreach ($data as $row) {
-            $customerCode = substr($row['物料代码'],0,$num).substr($row['客户编号'],2,2).'/'.$row['客户名称'];
-            $materialCodePrefix = substr($row['物料代码'], 0, $num);
-            if ($materialCodePrefix == 'Y1401' ){
-                $materialCodePrefix = $materialCodePrefix.'/糊盒类产品(含贴码)';
-            }else{
-                $materialCodePrefix = $materialCodePrefix.'/直接领用产品';
-            }
-            // 如果关联数组中不存在该物料代码前四位的键,则创建一个空数组
-            if (!isset($groupedData[$materialCodePrefix])) {
-                $groupedData[$materialCodePrefix] = [];
-            }
-            // 如果物料代码前四位数组中不存在该客户编号的键,则创建一个空数组
-            if (!isset($groupedData[$materialCodePrefix][$customerCode])) {
-                $groupedData[$materialCodePrefix][$customerCode] = [];
-            }
-            // 去除客户编号和客户名称
-            unset($row['客户编号']);
-            unset($row['客户名称']);
-            // 将当前行的数据添加到相应的物料代码前四位和客户编号的数组中
-            $groupedData[$materialCodePrefix][$customerCode][] = $row;
-        }
-        $this->success('请求成功',$groupedData);
-    }
-    /**
-     * 获取纸张代号及名称
-     * @ApiMethod GET
-     * @params string search
-    */
-    public function getProductZzList(){
+     * 获取左侧菜单产品分类列表
+     * 按 product_type 分组 → 分类下显示对应产品
+     */
+    public function ProductTypeMenu()
+    {
         if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
-        $params = Request::instance()->get();
-        $search = $params['search'];
-        $num = config('product_code_digit');
-        if (!empty($search)){
-            $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
-                rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
-                FROM `物料_存货编码` a
-                LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
-                LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
-                LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
-                WHERE (a.物料名称 LIKE '%{$search}%' or a.物料代码 LIKE '%{$search}%') and 
-                  (a.物料代码 LIKE 'Y00%' or a.物料代码 LIKE 'Y01%' or a.物料代码 LIKE 'Y04%' or a.物料代码 LIKE 'J03%' or a.物料代码 LIKE 'Y14%')";
-            $data = Db::query($sql);
-        }else{
-            $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
-                rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
-                FROM `物料_存货编码` a
-                LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
-                LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
-                LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
-                WHERE a.物料代码 LIKE 'Y00%' or a.物料代码 LIKE 'Y01%' or a.物料代码 LIKE 'Y04%' or a.物料代码 LIKE 'J03%' or a.物料代码 LIKE 'Y14%'";
-            $data = Db::query($sql);
-        }
-        $mergedArray = [];
-        foreach ($data as $item) {
-            $oneCode = $item['oneCode'];
-            $twoCode = $item['twoCode'];
-            $thrCode = $item['thrCode'];
-            $oneName = $item['oneName'];
-            $twoName = $item['twoName'];
-            $thrName = $item['thrName'];
-            // Create a unique key using the combination of oneCode, twoCode, and thrCode
-            $oneKey = "{$oneCode}/{$oneName}";
-            $twoKey = "{$twoCode}/{$twoName}";
-            $thrKey = "{$thrCode}/{$thrName}";
-            // Initialize arrays if not already set
-            if (!isset($mergedArray[$oneKey])) {
-                $mergedArray[$oneKey] = [];
-            }
-            if (!isset($mergedArray[$oneKey][$twoKey])) {
-                $mergedArray[$oneKey][$twoKey] = [];
+        $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']
+                ];
             }
-            // Append items to the arrays
-            $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
         }
-        $this->success('请求成功',$mergedArray);
+
+        // 转成索引数组返回
+        $result = array_values($data);
+
+        $this->success('获取成功', $result);
     }
+
     /**
-     *3.6工艺资料-获取产品工艺资料
-    */
-    public function getProductGyInfo(){
+     * 获取产品资料列表
+     */
+    public function ProductList()
+    {
         if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
         $params = Request::instance()->param();
-        if (empty($params['UniqID']) || empty($params['UniqID'])){
-            $this->error('参数错误');
-        }
-        $field = "rtrim(a.Gy0_方案) as Gy0_方案,a.Gy0_yjno,a.Gy0_gxh,a.Gy0_Ks,a.Gy0_ls,rtrim(a.Gy0_site) as Gy0_site,rtrim(a.gy0_gxmc) as gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_Ms,
-                  rtrim(a.Gy0_sbbh) as Gy0_sbbh,rtrim(a.Gy0_shdh) as Gy0_shdh,rtrim(b.sys_mc) as sys_mc,b.sys_rate0,b.sys_rate1,a.工价系数,a.损耗系数,rtrim(a.工序备注) as 工序备注,
-                  rtrim(a.质量要求) as 质量要求,rtrim(a.质量隐患) as 质量隐患,a.UniqID";
-        $data = \db('产品_工艺资料')->alias('a')
-            ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
-            ->where('a.UniqID',$params['UniqID'])
-            ->field($field)
-            ->find();
-        $this->success('请求成功',$data);
-    }
-    /**
-     * 3.7工艺资料-获取车间及工艺名称
-     * @ApiMethod GET
-     *
-    */
-    public function getDepartName(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $param = $this->request->param();
-        $data = \db('erp_常用字典')->where('分类','印刷工艺')->order('编号 asc')->column('名称');
 
-        $resultArray = [];
-        foreach ($data as $item) {
-            $parts = explode('_', $item);
-            // 使用第一个部分作为一级键,第二个部分作为二级键
-            $firstKey = $parts[0];
-            $secondKey = $parts[1];
-            $thirdValue = $parts[2];
+        $where = [];
 
-            $resultArray[$firstKey][$secondKey][] = $thirdValue;
-        }
-        if (isset($param['sort'])){
-            $result['标准工艺']['智能车间'] = $resultArray['标准工艺']['智能车间'];
-        }else{
-            unset($resultArray['标准工艺']['智能车间']);
-            $result = $resultArray;
-        }
-        $this->success('请求成功',$result);
-    }
-    /**
-     * 3.8工艺资料-新增产品工艺
-    */
-    public function addProductGyInfo(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
+        if (!empty($params['search'])){
+            $where['product_code|product_name|product_type'] = array('like','%'.$params['search'].'%');
         }
-        $params = Request::instance()->post();
-        $UniqId = \db('产品_工艺资料')->order('UniqID desc')->value('UniqID');
-        if ($UniqId < 2000000){
-            $UniqId = 2000000;
-        }else{
-            $UniqId = $UniqId + 1;
+        $limit = $params['limit'];
+        if (empty($limit)){
+            $limit = 30;
         }
-        $params['UniqID'] = $UniqId;
-        $params['Sys_rq'] = date('Y-m-d H:i:s');
-        $sql = \db('产品_工艺资料')->fetchSql(true)->insert($params);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('新增成功');
-        }else{
-            $this->error('新增失败');
+        $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]);
     }
+
     /**
-     * 3.9印版资料-获取产品印版资料
-     * @ApiMethod GET
-    */
-    public function getProductYbInfo(){
-        if (Request::instance()->isGet() == false){
+     * 修改产品资料
+     */
+    public function ProductEdit()
+    {
+        if (!Request::instance()->isPost()) {
             $this->error('非法请求');
         }
+
         $params = Request::instance()->param();
-        if (empty($params['UniqID']) || empty($params['UniqID'])){
-            $this->error('参数错误');
-        }
-        $field = "rtrim(a.YB_方案) as YB_方案,a.YB_Yjno,a.YB_gxh,rtrim(a.存货编码) as 存货编码,rtrim(a.印版名称) as 印版名称,a.UniqID,rtrim(b.gy0_gxmc) as gy0_gxmc,
-                rtrim(b.Add_gxmc) as Add_gxmc,rtrim(c.物料名称) as 物料名称,rtrim(a.YB_cpdh) as YB_cpdh";
-        $data = \db('产品_印版资料')->alias('a')
-            ->join('产品_工艺资料 b','a.YB_cpdh = b.Gy0_cpdh and a.YB_Yjno = b.Gy0_yjno and a.YB_gxh = b.Gy0_gxh','left')
-            ->join('物料_存货编码 c','a.存货编码 = c.物料代码','left')
-            ->where('a.UniqID',$params['UniqID'])->field($field)->order('存货编码')->find();
-        if (empty($data)){
-            $this->error('未查询到产品印版资料');
-        }
-        $where['Gy0_site'] = [
-            ['like','胶印%'],
-            ['like','烫模%'],
-            'or'
-        ];
-        $option['Gy0_cpdh'] = $data['YB_cpdh'];
-        $option['Gy0_gxh'] = ['<',10];
-        $option['Gy0_sbbh'] = ['neq',''];
-        $gyData = \db('产品_工艺资料')->where($option)->where($where)
-            ->field('rtrim(Gy0_方案) as Gy0_方案,Gy0_yjno,Gy0_gxh,rtrim(gy0_gxmc) as gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')
-            ->order('Gy0_yjno,Gy0_gxh')->select();
-        $list = [];
-        foreach ($gyData as $key=>$value){
-            $yjno = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
-            $gxh =  $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
-            $list[$key]['gy'] = $value['Gy0_方案'].'-->'.$yjno.'-'.$gxh.' '.$value['gy0_gxmc'];
-            $list[$key]['gxmc'] = $value['Add_gxmc'];
-        }
-        $data['gy_data'] = $list;
-        $this->success('请求成功',$data);
-    }
-    /**
-     * 3.10印版资料-修改产品印版资料
-     * @ApiMethod POST
-     * @params string UniqId
-    */
-    public function editProductYbInfo(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        if (empty($params) || !isset($params['UniqId'])){
-            $this->error('参数不能为空');
-        }
-        $UniqId = $params['UniqId'];
-        unset($params['UniqId']);
-        $sql = \db('产品_印版资料')->where('UniqId',$UniqId)->fetchSql(true)->update($params);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('更新成功');
-        }else{
-            $this->error('更新失败');
-        }
-    }
-    /**
-     * 印版资料-获取物料名称
-     * @ApiMethod GET
-     *
-    */
-    public function getProductYbMaterialList(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $sql = "SELECT rtrim(`编号`) as 编号, rtrim(`名称`) as 名称 FROM `物料_存货结构` WHERE `编号` IN ('0502','0503','0510','0511','0512','0513','0514','0520','0521','0523','0524','0525')";
-        $data = Db::query($sql);
-        $this->success('请求成功',$data);
-    }
-    /**
-     *3.12印版资料-获取详细存货名称
-     * @ApiMethod GET
-     * @params string code
-    */
-    public function getProductYbMaterialDetail(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->get();
-        if (empty($params) || !isset($params['code'])){
-            $this->error('参数不能为空');
-        }
-        $code = $params['code'];
-        $search = $params['search'];
-        $num = config('product_code_digit');
-        if (!empty($search)){
-            $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
-                rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
-                FROM `物料_存货编码` a
-                LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
-                LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
-                WHERE  a.物料代码 LIKE '{$code}%' AND a.物料名称 LIKE '%{$search}%'";
-        }else{
-            $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,
-                rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
-                FROM `物料_存货编码` a
-                LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
-                LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
-                WHERE  a.物料代码 LIKE '{$code}%'";
-        }
-        $data = Db::query($sql);
-        $mergedArray = [];
-        foreach ($data as $item) {
-            $oneCode = '05';
-            $twoCode = $item['twoCode'];
-            $thrCode = $item['thrCode'];
-            $oneName = '版材';
-            $twoName = $item['twoName'];
-            $thrName = $item['thrName'];
-            $oneKey = "{$oneCode}/{$oneName}";
-            $twoKey = "{$twoCode}/{$twoName}";
-            $thrKey = "{$thrCode}/{$thrName}";
-            if (!isset($mergedArray[$oneKey])) {
-                $mergedArray[$oneKey] = [];
-            }
-            if (!isset($mergedArray[$oneKey][$twoKey])) {
-                $mergedArray[$oneKey][$twoKey] = [];
-            }
-            $mergedArray[$oneKey][$twoKey][$thrKey][] = $item;
-        }
-        $this->success('请求成功',$mergedArray);
-    }
-    /**
-     * 3.13印版资料-新增产品印版资料
-     * @ApiMethod POST
-     * @params array data
-    */
-    public function addProductYbInfo(){
-        if (Request::instance()->isPost() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->post();
-        $UniqId = \db('产品_印版资料')->order('UniqID desc')->value('UniqID');
-        if ($UniqId < 2000000){
-            $UniqId = 2000000;
-        }else{
-            $UniqId = $UniqId + 1;
-        }
-        $params['UniqID'] = $UniqId;
-        $params['考核印数'] = '0.00';
-        $params['Sys_rq'] = date('Y-m-d H:i:s');
-        $sql = \db('产品_印版资料')->fetchSql(true)->insert($params);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('新增成功');
-        }else{
-            $this->error('新增失败');
-        }
-    }
-    /**
-     * 3.14工艺资料-获取损耗代号
-     * @ApiMethod GET
-     * @params code
-    */
-    public function getLossCode(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->get();
-        if (empty($params) || !isset($params['code'])){
-            $this->error('参数不能为空');
+
+        if (empty($params['id'])) {
+            $this->error('请选择数据');
         }
 
-        $code = $params['code'];
-        $where['sys_bh|sys_mc'] = array('like','%'.$code.'%');
-        $data = \db('dic_lzsh')
-                ->where($where)
-            ->field('rtrim(sys_bh) as sys_bh, rtrim(sys_mc) as sys_mc,sys_rate0,sys_rate1')
-            ->select();
-        $this->success('请求成功',$data);
+        // 禁止修改编号
+        unset($params['product_code']);
+
+        $result = \db('产品_基本资料')
+            ->where('id', $params['id'])
+            ->update($params);
+
+        if ($result !== false) {
+            $this->success('修改成功');
+        } else {
+            $this->error('修改失败');
+        }
     }
 
     /**
-     * 产品工艺资料删除
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\exception\PDOException
+     * 删除产品资料(软删除)
      */
-    public function ProcessDetailDel()
+    public function ProductDelete()
     {
-        if ($this->request->isGet() === false) {
-            $this->error('请求错误');
+        if (!Request::instance()->isPost()) {
+            $this->error('非法请求');
         }
-        $param = $this->request->param();
-        if (isset($param['UniqId']) === false) {
-            $this->error('参数错误');
+
+        $id = input('id');
+        if (empty($id)) {
+            $this->error('请选择需要删除的数据');
         }
-        $printId = explode(',', $param['UniqId']);
-        $res = \db('产品_工艺资料')->where('UniqID','in',$printId)->delete();
-        if ($res){
+
+        $ids = explode(',', $id);
+
+        $result = \db('产品_基本资料')
+            ->where('id', 'in', $ids)
+            ->update(['mod_rq' => 1]);
+
+        if ($result !== false) {
             $this->success('删除成功');
-        }else{
+        } else {
             $this->error('删除失败');
         }
     }
 
     /**
-     * 产品印件资料删除
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\exception\PDOException
+     * 获取产品工艺列表
      */
-    public function PrintDetailDel()
+    public function ProductGyList()
     {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        $param = $this->request->param();
-        if (isset($param['UniqId']) === false){
-            $this->error('参数错误');
-        }
-        $printId = explode(',',$param['UniqId']);
-        $res = \db('产品_印件资料')->where('UniqID','in',$printId)->delete();
-        if ($res){
-            $this->success('删除成功');
-        }else{
-            $this->error('删除失败');
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
         }
+        $params = Request::instance()->param();
 
-    }
-    /**
-     * 新增产品
-     * @ApiMethod POST
-     *
-    */
-   public function addProduct(){
-       if (Request::instance()->isPost() == false){
-           $this->error('非法请求');
-       }
-       $params = Request::instance()->post();
-       if (empty($params)){
-           $this->error('参数不能为空');
-       }
-       $uniqId = \db('产品_基本资料')->order('UniqID desc')->value('UniqID');
-       if (empty($uniqId)){
-           $params['UniqID'] = 1;
-       }else{
-           $params['UniqID'] = $uniqId + 1;
-       }
-       $params['Sys_rq'] = date('Y-m-d H:i:s');
-       $sql = \db('产品_基本资料')->fetchSql(true)->insert($params);
-       $res = Db::query($sql);
-       if ($res !== false){
-           $this->success('新增成功');
-       }else{
-           $this->error('新增失败');
-       }
-   }
+        $where = [];
 
-    /**
-     * 产品资料删除
-     * @return void
-     * @throws \think\exception\PDOException
-     */
-    public function ProductDel()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
+        if (!empty($params['search'])){
+            $where['gy_name'] = array('like','%'.$params['search'].'%');
         }
-        $param = $this->request->param();
-        if (isset($param['UniqId']) === false){
-            $this->error('参数错误');
+        if (!empty($params['product_code'])){
+            $where['product_code'] = $params['product_code'];
         }
-        $WorkOrderId = explode(',',$param['UniqId']);
-        $i = 0;
-        foreach ($WorkOrderId as $key=>$value){
-            //获取产品编号
-            $product = \db('产品_基本资料')
-                ->where('UniqID',$value)
-                ->value('rtrim(产品编号)');
-            //删除工单资料、工艺资料、印件资料
-            \db()->startTrans();
-            try {
-                \db('产品_基本资料')->where('UniqID',$value)->delete();
-                if (!empty(\db('产品_工艺资料')->where('Gy0_cpdh',$product)->find())){
-                    \db('产品_工艺资料')->where('Gy0_cpdh',$product)->delete();
-                }
-                if (!empty(\db('产品_印件资料')->where('yj_cpdh',$product)->find())){
-                    \db('产品_印件资料')->where('yj_cpdh',$product)->delete();
-                }
-                \db()->commit();
-            }catch (\Exception $e){
-                \db()->rollback();
-                $i++;
-            }
+        $limit = $params['limit'];
+        if (empty($limit)){
+            $limit = 30;
         }
-        if ($i === 0){
-            $this->success('删除成功');
-        }else{
-            $this->error('删除失败');
+        $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]);
+
     }
 
     /**
-     * 修改产品工艺资料
-     * @ApiMethod POST
-     *
+     * 获取产品部件列表
      */
-    public function productEdit(){
-        if (Request::instance()->isPost() == false){
+    public function ProductPartList()
+    {
+        if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
-        $params = Request::instance()->post();
-        if (empty($params)){
-            $this->error('参数不能为空');
+        $params = Request::instance()->param();
+
+        $where = [];
+
+        if (!empty($params['search'])){
+            $where['part_name'] = array('like','%'.$params['search'].'%');
         }
-        $UniqId = $params['UniqID'];
-        unset($params['UniqID']);
-        $params['Mod_rq'] = date('Y-m-d H:i:s');
-        $sql = \db('产品_工艺资料')->where('UniqID',$UniqId)->fetchSql(true)->update($params);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('修改成功');
-        }else{
-            $this->error('修改失败');
+        if (!empty($params['product_code'])){
+            $where['product_code'] = array('like','%'.$params['product_code'].'%');
         }
-    }
-
-    /**
-     * 获取联数
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function getCouplet()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
+        $limit = $params['limit'];
+        if (empty($limit)){
+            $limit = 30;
         }
-        $param = $this->request->param();
-        if (empty($param['product']) || empty($param['yjno'])){
-            $this->error('参数错误');
+        $pages = $params['page'];
+        if (empty($pages)){
+            $pages = 1;
         }
-        $list = \db('产品_印件资料')
-            ->where('yj_cpdh',$param['product'])
-            ->where('yj_yjno',$param['yjno'])
-            ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
-            ->find();
-        $process = \db('产品_工艺资料')
-            ->where('Gy0_cpdh',$param['product'])
-            ->where('Gy0_yjno',$param['yjno'])
-            ->order('Gy0_gxh desc')
-            ->value('Gy0_gxh');
-        $list['工序号'] = $process + 1;
-        $this->success('成功',$list);
+        $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]);
     }
+
+
 }

+ 132 - 182
application/api/controller/Staff.php

@@ -12,25 +12,65 @@ class Staff extends Api
 {
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
-
     /**
      * 首页
-     *
      */
     public function index()
     {
-        $this->success('请求成功');
+        $this->success('员工资料接口');
     }
+
+    /**
+     * 获取部门列表
+     */
+    public function getDepartment(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+
+        // 1. 查询所有有效人员(按部门+工序分组)
+        $list = db('人员_基本资料')
+            ->field('所在部门, 生产工序, COUNT(*) AS count')
+            ->whereNull('mod_rq')
+            ->group('所在部门, 生产工序')
+            ->order('id asc')
+            ->select();
+
+        // 2. 构建 部门 → 工序 二级结构
+        $tree = [];
+        foreach ($list as $item) {
+            $dept = $item['所在部门'];
+            $process = $item['生产工序'];
+            $count = $item['count'];
+
+            // 初始化部门
+            if (!isset($tree[$dept])) {
+                $tree[$dept] = [
+                    'label' => $dept,
+                    'count' => 0,
+                    'children' => []
+                ];
+            }
+
+            // 总数量累加
+            $tree[$dept]['count'] += $count;
+
+            // 有生产工序 → 加入二级
+            if (!empty($process)) {
+                $tree[$dept]['children'][] = [
+                    'label' => $process,
+                    'count' => $count
+                ];
+            }
+        }
+
+        // 转成索引数组返回
+        $result = array_values($tree);
+        $this->success('获取部门数据', $result);
+    }
+
     /**
      * 获取员工列表信息
-     *
-     * @ApiMethod (GET)
-     * @param string department_code
-     * @param string mes_online
-     * @param string u8_online
-     * @param string limit
-     * @param string page
-     *
     */
     public function getStaffList(){
         if (Request::instance()->isGet() == false){
@@ -38,15 +78,14 @@ class Staff extends Api
         }
         $params = Request::instance()->param();
         $where = [];
-        $where['在职状态'] = '在职';
-        if (isset($params['mes_online'])){
-            $where['在职状态'] = $params['mes_online'] > 1 ? '离职':'在职';
+
+        if (!empty($params['search'])){
+            $where['员工编号|员工姓名'] = array('like','%'.$params['search'].'%');
         }
-        $where['U8在职'] = '在职';
-        if (isset($params['u8_online'])){
-            $where['U8在职'] = $params['u8_online'] > 1 ? '离职':'在职';
+        if (!empty($params['department_code'])) {
+            $where['所在部门|生产工序'] = $params['department_code'];
         }
-        $where['员工编号|员工姓名'] = array('like','%'.$params['search'].'%');
+
         $limit = $params['limit'];
         if (empty($limit)){
             $limit = 15;
@@ -55,76 +94,15 @@ class Staff extends Api
         if (empty($pages)){
             $pages = 1;
         }
-
-        $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(部门编码) as 部门编码,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期,
-        rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq';
-        if (strlen($params['department_code']) > 1){
-            $list = db('人事_基本资料')->where($where)->where('部门编码',$params['department_code'])->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
-            $total = db('人事_基本资料')->where($where)->where('部门编码',$params['department_code'])->count();
-        }else if (strlen($params['department_code']) == 1){
-            $list = db('人事_基本资料')->where($where)->where('LEFT(部门编码,1)='.$params['department_code'])->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
-            $total = db('人事_基本资料')->where($where)->where('LEFT(部门编码,1)='.$params['department_code'])->count();
-        }else{
-            $list = db('人事_基本资料')->where($where)->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
-            $total = db('人事_基本资料')->where($where)->count();
-        }
+        $list = db('人员_基本资料')->where($where)->page($pages)->limit($limit)->order('id asc')->whereNull('mod_rq')->select();
+        $total = db('人员_基本资料')->where($where)->whereNull('mod_rq')->count();
         $data['list'] = $list;
         $data['total'] = $total;
-        $this->success('请求成功',$data);
-    }
-    /**
-     * 获取部门列表
-     *
-     * @ApiMethod (GET)
-     *
-    */
-    public function getDepartment(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $sql = "select rtrim(编号) as 编号,rtrim(名称) as 名称 from 人事_组织结构 where  状态 = '' order by 编号 asc  ";
-        $list = Db::query($sql);
-        $data = [];
-        foreach ($list as $key => $value){
-            $number = $value['编号'];
-            if (strlen($number) ==  2 ){//一级菜单
-                $sql = "select count(*) as total from 人事_基本资料 where LEFT(部门编码,2)='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
-                $res = Db::query($sql);
-                $value['num'] = $res[0]['total'];
-                $list[$key] = $value;
-                $data[$number] = $value;
-            }else { //二级菜单
-                $sql = "select count(*) as total from 人事_基本资料 where 部门编码='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
-                $res = Db::query($sql);
-                $value['num'] = $res[0]['total'];
-                $list[$key] = $value;
-            }
-        }
-        $six = db('人事_基本资料')->where('在职状态','在职')->where('U8在职','离职')->count();
-        $sixArr['编号'] = '';
-        $sixArr['名称'] = '离职工资结算中';
-        $sixArr['total'] = $six;
-        $sev = db('人事_基本资料')->where('在职状态','离职')->where('U8在职','离职')->count();
-        $sevArr['编号'] = '';
-        $sevArr['名称'] = '离职清单';
-        $sevArr['total'] = $sev;
-        array_push($data,$sixArr,$sevArr);
-        foreach ($data as $k=>$v){
-            $i = 0;
-            $data[$k]['children'] = [];
-            foreach ($list as $item){
-                $num = $item['编号'];
-                if (strlen($num) >= 4 && substr($num,0,2) == $k){
-                    if ($item['num'] > 0){
-                        $data[$k]['children'][$i] = $item;
-                        $i++;
-                    }
-                }
-            }
-        }
-        $data = array_values($data);
-        $this->success('请求成功',$data);
+        $this->success('获取员工列表信息',$data);
     }
+
+
+
     /**
      * 获取员工资料
      * @ApiMethod GET
@@ -134,33 +112,61 @@ class Staff extends Api
         if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
+
         $params = Request::instance()->param();
         $where = [];
-        if (isset($params['code'])){
-            $where['员工编号'] = $params['code'] ;
+        if (isset($params['id'])){
+            $where['a.id'] = $params['id'];
+        }
+
+        // 1. 查询人员基础信息
+        $staffList = db('人员_基本资料')->alias('a')
+            ->where($where)
+            ->whereNull('a.mod_rq')
+            ->select();
+
+        // 2. 循环给每个人绑定 工序列表
+        foreach ($staffList as &$item) {
+            // 查询该人员的所有绑定工序
+            $processList = db('人员_工序绑定关联')
+                ->where('user_id', $item['id'])
+                ->whereNull('mod_rq')
+                ->column('工序ID,工序名称,工序编码,生产工序');
+            // 把工序放进当前人员信息里
+            $item['process_list'] = $processList;
+        }
+        $this->success('获取员工资料', $staffList);
+    }
+
+    /**
+     * 新增员工资料
+     */
+    public function PostStaffAdd(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
         }
-        $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(部门编码) as 部门编码,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期,
-        rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq';
-        $data = db('人事_基本资料')->where($where)->field($field)->find();
-        $this->success('请求成功',$data);
+        $params = Request::instance()->param();
+        echo "<pre>";
+        print_r($params);
+        echo "<pre>";die;
     }
+
+
     /**
      * 修改员工资料
-     *
      * @ApiMethod POST
      *
     */
-    public function edit(){
+    public function PostStaffEdit(){
         if (Request::instance()->isPost() == false){
             $this->error('非法请求');
         }
         $params = Request::instance()->param();
-        if (empty($params['员工编号'])){
+        if (empty($params['id'])){
             $this->error('参数不能为空');
         }
-        $staffCode = $params['员工编号'];
-        unset($params['员工编号']);
-        $sql = db('人事_基本资料')->where('员工编号',$staffCode)->fetchSql(true)->update($params);
+        $staffCode = $params['id'];
+        $sql = db('人员_基本资料')->where('员工编号',$staffCode)->fetchSql(true)->whereNull('mod_rq')->update($params);
         $res = Db::query($sql);
         if ($res !== false){
             $this->success('更新成功');
@@ -170,97 +176,41 @@ class Staff extends Api
     }
 
     /**
-     * 员工法定天数修改
-     * @return void
-     * @throws \think\Exception
-     * @throws \think\db\exception\BindParamException
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     * @throws \think\exception\PDOException
+     * 删除员工资料
      */
-    public function clockUpdate()
+    public function delete()
     {
-        if (Request::instance()->isPost() === false){
+        if (Request::instance()->isPost() == false){
             $this->error('非法请求');
         }
-        $params = Request::instance()->post();
-        if (empty($params['month']) || empty($params['number'])){
-            $this->error('参数错误');
-        }
-        $staffList = \db('人事_基本资料')
-            ->field('rtrim(员工编号) as 员工编号,rtrim(班次类型) as 班次类型')
-            ->where('在职状态','在职')
-            ->select();
-        $status = \db('人事_考勤资料')->where('kqzl_ny',$params['month'])->count();
-        $data = [];
-        foreach ($staffList as $key => $value){
-            if ($value['班次类型'] === 'A类(双休班)'){
-                $hours = $params['typeA'];
-            }elseif ($value['班次类型'] === 'B类(7.5小时班)'){
-                $hours = $params['typeB'];
-            }else{
-                $hours = $params['typeC'];
-            }
-            $data[$key] =[
-                'kqzl_ygbh' => $value['员工编号'],
-                'kqzl_ny' => $params['month'],
-                '法定天数' => $params['number'],
-                '不计定额天数' => 0,
-                '法定工时' => $hours,
-                '非考勤天数' => 0,
-                '非考勤工时' => 0,
-                '工作日出勤天数' => 0,
-                '工作日出勤标准工时' => 0,
-                '工作日出勤总工时' => 0,
-                '可享法定假小时数' => 0,
-                '有薪假工时' => 0,
-                '延时加班' => 0,
-                '双休加班天数' => 0,
-                '双休加班' => 0,
-                '法定假加班' => 0,
-                '夜班次数' => 0,
-                '调休类加班' => 0,
-                '调休' => 0,
-                '病假工时' => 0,
-                '工伤工时' => 0,
-                'X_旷工工时' => 0,
-                'sys_id' => $params['sys_id'],
-                'sys_rq' => date('Y-m-d H:i:s',time()),
-                'mod_rq' => '1900-01-01 00:00:00',
-            ];
+        $params = Request::instance()->param();
+        if (empty($params['id'])){
+            $this->error('参数不能为空');
         }
-        $lastId = \db('人事_考勤资料')->order('UniqId desc')->value('UniqId');
-        if ($status === 0){
-            foreach ($data as $key=>$value){
-                $data[$key]['UniqId'] = $lastId + $key + 1;
-            }
-            $sql = \db('人事_考勤资料')->fetchSql(true)->insertAll($data);
-            $res = \db()->query($sql);
-            if ($res !== false){
-                $this->success('成功');
-            }else{
-                $this->error('失败');
-            }
+        $staffCode = $params['id'];
+        $sql = db('人员_基本资料')->where('id',$staffCode)->fetchSql(true)->update(['mod_rq'=>date('Y-m-d H:i:s')]);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('删除成功');
         }else{
-            $i = 0;
-            foreach ($data as $key=>$value){
-                $value['mod_rq'] = date('Y-m-d H:i:s',time());
-                $sql = \db('人事_考勤资料')
-                    ->where('kqzl_ygbh',$value['kqzl_ygbh'])
-                    ->where('kqzl_ny',$value['kqzl_ny'])
-                    ->fetchSql(true)
-                    ->update($value);
-                $res = \db()->query($sql);
-                if ($res === false){
-                    $i++;
-                }
-            }
-            if ($i === 0){
-                $this->success('成功');
-            }else{
-                $this->error('失败');
-            }
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 获取设备编组
+     */
+    public function GetDeviceNameList(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
         }
+        $list = Db::name('设备_基本资料')
+            ->field('设备编组,生产工序,工序')
+            ->where('设备名称','1')
+            ->whereNull('mod_rq')
+            ->group('设备编组')
+            ->order('工序,UniqId asc')
+            ->select();
+        $this->success('获取设备编组成功', $list);
     }
 }