update
This commit is contained in:
parent
3ee1960a59
commit
c78701aea0
@ -59,14 +59,19 @@
|
|||||||
return $this->fail(FinancialInvoiceLogic::getError());
|
return $this->fail(FinancialInvoiceLogic::getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function upload()
|
public function download()
|
||||||
{
|
{
|
||||||
$params = (new FinancialInvoiceValidate())->post()->goCheck('upload');
|
$params = (new FinancialInvoiceValidate())->post()->goCheck('detail');
|
||||||
$result = FinancialInvoiceLogic::upload($params);
|
$result = FinancialInvoiceLogic::download($params);
|
||||||
if (true === $result) {
|
if (false === $result) {
|
||||||
return $this->success('上传成功', [], 1, 1);
|
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());
|
return $this->fail(FinancialRefundLogic::getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function upload()
|
public function download()
|
||||||
{
|
{
|
||||||
$params = (new FinancialRefundValidate())->post()->goCheck('upload');
|
$params = (new FinancialRefundValidate())->post()->goCheck('detail');
|
||||||
$result = FinancialRefundLogic::upload($params);
|
$result = FinancialRefundLogic::download($params);
|
||||||
if (true === $result) {
|
if (false === $result) {
|
||||||
return $this->success('上传成功', [], 1, 1);
|
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\MarketingContract;
|
||||||
use app\common\model\marketing\MarketingCustom;
|
use app\common\model\marketing\MarketingCustom;
|
||||||
use think\facade\Db;
|
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 {
|
try {
|
||||||
FinancialInvoice::where('id', $params['id'])->update([
|
$data = FinancialInvoice::field('annex')->where('id', $params['id'])->findOrEmpty();
|
||||||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
if ($data->isEmpty() || !$data['annex']) {
|
||||||
'update_time' => time()
|
self::setError("文件为空");
|
||||||
]);
|
return false;
|
||||||
Db::commit();
|
}
|
||||||
return true;
|
$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) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
use app\common\model\marketing\MarketingContract;
|
use app\common\model\marketing\MarketingContract;
|
||||||
use app\common\model\marketing\MarketingCustom;
|
use app\common\model\marketing\MarketingCustom;
|
||||||
use think\facade\Db;
|
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 {
|
try {
|
||||||
FinancialRefund::where('id', $params['id'])->update([
|
$data = FinancialRefund::field('annex')->where('id', $params['id'])->findOrEmpty();
|
||||||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
if ($data->isEmpty() || !$data['annex']) {
|
||||||
'update_time' => time()
|
self::setError("文件为空");
|
||||||
]);
|
return false;
|
||||||
Db::commit();
|
}
|
||||||
return true;
|
$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) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -83,12 +83,6 @@
|
|||||||
return $this->remove('id', true);
|
return $this->remove('id', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sceneUpload()
|
|
||||||
{
|
|
||||||
return $this->only(['id', 'annex']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 编辑场景
|
* @notes 编辑场景
|
||||||
* @return FinancialInvoiceValidate
|
* @return FinancialInvoiceValidate
|
||||||
|
@ -72,11 +72,6 @@
|
|||||||
return $this->remove('id', true);
|
return $this->remove('id', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sceneUpload()
|
|
||||||
{
|
|
||||||
return $this->only(['id', 'annex']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 编辑场景
|
* @notes 编辑场景
|
||||||
|
@ -34,7 +34,8 @@
|
|||||||
"rmccue/requests": "^2.0",
|
"rmccue/requests": "^2.0",
|
||||||
"w7corp/easywechat": "^6.8",
|
"w7corp/easywechat": "^6.8",
|
||||||
"tencentcloud/sms": "^3.0",
|
"tencentcloud/sms": "^3.0",
|
||||||
"ext-bcmath": "*"
|
"ext-bcmath": "*",
|
||||||
|
"ext-zip": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/var-dumper": "^4.2",
|
"symfony/var-dumper": "^4.2",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user