|
|
@@ -23,6 +23,7 @@ use App\Shop;
|
|
|
use App\UserWorkgroup;
|
|
|
use Exception;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Arr;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
@@ -587,4 +588,147 @@ class OrderIssueController extends Controller
|
|
|
return ['success'=>false,'fail_info'=>$e->getMessage()];
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function exportJsonExcel(Request $request)
|
|
|
+ {
|
|
|
+ if (!Gate::allows('订单管理-问题件-查询')) {
|
|
|
+ return redirect(url('/'));
|
|
|
+ }
|
|
|
+ $params = $request->input();
|
|
|
+ if ($request->checkAllSign){
|
|
|
+ $params = $request->input();
|
|
|
+ unset($params['checkAllSign']);
|
|
|
+ }else{
|
|
|
+ $params['id'] = $request['data'];
|
|
|
+ $params['is_handle'] = true;
|
|
|
+ }
|
|
|
+ /** @var OrderIssueService $service */
|
|
|
+ $service = app('OrderIssueService');
|
|
|
+
|
|
|
+ $order_Issues = $service->getJsonObj($params);
|
|
|
+ $json = [];
|
|
|
+ $row = [
|
|
|
+ '登记日期','创建日期','客户','客户订单号','原始承运商','收货人','收货电话','省','市','区','收货人地址',
|
|
|
+ '原始运单号','原始商品','原始商品名称','原始商品数量',
|
|
|
+ '退单备注','退单商品名','退单商品条码','退单商品数量','退单状态',
|
|
|
+ '操作类型','说明','操作者','情况说明','问题类别',
|
|
|
+ '二次订单号','二次承运商','二次运单号','二次商品条码','二次商品名','二次商品数量',
|
|
|
+ '最终状态', '承运商赔偿金额', '承运商快递减免', '宝时赔偿金额', '宝时快递减免','事故责任方'
|
|
|
+ ];
|
|
|
+ $count = null;
|
|
|
+ $row_count = 0;
|
|
|
+ $start_row= 0;
|
|
|
+ $mergeRow = []; //合并规则
|
|
|
+ $row_number = 2;
|
|
|
+ $order_Issues->each(function ($order_issue)use(&$json,&$row_number,&$mergeRow){
|
|
|
+ $order = $order_issue->order;
|
|
|
+ $send_order = $order_issue->secondOrder ?? new Order();
|
|
|
+ $logs = $order_issue->logs ?? collect();
|
|
|
+ $issueType = $order_issue->issueType->name;
|
|
|
+ $rejectedBill = $order_issue->rejectedBill ?? new RejectedBill();
|
|
|
+ // 订单信息
|
|
|
+ $order_logistic_number = [];
|
|
|
+ $order_info = [];
|
|
|
+ $order->packages->each(function($package)use(&$order_logistic_number,&$order_info){
|
|
|
+ $order_logistic_number [] = $package->logistic_number;
|
|
|
+ $package->commodities->each(function($commodities)use(&$order_info){
|
|
|
+ $sku = $commodities->commodity;
|
|
|
+ if($sku?? false)
|
|
|
+ $order_info[]=['sku'=>$sku->sku,'sku_name'=>$sku->name,'amount'=>$commodities->amount];
|
|
|
+ });
|
|
|
+ });
|
|
|
+ // 二次订单信息
|
|
|
+ $send_order_logistic_number = [];
|
|
|
+ $send_order_info = [];
|
|
|
+ $send_order->packages->each(function($package)use(&$send_order_logistic_number,&$send_order_info){
|
|
|
+ $send_order_logistic_number [] = $package->logistic_number;
|
|
|
+ $package->commodities->each(function($commodities)use(&$send_order_info){
|
|
|
+ $sku = $commodities->commodity;
|
|
|
+ if($sku?? false)
|
|
|
+ $send_order_info[] = ['send_sku'=>$sku->sku ?? '','send_sku_name'=>$sku->name ?? '','send_amount'=>$commodities->amount ?? ''];
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 退回单信息
|
|
|
+ $rejected_Bill_info = [];
|
|
|
+ $rejected_Bill_remark =$rejectedBill->remark ?? '';
|
|
|
+ $rejectedBill->items->each(function($item)use(&$rejected_Bill_info){
|
|
|
+ $rejected_Bill_info[] = ['rejected_item_name'=>$item->name_goods,'rejected_item_barcode'=>$item->barcode_goods,'rejected_item_amount'=>$item->amount];
|
|
|
+ });
|
|
|
+ $logs_info = [];
|
|
|
+ $logs->each(function($log)use(&$logs_info){
|
|
|
+ $logs_info[] = ['log_type'=>$log->type,'log_content'=>$log->content,'log_user'=>$log->user->name];
|
|
|
+ });
|
|
|
+ $rows = [count($rejected_Bill_info),count($logs_info),count($send_order_info),count($order_info)];
|
|
|
+ $max_rows = max($rows);
|
|
|
+ $start_row = $row_number;
|
|
|
+ for ($index =0 ;$index<$max_rows ;$index++){
|
|
|
+ $json[] = [
|
|
|
+ $order_issue->created_at, // 登记日期
|
|
|
+ $order->created_at, // 创建日期
|
|
|
+ $order->owner->name ?? '', // 客户
|
|
|
+ $order->client_code, // 客户订单号
|
|
|
+ $order->logistic->name ?? '', // 原始承运商
|
|
|
+ $order->consignee_name, // 收货人
|
|
|
+ $order->consignee_phone, // 收货电话
|
|
|
+ $order->province, // 省
|
|
|
+ $order->city, // 市
|
|
|
+ $order->district, // 区
|
|
|
+ $order->address, // 收货人地址
|
|
|
+
|
|
|
+ $order_logistic_number[$index]??'', //原始运单号
|
|
|
+ $order_info[$index]['sku']??'', //原始商品
|
|
|
+ $order_info[$index]['sku_name']??'', //原始商品名称
|
|
|
+ $order_info[$index]['amount']??'', //原始商品数量
|
|
|
+
|
|
|
+ //'退单备注','退单商品名','退单商品条码','退单商品数量','退单状态',
|
|
|
+ $rejected_Bill_remark, // 退单备注
|
|
|
+ $rejected_Bill_info[$index]['rejected_item_name'] ?? '', // 退单商品名
|
|
|
+ $rejected_Bill_info[$index]['rejected_item_barcode'] ?? '' , // 退单商品条码
|
|
|
+ $rejected_Bill_info[$index]['rejected_item_amount'] ?? '', // 退单商品数量
|
|
|
+ $order_issue->rejecting_status , // 退单状态
|
|
|
+
|
|
|
+ // '操作类型','情况说明','问题类别',
|
|
|
+ $logs_info[$index]['log_type'] ?? '', //操作类型
|
|
|
+ $logs_info[$index]['log_content'] ?? '', //情况说明
|
|
|
+ $logs_info[$index]['log_user'] ?? '', //操作者
|
|
|
+
|
|
|
+ // '情况说明','问题类别',
|
|
|
+ $order_issue->result_explain, // 情况说明
|
|
|
+ $order_issue->issueType->name ?? '', // 问题类别
|
|
|
+
|
|
|
+ // '二次订单号','二次承运商','二次运单号','二次商品条码','二次商品名','二次商品数量',
|
|
|
+ $order_issue->secondOrder->client_code ?? '', //二次订单号
|
|
|
+ $order_issue->secondOrder->logistic->name ?? '', //二次承运商
|
|
|
+ $send_order_logistic_number[$index] ?? '' , //二次运单号
|
|
|
+ $send_order_info[$index]['send_sku'] ?? '', // 二次商品条码
|
|
|
+ $send_order_info[$index]['send_sku_name'] ?? '', // 二次商品名
|
|
|
+ $send_order_info[$index]['send_amount'] ?? '', // 二次商品数量
|
|
|
+
|
|
|
+ //'最终状态', '承运商赔偿金额', '承运商快递减免', '宝时赔偿金额', '宝时快递减免','事故责任方'
|
|
|
+ $order_issue->final_status??'',
|
|
|
+ $order_issue->logistic_indemnity_money ,
|
|
|
+ $order_issue->logistic_express_remission,
|
|
|
+ $order_issue->baoshi_indemnity_money,
|
|
|
+ $order_issue->baoshi_express_remission,
|
|
|
+ $order_issue->userWorkGroup->name ?? '',
|
|
|
+ ];
|
|
|
+ $row_number++;
|
|
|
+ }
|
|
|
+ if($max_rows>1){
|
|
|
+ $mergeRow[(string)($start_row)] =(string)($row_number-1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $mergeColumn = ['A','B','C','D','E','F','G','H','I','J','K','L','P','T','X','Y','Z','AA','AF','AG','AH','AI','AJ','AK']; // 合并行
|
|
|
+ $post=Http::post(config('go.export.url'),['type'=>'base','data'=>json_encode(['row'=>$row,'list'=>$json,'mergeColumn'=>$mergeColumn,'mergeRow'=>$mergeRow],JSON_UNESCAPED_UNICODE),'createFormat'=>'merge']);
|
|
|
+// $post=Http::post(config('go.export.url'),['type'=>'base','data'=>json_encode(['row'=>$row,'list'=>$json],JSON_UNESCAPED_UNICODE)]);
|
|
|
+
|
|
|
+ if ($post->status() == 500){
|
|
|
+ throw new Exception($post->header("Msg"));
|
|
|
+ }
|
|
|
+ return response($post,200, [
|
|
|
+ "Content-type"=>"application/octet-stream",
|
|
|
+ "Content-Disposition"=>"attachment; filename=订单问题件-".date('ymdHis').'.xlsx',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
}
|