Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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,35 @@ 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']); // 止盈价
|
||||||
|
$zs_price = floatval($contract['zs_price']); // 止损价
|
||||||
|
|
||||||
|
// 根据止盈止损自动确定平仓价格
|
||||||
|
$pc_price = $market_price; // 默认以市场价平仓
|
||||||
|
if ($contract['type'] == 'more') {
|
||||||
|
// 做多: 止盈价 > 0 且 当前价 >= 止盈价 → 以止盈价平仓
|
||||||
|
if ($zy_price > 0 && $market_price >= $zy_price) {
|
||||||
|
$pc_price = $zy_price;
|
||||||
|
}
|
||||||
|
// 做多: 止损价 > 0 且 当前价 <= 止损价 → 以止损价平仓
|
||||||
|
elseif ($zs_price > 0 && $market_price <= $zs_price) {
|
||||||
|
$pc_price = $zs_price;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 做空: 止盈价 > 0 且 当前价 <= 止盈价 → 以止盈价平仓
|
||||||
|
if ($zy_price > 0 && $market_price <= $zy_price) {
|
||||||
|
$pc_price = $zy_price;
|
||||||
|
}
|
||||||
|
// 做空: 止损价 > 0 且 当前价 >= 止损价 → 以止损价平仓
|
||||||
|
elseif ($zs_price > 0 && $market_price >= $zs_price) {
|
||||||
|
$pc_price = $zs_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 {
|
||||||
@@ -135,7 +164,7 @@ class AppContract extends Backend
|
|||||||
->where('id', $currency['id'])
|
->where('id', $currency['id'])
|
||||||
->update(['num' => $lostnum, 'updatetime' => time()]);
|
->update(['num' => $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()
|
||||||
|
{
|
||||||
|
$a = mt_rand(1, 20);
|
||||||
|
$b = mt_rand(1, 20);
|
||||||
|
$operators = ['+', '-'];
|
||||||
|
$op = $operators[array_rand($operators)];
|
||||||
|
if ($op == '-' && $a < $b) {
|
||||||
|
// 确保减法结果非负
|
||||||
|
$tmp = $a; $a = $b; $b = $tmp;
|
||||||
|
}
|
||||||
|
$answer = ($op == '+') ? ($a + $b) : ($a - $b);
|
||||||
|
$text = "{$a} {$op} {$b} = ?";
|
||||||
|
|
||||||
|
// 生成唯一key标识本次验证码
|
||||||
|
$captcha_key = md5(uniqid(mt_rand(), true));
|
||||||
|
|
||||||
|
// 将答案存入缓存(使用ThinkPHP缓存,5分钟过期)
|
||||||
|
cache('captcha_' . $captcha_key, strval($answer), 300);
|
||||||
|
|
||||||
|
// 生成验证码图片
|
||||||
|
$width = 200;
|
||||||
|
$height = 60;
|
||||||
|
$img = imagecreatetruecolor($width, $height);
|
||||||
|
|
||||||
|
// 背景色
|
||||||
|
$bgColor = imagecolorallocate($img, 240, 244, 250);
|
||||||
|
imagefilledrectangle($img, 0, 0, $width, $height, $bgColor);
|
||||||
|
|
||||||
|
// 干扰线
|
||||||
|
for ($i = 0; $i < 5; $i++) {
|
||||||
|
$lineColor = imagecolorallocate($img, mt_rand(100, 200), mt_rand(100, 200), mt_rand(100, 200));
|
||||||
|
imageline($img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $lineColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 干扰点
|
||||||
|
for ($i = 0; $i < 50; $i++) {
|
||||||
|
$dotColor = imagecolorallocate($img, mt_rand(100, 255), mt_rand(100, 255), mt_rand(100, 255));
|
||||||
|
imagesetpixel($img, mt_rand(0, $width), mt_rand(0, $height), $dotColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文字颜色
|
||||||
|
$textColor = imagecolorallocate($img, mt_rand(10, 80), mt_rand(10, 80), mt_rand(10, 80));
|
||||||
|
|
||||||
|
// 使用内置字体绘制文字
|
||||||
|
$fontSize = 5; // imagestring内置字体最大5
|
||||||
|
$textWidth = imagefontwidth($fontSize) * strlen($text);
|
||||||
|
$textHeight = imagefontheight($fontSize);
|
||||||
|
$x = ($width - $textWidth) / 2;
|
||||||
|
$y = ($height - $textHeight) / 2;
|
||||||
|
imagestring($img, $fontSize, $x, $y, $text, $textColor);
|
||||||
|
|
||||||
|
// 输出为base64
|
||||||
|
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 = (trim($captcha_code) === trim($answer));
|
||||||
|
// 验证后立即删除,防止重放
|
||||||
|
cache('captcha_' . $captcha_key, null);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成随机key secrit
|
* 生成随机key secrit
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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']);
|
||||||
|
|||||||
@@ -141,21 +141,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', '');
|
||||||
|
|
||||||
|
// 验证图形验证码(替代邮箱/短信OTP)
|
||||||
|
if (!$captcha_key || !$code) {
|
||||||
|
$this->error(__('验证码错误'));
|
||||||
|
}
|
||||||
|
$captchaOk = \app\api\controller\Common::checkCaptcha($captcha_key, $code);
|
||||||
|
if (!$captchaOk) {
|
||||||
|
$this->error(__('验证码错误'));
|
||||||
|
}
|
||||||
|
|
||||||
if($mobile){
|
if($mobile){
|
||||||
$ret = Sms::check($mobile, $code, 'register');
|
|
||||||
if (!$ret && $code!=157258) {
|
|
||||||
$this->error(__('验证码错误'));
|
|
||||||
}
|
|
||||||
$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'] = "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -539,15 +539,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,27 +587,20 @@ 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,
|
||||||
"is_google" => $is_google,
|
"is_google" => $is_google,
|
||||||
"m_prefix" => $this->auth->m_prefix,
|
"m_prefix" => $this->auth->m_prefix,
|
||||||
"mobile" => $this->auth->mobile,
|
"mobile" => $this->auth->mobile,
|
||||||
"email" => $this->auth->email,
|
"email" => $this->auth->email,
|
||||||
"apy_pay" => $this->auth->apy_pay,
|
"apy_pay" => $this->auth->apy_pay,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->success('success',$data);
|
$this->success('success',$data);
|
||||||
@@ -796,10 +812,10 @@ class Wallet extends Api
|
|||||||
$zhuanghu = array(
|
$zhuanghu = array(
|
||||||
['id'=>1,"name"=>__("现货账户")],
|
['id'=>1,"name"=>__("现货账户")],
|
||||||
['id'=>2,"name"=>__("法币账户")],
|
['id'=>2,"name"=>__("法币账户")],
|
||||||
// ['id'=>3,"name"=>__("量化账户")],
|
['id'=>3,"name"=>__("合约账户")],
|
||||||
);
|
);
|
||||||
//获取可划转币种
|
//获取可划转币种 + 汇率用于实时价格转换
|
||||||
$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,8 +863,121 @@ 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 = "现货账户";
|
||||||
|
$right_msg = "合约账户";
|
||||||
|
|
||||||
|
//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."转到".$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."转到".$right_msg."(按".$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 = "合约账户";
|
||||||
|
$right_msg = "现货账户";
|
||||||
|
|
||||||
|
$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."转到".$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']."(按".$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:
|
||||||
@@ -864,7 +993,7 @@ class Wallet extends Api
|
|||||||
$left_type = 1;
|
$left_type = 1;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$left_msg = "量化账户";
|
$left_msg = "合约账户";
|
||||||
$left_field = "num_lh";
|
$left_field = "num_lh";
|
||||||
$left_table = "app_detailed_lh";
|
$left_table = "app_detailed_lh";
|
||||||
$left_type = 1;
|
$left_type = 1;
|
||||||
@@ -887,7 +1016,7 @@ class Wallet extends Api
|
|||||||
$right_type = 1;
|
$right_type = 1;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$right_msg = "量化账户";
|
$right_msg = "合约账户";
|
||||||
$right_field = "num_lh";
|
$right_field = "num_lh";
|
||||||
$right_table = "app_detailed_lh";
|
$right_table = "app_detailed_lh";
|
||||||
$right_type = 1;
|
$right_type = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user