update
This commit is contained in:
parent
3ee1960a59
commit
c78701aea0
@ -59,14 +59,19 @@
|
||||
return $this->fail(FinancialInvoiceLogic::getError());
|
||||
}
|
||||
|
||||
public function upload()
|
||||
public function download()
|
||||
{
|
||||
$params = (new FinancialInvoiceValidate())->post()->goCheck('upload');
|
||||
$result = FinancialInvoiceLogic::upload($params);
|
||||
if (true === $result) {
|
||||
return $this->success('上传成功', [], 1, 1);
|
||||
$params = (new FinancialInvoiceValidate())->post()->goCheck('detail');
|
||||
$result = FinancialInvoiceLogic::download($params);
|
||||
if (false === $result) {
|
||||
return $this->fail(FinancialInvoiceLogic::getError());
|
||||
}
|
||||
return $this->fail(FinancialInvoiceLogic::getError());
|
||||
header("Content-Type: application/zip");
|
||||
header("Content-Transfer-Encoding: Binary");
|
||||
header("Content-Length: " . filesize($result));
|
||||
header("Content-Disposition: attachment; filename=\"" . basename($result) . "\"");
|
||||
readfile($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,14 +76,19 @@
|
||||
return $this->fail(FinancialRefundLogic::getError());
|
||||
}
|
||||
|
||||
public function upload()
|
||||
public function download()
|
||||
{
|
||||
$params = (new FinancialRefundValidate())->post()->goCheck('upload');
|
||||
$result = FinancialRefundLogic::upload($params);
|
||||
if (true === $result) {
|
||||
return $this->success('上传成功', [], 1, 1);
|
||||
$params = (new FinancialRefundValidate())->post()->goCheck('detail');
|
||||
$result = FinancialRefundLogic::download($params);
|
||||
if (false === $result) {
|
||||
return $this->fail(FinancialRefundLogic::getError());
|
||||
}
|
||||
return $this->fail(FinancialRefundLogic::getError());
|
||||
header("Content-Type: application/zip");
|
||||
header("Content-Transfer-Encoding: Binary");
|
||||
header("Content-Length: " . filesize($result));
|
||||
header("Content-Disposition: attachment; filename=\"" . basename($result) . "\"");
|
||||
readfile($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
use app\common\model\marketing\MarketingContract;
|
||||
use app\common\model\marketing\MarketingCustom;
|
||||
use think\facade\Db;
|
||||
use ZipArchive;
|
||||
|
||||
|
||||
/**
|
||||
@ -114,18 +115,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
public static function upload(array $params): bool
|
||||
public static function download(array $params): bool|string
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
FinancialInvoice::where('id', $params['id'])->update([
|
||||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||||
'update_time' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
$data = FinancialInvoice::field('annex')->where('id', $params['id'])->findOrEmpty();
|
||||
if ($data->isEmpty() || !$data['annex']) {
|
||||
self::setError("文件为空");
|
||||
return false;
|
||||
}
|
||||
$zipname = 'uploads/financial_invoice_' . $params['id'] . '.zip';
|
||||
if (file_exists($zipname)) {
|
||||
return $zipname;
|
||||
}
|
||||
$files = [];
|
||||
foreach ($data['annex'] as $v) {
|
||||
if (!empty($v['uri'])) {
|
||||
$file = explode('uploads', $v['uri']);
|
||||
$files[] = 'uploads' . $file[1];
|
||||
}
|
||||
}
|
||||
$zip = new ZipArchive();
|
||||
$res = $zip->open($zipname, ZipArchive::CREATE);
|
||||
if ($res === TRUE) {
|
||||
foreach ($files as $file) {
|
||||
if (file_exists($file)) {
|
||||
$new_filename = substr($file, strrpos($file, '/') + 1);
|
||||
$zip->addFile($file, $new_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
return $zipname;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
use app\common\model\marketing\MarketingContract;
|
||||
use app\common\model\marketing\MarketingCustom;
|
||||
use think\facade\Db;
|
||||
use ZipArchive;
|
||||
|
||||
|
||||
/**
|
||||
@ -96,18 +97,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
public static function upload(array $params): bool
|
||||
public static function download(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
FinancialRefund::where('id', $params['id'])->update([
|
||||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||||
'update_time' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
$data = FinancialRefund::field('annex')->where('id', $params['id'])->findOrEmpty();
|
||||
if ($data->isEmpty() || !$data['annex']) {
|
||||
self::setError("文件为空");
|
||||
return false;
|
||||
}
|
||||
$zipname = 'uploads/financial_refund_' . $params['id'] . '.zip';
|
||||
if (file_exists($zipname)) {
|
||||
return $zipname;
|
||||
}
|
||||
$files = [];
|
||||
foreach ($data['annex'] as $v) {
|
||||
if (!empty($v['uri'])) {
|
||||
$file = explode('uploads', $v['uri']);
|
||||
$files[] = 'uploads' . $file[1];
|
||||
}
|
||||
}
|
||||
$zip = new ZipArchive();
|
||||
$res = $zip->open($zipname, ZipArchive::CREATE);
|
||||
if ($res === TRUE) {
|
||||
foreach ($files as $file) {
|
||||
if (file_exists($file)) {
|
||||
$new_filename = substr($file, strrpos($file, '/') + 1);
|
||||
$zip->addFile($file, $new_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
return $zipname;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
@ -83,12 +83,6 @@
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
public function sceneUpload()
|
||||
{
|
||||
return $this->only(['id', 'annex']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return FinancialInvoiceValidate
|
||||
|
@ -72,11 +72,6 @@
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
public function sceneUpload()
|
||||
{
|
||||
return $this->only(['id', 'annex']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
|
@ -34,7 +34,8 @@
|
||||
"rmccue/requests": "^2.0",
|
||||
"w7corp/easywechat": "^6.8",
|
||||
"tencentcloud/sms": "^3.0",
|
||||
"ext-bcmath": "*"
|
||||
"ext-bcmath": "*",
|
||||
"ext-zip": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2",
|
||||
|
Loading…
x
Reference in New Issue
Block a user