setter
parent
004c23726e
commit
ae7c467ada
|
@ -297,10 +297,8 @@ class Order extends Base
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($this->request->isPost()) {
|
if ($this->request->isPost()) {
|
||||||
$businessRemarks = trim(input('business_remarks/s', ''));
|
$data = input("item/a",[]);
|
||||||
|
$item->save($data);
|
||||||
$item->save(['business_remarks' => $businessRemarks]);
|
|
||||||
|
|
||||||
return $this->json();
|
return $this->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,6 +580,7 @@ class Order extends Base
|
||||||
public function exportOrderInfo()
|
public function exportOrderInfo()
|
||||||
{
|
{
|
||||||
$id = input("id/d");
|
$id = input("id/d");
|
||||||
|
$type = input("type/s","save");
|
||||||
$order = OrderModel::findById($id, [], function ($q) {
|
$order = OrderModel::findById($id, [], function ($q) {
|
||||||
return $q->with([ 'skus']);
|
return $q->with([ 'skus']);
|
||||||
});
|
});
|
||||||
|
@ -697,18 +696,56 @@ class Order extends Base
|
||||||
//第一种保存方式
|
//第一种保存方式
|
||||||
$writer = new Xlsx($spreadsheet);
|
$writer = new Xlsx($spreadsheet);
|
||||||
//保存的路径可自行设置
|
//保存的路径可自行设置
|
||||||
$path = public_path()."storage/order_excel/" ;
|
$path = "storage/order_excel/" ;
|
||||||
if(!is_writable($path)){
|
if(!is_writable($path)){
|
||||||
return $this->json(4001,"上传文件夹需要写入权限");
|
return $this->json(4001,"上传文件夹需要写入权限");
|
||||||
}
|
}
|
||||||
$path.=date("Ymd")."/";
|
$path.=date("Ymd")."/";
|
||||||
if(!is_dir($path)){
|
if(!is_dir(public_path().$path)){
|
||||||
mkdir($path);
|
mkdir(public_path().$path);
|
||||||
}
|
}
|
||||||
$downloadFileName = $order->contacts . "_" . $order->phone . "_" . $order->coding ;
|
$downloadFileName = $order->contacts . "_" . $order->phone . "_" . $order->coding ;
|
||||||
$fileName = $downloadFileName . ".xlsx";
|
$fileName = $downloadFileName . ".xlsx";
|
||||||
$filepath = $path. $fileName;
|
$filepath = public_path().$path. $fileName;
|
||||||
$writer->save($filepath);
|
$writer->save($filepath);
|
||||||
|
if($type =="save"){
|
||||||
return download($filepath,$downloadFileName );
|
return download($filepath,$downloadFileName );
|
||||||
|
}else{
|
||||||
|
return $this->json(0,"success",["url"=>$path.$fileName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出订单信息
|
||||||
|
* */
|
||||||
|
public function exportOrderInfoZip()
|
||||||
|
{
|
||||||
|
$urls = input("urls/s",'');
|
||||||
|
$urls = array_filter(explode(",", $urls));
|
||||||
|
if(empty($urls)){
|
||||||
|
return $this->json("4001","空的文件");
|
||||||
|
} if(count($urls)>10){
|
||||||
|
return $this->json("4001","最多支持10个文件");
|
||||||
|
}
|
||||||
|
$zipdir = date("Ymd_His_") .randomStr();
|
||||||
|
$downloadZipFilename = $zipdir. '.zip';
|
||||||
|
$zipFilename = public_path() . 'storage/order_excel_zip/' . $downloadZipFilename;
|
||||||
|
$zip = new \ZipArchive();
|
||||||
|
// 打开一个zip文档,ZipArchive::OVERWRITE:如果存在这样的文档,则覆盖;ZipArchive::CREATE:如果不存在,则创建
|
||||||
|
$res = $zip->open($zipFilename, $zip::OVERWRITE | $zip::CREATE);
|
||||||
|
$zip->addEmptyDir($zipdir);
|
||||||
|
if($res){
|
||||||
|
foreach ($urls as $url) {
|
||||||
|
$filrnamearr = explode("/",$url);
|
||||||
|
$filrname = end($filrnamearr);
|
||||||
|
$zip->addFile(public_path() . $url, $zipdir . "/" . $filrname);
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
return download($zipFilename, $downloadZipFilename);
|
||||||
|
}
|
||||||
|
return $this->json(5001,"创建压缩文件失败");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue