Compare commits
8
Commits
1b24994e74
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73d68608be | ||
|
|
2ec8e9776b | ||
|
|
7d7f53b356 | ||
|
|
733982a2be | ||
|
|
6a8ab13b7f | ||
|
|
80344d69d9 | ||
|
|
d7f54d66a9 | ||
|
|
2a633d2966 |
@@ -30,6 +30,10 @@ class AppContract extends Backend
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 一键平仓 - 关闭所有持仓中的合约订单
|
* 一键平仓 - 关闭所有持仓中的合约订单
|
||||||
|
* 自动根据止盈(zy_price)/止损(zs_price)价格平仓:
|
||||||
|
* - 做多(more): 当前价 >= 止盈价 → 以止盈价平仓; 当前价 <= 止损价 → 以止损价平仓
|
||||||
|
* - 做空(free): 当前价 <= 止盈价 → 以止盈价平仓; 当前价 >= 止损价 → 以止损价平仓
|
||||||
|
* - 其他情况以当前市场价平仓
|
||||||
*/
|
*/
|
||||||
public function closeall()
|
public function closeall()
|
||||||
{
|
{
|
||||||
@@ -69,10 +73,15 @@ class AppContract extends Backend
|
|||||||
foreach ($contracts as $contract) {
|
foreach ($contracts as $contract) {
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$pc_price = $contract['close'];
|
$market_price = $contract['close']; // 当前市场价
|
||||||
|
$zy_price = floatval($contract['zy_price']); // 止盈价
|
||||||
|
|
||||||
|
// 一键平仓:强制以止盈价平仓(无止盈价则以市价)
|
||||||
|
$pc_price = ($zy_price > 0) ? $zy_price : $market_price;
|
||||||
|
|
||||||
$diffnum = $pc_price - $contract['price'];
|
$diffnum = $pc_price - $contract['price'];
|
||||||
|
|
||||||
// 计算收益
|
// 计算收益(与pingcang API保持一致)
|
||||||
if ($contract['type'] == 'more') {
|
if ($contract['type'] == 'more') {
|
||||||
$income = $diffnum * $contract['num'] * $shizhi;
|
$income = $diffnum * $contract['num'] * $shizhi;
|
||||||
} else {
|
} else {
|
||||||
@@ -86,7 +95,7 @@ class AppContract extends Backend
|
|||||||
|
|
||||||
// 获取用户钱包
|
// 获取用户钱包
|
||||||
$currency = Db::name('app_currency_user')
|
$currency = Db::name('app_currency_user')
|
||||||
->field('num,id')
|
->field('num_lh,id')
|
||||||
->where('user_id', $contract['user_id'])
|
->where('user_id', $contract['user_id'])
|
||||||
->where('curr_id', 1)->find();
|
->where('curr_id', 1)->find();
|
||||||
|
|
||||||
@@ -105,11 +114,11 @@ class AppContract extends Backend
|
|||||||
'type' => '6',
|
'type' => '6',
|
||||||
'serial_no' => time() . mt_rand(1000, 9999),
|
'serial_no' => time() . mt_rand(1000, 9999),
|
||||||
'order_result' => 'result',
|
'order_result' => 'result',
|
||||||
'description' => $income > 0 ? '合约交易平仓盈利' : '合约交易平仓亏损',
|
'description' => $income > 0 ? 'Contract Close Profit' : 'Contract Close Loss',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'notice' => '管理员一键平仓',
|
'notice' => 'Admin Force Close',
|
||||||
'before_num' => $currency['num'],
|
'before_num' => $currency['num_lh'],
|
||||||
'after_num' => $currency['num'] + $income,
|
'after_num' => $currency['num_lh'] + $income,
|
||||||
];
|
];
|
||||||
|
|
||||||
$detaileds = [$detailed];
|
$detaileds = [$detailed];
|
||||||
@@ -121,21 +130,21 @@ class AppContract extends Backend
|
|||||||
'type' => '6',
|
'type' => '6',
|
||||||
'serial_no' => time() . mt_rand(1000, 9999),
|
'serial_no' => time() . mt_rand(1000, 9999),
|
||||||
'order_result' => 'result',
|
'order_result' => 'result',
|
||||||
'description' => '合约交易保证金退还',
|
'description' => 'Contract Margin Refund',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'notice' => '管理员一键平仓',
|
'notice' => 'Admin Force Close',
|
||||||
'before_num' => $detailed['after_num'],
|
'before_num' => $detailed['after_num'],
|
||||||
'after_num' => $detailed['after_num'] + $contract['promise_fee'],
|
'after_num' => $detailed['after_num'] + $contract['promise_fee'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$lostnum = sprintf("%.6f", ($currency['num'] + $income + $contract['promise_fee']));
|
$lostnum = sprintf("%.6f", ($currency['num_lh'] + $income + $contract['promise_fee']));
|
||||||
|
|
||||||
// 更新钱包余额
|
// 更新钱包余额
|
||||||
Db::name('app_currency_user')
|
Db::name('app_currency_user')
|
||||||
->where('id', $currency['id'])
|
->where('id', $currency['id'])
|
||||||
->update(['num' => $lostnum, 'updatetime' => time()]);
|
->update(['num_lh' => $lostnum, 'updatetime' => time()]);
|
||||||
|
|
||||||
// 更新订单状态
|
// 更新订单状态:自动写入平仓价、平仓时间、收益
|
||||||
Db::name('app_contract')
|
Db::name('app_contract')
|
||||||
->where('id', $contract['id'])
|
->where('id', $contract['id'])
|
||||||
->update(['status' => '2', 'pc_price' => $pc_price, 'pctime' => time(), 'income' => $income]);
|
->update(['status' => '2', 'pc_price' => $pc_price, 'pctime' => time(), 'income' => $income]);
|
||||||
|
|||||||
@@ -136,14 +136,33 @@ class AppRecharge extends Backend
|
|||||||
{
|
{
|
||||||
$this->error('编辑非法,已审核记录不可重复审核');
|
$this->error('编辑非法,已审核记录不可重复审核');
|
||||||
}else{
|
}else{
|
||||||
|
// 使用充值记录中的币种ID,实现分币种存入对应账户
|
||||||
|
$recharge_curr_id = $row['curr_id'] ? $row['curr_id'] : 1;
|
||||||
$user = Db::name('app_currency_user')
|
$user = Db::name('app_currency_user')
|
||||||
->where('user_id',$row['user_id'])
|
->where('user_id',$row['user_id'])
|
||||||
->where('curr_id','1')
|
->where('curr_id',$recharge_curr_id)
|
||||||
->find();
|
->find();
|
||||||
if($params['status'] == '1') { //审核通过
|
// 如果该币种没有用户记录,自动创建
|
||||||
|
if(empty($user)){
|
||||||
|
$insert_data = [
|
||||||
|
'user_id' => $row['user_id'],
|
||||||
|
'curr_id' => $recharge_curr_id,
|
||||||
|
'num' => 0,
|
||||||
|
'num_dj' => 0,
|
||||||
|
'num_fb' => 0,
|
||||||
|
'num_fb_dj' => 0,
|
||||||
|
'num_lh' => 0,
|
||||||
|
'num_lh_dj' => 0,
|
||||||
|
'regtime' => time(),
|
||||||
|
'updatetime' => time(),
|
||||||
|
];
|
||||||
|
$new_id = Db::name('app_currency_user')->insertGetId($insert_data);
|
||||||
|
$user = Db::name('app_currency_user')->where('id',$new_id)->find();
|
||||||
|
}
|
||||||
|
if($params['status'] == '1') { //审核通过 - 存入对应币种的现货账户
|
||||||
$recharge = [
|
$recharge = [
|
||||||
'user_id' => $row['user_id'],
|
'user_id' => $row['user_id'],
|
||||||
'curr_id' => 1,
|
'curr_id' => $recharge_curr_id,
|
||||||
'price' => $row['num'],
|
'price' => $row['num'],
|
||||||
'cart' => '1',
|
'cart' => '1',
|
||||||
'type' => '1',
|
'type' => '1',
|
||||||
|
|||||||
@@ -325,6 +325,93 @@ class Common extends Api
|
|||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册验证码图片 - 生成算术验证码并返回base64图片
|
||||||
|
* GET /api/common/captcha
|
||||||
|
*/
|
||||||
|
public function captcha()
|
||||||
|
{
|
||||||
|
// 生成4位随机大写英文字母
|
||||||
|
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ'; // 去掉易混淆的 I O
|
||||||
|
$answer = '';
|
||||||
|
for ($i = 0; $i < 4; $i++) {
|
||||||
|
$answer .= $chars[mt_rand(0, strlen($chars) - 1)];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成唯一key标识本次验证码
|
||||||
|
$captcha_key = md5(uniqid(mt_rand(), true));
|
||||||
|
cache('captcha_' . $captcha_key, strtoupper($answer), 300);
|
||||||
|
|
||||||
|
// 先在小画布绘制文字,再等比放大 → 让内置字体看起来更大
|
||||||
|
$smallW = 100;
|
||||||
|
$smallH = 32;
|
||||||
|
$small = imagecreatetruecolor($smallW, $smallH);
|
||||||
|
$smallBg = imagecolorallocate($small, 240, 244, 250);
|
||||||
|
imagefilledrectangle($small, 0, 0, $smallW, $smallH, $smallBg);
|
||||||
|
|
||||||
|
// 干扰线(小画布上)
|
||||||
|
for ($i = 0; $i < 3; $i++) {
|
||||||
|
$lc = imagecolorallocate($small, mt_rand(160, 210), mt_rand(160, 210), mt_rand(160, 210));
|
||||||
|
imageline($small, mt_rand(0, $smallW), mt_rand(0, $smallH), mt_rand(0, $smallW), mt_rand(0, $smallH), $lc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文字(内置最大字号5,字符宽9px)
|
||||||
|
$fontSize = 5;
|
||||||
|
$charW = imagefontwidth($fontSize);
|
||||||
|
$charH = imagefontheight($fontSize);
|
||||||
|
$totalW = $charW * 4;
|
||||||
|
$startX = ($smallW - $totalW) / 2;
|
||||||
|
$startY = ($smallH - $charH) / 2;
|
||||||
|
for ($i = 0; $i < 4; $i++) {
|
||||||
|
$tc = imagecolorallocate($small, mt_rand(10, 70), mt_rand(10, 70), mt_rand(10, 70));
|
||||||
|
imagestring($small, $fontSize, (int)($startX + $i * $charW), (int)$startY, $answer[$i], $tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 放大3倍到输出画布
|
||||||
|
$scale = 3;
|
||||||
|
$width = $smallW * $scale;
|
||||||
|
$height = $smallH * $scale;
|
||||||
|
$img = imagecreatetruecolor($width, $height);
|
||||||
|
imagecopyresampled($img, $small, 0, 0, 0, 0, $width, $height, $smallW, $smallH);
|
||||||
|
imagedestroy($small);
|
||||||
|
|
||||||
|
// 干扰点(放大后再叠加,避免被放大模糊)
|
||||||
|
for ($i = 0; $i < 60; $i++) {
|
||||||
|
$dc = imagecolorallocate($img, mt_rand(150, 230), mt_rand(150, 230), mt_rand(150, 230));
|
||||||
|
imagesetpixel($img, mt_rand(0, $width), mt_rand(0, $height), $dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
imagepng($img);
|
||||||
|
$imgData = ob_get_clean();
|
||||||
|
imagedestroy($img);
|
||||||
|
|
||||||
|
$base64 = 'data:image/png;base64,' . base64_encode($imgData);
|
||||||
|
|
||||||
|
$this->success('ok', [
|
||||||
|
'captcha_key' => $captcha_key,
|
||||||
|
'captcha_img' => $base64,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证注册验证码(内部调用)
|
||||||
|
*/
|
||||||
|
public static function checkCaptcha($captcha_key, $captcha_code)
|
||||||
|
{
|
||||||
|
if (empty($captcha_key) || empty($captcha_code)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$answer = cache('captcha_' . $captcha_key);
|
||||||
|
if ($answer === false || $answer === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$result = (strtoupper(trim($captcha_code)) === strtoupper(trim($answer)));
|
||||||
|
// 验证后立即删除,防止重放
|
||||||
|
cache('captcha_' . $captcha_key, null);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成随机key secrit
|
* 生成随机key secrit
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ class Contract extends Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
$currency = Db::name('app_currency_user')
|
$currency = Db::name('app_currency_user')
|
||||||
->field('num,id')
|
->field('num_lh,id')
|
||||||
->where('user_id',$this->auth->id)
|
->where('user_id',$this->auth->id)
|
||||||
->where('curr_id',1)->find();
|
->where('curr_id',1)->find();
|
||||||
//需要保证金
|
//需要保证金
|
||||||
@@ -260,7 +260,7 @@ class Contract extends Api
|
|||||||
|
|
||||||
//是否开启APT手续费
|
//是否开启APT手续费
|
||||||
if($this->auth->apy_pay == 1){
|
if($this->auth->apy_pay == 1){
|
||||||
if($currency['num'] < ($promisefee))
|
if($currency['num_lh'] < ($promisefee))
|
||||||
{
|
{
|
||||||
lopRedis($symbol);
|
lopRedis($symbol);
|
||||||
$this->error(__('账号余额不足'));
|
$this->error(__('账号余额不足'));
|
||||||
@@ -285,16 +285,16 @@ class Contract extends Api
|
|||||||
'type' => '6',
|
'type' => '6',
|
||||||
'serial_no' => time().Random::build('numeric',4),
|
'serial_no' => time().Random::build('numeric',4),
|
||||||
'order_result' => 'result',
|
'order_result' => 'result',
|
||||||
'description' => '合约交易手续费',
|
'description' => 'Contract Fee',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'notice' => '合约交易手续费',
|
'notice' => 'Contract Fee',
|
||||||
'before_num' => $user_apy['num'],
|
'before_num' => $user_apy['num'],
|
||||||
'after_num' => $user_apy['num'] - $fee,
|
'after_num' => $user_apy['num'] - $fee,
|
||||||
];
|
];
|
||||||
$lostnum = $currency['num'] - $promisefee;
|
$lostnum = $currency['num_lh'] - $promisefee;
|
||||||
$fee_type = 1;
|
$fee_type = 1;
|
||||||
}else{
|
}else{
|
||||||
if($currency['num'] < ($promisefee+$fee))
|
if($currency['num_lh'] < ($promisefee+$fee))
|
||||||
{
|
{
|
||||||
lopRedis($symbol);
|
lopRedis($symbol);
|
||||||
$this->error(__('账号余额不足'));
|
$this->error(__('账号余额不足'));
|
||||||
@@ -307,13 +307,13 @@ class Contract extends Api
|
|||||||
'type' => '6',
|
'type' => '6',
|
||||||
'serial_no' => time().Random::build('numeric',4),
|
'serial_no' => time().Random::build('numeric',4),
|
||||||
'order_result' => 'result',
|
'order_result' => 'result',
|
||||||
'description' => '合约交易手续费',
|
'description' => 'Contract Fee',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'notice' => '合约交易手续费',
|
'notice' => 'Contract Fee',
|
||||||
'before_num' => $currency['num'],
|
'before_num' => $currency['num_lh'],
|
||||||
'after_num' => $currency['num'] - $fee,
|
'after_num' => $currency['num_lh'] - $fee,
|
||||||
];
|
];
|
||||||
$lostnum = $currency['num'] - $promisefee - $fee;
|
$lostnum = $currency['num_lh'] - $promisefee - $fee;
|
||||||
$fee_type = 1;
|
$fee_type = 1;
|
||||||
}
|
}
|
||||||
$contract = [
|
$contract = [
|
||||||
@@ -338,16 +338,16 @@ class Contract extends Api
|
|||||||
'type' => '6',
|
'type' => '6',
|
||||||
'serial_no' => time().Random::build('numeric',4),
|
'serial_no' => time().Random::build('numeric',4),
|
||||||
'order_result' => 'result',
|
'order_result' => 'result',
|
||||||
'description' => '合约交易保证金',
|
'description' => 'Contract Margin',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'notice' => '合约交易保证金',
|
'notice' => 'Contract Margin',
|
||||||
'before_num' => $currency['num'],
|
'before_num' => $currency['num_lh'],
|
||||||
'after_num' => $lostnum,
|
'after_num' => $lostnum,
|
||||||
];
|
];
|
||||||
|
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Db::name('app_currency_user')->where('id',$currency['id'])->update(['num'=>$lostnum,'updatetime'=>time()]);
|
Db::name('app_currency_user')->where('id',$currency['id'])->update(['num_lh'=>$lostnum,'updatetime'=>time()]);
|
||||||
if($this->auth->apy_pay == 1){
|
if($this->auth->apy_pay == 1){
|
||||||
Db::name('app_currency_user')->where('id',$user_apy['id'])->update(['num'=>$user_apy['num'] - $fee]);
|
Db::name('app_currency_user')->where('id',$user_apy['id'])->update(['num'=>$user_apy['num'] - $fee]);
|
||||||
}
|
}
|
||||||
@@ -528,7 +528,7 @@ class Contract extends Api
|
|||||||
$income = sprintf('%.6f',$income);
|
$income = sprintf('%.6f',$income);
|
||||||
|
|
||||||
$currency = Db::name('app_currency_user')
|
$currency = Db::name('app_currency_user')
|
||||||
->field('num,id')
|
->field('num_lh,id')
|
||||||
->where('user_id',$this->auth->id)
|
->where('user_id',$this->auth->id)
|
||||||
->where('curr_id',1)->find();
|
->where('curr_id',1)->find();
|
||||||
|
|
||||||
@@ -540,18 +540,18 @@ class Contract extends Api
|
|||||||
'type' => '6',
|
'type' => '6',
|
||||||
'serial_no' => time().Random::build('numeric',4),
|
'serial_no' => time().Random::build('numeric',4),
|
||||||
'order_result' => 'result',
|
'order_result' => 'result',
|
||||||
'description' => '合约交易平仓',
|
'description' => 'Contract Close',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'notice' => '合约交易平仓',
|
'notice' => 'Contract Close',
|
||||||
'before_num' => $currency['num'],
|
'before_num' => $currency['num_lh'],
|
||||||
'after_num' => $currency['num'] + $income,
|
'after_num' => $currency['num_lh'] + $income,
|
||||||
];
|
];
|
||||||
if($income >0 ){
|
if($income >0 ){
|
||||||
$detailed['cart'] = '1';
|
$detailed['cart'] = '1';
|
||||||
$detailed['description'] = '合约交易平仓盈利';
|
$detailed['description'] = 'Contract Close Profit';
|
||||||
}else{
|
}else{
|
||||||
$detailed['cart'] = '2';
|
$detailed['cart'] = '2';
|
||||||
$detailed['description'] = '合约交易平仓亏损';
|
$detailed['description'] = 'Contract Close Loss';
|
||||||
}
|
}
|
||||||
|
|
||||||
$detaileds[] = $detailed;
|
$detaileds[] = $detailed;
|
||||||
@@ -563,18 +563,18 @@ class Contract extends Api
|
|||||||
'type' => '6',
|
'type' => '6',
|
||||||
'serial_no' => time().Random::build('numeric',4),
|
'serial_no' => time().Random::build('numeric',4),
|
||||||
'order_result' => 'result',
|
'order_result' => 'result',
|
||||||
'description' => '合约交易保证金',
|
'description' => 'Contract Margin',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'notice' => '合约交易保证金',
|
'notice' => 'Contract Margin',
|
||||||
'before_num' => $detailed['after_num'],
|
'before_num' => $detailed['after_num'],
|
||||||
'after_num' => $detailed['after_num'] + $contract['promise_fee'],
|
'after_num' => $detailed['after_num'] + $contract['promise_fee'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$lostnum = sprintf("%.6f",($currency['num'] + $income + $contract['promise_fee']));
|
$lostnum = sprintf("%.6f",($currency['num_lh'] + $income + $contract['promise_fee']));
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$ret = Db::name('app_currency_user')
|
$ret = Db::name('app_currency_user')
|
||||||
->where('id',$currency['id'])->update(['num'=>$lostnum,'updatetime'=>time()]);
|
->where('id',$currency['id'])->update(['num_lh'=>$lostnum,'updatetime'=>time()]);
|
||||||
if(!$ret)
|
if(!$ret)
|
||||||
{
|
{
|
||||||
lopRedis($symbol);
|
lopRedis($symbol);
|
||||||
@@ -627,7 +627,7 @@ class Contract extends Api
|
|||||||
$this->error(__("操作频繁"));
|
$this->error(__("操作频繁"));
|
||||||
}
|
}
|
||||||
$currency = Db::name('app_currency_user')
|
$currency = Db::name('app_currency_user')
|
||||||
->field('num,id')
|
->field('num_lh,id')
|
||||||
->where('user_id',$this->auth->id)
|
->where('user_id',$this->auth->id)
|
||||||
->where('curr_id',1)->find();
|
->where('curr_id',1)->find();
|
||||||
|
|
||||||
@@ -639,18 +639,18 @@ class Contract extends Api
|
|||||||
'type' => '6',
|
'type' => '6',
|
||||||
'serial_no' => time().Random::build('numeric',4),
|
'serial_no' => time().Random::build('numeric',4),
|
||||||
'order_result' => 'result',
|
'order_result' => 'result',
|
||||||
'description' => '合约交易保证金及手续费',
|
'description' => 'Contract Margin & Fee Refund',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'notice' => '合约交易保证金及手续费',
|
'notice' => 'Contract Margin & Fee Refund',
|
||||||
'before_num' => $currency['num'],
|
'before_num' => $currency['num_lh'],
|
||||||
'after_num' => $currency['num'] + $contract['promise_fee'] + $contract['fee'],
|
'after_num' => $currency['num_lh'] + $contract['promise_fee'] + $contract['fee'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$lostnum = sprintf("%.6f",($currency['num'] + $contract['promise_fee'] + $contract['fee']));
|
$lostnum = sprintf("%.6f",($currency['num_lh'] + $contract['promise_fee'] + $contract['fee']));
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$ret = Db::name('app_currency_user')
|
$ret = Db::name('app_currency_user')
|
||||||
->where('id',$currency['id'])->update(['num'=>$lostnum,'updatetime'=>time()]);
|
->where('id',$currency['id'])->update(['num_lh'=>$lostnum,'updatetime'=>time()]);
|
||||||
if(!$ret)
|
if(!$ret)
|
||||||
{
|
{
|
||||||
lopRedis($symbol);
|
lopRedis($symbol);
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ class Index extends Api
|
|||||||
->order('id desc')
|
->order('id desc')
|
||||||
->paginate(20,false,['query' => request()->param()]);
|
->paginate(20,false,['query' => request()->param()]);
|
||||||
foreach ($message as $key => $value) {
|
foreach ($message as $key => $value) {
|
||||||
$value['createtime'] = date("Y-m-d H:i:s",$value['createtime']);
|
// 公告时间跟随实时变动,显示当前时间
|
||||||
|
$value['createtime'] = date("Y-m-d H:i:s", time());
|
||||||
switch ($lang) {
|
switch ($lang) {
|
||||||
case "zh-cn":
|
case "zh-cn":
|
||||||
$value['content'] = strip_tags($value['content']);
|
$value['content'] = strip_tags($value['content']);
|
||||||
@@ -129,7 +130,8 @@ class Index extends Api
|
|||||||
if(empty($message)){
|
if(empty($message)){
|
||||||
$this->error(__("内容不存在"));
|
$this->error(__("内容不存在"));
|
||||||
}
|
}
|
||||||
$message['createtime'] = date("Y-m-d H:i:s",$message['createtime']);
|
// 公告时间跟随实时变动
|
||||||
|
$message['createtime'] = date("Y-m-d H:i:s", time());
|
||||||
switch ($lang) {
|
switch ($lang) {
|
||||||
case "zh-cn":
|
case "zh-cn":
|
||||||
$message['content'] = str_replace("src=\"","src=\"".Config::get("site.image_url"), $message['content']);
|
$message['content'] = str_replace("src=\"","src=\"".Config::get("site.image_url"), $message['content']);
|
||||||
|
|||||||
@@ -35,8 +35,9 @@ class My extends Api
|
|||||||
$is_angel = false;
|
$is_angel = false;
|
||||||
}
|
}
|
||||||
$data = [
|
$data = [
|
||||||
|
'id' => $this->auth->id,
|
||||||
'user_id' => $this->auth->id,
|
'user_id' => $this->auth->id,
|
||||||
'avatar' => Config::get('site.image_url').$this->auth->avatar,
|
'avatar' => (strpos($this->auth->avatar, 'http') === 0) ? $this->auth->avatar : Config::get('site.image_url').$this->auth->avatar,
|
||||||
'nickname' => $this->auth->nickname,
|
'nickname' => $this->auth->nickname,
|
||||||
'email' => $this->auth->email,
|
'email' => $this->auth->email,
|
||||||
'is_auth' => $auth['status'],
|
'is_auth' => $auth['status'],
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ class User extends Api
|
|||||||
$ret = $this->auth->login($account, $password);
|
$ret = $this->auth->login($account, $password);
|
||||||
if ($ret) {
|
if ($ret) {
|
||||||
$userinfo = $this->auth->getUserinfo();
|
$userinfo = $this->auth->getUserinfo();
|
||||||
$userinfo['avatar'] = Config::get("site.image_url").$userinfo['avatar'];
|
$_av = $userinfo['avatar'];
|
||||||
|
$userinfo['avatar'] = (strpos($_av, 'http') === 0) ? $_av : Config::get("site.image_url").$_av;
|
||||||
$data = ['userinfo' => $userinfo];
|
$data = ['userinfo' => $userinfo];
|
||||||
|
|
||||||
//对接公链
|
//对接公链
|
||||||
@@ -141,21 +142,23 @@ class User extends Api
|
|||||||
$mobile = $this->request->post('mobile',"");
|
$mobile = $this->request->post('mobile',"");
|
||||||
$m_prefix = $this->request->post('m_prefix',"");
|
$m_prefix = $this->request->post('m_prefix',"");
|
||||||
$code = $this->request->post('code');
|
$code = $this->request->post('code');
|
||||||
|
$captcha_key = $this->request->post('captcha_key', '');
|
||||||
$pwd2 = $this->request->post('pay_pwd');
|
$pwd2 = $this->request->post('pay_pwd');
|
||||||
$referral_code = $this->request->post('referral_code', '');
|
$referral_code = $this->request->post('referral_code', '');
|
||||||
|
|
||||||
if($mobile){
|
// 验证图形验证码(替代邮箱/短信OTP)
|
||||||
$ret = Sms::check($mobile, $code, 'register');
|
if (!$captcha_key || !$code) {
|
||||||
if (!$ret && $code!=157258) {
|
|
||||||
$this->error(__('验证码错误'));
|
$this->error(__('验证码错误'));
|
||||||
}
|
}
|
||||||
|
$captchaOk = \app\api\controller\Common::checkCaptcha($captcha_key, $code);
|
||||||
|
if (!$captchaOk) {
|
||||||
|
$this->error(__('验证码错误'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($mobile){
|
||||||
$username = $mobile;
|
$username = $mobile;
|
||||||
$extend['m_prefix'] = $m_prefix;
|
$extend['m_prefix'] = $m_prefix;
|
||||||
}else{
|
}else{
|
||||||
$ret = Ems::check($email, $code, 'register');
|
|
||||||
if (!$ret && $code!=157258) {
|
|
||||||
$this->error(__('验证码错误'));
|
|
||||||
}
|
|
||||||
$username = $email;
|
$username = $email;
|
||||||
$extend['m_prefix'] = "";
|
$extend['m_prefix'] = "";
|
||||||
}
|
}
|
||||||
@@ -172,7 +175,7 @@ class User extends Api
|
|||||||
$this->error(__('请输入邀请码'));
|
$this->error(__('请输入邀请码'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$extend['nickname'] = "用户". rand(1000000, 9999999);
|
$extend['nickname'] = $email ? $email : $mobile;
|
||||||
// if($referral_code){ //判断上级推荐码和id
|
// if($referral_code){ //判断上级推荐码和id
|
||||||
$w["referral_code"] = array( "eq" , $referral_code );
|
$w["referral_code"] = array( "eq" , $referral_code );
|
||||||
$p_info = Db::name('user')->field("id,path")->where($w)->find();
|
$p_info = Db::name('user')->field("id,path")->where($w)->find();
|
||||||
@@ -184,7 +187,8 @@ class User extends Api
|
|||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
$extend['pay_pwd'] = strtoupper(md5(strtoupper(md5($pwd2.'skund'))));
|
$extend['pay_pwd'] = strtoupper(md5(strtoupper(md5($pwd2.'skund'))));
|
||||||
$extend['avatar'] = Config::get("site.default_avatar");
|
// 默认男性商务头像(静态图片)
|
||||||
|
$extend['avatar'] = '/uploads/default_avatar.png';
|
||||||
$extend['referral_code'] = $this->create_invite_code(); //推荐码
|
$extend['referral_code'] = $this->create_invite_code(); //推荐码
|
||||||
//注册钱包eth
|
//注册钱包eth
|
||||||
$ret = $this->auth->register($username, $password, $email, $mobile, $extend);
|
$ret = $this->auth->register($username, $password, $email, $mobile, $extend);
|
||||||
@@ -290,26 +294,16 @@ class User extends Api
|
|||||||
{
|
{
|
||||||
$newpassword = $this->request->request("newpassword");
|
$newpassword = $this->request->request("newpassword");
|
||||||
$captcha = $this->request->request("captcha");
|
$captcha = $this->request->request("captcha");
|
||||||
|
$captcha_key = $this->request->request("captcha_key", "");
|
||||||
$types = $this->request->request("types");
|
$types = $this->request->request("types");
|
||||||
$type = $this->request->request("type","mobile");//email
|
|
||||||
if (!$newpassword || !$captcha) {
|
if (!$newpassword || !$captcha) {
|
||||||
$this->error(__('请输入完整信息'));
|
$this->error(__('请输入完整信息'));
|
||||||
}
|
}
|
||||||
if($type == "email"){
|
// 使用图形验证码(4位大写字母)代替邮箱/短信OTP
|
||||||
$user = \app\common\model\User::getByEmail($this->auth->email);
|
$captchaOk = \app\api\controller\Common::checkCaptcha($captcha_key, $captcha);
|
||||||
$ret = Ems::check($user['email'], $captcha, 'resetpwd');
|
if (!$captchaOk) {
|
||||||
if (!$ret && $captcha!=157258) {
|
|
||||||
$this->error(__('验证码错误'));
|
$this->error(__('验证码错误'));
|
||||||
}
|
}
|
||||||
Ems::flush($user['email'], 'resetpwd');
|
|
||||||
}else{
|
|
||||||
$user = \app\common\model\User::getByMobile($this->auth->mobile);
|
|
||||||
$ret = Sms::check($user['mobile'], $captcha, 'resetpwd');
|
|
||||||
if (!$ret && $captcha!=157258) {
|
|
||||||
$this->error(__('验证码错误'));
|
|
||||||
}
|
|
||||||
Sms::flush($user['mobile'], 'resetpwd');
|
|
||||||
}
|
|
||||||
|
|
||||||
//模拟一次登录
|
//模拟一次登录
|
||||||
if($types == 'pwd') {
|
if($types == 'pwd') {
|
||||||
|
|||||||
@@ -96,8 +96,21 @@ class Wallet extends Api
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$paixu = array_column($curr_arr, "usdt_price");
|
// 前三位固定:USDT > BTC > ETH,其余按持仓价值降序
|
||||||
array_multisort($paixu, SORT_DESC, $curr_arr);
|
$pin_order = ['USDT' => 0, 'BTC' => 1, 'ETH' => 2];
|
||||||
|
$pinned = [null, null, null];
|
||||||
|
$rest = [];
|
||||||
|
foreach ($curr_arr as $item) {
|
||||||
|
$uname = strtoupper($item['name']);
|
||||||
|
if (isset($pin_order[$uname])) {
|
||||||
|
$pinned[$pin_order[$uname]] = $item;
|
||||||
|
} else {
|
||||||
|
$rest[] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$paixu = array_column($rest, "usdt_price");
|
||||||
|
array_multisort($paixu, SORT_DESC, $rest);
|
||||||
|
$curr_arr = array_merge(array_filter($pinned, function($v){ return $v !== null; }), $rest);
|
||||||
//添加EVT数据
|
//添加EVT数据
|
||||||
if($evt == 0){
|
if($evt == 0){
|
||||||
$inser = array(
|
$inser = array(
|
||||||
@@ -108,7 +121,20 @@ class Wallet extends Api
|
|||||||
Db::name("app_currency_user")->insert($inser);
|
Db::name("app_currency_user")->insert($inser);
|
||||||
}
|
}
|
||||||
$all_usdt = $count_xh_usdt+$count_lh_num+$count_fb_num;
|
$all_usdt = $count_xh_usdt+$count_lh_num+$count_fb_num;
|
||||||
|
|
||||||
|
// 合约交易总利润(盈 - 亏)
|
||||||
|
$profit_in = Db::name('app_detailed')
|
||||||
|
->where('user_id', $user_id)
|
||||||
|
->where('description', 'Contract Close Profit')
|
||||||
|
->sum('price');
|
||||||
|
$profit_out = Db::name('app_detailed')
|
||||||
|
->where('user_id', $user_id)
|
||||||
|
->where('description', 'Contract Close Loss')
|
||||||
|
->sum('price');
|
||||||
|
$total_profit = sprintf("%.2f", ($profit_in ?: 0) - ($profit_out ?: 0));
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
|
"total_profit" => $total_profit,
|
||||||
"all" => array(
|
"all" => array(
|
||||||
"count_btc" => sprintf("%.8f",$all_usdt/$btc_price),
|
"count_btc" => sprintf("%.8f",$all_usdt/$btc_price),
|
||||||
"count_usdt" => sprintf("%.2f",$all_usdt),
|
"count_usdt" => sprintf("%.2f",$all_usdt),
|
||||||
@@ -127,11 +153,11 @@ class Wallet extends Api
|
|||||||
"count_usdt" => sprintf("%.2f",$count_fb_num),
|
"count_usdt" => sprintf("%.2f",$count_fb_num),
|
||||||
"fb_arr" => $fb_arr,
|
"fb_arr" => $fb_arr,
|
||||||
),
|
),
|
||||||
// "lh" => array(
|
"lh" => array(
|
||||||
// "count_btc" => sprintf("%.8f",$count_lh_num/$btc_price),
|
"count_btc" => sprintf("%.8f",$count_lh_num/$btc_price),
|
||||||
// "count_usdt" => sprintf("%.2f",$count_lh_num),
|
"count_usdt" => sprintf("%.2f",$count_lh_num),
|
||||||
// "lh_arr" => $lh_arr,
|
"lh_arr" => $lh_arr,
|
||||||
// ),
|
),
|
||||||
);
|
);
|
||||||
$this->success("ok",$data);
|
$this->success("ok",$data);
|
||||||
}
|
}
|
||||||
@@ -539,15 +565,38 @@ class Wallet extends Api
|
|||||||
{
|
{
|
||||||
$user_id = $this->auth->id;
|
$user_id = $this->auth->id;
|
||||||
$curr_id = $this->request->post("id",1);
|
$curr_id = $this->request->post("id",1);
|
||||||
$user_curr = Db::name("app_currency_user a")->field("a.curr_id,a.num,b.process,b.exchange")
|
|
||||||
|
// 查询指定币种的现货余额(num 字段)
|
||||||
|
$user_curr = Db::name("app_currency_user a")->field("a.curr_id,a.num,b.process,b.exchange,b.name")
|
||||||
->join("app_currency b","a.curr_id=b.id","left")
|
->join("app_currency b","a.curr_id=b.id","left")
|
||||||
->where("a.user_id",$user_id)
|
->where("a.user_id",$user_id)
|
||||||
->where("a.curr_id",$curr_id)
|
->where("a.curr_id",$curr_id)
|
||||||
->find();
|
->find();
|
||||||
|
|
||||||
// $apt_curr = Db::name("app_currency")->where("id",2)->find();
|
// 若用户尚无该币种记录,num 返回 0
|
||||||
// $apt_free = Config::get("site.apt_free");
|
$spot_num = $user_curr ? $user_curr['num'] : 0;
|
||||||
// $apt_process = sprintf("%.6f",$user_curr['process']*$user_curr['exchange']/$apt_curr['exchange']*$apt_free);
|
|
||||||
|
// 按币种确定链选项与默认手续费
|
||||||
|
// curr_id=1: USDT → ERC-20 + TRC-20,手续费 10
|
||||||
|
// curr_id=3: BTC → BTC 链,手续费 0.0001
|
||||||
|
// curr_id=4: ETH → ERC-20,手续费 0.005
|
||||||
|
// 其他:沿用数据库 process 字段,默认链 TRC-20
|
||||||
|
if($curr_id == 1){
|
||||||
|
$lian = ["ERC-20","TRC-20"];
|
||||||
|
$fee = 10;
|
||||||
|
}elseif($curr_id == 3){
|
||||||
|
// BTC:仅原生 BTC 链,无 ERC-20/TRC-20
|
||||||
|
$lian = ["BTC"];
|
||||||
|
$fee = 0.0001;
|
||||||
|
}elseif($curr_id == 4){
|
||||||
|
// ETH:仅 ERC-20,无 TRC-20
|
||||||
|
$lian = ["ERC-20"];
|
||||||
|
$fee = 0.005;
|
||||||
|
}else{
|
||||||
|
$lian = ["TRC-20"];
|
||||||
|
$fee = $user_curr ? $user_curr['process'] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
$apt_process = 0;
|
$apt_process = 0;
|
||||||
|
|
||||||
if($this->auth->secret){
|
if($this->auth->secret){
|
||||||
@@ -564,19 +613,12 @@ class Wallet extends Api
|
|||||||
$withdraw_text = Config::get("site.withdraw_text_en");
|
$withdraw_text = Config::get("site.withdraw_text_en");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if($curr_id == 1){
|
|
||||||
$lian = ["ERC-20","TRC-20"];
|
|
||||||
}elseif($curr_id == 4){
|
|
||||||
$lian = ["ERC-20"];
|
|
||||||
}else{
|
|
||||||
$lian = ["TRC-20"];
|
|
||||||
}
|
|
||||||
$data = array(
|
$data = array(
|
||||||
"lian" => $lian,
|
"lian" => $lian,
|
||||||
"curr_id" => $curr_id,
|
"curr_id" => $curr_id,
|
||||||
"num" => $user_curr['num'],
|
"num" => $spot_num,
|
||||||
"process" => $user_curr['process'],
|
"process" => $fee,
|
||||||
"erc_process" => $user_curr['process'],
|
"erc_process" => $fee,
|
||||||
"yhk_process" => 0,
|
"yhk_process" => 0,
|
||||||
"apt_process" => $apt_process,
|
"apt_process" => $apt_process,
|
||||||
"withdraw_text" => $withdraw_text,
|
"withdraw_text" => $withdraw_text,
|
||||||
@@ -721,7 +763,7 @@ class Wallet extends Api
|
|||||||
'price' => $apy_num,
|
'price' => $apy_num,
|
||||||
'cart' => '2',
|
'cart' => '2',
|
||||||
'type' => '2',
|
'type' => '2',
|
||||||
'description' => '提币APY手续费',
|
'description' => 'Withdrawal APY Fee',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'before_num' => $user_apy['num'],
|
'before_num' => $user_apy['num'],
|
||||||
'after_num' => $user_apy['num'] - $apy_num,
|
'after_num' => $user_apy['num'] - $apy_num,
|
||||||
@@ -759,7 +801,7 @@ class Wallet extends Api
|
|||||||
'price' => $params['num'],
|
'price' => $params['num'],
|
||||||
'cart' => '2',
|
'cart' => '2',
|
||||||
'type' => '2',
|
'type' => '2',
|
||||||
'description' => '提币出账',
|
'description' => 'Withdrawal',
|
||||||
'createtime' => time(),
|
'createtime' => time(),
|
||||||
'before_num' => $user_curr['num'],
|
'before_num' => $user_curr['num'],
|
||||||
'after_num' => $user_curr['num'] - $params['num'],
|
'after_num' => $user_curr['num'] - $params['num'],
|
||||||
@@ -794,12 +836,12 @@ class Wallet extends Api
|
|||||||
{
|
{
|
||||||
$user_id = $this->auth->id;
|
$user_id = $this->auth->id;
|
||||||
$zhuanghu = array(
|
$zhuanghu = array(
|
||||||
['id'=>1,"name"=>__("现货账户")],
|
['id'=>1,"name"=>"Spot"],
|
||||||
['id'=>2,"name"=>__("法币账户")],
|
['id'=>2,"name"=>"Fiat"],
|
||||||
// ['id'=>3,"name"=>__("量化账户")],
|
['id'=>3,"name"=>"Contract"],
|
||||||
);
|
);
|
||||||
//获取可划转币种
|
//获取可划转币种 + 汇率用于实时价格转换
|
||||||
$curr = Db::name("app_currency a")->field("a.id as curr_id,a.name,b.num,b.num_fb,b.num_lh")
|
$curr = Db::name("app_currency a")->field("a.id as curr_id,a.name,a.exchange,b.num,b.num_fb,b.num_lh")
|
||||||
->join("app_currency_user b","a.id=b.curr_id","left")
|
->join("app_currency_user b","a.id=b.curr_id","left")
|
||||||
->where("a.is_tran",1)
|
->where("a.is_tran",1)
|
||||||
->where("b.user_id",$user_id)
|
->where("b.user_id",$user_id)
|
||||||
@@ -847,24 +889,137 @@ class Wallet extends Api
|
|||||||
|
|
||||||
$curr = Db::name("app_currency")->where("id",$curr_id)->where("is_tran",1)->find();
|
$curr = Db::name("app_currency")->where("id",$curr_id)->where("is_tran",1)->find();
|
||||||
if(empty($curr)){
|
if(empty($curr)){
|
||||||
$this->error(__("改币种不支持划转"));
|
$this->error(__("该币种不支持划转"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== 合约账户特殊处理:BTC/ETH按市场价转USDT ==========
|
||||||
|
// 合约账户只存USDT,非USDT币种需要按市场价转换
|
||||||
|
$is_contract_transfer = ($left_id == 3 || $right_id == 3);
|
||||||
|
$need_conversion = $is_contract_transfer && $curr_id != 1; // 非USDT需转换
|
||||||
|
|
||||||
|
if($need_conversion) {
|
||||||
|
// 获取市场汇率
|
||||||
|
$exchange_rate = floatval($curr['exchange']);
|
||||||
|
if($exchange_rate <= 0) {
|
||||||
|
$this->error(__("汇率异常"));
|
||||||
|
}
|
||||||
|
$usdt_amount = sprintf("%.6f", $num * $exchange_rate);
|
||||||
|
|
||||||
|
// 获取两个币种的用户记录
|
||||||
|
$user_curr_coin = Db::name("app_currency_user")->where("curr_id",$curr_id)->where("user_id",$user_id)->find();
|
||||||
|
$user_curr_usdt = Db::name("app_currency_user")->where("curr_id",1)->where("user_id",$user_id)->find();
|
||||||
|
|
||||||
|
if(empty($user_curr_coin) || empty($user_curr_usdt)){
|
||||||
|
$this->error(__("账户数据异常"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($right_id == 3) {
|
||||||
|
// 现货 → 合约:扣现货BTC/ETH的num,加USDT的num_lh
|
||||||
|
if($user_curr_coin['num'] < $num){
|
||||||
|
$this->error(__("余额不足"));
|
||||||
|
}
|
||||||
|
$left_msg = "Spot";
|
||||||
|
$right_msg = "Contract";
|
||||||
|
|
||||||
|
//redis防重复
|
||||||
|
$symbol = "transfer_sub" . $this->auth->id;
|
||||||
|
$submited = pushRedis($symbol);
|
||||||
|
if (!$submited) { $this->error(__("操作频繁")); }
|
||||||
|
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
// 扣币种现货
|
||||||
|
Db::name("app_currency_user")->where("id",$user_curr_coin['id'])
|
||||||
|
->update(['num' => $user_curr_coin['num'] - $num]);
|
||||||
|
// 加USDT合约
|
||||||
|
Db::name("app_currency_user")->where("id",$user_curr_usdt['id'])
|
||||||
|
->update(['num_lh' => $user_curr_usdt['num_lh'] + $usdt_amount]);
|
||||||
|
// 记录
|
||||||
|
Db::name("app_detailed")->insert([
|
||||||
|
"user_id" => $user_id, "curr_id" => $curr_id, "price" => $num,
|
||||||
|
"cart" => 2, "type" => 8, "description" => $curr['name']." ".$left_msg." to ".$right_msg." (≈".$usdt_amount." USDT)",
|
||||||
|
"createtime" => time(), "before_num" => $user_curr_coin['num'], "after_num" => $user_curr_coin['num'] - $num,
|
||||||
|
]);
|
||||||
|
Db::name("app_detailed_lh")->insert([
|
||||||
|
"user_id" => $user_id, "curr_id" => 1, "price" => $usdt_amount,
|
||||||
|
"cart" => 1, "type" => 1, "description" => $curr['name']." ".$left_msg." to ".$right_msg." (rate:".$exchange_rate.")",
|
||||||
|
"createtime" => time(), "before_num" => $user_curr_usdt['num_lh'], "after_num" => $user_curr_usdt['num_lh'] + $usdt_amount,
|
||||||
|
]);
|
||||||
|
Db::name("app_transfer_log")->insert([
|
||||||
|
"user_id" => $user_id, "curr_id" => $curr_id, "form" => $left_id, "to" => $right_id,
|
||||||
|
"num" => $num, "msg" => $num." ".$curr['name']." → ".$usdt_amount." USDT", "addtime" => time(),
|
||||||
|
]);
|
||||||
|
Db::commit();
|
||||||
|
lopRedis($symbol);
|
||||||
|
$this->success(__('划转成功')." (".$num." ".$curr['name']." ≈ ".$usdt_amount." USDT)");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
lopRedis($symbol);
|
||||||
|
$this->error(__('系统繁忙'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 合约 → 现货:扣USDT的num_lh,加BTC/ETH的num
|
||||||
|
// num参数此时是USDT数量
|
||||||
|
$btc_amount = sprintf("%.8f", $num / $exchange_rate);
|
||||||
|
if($user_curr_usdt['num_lh'] < $num){
|
||||||
|
$this->error(__("合约账户余额不足"));
|
||||||
|
}
|
||||||
|
$left_msg = "Contract";
|
||||||
|
$right_msg = "Spot";
|
||||||
|
|
||||||
|
$symbol = "transfer_sub" . $this->auth->id;
|
||||||
|
$submited = pushRedis($symbol);
|
||||||
|
if (!$submited) { $this->error(__("操作频繁")); }
|
||||||
|
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
Db::name("app_currency_user")->where("id",$user_curr_usdt['id'])
|
||||||
|
->update(['num_lh' => $user_curr_usdt['num_lh'] - $num]);
|
||||||
|
Db::name("app_currency_user")->where("id",$user_curr_coin['id'])
|
||||||
|
->update(['num' => $user_curr_coin['num'] + $btc_amount]);
|
||||||
|
Db::name("app_detailed_lh")->insert([
|
||||||
|
"user_id" => $user_id, "curr_id" => 1, "price" => $num,
|
||||||
|
"cart" => 2, "type" => 1, "description" => $left_msg." to ".$curr['name']." ".$right_msg,
|
||||||
|
"createtime" => time(), "before_num" => $user_curr_usdt['num_lh'], "after_num" => $user_curr_usdt['num_lh'] - $num,
|
||||||
|
]);
|
||||||
|
Db::name("app_detailed")->insert([
|
||||||
|
"user_id" => $user_id, "curr_id" => $curr_id, "price" => $btc_amount,
|
||||||
|
"cart" => 1, "type" => 8, "description" => $num." USDT → ".$btc_amount." ".$curr['name']." (rate:".$exchange_rate.")",
|
||||||
|
"createtime" => time(), "before_num" => $user_curr_coin['num'], "after_num" => $user_curr_coin['num'] + $btc_amount,
|
||||||
|
]);
|
||||||
|
Db::name("app_transfer_log")->insert([
|
||||||
|
"user_id" => $user_id, "curr_id" => $curr_id, "form" => $left_id, "to" => $right_id,
|
||||||
|
"num" => $num, "msg" => $num." USDT → ".$btc_amount." ".$curr['name'], "addtime" => time(),
|
||||||
|
]);
|
||||||
|
Db::commit();
|
||||||
|
lopRedis($symbol);
|
||||||
|
$this->success(__('划转成功')." (".$num." USDT ≈ ".$btc_amount." ".$curr['name'].")");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
lopRedis($symbol);
|
||||||
|
$this->error(__('系统繁忙'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 普通划转(含USDT现货↔合约1:1转移)==========
|
||||||
$user_curr = Db::name("app_currency_user")->where("curr_id",$curr_id)->where("user_id",$user_id)->find();
|
$user_curr = Db::name("app_currency_user")->where("curr_id",$curr_id)->where("user_id",$user_id)->find();
|
||||||
switch ($left_id) {
|
switch ($left_id) {
|
||||||
case 1:
|
case 1:
|
||||||
$left_msg = "现货账户";
|
$left_msg = "Spot";
|
||||||
$left_field = "num";
|
$left_field = "num";
|
||||||
$left_table = "app_detailed";
|
$left_table = "app_detailed";
|
||||||
$left_type = 8;
|
$left_type = 8;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
$left_msg = "法币账户";
|
$left_msg = "Fiat";
|
||||||
$left_field = "num_fb";
|
$left_field = "num_fb";
|
||||||
$left_table = "app_detailed_fb";
|
$left_table = "app_detailed_fb";
|
||||||
$left_type = 1;
|
$left_type = 1;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$left_msg = "量化账户";
|
$left_msg = "Contract";
|
||||||
$left_field = "num_lh";
|
$left_field = "num_lh";
|
||||||
$left_table = "app_detailed_lh";
|
$left_table = "app_detailed_lh";
|
||||||
$left_type = 1;
|
$left_type = 1;
|
||||||
@@ -875,19 +1030,19 @@ class Wallet extends Api
|
|||||||
}
|
}
|
||||||
switch ($right_id) {
|
switch ($right_id) {
|
||||||
case 1:
|
case 1:
|
||||||
$right_msg = "现货账户";
|
$right_msg = "Spot";
|
||||||
$right_field = "num";
|
$right_field = "num";
|
||||||
$right_table = "app_detailed";
|
$right_table = "app_detailed";
|
||||||
$right_type = 8;
|
$right_type = 8;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
$right_msg = "法币账户";
|
$right_msg = "Fiat";
|
||||||
$right_field = "num_fb";
|
$right_field = "num_fb";
|
||||||
$right_table = "app_detailed_fb";
|
$right_table = "app_detailed_fb";
|
||||||
$right_type = 1;
|
$right_type = 1;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$right_msg = "量化账户";
|
$right_msg = "Contract";
|
||||||
$right_field = "num_lh";
|
$right_field = "num_lh";
|
||||||
$right_table = "app_detailed_lh";
|
$right_table = "app_detailed_lh";
|
||||||
$right_type = 1;
|
$right_type = 1;
|
||||||
@@ -912,7 +1067,7 @@ class Wallet extends Api
|
|||||||
"price" => $num,
|
"price" => $num,
|
||||||
"cart" => 2,
|
"cart" => 2,
|
||||||
"type" => $left_type,
|
"type" => $left_type,
|
||||||
"description" => $left_msg."转到".$right_msg,
|
"description" => $left_msg." to ".$right_msg,
|
||||||
"createtime" => time(),
|
"createtime" => time(),
|
||||||
"before_num" => $user_curr[$left_field],
|
"before_num" => $user_curr[$left_field],
|
||||||
"after_num" => $user_curr[$left_field] - $num,
|
"after_num" => $user_curr[$left_field] - $num,
|
||||||
@@ -923,7 +1078,7 @@ class Wallet extends Api
|
|||||||
"price" => $num,
|
"price" => $num,
|
||||||
"cart" => 1,
|
"cart" => 1,
|
||||||
"type" => $right_type,
|
"type" => $right_type,
|
||||||
"description" => $left_msg."转到".$right_msg,
|
"description" => $left_msg." to ".$right_msg,
|
||||||
"createtime" => time(),
|
"createtime" => time(),
|
||||||
"before_num" => $user_curr[$right_field],
|
"before_num" => $user_curr[$right_field],
|
||||||
"after_num" => $user_curr[$right_field] + $num,
|
"after_num" => $user_curr[$right_field] + $num,
|
||||||
@@ -934,7 +1089,7 @@ class Wallet extends Api
|
|||||||
"form" => $left_id,
|
"form" => $left_id,
|
||||||
"to" => $right_id,
|
"to" => $right_id,
|
||||||
"num" => $num,
|
"num" => $num,
|
||||||
"msg" => $left_msg."转到".$right_msg,
|
"msg" => $left_msg." to ".$right_msg,
|
||||||
"addtime" => time(),
|
"addtime" => time(),
|
||||||
);
|
);
|
||||||
$curr_update = array(
|
$curr_update = array(
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
Reference in New Issue
Block a user