Browse Source

复用订单批量导出接口

wufeng 2 years ago
parent
commit
1d51e65860
2 changed files with 87 additions and 0 deletions
  1. 84 0
      app/abutment/controller/Order.php
  2. 3 0
      app/abutment/route/app.php

+ 84 - 0
app/abutment/controller/Order.php

@@ -810,5 +810,89 @@ class Order extends HomeBaseController
         }
     }
 
+    //导出
+    public function exportCgdList()
+    {
+        $cgdNos = $this->request->post('cgdNos', [], 'trim');
+
+        if (empty($cgdNos)) return json_show(1004, '要导出的采购单编号不能为空');
+
+        $i = 1;
+        $send_type = [1 => '直接发货', 2 => '延时发货'];
+        $status = [0 => '待与供应商确认', 1 => '待入库', 2 => '部分入库', 3 => '入库完成', 4 => '已取消订单'];
+        $list = Db::name("purchease_order")
+            ->alias('po')
+            ->field('"" as 序号,po.addtime as 创建时间,po.cgdNo as 采购单编号,po.status as 采购单状态,po.cgder as 采购员,s.orderCode as 确认单号,s.addtime as 确认单时间,po.spuCode as 产品编号,po.good_name as 产品名称,"" as 规格,"" as 单位,po.supplier_name as 供应商名称,po.supplierNo as 供应商编号,po.nake_fee as 裸价,po.delivery_fee as 物流费,s.send_type as 发货方式,po.good_price as 采购单价,s.remark as 确认单备注,po.good_num as 采购数量,po.total_fee as 采购货款,b.company as 购买方公司,s.arrive_time as 到货时间,"" 税率,oa.addr 收货地址,oa.mobile 电话,oa.contactor 联系人,s.platform_order 平台订单编号,oa.receipt_quantity 地址发货数量, oa.addr_code,po.order_type')
+            ->whereIn('po.cgdNo', $cgdNos)
+            ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
+            ->leftJoin('sale s', 's.orderCode=on.orderCode  AND s.is_del=0')
+            ->leftJoin('order_addr oa', 'oa.orderCode=on.orderCode AND oa.is_del=0')
+            ->leftJoin('business b', 'b.companyNo=s.supplierNo AND b.is_del=0')
+            ->order("po.addtime desc")
+            ->withAttr('序号', function () use (&$i) {
+                return $i++;
+            })->withAttr('采购单状态', function ($val) use ($status) {
+                return isset($status[$val]) ? $status[$val] : '';
+            })->withAttr('发货方式', function ($val) use ($send_type) {
+                return isset($send_type[$val]) ? $send_type[$val] : '';
+            })->withAttr('发货方式', function ($val) use ($send_type) {
+                return isset($send_type[$val]) ? $send_type[$val] : '';
+            })
+            ->select()
+            ->toArray();
+
+        foreach ($list as &$value) {
+
+            if ($value['order_type'] == 3) {
+                $temp = Db::name("good_zixun")
+                    ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
+                    ->field('id,specinfo,good_unit,tax')
+                    ->find();
+                $good_unit = isset($temp['good_unit']) ? $temp['good_unit'] : 0;
+                $specinfo = isset($temp['specinfo']) ? json_decode($temp['specinfo'], true) : [];
+
+                $speclist = [];
+                foreach ($specinfo as $val) {
+                    $speclist[] = $val['spec_name'] . ':' . $val['spec_value_name'];
+                }
+                $value['税率'] = $temp['tax'] . '%';
+            } else {
+                $good_unit = Db::name('good_basic')
+                    ->field('id,good_unit,tax')
+                    ->where(['spuCode' => $value['产品编号']])
+                    ->find();
+                $spec = Db::name("good_spec")
+                    ->field('id,spec_id,spec_value_id')
+                    ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
+                    ->select()
+                    ->toArray();
+                $speclist = [];
+                if (!empty($spec)) {
+                    foreach ($spec as $val) {
+                        $speclist[] = Db::name("specs")->where(["id" => $val['spec_id']])->value('spec_name', '') . ':' . Db::name("spec_value")->where(["id" => $val['spec_value_id']])->value('spec_value', '');
+
+                    }
+                }
+                $value['税率'] = isset($good_unit['tax']) ? $good_unit['tax'] . '%' : '';
+            }
+
+            $value['规格'] = empty($speclist) ? '' : implode(',', $speclist);;
+            $value['单位'] = isset($good_unit['good_unit']) ? Db::name('unit')->where(['id' => $good_unit['good_unit'], 'is_del' => 0])->value('unit', '') : '';
+
+            if (!empty($value['addr_code'])) {
+                $temp = explode(',', $value['addr_code']);
+                $temp_ = GetAddr(json_encode(['provice_code' => $temp[0], 'city_code' => $temp[1], 'area_code' => $temp[2]]));
+                $value['收货地址'] = $temp_ . $value['收货地址'];
+            }
+
+            unset($value['addr_code']);
+            unset($value['order_type']);
+
+        }
+
+        $headerArr = array_keys($list[0]);
+        excelSave('采购单导出' . date('YmdHis'), $headerArr, $list);
+    }
+
 
 }

+ 3 - 0
app/abutment/route/app.php

@@ -45,6 +45,9 @@ route::rule('getOrderList', 'abutment/Order/getList');//列表
 route::rule('getOrderInfo', 'abutment/Order/info');//详情
 route::rule('changeOrderStatus', 'abutment/Order/status');//订单确认
 route::rule('addOrderIn', 'abutment/Order/add');//订单批量入库
+route::rule('exportCgdList', 'abutment/Order/exportCgdList');//订单批量导出
+
+
 route::rule('saleOutList', 'abutment/Sale/saleout');//发货单列表
 route::rule('saleOutInfo', 'abutment/Sale/saleOutInfo');//发货单详情
 route::rule('outSend', 'abutment/Sale/outSend');//发货单库管发货