success('请求成功'); } /** * 获取工单核验单侧边栏 * @ApiMethod (GET) */ public function getTab() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } if(!cache('WorkOrderVerification-getTable')){ $time = date('Y-m-d',time()-8640000); $rows = db()->table('db_qczl') ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts') ->where('sys_rq','>=',$time) ->group('date') ->order('date desc') ->limit(30) ->select(); $arr = db()->table('db_qczl') ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count') ->where('sys_rq','>=',$rows[count($rows)-1]['date']) ->group('date, sys_id') ->select(); foreach($rows as $key=>$value){ $rows[$key]['sys'] = []; foreach($arr as $k=>$v){ if($value['date'] == $v['date']){ unset($v['date']); array_push($rows[$key]['sys'],$v); unset($arr[$k]); } } $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']); } //设置缓存 cache('WorkOrderVerification-getTable',$rows,3600); }else{ $rows = cache('WorkOrderVerification-getTable'); } $this->success('成功',$rows); } /** * 获取工单核验单侧边栏通过工单编号 * @ApiMethod (GET) */ public function getTabByGdbh() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $date = date('Y-m-d',strtotime("-1 year")); $rows = db()->table('db_qczl')->alias('d') ->field('d.qczl_gdbh, rtrim(y.Gd_cpmc) as Gd_cpmc') ->join('工单_基本资料 y','y.Gd_gdbh = d.qczl_gdbh','left') ->where('d.sys_rq','>=',$date) ->group('d.qczl_gdbh') ->order('d.qczl_gdbh desc') ->limit(65) ->select(); $arr = db()->table('db_qczl') ->field('qczl_gdbh, rtrim(sys_id) as sys_id, COUNT(*) as count') ->where('qczl_gdbh','>=',$rows[count($rows)-1]['qczl_gdbh']) ->group('qczl_gdbh, sys_id') ->select(); foreach($rows as $key=>$value){ $rows[$key]['sys'] = []; foreach($arr as $k=>$v){ if($value['qczl_gdbh'] == $v['qczl_gdbh']){ unset($v['qczl_gdbh']); array_push($rows[$key]['sys'],$v); unset($arr[$k]); } } } $this->success('成功',$rows); } /** * 获取工单核验单列表 * @ApiMethod (GET) * @param string $date 时间 * @param string $sys_id 用户 */ public function getList() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $req = $this->request->param(); $page = 1; $limit = 15; if (isset($req['page']) && !empty($req['page'])) $page = $req['page']; if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit']; $where = []; if (isset($req['date']) && !empty($req['date'])){ $where['sys_rq'] = ['LIKE',$req['date'].'%']; } 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']; if (isset($req['cpmc']) && !empty($req['cpmc'])){ //查询工单表 $gd = db('工单_基本资料') ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%') ->column('Gd_gdbh'); $where['qczl_gdbh'] = ['in', $gd]; } $rows = db()->table('db_qczl') ->field('qczl_gdbh, qczl_yjno, LEFT(qczl_rq, 10) as qczl_rq, qczl_num, rtrim(qczl_NumDesc) as qczl_NumDesc, qczl_fp, fp_lb1, fp_lb2, fp_lb3, fp_lb4, fp_lb5, fp_lb6, fp_lb7, fp_lb8, fp_lb9, fp_lb10, fp_lb11, fp_lb12, fp_lb13, fp_lb14, fp_lb15, fp_lb16, fp_lb17, 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, fp_sl14, fp_sl15, fp_sl16, fp_sl17, rtrim(sys_id) as sys_id,UniqId') ->where($where) ->order('UniqId desc') ->page($page,$limit) ->select(); $total = db()->table('db_qczl')->where($where)->count(); $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc'); foreach ($rows as $key=>$value){ $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : ''; for ($i=1;$i<=17;$i++){ if ($value['fp_sl'.$i]==0){ $rows[$key]['sl_lb'.$i] = ''; }else{ $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i]); } unset($rows[$key]['fp_sl'.$i]); unset($rows[$key]['fp_lb'.$i]); } } $data = [ 'total' => $total, 'rows' => $rows, ]; $this->success('成功',$data); } /** * 获取工单核验单信息 * @ApiMethod (GET) * @param string $UniqId UniqId */ public function getInfo() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (isset($req['UniqId']) && !empty($req['UniqId'])){ $UniqId = $req['UniqId']; }else{ $this->error('参数错误'); } $rows = db()->table('db_qczl')->alias('d') ->field('d.*, ') ->join('工单_基本资料 g', 'd.') ->where('d.UniqId',$UniqId) ->select(); $this->success('成功',$rows); } /** * 获取单个工单核检单信息 * @ApiMethod GET * @params string UniqId */ public function getOneWorkOrder(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['UniqId']) || empty($params['UniqId'])){ $this->error('参数错误'); } $field = 'qczl_gdbh,qczl_Pygd,qczl_yjno,qczl_gxh,qczl_gxmc,qczl_type,qczl_rq,qczl_num,qczl_fp, qczl_NumDesc,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8, fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13,trim(fp_lb14) as fp_lb14,trim(fp_lb15) as fp_lb15,trim(fp_lb16) as fp_lb16,trim(fp_lb17) as fp_lb17, 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,fp_sl14,fp_sl15,fp_sl16,fp_sl17, fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13, fp_bz1,fp_bz2,fp_bz3,fp_bz4,fp_bz5,fp_bz6,fp_bz7,fp_bz8,fp_bz9,fp_bz10,fp_bz11,fp_bz12,fp_bz13, fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13, sys_id,rtrim(sys_rq) as sys_rq,UniqId'; $list = db('db_qczl')->where('UniqId',$params['UniqId'])->field($field)->find(); $list['fp_name1'] = ''; if (!empty($list['fp_bh1'])){ $list['fp_name1'] = db('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)'); } $list['fp_name2'] = ''; if (!empty($list['fp_bh2'])){ $list['fp_name2'] = db('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)'); } $list['fp_name3'] = ''; if (!empty($list['fp_bh3'])){ $list['fp_name3'] = db('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)'); } $list['fp_name4'] = ''; if (!empty($list['fp_bh4'])){ $list['fp_name4'] = db('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)'); } $list['fp_name5'] = ''; if (!empty($list['fp_bh5'])){ $list['fp_name5'] = db('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)'); } $list['fp_name6'] = ''; if (!empty($list['fp_bh6'])){ $list['fp_name6'] = db('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)'); } $list['fp_name7'] = ''; if (!empty($list['fp_bh7'])){ $list['fp_name7'] = db('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)'); } $list['fp_name8'] = ''; if (!empty($list['fp_bh8'])){ $list['fp_name8'] = db('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)'); } $list['fp_name9'] = ''; if (!empty($list['fp_bh9'])){ $list['fp_name9'] = db('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)'); } $list['fp_name10'] = ''; if (!empty($list['fp_bh10'])){ $list['fp_name10'] = db('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)'); } $list['fp_name11'] = ''; if (!empty($list['fp_bh11'])){ $list['fp_name11'] = db('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)'); } $list['fp_name12'] = ''; if (!empty($list['fp_bh12'])){ $list['fp_name12'] = db('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)'); } $list['fp_name13'] = ''; if (!empty($list['fp_bh13'])){ $list['fp_name13'] = db('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)'); } $max = db('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find(); $list['total_liucheng'] = $max['sczl_num']; $this->success('请求成功',$list); } /** * 获取工单基本信息 * @ApiMethod GET * @params string order */ public function getOrderInfo(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['order']) || empty($params['order'])){ $this->error('参数错误'); } $list = db('工单_基本资料')->alias('a') ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left') ->where('a.Gd_gdbh',$params['order']) ->where('a.行号',1) ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc') ->select(); $this->success('请求成功',$list); } /** * 获取印件名称及工序 * @ApiMethod GET * @params string order * @params string yj_no */ public function getYjInfo(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['order']) || empty($params['order'])){ $this->error('参数错误'); } if (!isset($params['yj_no']) || empty($params['yj_no'])){ $this->error('参数错误'); } $where['Yj_Gdbh'] = $params['order']; $where['yj_Yjno'] = $params['yj_no']; $list = db('工单_印件资料')->where($where)->field('yj_yjmc')->find(); $option['Gy0_gdbh'] = $params['order']; $option['Gy0_yjno'] = $params['yj_no']; // $option['Gy0_site'] = '印后车间'; $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']); $gxList = db('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select(); $max = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num'); $list['gx_data'] = $gxList; $list['max_num'] = $max; $this->success('请求成功',$list); } /** * 获取废品分类 * @ApiMethod GET * @params string search */ public function getWastInfo(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $where['分类'] = '废品分类'; if (!empty($params['search'])){ $where['名称'] = array('like','%'.$params['search'].'%'); } $data = db('erp_常用字典')->where($where)->column('名称'); // 分割字符串并合并相同项 $resultArray = []; foreach ($data as $item) { $parts = explode('_', $item); // 使用第一个部分作为一级键,第二个部分作为二级键 $firstKey = $parts[0]; $secondKey = $parts[1]; $thirdValue = $parts[2]; $resultArray[$firstKey][$secondKey][] = $thirdValue; } // 对废品分类下的数组进行升序排序 if (isset($resultArray['data']['废品分类'])) { foreach ($resultArray['data']['废品分类'] as &$category) { // 判断是关联数组(单凹等)还是索引数组(分切等) if (is_array($category) && !empty($category) && is_array(current($category))) { foreach ($category as &$subCategory) { ksort($subCategory); } } else { ksort($category); } } } $this->success('请求成功',$resultArray); } /** *获取工序及责任组长 * @ApiMethod GET * @params string type * @params string order */ public function getGxAndLeader(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['type']) || empty($params['type'])){ $this->error('参数错误'); } if (!isset($params['order']) || empty($params['order'])){ $this->error('参数错误'); } if (!isset($params['yjno']) || empty($params['yjno'])){ $this->error('参数错误'); } $type = trim($params['type']); $waste = db('erp_常用字典')->where('名称','like','%'.$type.'%')->find(); if (empty($waste)){ $this->error('未查询到废品分类'); } $wasteType = explode('_',substr($waste['名称'],0,-1)); $searchArr = explode('-',$wasteType[1]); $search = substr($searchArr[1],0,6); $where['a.sczl_gdbh'] = $params['order']; $where['a.sczl_type'] = array('like','%'.$search.'%'); $where['a.sczl_yjno'] = $params['yjno']; $list = db('设备_产量计酬')->alias('a') ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left') ->where($where)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name') ->select(); $count = count($list); $list[$count]['sczl_gxmc'] = '99-外发加工'; $list[$count]['sczl_bzdh'] = 'A班'; $list[$count]['sczl_jtbh'] = ''; $list[$count]['sczl_bh1'] = '000000'; $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('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params); $res = Db::query($sql); if ($res !== 0){ cache('WorkOrderVerification-getTable',null); $this->success('更新成功'); }else{ $this->error('更新失败'); } } /** * 新增工单核检单 * @ApiMethod POST * @params array data */ public function add(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $params = Request::instance()->post(); $UniqId = db('db_qczl')->order('UniqId desc')->value('UniqId'); if ($UniqId < 10000000){ $UniqId = 10000000; }else{ $UniqId = $UniqId + 1; } $params['UniqId'] = $UniqId; $params['sys_rq'] = date('Y-m-d H:i:s'); $res = \db('db_qczl')->insert($params); if ($res !== false){ cache('WorkOrderVerification-getTable',null); $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('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('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('工单_基本资料')->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('成品入仓')->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('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('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料'); $gyData = db('工单_工艺资料')->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, a.UniqId,sum(b.sczl_cl) as cl') ->group('a.Gy0_gxh') ->select(); $lastNum = $productNum; $res = []; foreach ($gyData as $key=> $process) { $res[$key]['UniqId'] = $process['UniqId']; $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'] = rtrim($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); } /** * 工单工序状态更正 * @ApiMethod POST * @params string UniqId * @params string date */ public function editOrderFinishDate(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $params = Request::instance()->post(); if (!isset($params['UniqId']) || !isset($params['date'])){ $this->error('参数错误'); } if (empty($params['UniqId'])){ $this->error('参数不能为空'); } if (empty($params['date'])){ $params['date'] = '1900-01-01 00:00:00'; } $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']); if ($res != false){ $this->success('更新成功'); }else{ $this->error('更新失败'); } } /** * 工单工序生产进程菜单栏 * @ApiMethod GET * @params string order */ public function getOrderProcessLeft(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['order']) || empty($params['order'])){ $this->error('参数错误'); } $where['Gd_gdbh'] = $params['order']; $where['行号'] = 1; //工单基本资料 $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号) as code,rtrim(成品名称) as name')->find(); //工艺资料 $option['Gy0_gdbh'] = $params['order']; $gyInfo = db('工单_工艺资料') ->where($option) ->where(function ($query) { $query->where('Gy0_sbbh', '<>', '') ->whereOr('Gy0_gxmc', '核检') ->whereOr('Gy0_gxmc', '成品防护'); }) ->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc') ->select(); foreach ($gyInfo as $key=>$value){ $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno']; $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh']; } $res['Gd_info'] = $info; $res['Gy_info'] = $gyInfo; $this->success('请求成功',$res); } /** * 工单工序生产进程右侧 * @ApiMethod GET * @params string order * @params string gxNo */ public function getOrderProcessRight(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['order']) || empty($params['order'])){ $this->error('参数错误'); } if (!isset($params['gxNo']) || empty($params['gxNo'])){ $this->error('参数错误'); } $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->order('sczl_num')->column('distinct(sczl_num)'); $where['sczl_gxh'] = (int)$params['gxNo']; $where['sczl_gdbh'] = $params['order']; //机器设备数据 $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)'); //手工数据 $option['qczl_gdbh'] = $params['order']; $option['qczl_gxh'] = (int)$params['gxNo']; $handProcess = db('db_qczl')->where($option)->field('qczl_num,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8')->select(); // 提取数据 $result = array(); foreach ($handProcess as $subArray) { $qczl_num = $subArray["qczl_num"]; $result[] = $qczl_num; // 提取以qczl_NumDesc开头的键对应的值 for ($i = 1; $i <= 8; $i++) { $key = "qczl_NumDesc" . $i; if ($subArray[$key] != 0){ $result[] = $subArray[$key]; } } } // 去重 $result = array_unique($result); // 对结果进行排序 sort($result); $res['total_process'] = $total; $res['process'] = $process; if (empty($process)){ $res['process'] = $result; } $this->success('请求成功',$res); } /** * 核检废品日统计 * @ApiMethod GET * @params date start_date * @params date end_date */ public function getDaysWast() { if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['start_date']) || empty($params['start_date'])) { $this->error('参数错误'); } if (!isset($params['end_date']) || empty($params['end_date'])) { $this->error('参数错误'); } $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]); $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, fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13, rtrim(fp_bz1) as fp_bz1, rtrim(fp_bz2) as fp_bz2, rtrim(fp_bz3) as fp_bz3, rtrim(fp_bz4) as fp_bz4, rtrim(fp_bz5) as fp_bz5, rtrim(fp_bz6) as fp_bz6, rtrim(fp_bz7) as fp_bz7, rtrim(fp_bz8) as fp_bz8, rtrim(fp_bz9) as fp_bz9, rtrim(fp_bz10) as fp_bz10, rtrim(fp_bz11) as fp_bz11, rtrim(fp_bz12) as fp_bz12, rtrim(fp_bz13) as fp_bz13, qczl_rq '; $resultArray = array(); $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date']; $is_have_cache = Cache::has($key); if ($is_have_cache === false){ $data = db('db_qczl') ->where($where) ->where(function ($query) { for ($i = 1; $i <= 13; $i++) { $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0); } }) ->field($field)->select(); $list = []; $j = 0; foreach ($data as $entry) { for ($i = 1; $i <= 13; $i++) { $labelKey = "fp_lb" . $i; $slKey = "fp_sl" . $i; $bhKey = "fp_bh" . $i; $bzKey = "fp_bz" . $i; if (!empty($entry[$labelKey])) { if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){ $list[$j]['fp_lb'] = $entry[$labelKey]; $list[$j]['fp_sl'] = $entry[$slKey]; $list[$j]['fp_bh'] = $entry[$bhKey]; $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)'); $list[$j]['fp_name'] = empty($name) ? '计时工' : $name; $list[$j]['fp_bz'] = $entry[$bzKey]; $list[$j]['qczl_rq'] = $entry['qczl_rq']; $j++; } } } } foreach ($list as $item) { $found = false; foreach ($resultArray as &$resultItem) { if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) { $resultItem["fp_sl"] += (int)$item["fp_sl"]; $found = true; break; } } if (!$found) { $resultArray[] = $item; } } // 使用usort进行排序 usort($resultArray, function($a, $b) { // First, sort by fp_lb (K01/K02) $compareLb = strcmp($a['fp_lb'], $b['fp_lb']); if ($compareLb !== 0) { return $compareLb; } // If fp_lb is the same, prioritize B班 over A班 $compareBz = strcmp($a['fp_bz'], $b['fp_bz']); if ($compareBz !== 0) { return (trim($a['fp_bz']) === 'B班') ? -1 : 1; } // If fp_bz is the same, sort by fp_bh $compareBh = strcmp($a['fp_bh'], $b['fp_bh']); return $compareBh; }); Cache::set($key,$resultArray,86400); }else{ $resultArray = Cache::get($key); } $this->success('请求成功',$resultArray); } /** * 月度核检废品责任人统计 * @ApiMethod GET * @params string date */ public function getMonthPeopleTotal(){ if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['date']) || empty($params['date'])) { $this->error('参数错误'); } } /** * 工单质检废品统计 * @ApiMethod GET * @params string order */ public function getOrderWasteTotal(){ if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['order']) || empty($params['order'])) { $this->error('参数错误'); } $field = ' rtrim(a.fp_lb1) as fp_lb1,rtrim(a.fp_lb2) as fp_lb2,rtrim(a.fp_lb3) as fp_lb3,rtrim(a.fp_lb4) as fp_lb4,rtrim(a.fp_lb5) as fp_lb5,rtrim(a.fp_lb6) as fp_lb6,rtrim(a.fp_lb7) as fp_lb7, rtrim(a.fp_lb8) as fp_lb8,rtrim(a.fp_lb9) as fp_lb9,rtrim(a.fp_lb10) as fp_lb10,rtrim(a.fp_lb11) as fp_lb11,rtrim(a.fp_lb12) as fp_lb12,rtrim(a.fp_lb13) as fp_lb13, a.fp_sl1,a.fp_sl2,a.fp_sl3,a.fp_sl4,a.fp_sl5,a.fp_sl6,a.fp_sl7,a.fp_sl8,a.fp_sl9,a.fp_sl10,a.fp_sl11,a.fp_sl12,a.fp_sl13, a.fp_bh1,a.fp_bh2,a.fp_bh3,a.fp_bh4,a.fp_bh5,a.fp_bh6,a.fp_bh7,a.fp_bh8,a.fp_bh9,a.fp_bh10,a.fp_bh11,a.fp_bh12,a.fp_bh13, rtrim(a.fp_gxmc1) as fp_gxmc1, rtrim(a.fp_gxmc2) as fp_gxmc2, rtrim(a.fp_gxmc3) as fp_gxmc3, rtrim(a.fp_gxmc4) as fp_gxmc4, rtrim(a.fp_gxmc5) as fp_gxmc5, rtrim(a.fp_gxmc6) as fp_gxmc6, rtrim(a.fp_gxmc7) as fp_gxmc7,rtrim(a.fp_gxmc8) as fp_gxmc8, rtrim(a.fp_gxmc9) as fp_gxmc9, rtrim(a.fp_gxmc10) as fp_gxmc10, rtrim(a.fp_gxmc11) as fp_gxmc11, rtrim(a.fp_gxmc12) as fp_gxmc12, rtrim(a.fp_gxmc13) as fp_gxmc13,a.qczl_num,a.qczl_yjno,rtrim(b.成品代号) as product_code,rtrim(b.成品名称) as product_name,b.订单数量,rtrim(b.计量单位) as 计量单位,b.实际投料,b.交货日期, c.yj_ls,d.jjcp_sl,d.jjcp_sj '; $where['a.qczl_gdbh'] = $params['order']; $where['b.行号'] = 1; $data = db('db_qczl')->alias('a') ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh','left') ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh','left') ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh','left') ->where($where) ->field($field)->select(); $list = []; $j = 0; foreach ($data as $entry) { for ($i = 1; $i <= 13; $i++) { $labelKey = "fp_lb" . $i; $slKey = "fp_sl" . $i; $bhKey = "fp_bh" . $i; $gxhKey = "fp_gxmc". $i; if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) { $list[$j]['fp_lb'] = $entry[$labelKey]; $list[$j]['fp_sl'] = $entry[$slKey]; $list[$j]['fp_bh'] = $entry[$bhKey]; $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)'); $list[$j]['fp_name'] = $name; $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2); $list[$j]['qczl_num'] = $entry['qczl_num']; $list[$j]['qczl_yjno'] = $entry['qczl_yjno']; $list[$j]['product_code'] = $entry['product_code']; $list[$j]['product_name'] = $entry['product_name']; $list[$j]['订单数量'] = $entry['订单数量']; $list[$j]['计量单位'] = $entry['计量单位']; $list[$j]['交货日期'] = substr($entry['交货日期'],0,10); $list[$j]['yj_ls'] = $entry['yj_ls']; $list[$j]['jjcp_sl'] = $entry['jjcp_sl']; $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10); $j++; } } } $summedData = []; foreach ($list as $item) { $key = $item['qczl_num'] . $item['fp_lb']; if (!isset($summedData[$key])) { $summedData[$key] = $item; } else { $summedData[$key]['fp_sl'] += $item['fp_sl']; } } $fpGxhColumn = array_column($summedData, 'fp_gxh'); $qczlNumColumn = array_column($summedData, 'qczl_num'); $fpLbColumn = array_column($summedData, 'fp_lb'); array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData); $summedData = array_values($summedData); $this->success('请求成功',$summedData); } }