From 0f2161922caf84f7c1c03ce430e9cea60b761869 Mon Sep 17 00:00:00 2001 From: weizong song Date: Mon, 24 May 2021 13:39:50 +0800 Subject: [PATCH] up --- .../Admin/StatisticsController.php | 105 ++++++++++-------- app/Libs/WxMicroPay.class.php | 18 +++ routes/web.php | 1 + 3 files changed, 75 insertions(+), 49 deletions(-) diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php index 04e8118..69a9c25 100755 --- a/app/Http/Controllers/Admin/StatisticsController.php +++ b/app/Http/Controllers/Admin/StatisticsController.php @@ -9,6 +9,7 @@ namespace App\Http\Controllers\Admin; use App\Customer; +use App\Libs\WxMicroPay; use App\Models\Balance; use App\Models\Factor; use App\Models\FactorItems; @@ -197,55 +198,6 @@ class StatisticsController extends CommonController } } - public function fixMonthLastDayCheckout(Request $request) - { - $day = $request->day; - if (!$day) { - dd("日期不正确"); - } - DB::enableQueryLog(); - $orders = Orders::whereIn("serial", ["20201130000003", "20201130000005", "20201128000004", "20201126000006", "20201127000005", "20201126000003", "20201130000004", "20201127000008", "20201130000001", "20201126000008"])->get(); - $orderItems = OrderItems::with(["balance", "order"]) - ->whereNotNull("paid_at") - ->whereRaw("UNIX_TIMESTAMP(`paid_at`) > " . strtotime("2020-12-01")) - ->whereRaw("UNIX_TIMESTAMP(`paid_at`) < " . strtotime("2020-12-04")) - ->whereIn("order_id", $orders->pluck("id")->toArray()) - ->limit(100)->get(); - try { - foreach ($orderItems as $orderItem) { - $new_paid_at = "{$day} 22:00:01"; - $orderItem->update([ - "paid_at" => $new_paid_at - ]); - $orderItem->balance->update([ - "created_at" => $new_paid_at, - "remark" => "本条经过时间校准处理。原始创建时间为:" . $orderItem->balance->created_at - ]); - } - DB::commit(); - dd("处理完毕"); - } catch (\Exception $exception) { - DB::rollBack(); - dd($exception->getMessage()); - } - } - - public function fixBalanceOrderId() - { - $balances = Balance::whereNull("order_id")->with("belongs")->limit("100")->get(); - if (!$balances->count()) { - return $this->success("处理完毕", url($this->urlPrefix . "/overview")); - } - foreach ($balances as $balance) { - $balance->timestamps = false; - $balance->update([ - "order_id" => $balance->belongs->order_id - ]); - } - - return $this->success("处理完毕" . $balances->count() . "条数据,正在进入下一批数据。", url($this->urlPrefix . "/finance/fix-balance-order-id?timer=" . time())); - } - public function finance(Request $request) { $projects = $this->_checkProjects(); @@ -298,4 +250,59 @@ class StatisticsController extends CommonController return view($this->bladePath . ".customer-balance", compact("customers", "before_datetime")); } + + public function fixMonthLastDayCheckout(Request $request) + { + $day = $request->day; + if (!$day) { + dd("日期不正确"); + } + DB::enableQueryLog(); + $orders = Orders::whereIn("serial", ["20201130000003", "20201130000005", "20201128000004", "20201126000006", "20201127000005", "20201126000003", "20201130000004", "20201127000008", "20201130000001", "20201126000008"])->get(); + $orderItems = OrderItems::with(["balance", "order"]) + ->whereNotNull("paid_at") + ->whereRaw("UNIX_TIMESTAMP(`paid_at`) > " . strtotime("2020-12-01")) + ->whereRaw("UNIX_TIMESTAMP(`paid_at`) < " . strtotime("2020-12-04")) + ->whereIn("order_id", $orders->pluck("id")->toArray()) + ->limit(100)->get(); + try { + foreach ($orderItems as $orderItem) { + $new_paid_at = "{$day} 22:00:01"; + $orderItem->update([ + "paid_at" => $new_paid_at + ]); + $orderItem->balance->update([ + "created_at" => $new_paid_at, + "remark" => "本条经过时间校准处理。原始创建时间为:" . $orderItem->balance->created_at + ]); + } + DB::commit(); + dd("处理完毕"); + } catch (\Exception $exception) { + DB::rollBack(); + dd($exception->getMessage()); + } + } + + public function fixBalanceOrderId() + { + $balances = Balance::whereNull("order_id")->with("belongs")->limit("100")->get(); + if (!$balances->count()) { + return $this->success("处理完毕", url($this->urlPrefix . "/overview")); + } + foreach ($balances as $balance) { + $balance->timestamps = false; + $balance->update([ + "order_id" => $balance->belongs->order_id + ]); + } + + return $this->success("处理完毕" . $balances->count() . "条数据,正在进入下一批数据。", url($this->urlPrefix . "/finance/fix-balance-order-id?timer=" . time())); + } + + public function manualQueryRecharge($id) { + $recharge = Recharge::find($id); + $res = (new WxMicroPay())->manualQuery($recharge); + dd($res); + } } diff --git a/app/Libs/WxMicroPay.class.php b/app/Libs/WxMicroPay.class.php index 7a1c5a8..cbe0d5b 100644 --- a/app/Libs/WxMicroPay.class.php +++ b/app/Libs/WxMicroPay.class.php @@ -89,5 +89,23 @@ class WxMicroPay extends WxPayCommon } } + public function manualQuery(Recharge $recharge) { + $query_result = $this->orderQuery($recharge->serial); + dd($query_result); + if ($query_result["trade_state"] == "SUCCESS") { + $transaction_id = $query_result["transaction_id"]; + $update = [ + "paid_at" => date("Y-m-d H:i:s"), + "payment_serial" => $transaction_id + ]; + $recharge->update($update); + //充值成功后处理 + event(new RechargeSucceed($recharge)); + return true; + } else { + return false; + } + } + //todo: 取消支付单 } diff --git a/routes/web.php b/routes/web.php index 17a9fdf..8daa682 100644 --- a/routes/web.php +++ b/routes/web.php @@ -83,6 +83,7 @@ Route::group(["namespace" => "Admin", "prefix" => "admin"], function () { Route::get("statistics/salary/sync-order-items", 'StatisticsController@syncOrderItems'); Route::get("statistics/salary/fix-month-last-day-checkout", 'StatisticsController@fixMonthLastDayCheckout'); Route::get("statistics/finance/fix-balance-order-id", 'StatisticsController@fixBalanceOrderId'); + Route::get("statistics/finance/manual-query-recharge/{id}", 'StatisticsController@manualQueryRecharge'); }); });