瀏覽代碼

Merge branch 'master' of https://git.7in6.com/Minong/mes-server-api

曹鹤洋 1 年之前
父節點
當前提交
c647ec7d49

+ 54 - 0
application/api/controller/Custom.php

@@ -56,6 +56,7 @@ class Custom extends Api
         }else{
             $class = '供应商';
         }
+        $search = $params['search'];
         $limit = $params['limit'];
         if (empty($limit)){
             $limit = 15;
@@ -65,6 +66,9 @@ class Custom extends Api
             $pages = 1;
         }
         $where['类型'] = $class;
+        if (!empty($search)){
+            $where['编号|名称|地址|联系人|业务员'] = array('like','%'.$search.'%');
+        }
         $field = 'rtrim(编号) as 编号,rtrim(名称) as 名称,rtrim(简称) as 简称,rtrim(地址) as 地址,rtrim(联系人) as 联系人,rtrim(电话) as 电话,业务员,rtrim(币种) as 币种,rtrim(Sys_id) as Sys_id,Sys_rq,Mod_rq,UniqId';
         $list = Db::name('erp_客户供应商')->where($where)->field($field)->limit($limit)->page($pages)->select();
         $total = Db::name('erp_客户供应商')->where($where)->count();
@@ -72,4 +76,54 @@ class Custom extends Api
         $data['total'] = $total;
         $this->success('请求成功',$data);
     }
+    /**
+     * 供应商资料查改
+     *
+     * @ApiMethod POST
+     * @params array data
+    */
+    public function edit(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (empty($params) || !isset($params['UniqId'])){
+            $this->error('参数不能为空');
+        }
+        $data = [];
+        if (!empty($params['code'])){
+            $data['编号'] = $params['code'];
+        }
+        if (!empty($params['name'])){
+            $data['名称'] = $params['name'];
+        }
+        if (!empty($params['refer'])){
+            $data['简称'] = $params['refer'];
+        }
+        if (!empty($params['add'])){
+            $data['地址'] = $params['add'];
+        }
+        if (!empty($params['department_code'])){
+            $data['对口部门'] = $params['department_code'];
+        }
+        if (!empty($params['contacts'])){
+            $data['联系人'] = $params['contacts'];
+        }
+        if (!empty($params['phone'])){
+            $data['电话'] = $params['phone'];
+        }
+        if (!empty($params['salesman'])){
+            $data['业务员'] = $params['salesman'];
+        }
+        if (!empty($params['currency'])){
+            $data['币种'] = $params['currency'];
+        }
+        $sql = Db::name('erp_客户供应商')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
 }

+ 339 - 8
application/api/controller/Facility.php

@@ -39,12 +39,13 @@ class Facility extends Api
                 $machine = Db::table('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
                 foreach ($machine as $kk=>$vv){
                     if ($vv['设备编号'] !== 'ZH01#'){
-                        $date = Db::table('设备_产量计酬')->where('sczl_jtbh',$vv['设备编号'])->distinct(true)->order('UniqId desc')->limit(40)->column('sczl_rq');
+                        $date = Db::table('设备_产量计酬')->where('sczl_jtbh',$vv['设备编号'])->distinct(true)->cache(60)->order('UniqId desc')->limit(40)->column('sczl_rq');
                         $data[rtrim($value)][$vv['设备编号'].'【'.$vv['设备名称'].'】'] = $date;
                     }
                 }
             }
         }
+
         $this->success('成功',$data);
     }
 
@@ -64,11 +65,11 @@ class Facility extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
-        $machine = input('machine');
+        $machine = input('machine').'#';
         $date = input('date');
         $where = [
             'sczl_jtbh' => $machine,
-            'sczl_rq' => date('Y-m-d H:i:s',strtotime($date)),
+            'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
         ];
         $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
         rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
@@ -204,7 +205,16 @@ class Facility extends Api
         $this->success('成功',$list);
     }
 
