|
|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace app\api\controller\coin;
|
|
|
|
|
|
+use app\admin\model\user\User;
|
|
|
+use app\admin\model\user\UserBill;
|
|
|
use app\models\coin\UserCoinTransfer;
|
|
|
use tw\redis\UserRds;
|
|
|
use app\models\store\StoreOrderCartInfo;
|
|
|
@@ -248,7 +250,7 @@ class UserCoinController
|
|
|
return app('json')->fail('启动失败');
|
|
|
}
|
|
|
// 开启
|
|
|
- $step = self::get_step();
|
|
|
+ $step = self::get_step();
|
|
|
$progress = $step;
|
|
|
$icon = DictCoin::getIcon($symbol);
|
|
|
// 已挖总额
|
|
|
@@ -344,47 +346,74 @@ class UserCoinController
|
|
|
{
|
|
|
list($symbol, $amount) = UtilService::postMore([
|
|
|
['symbol', ''],
|
|
|
- ['amount', 0.0]
|
|
|
+ ['amount', 0]
|
|
|
], $request, true);
|
|
|
|
|
|
+ $uid = $request->uid();
|
|
|
+
|
|
|
+ $user = User::getUserinfos($uid);
|
|
|
if (!$symbol) {
|
|
|
return app('json')->fail('参数不可为空');
|
|
|
}
|
|
|
$meta = DictCoin::where('symbol', $symbol)->find();
|
|
|
if (!$meta) {
|
|
|
- return app('json')->fail('未找到目标');
|
|
|
+ return app('json')->fail('未找到币种');
|
|
|
}
|
|
|
$meta = $meta->toArray();
|
|
|
if ($amount < $meta['min_withdrawal']) {
|
|
|
return app('json')->fail('未达到最低限额');
|
|
|
}
|
|
|
- $uid = $request->uid();
|
|
|
$userCoin = UserCoin::where(['uid' => $uid, 'symbol' => $symbol])->find();
|
|
|
if (!$userCoin) {
|
|
|
return app('json')->fail('不适用的用户');
|
|
|
}
|
|
|
$userCoin = $userCoin->toArray();
|
|
|
- if (!$userCoin['addr']) {
|
|
|
- return app('json')->fail('地址未设置');
|
|
|
+
|
|
|
+ if ($symbol == 'RMB') {
|
|
|
+ return $this->_transfer_fiat($user, $amount, $userCoin);
|
|
|
+ } else {
|
|
|
+ return $this->_transfer_crypto_coin($amount, $symbol);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function _transfer_crypto_coin($amount, $symbol)
|
|
|
+ {
|
|
|
+ return app('json')->fail('转账加密货币,请联系客服');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function _transfer_fiat($user, $amount, $userCoin)
|
|
|
+ {
|
|
|
+ $uid = $user['uid'];
|
|
|
+ $symbol = $userCoin['symbol'];
|
|
|
+
|
|
|
+ $amount = floor($amount);
|
|
|
if ($userCoin['balance'] < $amount) {
|
|
|
return app('json')->fail('余额不足');
|
|
|
}
|
|
|
- $transferred = UserCoinTransfer::hasTransferred($uid, $symbol, $userCoin['addr']);
|
|
|
- if (!$transferred) {
|
|
|
- return app('json')->fail('首次操作需联系客服进行');
|
|
|
- }
|
|
|
// transfer
|
|
|
UserCoin::beginTrans();
|
|
|
- $left = twsub($userCoin['balance'], $amount, 8);
|
|
|
- $res1 = UserCoin::where(['uid' => $uid, 'symbol' => $symbol])->update(['balance' => $left]);
|
|
|
- $res2 = UserCoinTransfer::withdrawal($uid, $symbol, $userCoin['addr'], $amount);
|
|
|
+ // 扣除
|
|
|
+ $res1 = UserCoin::where(['uid' => $uid, 'symbol' => $symbol])->dec('balance', $amount)->update();
|
|
|
+ // 添加佣金
|
|
|
+ $res3 = UserBill::income(
|
|
|
+ '钱包转出' . $symbol,
|
|
|
+ $uid,
|
|
|
+ 'now_money',
|
|
|
+ 'brokerage',
|
|
|
+ $amount,
|
|
|
+ 0,
|
|
|
+ twadd($user['brokerage_price'], $amount, 2),
|
|
|
+ '黑洞星球转入' . $amount . '元'
|
|
|
+ );
|
|
|
+ $res4 = User::bcInc($uid, 'brokerage_price', $amount, 'uid');
|
|
|
+ // 转账记录
|
|
|
+ $res2 = true; // UserCoinTransfer::withdrawal($uid, $symbol, $userCoin['addr'], $amount);
|
|
|
|
|
|
- $ok = $res1 && $res2;
|
|
|
+ $ok = $res1 && $res2 && $res3 && $res4;
|
|
|
UserCoin::checkTrans($ok);
|
|
|
if (!$ok) {
|
|
|
return app('json')->fail('执行失败');
|
|
|
}
|
|
|
- return app('json')->successful('成功,已开始审核');
|
|
|
+ return app('json')->successful('转出成功');
|
|
|
}
|
|
|
}
|