5 changed files with 119 additions and 17 deletions
@ -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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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…
Reference in new issue