发票管理apiadmin
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.
 
 
 

99 lines
3.5 KiB

<?php
namespace app\controller\task;
use app\model\InvoiceIssuance as InvoiceIssuanceModel;
use app\service\invoice\InvoiceIssuanceService;
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();
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
$result = (new InvoiceIssuanceService())->IssueAnInvoice($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();
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
$result = (new InvoiceIssuanceService())->cancelInitiateAgain($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 runSummaryReport(): Response
{
$where = ['status' => 3, 'delete_time' => 0];
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where($where)->page(1, $this->limit)->select();
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
$result = (new InvoiceIssuanceService())->summaryReport($InvoiceIssuanceValue);
if ($result === true) {
$this->invoiceSuccess($InvoiceIssuanceValue);
}
}
return $this->buildSuccess();
}
/**
* 开票成功 发送邮箱及短信提示
* @param $InvoiceIssuanceValue
* @throws \fast\FuncException
*/
private function invoiceSuccess($InvoiceIssuanceValue)
{
if ($InvoiceIssuanceValue['email']) {
// 发送发票到邮箱
$path = InvoiceIssuanceService::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']));
}
}
}
}