Commit c017b59d by haojie

1

parent 835955df
<?php
namespace App\Http\Controllers\API\Redis;
use App\Models\UserWallet;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class CheckArrivalCl
{
public function check($hash, $price, $address, $to)
{
Log::error('执行异步任务');
# 添加订单后--查询是否到账--最多检测20次
for ($i = 1; $i <= 10; $i++) {
$type = self::IntervalCheck($hash, $price, $address, $to);
Log::error($type);
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;
}
Log::error('插入redis');
# 获取交易
$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;
}
}
...@@ -3,14 +3,11 @@ ...@@ -3,14 +3,11 @@
namespace App\Jobs; namespace App\Jobs;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log; use App\Http\Controllers\API\Redis\CheckArrivalCl;
use Illuminate\Support\Facades\Redis;
use App\Models\UserWallet;
class CheckArrival implements ShouldQueue class CheckArrival implements ShouldQueue
{ {
...@@ -32,6 +29,7 @@ public function __construct(string $hash, int $price, string $address, string $t ...@@ -32,6 +29,7 @@ public function __construct(string $hash, int $price, string $address, string $t
$this->price = $price; $this->price = $price;
$this->address = $address; $this->address = $address;
$this->to = $to; $this->to = $to;
$this->queue = "{check-check-arrival}";
} }
/** /**
...@@ -41,42 +39,9 @@ public function __construct(string $hash, int $price, string $address, string $t ...@@ -41,42 +39,9 @@ public function __construct(string $hash, int $price, string $address, string $t
*/ */
public function handle() public function handle()
{ {
Log::error('执行异步任务');
# 处理 支付到账模块 # 处理 支付到账模块
# 添加订单后--查询是否到账--最多检测20次 app(CheckArrivalCl::class)->check($this->hash, $this->price, $this->address, $this->to);
for ($i = 1; $i <= 10; $i++) {
$type = self::IntervalCheck($this->hash, $this->price, $this->address, $this->to);
Log::error($type);
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;
}
Log::error('插入redis');
# 获取交易
$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