|
|
@@ -36,7 +36,7 @@ class Ledger extends Api
|
|
|
$res['assets'] = $wallet->token;
|
|
|
$res['transfes_fee'] = $config['transfer_fee']; //转让手续费比例
|
|
|
$res['transfes_txt'] = $config['transfes_txt']; //转让文字表述
|
|
|
- $res['chabao_rate'] = $config['chabao_rate']; //茶宝汇率
|
|
|
+ $res['chabao_rate'] = $config['chabao_rate']; //茶宝汇率
|
|
|
$res['withdrawal_next_fee'] = $config['withdrawal_next_fee']; //600以下提现收费
|
|
|
$res['withdrawal_up_fee'] = $config['withdrawal_up_fee']; //600以上提现收费
|
|
|
$res['coin_list'] = [
|
|
|
@@ -44,13 +44,17 @@ class Ledger extends Api
|
|
|
'coin_name' => '茶宝',
|
|
|
'coin_key' => 'token',
|
|
|
'amount' => $wallet->token,
|
|
|
- 'frozen_amount'=> $wallet->frozen //冻结金额
|
|
|
- ],
|
|
|
- [
|
|
|
+ 'frozen_amount'=> 0 //冻结金额
|
|
|
+ ],[
|
|
|
'coin_name' => 'Teac',
|
|
|
'coin_key' => 'teac',
|
|
|
'amount' => $wallet->teac,
|
|
|
'frozen_amount'=> 0 //冻结金额
|
|
|
+ ],[
|
|
|
+ 'coin_name' => '茶宝(标记账户)',
|
|
|
+ 'coin_key' => 'frozen',
|
|
|
+ 'amount' => $wallet->frozen,
|
|
|
+ 'frozen_amount'=> 0 //冻结金额
|
|
|
]
|
|
|
];
|
|
|
$this->success('', $res);
|
|
|
@@ -60,7 +64,7 @@ class Ledger extends Api
|
|
|
* 资产变动明细
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function coinList(LedgerWalletModel $ledgerWalletModel)
|
|
|
+ public function coinList()
|
|
|
{
|
|
|
$type_id = $this->request->post('query.action'); // 账变类型
|
|
|
$coin_type = $this->request->post('query.coin_type'); // 資金类型
|
|
|
@@ -73,15 +77,14 @@ class Ledger extends Api
|
|
|
case 'teac':
|
|
|
$paginator = Loader::model('LedgerTeacChangeModel');
|
|
|
$res['data'] = $paginator->where($where)->order('id DESC')->paginate($this->pageSize);
|
|
|
- $res['statusList'] = $paginator::getStatusList();
|
|
|
break;
|
|
|
case 'token':
|
|
|
- $res['data'] = Loader::model('LedgerTokenChangeModel')->alias('a')
|
|
|
+ $paginator = Loader::model('LedgerTokenChangeModel');
|
|
|
+ $res['data'] = $paginator->alias('a')
|
|
|
->join('user u', 'a.from_id = u.id and a.action > 9 and a.action < 12', 'LEFT')
|
|
|
->field('a.*, u.address')
|
|
|
->where($where)
|
|
|
->order('a.id DESC')->paginate($this->pageSize);
|
|
|
- $res['statusList'] = LedgerWalletModel::getStatusList();
|
|
|
break;
|
|
|
case 'smh':
|
|
|
$paginator = (new LedgerSmhChangeModel());
|
|
|
@@ -93,50 +96,68 @@ class Ledger extends Api
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
break;
|
|
|
}
|
|
|
+ $res['statusList'] = $paginator::getStatusList();
|
|
|
$this->success('',$res);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 资产变动类型
|
|
|
+ * Teac资产转账
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function coinAction()
|
|
|
+ public function freezeTransfer(UserModel $userModel, LedgerWalletModel $ledgerWalletModel)
|
|
|
{
|
|
|
- $coin_type = $this->request->post('coin_type'); // 資金类型
|
|
|
- switch ($coin_type){
|
|
|
- case 'smh':
|
|
|
- $res = (new LedgerSmhChangeModel())->pay_status;//资金变动类型列表
|
|
|
- break;
|
|
|
- case 'qubic':
|
|
|
- $res = (new LedgerQubicChangeModel())->aciton_name;//资金变动类型列表
|
|
|
- break;
|
|
|
- case 'aleo':
|
|
|
- $res = (new LedgerTokenChangeModel())->aciton_name;//资金变动类型列表
|
|
|
- break;
|
|
|
- default:
|
|
|
- $res = Action::getAll($coin_type);//资金变动类型列表
|
|
|
- break;
|
|
|
+ $amount = $this->request->post('amount'); // 茶宝
|
|
|
+ $address = $this->request->post('address'); // 地址
|
|
|
+ if(empty($amount) || empty($address)){
|
|
|
+ $this->error(__('Parameter error'));
|
|
|
}
|
|
|
- $this->success('',$res);
|
|
|
+ $real = bcsub($amount, bcmul(getConfig('frozen_transfer'), $amount, 2), 2) ; // 手续费
|
|
|
+
|
|
|
+ // 启动事务
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $user = $userModel->getByAddress($address);
|
|
|
+ if(empty($user)) throw new Exception(__("赠送用户不存在"));
|
|
|
+ if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));
|
|
|
+
|
|
|
+ $freeze = $ledgerWalletModel::getWalletFrozen($this->auth->id);
|
|
|
+ //剩余冻结金额
|
|
|
+ $available = bcsub($freeze, config('min_frozen'), 2);
|
|
|
+ if(bccomp($amount, $available, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
|
+
|
|
|
+ // 更新USDT和账变
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::FROZEN, -$amount, LedgerTokenChangeModel::FroTrans, $user['id']);
|
|
|
+
|
|
|
+ $ledgerWalletModel->changeWalletAccount($user['id'], Asset::FROZEN, $real, LedgerTokenChangeModel::FroRecei, $this->auth->id);
|
|
|
+ // 提交事务
|
|
|
+ Db::commit();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage(), null, $e->getCode());
|
|
|
+ }
|
|
|
+ $this->success('ok');
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * 茶宝赠送明细
|
|
|
+ * 赠送/转账明细
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function chabao()
|
|
|
+ public function getGiftDesc()
|
|
|
{
|
|
|
- $this->success('', ['value' => getConfig('chabao_giveaway'), 'text' => getConfig('chabao_giveaway_txt')]);
|
|
|
+ $this->success('', ['chabao'=>['value' => getConfig('chabao_giveaway'), 'text' => getConfig('chabao_giveaway_txt')],
|
|
|
+ 'frozen'=>['value' => getConfig('frozen_transfer'), 'text' => getConfig('frozen_transfer_txt')]]);
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 茶宝赠送
|
|
|
* @return void
|
|
|
*/
|
|
|
public function chabaoGift(UserModel $userModel, LedgerWalletModel $ledgerWalletModel)
|
|
|
{
|
|
|
-
|
|
|
$amount = $this->request->post('amount'); // 茶宝
|
|
|
$address = $this->request->post('address'); // 地址
|
|
|
if(empty($amount) || empty($address)){
|
|
|
@@ -155,9 +176,9 @@ class Ledger extends Api
|
|
|
if(bccomp($amount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
|
|
|
|
// 更新USDT和账变
|
|
|
- $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$amount, $ledgerWalletModel::GiftPay, $user['id']);
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$amount, LedgerTokenChangeModel::GiftPay, $user['id']);
|
|
|
|
|
|
- $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $real, $ledgerWalletModel::GiftReceipt, $this->auth->id);
|
|
|
+ $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $real, LedgerTokenChangeModel::GiftReceipt, $this->auth->id);
|
|
|
// 提交事务
|
|
|
Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
@@ -168,25 +189,11 @@ class Ledger extends Api
|
|
|
$this->success('ok');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 虚拟币明细
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function tokenList()
|
|
|
- {
|
|
|
- $type = $this->request->post('query.action'); // 账变类型
|
|
|
- $where = ['user_id' => $this->auth->getTokenUserID()];
|
|
|
- if ($type != Action::All) {
|
|
|
- $where['action'] = $type;
|
|
|
- }
|
|
|
- $paginator = (new LedgerTokenChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
|
|
|
- $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 提现自动打款回调
|
|
|
* 接口回调信息格式:
|
|
|
- *
|
|
|
* @return void
|
|
|
*/
|
|
|
public function withdrawCallback_my()
|