|
@@ -13,7 +13,7 @@ use app\common\model\ProductWelfareRede;
|
|
|
use app\common\model\RwaExchangeRecordModel;
|
|
use app\common\model\RwaExchangeRecordModel;
|
|
|
use app\common\model\LedgerWalletModel;
|
|
use app\common\model\LedgerWalletModel;
|
|
|
use app\common\model\LedgerTeacChangeModel;
|
|
use app\common\model\LedgerTeacChangeModel;
|
|
|
-use fast\Action;
|
|
|
|
|
|
|
+use app\common\model\LedgerTokenChangeModel;
|
|
|
use fast\Asset;
|
|
use fast\Asset;
|
|
|
use think\Db;
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
use think\Exception;
|
|
@@ -58,6 +58,8 @@ class Exchange extends Api
|
|
|
'is_token' => $welfare['is_token'],
|
|
'is_token' => $welfare['is_token'],
|
|
|
'token_name' => $welfare['token_name'],
|
|
'token_name' => $welfare['token_name'],
|
|
|
'token_num' => round($welfare['token_num'], 2),
|
|
'token_num' => round($welfare['token_num'], 2),
|
|
|
|
|
+ 'is_chabao' => $welfare['is_chabao'],
|
|
|
|
|
+ 'chabao_num' => $welfare['chabao_num']
|
|
|
];
|
|
];
|
|
|
$this->success('ok', ['data'=>$data_info, 'desc'=> $welfare['describe']]);
|
|
$this->success('ok', ['data'=>$data_info, 'desc'=> $welfare['describe']]);
|
|
|
}
|
|
}
|
|
@@ -67,6 +69,7 @@ class Exchange extends Api
|
|
|
public function submitWelfare(LedgerWalletModel $ledgerWalletModel, ProductWelfareRede $productWelfareRede)
|
|
public function submitWelfare(LedgerWalletModel $ledgerWalletModel, ProductWelfareRede $productWelfareRede)
|
|
|
{
|
|
{
|
|
|
$ids = $this->request->post('ids'); // 代币ids
|
|
$ids = $this->request->post('ids'); // 代币ids
|
|
|
|
|
+ $type_id = $this->request->post('type_id'); // 类型0U 1茶宝
|
|
|
$coin_from_address = $this->request->post('coin_from_address'); // 代码转入地址
|
|
$coin_from_address = $this->request->post('coin_from_address'); // 代码转入地址
|
|
|
$usdt_from_address = $this->request->post('usdt_from_address'); // U转入地址
|
|
$usdt_from_address = $this->request->post('usdt_from_address'); // U转入地址
|
|
|
if (empty($ids) || empty($usdt_from_address)) {
|
|
if (empty($ids) || empty($usdt_from_address)) {
|
|
@@ -90,7 +93,7 @@ class Exchange extends Api
|
|
|
->count();
|
|
->count();
|
|
|
if($check_user >= $welfare_config['limit_num']) $this->error('每人限制兑换' .$welfare_config['limit_num'].'套,您已达上限');
|
|
if($check_user >= $welfare_config['limit_num']) $this->error('每人限制兑换' .$welfare_config['limit_num'].'套,您已达上限');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ $token = 0;
|
|
|
$order_no = date('YmdHis') . rand(1000, 9999);
|
|
$order_no = date('YmdHis') . rand(1000, 9999);
|
|
|
$inster_data = [
|
|
$inster_data = [
|
|
|
'order_no' => $order_no,
|
|
'order_no' => $order_no,
|
|
@@ -149,41 +152,46 @@ class Exchange extends Api
|
|
|
$inster_data['amount_token'] = $coin_data['amount'];
|
|
$inster_data['amount_token'] = $coin_data['amount'];
|
|
|
$inster_data['tx_hash_token'] = $coin_data['hash'];
|
|
$inster_data['tx_hash_token'] = $coin_data['hash'];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- //USDT转入记录
|
|
|
|
|
- $BscApi = new BscApi('0x55d398326f99059ff775485246999027b3197955');
|
|
|
|
|
- $result_usdt = $BscApi->getTransactionRecordsByAddress($usdt_from_address, $welfare_config->transfer_address, 49990000);
|
|
|
|
|
- if ($result_usdt['code'] == 0) {
|
|
|
|
|
- $this->error($result_usdt['msg']);
|
|
|
|
|
- }
|
|
|
|
|
- Log::info($result_usdt, 'USDT所有转入记录');
|
|
|
|
|
- $usdt_list = [];
|
|
|
|
|
- foreach ($result_usdt['data'] as $value) {
|
|
|
|
|
- if ($value['amount'] == $welfare_config->usdt_num) {
|
|
|
|
|
- $usdt_list[] = $value;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (empty($usdt_list)) {
|
|
|
|
|
- $this->error('未识别到USDT转入记录');
|
|
|
|
|
- }
|
|
|
|
|
- Log::info($usdt_list, 'USDT精准转入记录');
|
|
|
|
|
-
|
|
|
|
|
- $usdt_data = [];
|
|
|
|
|
- foreach ($usdt_list as $item) {
|
|
|
|
|
- $check_info = (new RwaExchangeRecordModel())->where('tx_hash_usdt', $item['hash'])->find();
|
|
|
|
|
- if (empty($check_info)) {
|
|
|
|
|
- $usdt_data = $item;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (empty($usdt_data)) {
|
|
|
|
|
- $this->error('未识别到新USDT转入记录');
|
|
|
|
|
- }
|
|
|
|
|
- Log::info($usdt_list, 'USDT可用入记录');
|
|
|
|
|
-
|
|
|
|
|
- //记录
|
|
|
|
|
- $inster_data['tx_hash_usdt'] = $usdt_data['hash'];
|
|
|
|
|
- Log::info($inster_data, '插入数据');
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if(empty($type_id)){
|
|
|
|
|
+ //USDT转入记录
|
|
|
|
|
+ $BscApi = new BscApi('0x55d398326f99059ff775485246999027b3197955');
|
|
|
|
|
+ $result_usdt = $BscApi->getTransactionRecordsByAddress($usdt_from_address, $welfare_config->transfer_address, 49990000);
|
|
|
|
|
+ if ($result_usdt['code'] == 0) {
|
|
|
|
|
+ $this->error($result_usdt['msg']);
|
|
|
|
|
+ }
|
|
|
|
|
+ Log::info($result_usdt, 'USDT所有转入记录');
|
|
|
|
|
+ $usdt_list = [];
|
|
|
|
|
+ foreach ($result_usdt['data'] as $value) {
|
|
|
|
|
+ if ($value['amount'] == $welfare_config->usdt_num) {
|
|
|
|
|
+ $usdt_list[] = $value;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($usdt_list)) {
|
|
|
|
|
+ $this->error('未识别到USDT转入记录');
|
|
|
|
|
+ }
|
|
|
|
|
+ Log::info($usdt_list, 'USDT精准转入记录');
|
|
|
|
|
+
|
|
|
|
|
+ $usdt_data = [];
|
|
|
|
|
+ foreach ($usdt_list as $item) {
|
|
|
|
|
+ $check_info = (new RwaExchangeRecordModel())->where('tx_hash_usdt', $item['hash'])->find();
|
|
|
|
|
+ if (empty($check_info)) {
|
|
|
|
|
+ $usdt_data = $item;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($usdt_data)) {
|
|
|
|
|
+ $this->error('未识别到新USDT转入记录');
|
|
|
|
|
+ }
|
|
|
|
|
+ Log::info($usdt_list, 'USDT可用入记录');
|
|
|
|
|
+
|
|
|
|
|
+ //记录
|
|
|
|
|
+ $inster_data['tx_hash_usdt'] = $usdt_data['hash'];
|
|
|
|
|
+ Log::info($inster_data, '插入数据');
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $inster_data['token_name'] =$token= $welfare_config->chabao_num;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
@@ -196,6 +204,10 @@ class Exchange extends Api
|
|
|
$ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::FROZEN, $welfare_config['send_chabao'], LedgerFrozenChangeModel::RwaExchangeRecord, 0);
|
|
$ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::FROZEN, $welfare_config['send_chabao'], LedgerFrozenChangeModel::RwaExchangeRecord, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //扣除茶宝
|
|
|
|
|
+ if($token > 0){
|
|
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, $token, LedgerTokenChangeModel::RwaExchangeRecord, 0);
|
|
|
|
|
+ }
|
|
|
//发放产品奖励
|
|
//发放产品奖励
|
|
|
$rs =WelfareLoginc::setUserWelfareProduct($this->auth->id, $welfare_config['product_id'], ProductOrder::RwaExchange);
|
|
$rs =WelfareLoginc::setUserWelfareProduct($this->auth->id, $welfare_config['product_id'], ProductOrder::RwaExchange);
|
|
|
Log::info($rs, '发放产品奖励状态');
|
|
Log::info($rs, '发放产品奖励状态');
|