校验平安券核销
This commit is contained in:
@@ -83,7 +83,7 @@ class IndexController extends AdminController
|
||||
$grid->column('price', '核销金额');
|
||||
$grid->column('total', '订单金额');
|
||||
$grid->column('orderid', '订单id');
|
||||
$grid->column('pa_order_id', '平安主订单号')->hide();
|
||||
$grid->column('pa_order_id', '平安主订单号');
|
||||
$grid->column('pa_sub_order_id', '平安子订单号')->hide();
|
||||
|
||||
$grid->column('资金通道结算')->display(function () {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Jobs\CheckCouponByLog;
|
||||
use App\Jobs\CheckCouponLog;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\Log;
|
||||
use Carbon\Carbon;
|
||||
@@ -9,6 +11,7 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use XuanChen\Coupon\Action\pingan\Verification;
|
||||
|
||||
class TestController
|
||||
@@ -152,4 +155,44 @@ class TestController
|
||||
dd(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 设置数据
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2022/1/19 13:29
|
||||
*/
|
||||
public function checkCouponLog(Request $request)
|
||||
{
|
||||
$type = $request->type ?? '';
|
||||
|
||||
if (! $type) {
|
||||
dd('type 错误');
|
||||
}
|
||||
|
||||
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames();
|
||||
|
||||
foreach ($tables as $table) {
|
||||
|
||||
if (Str::contains($table, 'api_log_')) {
|
||||
echo " 开始处理 ".$table." <br>";
|
||||
|
||||
if (! Schema::hasColumn($table, 'coupon_no')) {
|
||||
Schema::table($table, function (Blueprint $table) {
|
||||
$table->string('coupon_no')->after('out_source')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
if ($type == 'log') {
|
||||
CheckCouponLog::dispatch($table);
|
||||
}
|
||||
|
||||
if ($type == 'coupon') {
|
||||
CheckCouponByLog::dispatch($table);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ Route::group([
|
||||
|
||||
$router->get('/', 'HomeController@index')->name('admin.home');
|
||||
$router->get('test', 'TestController@index')->name('test.index');
|
||||
$router->get('test/coupon', 'TestController@coupon')->name('test.index');
|
||||
$router->get('test/coupon', 'TestController@coupon');
|
||||
$router->get('test/check_coupon_log', 'TestController@checkCouponLog');
|
||||
|
||||
$router->post('uploads/editor', 'UploadController@editor')->name('uploads.editor');
|
||||
|
||||
|
||||
67
app/Jobs/CheckCouponByLog.php
Normal file
67
app/Jobs/CheckCouponByLog.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Log;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class CheckCouponByLog implements ShouldQueue
|
||||
{
|
||||
|
||||
use Dispatchable, InteractsWithQueue;
|
||||
|
||||
public $queue = 'LISTENER';
|
||||
|
||||
public $delay = 0;
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
public $timeout = 30;
|
||||
|
||||
|
||||
protected $table;
|
||||
|
||||
public function __construct(string $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
info(__CLASS__.' 开始处理 '.$this->table);
|
||||
|
||||
$count = (new Log())->setTable($this->table)
|
||||
->whereHas('coupon', function ($q) {
|
||||
$q->whereNull('pa_order_id');
|
||||
})
|
||||
->where('path',
|
||||
'http://api.pingan.com.cn/open/vassPartner/appsvr/property/api/new/partner/redemption')
|
||||
->where('out_source->code', 200)
|
||||
->count();
|
||||
|
||||
if ($count > 0) {
|
||||
|
||||
(new Log())->setTable($this->table)
|
||||
->whereHas('coupon', function ($q) {
|
||||
$q->whereNull('pa_order_id');
|
||||
})
|
||||
->where('path',
|
||||
'http://api.pingan.com.cn/open/vassPartner/appsvr/property/api/new/partner/redemption')
|
||||
->where('out_source->code', 200)
|
||||
->chunkById(1000, function ($logs) {
|
||||
foreach ($logs as $log) {
|
||||
$log->coupon->update([
|
||||
'pa_order_id' => $log->out_source['data']['orderId'],
|
||||
'pa_sub_order_id' => $log->out_source['data']['subOrderId'],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
info(__CLASS__.' '.$this->table.' 成功处理 '.$count);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
55
app/Jobs/CheckCouponLog.php
Normal file
55
app/Jobs/CheckCouponLog.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Log;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use XuanChen\Coupon\Action\pingan\Verification;
|
||||
|
||||
class CheckCouponLog
|
||||
{
|
||||
|
||||
use Dispatchable, InteractsWithQueue;
|
||||
|
||||
protected $table;
|
||||
|
||||
public function __construct(string $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
info(__CLASS__.' 开始处理 '.$this->table);
|
||||
|
||||
$count = (new Log())->setTable($this->table)
|
||||
->whereNull('coupon_no')
|
||||
->where('path',
|
||||
'http://api.pingan.com.cn/open/vassPartner/appsvr/property/api/new/partner/redemption')
|
||||
->where('out_source->code', 200)
|
||||
->count();
|
||||
|
||||
if ($count > 0) {
|
||||
(new Log())->setTable($this->table)
|
||||
->whereNull('coupon_no')
|
||||
->where('path',
|
||||
'http://api.pingan.com.cn/open/vassPartner/appsvr/property/api/new/partner/redemption')
|
||||
->where('out_source->code', 200)
|
||||
->chunkById(1000, function ($logs) {
|
||||
foreach ($logs as $log) {
|
||||
$data = (new Verification())->decrypt($log->in_source['json']['data']);
|
||||
$data = json_decode($data, true);
|
||||
$log->update([
|
||||
'coupon_no' => $data['couponNo']
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
info(__CLASS__.' '.$this->table.' 成功处理 '.$count);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user