Browse Source

修改为脚本运行 申请开票 和 再次发起开票接口

master
wanghongjun 12 months ago
parent
commit
6eca982663
  1. 18
      app/controller/api/InvoiceIssuance.php
  2. 56
      app/controller/task/Base.php
  3. 48
      app/controller/task/InvoiceIssuanceTask.php
  4. 3
      app/service/invoice/InvoiceIssuanceService.php
  5. 11
      route/taskRoute.php

18
app/controller/api/InvoiceIssuance.php

@ -168,28 +168,12 @@ 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();
$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);
}
(new InvoiceIssuanceModel())->save($data);
}
Db::commit();

56
app/controller/task/Base.php

@ -0,0 +1,56 @@
<?php
declare (strict_types=1);
/**
* 工程基类
* @since 2017/02/28 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace app\controller\task;
use app\BaseController;
use app\util\ReturnCode;
use think\facade\Env;
use think\Response;
class Base extends BaseController {
private $debug = [];
protected $userInfo = [];
public function _initialize() {
// $this->userInfo = ''; 这部分初始化用户信息可以参考admin模块下的Base去自行处理
}
public function buildSuccess(array $data = [], string $msg = '操作成功', int $code = ReturnCode::SUCCESS): Response {
$return = [
'code' => $code,
'msg' => $msg,
'data' => $data
];
if (Env::get('APP_DEBUG') && $this->debug) {
$return['debug'] = $this->debug;
}
return json($return);
}
public function buildFailed(int $code, string $msg = '操作失败', array $data = []): Response {
$return = [
'code' => $code,
'msg' => $msg,
'data' => $data
];
if (Env::get('APP_DEBUG') && $this->debug) {
$return['debug'] = $this->debug;
}
return json($return);
}
protected function debug($data): void {
if ($data) {
$this->debug[] = $data;
}
}
}

48
app/controller/task/InvoiceIssuanceTask.php

@ -0,0 +1,48 @@
<?php
namespace app\controller\task;
use app\model\InvoiceIssuance as InvoiceIssuanceModel;
use app\service\invoice\InvoiceIssuanceService;
class InvoiceIssuanceTask extends Base
{
/**
* 申请开票任务
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function runIssueAnInvoice()
{
$limit = 100;
$where = ['status' => 0, 'delete_time' => 0];
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where($where)->page($limit)->select();
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
(new InvoiceIssuanceService())->IssueAnInvoice($InvoiceIssuanceValue);
}
return $this->buildSuccess();
}
/**
* 开票失败 修改为虚拟 继续发起
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function runCancelInitiateAgain()
{
$limit = 100;
$where = ['status' => 2, 'delete_time' => 0];
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where($where)->page($limit)->select();
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
(new InvoiceIssuanceService())->cancelInitiateAgain($InvoiceIssuanceValue);
}
return $this->buildSuccess();
}
}

3
app/service/invoice/InvoiceIssuanceService.php

@ -158,6 +158,7 @@ class InvoiceIssuanceService
*/
private function getInvoiceDate($expire_time): array
{
$expire_time = strtotime(date("Y-m",$expire_time));
return [
'nsqxDm' => date("m", $expire_time), // 申请月份
'skssqq' => date("Y-m-d", $expire_time), // 申请开始日期
@ -290,6 +291,7 @@ class InvoiceIssuanceService
}
return true;
} catch (\Exception $e) {
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'ycms', $e->getMessage());
$this->writeLog($e);
return $e->getMessage();
}
@ -337,6 +339,7 @@ class InvoiceIssuanceService
return true;
} catch (\Exception $e) {
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'ycms', $e->getMessage());
$this->writeLog($e);
return $e->getMessage();
}

11
route/taskRoute.php

@ -0,0 +1,11 @@
<?php
/**
* Task路由
*/
use think\facade\Route;
Route::group('task', function() {
Route::rule('InvoiceIssuanceTask/runIssueAnInvoice', 'task.InvoiceIssuanceTask/runIssueAnInvoice', 'get');
Route::rule('InvoiceIssuanceTask/runCancelInitiateAgain', 'task.InvoiceIssuanceTask/runCancelInitiateAgain', 'get');
});//->middleware(app\middleware\ApiResponse::class)
Loading…
Cancel
Save