-    //生产中工单信息
+    /**
+     * 设备生产中工单信息
+     * @ApiMethod (GET)
+     * @param string $machine   机台编号
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
     public function Production()
     {
         if ($this->request->isGet() === false){
@@ -214,12 +224,333 @@ class Facility extends Api
         if (empty($machine)){
             $this->error('参数错误');
         }
-        $nowTime = date('Y-m-d H:i:s',time());
+        $lastUniqid = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
+        $startUniqid = $lastUniqid['UniqId']-10000;
+        $workOrder = Db::table('设备_产量计酬')->where('sczl_jtbh',$machine)->where('UniqId','>',$startUniqid)->field('sczl_gdbh')->order('UniqId desc')->find();
+        if (empty($workOrder)){
+            $this->error('未找到正在生产工单');
+        }
         $where = [
             'Gy0_sbbh' => $machine,
-            'Gy0_sj1' => ['<',$nowTime],
-            'Gy0_sj2' => ['>',$nowTime],
+            'Gy0_gdbh' => $workOrder['sczl_gdbh']
         ];
-//        $field = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件编号,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Ass_gxmc) as add,'
+        $list = Db::table('工单_工艺资料')->where($where)->find();
+        if (empty($list)){
+            $this->error('未找到正在生产工单');
+        }
+        $facilityWhere = [
+            'sczl_jtbh'=>$machine,
+            'sczl_gdbh'=>$list['Gy0_gdbh']
+        ];
+        $facilityField = 'sczl_bh1,sczl_bh2,sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10';
+        $Ctaff = Db::table('设备_产量计酬')->where($facilityWhere)->where('UniqId','>',$startUniqid)->field($facilityField)->order('UniqId desc')->find();
+        $data = [];
+        foreach ($Ctaff as $key=>$value){
+            if (!empty($value)){
+                $staffName = Db::table('人事_基本资料')->where('员工编号',$value)->field('员工姓名,员工编号')->find();
+                $data[$key] = [
+                    '员工编号' => rtrim($staffName['员工编号']),
+                    '员工姓名' => rtrim($staffName['员工姓名']),
+                ];
+            }
+        }
+        if ($list['Gy0_yjno']<10){
+            $list['Gy0_yjno'] = '0'.$list['Gy0_yjno'];
+        }
+        if ($list['Gy0_gxh']<10){
+            $list['Gy0_gxh'] = '0'.$list['Gy0_gxh'];
+        }
+        $data['工单编号'] = rtrim($list['Gy0_gdbh']);
+        $data['印件编号'] = rtrim($list['Gy0_yjno']);
+        $data['工序名称'] = rtrim($list['Gy0_gxh']).'-'.rtrim($list['Gy0_gxmc']).'【'.rtrim($list['Add_gxmc']).'】';
+        $data['产品名称'] = Db::table('工单_基本资料')->where('Gd_gdbh',rtrim($list['Gy0_gdbh']))->field('rtrim(Gd_cpmc) as 产品名称')->find()['产品名称'];
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 设备工作清单
+     * @ApiMethod (GET)
+     * @param string $machine 机台编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function EquipmentWorklist()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        if (empty($machine)){
+            $this->error('参数错误');
+        }
+        $lastTechonUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
+        $startTechonUniqId = $lastTechonUniqId['UniqId']-10000;
+        $lastYieldUniqId = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
+        $startYieldUniqId = $lastYieldUniqId['UniqId']-10000;
+        $workOrder = Db::table('设备_产量计酬')->where('sczl_jtbh',$machine)->field('sczl_gdbh')->where('UniqId','>',$startYieldUniqId)->order('UniqId desc')->find();
+        $startTime = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder['sczl_gdbh'])->where('Gy0_sbbh',$machine)->where('UniqId','>',$startTechonUniqId)->field('Gy0_sj1')->order('UniqId desc')->find();
+        $where = [
+            'UniqId' => ['>',$startTechonUniqId],
+            'Gy0_sbbh' => $machine,
+            'Gy0_sj1' => ['>= time',$startTime['Gy0_sj1']],
+        ];
+        $field = 'rtrim(Gy0_gdbh) as gdbh,rtrim(质量要求) as 质量信息,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,
+        rtrim(Add_gxmc) as add_gxmc,rtrim(Gy0_辅助工时) as 装版时数,rtrim(Gy0_小时产能) as 工序产能,rtrim(Gy0_生产工时) as 计划工时,
+        rtrim(Gy0_sj1) as sj1,rtrim(Gy0_sj2) as sj2,rtrim(工序备注) as 排产备注';
+        $orderList = Db::table('工单_工艺资料')
+            ->where($where)
+            ->where('Gy0_sj1','<','2099-01-01 00:00:00')
+            ->field($field)
+            ->order('UniqId desc')
+            ->select();
+        foreach ($orderList as $key=>$value){
+            $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
+            $name = Db::table('工单_印件资料')->where(['Yj_Gdbh'=>$value['gdbh'],'yj_Yjno'=>$value['yjno']])->field('yj_yjmc')->find();
+            if ($value['yjno']<10){
+                $orderList[$key]['yjno'] = '0'.$value['yjno'];
+            }
+            if ($value['gxh']<10){
+                $orderList[$key]['gxh'] = '0'.$value['gxh'];
+            }
+            $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.rtrim($name['yj_yjmc']);
+            $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
+            $scheduled = Db::table('工单_基本资料')->where('Gd_gdbh',$value['gdbh'])->field('rtrim(计划投料) as 计划产量')->find();
+            $finished = Db::table('设备_产量计酬')
+                ->where('sczl_gdbh',$value['gdbh'])
+                ->where('sczl_jtbh',$machine)
+                ->where('UniqId','>',$startYieldUniqId)
+                ->order('UniqId desc')
+                ->field('SUM(sczl_cl) as cl')
+                ->select();
+            $orderList[$key]['计划产量/已完成'] = $scheduled['计划产量'].'/'.$finished[0]['cl']=null?'':(int)$finished[0]['cl'];
+            $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
+            $orderList[$key]['产品名称'] = rtrim($name['yj_yjmc']);
+            unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['yjno'],$orderList[$key]['gxh'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['sj1'],$orderList[$key]['sj2']);
+        }
+        $this->success('成功',$orderList);
+    }
+
+
+
+    /**
+     * 工序、印件、完成数量
+     * @ApiMethod (GET)
+     * @param string $workOrder  工单编号
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function Procedure()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('Gd_gdbh');
+        if (empty($workOrder)){
+            $this->error('参数错误');
+        }
+        $lastUniqid = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
+        $startUniqid = $lastUniqid['UniqId']-100000;
+        //右边工艺及完成数量
+        $Process = Db::table('设备_产量计酬')->where('sczl_gdbh',$workOrder)->where('UniqId','>',$startUniqid)->distinct(true)->order('sczl_gxh')->column('sczl_gxh');
+        $data = [];
+        foreach ($Process as $k=>$v){
+            $res= Db::table('设备_产量计酬')->where('sczl_gdbh',$workOrder)
+                ->where('UniqId','>',$startUniqid)
+                ->where('sczl_gxh',$v)
+                ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
+                ->find();
+            if ($res['sczl_yjno']<10){
+                $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
+            }
+            $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
+            $processList['completed'] = Db::table('设备_产量计酬')->where('sczl_gdbh',$workOrder)->where('UniqId','>',$startUniqid)->where('sczl_gxh',$v)->count();
+            array_push($data,$processList);
+        }
+        $this->success('成功',$data);
+    }
+
+    //
+
+    /**
+     * 班组人员及分配比例
+     * @ApiMethod (GET)
+     * @param string $machine 机台编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function Team()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        if (empty($machine)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'sczl_jtbh' => $machine,
+        ];
+        $field = 'rtrim(sczl_bzdh) as 班组号,rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
+        rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
+        rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
+        rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10';
+        $team = Db::table('设备_产量计酬')
+            ->where('sczl_jtbh',$machine)
+            ->field($field)
+            ->order('UniqId desc')
+            ->find();
+        $list = Db::table('设备_班组资料')->where($where)->field($field)->select();
+        $data = [];
+        foreach ($list as $k=>$v){
+            if ($team == $v){
+                $data[$k]['status'] = 1;
+            }else{
+                $data[$k]['status'] = 0;
+            }
+            $data[$k]['班组号'] = $v['班组号'];
+            for ($i=1;$i<11;$i++){
+                if ($v['bh'.$i] != ''){
+                    $name = Db::table('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
+                    $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
+                }
+            }
+        }
+        $this->success('成功',$data);
+    }
+
+    //当班产量明细
+
+    /**
+     * 当班产量明细
+     * @ApiMethod (GET)
+     * @param string $machine  机台编号
+     * @param string $workOrder  工单编号
+     * @param string $team   班次
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function OutputDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        $workOrder = input('Gd_gdbh');
+        $team = input('team');
+        if (empty($machine) || empty($workOrder) || empty($team)){
+            $this->error('参数错误');
+        }
+        $lastUniqid = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
+        $startUniqid = $lastUniqid['UniqId']-100000;
+        $name = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(Gd_cpmc) as productName')->find();
+        $where = [
+            'UniqId' => ['>',$startUniqid],
+            'sczl_gdbh' => $workOrder,
+            'sczl_jtbh' => $machine,
+            'sczl_cl' => ['<>',0.0],
+            'sczl_bzdh' => $team,
+        ];
+        $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
+        rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
+        rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
+        rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
+        rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2';
+        $list = Db::table('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
+        if (empty($list)){
+            $this->error('未找到生产记录');
+        }
+        foreach ($list as $k=>$v){
+            if ($v['yjno']<10){
+                $list[$k]['yjno'] = '0'.$v['yjno'];
+            }
+            $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
+            $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
+            $list[$k]['产品名称'] = $name['productName'];
+            unset($list[$k]['yjno'],$list[$k]['gxmc'],$list[$k]['sj1'],$list[$k]['sj2']);
+        }
+        $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
+        SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
+        SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
+        SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
+        $total = Db::table('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
+        $total[0]['版数'] = count($list);
+        $list['total'] = $total[0];
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 检验记录
+     * @ApiMethod (GET)
+     * @param string $machine  机台编号
+     * @param string $workOrder  工单编号
+     * @param string $team   班次
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function InspectionRecord()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求失败');
+        }
+        $machine = input('machine');
+        $workOrder = input('Gd_gdbh');
+        $team = input('team');
+        if (empty($machine) || empty($workOrder) || empty($team)){
+            $this->error('参数错误');
+        }
+        $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
+        $startId = $last_id['UniqId']-100000;
+        $where = [
+            '设备编号' => $machine,
+            '工单编号' => $workOrder,
+            '班组编号' => $team,
+            '类别' => ['in',['IPQC检验','机台检验']],
+            'UniqId' => ['>',$startId],
+        ];
+        //检验项目筛选
+        $item = Db::table('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
+        //检验时间
+        $InspectionTime = Db::table('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
+        foreach ($InspectionTime as $k=>$v){
+            $InspectionTime[$k] = date('H:i',strtotime($v));
+        }
+        //检测记录详情
+        $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
+        $nameDetail = Db::table('制程检验_记录')->where($where)->field($field)->find();
+        $data = [];
+        //检测数据
+        foreach ($item as $key=>$value){
+            $SubmissionTime = Db::table('制程检验_记录')->where($where)
+                ->where('检验项目',$value)
+                ->where('检验结果','合格')
+                ->field('rtrim(提交时间) as 提交时间')
+                ->select();
+            $time = [];
+            foreach ($SubmissionTime as $k=>$v){
+                $time[$k] = date('H:i',strtotime($v['提交时间']));
+            }
+            $data[$key] = [
+                '工单编号' => $nameDetail['工单编号'],
+                '印件号' => $nameDetail['印件号'],
+                '工序名称' => $nameDetail['工序名称'],
+                '检验项目' => $value,
+                'inspectresult' => implode(',',$time),
+            ];
+        }
+        $data['inspectiontime'] = $InspectionTime;
+        $this->success('成功',$data);
     }
 }

+ 57 - 0
application/api/controller/PieceWork.php

@@ -109,4 +109,61 @@ class PieceWork extends Api
 
 
     }
+    /**
+     * 获取日定额参数
+     * @ApiMethod POST
+     * @params string code
+     */
+    public function getPieceParams(){
+        if(!$this->request->isGet()){
+            $this->error('非法请求');
+        }
+        $req = $this->request->param();
+        if (!isset($req['code']) || empty($req['code'])){
+            $this->error('请求参数错误');
+        }
+        $where['sys_bh'] = array('like','%'.$req['code'].'%');
+        $field = 'rtrim(sys_bh) as sys_bh,rtrim(sys_mc) as sys_mc,rtrim(适用工序) as use_gx,rtrim(适用机型) as use_machine,日定额 as daily_quota,千件工价 as thousand_piece,
+        补产标准 as production_standard,UniqId';
+        $list = Db::name('dic_lzde')->where($where)->field($field)->select();
+        $this->success('请求成功',$list);
+    }
+    /**
+     * 批量修改定额参数
+     * @ApiMethod POST
+     * @params object data
+    */
+    public function editAllParams(){
+        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['daily_quota'])){
+                $data['日定额'] = $value['daily_quota'];
+            }
+            if (!empty($value['thousand_piece'])){
+                $data['千件工价'] = $value['thousand_piece'];
+            }
+            if (!empty($value['production_standard'])){
+                $data['补产标准'] = $value['production_standard'];
+            }
+
+            $sql = Db::name('dic_lzde')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
+            $res = Db::query($sql);
+            if ($res !== false){
+                $i++;
+            }
+        }
+        if ($i !== 0){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
 }

