Bladeren bron

接口开发及优化

huangsanjia 1 jaar geleden
bovenliggende
commit
876a1eddca

+ 1 - 1
application/api/controller/Machine.php

@@ -29,7 +29,7 @@ class Machine extends Api
      *@params string department
     */
     public function getMachineInfo(){
-        if (Request::instance()->isPost() == false){
+        if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
         $params = Request::instance()->param();

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

@@ -0,0 +1,110 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use \think\Request;
+use \think\Db;
+/**
+ * 计件定额管理接口
+ */
+class PieceWork extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 首页
+     *
+     */
+    public function index()
+    {
+        $this->success('请求成功');
+    }
+    /**
+     * 获取单个计件定额
+     *
+     * @ApiMethod POST
+     * @params string code
+    */
+    public function getOnePieceWork(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        $code = $params['code'];
+        if (!isset($code)){
+            $this->error('参数不能为空');
+        }
+        $where['sys_bh'] = $code;
+        $field = 'rtrim(sys_bh) as sys_bh,rtrim(sys_mc) as sys_mc,rtrim(适用工序) as 适用工序,rtrim(适用机型) as 适用机型,
+                    日定额,千件工价,补产标准,机长比例,副机比例,调墨比例,二手比例,飞达比例,辅助比例,放卷比例,分切1比例,分切2比例,检验比例';
+        $data = Db::name('dic_lzde')->where($where)->field($field)->select();
+        $this->success('请求成功',$data);
+
+    }
+    /**
+     * 获取计件定额列表
+     *
+     * @ApiMethod GET
+     *
+    */
+    public function getPieceWork(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $field = 'Key_,Parent,rtrim(sys_bh) as sys_bh, rtrim(sys_mc) as sys_mc,rtrim(适用工序) as 适用工序,rtrim(适用机型) as 适用机型';
+        $list = Db::name('dic_lzde')->field($field)->order('sys_bh')->select();
+        $data = [];
+        $machineData = [];
+        $handData = [];
+        foreach ($list as $key=>$value){
+            if (substr($value['sys_bh'],0,3) == '020' && $value['Parent'] == '1_'){//机器作业计件定额
+                $machineData[$key] = $value;
+            }
+            if (substr($value['sys_bh'],0,3) == '030' && $value['Parent'] == '196_'){//人工作业计件定额
+                $handData[$key] = $value;
+            }
+        }
+
+        //对机器作业计件定额的数组进行处理
+        $machineData = array_values($machineData);
+        foreach ($machineData as $k=>$v){
+            $child = Db::name('dic_lzde')->where('Parent',$v['Key_'])->field($field)->select();
+            if (!empty($child)){
+                $machineData[$k]['child'] = $child;
+                foreach ($child as $i=>$j){
+                    if ($v['sys_mc'] == '检验车间'){ //找出检验车间机器下面的数据
+                        $children = Db::name('dic_lzde')->where('Parent',$j['Key_'])->field($field)->select();
+                        $machineData[$k]['child'][$i]['children'] = $children;
+                    } else{
+                        $machineData[$k]['child'][$i]['children'] = [];
+                    }
+                }
+            }
+        }
+        $data['machineData'] = $machineData;
+        //对手工作业计件定额的数组进行处理
+        $handData = array_values($handData);
+        foreach ($handData as $k=>$v){
+            $child = Db::name('dic_lzde')->where('Parent',$v['Key_'])->field($field)->select();
+            if (!empty($child)){
+                $handData[$k]['child'] = $child;
+                foreach ($child as $i=>$j){
+                    $children = Db::name('dic_lzde')->where('Parent',$j['Key_'])->field($field)->select();
+                    if (!empty($children)){
+                        $handData[$k]['child'][$i]['children'] = $children;
+                    } else{
+                        $handData[$k]['child'][$i]['children'] = [];
+                    }
+                }
+            }else{
+                $handData[$k]['child'] = [];
+            }
+        }
+        $data['handData'] = $handData;
+        $this->success('请求成功',$data);
+
+
+    }
+}

+ 90 - 0
application/api/controller/Process.php

@@ -0,0 +1,90 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use \think\Request;
+use \think\Db;
+
+/**
+ * 工序损耗管理接口
+ */
+class Process extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 首页
+     *
+     */
+    public function index()
+    {
+        $this->success('请求成功');
+    }
+    /**
+     * 单个工序损耗接口
+     *
+     * @ApiMethod POST
+     * @params string gy
+    */
+    public function getProcessLoss(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        $code = $params['code'];
+        if (!isset($code)){
+            $this->error('参数不能为空');
+        }
+        $where['sys_bh'] = $code;
+        $field = 'rtrim(sys_bh) as sys_bh,rtrim(sys_mc) as sys_mc,sys_rate0,sys_rate1,rtrim(适用机型) as 备注(机型)';
+        $data = Db::name('dic_lzsh')->where($where)->field($field)->select();
+        $this->success('请求成功',$data);
+    }
+    /**
+     * 获取工序损耗列表接口
+     *
+     * @ApiParams GET
+    */
+    public function getProcess(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $field = 'Key_,Parent,rtrim(sys_bh) as sys_bh,rtrim(sys_mc) as sys_mc';
+        $list = Db::name('dic_lzsh')->field($field)->select();
+        $data = [];
+        $i = 0;
+        foreach ($list as $value){
+            if ($value['Parent'] == '0_'){
+                $data[$i] = $value;
+                //一级菜单
+                $data[$i]['child'] = Db::name('dic_lzsh')->where('Parent',$value['Key_'])->field($field)->select();
+                foreach ($data[$i]['child'] as $k=>$v){
+                    $children = Db::name('dic_lzsh')->where('Parent',$v['Key_'])->field($field)->select();
+                    //二级菜单
+                    $data[$i]['child'][$k]['children'] =  $children;
+                    if (!empty($children)){
+                        foreach ($children as $key=>$item){
+                            $childrens = Db::name('dic_lzsh')->where('Parent',$item['Key_'])->field($field)->select();
+                            //三级菜单
+                            $data[$i]['child'][$k]['children'][$key]['childrens'] =  $childrens;
+                            if (!empty($childrens)){
+                                foreach ($childrens as $k1=>$v1){
+                                    $fiveChild = Db::name('dic_lzsh')->where('Parent',$v1['Key_'])->field($field)->select();
+                                    $data[$i]['child'][$k]['children'][$key]['childrens'][$k1]['fiveChild'] =  $fiveChild;
+                                }
+                            }else{
+                                $data[$i]['child'][$k]['children'][$key]['childrens'] = [];
+                            }
+                        }
+                    }else{
+                        $data[$i]['child'][$k]['children']= [];
+                    }
+                }
+                $i++;
+            }
+        }
+        $this->success('请求成功',$data);
+    }
+}

+ 1 - 1
application/api/controller/Product.php

@@ -106,7 +106,7 @@ class Product extends Api
         $yjRes = Db::name('产品_印件资料')->where($where)->field($field)->select();
         //印版资料
         $filter['a.YB_Cpdh'] = $code;
-        $yb_field = 'a.YB_方案,a.YB_Yjno,a.存货编码,a.考核印数,a.Sys_id,a.Mod_rq,b.物料名称 as 印版名称';
+        $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 印版名称';
         $ybRes = Db::name('产品_印版资料')->alias('a')
             ->join('物料_存货编码 b','a.存货编码 = b.物料代码')
             ->where($filter)->field($yb_field)->select();