You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.1 KiB
92 lines
3.1 KiB
<?php
|
|
|
|
namespace app\controller\task;
|
|
|
|
use app\model\InvoiceIssuance as InvoiceIssuanceModel;
|
|
use app\service\invoice\InvoiceIssuanceService;
|
|
use app\service\invoice\InvoiceQrCode;
|
|
use app\service\user\EmailService;
|
|
use app\service\user\SmsService;
|
|
use think\Response;
|
|
|
|
class InvoiceIssuanceTask extends Base
|
|
{
|
|
protected $limit = 100;
|
|
|
|
/**
|
|
* 申请开票任务
|
|
* @return Response
|
|
* @throws \fast\FuncException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function runIssueAnInvoice(): Response
|
|
{
|
|
$where = ['status' => 0, 'delete_time' => 0];
|
|
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where($where)->page(1, $this->limit)->select()->toArray();
|
|
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
|
|
$result = (new InvoiceIssuanceService())->tempIssueAnInvoice($InvoiceIssuanceValue);
|
|
if ($result === true) {
|
|
$this->invoiceSuccess($InvoiceIssuanceValue);
|
|
}
|
|
}
|
|
return $this->buildSuccess();
|
|
}
|
|
|
|
|
|
/**
|
|
* 开票失败 修改为虚拟 继续发起
|
|
* @return Response
|
|
* @throws \fast\FuncException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function runCancelInitiateAgain(): Response
|
|
{
|
|
$where = ['status' => 1, 'delete_time' => 0];
|
|
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where($where)->page(1, $this->limit)->select()->toArray();
|
|
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
|
|
$result = (new InvoiceIssuanceService())->cancelInitiateAgain($InvoiceIssuanceValue);
|
|
if ($result === true) {
|
|
$this->invoiceSuccess($InvoiceIssuanceValue);
|
|
}
|
|
}
|
|
return $this->buildSuccess();
|
|
}
|
|
|
|
/**
|
|
* 保存结报数据
|
|
* @return Response
|
|
*/
|
|
public function runSummaryReport(): Response
|
|
{
|
|
$result = (new InvoiceIssuanceService())->saveSummaryReport();
|
|
if ($result !== true) {
|
|
return $this->buildFailed('0', $result);
|
|
}
|
|
return $this->buildSuccess();
|
|
}
|
|
|
|
/**
|
|
* 开票成功 发送邮箱及短信提示
|
|
* @param $InvoiceIssuanceValue
|
|
* @throws \fast\FuncException
|
|
*/
|
|
private function invoiceSuccess($InvoiceIssuanceValue)
|
|
{
|
|
if ($InvoiceIssuanceValue['email']) {
|
|
|
|
// 发送发票到邮箱
|
|
$path = InvoiceQrCode::getDownFileUrl($InvoiceIssuanceValue['id']);
|
|
$emailResult = (new EmailService())->sendInvoice($InvoiceIssuanceValue['email'], '发票', $path);
|
|
if ($emailResult === true && $InvoiceIssuanceValue['mobile']) {
|
|
// 发送短信
|
|
$SmsService = new SmsService();
|
|
$SmsService->sendSms($InvoiceIssuanceValue['mobile'], $SmsService->smsInvoiceTemplate($InvoiceIssuanceValue['email']));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|