Browse Source

报表优化

wufeng 2 years ago
parent
commit
06d20d853b
1 changed files with 822 additions and 66 deletions
  1. 822 66
      app/admin/controller/SaleReport.php

+ 822 - 66
app/admin/controller/SaleReport.php

@@ -2,8 +2,9 @@
 
 namespace app\admin\controller;
 
+use app\abutment\model\SupplierRelationUser;
+use app\abutment\model\SupplierUser;
 use think\facade\Db;
-use think\facade\Validate;
 
 //前端报表处理类
 class SaleReport extends Base
@@ -189,13 +190,12 @@ class SaleReport extends Base
             $list[] = $val;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
-
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('咨询单报表' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
 
-    //【一、管理报表】2.咨询单报表
+    //【一、管理报表】2.竞价反馈报表
     public function consultInfo()
     {
         $param = $this->request->only([
@@ -221,7 +221,7 @@ class SaleReport extends Base
 
         $data = Db::name('consult_info')
             ->alias('ci')
-            ->field('co.creater,ci.addtime,ci.zxNo,csi.companyName,ci.good_name,ci.num,u.unit,ci.budget_price,cb.id bid_id,ci.status,csi.itemid,co.createrid')
+            ->field('co.creater,ci.addtime,ci.infoNo,cb.bidNo,csi.companyName,ci.good_name,ci.num,u.unit,ci.budget_price,cb.id bid_id,ci.status,csi.itemid,co.createrid')
             ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
             ->leftJoin('unit u', 'u.id=ci.unit')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
@@ -231,17 +231,19 @@ class SaleReport extends Base
             ->order('ci.addtime', 'desc')
             ->cursor();
 
-        $list = [];
+        $list = $customer_tmp = $company_tmp = [];
         foreach ($data as $value) {
             $value['total_fee'] = round($value['budget_price'] * $value['num'], 2);
             $value['is_bids'] = is_null($value['bid_id']) ? '否' : '是';
             $value['is_zhuandan'] = $value['status'] == 5 ? '是' : '否';//5成功转单
             if (!empty($value['itemid'])) {
-                $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
-                $value['first_customer_org'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
-                $value['second_customer_org'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
+                if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
+                $value['first_customer_org'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
+                $value['second_customer_org'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
             }
-            $value['creater_company'] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
+
+            if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
+            $value['creater_company'] = $company_tmp[$value['createrid']] ?? '';
             $list[] = $value;
         }
 
@@ -249,7 +251,7 @@ class SaleReport extends Base
 
     }
 
-    //【一、管理报表】2.咨询单报表_导出
+    //【一、管理报表】2.竞价反馈报表_导出
     public function consultInfoExport()
     {
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => ''], 'post', 'trim');
@@ -259,7 +261,7 @@ class SaleReport extends Base
 
         $data = Db::name('consult_info')
             ->alias('ci')
-            ->field('co.creater 创建人,"" 创建人所属部门,ci.addtime 咨询时间,ci.zxNo 咨询单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,ci.good_name 商品名称,ci.num 数量,u.unit 单位,ci.budget_price 单价, "" 金额,cb.id 是否采反,ci.status 是否转单,csi.itemid,co.createrid')
+            ->field('co.creater 创建人,"" 创建人部门,ci.addtime 竞价时间,ci.infoNo 竞价单号,cb.bidNo 反馈编号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,ci.good_name 产品名称,ci.num 数量,u.unit 单位,ci.budget_price 单价, "" 金额,cb.id 是否采反,ci.status 是否转单,csi.itemid,co.createrid')
             ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
             ->leftJoin('unit u', 'u.id=ci.unit')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
@@ -268,17 +270,18 @@ class SaleReport extends Base
             ->order('ci.addtime', 'desc')
             ->cursor();
 
-        $list = [];
+        $list = $customer_tmp = $company_tmp = [];
         foreach ($data as $value) {
-            $value['创建人所属部门'] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
+            if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
+            $value['创建人部门'] = $company_tmp[$value['createrid']] ?? '';
             $value['金额'] = round($value['单价'] * $value['数量'], 2);
             $value['是否采反'] = is_null($value['是否采反']) ? '否' : '是';
             $value['是否转单'] = $value['是否转单'] == 5 ? '是' : '否';//5成功转单
 
             if (!empty($value['itemid'])) {
-                $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
-                $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
-                $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
+                if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
+                $value['一级企业'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
+                $value['二级企业'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
             }
 
             unset($value['createrid']);
@@ -287,9 +290,109 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
 
-        excelSave('咨询单报表' . date('YmdHis'), array_keys($list[0]), $list);
+        excelSave('竞价反馈报表' . date('YmdHis'), array_keys($list[0]), $list);
+
+    }
+
+    //【一、管理报表】2.1.竞价单报表
+    public function consultInfoNew()
+    {
+        $param = $this->request->only([
+            'token',
+            'start_date' => '',
+            'end_date' => '',
+            'page' => 1,
+            'size' => 15,
+        ], 'post', 'trim');
+
+        $where = [['ci.is_del', '=', 0]];
+        if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
+
+        $count = Db::name('consult_info')
+            ->alias('ci')
+            ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
+            ->leftJoin('unit u', 'u.id=ci.unit')
+            ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
+            ->where($where)
+            ->order('ci.addtime', 'desc')
+            ->count('ci.id');
+
+        $data = Db::name('consult_info')
+            ->alias('ci')
+            ->field('co.creater,ci.addtime,ci.infoNo,csi.companyName,ci.good_name,ci.num,u.unit,ci.budget_price,ci.status,csi.itemid,co.createrid')
+            ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
+            ->leftJoin('unit u', 'u.id=ci.unit')
+            ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
+            ->where($where)
+            ->page($param['page'], $param['size'])
+            ->order('ci.addtime', 'desc')
+            ->cursor();
+
+        $list = $customer_tmp = $company_tmp = [];
+        foreach ($data as $value) {
+            $value['total_fee'] = round($value['budget_price'] * $value['num'], 2);
+            $value['is_zhuandan'] = $value['status'] == 5 ? '是' : '否';//5成功转单
+            if (!empty($value['itemid'])) {
+                if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
+                $value['first_customer_org'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
+                $value['second_customer_org'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
+            }
+
+            if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
+            $value['creater_company'] = $company_tmp[$value['createrid']] ?? '';
+            $list[] = $value;
+        }
+
+        return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
+
+    }
+
+    //【一、管理报表】2.1.竞价单报表_导出
+    public function consultInfoNewExport()
+    {
+        $param = $this->request->only([
+            'token',
+            'start_date' => '',
+            'end_date' => '',
+        ], 'post', 'trim');
+
+        $where = [['ci.is_del', '=', 0]];
+        if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
+
+        $data = Db::name('consult_info')
+            ->alias('ci')
+            ->field('co.creater 创建人,"" 创建人部门,ci.addtime 竞价时间,ci.infoNo 竞价单号,"" 一级企业,"" 二级企业,csi.companyName 客户名称,ci.good_name 产品名称,ci.num 数量,u.unit 单位,ci.budget_price 单价, "" 金额,ci.status 是否转单,csi.itemid,co.createrid')
+            ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
+            ->leftJoin('unit u', 'u.id=ci.unit')
+            ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
+            ->where($where)
+            ->order('ci.addtime', 'desc')
+            ->cursor();
+
+        $list = $customer_tmp = $company_tmp = [];
+        foreach ($data as $value) {
+            if (!isset($company_tmp[$value['createrid']])) $company_tmp[$value['createrid']] = get_company_name_by_uid($value['createrid']);//获取创建人的所属部门
+            $value['创建人部门'] = $company_tmp[$value['createrid']] ?? '';
+            $value['金额'] = round($value['单价'] * $value['数量'], 2);
+            $value['是否转单'] = $value['是否转单'] == 5 ? '是' : '否';//5成功转单
+
+            if (!empty($value['itemid'])) {
+                if (!isset($customer_tmp[$value['itemid']])) $customer_tmp[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
+                $value['一级企业'] = isset($customer_tmp[$value['itemid']][1]) ? $customer_tmp[$value['itemid']][1] : '';
+                $value['二级企业'] = isset($customer_tmp[$value['itemid']][2]) ? $customer_tmp[$value['itemid']][2] : '';
+            }
+
+            unset($value['createrid']);
+            unset($value['itemid']);
+
+            $list[] = $value;
+        }
+
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
+
+        excelSave('竞价单报表' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
 
@@ -332,7 +435,8 @@ class SaleReport extends Base
             $value['order_type'] = isset($this->all_order_type[$value['order_type']]) ? $this->all_order_type[$value['order_type']] : '';
             $value['creater_company'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
             if (!isset($cat_tmp[$value['cat_id']])) $cat_tmp[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
-            $value['cat_name'] = $cat_tmp[$value['cat_id']];
+
+            $value['cat_name'] = $cat_tmp[$value['cat_id']] ?? '';
 
             $list[] = $value;
         }
@@ -357,13 +461,15 @@ class SaleReport extends Base
             ->order('s.addtime', 'desc')
             ->cursor();
 
-        $list = $cat_tmp = [];
+        $list = $tmp_customer = $tmp_item = $cat_tmp = [];
         foreach ($data as $value) {
 
             if (!empty($value['itemid'])) {
-                $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
-                $value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
-                $value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
+
+                if (!isset($tmp_customer[$value['itemid']])) $tmp_customer[$value['itemid']] = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
+//                $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
+                $value['一级企业'] = isset($tmp_customer[$value['itemid']][1]) ? $tmp_customer[$value['itemid']][1] : '';
+                $value['二级企业'] = isset($tmp_customer[$value['itemid']][2]) ? $tmp_customer[$value['itemid']][2] : '';
             }
 
             if ($value['订单类型'] == 3 || $value['订单类型'] == 4) {
@@ -383,10 +489,11 @@ class SaleReport extends Base
             $value['是否库存'] = isset($this->all_stock[$value['是否库存']]) ? $this->all_stock[$value['是否库存']] : '';
             $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
 
-            $value['创建人所属部门'] = get_company_name_by_uid($value['apply_id']);//获取创建人的所属部门
+            if (!isset($tmp_item[$value['apply_id']])) $tmp_item[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
+            $value['创建人所属部门'] = $tmp_item[$value['apply_id']];//获取创建人的所属部门
 
             if (!isset($cat_tmp[$value['cat_id']])) $cat_tmp[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
-            $value['分类名称'] = $cat_tmp[$value['cat_id']];
+            $value['分类'] = $cat_tmp[$value['cat_id']] ?? '';
 
             unset($value['itemid']);
             unset($value['apply_id']);
@@ -396,7 +503,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
 
         excelSave('订单报表' . date('YmdHis'), array_keys($list[0]), $list);
 
@@ -502,7 +609,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
 
         excelSave('未发货报表' . date('YmdHis'), array_keys($list[0]), $list);
 
@@ -741,7 +848,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('售后报表' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -832,7 +939,7 @@ class SaleReport extends Base
         }
 
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('产品热销排行' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -851,7 +958,8 @@ class SaleReport extends Base
             ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
             ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
             ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
-            ->leftJoin('company_item item', 'item.id=co.depart')
+            ->leftJoin('depart_user du', 'du.uid=co.saleid AND du.is_del=0')
+            ->leftJoin('company_item item', 'item.id=du.itemid')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
             ->leftJoin('brand b', 'b.id=ci.brand_id')
             ->leftJoin('unit u', 'u.id=ci.unit')
@@ -865,7 +973,8 @@ class SaleReport extends Base
             ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
             ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
             ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
-            ->leftJoin('company_item item', 'item.id=co.depart')
+            ->leftJoin('depart_user du', 'du.uid=co.saleid AND du.is_del=0')
+            ->leftJoin('company_item item', 'item.id=du.itemid')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
             ->leftJoin('brand b', 'b.id=ci.brand_id')
             ->leftJoin('unit u', 'u.id=ci.unit')
@@ -915,7 +1024,8 @@ class SaleReport extends Base
             ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo AND cb.is_del=0')
             ->leftJoin('sale s', 's.zxNo=cb.bidNo AND s.is_del=0')
             ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
-            ->leftJoin('company_item item', 'item.id=co.depart')
+            ->leftJoin('depart_user du', 'du.uid=co.saleid AND du.is_del=0')
+            ->leftJoin('company_item item', 'item.id=du.itemid')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
             ->leftJoin('brand b', 'b.id=ci.brand_id')
             ->leftJoin('unit u', 'u.id=ci.unit')
@@ -947,7 +1057,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('咨询单导出明细' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -1047,7 +1157,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('工差明细表' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -1228,7 +1338,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('退货明细表' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -1326,7 +1436,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('售后明细表' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -1406,7 +1516,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('议价明细表' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -1416,7 +1526,7 @@ class SaleReport extends Base
     {
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
 
-        $where = [['b.is_del', '=', 0], ['b.send_type', '=', 2]];//send_type==2 延迟发
+        $where = [['a.is_del', '=', 0], ['b.send_type', '=', 2], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==2 延迟发货,a.status==4 已全部退
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
         if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
@@ -1431,28 +1541,30 @@ class SaleReport extends Base
             ->leftJoin("business bus", "bus.companyNo=b.supplierNo")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->leftJoin("company_item ci", "ci.id=u.itemid")
-            ->where($where)
+            ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
+            ->leftJoin("supplier e", "e.code=d.supplierNo")->where($where)
             ->order("a.addtime desc")
             ->count('a.id');
 
         $data = Db::name('order_out')
             ->alias('a')
-            ->field('a.addtime,a.orderCode,os.cgdNo,bus.company,a.apply_name,a.apply_id,a.status,a.send_num,b.good_code,b.good_name,v.companyName,b.wsend_num,b.skuCode,b.order_type')
+            ->field('a.addtime,a.orderCode,os.cgdNo,bus.company,a.apply_name,a.apply_id,a.status,a.send_num,b.good_code,b.good_name,v.companyName,b.wsend_num,b.skuCode,b.order_type,e.person')
             ->leftJoin("sale b", "b.orderCode=a.orderCode")
             ->leftJoin("customer_info v", "v.companyNo=b.customer_code")
             ->leftJoin("order_send os", "os.outCode=a.outCode")
             ->leftJoin("business bus", "bus.companyNo=b.supplierNo")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->leftJoin("company_item ci", "ci.id=u.itemid")
-            ->where($where)
+            ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
+            ->leftJoin("supplier e", "e.code=d.supplierNo")->where($where)
             ->page($param['page'], $param['size'])
             ->order("a.addtime desc")
             ->cursor();
 
-        $list = [];
+        $list = $tmp_apply = $tmp_cat = [];
         foreach ($data as $value) {
-
-            $value['apply_company'] = get_company_name_by_uid($value['apply_id']);
+            if (!isset($tmp_apply[$value['apply_id']])) $tmp_apply[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
+            $value['apply_company'] = $tmp_apply[$value['apply_id']];
 
             if ($value['order_type'] == 3 || $value['order_type'] == 4) {
                 $goon = Db::name("good_zixun")
@@ -1468,7 +1580,9 @@ class SaleReport extends Base
                     ->find();
             }
 
-            $value['cat'] = implode('/', array_column(made($goon['cat_id']), 'name'));
+            if (!isset($tmp_cat[$goon['cat_id']])) $tmp_cat[$goon['cat_id']] = implode('/', array_column(made($goon['cat_id']), 'name'));
+            $value['cat'] = $tmp_cat[$goon['cat_id']];
+
             $value['send_date'] = date('Y-m-d H:i:s', strtotime($value['addtime']) + $goon['customized'] * 24 * 3600);
 
             $value['status'] = isset($this->order_out_status[$value['status']]) ? $this->order_out_status[$value['status']] : '';
@@ -1485,7 +1599,7 @@ class SaleReport extends Base
 
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
 
-        $where = [['b.is_del', '=', 0], ['b.send_type', '=', 2]];//send_type==2 延迟发
+        $where = [['a.is_del', '=', 0], ['b.send_type', '=', 2], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==2 延迟发货,a.status==4 已全部退
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
         if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
@@ -1494,21 +1608,24 @@ class SaleReport extends Base
 
         $data = Db::name('order_out')
             ->alias('a')
-            ->field('a.addtime 下单时间,a.orderCode 订单编号,os.cgdNo 采购单编号,bus.company 公司名称,a.apply_name 申请人,"" 部门,a.apply_id,a.status 状态,a.send_num 出库总数,"" 商品分类,b.good_code 商品编码,b.good_name 商品名称,v.companyName 客户名称,b.wsend_num 未发货数量,"" 应发货日期,b.skuCode,b.order_type 订单类型')
+            ->field('a.addtime 下单时间,a.orderCode 订单编号,os.cgdNo 采购单编号,bus.company 公司名称,a.apply_name 申请人,"" 部门,a.apply_id,a.status 状态,a.send_num 出库总数,"" 商品分类,b.good_code 商品编码,b.good_name 商品名称,v.companyName 客户名称,b.wsend_num 未发货数量,"" 应发货日期,b.skuCode,b.order_type 订单类型,e.person 采购员')
             ->leftJoin("sale b", "b.orderCode=a.orderCode")
             ->leftJoin("customer_info v", "v.companyNo=b.customer_code")
             ->leftJoin("order_send os", "os.outCode=a.outCode")
             ->leftJoin("business bus", "bus.companyNo=b.supplierNo")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->leftJoin("purchease_order d", "d.cgdNo=os.cgdNo")
+            ->leftJoin("supplier e", "e.code=d.supplierNo")
             ->where($where)
             ->order("a.addtime desc")
             ->cursor();
 
-        $list = [];
+        $list = $tmp_apply = $tmp_cat = [];
         foreach ($data as $value) {
 
-            $value['部门'] = get_company_name_by_uid($value['apply_id']);
+            if (!isset($tmp_apply[$value['apply_id']])) $tmp_apply[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
+            $value['部门'] = $tmp_apply[$value['apply_id']];
 
             if ($value['订单类型'] == 3 || $value['订单类型'] == 4) {
                 $goon = Db::name("good_zixun")
@@ -1525,7 +1642,9 @@ class SaleReport extends Base
                     ->find();
             }
 
-            $value['商品分类'] = implode('/', array_column(made($goon['cat_id']), 'name'));
+            if (!isset($tmp_cat[$goon['cat_id']])) $tmp_cat[$goon['cat_id']] = implode('/', array_column(made($goon['cat_id']), 'name'));
+            $value['商品分类'] = $tmp_cat[$goon['cat_id']];
+
             $value['应发货日期'] = date('Y-m-d H:i:s', strtotime($value['下单时间']) + $goon['customized'] * 24 * 3600);
 
             $value['状态'] = isset($this->order_out_status[$value['状态']]) ? $this->order_out_status[$value['状态']] : '';
@@ -1537,7 +1656,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('延时发货申请单' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -1547,7 +1666,8 @@ class SaleReport extends Base
     {
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
 
-        $where = [['b.send_type', '=', 1]];//send_type==1 直接发货
+        $where = [['a.is_del', '=', 0], ['b.send_type', '=', 1], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==1 直接发货
+
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
         if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
@@ -1562,19 +1682,21 @@ class SaleReport extends Base
             ->leftJoin("order_addr oa", "oa.id=a.addrid")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->leftJoin("supplier c", "c.code=po.supplierNo")
             ->where($where)
             ->order("a.addtime desc")
             ->count('a.id');
 
         $data = Db::name('order_out')
             ->alias('a')
-            ->field('a.addtime,a.orderCode,a.sendtime,a.outCode,a.status,b.good_name,b.sale_price,a.send_num,a.apply_name,ci.name apply_company,po.cgder,a.post_name,a.post_code,oa.contactor,oa.mobile,oa.addr,oa.addr_code,a.remark,b.order_type')
+            ->field('a.addtime,a.orderCode,a.sendtime,a.outCode,a.status,b.good_name,b.sale_price,a.send_num,a.apply_name,ci.name apply_company,c.person cgder,a.post_name,a.post_code,oa.contactor,oa.mobile,oa.addr,oa.addr_code,a.remark,b.order_type')
             ->leftJoin("sale b", "b.orderCode=a.orderCode")
             ->leftJoin("order_send os", "os.outCode=a.outCode")
             ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo")
             ->leftJoin("order_addr oa", "oa.id=a.addrid")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->leftJoin("supplier c", "c.code=po.supplierNo")
             ->where($where)
             ->page($param['page'], $param['size'])
             ->order("a.addtime desc")
@@ -1602,12 +1724,13 @@ class SaleReport extends Base
 
     }
 
-    //【九、直接发货申请单统计 
+    //【九、直接发货申请单统计-导出
     public function orderOutAddrExport()
     {
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'start_sendtime' => '', 'end_sendtime' => '', 'status' => '', 'apply_company' => '', 'order_type' => ''], 'post', 'trim');
 
-        $where = [['b.send_type', '=', 1]];//send_type==1 直接发货
+        $where = [['a.is_del', '=', 0], ['b.send_type', '=', 1], ['a.send_num', '>', 0], ['a.status', '<>', 4]];//send_type==1 直接发货
+
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['start_sendtime'] != '' && $param['end_sendtime'] != '') $where[] = ['a.sendtime', 'between', [$param['start_sendtime'] . ' 00:00:00', $param['end_sendtime'] . ' 23:59:59']];
         if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
@@ -1616,13 +1739,14 @@ class SaleReport extends Base
 
         $data = Db::name('order_out')
             ->alias('a')
-            ->field('a.addtime 下单日期,a.orderCode 订单编号,a.sendtime 发货时间,a.outCode 发货申请单号,a.status 发货申请单状态,b.good_name 商品名称,b.sale_price 产品单价,a.send_num 发货数量,"" 发货申请单总价,a.apply_name 申请人,ci.name 部门,po.cgder 采购人,a.post_name 快递公司,a.post_code 快递单号,oa.contactor 收货人,oa.mobile 收货电话,oa.addr 收货地址,oa.addr_code,a.remark 备注,b.order_type 订单类型')
+            ->field('a.addtime 下单日期,a.orderCode 订单编号,a.sendtime 发货时间,a.outCode 发货申请单号,a.status 发货申请单状态,b.good_name 商品名称,b.sale_price 产品单价,a.send_num 发货数量,"" 发货申请单总价,a.apply_name 申请人,ci.name 部门,c.person 采购员,a.post_name 快递公司,a.post_code 快递单号,oa.contactor 收货人,oa.mobile 收货电话,oa.addr 收货地址,oa.addr_code,a.remark 备注,b.order_type 订单类型')
             ->leftJoin("sale b", "b.orderCode=a.orderCode")
             ->leftJoin("order_send os", "os.outCode=a.outCode")
             ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo")
             ->leftJoin("order_addr oa", "oa.id=a.addrid")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->leftJoin("supplier c", "c.code=po.supplierNo")
             ->where($where)
             ->order("a.addtime desc")
             ->cursor();
@@ -1630,7 +1754,7 @@ class SaleReport extends Base
         $list = [];
         foreach ($data as $value) {
 
-            $value['发货申请单总价'] = round($value['发货数量'] * $value['产品单价'], 2);
+            $value['发货申请单总价'] = round(bcmul($value['发货数量'], $value['产品单价'], 3), 2);
 
             $value['发货申请单状态'] = isset($this->order_out_status[$value['发货申请单状态']]) ? $this->order_out_status[$value['发货申请单状态']] : '';
             $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
@@ -1648,7 +1772,7 @@ class SaleReport extends Base
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('直接发货申请单统计' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
@@ -1659,7 +1783,7 @@ class SaleReport extends Base
 
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'apply_company' => '', 'page' => 1, 'size' => 15, 'order_type' => ''], 'post', 'trim');
 
-        $where = [['a.send_type', '=', 2], ['a.is_del', '=', 0]];//send_type==2 延迟发货
+        $where = [['a.send_type', '=', 2], ['a.is_del', '=', 0], ['a.status', '<>', 3]];//send_type==2 延迟发货
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
         if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
@@ -1675,12 +1799,32 @@ class SaleReport extends Base
             ->having('a.good_num > SUM(IFNULL(b.receipt_quantity,0)) ')
             ->count('a.id');
 
+        $cgd_sql = Db::name('sale')
+            ->alias('a')
+            ->field('a.orderCode')
+            ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
+            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0 AND u.status=1")
+            ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->where($where)
+            ->order("a.addtime desc")
+            ->buildSql();
+
+        $cgd = Db::name('order_num')
+            ->alias('a')
+            ->leftJoin("purchease_order d", "d.cgdNo=a.cgdNo")
+            ->leftJoin("supplier e", "e.code=d.supplierNo")
+            ->where('a.orderCode IN ' . $cgd_sql)
+            ->column('e.person', 'a.orderCode');
+
         $data = Db::name('sale')
             ->alias('a')
-            ->field('a.id,a.orderCode,a.order_type,a.good_code,a.skuCode,good_name,a.good_num,a.send_num,a.wsend_num,a.status,u.nickname,ci.name,(a.good_num - SUM(IFNULL(b.receipt_quantity,0)) ) as  not_addr_address_good_num')
+            ->field('a.id,a.orderCode,a.order_type,a.good_code,a.skuCode,good_name,a.good_num,a.send_num,a.wsend_num,a.status,u.nickname,ci.name,(a.good_num - SUM(IFNULL(b.receipt_quantity,0)) ) as  not_addr_address_good_num,"" person')
             ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->withAttr('person', function ($val, $da) use ($cgd) {
+                return $cgd[$da['orderCode']] ?? '';
+            })
             ->where($where)
             ->group('a.id,a.orderCode,a.order_type,a.good_code,a.skuCode,good_name,a.good_num,a.send_num,a.wsend_num,a.status,u.nickname,ci.name,b.orderCode')
             ->having('not_addr_address_good_num > 0 ')
@@ -1699,7 +1843,7 @@ class SaleReport extends Base
 
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'status' => '', 'apply_company' => '', 'order_type' => ''], 'post', 'trim');
 
-        $where = [['a.send_type', '=', 2], ['a.is_del', '=', 0]];//send_type==2 延迟发货
+        $where = [['a.send_type', '=', 2], ['a.is_del', '=', 0], ['a.status', '<>', 3]];//send_type==2 延迟发货
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
         if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
@@ -1707,27 +1851,639 @@ class SaleReport extends Base
 
         $data = Db::name('sale')
             ->alias('a')
-            ->field('a.orderCode 订单编号,a.order_type 订单类型,a.good_code 商品成本编码,a.skuCode 商品上线编码,good_name 商品名称,a.good_num 购买数量,a.send_num 已发货数量,a.wsend_num 未发货数量,a.status 订单状态,u.nickname 申请人名称,ci.name 申请人所属部门,(a.good_num - SUM(IFNULL(b.receipt_quantity,0)) ) as  无地址数量')
-            ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
+            ->field('a.orderCode 订单编号,a.order_type 订单类型,a.good_code 商品成本编码,a.skuCode 商品上线编码,a.good_name 商品名称,a.good_num 购买数量,a.send_num 已发货数量,a.wsend_num 未发货数量,a.status 订单状态,u.nickname 申请人名称,ci.name 申请人所属部门,(a.good_num - SUM(IFNULL(b.receipt_quantity,0)) ) as  无地址数量,"" 采购员')
+            ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
+            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0 AND u.status=1")
             ->leftJoin("company_item ci", "ci.id=u.itemid")
             ->where($where)
-            ->group('a.id,a.orderCode,a.order_type,a.good_code,a.skuCode,good_name,a.good_num,a.send_num,a.wsend_num,a.status,u.nickname,ci.name,b.orderCode')
+            ->group('a.id,a.orderCode,a.order_type,a.good_code,a.skuCode,a.good_name,a.good_num,a.send_num,a.wsend_num,a.status,u.nickname,ci.name,b.orderCode')
             ->having('无地址数量 > 0')
             ->order("a.addtime desc")
             ->cursor();
 
+        $cgd_sql = Db::name('sale')
+            ->alias('a')
+            ->field('a.orderCode')
+            ->leftJoin("order_addr b", "b.orderCode=a.orderCode AND b.is_del=0")
+            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0 AND u.status=1")
+            ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->where($where)
+            ->order("a.addtime desc")
+            ->buildSql();
+
+        $cgd = Db::name('order_num')
+            ->alias('a')
+            ->leftJoin("purchease_order d", "d.cgdNo=a.cgdNo")
+            ->leftJoin("supplier e", "e.code=d.supplierNo")
+            ->where('a.orderCode IN ' . $cgd_sql)
+            ->column('e.person', 'a.orderCode');
+
         $list = [];
         foreach ($data as $value) {
 
             $value['订单类型'] = isset($this->all_order_type[$value['订单类型']]) ? $this->all_order_type[$value['订单类型']] : '';
             $value['订单状态'] = isset($this->all_sale_status[$value['订单状态']]) ? $this->all_sale_status[$value['订单状态']] : '';
+            $value['采购员'] = $cgd[$value['订单编号']] ?? '';
 
             $list[] = $value;
         }
 
-        if (empty($list)) $list[] = '没有相关可导出的数据';
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('无地址销售订单列表' . date('YmdHis'), array_keys($list[0]), $list);
 
     }
 
+    //【十一、销售订单商品类型】
+    public function saleMonth()
+    {
+
+        $param = $this->request->only(['token', 'apply_company' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0]];
+        if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
+        if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
+
+        $data = Db::name('sale')
+            ->alias('a')
+            ->field('a.id,a.order_type,u.itemid,ci.name')
+            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
+            ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->where($where)
+            ->cursor();
+        $list = [];
+        $total = ['name' => '总计', 'tag_1' => 0, 'tag_2' => 0, 'tag_3' => 0, 'tag_total' => 0];
+        foreach ($data as $val) {
+            if (!isset($list[$val['itemid']])) $list[$val['itemid']] = [
+                'name' => $val['name'],
+                'tag_1' => 0,
+                'tag_2' => 0,
+                'tag_3' => 0,
+                'tag_total' => 0,
+            ];
+            $list[$val['itemid']]['tag_' . $val['order_type']]++;
+            $list[$val['itemid']]['tag_total']++;
+            $total['tag_' . $val['order_type']]++;
+            $total['tag_total']++;
+
+        }
+        $list = array_merge($list);//重置下标
+        $list[] = $total;
+        return app_show(0, '请求成功', $list);
+
+    }
+
+    //【十一、销售订单商品类型-导出】
+    public function saleMonthExport()
+    {
+
+        $param = $this->request->only(['token', 'apply_company' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0]];
+        if ($param['apply_company'] != '') $where[] = ['ci.name', 'like', '%' . $param['apply_company'] . '%'];
+        if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
+
+        $data = Db::name('sale')
+            ->alias('a')
+            ->field('a.id,a.order_type,u.itemid,ci.name')
+            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
+            ->leftJoin("company_item ci", "ci.id=u.itemid")
+            ->where($where)
+            ->cursor();
+        $list = [];
+        $total = ['部门' => '总计', '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
+        foreach ($data as $k => $val) {
+            if (!isset($list[$val['itemid']])) $list[$val['itemid']] = ['部门' => $val['name'], '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
+
+            switch ($val['order_type']) {
+                case 1:
+                    $list[$val['itemid']]['库存品']++;
+                    $total['库存品']++;
+                    break;
+                case 2:
+                    $list[$val['itemid']]['非库存品']++;
+                    $total['非库存品']++;
+                    break;
+                case 3:
+                    $list[$val['itemid']]['咨询采反']++;
+                    $total['咨询采反']++;
+                    break;
+            }
+
+            $list[$val['itemid']]['总计']++;
+            $total['总计']++;
+
+        }
+        $list = array_merge($list);//重置下标
+        $list[] = $total;
+
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
+        excelSave('销售订单商品类型' . date('YmdHis'), array_keys($list[0]), $list);
+
+    }
+
+    //【十二、采购订单发货维度表】
+    public function orderOutMonth()
+    {
+
+        $param = $this->request->only(['token', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
+        if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
+
+        $data = Db::name('order_out')
+            ->alias('a')
+            ->field('a.id,b.order_type,b.cat_id,d.supplierNo')
+            ->leftJoin('sale b', 'b.orderCode=a.orderCode')
+            ->leftJoin('order_send c', 'c.outCode=a.outCode')
+            ->leftJoin('purchease_order d', 'd.cgdNo=c.cgdNo')
+            ->where($where)
+            ->cursor();
+        $list = [];
+//        $total = ['cat_1' => '总计', 'cat_2' => '', 'cat_3' => '', 'tag_1' => 0, 'tag_2' => 0, 'tag_3' => 0, 'tag_supplier' => 0, 'tag_person' => 0, 'tag_logistics' => 0, 'tag_total' => 0];
+
+        $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
+            ->group('supplierNo')
+            ->column('supplierNo');
+
+        foreach ($data as $val) {
+
+            if (!isset($list[$val['cat_id']])) {
+                $cat = made($val['cat_id']);
+                $list[$val['cat_id']] = [
+                    'cat_1' => $cat[0]['name'] ?? '',
+                    'cat_2' => $cat[1]['name'] ?? '',
+                    'cat_3' => $cat[2]['name'] ?? '',
+                    'tag_1' => 0,
+                    'tag_2' => 0,
+                    'tag_3' => 0,
+                    'tag_supplier' => 0,
+                    'tag_person' => 0,
+                    'tag_logistics' => 0,
+                ];
+            }
+
+            switch ($val['order_type']) {
+                case 1:
+                    //库存品,物流岗发
+                    $list[$val['cat_id']]['tag_logistics']++;
+                    break;
+                case 2: //非库存品
+                case 3: //咨询采反
+                    if (in_array($val['supplierNo'], $supplierNos)) $list[$val['cat_id']]['tag_supplier']++;
+                    else $list[$val['cat_id']]['tag_person']++;
+                    break;
+
+            }
+
+            $list[$val['cat_id']]['tag_' . $val['order_type']]++;
+//            $list[$val['cat_id']]['tag_total']++;
+//            $total['tag_' . $val['order_type']]++;
+//            $total['tag_total']++;
+
+        }
+        $list = array_merge($list);//重置下标
+//        $list[] = $total;
+        return app_show(0, '请求成功', $list);
+
+    }
+
+    //【十二、采购订单发货维度表-导出】
+    public function orderOutMonthExport()
+    {
+        $param = $this->request->only(['token', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
+        if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
+
+        $data = Db::name('order_out')
+            ->alias('a')
+            ->field('a.id,b.order_type,b.cat_id,d.supplierNo')
+            ->leftJoin("sale b", "b.orderCode=a.orderCode")
+            ->leftJoin('order_send c', 'c.outCode=a.outCode')
+            ->leftJoin('purchease_order d', 'd.cgdNo=c.cgdNo')
+            ->where($where)
+            ->cursor();
+
+        $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
+            ->group('supplierNo')
+            ->column('supplierNo');
+
+        $list = [];
+
+//        $total = ['一级分类' => '总计', '二级分类' => '', '三级分类' => '', '库存品' => 0, '非库存品' => 0, '咨询采反' => 0, '总计' => 0];
+        foreach ($data as $val) {
+
+            if (!isset($list[$val['cat_id']])) {
+                $cat = made($val['cat_id']);
+                $list[$val['cat_id']] = [
+                    '一级分类' => $cat[0]['name'] ?? '',
+                    '二级分类' => $cat[1]['name'] ?? '',
+                    '三级分类' => $cat[2]['name'] ?? '',
+                    '库存品' => 0,
+                    '非库存品' => 0,
+                    '咨询采反' => 0,
+                    '供应商发货' => 0,
+                    '负责人发货' => 0,
+                    '物流岗发货' => 0,
+//                    '总计' => 0,
+                ];
+            }
+
+
+            switch ($val['order_type']) {
+                case 1:
+                    $list[$val['cat_id']]['库存品']++;
+//                    $total['库存品']++;
+                    //物流岗发
+                    $list[$val['cat_id']]['物流岗发货']++;
+                    break;
+                case 2:
+                    $list[$val['cat_id']]['非库存品']++;
+//                    $total['非库存品']++;
+                    if (in_array($val['supplierNo'], $supplierNos)) $list[$val['cat_id']]['供应商发货']++;
+                    else $list[$val['cat_id']]['负责人发货']++;
+                    break;
+                case 3:
+                    $list[$val['cat_id']]['咨询采反']++;
+                    if (in_array($val['supplierNo'], $supplierNos)) $list[$val['cat_id']]['供应商发货']++;
+                    else $list[$val['cat_id']]['负责人发货']++;
+//                    $total['咨询采反']++;
+                    break;
+            }
+
+//            $list[$val['cat_id']]['总计']++;
+//            $total['总计']++;
+
+        }
+        $list = array_merge($list);//重置下标
+//        $list[] = $total;
+
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
+        excelSave('采购订单发货维度表' . date('YmdHis'), array_keys($list[0]), $list);
+
+    }
+
+    //【十三、供应商采购订单情况】
+    public function purcheaseOrderMonth()
+    {
+        $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0]];
+        if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
+        if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
+        if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
+
+        $data = Db::name('purchease_order')
+            ->alias('a')
+            ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type')
+            ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
+            ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
+            ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
+            ->where($where)
+            ->cursor();
+        $list = $tmp = [];
+        $total = ['supplier_name' => '总计', 'total_cgd' => 0, 'tag_1' => 0, 'tag_2' => 0, 'tag_c' => 0, 'tag_b' => 0, 'tag_zx' => 0];
+        foreach ($data as $val) {
+
+            if (!isset($list[$val['supplierNo']])) {
+                $list[$val['supplierNo']] = [
+                    'supplier_name' => $val['supplier_name'],
+                    'total_cgd' => 0,//订单总量
+                    'tag_1' => 0,//库存品
+                    'tag_2' => 0,//非库存品
+                    'tag_c' => 0,//to C
+                    'tag_b' => 0,//to B
+                    'tag_zx' => 0,//咨询采反总数
+                ];
+            }
+
+            switch ($val['order_type']) {
+                case 1:
+                    //库存品
+                    if ($val['order_source'] == 0) {
+                        $list[$val['supplierNo']]['tag_1']++;
+                        $total['tag_1']++;
+                    }
+                    break;
+
+                case 2:
+                    //非库存品
+                    $list[$val['supplierNo']]['tag_2']++;
+                    $total['tag_2']++;
+
+                case 3:
+                    //咨询采反
+                    if ($val['order_source'] == 2) {
+                        $list[$val['supplierNo']]['tag_zx']++;
+                        $total['tag_zx']++;
+                    }
+                    break;
+            }
+
+            switch ($val['use_type']) {
+                case 1:
+                    //to B
+                    $list[$val['supplierNo']]['tag_b']++;
+                    $total['tag_b']++;
+                    break;
+
+                case 2:
+                    //to C
+                    $list[$val['supplierNo']]['tag_c']++;
+                    $total['tag_c']++;
+                    break;
+            }
+
+            $list[$val['supplierNo']]['total_cgd']++;
+            $total['total_cgd']++;
+
+        }
+
+//        $list = array_merge($list);//重置下标,关联数组,下标是字符,无法通过array_merge方法重置下标
+
+        foreach ($list as $value) {
+            $tmp[] = $value;
+        }
+        $tmp[] = $total;
+
+        return app_show(0, '请求成功', $tmp);
+
+    }
+
+    //【十三、供应商采购订单情况-导出】
+    public function purcheaseOrderMonthExport()
+    {
+        $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0]];
+
+        if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
+        if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
+        if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
+
+        $data = Db::name('purchease_order')
+            ->alias('a')
+            ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type')
+            ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
+            ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
+            ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
+            ->where($where)
+            ->cursor();
+        $list = $tmp = [];
+        $total = ['采购方' => '总计', '订单总量' => 0, '库存品' => 0, '非库存品' => 0, 'toC' => 0, 'toB' => 0, '反馈单数合计' => 0];
+        foreach ($data as $val) {
+
+            if (!isset($list[$val['supplierNo']])) {
+                $list[$val['supplierNo']] = [
+                    '采购方' => $val['supplier_name'],
+                    '订单总量' => 0,//订单总量
+                    '库存品' => 0,//库存品
+                    '非库存品' => 0,//非库存品
+                    'toC' => 0,//to C
+                    'toB' => 0,//to B
+                    '反馈单数合计' => 0,//咨询采反总数
+                ];
+            }
+
+            switch ($val['order_type']) {
+                case 1:
+                    //库存品
+                    if ($val['order_source'] == 0) {
+                        $list[$val['supplierNo']]['库存品']++;
+                        $total['库存品']++;
+                    }
+                    break;
+
+                case 2:
+                    //非库存品
+                    $list[$val['supplierNo']]['非库存品']++;
+                    $total['非库存品']++;
+                    break;
+
+                case 3:
+                    //咨询采反
+                    if ($val['order_source'] == 2) {
+                        $list[$val['supplierNo']]['反馈单数合计']++;
+                        $total['反馈单数合计']++;
+                    }
+                    break;
+            }
+
+            switch ($val['use_type']) {
+                case 1:
+                    //to B
+                    $list[$val['supplierNo']]['toB']++;
+                    $total['toB']++;
+                    break;
+
+                case 2:
+                    //to C
+                    $list[$val['supplierNo']]['toC']++;
+                    $total['toC']++;
+                    break;
+            }
+
+            $list[$val['supplierNo']]['订单总量']++;
+            $total['订单总量']++;
+
+        }
+
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
+        excelSave('供应商采购订单情况' . date('YmdHis'), array_keys($total), $list);
+
+    }
+
+    //【十四、供应商负责人采购订单情况】
+    public function purcheaseOrderPersonMonth()
+    {
+        $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'flag' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0]];
+
+        if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
+        if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
+        if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
+
+        if ($param['flag'] != '') {
+            $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
+                ->group('supplierNo')
+                ->column('supplierNo');
+            if ($param['flag'] == 1) $where[] = ['a.supplierNo', 'in', $supplierNos];//1.开通账号的
+            else $where[] = ['a.supplierNo', 'not in', $supplierNos];//2.未开通账号的
+        }
+
+        $data = Db::name('purchease_order')
+            ->alias('a')
+            ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type,c.personid,c.person')
+            ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
+            ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
+            ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
+            ->leftJoin("supplier c", "c.code=a.supplierNo AND c.is_del=0")
+            ->where($where)
+            ->cursor();
+
+        $list = [];
+        $total = ['person' => '总计', 'total_cgd' => 0, 'tag_1' => 0, 'tag_2' => 0, 'tag_c' => 0, 'tag_b' => 0, 'tag_zx' => 0];
+        foreach ($data as $val) {
+
+            if (!isset($list[$val['personid']])) {
+                $list[$val['personid']] = [
+                    'person' => $val['person'],
+                    'total_cgd' => 0,//订单总量
+                    'tag_1' => 0,//库存品
+                    'tag_2' => 0,//非库存品
+                    'tag_c' => 0,//to C
+                    'tag_b' => 0,//to B
+                    'tag_zx' => 0,//咨询采反总数
+                ];
+            }
+
+            switch ($val['order_type']) {
+                case 1:
+                    //库存品
+                    if ($val['order_source'] == 0) {
+                        $list[$val['personid']]['tag_1']++;
+                        $total['tag_1']++;
+                    }
+                    break;
+                case 2:
+                    //非库存品
+                    $list[$val['personid']]['tag_2']++;
+                    $total['tag_2']++;
+                    break;
+
+                case 3:
+                    //咨询采反
+                    if ($val['order_source'] == 2) {
+                        $list[$val['personid']]['tag_zx']++;
+                        $total['tag_zx']++;
+                    }
+                    break;
+            }
+
+            switch ($val['use_type']) {
+                case 1:
+                    //to B
+                    $list[$val['personid']]['tag_b']++;
+                    $total['tag_b']++;
+                    break;
+
+                case 2:
+                    //to C
+                    $list[$val['personid']]['tag_c']++;
+                    $total['tag_c']++;
+                    break;
+            }
+
+            $list[$val['personid']]['total_cgd']++;
+            $total['total_cgd']++;
+
+        }
+
+        $list = array_merge($list);//重置下标,关联数组,下标是字符,无法通过array_merge方法重置下标
+
+        $list[] = $total;
+
+        return app_show(0, '请求成功', $list);
+
+    }
+
+    //【十四、供应商负责人采购订单情况-导出】
+    public function purcheaseOrderPersonMonthExport()
+    {
+
+        $param = $this->request->only(['token', 'supplierNo' => '', 'supplier_name' => '', 'flag' => '', 'start_day' => date('Y-m-01'), 'end_day' => date('Y-m-t')], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0]];
+
+        if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
+        if ($param['supplier_name'] != '') $where[] = ['a.supplier_name', 'like', '%' . $param['supplier_name'] . '%'];
+        if ($param['start_day'] != '' && $param['end_day'] != '') $where[] = ['a.addtime', 'between', [$param['start_day'] . ' 00:00:00', $param['end_day'] . ' 23:59:59']];
+
+        if ($param['flag'] != '') {
+            $supplierNos = SupplierRelationUser::where(['is_del' => SupplierUser::$is_del_normal, 'status' => SupplierUser::$status_normal])
+                ->group('supplierNo')
+                ->column('supplierNo');
+            if ($param['flag'] == 1) $where[] = ['a.supplierNo', 'in', $supplierNos];//1.开通账号的
+            else $where[] = ['a.supplierNo', 'not in', $supplierNos];//2.未开通账号的
+        }
+
+        $data = Db::name('purchease_order')
+            ->alias('a')
+            ->field('a.id,a.supplierNo,a.supplier_name,a.order_type,a.order_source,p.use_type,c.personid,c.person')
+            ->leftJoin("order_num b", "b.cgdNo=a.cgdNo")
+            ->leftJoin("sale s", "s.orderCode=b.orderCode AND s.is_del=0")
+            ->leftJoin("platform p", "p.id=s.platform_id AND p.is_del=0")
+            ->leftJoin("supplier c", "c.code=a.supplierNo AND c.is_del=0")
+            ->where($where)
+            ->cursor();
+        $list = [];
+        $total = ['采购方' => '总计', '订单总量' => 0, '库存品' => 0, '非库存品' => 0, 'toC' => 0, 'toB' => 0, '反馈单数合计' => 0];
+        foreach ($data as $val) {
+
+            if (!isset($list[$val['personid']])) {
+                $list[$val['personid']] = [
+                    '采购方' => $val['person'],
+                    '订单总量' => 0,//订单总量
+                    '库存品' => 0,//库存品
+                    '非库存品' => 0,//非库存品
+                    'toC' => 0,//to C
+                    'toB' => 0,//to B
+                    '反馈单数合计' => 0,//咨询采反总数
+                ];
+            }
+
+            switch ($val['order_type']) {
+                case 1:
+                    //库存品
+                    if ($val['order_source'] == 0) {
+                        $list[$val['personid']]['库存品']++;
+                        $total['库存品']++;
+                    }
+
+                    break;
+
+                case 2:
+                    //非库存品
+                    $list[$val['personid']]['非库存品']++;
+                    $total['非库存品']++;
+                    break;
+
+                case 3:
+                    //咨询采反
+                    if ($val['order_source'] == 2) {
+                        $list[$val['personid']]['反馈单数合计']++;
+                        $total['反馈单数合计']++;
+                    }
+
+                    break;
+            }
+
+            switch ($val['use_type']) {
+                case 1:
+                    //to B
+                    $list[$val['personid']]['toB']++;
+                    $total['toB']++;
+                    break;
+
+                case 2:
+                    //to C
+                    $list[$val['personid']]['toC']++;
+                    $total['toC']++;
+                    break;
+            }
+
+            $list[$val['personid']]['订单总量']++;
+            $total['订单总量']++;
+
+        }
+
+        $list[] = $total;
+
+        if (empty($list)) $list[] = ['没有相关可导出的数据'];
+        excelSave('供应商负责人采购订单情况' . date('YmdHis'), array_keys($total), $list);
+
+    }
+
+
 }