|
|
@@ -3,6 +3,7 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
+use think\Cache;
|
|
|
use \think\Request;
|
|
|
use \think\Db;
|
|
|
/**
|
|
|
@@ -30,52 +31,52 @@ class OrderSuperLoss extends Api
|
|
|
if (Request::instance()->isGet() == false) {
|
|
|
$this->error('非法请求');
|
|
|
}
|
|
|
- $sql = "SELECT DISTINCT(Gd_gdbh),`年月`,rtrim(`客户编号`) as 客户编号,rtrim(`客户名称`) as 客户名称 FROM `rec_月度废品汇总`
|
|
|
+ $is_hav_cache = Cache::get('OrderSuperLoss/getTab');
|
|
|
+ if ($is_hav_cache === false){
|
|
|
+ $sql = "SELECT DISTINCT(Gd_gdbh),`年月`,rtrim(`客户编号`) as 客户编号,rtrim(`客户名称`) as 客户名称 FROM `rec_月度废品汇总`
|
|
|
WHERE STR_TO_DATE(`年月`, '%Y%m') >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) order by 年月 desc,客户编号 asc";
|
|
|
- $data = Db::query($sql);
|
|
|
-
|
|
|
- $outputArray = [];
|
|
|
-
|
|
|
- foreach ($data as $item) {
|
|
|
- $yearMonth = $item['年月'];
|
|
|
-
|
|
|
- if (!isset($outputArray[$yearMonth])) {
|
|
|
- // If key doesn't exist in output array, initialize it
|
|
|
- $outputArray[$yearMonth] = [];
|
|
|
- }
|
|
|
-
|
|
|
- // Check if the customer already exists in the current yearMonth array
|
|
|
- $existingCustomerIndex = null;
|
|
|
- foreach ($outputArray[$yearMonth] as $index => $customer) {
|
|
|
- if ($customer['客户编号'] === $item['客户编号']) {
|
|
|
- $existingCustomerIndex = $index;
|
|
|
- break;
|
|
|
+ $data = Db::query($sql);
|
|
|
+ $outputArray = [];
|
|
|
+ foreach ($data as $item) {
|
|
|
+ $yearMonth = $item['年月'];
|
|
|
+ if (!isset($outputArray[$yearMonth])) {
|
|
|
+ // If key doesn't exist in output array, initialize it
|
|
|
+ $outputArray[$yearMonth] = [];
|
|
|
+ }
|
|
|
+ // Check if the customer already exists in the current yearMonth array
|
|
|
+ $existingCustomerIndex = null;
|
|
|
+ foreach ($outputArray[$yearMonth] as $index => $customer) {
|
|
|
+ if ($customer['客户编号'] === $item['客户编号']) {
|
|
|
+ $existingCustomerIndex = $index;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($existingCustomerIndex !== null) {
|
|
|
+ // If customer exists, increment the total
|
|
|
+ $outputArray[$yearMonth][$existingCustomerIndex]['total']++;
|
|
|
+ } else {
|
|
|
+ // If customer doesn't exist, add a new entry
|
|
|
+ $outputArray[$yearMonth][] = [
|
|
|
+ '客户名称' => $item['客户名称'],
|
|
|
+ '客户编号' => $item['客户编号'],
|
|
|
+ 'total' => 1,
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if ($existingCustomerIndex !== null) {
|
|
|
- // If customer exists, increment the total
|
|
|
- $outputArray[$yearMonth][$existingCustomerIndex]['total']++;
|
|
|
- } else {
|
|
|
- // If customer doesn't exist, add a new entry
|
|
|
- $outputArray[$yearMonth][] = [
|
|
|
- '客户名称' => $item['客户名称'],
|
|
|
- '客户编号' => $item['客户编号'],
|
|
|
- 'total' => 1,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- // 遍历每个年月的数组
|
|
|
- $list = [];
|
|
|
- foreach ($outputArray as $yearMonth => $orders) {
|
|
|
- $totalOrders = 0;
|
|
|
-
|
|
|
- // 遍历每个订单,累加订单数量
|
|
|
- foreach ($orders as $order) {
|
|
|
- $totalOrders += $order['total'];
|
|
|
+ // 遍历每个年月的数组
|
|
|
+ $list = [];
|
|
|
+ foreach ($outputArray as $yearMonth => $orders) {
|
|
|
+ $totalOrders = 0;
|
|
|
+ // 遍历每个订单,累加订单数量
|
|
|
+ foreach ($orders as $order) {
|
|
|
+ $totalOrders += $order['total'];
|
|
|
+ }
|
|
|
+ // 输出每个年月的订单数量
|
|
|
+ $list[$yearMonth.'-'.$totalOrders] = $orders;
|
|
|
}
|
|
|
- // 输出每个年月的订单数量
|
|
|
- $list[$yearMonth.'-'.$totalOrders] = $orders;
|
|
|
+ Cache::set('OrderSuperLoss/getTab',$list,86400);
|
|
|
+ }else{
|
|
|
+ $list = Cache::get('OrderSuperLoss/getTab');
|
|
|
}
|
|
|
$this->success('请求成功',$list);
|
|
|
}
|
|
|
@@ -146,7 +147,7 @@ class OrderSuperLoss extends Api
|
|
|
UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$value['Gd_gdbh']}') AS combined_result";
|
|
|
$gxh_arr = Db::query($gxh_sql);
|
|
|
$gxh_values = array_column($gxh_arr, 'sczl_gxh');
|
|
|
- $gy_data = Db::name('工单_工艺资料')->where('Gy0_gdbh',$value['Gd_gdbh'])->where('Gy0_gxh','in',$gxh_values)->field('Gy0_计划接货数,Gy0_计划损耗')->select();
|
|
|
+ $gy_data =db('工单_工艺资料')->where('Gy0_gdbh',$value['Gd_gdbh'])->where('Gy0_gxh','in',$gxh_values)->field('Gy0_计划接货数,Gy0_计划损耗')->select();
|
|
|
$arr = [];
|
|
|
$plan_loss = [];//工单计划损耗
|
|
|
foreach ($gy_data as $k=>$v){
|
|
|
@@ -162,15 +163,15 @@ class OrderSuperLoss extends Api
|
|
|
$data[$key]['reward_rate'] = '';
|
|
|
$data[$key]['reward_money'] = '';
|
|
|
//制程废品
|
|
|
- $zzfp_data = Db::name('设备_产量计酬')->where('sczl_gdbh',$value['Gd_gdbh'])->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
|
|
|
+ $zzfp_data =db('设备_产量计酬')->where('sczl_gdbh',$value['Gd_gdbh'])->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
|
|
|
$data[$key]['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $value['yj_ls'];//制程废品
|
|
|
$data[$key]['废品合计'] = $data[$key]['zcfp'] + $value['废品合计'];//废品合计
|
|
|
$data[$key]['intangible_loss'] = $value['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $data[$key]['废品合计'];//工单无形损
|
|
|
//材料废
|
|
|
- $waste_l = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
|
|
|
+ $waste_l =db('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
|
|
|
$data[$key]['material_waste'] = $waste_l[0]['废品数量'];
|
|
|
//零头处理
|
|
|
- $waste_w = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
|
|
|
+ $waste_w = db('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
|
|
|
$data[$key]['minor_processing'] = $waste_w[0]['废品数量'];
|
|
|
//外发废
|
|
|
$out_sql = "SELECT 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,
|
|
|
@@ -260,7 +261,7 @@ class OrderSuperLoss extends Api
|
|
|
}
|
|
|
$order = $params['order'];
|
|
|
$field = 'Gd_gdbh,rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(销售订单号) as 销售订单号,订单数量,实际投料';
|
|
|
- $data = Db::name('工单_基本资料')->where('Gd_Gdbh',$order)->where('行号',1)->field($field)->find();
|
|
|
+ $data =db('工单_基本资料')->where('Gd_Gdbh',$order)->where('行号',1)->field($field)->find();
|
|
|
//查出成品数量及日期
|
|
|
$cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$order}' GROUP BY jjcp_gdbh";
|
|
|
$cp_data = Db::query($cp_sql);
|
|
|
@@ -272,7 +273,7 @@ class OrderSuperLoss extends Api
|
|
|
UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$order}') AS combined_result";
|
|
|
$gxh_arr = Db::query($gxh_sql);
|
|
|
$gxh_values = array_column($gxh_arr, 'sczl_gxh');
|
|
|
- $gy_data = Db::name('工单_工艺资料')
|
|
|
+ $gy_data =db('工单_工艺资料')
|
|
|
->alias('a')
|
|
|
->field([
|
|
|
'a.Gy0_yjno', 'a.Gy0_gxh', 'RTRIM(a.Gy0_gxmc) as Gy0_gxmc','RTRIM(a.Add_gxmc) as Add_gxmc', 'a.Gy0_ls', 'a.Gy0_计划接货数',
|
|
|
@@ -298,22 +299,22 @@ class OrderSuperLoss extends Api
|
|
|
$real_rate = $cp_data[0]['cp_sl'] / ($data['实际投料'] * 10000) *100;
|
|
|
$data['real_rate'] = number_format($real_rate,2) . '%';//实际合格率
|
|
|
//制程废品
|
|
|
- $zzfp_data = Db::name('设备_产量计酬')->where('sczl_gdbh',$order)->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
|
|
|
+ $zzfp_data =db('设备_产量计酬')->where('sczl_gdbh',$order)->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
|
|
|
//联数
|
|
|
- $ls = Db::name('工单_印件资料')->where('Yj_Gdbh',$order)->value('yj_ls');
|
|
|
+ $ls =db('工单_印件资料')->where('Yj_Gdbh',$order)->value('yj_ls');
|
|
|
//制程废品*ls
|
|
|
$data['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $ls;
|
|
|
//废品数量
|
|
|
- $waste = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->field('SUM(废品数量) as 废品合计')->select();
|
|
|
+ $waste =db('rec_月度废品汇总')->where('Gd_gdbh',$order)->field('SUM(废品数量) as 废品合计')->select();
|
|
|
//废品合计
|
|
|
$waste_total = $data['zcfp'] + $waste[0]['废品合计'];
|
|
|
//工单无形损
|
|
|
$data['intangible_loss'] = $data['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $waste_total;
|
|
|
//材料废
|
|
|
- $waste_l = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
|
|
|
+ $waste_l =db('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
|
|
|
$data['material_waste'] = $waste_l[0]['废品数量'];
|
|
|
//零头处理
|
|
|
- $waste_w = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
|
|
|
+ $waste_w = db('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
|
|
|
$data['minor_processing'] = $waste_w[0]['废品数量'];
|
|
|
//外发废
|
|
|
$out_sql = "SELECT 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,
|
|
|
@@ -350,7 +351,7 @@ class OrderSuperLoss extends Api
|
|
|
$data['waste_out'] = array_sum($list);//外发废
|
|
|
//质检废
|
|
|
$data['waste_quality'] = array_sum($quality);
|
|
|
- $plan_total = Db::name('工单_工艺资料')->where(['Gy0_gdbh' => $order, 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
|
|
|
+ $plan_total =db('工单_工艺资料')->where(['Gy0_gdbh' => $order, 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
|
|
|
// halt($plan_total);
|
|
|
//按工序打印
|
|
|
if ($params['type'] == 1){
|
|
|
@@ -412,7 +413,7 @@ class OrderSuperLoss extends Api
|
|
|
}
|
|
|
$order = $params['order'];
|
|
|
$field = 'Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc,Gy0_rate0,Gy0_rate1,损耗系数,无形损承担比例 as loss_one,超节损承担比例 as loss_two,超节损核算单价 as loss_thr,UniqId';
|
|
|
- $data = Db::name('工单_工艺资料')->where('Gy0_gdbh',$order)->field($field)->select();
|
|
|
+ $data =db('工单_工艺资料')->where('Gy0_gdbh',$order)->field($field)->select();
|
|
|
$this->success('请求成功',$data);
|
|
|
}
|
|
|
/**
|
|
|
@@ -434,7 +435,7 @@ class OrderSuperLoss extends Api
|
|
|
$data['无形损承担比例'] = $value['loss_one'];
|
|
|
$data['超节损承担比例'] = $value['loss_two'];
|
|
|
$data['超节损核算单价'] = $value['loss_thr'];
|
|
|
- $sql = Db::name('工单_工艺资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
|
|
|
+ $sql =db('工单_工艺资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
|
|
|
$res = Db::query($sql);
|
|
|
if ($res !== false){
|
|
|
$i++;
|
|
|
@@ -459,7 +460,7 @@ class OrderSuperLoss extends Api
|
|
|
if (!isset($params['order']) || empty($params['order'])) {
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
- $data = Db::name('工单_印件资料')->where('Yj_gdbh',$params['order'])->field('Yj_gdbh,rtrim(yj_Yjdh) as yj_Yjdh,yj_Yjno,rtrim(yj_yjmc) as yj_yjmc,质量考核')->find();
|
|
|
+ $data =db('工单_印件资料')->where('Yj_gdbh',$params['order'])->field('Yj_gdbh,rtrim(yj_Yjdh) as yj_Yjdh,yj_Yjno,rtrim(yj_yjmc) as yj_yjmc,质量考核')->find();
|
|
|
$this->success('请求成功',$data);
|
|
|
}
|
|
|
/**
|
|
|
@@ -483,7 +484,7 @@ class OrderSuperLoss extends Api
|
|
|
}
|
|
|
$where['Yj_gdbh'] = $params['order'];
|
|
|
$where['yj_Yjno'] = $params['yj_yjno'];
|
|
|
- $res = Db::name('工单_印件资料')->where($where)->setField('质量考核',$params['examine']);
|
|
|
+ $res =db('工单_印件资料')->where($where)->setField('质量考核',$params['examine']);
|
|
|
if ($res !== false){
|
|
|
$this->success('更新成功');
|
|
|
}else{
|
|
|
@@ -507,7 +508,7 @@ class OrderSuperLoss extends Api
|
|
|
$search = $params['year'].'.'.$params['month'];
|
|
|
$field = "a.Gd_gdbh,rtrim(c.yj_yjdh) as yj_yjdh,c.yj_Yjno, c.yj_ks,c.yj_ls,rtrim(c.yj_zzdh) as yj_zzdh,
|
|
|
rtrim(b.BOM_物料名称) as BOM_物料名称,rtrim(c.yj_tlgg) as yj_tlgg,rtrim(b.BOM_投料单位) as BOM_投料单位,a.订单数量,c.yj_平张投料, b.BOM_实际用量,a.实际投料,a.投料确认,a.UniqId";
|
|
|
- $data = Db::name('工单_基本资料')->alias('a')
|
|
|
+ $data =db('工单_基本资料')->alias('a')
|
|
|
->join('工单_印件资料 c','a.Gd_gdbh = c.Yj_Gdbh','left')
|
|
|
->join('工单_bom资料 b','c.Yj_Gdbh = b.BOM_工单编号 AND c.yj_zzdh = b.BOM_物料编码','left')
|
|
|
->where('a.投料确认','like','%'.$search.'%')
|
|
|
@@ -549,9 +550,12 @@ class OrderSuperLoss extends Api
|
|
|
$i = 0;
|
|
|
foreach ($params as $key=>$value){
|
|
|
if (!empty($value['number'])){
|
|
|
- $info = Db::name('工单_基本资料')->where('UniqId',$value['UniqId'])->value('Gd_gdbh');
|
|
|
- $res = Db::name('工单_基本资料')->where('UniqId',$value['UniqId'])->setField('实际投料',$value['number']);
|
|
|
- $yjRes = Db::name('工单_印件资料')->where('Yj_Gdbh',$info)->setField('yj_实际投料',$value['number']);
|
|
|
+ $info = db('工单_基本资料')->where('UniqId',$value['UniqId'])->value('Gd_gdbh');
|
|
|
+ $res_sql = db('工单_基本资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->setField('实际投料',$value['number']);
|
|
|
+ $res = Db::query($res_sql);
|
|
|
+ $data['yj_实际投料'] = $value['number'];
|
|
|
+ $yj_sql =db('工单_印件资料')->where('Yj_Gdbh',$info)->fetchSql(true)->update($data);
|
|
|
+ $yjRes = Db::query($yj_sql);
|
|
|
if (!$res && !$yjRes){
|
|
|
$i++;
|
|
|
}
|
|
|
@@ -584,10 +588,8 @@ class OrderSuperLoss extends Api
|
|
|
LEFT JOIN db_sczl c ON a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh
|
|
|
WHERE a.Gy0_gdbh = '{$order}' GROUP BY a.Gy0_gxh";
|
|
|
$data = Db::query($sql);
|
|
|
-// halt($data);
|
|
|
//手检数据
|
|
|
- $handData = Db::name('db_手工检验')->where('sczl_gdbh',$order)->field('sum(sczl_cl) as cl,rtrim(sczl_yjgx) as sczl_gxh')->select();
|
|
|
-// halt($handData);
|
|
|
+ $handData =db('db_手工检验')->where('sczl_gdbh',$order)->field('sum(sczl_cl) as cl,rtrim(sczl_yjgx) as sczl_gxh')->select();
|
|
|
//包装及成品防护数据
|
|
|
$sql = "SELECT sczl_gdbh1,sczl_gdbh2,sczl_gdbh3,sczl_gdbh4,sczl_gdbh5,sczl_gdbh6,rtrim(sczl_gxmc1) as sczl_gxmc1,rtrim(sczl_gxmc2) as sczl_gxmc2,
|
|
|
rtrim(sczl_gxmc3) as sczl_gxmc3,rtrim(sczl_gxmc4) as sczl_gxmc4,rtrim(sczl_gxmc5) as sczl_gxmc5,rtrim(sczl_gxmc6) as sczl_gxmc6,
|
|
|
@@ -625,7 +627,6 @@ class OrderSuperLoss extends Api
|
|
|
$sumArray[$key] += $product;
|
|
|
}
|
|
|
$handGxh = substr($handData[0]['sczl_gxh'],-2);
|
|
|
-// halt($sumArray['包装']);
|
|
|
foreach ($data as $key=>$item){
|
|
|
$data[$key]['折算车头产量'] = round($item['Gy0_计划接货数']/$item['Gy0_ls']);
|
|
|
$data[$key]['制程废品率'] = '';
|