|
|
|
@ -4,12 +4,14 @@ namespace app\controller\api; |
|
|
|
|
|
|
|
use app\model\InvoiceHead; |
|
|
|
use app\model\InvoiceIssuance as InvoiceIssuanceModel; |
|
|
|
use app\model\InvoiceIssuanceData; |
|
|
|
use app\model\WechatPucode; |
|
|
|
use app\service\invoice\InvoiceIssuanceService; |
|
|
|
use app\service\wechat\WechatService; |
|
|
|
use app\util\ReturnCode; |
|
|
|
use app\validate\InvoiceHeadValidate; |
|
|
|
use app\validate\InvoiceIssuanceValidate; |
|
|
|
use fast\FuncException; |
|
|
|
use think\facade\App; |
|
|
|
use think\facade\Db; |
|
|
|
use think\Response; |
|
|
|
|
|
|
|
@ -139,7 +141,7 @@ class InvoiceIssuance extends Base |
|
|
|
'expire_time' => strtotime($params['expire_time']), |
|
|
|
]; |
|
|
|
|
|
|
|
$where = [['status', '>', 0], ['delete_time', '=', 0]]; |
|
|
|
$where = [['status', '<>', 3], ['delete_time', '=', 0]]; |
|
|
|
if ($id) { |
|
|
|
$where[] = ['id', '!=', $id]; |
|
|
|
} |
|
|
|
@ -166,15 +168,28 @@ class InvoiceIssuance extends Base |
|
|
|
$data['update_time'] = time(); |
|
|
|
|
|
|
|
(new InvoiceIssuanceModel())->update($data, ['id' => $id]); |
|
|
|
|
|
|
|
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where('id', $id)->find(); |
|
|
|
if ($InvoiceIssuanceData['status'] == 2) { |
|
|
|
$result = (new InvoiceIssuanceService())->cancelInitiateAgain($InvoiceIssuanceData); |
|
|
|
if ($result !== true) { |
|
|
|
throw new \Exception($result); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
validate(InvoiceIssuanceValidate::class)->scene('add')->check($params); |
|
|
|
|
|
|
|
$data['create_time'] = time(); |
|
|
|
|
|
|
|
$InvoiceModel = (new InvoiceIssuanceModel())->save($data); |
|
|
|
if (!$InvoiceModel) { |
|
|
|
$id = (new InvoiceIssuanceModel())->insertGetId($data); |
|
|
|
if (!$id) { |
|
|
|
throw new \Exception('申请失败'); |
|
|
|
} |
|
|
|
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where('id', $id)->find(); |
|
|
|
$result = (new InvoiceIssuanceService())->IssueAnInvoice($InvoiceIssuanceData); |
|
|
|
if ($result !== true) { |
|
|
|
throw new \Exception($result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Db::commit(); |
|
|
|
@ -209,16 +224,60 @@ class InvoiceIssuance extends Base |
|
|
|
/** |
|
|
|
* 获取二维码 |
|
|
|
* @return Response |
|
|
|
* @throws \Exception |
|
|
|
*/ |
|
|
|
public function getQrCode(): Response |
|
|
|
{ |
|
|
|
// 验证 |
|
|
|
$id = $this->request->get('id', ''); |
|
|
|
if (empty($id)) { |
|
|
|
throw new \Exception('缺少必传参数'); |
|
|
|
} |
|
|
|
|
|
|
|
// 生成 |
|
|
|
$qrCodeImage = InvoiceIssuanceService::getQrCode(); |
|
|
|
$qrCodeImage = InvoiceIssuanceService::getQrCode($id); |
|
|
|
|
|
|
|
// 返回 |
|
|
|
return $this->buildSuccess(['qrCodeImage' => $qrCodeImage]); |
|
|
|
} |
|
|
|
|
|
|
|
public function downFile() |
|
|
|
{ |
|
|
|
try { |
|
|
|
$id = $this->request->get('id', ''); |
|
|
|
if (empty($id)) { |
|
|
|
throw new \Exception('缺少必传参数'); |
|
|
|
} |
|
|
|
$InvoiceIssuanceData = (new InvoiceIssuanceData)->where(['invoice_issuance_id' => $id, 'status' => 1])->find(); |
|
|
|
if (!$InvoiceIssuanceData) { |
|
|
|
throw new FuncException('PDF文件为下载成功'); |
|
|
|
} |
|
|
|
$filePath = $InvoiceIssuanceData['pdf_filepath']; |
|
|
|
$file_dir = App::getRootPath() . 'public/' . $filePath; |
|
|
|
if (file_exists($file_dir)) { |
|
|
|
// 打开文件 |
|
|
|
$file1 = fopen($file_dir, "r"); |
|
|
|
|
|
|
|
//文件名,自定义名称+文件后缀 |
|
|
|
$file_houzhui = strrchr($file_dir, '.'); |
|
|
|
$file_name = time().rand(0000,9999).$file_houzhui; |
|
|
|
// 输入文件标签 |
|
|
|
Header("Content-type: application/octet-stream"); |
|
|
|
Header("Accept-Ranges: bytes"); |
|
|
|
Header("Accept-Length:".filesize($file_dir)); |
|
|
|
Header("Content-Disposition: attachment;filename=" . $file_name);//自定义文件名 |
|
|
|
ob_clean(); // 重点!!! |
|
|
|
flush(); // 重点!!!!可以清除文件中多余的路径名以及解决乱码的问题: |
|
|
|
//输出文件内容 |
|
|
|
//读取文件内容并直接输出到浏览器 |
|
|
|
echo fread($file1, filesize($file_dir)); |
|
|
|
fclose($file1); |
|
|
|
exit(); |
|
|
|
} else { |
|
|
|
throw new \Exception('文件不存在'); |
|
|
|
} |
|
|
|
} catch (\Exception $e) { |
|
|
|
return $this->buildFailed(ReturnCode::NOT_EXISTS, $e->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|