huangsanjia 1 vuosi sitten
vanhempi
commit
9448e36188
1 muutettua tiedostoa jossa 193 lisäystä ja 2 poistoa
  1. 193 2
      application/api/controller/WorkOrderVerification.php

+ 193 - 2
application/api/controller/WorkOrderVerification.php

@@ -81,8 +81,6 @@ class WorkOrderVerification extends Api
         $where = [];
         if (isset($req['date']) && !empty($req['date'])){
             $where['sys_rq'] = ['LIKE',$req['date'].'%'];
-        }else{
-            $this->error('参数错误');
         }
         if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
         if (isset($req['order']) && !empty($req['order'])) $where['qczl_gdbh'] = $req['order'];
@@ -160,6 +158,7 @@ class WorkOrderVerification extends Api
         if (!isset($params['UniqId']) || empty($params['UniqId'])){
             $this->error('参数错误');
         }
+        $field = '';
         $list = Db::name('db_qczl')->where('UniqId',$params['UniqId'])->find();
         $list['fp_name1'] = '';
         if (!empty($list['fp_bh1'])){
@@ -350,5 +349,197 @@ class WorkOrderVerification extends Api
         $list[$count]['name'] = '计时工';
         $this->success('请求成功',$list);
     }
+    /**
+     * 修改工单核检单
+     * @ApiMethod POST
+     * @params array data
+    */
+    public function edit(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (!isset($params['UniqId'])){
+            $this->error('参数不能为空');
+        }
+        $id = $params['UniqId'];
+        unset($params['UniqId']);
+        $sql = Db::name('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
+        $res = Db::query($sql);
+        if ($res !== 0){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
+    /**
+     * 工单核检废品分布
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function wasteDistribution(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        $field = '
+        rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
+        rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
+        fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13
+        ';
+        $data = Db::name('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
+        if (empty($data)){
+            $this->error('暂无废品数据');
+        }
+        // 用于存储废品类别和对应废品数量的数组
+        $categories = array();
+        // 循环遍历原始数组
+        foreach ($data as $item) {
+            // 提取废品类别和对应废品数量
+            foreach ($item as $key => $value) {
+                if (strpos($key, "fp_lb") === 0) {
+                    $categoryKey = $key;
+                    $quantityKey = str_replace("fp_lb", "fp_sl", $key);
+                    $quantityValue = $item[$quantityKey];
+
+                    if (!isset($categories[$value])) {
+                        $categories[$value] = 0;
+                    }
+
+                    $categories[$value] += (int)$quantityValue;
+                }
+            }
+        }
+        ksort($categories);
+        $wasteTotal = Db::name('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
+        if (empty($wasteTotal)){
+            $wasteTotal = 0;
+        }
+        $where['a.Gd_gdbh'] = $params['order'];
+        $where['a.行号'] = 1;
+        $gdInfo = Db::name('工单_基本资料')->alias('a')
+            ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
+            ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
+        $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
+        $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
+        $gdInfo['wasteTotal'] = $wasteTotal;
+        $finishNum = Db::name('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
+        $gdInfo['passRate'] = '';
+        if (!empty($finishNum)){
+            $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
+        }
+        //左侧废品数据
+        $wasteData = array();
+        $i = 0;
+        foreach ($categories as $key=>$value){
+            if ($value != 0){
+                $wasteData[$i]['type'] = $key;
+                $wasteData[$i]['num'] = $value;
+                $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
+                $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
+                $i++;
+            }
+        }
+        // 按首字母相同的键将值相加
+        $newArray = array();
+        foreach ($categories as $key => $value) {
+            $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
+
+            if (!isset($newArray[$firstLetter])) {
+                $newArray[$firstLetter] = 0;
+            }
+
+            $newArray[$firstLetter] += $value;
+        }
+        // 去掉值为零的项
+        $newArray = array_filter($newArray, function($value) {
+            return $value !== 0;
+        });
+        //右侧废品数据
+        $rightData = array();
+        $i = 0;
+        $name = array();
+        foreach ($newArray as $key=>$value){
+            $item = Db::name('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
+            $item = explode('_',substr($item,0,-1));
+            $rightData[$i]['type'] = $item[1];
+            $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
+            $name[$i] = $item[1];
+            $i++;
+        }
+        $gdInfo['wasteData'] = $wasteData;
+        $gdInfo['rightData'] = $rightData;
+        $gdInfo['rightTitle'] = $name;
+        $this->success('请求成功',$gdInfo);
+    }
+    /**
+     * 工单工期异常调整
+     * @ApiMethod GET
+     * @params string order
+     * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
+     * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
+    */
+    public function getOrderDate(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        $where['a.Gy0_gdbh'] = $params['order'];
+        $where['a.Gy0_sbbh'] = array('neq',' ');
+        $productNum = Db::name('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
+        $gyData = Db::name('工单_工艺资料')->alias('a')
+            ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
+            ->where($where)
+            ->field('a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,a.Gy0_sbbh,a.Gy0_Rate0,a.Gy0_Rate1,a.损耗系数 as Gy0_Rate3,a.Gy0_Ms,a.Gy0_SITE,a.Gy0_计划接货数,a.PD_WG,
+            sum(b.sczl_cl) as cl')
+            ->group('a.Gy0_gxh')
+            ->select();
+        $lastNum = $productNum;
+        $res = [];
+        foreach ($gyData as $key=> $process) {
+            $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
+            $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
+            $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
+            $res[$key]['Gy0_sbbh'] = $process['Gy0_sbbh'];
+            $res[$key]['PD_WG'] = $process['PD_WG'];
+            $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
+            // 计算工序计划产量
+            if ($process["Gy0_gxh"] == "1") {
+                // 第一道工序直接使用初始计划产量
+                $Num = $lastNum;
+            } else {
+                $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
+                $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
+                $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
+                $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
+                // 大于第一道工序,使用上一道工序的计划产量
+                // 根据公式计算工序计划产量
+                if ($Gy0_Ms != "0.00") {
+                    $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
+                } else {
+                    $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
+                }
+            }
+            if (trim($process['Gy0_SITE']) == '检验车间'){
+                $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
+            }else{
+                $res[$key]['plan'] = (int)round($Num);
+            }
+            $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
+            $res[$key]['finish_rate'] = '';
+            if ($finish_rate != 0){
+                $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
+            }
 
+            // 更新 $lastNum 为当前工序的计划产量
+            $lastNum = $Num;
+        }
+        $this->success('请求成功',$res);
+    }
 }