|
|
@@ -0,0 +1,657 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use \think\Request;
|
|
|
+use \think\Db;
|
|
|
+/**
|
|
|
+ * 工单超节损核算接口
|
|
|
+ */
|
|
|
+class OrderSuperLoss extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = ['*'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 首页
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $this->success('请求成功');
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取左侧菜单栏
|
|
|
+ * @ApiMethod GET
|
|
|
+ */
|
|
|
+ public function getTab()
|
|
|
+ {
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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[$yearMonth.'-'.$totalOrders] = $orders;
|
|
|
+ }
|
|
|
+ $this->success('请求成功',$list);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取超节损工单列表
|
|
|
+ * @ApiMethod GET
|
|
|
+ * @params string date
|
|
|
+ * @params string code
|
|
|
+ * 报废定额=(基础损耗+损耗率*计划产量)*损耗系数*计损色数(特定工序会有,如果无就不乘)
|
|
|
+ * 允损比例=报废定额/计划产量
|
|
|
+ * 目标合格率 = 100%-超节损工单中显示工序的允损比例之和
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function getList(){
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->param();
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if (!empty($params['code'])) {
|
|
|
+ if (!empty($params['search'])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $where['a.客户编号' ] = $params['code'];
|
|
|
+ }
|
|
|
+ if (!empty($params['date'])) {
|
|
|
+ if (!empty($params['search'])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $where['a.年月' ] = $params['date'];
|
|
|
+ }
|
|
|
+ if (!empty($params['search'])) {
|
|
|
+ if (!empty($params['date']) || !empty($params['code'])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $where['a.产品名称'] = array('like','%'.$params['search'].'%');
|
|
|
+ }
|
|
|
+ $where['b.行号' ] = 1;
|
|
|
+ $limit = $params['limit'];
|
|
|
+ if (empty($limit)){
|
|
|
+ $limit = 15;
|
|
|
+ }
|
|
|
+ $pages = $params['page'];
|
|
|
+ if (empty($pages)){
|
|
|
+ $pages = 1;
|
|
|
+ }
|
|
|
+ $data = Db::table('rec_月度废品汇总')->alias('a')
|
|
|
+ ->join('工单_基本资料 b', 'a.Gd_gdbh = b.Gd_gdbh','left')
|
|
|
+ ->join('工单_印件资料 c', 'a.Gd_gdbh = c.Yj_Gdbh','left')
|
|
|
+ ->where($where)
|
|
|
+ ->field('a.Gd_gdbh, SUM(a.废品数量) AS 废品合计, a.年月, rtrim(a.Gd_cpmc) as Gd_cpmc, a.Gd_cpdh, a.实际投料, b.计量单位, c.yj_Yjno, c.yj_ls')
|
|
|
+ ->group('a.Gd_gdbh')
|
|
|
+ ->order('a.Gd_cpdh asc,a.年月 desc')
|
|
|
+ ->fetchSql(true)
|
|
|
+ ->page($pages)
|
|
|
+ ->limit($limit)
|
|
|
+ ->select();
|
|
|
+ foreach ($data as $key => $value){
|
|
|
+ //查出成品数量及日期
|
|
|
+ $cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$value['Gd_gdbh']}' GROUP BY jjcp_gdbh";
|
|
|
+ $cp_data = Db::query($cp_sql);
|
|
|
+ $data[$key]['warehousing_num'] = $cp_data[0]['cp_sl'];
|
|
|
+ $data[$key]['warehousing_date'] = substr($cp_data[0]['jjcp_sj'],0,10);
|
|
|
+ //查出进入超节损的工序,有上报产量的工序就进入超节损
|
|
|
+ $gxh_sql = "SELECT sczl_gxh FROM
|
|
|
+ (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$value['Gd_gdbh']}'
|
|
|
+ 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();
|
|
|
+ $arr = [];
|
|
|
+ $plan_loss = [];//工单计划损耗
|
|
|
+ foreach ($gy_data as $k=>$v){
|
|
|
+ $rate = round($v['Gy0_计划损耗'] / $v['Gy0_计划接货数'],5);
|
|
|
+ $arr[$k] = floor($rate * 10000) /10000;
|
|
|
+ $plan_loss[$k] = $v['Gy0_计划损耗'];
|
|
|
+ }
|
|
|
+ $target_rate = (1-array_sum($arr))*100;
|
|
|
+ $data[$key]['target_rate'] =$target_rate.'%'; //目标合格率
|
|
|
+ $real_rate = $cp_data[0]['cp_sl'] / ($value['实际投料'] * 10000) *100;
|
|
|
+ $data[$key]['real_rate'] = number_format($real_rate,2) . '%';//实际合格率
|
|
|
+ //奖惩系数及金额
|
|
|
+ $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();
|
|
|
+ $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();
|
|
|
+ $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();
|
|
|
+ $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,
|
|
|
+ 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_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_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
|
|
|
+ FROM db_qczl WHERE qczl_gdbh = '{$value['Gd_gdbh']}'";
|
|
|
+ $waste_out = Db::query($out_sql);
|
|
|
+ $list = [];
|
|
|
+ $quality = [];
|
|
|
+ $j = 0;
|
|
|
+ $m = 0;
|
|
|
+ foreach ($waste_out as $entry) {
|
|
|
+ for ($i = 1; $i <= 13; $i++) {
|
|
|
+ $labelKey = "fp_lb" . $i;
|
|
|
+ $bhKey = "fp_bh" . $i;
|
|
|
+ $gxmcKey = "fp_gxmc" . $i;
|
|
|
+ $slKey = "fp_sl" . $i;
|
|
|
+ if (!empty($entry[$labelKey])) {
|
|
|
+ if (substr($entry[$gxmcKey],0,2) == '99'){
|
|
|
+ $list[$j]= $entry[$slKey];
|
|
|
+ $j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($entry[$bhKey])) {
|
|
|
+ if ($entry[$bhKey] != '000000' && $entry[$slKey] > 0){
|
|
|
+ $quality[$m]= $entry[$slKey];
|
|
|
+ $m++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data[$key]['waste_out'] = array_sum($list);//外发废
|
|
|
+ $data[$key]['waste_share'] = '';//分摊废
|
|
|
+ $data[$key]['plan_loss'] = array_sum($plan_loss);//工单计划损耗
|
|
|
+ $data[$key]['waste_quality'] = array_sum($quality); //质检废
|
|
|
+ }
|
|
|
+ $this->success('请求成功',$data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取工单超节损工艺
|
|
|
+ * @ApiMethod GET
|
|
|
+ * @params string order
|
|
|
+ */
|
|
|
+ public function getOrderSuperLossGy(){
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->param();
|
|
|
+ if (!isset($params['order']) || empty($params['order'])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $sql = "SELECT a.Gy0_gdbh,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_Rate0,a.Gy0_Rate1,a.损耗系数,a.Gy0_ms,
|
|
|
+ a.Gy0_计划接货数,a.Gy0_计划损耗,sum(b.sczl_cl) as total_cl,sum(b.sczl_zcfp) as total_fp,sum(c.sczl_cl) as cl,SUM(c.sczl_fp) as fp FROM `工单_工艺资料` a
|
|
|
+ LEFT JOIN `设备_产量计酬` b ON a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh
|
|
|
+ LEFT JOIN `db_sczl` c ON a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh
|
|
|
+ WHERE a.Gy0_gdbh = '{$params['order']}' GROUP BY a.Gy0_gxh";
|
|
|
+ $data = Db::query($sql);
|
|
|
+ foreach ($data as $key=>$value){
|
|
|
+ if (!empty($value['total_cl'])){
|
|
|
+ $data[$key]['total_cl'] = $value['total_cl'] *$value['Gy0_ls'];
|
|
|
+ }else{
|
|
|
+ $data[$key]['total_cl'] =$value['cl'] *$value['Gy0_ls'];
|
|
|
+ }
|
|
|
+ if (!empty($value['total_fp'])){
|
|
|
+ $data[$key]['total_fp'] = $value['total_fp'] *$value['Gy0_ls'];
|
|
|
+ }else{
|
|
|
+ $data[$key]['total_fp'] = $value['fp'] *$value['Gy0_ls'];
|
|
|
+ }
|
|
|
+ unset($data[$key]['cl']);
|
|
|
+ unset($data[$key]['fp']);
|
|
|
+ }
|
|
|
+ $this->success('请求成功',$data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 工单超节损统计
|
|
|
+ * @ApiMethod GET
|
|
|
+ * @params string order
|
|
|
+ */
|
|
|
+ public function getOrderSuperLossCount(){
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->param();
|
|
|
+ if (!isset($params['order']) || empty($params['order'])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $order = $params['order'];
|
|
|
+ $field = 'Gd_gdbh,rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(销售订单号) as 销售订单号,订单数量,实际投料';
|
|
|
+ $data = Db::name('工单_基本资料')->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);
|
|
|
+ $data['warehousing_num'] = $cp_data[0]['cp_sl'];
|
|
|
+ $data['warehousing_date'] = substr($cp_data[0]['jjcp_sj'],0,10);
|
|
|
+ //查出进入超节损的工序,有上报产量的工序就进入超节损
|
|
|
+ $gxh_sql = "SELECT sczl_gxh FROM
|
|
|
+ (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$order}'
|
|
|
+ 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('工单_工艺资料')
|
|
|
+ ->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_计划接货数',
|
|
|
+ 'a.Gy0_计划损耗', 'a.超节损承担比例','SUM(b.sczl_zcfp) as total_fp','SUM(b.sczl_cl) as total_cl','SUM(c.sczl_cl) as cl','SUM(c.sczl_fp) as fp',
|
|
|
+ ])
|
|
|
+ ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','left')
|
|
|
+ ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh','left')
|
|
|
+ ->where([
|
|
|
+ 'a.Gy0_gdbh' => $order,
|
|
|
+ 'a.Gy0_gxh' => ['in', $gxh_values]
|
|
|
+ ])
|
|
|
+ ->group('a.Gy0_gxh')
|
|
|
+ ->select();
|
|
|
+ $arr = [];
|
|
|
+ $plan_loss = [];//工单计划损耗
|
|
|
+ foreach ($gy_data as $k=>$v){
|
|
|
+ $rate = round($v['Gy0_计划损耗'] / $v['Gy0_计划接货数'],5);
|
|
|
+ $arr[$k] = floor($rate * 10000) /10000;
|
|
|
+ $plan_loss[$k] = $v['Gy0_计划损耗'];
|
|
|
+ }
|
|
|
+ $target_rate = (1-array_sum($arr))*100;
|
|
|
+ $data['target_rate'] =$target_rate.'%'; //目标合格率
|
|
|
+ $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();
|
|
|
+ //联数
|
|
|
+ $ls = Db::name('工单_印件资料')->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_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();
|
|
|
+ $data['material_waste'] = $waste_l[0]['废品数量'];
|
|
|
+ //零头处理
|
|
|
+ $waste_w = Db::name('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,
|
|
|
+ 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_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_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
|
|
|
+ FROM db_qczl WHERE qczl_gdbh = '{$order}'";
|
|
|
+ $waste_out = Db::query($out_sql);
|
|
|
+ $list = [];
|
|
|
+ $quality = [];
|
|
|
+ $j = 0;
|
|
|
+ $m = 0;
|
|
|
+ foreach ($waste_out as $entry) {
|
|
|
+ for ($i = 1; $i <= 13; $i++) {
|
|
|
+ $labelKey = "fp_lb" . $i;
|
|
|
+ $bhKey = "fp_bh" . $i;
|
|
|
+ $gxmcKey = "fp_gxmc" . $i;
|
|
|
+ $slKey = "fp_sl" . $i;
|
|
|
+ if (!empty($entry[$labelKey])) {
|
|
|
+ if (substr($entry[$gxmcKey],0,2) == '99'){
|
|
|
+ $list[$j]= $entry[$slKey];
|
|
|
+ $j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($entry[$bhKey])) {
|
|
|
+ if ($entry[$bhKey] != '000000' && $entry[$slKey] > 0){
|
|
|
+ $quality[$m]= $entry[$slKey];
|
|
|
+ $m++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $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_计划损耗)');
|
|
|
+// halt($plan_total);
|
|
|
+ //按工序打印
|
|
|
+ if ($params['type'] == 1){
|
|
|
+ $total = [];
|
|
|
+ $total['plan_loss'] = 0;
|
|
|
+ $total['total_fp'] = 0;
|
|
|
+ $total['waste_quality'] = 0;
|
|
|
+ $total['waste_intangible'] = 0;
|
|
|
+ $total['total_waste'] = 0;
|
|
|
+ $total['loss'] = 0;
|
|
|
+ foreach ($gy_data as $k=>$item){
|
|
|
+ $gy_data[$k]['waste_quality'] = 0;
|
|
|
+ $gy_data[$k]['total_fp'] = $item['total_fp'] * $item['Gy0_ls'];
|
|
|
+ $gy_data[$k]['total_cl'] = $item['total_cl'] * $item['Gy0_ls'];
|
|
|
+ $gy_data[$k]['intangible_loss'] = round($item['Gy0_计划损耗'] / $plan_total * $data['intangible_loss']);
|
|
|
+ foreach ($waste_out as $entry) {
|
|
|
+ for ($i = 1; $i <= 13; $i++) {
|
|
|
+ $gxmcKey = "fp_gxmc" . $i;
|
|
|
+ $slKey = "fp_sl" . $i;
|
|
|
+ if ((int)substr($entry[$gxmcKey],0,2) == $item['Gy0_gxh']){
|
|
|
+ $gy_data[$k]['waste_quality'] += $entry[$slKey];
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['intangible_loss'] + $gy_data[$k]['total_fp'];
|
|
|
+ $gy_data[$k]['loss'] = $item['Gy0_计划损耗'] - $gy_data[$k]['total_waste'];
|
|
|
+ $gy_data[$k]['loss_rate'] = number_format($gy_data[$k]['loss'] / $item['Gy0_计划接货数'],4) * 100 .'%';
|
|
|
+ $gy_data[$k]['target_loss_rate'] = number_format($item['Gy0_计划损耗'] / $item['Gy0_计划接货数'],4) * 100 .'%';
|
|
|
+ $gy_data[$k]['actual_loss_rate'] = number_format($gy_data[$k]['total_waste'] / $item['Gy0_计划接货数'],4) * 100 .'%';
|
|
|
+ $gy_data[$k]['超节损承担比例'] = number_format($item['超节损承担比例'],4) * 100 .'%';
|
|
|
+
|
|
|
+ $total['plan_loss'] += $gy_data[$k]['Gy0_计划损耗'];
|
|
|
+ $total['total_fp'] += $gy_data[$k]['total_fp'];
|
|
|
+ $total['waste_quality'] += $gy_data[$k]['waste_quality'];
|
|
|
+ $total['waste_intangible'] += $gy_data[$k]['intangible_loss'];
|
|
|
+ $total['total_waste'] += $gy_data[$k]['total_waste'];
|
|
|
+ $total['loss'] += $gy_data[$k]['loss'];
|
|
|
+ }
|
|
|
+ $data['gy_data'] = $gy_data;
|
|
|
+ $data['total'] = $total;
|
|
|
+ $this->success('请求成功',$data);
|
|
|
+ }else{ //按班组打印
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取工单工艺
|
|
|
+ * @ApiMethod GET
|
|
|
+ * @params string order
|
|
|
+ */
|
|
|
+ public function getOrderGy(){
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->param();
|
|
|
+ if (!isset($params['order']) || empty($params['order'])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $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();
|
|
|
+ $this->success('请求成功',$data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新工单工艺
|
|
|
+ * @ApiMethod POST
|
|
|
+ * @params array data
|
|
|
+ */
|
|
|
+ public function updateOrderGy(){
|
|
|
+ if (Request::instance()->isPost() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->request();
|
|
|
+ if (!isset($params) || !isset($params[0]['UniqId'])){
|
|
|
+ $this->error('参数不能为空');
|
|
|
+ }
|
|
|
+ $i = 0;
|
|
|
+ foreach ($params as $key=>$value){
|
|
|
+ $data = [];
|
|
|
+ $data['无形损承担比例'] = $value['loss_one'];
|
|
|
+ $data['超节损承担比例'] = $value['loss_two'];
|
|
|
+ $data['超节损核算单价'] = $value['loss_thr'];
|
|
|
+ $sql = Db::name('工单_工艺资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
|
|
|
+ $res = Db::query($sql);
|
|
|
+ if ($res !== false){
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($i !== 0){
|
|
|
+ $this->success('更新成功');
|
|
|
+ }else{
|
|
|
+ $this->error('更新失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取工单印件考核资料
|
|
|
+ * @ApiMethod GET
|
|
|
+ * @params string order
|
|
|
+ */
|
|
|
+ public function getOrderYj(){
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->request();
|
|
|
+ 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();
|
|
|
+ $this->success('请求成功',$data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新工单印件考核资料
|
|
|
+ * @ApiMethod POST
|
|
|
+ * @params array data
|
|
|
+ */
|
|
|
+ public function updateOrderYj(){
|
|
|
+ if (Request::instance()->isPost() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->request();
|
|
|
+ if (!isset($params['order'])){
|
|
|
+ $this->error('参数不能为空');
|
|
|
+ }
|
|
|
+ if (!isset($params['yj_yjno'])){
|
|
|
+ $this->error('参数不能为空');
|
|
|
+ }
|
|
|
+ if (!isset($params['examine'])){
|
|
|
+ $this->error('参数不能为空');
|
|
|
+ }
|
|
|
+ $where['Yj_gdbh'] = $params['order'];
|
|
|
+ $where['yj_Yjno'] = $params['yj_yjno'];
|
|
|
+ $res = Db::name('工单_印件资料')->where($where)->setField('质量考核',$params['examine']);
|
|
|
+ if ($res !== false){
|
|
|
+ $this->success('更新成功');
|
|
|
+ }else{
|
|
|
+ $this->error('更新失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取修正工单实际投料列表
|
|
|
+ * @ApiMethod GET
|
|
|
+ * @params string year
|
|
|
+ * @params string month
|
|
|
+ */
|
|
|
+ public function getOrderFeedList(){
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->request();
|
|
|
+ if (empty($params['year']) || empty($params['month'])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $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')
|
|
|
+ ->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.'%')
|
|
|
+ ->field($field)
|
|
|
+ ->group('a.Gd_gdbh')
|
|
|
+ ->order('b.BOM_投料单位,a.UniqId asc')
|
|
|
+ ->select();
|
|
|
+ if (empty($data)){
|
|
|
+ $this->success('请求成功');
|
|
|
+ }
|
|
|
+ foreach ($data as $key=>$value){
|
|
|
+ $len = stripos($value['yj_tlgg'],'/');
|
|
|
+ if ($len){
|
|
|
+ $name = substr($value['yj_tlgg'],0,$len);
|
|
|
+ $len_two = stripos($value['yj_tlgg'],'(');
|
|
|
+ if ($len_two){
|
|
|
+ $name = substr($name,0,$len_two);
|
|
|
+ }
|
|
|
+ $data[$key]['yj_tlgg'] = $name;
|
|
|
+ }
|
|
|
+ $data[$key]['rate'] = '';
|
|
|
+ }
|
|
|
+ $this->success('请求成功',$data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新工单实际投料
|
|
|
+ * @ApiMethod POST
|
|
|
+ * @params int UniqId
|
|
|
+ * @params string number
|
|
|
+ */
|
|
|
+ public function updateOrderFeed(){
|
|
|
+ if (Request::instance()->isPost() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->post();
|
|
|
+ if (!isset($params[0]['UniqId']) || empty($params[0]['UniqId'])){
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $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']);
|
|
|
+ if (!$res && !$yjRes){
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($i != 0){
|
|
|
+ $this->success('更新成功');
|
|
|
+ }else{
|
|
|
+ $this->error('更新失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 工单工序产量统计
|
|
|
+ * @ApiMethod GET
|
|
|
+ * @params string order
|
|
|
+ */
|
|
|
+ public function getOrderProcessCount(){
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->request();
|
|
|
+ if (empty($params['order']) || empty($params['order'])) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $order = $params['order'];
|
|
|
+ $sql = "SELECT a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_计划接货数, a.Gy0_ls,a.Gy0_sbbh,a.PD_WG,SUM(b.sczl_cl) as sczl_cl,
|
|
|
+ SUM(b.sczl_zcfp) as sczl_zcfp,SUM(b.sczl_来料少数) as 来料异常,COUNT(DISTINCT b.sczl_num) as process_num,b.sczl_Pgcl,SUM(c.sczl_cl) as cl,b.sczl_rq
|
|
|
+ FROM `工单_工艺资料` a
|
|
|
+ LEFT JOIN `设备_产量计酬` b ON a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh
|
|
|
+ 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);
|
|
|
+ //包装及成品防护数据
|
|
|
+ $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,
|
|
|
+ sczl_cl1,sczl_cl2,sczl_cl3,sczl_cl4,sczl_cl5,sczl_cl6,sczl_PgCl1,sczl_PgCl2,sczl_PgCl3,sczl_PgCl4,sczl_PgCl5,sczl_PgCl6
|
|
|
+ FROM `mesdb`.`db_包装计件` WHERE `sczl_gdbh1` LIKE '%{$order}%' OR `sczl_gdbh2` LIKE '%{$order}%'
|
|
|
+ OR `sczl_gdbh3` LIKE '%{$order}%' OR `sczl_gdbh4` LIKE '%{$order}%' OR `sczl_gdbh5` LIKE '%{$order}%' OR `sczl_gdbh6` LIKE '%{$order}%'";
|
|
|
+ $package = Db::query($sql);
|
|
|
+ $list = [];
|
|
|
+ $j = 0;
|
|
|
+ foreach ($package as $value){
|
|
|
+ for ($i = 1; $i <= 6; $i++) {
|
|
|
+ $gdbhlKey = "sczl_gdbh" . $i;
|
|
|
+ $gxmcKey = "sczl_gxmc" . $i;
|
|
|
+ $clKey = "sczl_cl" . $i;
|
|
|
+ $pgclKey = "sczl_PgCl" . $i;
|
|
|
+ if ($value[$gdbhlKey] == '2311743' && $value[$clKey] > 0) {
|
|
|
+ $list[$j]['sczl_gdbh'] = $value[$gdbhlKey];
|
|
|
+ $list[$j]['sczl_gxmc'] = $value[$gxmcKey];
|
|
|
+ $list[$j]['sczl_cl'] = $value[$clKey];
|
|
|
+ $list[$j]['sczl_PgCl'] = $value[$pgclKey];
|
|
|
+ $j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 创建一个关联数组,用于存储相同 sczl_gxmc 的值和对应的乘积之和
|
|
|
+ $sumArray = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $key = $item['sczl_gxmc'];
|
|
|
+ $cl = floatval($item['sczl_cl']);
|
|
|
+ $pgCl = intval($item['sczl_PgCl']);
|
|
|
+ $product = $cl * $pgCl;
|
|
|
+ if (!isset($sumArray[$key])) {
|
|
|
+ $sumArray[$key] = 0;
|
|
|
+ }
|
|
|
+ $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]['制程废品率'] = '';
|
|
|
+ if ($item['sczl_zcfp'] > 0){
|
|
|
+ $data[$key]['制程废品率'] = number_format($item['sczl_zcfp']/$item['sczl_cl']*100,4).'%';
|
|
|
+ }
|
|
|
+ if ($item['cl'] > 0){
|
|
|
+ $data[$key]['sczl_cl'] = $item['cl'];
|
|
|
+ }
|
|
|
+ if ($item['sczl_Pgcl'] > 0){
|
|
|
+ $data[$key]['sczl_cl'] = $item['sczl_cl'] * $item['sczl_Pgcl'];
|
|
|
+ }
|
|
|
+ if ($item['Gy0_gxh'] == (int)$handGxh){
|
|
|
+ $data[$key]['sczl_cl'] = $handData[0]['cl'];
|
|
|
+ }
|
|
|
+ foreach ($sumArray as $k=>$v){
|
|
|
+ if ($item['Gy0_gxmc'] == $k){
|
|
|
+ $data[$key]['sczl_cl'] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (substr($item['PD_WG'],0,4) == '1900'){
|
|
|
+ $data[$key]['PD_WG'] = '计划';
|
|
|
+ }else{
|
|
|
+ $data[$key]['PD_WG'] = '完工';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->success('请求成功',$data);
|
|
|
+ }
|
|
|
+}
|