Commit 59cb9053 by haojie

到账检查

parent de0f61d6
......@@ -4,9 +4,11 @@
namespace App\Http\Controllers\API\BlindBox;
use App\Models\BlindBoxList;
use App\Models\SetAddress;
use App\Models\UserWallet;
use App\Models\UseUser;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class BuyBlindBoxController
......@@ -43,14 +45,43 @@ public function toBuy($address, $hash, $id, $invite_code, $Invitees_box_id)
# 创建订单
UserWallet::query()->create(['user_address' => $address, 'status' => 0, 'price' => $price->price, 'blind_box_id' => $id, 'hash' => $hash]);
}
$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()
public function IntervalCheck($hash, $price, $address, $to)
{
return '';
# 获取状态
$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;
}
/**
......
......@@ -122,6 +122,11 @@ public function useBuy(Request $request)
if (empty($address) || empty($hash) || empty($id)) {
return $this->error('缺少数据', 400, 400);
}
# 检查hash是否存在
$hashList = UserWallet::query()->where('hash', $hash)->first();
if ($hashList) {
return $this->error('hash已存在', 400, 400);
}
$result = app(BuyBlindBoxController::class)->toBuy($address, $hash, $id, $invite_code, $Invitees_box_id);
return $this->success('success', $result);
}
......@@ -139,26 +144,6 @@ public function usePayCheck(Request $request)
{
# 提交redis
$hash = $request->input('hash', null);
$amount = $request->input('price', null);
$form = $request->input('form', null);
# 先写死
$address = SetAddress::query()->first();
$to = $address->address;
if (empty($hash) || empty($amount) || empty($form)) {
return $this->error('缺少数据', 400, 400);
}
# 获取交易
$obj = (object)[];
$obj->hash = $hash;
$obj->notify_url = config('address.callback');
$obj->retry = 1;
$obj->amount = $amount;
# 要转小写
$obj->form = strtolower($form);
# 保留一个旧的
$obj->old_form = $form;
$obj->to = strtolower($to);
Redis::rpush('pay_notify', json_encode($obj));
# 获取状态
$item = UserWallet::query()->where('hash', $hash)->first(['status']);
if ($item->status == 1) {
......
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