+ 135 - 2
application/api/controller/Process.php

@@ -24,7 +24,6 @@ class Process extends Api
     }
     /**
      * 单个工序损耗接口
-     *
      * @ApiMethod GET
      * @params string code
     */
@@ -44,7 +43,6 @@ class Process extends Api
     }
     /**
      * 获取工序损耗列表接口
-     *
      * @ApiParams GET
     */
     public function getProcess(){
@@ -87,4 +85,139 @@ class Process extends Api
         }
         $this->success('请求成功',$data);
     }
+    /**
+     * 获取工序损耗编码
+     * @ApiMethod GET
+     * @params string code
+     * @params string same_item
+     * @params string child_item
+    */
+    public function getProcessCode(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['code']) || !isset($params['same_item']) || !isset($params['child_item'])){
+            $this->error('参数错误');
+        }
+        $code = $params['code'];
+        if (empty($code)){//科目编码为空,表示需要增加一级科目
+           $res = Db::name('dic_lzsh')->where('Parent','0_')->field('rtrim(sys_bh) as sys_bh')->order('UniqId desc')->find();
+           $num = (int)$res['sys_bh'] + 1;
+           $new_code = $num > 10 ? '0'.$num : '00'.$num;
+           $this->success('请求成功',$new_code);
+        }else{
+            if (($params['same_item'] == 0 && $params['child_item'] == 0) || ($params['same_item'] == 1 && $params['child_item'] == 1) ){
+                $this->error('参数错误');
+            }
+            $res = Db::name('dic_lzsh')->where('sys_bh',$code)->find();
+            if ($params['same_item'] == 1){ //表示增加同级科目
+                $list = Db::name('dic_lzsh')->where('Parent',$res['Parent'])->field('rtrim(sys_bh) as sys_bh')->order('UniqId desc')->find();
+                $num = (int)$list['sys_bh'] + 1;
+                $num = substr($num,-3);
+                $str = substr($code,0,-3);
+                $new_code = $str . $num;
+                halt($new_code);
+            }else{
+                $list = Db::name('dic_lzsh')->where('Parent',$res['Key_'])->field('rtrim(sys_bh) as sys_bh')->order('UniqId desc')->find();
+                if (!empty($list)){
+                    $num = (int)$list['sys_bh'] + 1;
+                    $num = substr($num,-3);
+                    $new_code = $code . $num;
+                }else{
+                    $num = '001';
+                    $new_code = $code . $num;
+                }
+            }
+            $this->success('请求成功',$new_code);
+        }
+    }
+    /**
+     * 增加左侧科目
+     * @ApiMethod POST
+     * @params string code
+     * @params string name
+     * @params float  sys_rate0
+     * @params float  sys_rate1
+     * @params string  remark
+    */
+    public function add(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (empty($params) || !isset($params['code']) || !isset($params['name'])){
+            $this->error('参数不能为空');
+        }
+        $parentCode = $str = substr($params['code'],0,-3);
+        $list = Db::name('dic_lzsh')->where('sys_bh',$parentCode)->field('Key_')->find();
+        $data = [];
+        $data['sys_bh'] = $params['code'];
+        $data['Parent'] = $list['Key_'];
+        $data['sys_mc'] = $params['name'];
+        $data['sys_rate0'] = $params['sys_rate0'];
+        $data['sys_rate1'] = $params['sys_rate1'];
+        if (!empty($params['remark'])){
+            $data['适用机型'] = $params['remark'];
+        }
+        $sql = Db::name('dic_lzsh')->fetchSql(true)->insert($data);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('新增成功');
+        }else{
+            $this->error('新增失败');
+        }
+    }
+    /**
+     * 修改左侧科目
+     * @params string code
+     * @params string name
+     * @params float  sys_rate0
+     * @params float  sys_rate1
+     * @params string  remark
+    */
+    public function edit(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (empty($params) || !isset($params['code']) || !isset($params['name'])){
+            $this->error('参数不能为空');
+        }
+        $data = [];
+        $data['sys_mc'] = $params['name'];
+        $data['sys_rate0'] = $params['sys_rate0'];
+        $data['sys_rate1'] = $params['sys_rate1'];
+
+        if (!empty($params['remark'])){
+            $data['适用机型'] = $params['remark'];
+        }
+        $sql = Db::name('dic_lzsh')->where('sys_bh',$params['code'])->fetchSql(true)->update($data);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
+    /**
+     * 删除
+     * @ApiMethod POST
+     * @params string code
+    */
+    public function delete(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (empty($params) || !isset($params['code'])){
+            $this->error('参数不能为空');
+        }
+        $res = Db::name('dic_lzsh')->where('sys_bh',$params['code'])->delete();
+        if ($res !== false){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
 }

+ 4 - 2
application/api/controller/ProcessDocument.php

@@ -56,8 +56,10 @@ class ProcessDocument extends Api
                 $res['paper'][$k] ['产品版本号'] =  rtrim($v['产品版本号']);
                 $res['paper'][$k] ['bom_计划用量'] = intval($v['BOM_计划用量']);
             }
-            $where['_string'] = 'FIND_IN_SET('."'$product_number'".',product_number)';
-            $list = Db::connect('db2')->name('qr_history_peijian')->where($where)->field('id,peijian_name')->select();
+            $list = Db::connect('db2')->name('qr_history_peijian')
+                ->where('FIND_IN_SET(:product_number, product_number)')
+                ->bind(['product_number' => $product_number])
+                ->field('id,peijian_name')->select();
             $res['peijian'] = $list;
         }else{
             $res['paper'][0]['bom_物料名称'] = rtrim($info[0]['BOM_物料名称']);