Browse Source

复用发货申请单导出接口

wufeng 2 years ago
parent
commit
40b3f22cbb
2 changed files with 85 additions and 0 deletions
  1. 84 0
      app/abutment/controller/Sale.php
  2. 1 0
      app/abutment/route/app.php

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

@@ -550,5 +550,89 @@ class Sale extends BaseController
         return json_show(0, "获取成功", $order);
     }
 
+    //发货申请单导出
+    public function exportSaleOut()
+    {
+        $outCodes = $this->request->filter('trim')->post('outCodes');
+
+        if (empty($outCodes)) return json_show(1004, '要导出的发货申请单编号不能为空');
+
+        $i = 1;
+        $send_type = [1 => '直接发货', 2 => '延时发货'];
+        $status = [0 => '待发货', 1 => '待库管发货', 2 => '已发货待收货', 3 => '已收货', 4 => '已全部退货'];
+        $list = Db::name("order_out")
+            ->alias('a')
+            ->field('"" as 序号,a.addtime as 创建时间,po.cgdNo as 采购单编号,po.status as 采购单状态,po.cgder as 采购员,b.orderCode as 确认单号,b.addtime as 确认单时间,b.good_code as 产品编号,b.good_name as 产品名称,"" as 规格,"" as 单位,wi.name as 供应商名称,s.code as 供应商编号,po.nake_fee as 裸价,a.post_fee as 物流费,b.send_type as 发货方式,po.good_price as 采购单价,b.remark as 确认单备注,po.good_num as 采购数量,po.total_fee as 采购货款,a.send_num 发货数量,oa.contactor as 收货人,oa.mobile as 联系方式,oa.addr as 收货地址,oa.addr_code,oa.arrive_time as 到货时间,a.outCode as 发货申请单号,po.order_type,b.platform_order 平台订单号,a.post_name 发货申请单物流公司,a.post_code 发货申请单物流单号,a.post_fee 发货申请单物流费用,a.remark 发货申请单备注,a.apply_name 申请人,b.cat_id 商品分类')
+            ->whereIn('a.outCode', $outCodes)
+            ->order("a.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] : '';
+            })->where("a.is_del", "=", 0)
+            ->leftJoin("sale b", "b.orderCode=a.orderCode")
+            ->leftJoin("order_addr oa", "oa.id=a.addrid AND oa.is_del=0")
+            ->leftJoin("warehouse_info wi", "wi.wsm_code=a.wsm_code AND wi.is_del=0")
+            ->leftJoin("supplier s", "s.code=wi.supplierNo AND s.is_del=0")
+            ->leftJoin('order_send os', 'os.outCode=a.outCode ')
+            ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo AND po.is_del=0")
+            ->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')
+                    ->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'];
+                }
+            } else {
+                $good_unit = Db::name('good_basic')
+                    ->where(['spuCode' => $value['产品编号']])
+                    ->value('good_unit', 0);
+                $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['规格'] = empty($speclist) ? '' : implode(',', $speclist);;
+            $value['单位'] = $good_unit ? Db::name('unit')->where(['id' => $good_unit, 'is_del' => 0])->value('unit', '') : '';
+            $value['商品分类'] = implode('/', array_column(made($value['商品分类']), 'name'));
+            $value['发货申请单物流单号'] = ' ' . $value['发货申请单物流单号'];//添加空格防止将数字转为科学计数法(比如,韵达的快递单号就是纯数字)
+            $addinfo =$value['addr_code']!=''?json_decode($value['addr_code'],true)??$value['addr_code']: '' ;
+            if(is_string($addinfo)&&$addinfo!=''){
+                $addinfo=["provice_code"=>'',"city_code"=>'',"area_code"=>''];
+                list($addinfo['provice_code'],$addinfo['city_code'],$addinfo['area_code']) = explode(",",$value['addr_code']);
+            }
+            $addr_cn =GetAddr(json_encode($addinfo));
+
+            $value['收货地址'] = $addr_cn.$value['收货地址'];
+            unset($value['order_type']);
+            unset($value['addr_code']);
+        }
+
+        if (empty($list)) $list[] = '没有可供导出的数据';
+
+        $headerArr = array_keys($list[0]);
+        excelSave('发货申请单导出' . date('YmdHis'), $headerArr, $list);
+    }
+
 
 }

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

@@ -39,6 +39,7 @@ route::rule('saleOutInfo', 'abutment/Sale/saleOutInfo');//发货单详情
 route::rule('outSend', 'abutment/Sale/outSend');//发货单库管发货
 route::rule('outSendBatchByImport', 'abutment/Sale/saleOutInfo');//发货单库管批量发货
 route::rule('goodZxInfo', 'abutment/Sale/goodzxinfo');//咨询商品详情
+route::rule('exportSaleOut', 'abutment/Sale/exportSaleOut');//发货申请单导出
 
 //竞价单
 route::rule('crontabList', 'abutment/Consult/crontablist');//招标工作台列表