Commit 10edde57 by haojie

1

parent 277efe9f
......@@ -8,7 +8,7 @@
use App\Models\UserWallet;
use App\Models\UseUser;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use App\Jobs\CheckArrival;
class BuyBlindBoxController
......@@ -49,39 +49,9 @@ public function toBuy($address, $hash, $id, $invite_code, $Invitees_box_id)
$address = SetAddress::query()->first();
$to = $address->address;
# 添加订单后--查询是否到账--最多检测20次
for ($i = 1; $i <= 10; $i++) {
$type = self::IntervalCheck($hash, $price->price, $address, $to);
if ($type) {
break;
}
sleep(1);
}
}
/**
* 向redis发送请求
*/
public function IntervalCheck($hash, $price, $address, $to)
{
# 获取状态
$item = UserWallet::query()->where('hash', $hash)->first(['status']);
if ($item->status == 1) {
return true;
}
# 获取交易
$obj = (object)[];
$obj->hash = $hash;
$obj->notify_url = config('address.callback');
$obj->retry = 1;
$obj->amount = $price;
# 要转小写
$obj->form = strtolower($address);
# 保留一个旧的
$obj->old_form = $address;
$obj->to = strtolower($to);
Redis::rpush('pay_notify', json_encode($obj));
return false;
# 添加订单后
# 异步检查到账情况
dispatch(new CheckArrival($hash, $price->price, $address, $to));
}
/**
......
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Redis;
use App\Models\UserWallet;
class CheckArrival implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public string $hash;
public int $price;
public string $address;
public string $to;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(string $hash, int $price, string $address, string $to)
{
$this->hash = $hash;
$this->price = $price;
$this->address = $address;
$this->to = $to;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
# 处理 支付到账模块
# 添加订单后--查询是否到账--最多检测20次
for ($i = 1; $i <= 10; $i++) {
$type = self::IntervalCheck($this->hash, $this->price, $this->address, $this->to);
if ($type) {
break;
}
sleep(1);
}
}
/**
* 向redis发送请求
*/
public function IntervalCheck($hash, $price, $address, $to)
{
# 获取状态
$item = UserWallet::query()->where('hash', $hash)->first(['status']);
if ($item->status == 1) {
return true;
}
# 获取交易
$obj = (object)[];
$obj->hash = $hash;
$obj->notify_url = config('address.callback');
$obj->retry = 1;
$obj->amount = $price;
# 要转小写
$obj->form = strtolower($address);
# 保留一个旧的
$obj->old_form = $address;
$obj->to = strtolower($to);
Redis::rpush('pay_notify', json_encode($obj));
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment