From 16e8a25b05a5cf5f58bc1a314c90f2fe356233e2 Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Wed, 19 Jan 2022 14:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=B9=B3=E5=AE=89=E5=88=B8?= =?UTF-8?q?=E6=A0=B8=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Coupon/IndexController.php | 2 +- app/Admin/Controllers/TestController.php | 43 ++++++++++++ app/Admin/routes.php | 3 +- app/Jobs/CheckCouponByLog.php | 67 +++++++++++++++++++ app/Jobs/CheckCouponLog.php | 55 +++++++++++++++ 5 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 app/Jobs/CheckCouponByLog.php create mode 100644 app/Jobs/CheckCouponLog.php diff --git a/app/Admin/Controllers/Coupon/IndexController.php b/app/Admin/Controllers/Coupon/IndexController.php index 34c26ff..a798f4c 100644 --- a/app/Admin/Controllers/Coupon/IndexController.php +++ b/app/Admin/Controllers/Coupon/IndexController.php @@ -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 () { diff --git a/app/Admin/Controllers/TestController.php b/app/Admin/Controllers/TestController.php index 6b03964..1b15824 100644 --- a/app/Admin/Controllers/TestController.php +++ b/app/Admin/Controllers/TestController.php @@ -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."
"; + + 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); + } + + + } + } + } + } diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 5b8fb10..8994ea2 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -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'); diff --git a/app/Jobs/CheckCouponByLog.php b/app/Jobs/CheckCouponByLog.php new file mode 100644 index 0000000..bc86db0 --- /dev/null +++ b/app/Jobs/CheckCouponByLog.php @@ -0,0 +1,67 @@ +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); + + } + +} \ No newline at end of file diff --git a/app/Jobs/CheckCouponLog.php b/app/Jobs/CheckCouponLog.php new file mode 100644 index 0000000..18db0f2 --- /dev/null +++ b/app/Jobs/CheckCouponLog.php @@ -0,0 +1,55 @@ +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); + + } + +} \ No newline at end of file