|
|
@@ -6,7 +6,7 @@ use app\admin\model\LedgerDeclarationChange;
|
|
|
use app\common\controller\Api;
|
|
|
use app\common\model\LedgerPowerChangeModel;
|
|
|
use app\common\model\LedgerQubicChangeModel;
|
|
|
-use app\common\model\LedgerServersPowerChangeModel;
|
|
|
+use app\common\model\UserModel;
|
|
|
use app\common\model\LedgerSmhChangeModel;
|
|
|
use app\common\model\LedgerTokenChangeModel;
|
|
|
use app\common\model\LedgerUsdtChangeModel;
|
|
|
@@ -15,6 +15,9 @@ use app\common\model\OfflineWithdrawRecordModel;
|
|
|
use fast\Action;
|
|
|
use think\Log;
|
|
|
use think\Env;
|
|
|
+use think\Db;
|
|
|
+use fast\Asset;
|
|
|
+use think\Exception;
|
|
|
|
|
|
/**
|
|
|
* 首页接口
|
|
|
@@ -162,40 +165,52 @@ class Ledger extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 算力明细
|
|
|
+ * 茶宝赠送明细
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function powerList()
|
|
|
+ public function chabao()
|
|
|
{
|
|
|
- $type = $this->request->post('query.action'); // 账变类型
|
|
|
- $where = [
|
|
|
- 'user_id' => $this->auth->getTokenUserID(),
|
|
|
- ];
|
|
|
- if ($type != Action::All) {
|
|
|
- $where['action'] = $type;
|
|
|
- }
|
|
|
- $paginator = (new LedgerPowerChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
|
|
|
- $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
|
|
|
+
|
|
|
+ $this->success('', ['value' => getConfig('chabao_giveaway'), 'text' => getConfig('chabao_giveaway_txt')]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * USDT明细
|
|
|
+ * 茶宝赠送
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function usdtList()
|
|
|
+ public function chabaoGift(UserModel $userModel, LedgerWalletModel $ledgerWalletModel)
|
|
|
{
|
|
|
- $type = $this->request->post('query.action'); // 账变类型
|
|
|
- $where = [
|
|
|
- 'user_id' => $this->auth->getTokenUserID(),
|
|
|
- ];
|
|
|
- if ($type != Action::All) {
|
|
|
- $where['action'] = $type;
|
|
|
+
|
|
|
+ $amount = $this->request->post('amount'); // 茶宝
|
|
|
+ $address = $this->request->post('address'); // 地址
|
|
|
+ if(empty($amount) || empty($address)){
|
|
|
+ $this->error(__('Parameter error'));
|
|
|
}
|
|
|
- $paginator = (new LedgerUsdtChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
|
|
|
- foreach ($paginator as $key => $item){
|
|
|
- $paginator[$key]['action_name'] = Action::getText($item['action']);
|
|
|
+ $real = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $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(__("赠送用户不能是自己"));
|
|
|
+ $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
+ if(bccomp($amount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
|
+
|
|
|
+ // 更新USDT和账变
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$amount, $ledgerWalletModel::GiftPay);
|
|
|
+
|
|
|
+ $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $real, $ledgerWalletModel::GiftReceipt);
|
|
|
+ // 提交事务
|
|
|
+ Db::commit();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('提交失败:' . $e->getMessage());
|
|
|
}
|
|
|
- $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
|
|
|
+
|
|
|
+ $this->success('ok');
|
|
|
}
|
|
|
|
|
|
/**
|