diff --git a/app/Console/Commands/SyncAlipayRechargeState.php b/app/Console/Commands/SyncAlipayRechargeState.php new file mode 100644 index 0000000..9bfa313 --- /dev/null +++ b/app/Console/Commands/SyncAlipayRechargeState.php @@ -0,0 +1,68 @@ +where("id", ">", $last_id) + ->whereNull("paid_at") + ->where("payment", "alipay") + ->whereRaw("UNIX_TIMESTAMP(`created_at`) between " . (time() + $offset_seconds) . " and " . (time() + $due_minutes * 60 + $offset_seconds)) + ->limit($threshold) + ->get(); + if (!$recharges->count()) { + cache(['last_sync_alipay_recharge_id' => null], now()->addSeconds(90)); + echo "nothing"; + return; + } + + foreach ($recharges as $recharge) { + $result = (new WxMicroPay())->manualQuery($recharge); + dump($result); + } + + cache(['last_sync_alipay_recharge_id' => $recharges->last()->id], now()->addSeconds(90)); + } +} diff --git a/app/Console/Commands/SyncWeixinRechargeState.php b/app/Console/Commands/SyncWeixinRechargeState.php index 727479b..329f06a 100644 --- a/app/Console/Commands/SyncWeixinRechargeState.php +++ b/app/Console/Commands/SyncWeixinRechargeState.php @@ -21,7 +21,7 @@ class SyncWeixinRechargeState extends Command * * @var string */ - protected $description = 'sync recharge pay state'; + protected $description = 'sync weixin recharge pay state'; /** * Create a new command instance. diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php index 69a9c25..1d1ac09 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\AlipayF2F; use App\Libs\WxMicroPay; use App\Models\Balance; use App\Models\Factor; @@ -302,7 +303,7 @@ class StatisticsController extends CommonController public function manualQueryRecharge($id) { $recharge = Recharge::find($id); - $res = (new WxMicroPay())->manualQuery($recharge); + $res = (new AlipayF2F())->manualQuery($recharge); dd($res); } } diff --git a/app/Libs/AlipayF2F.class.php b/app/Libs/AlipayF2F.class.php index ec1ea59..c33a75b 100644 --- a/app/Libs/AlipayF2F.class.php +++ b/app/Libs/AlipayF2F.class.php @@ -20,7 +20,7 @@ class AlipayF2F $result = Factory::setOptions($config)::payment() ->faceToFace() - ->pay("充值{$recharge->money}元" . ($recharge->project ? "-".$recharge->project->name : ""), $recharge->serial, $recharge->money, $auth_code); + ->pay("充值{$recharge->money}元" . ($recharge->project ? "-" . $recharge->project->name : ""), $recharge->serial, $recharge->money, $auth_code); $responseChecker = new ResponseChecker(); //处理响应或异常 if ($responseChecker->success($result)) { @@ -52,6 +52,34 @@ class AlipayF2F } } + public function manualQuery(Recharge $recharge) + { + $config = $this->getOptions(); + $query_result = Factory::setOptions($config)::payment() + ->common() + ->query($recharge->serial); + dd($query_result); + + $responseChecker = new ResponseChecker(); + //处理响应或异常 + if ($responseChecker->success($query_result)) { + if (!$recharge->paid_at) { + $transaction_id = $query_result["transaction_id"]; + $datetime = ""; + $update = [ + "paid_at" => $datetime, + "payment_serial" => $transaction_id + ]; + $recharge->update($update); + //充值成功后处理 + event(new RechargeSucceed($recharge)); + } + return true; + } else { + return false; + } + } + public function refund(Refund $refund) { try { diff --git a/app/Listeners/RechargeSucceedListener.php b/app/Listeners/RechargeSucceedListener.php index af7d938..033ef25 100644 --- a/app/Listeners/RechargeSucceedListener.php +++ b/app/Listeners/RechargeSucceedListener.php @@ -31,6 +31,11 @@ class RechargeSucceedListener public function handle(RechargeSucceed $event) { $recharge = $event->recharge; + //为避免重复入账,先check充值是否已经入账过 + if ($recharge->paid_at) { + return; + } + $balance = $recharge->customer->balance + $recharge->money; $recharge->customer->update([ "balance" => $balance