Merge branch 'master' of /data/git/tiantian2

master
root 5 years ago
commit 627fa97775

@ -0,0 +1,68 @@
<?php
namespace App\Console\Commands;
use App\Models\Recharge;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class SyncAlipayRechargeState extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync-recharge-pay-state:alipay';
/**
* The console command description.
*
* @var string
*/
protected $description = 'sync alipay recharge pay state';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$threshold = 5;
$offset_seconds = 40; //支付发起后多少秒开始轮询
$due_minutes = 5; //支付发起后第一次开始轮询的时间往后延迟5分钟后不再轮询
$last_id = cache("last_sync_alipay_recharge_id", 0);
DB::enableQueryLog();
$recharges = (new Recharge())
->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));
}
}

@ -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.

@ -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);
}
}

@ -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 {

@ -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

Loading…
Cancel
Save