error("非法操作");
}
}
public function update_levermoney($uid)
{
$uinfo = M("user")->where(array('id' => $uid))->field("id,username")->find();
$data['uid'] = $uid;
$data['username'] = $uinfo['username'];
$data['money'] = 0;
M("levermoney")->add($data);
}
//资产划转到合约账户
public function transfer()
{
// if($_POST){
$tbnum = trim(I('get.tbnum'));
$type = trim(I('get.type'));
$uid = userid();
if ($tbnum <= 0) {
$this->ajaxReturn(['code' => 2, 'info' => L('请输入正确的数量')]);
exit();
}
$uinfo = M("user")->where(array('id' => $uid))->field("id,username")->find();
$minfo = M("user_coin")->where(array('userid' => $uid))->find();
$money = $minfo['usdt'];
$lmoneyinfo = M("levermoney")->where(array('uid' => $uid))->find();
$levermoney = $lmoneyinfo['money'];
M()->startTrans();
try {
if ($type == 1) {
if ($money < $tbnum) {
$this->ajaxReturn(['code' => 2, 'info' => L('资金账户余额不足')]);
exit();
}
$dec_re = M("user_coin")->where(array('userid' => $uid))->setDec('usdt', $tbnum);
if ($dec_re) {
if (!M("levermoney")->where(array('uid' => $uid))->find())
M("levermoney")->add(['uid' => $uid, 'username' => $uinfo['username']]);
// var_dump(M("levermoney")->where(array('uid' => $uid))->find());
$inc_re = M("levermoney")->where(array('uid' => $uid))->setInc('money', $tbnum);
// var_dump($inc_re);
// var_dump(M("levermoney")->where(array('uid' => $uid))->find());
if ($inc_re) {
//操作日志
$bill['uid'] = $uid;
$bill['username'] = $uinfo['username'];
$bill['num'] = $tbnum;
$bill['coinname'] = 'usdt';
$bill['afternum'] = $minfo['usdt'] - $tbnum;
$bill['type'] = 18;
$bill['addtime'] = date("Y-m-d H:i:s", time());
$bill['st'] = 2;
$bill['remark'] = L('资金账户转合约账户');
M("bill")->add($bill);
M()->commit();
$this->ajaxReturn(['code' => 1, 'info' => L('划转成功')]);
exit();
} else {
M()->rollback();
$this->ajaxReturn(['code' => 2, 'info' => L('划转失败' . M('levermoney')->getLastSql())]);
exit();
}
}
} elseif ($type == 2) {
if ($levermoney < $tbnum) {
$this->ajaxReturn(['code' => 2, 'info' => L('合约账户余额不足')]);
exit();
}
$order_count = M("leverorder")->where("uid = {$uid} and (status = 1 or status = 2)")->count();
if ($order_count >= 1) {
$this->ajaxReturn(['code' => 2, 'info' => L('有合约定单未结算,不能划转合约账户')]);
exit();
}
$dec_re = M("levermoney")->where(array('uid' => $uid))->setDec('money', $tbnum);
if ($dec_re) {
if (!M("user_coin")->where(array('userid' => $uid))->find())
M("user_coin")->add(['userid' => $uid]);
$inc_re = M("user_coin")->where(array('userid' => $uid))->setInc('usdt', $tbnum);
if ($inc_re) {
//操作日志
$bill['uid'] = $uid;
$bill['username'] = $uinfo['username'];
$bill['num'] = $tbnum;
$bill['coinname'] = 'usdt';
$bill['afternum'] = $minfo['usdt'] + $tbnum;
$bill['type'] = 18;
$bill['addtime'] = date("Y-m-d H:i:s", time());
$bill['st'] = 2;
$bill['remark'] = L('合约账户转资金账户');
M("bill")->add($bill);
M()->commit();
$this->ajaxReturn(['code' => 1, 'info' => L('划转成功')]);
exit();
} else {
M()->rollback();
$this->ajaxReturn(['code' => 2, 'info' => L('划转失败' . M('user_coin')->getLastSql())]);
exit();
}
}
} else {
M()->rollback();
$this->ajaxReturn(['code' => 1, 'info' => L('参数错误')]);
exit();
}
} catch (Exception $e) {
M()->rollback();
$this->ajaxReturn(['code' => 1, 'info' => L($e->getMessage())]);
exit();
}
// }else{
// $id = trim(I('get.id'));
// if($id != 4){
// $this->redirect('User/index');
// }
// $info = M("coin")->where(array('id'=>$id))->find();
// $this->assign('info',$info);
// $coinname = $info['name'];
// $uid = userid();
// $minfo = M("user_coin")->where(array('userid'=>$uid))->find();
// $money = $minfo[$coinname];
// $this->assign('money',$money);
//
// $lmoneyinfo = M("levermoney")->where(array('uid'=>$uid))->find();
// if(empty($lmoneyinfo)){
// $this->update_levermoney($uid);
// $levermoney = 0;
// }else{
// $levermoney = $lmoneyinfo['money'];
// }
// $this->assign('levermoney',$levermoney);
// $this->display();
// }
}
//上传转账号凭证
public function paytax()
{
if ($_POST) {
$uid = userid();
$uinfo = M("user")->where(array('id' => $uid))->field("id,username")->find();
if (empty($uinfo)) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先登陆')]);
}
$cid = trim(I('post.cid'));
$zznum = trim(I('post.zznum'));
$payimg = trim(I('post.payimg'));
$coinname = trim(I('post.coinname'));
if ($zznum <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('请输入正确充值数量')]);
}
if ($payimg == "") {
$this->ajaxReturn(['code' => 0, 'info' => L('请上传转账凭证')]);
}
if ($coinname == "") {
$this->ajaxReturn(['code' => 0, 'info' => L('缺少重要参数')]);
}
if ($cid == "") {
$this->ajaxReturn(['code' => 0, 'info' => L('缺少重要参数')]);
}
$data['uid'] = $uid;
$data['username'] = $uinfo['username'];
$data['taxnum'] = $zznum;
$data['addtime'] = date("Y-m-d H:i:s", time());
$data['updatetime'] = date("Y-m-d H:i:s", time());
$data['status'] = 1;
$data['payimgs'] = $payimg;
$result = M("taxlist")->add($data);
if ($result) {
$this->ajaxReturn(['code' => 1, 'info' => L('凭证提交成功')]);
} else {
$this->ajaxReturn(['code' => 0, 'info' => L('凭证提交失败')]);
}
} else {
$this->ajaxReturn(['code' => 0, 'info' => L('参数错误')]);
}
}
//缴纳税金页面
public function cztax()
{
$id = 4;
if ($id <= 0) {
$this->redirect('User/czcoin');
}
$info = M("coin")->where(array('id' => $id))->find();
if ($info['czstatus'] != 1) {
$this->redirect('User/czcoin');
}
$this->assign('info', $info);
$address = $info['czaddress'];
$url = $address;
$drpath = './Public/Static/coinimgs/';
$imgma = $address . '.png';
$urel = './Public/Static/coinimgs/' . $imgma;
Vendor('phpqrcode.phpqrcode');
$object = new \QRcode();
$size = 3;
$errorLevel = 16;
$object->png($url, $drpath . '/' . $imgma, $errorLevel, $size);
$object->scerweima1($url, $urel, $url);
$this->assign("address", $address);
$config = M("config")->where(array('id' => 1))->field("taxnum")->find();
$taxnum = $config['taxnum'];
$this->assign('taxnum', $taxnum);
$tinfo = M("taxtxt")->where(array('id' => 2))->find();
$this->assign('tinfo', $tinfo);
$this->display();
}
//在线客服
public function online()
{
$uid = userid();
if ($uid <= 0) {
$this->redirect('Login/index');
}
$this->display();
}
public function getlineinfo()
{
$uid = userid();
$list = M("online")->where(array('uid' => $uid))->order('id asc')->field("type,content,addtime")->select();
foreach ($list as $k => $v) {
$list[$k]['time'] = date("H:i", strtotime($v['addtime']));
}
$this->ajaxReturn(['code' => 1, 'data' => $list]);
exit();
}
//提交聊天内容
public function uptxt($txt = null)
{
if (checkstr($txt)) {
$this->ajaxReturn(['code' => 0, 'info' => L('您输入的信息有误')]);
}
$uid = userid();
$uinfo = M("user")->where(array('id' => $uid))->field("id,username")->find();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 3, 'info' => L('请先登陆')]);
}
if ($txt == '') {
$this->ajaxReturn(['code' => 0, 'info' => L('请输入信息内容')]);
}
$data['uid'] = $uid;
$data['username'] = $uinfo['username'];
$data['type'] = 2;
$data['content'] = $txt;
$data['addtime'] = date("Y-m-d H:i:s", time());
$result = M("online")->add($data);
if ($result) {
$this->ajaxReturn(['code' => 1]);
} else {
$this->ajaxReturn(['code' => 0, 'info' => L('信息发送失败')]);
}
}
//实名认证页面
public function authrz()
{
$uid = userid();
if ($uid <= 0) {
$this->redirect('Login/index');
}
$userinfo = M("user")->where(array('id' => $uid))->find();
$this->assign("info", $userinfo);
$this->display();
}
//实名认证处理
public function upauthrzs($name, $zhengjian)
{
// if (checkstr($phone) || checkstr($cardzm) || checkstr($cardfm)) {
// $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
// }
$uid = userid();
$userinfo = M("user")->where(array('id' => $uid))->find();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先登陆')]);
}
// $uinfo = M("user")->where(array('phone'=>$phone))->find();
//if(!empty($uinfo)){
//$this->ajaxReturn(['code'=>0,'info'=>L('手机号已绑定')]);
//}
//if($userinfo['rzstatus'] == 1){
//$this->ajaxReturn(['code'=>0,'info'=>L('不能重复认证')]);
//}
//$data['phone'] = $phone;
$data['name'] = $name;
$data['zhengjian'] = $zhengjian;
$data['rzstatus'] = 1;
$data['rztime'] = time();
$re = M("user")->where(array('id' => $uid))->save($data);
if ($re) {
$notice['uid'] = $uid;
$notice['account'] = $userinfo['username'];
$notice['title'] = L('认证资料提交成功,耐心等待管理员审核');
$notice['content'] = L('实名资料提成功,耐心等待管理员审核');
$notice['addtime'] = date("Y-m-d H:i:s", time());
$notice['status'] = 1;
M("notice")->add($notice);
$this->ajaxReturn(['code' => 1, 'info' => L('认证资料提交成功')]);
} else {
$this->ajaxReturn(['code' => 0, 'info' => L('认证资料提交失败')]);
}
}
//实名认证处理
public function upauthrz($cardzm, $cardfm, $nickname, $card)
{
// if (checkstr($phone) || checkstr($cardzm) || checkstr($cardfm)) {
// $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
// }
$uid = userid();
$userinfo = M("user")->where(array('id' => $uid))->find();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先登陆')]);
}
if ($userinfo['rzstatus'] == 1) $this->ajaxReturn(['code' => 0, 'info' => L('已提交實名認證,請耐心等待')]);
if ($userinfo['rzstatus'] == 2) $this->ajaxReturn(['code' => 0, 'info' => L('已認證成功')]);
// $uinfo = M("user")->where(array('phone'=>$phone))->find();
//if(!empty($uinfo)){
//$this->ajaxReturn(['code'=>0,'info'=>L('手机号已绑定')]);
//}
//if($userinfo['rzstatus'] == 1){
//$this->ajaxReturn(['code'=>0,'info'=>L('不能重复认证')]);
//}
if ($cardzm == "") {
$this->ajaxReturn(['code' => 0, 'info' => L('请上传上传身份证正面')]);
}
if ($cardfm == "") {
$this->ajaxReturn(['code' => 0, 'info' => L('请上传上传身份证背面')]);
}
if ($nickname == '') $this->ajaxReturn(['code' => 0, 'info' => L('輸入姓名')]);
if ($card == '') $this->ajaxReturn(['code' => 0, 'info' => L('身份證')]);
$data['cardzm'] = $cardzm;
$data['cardfm'] = $cardfm;
$data['name'] = $nickname;
$data['zhengjian'] = $card;
$data['rzstatus'] = 1;
$data['rztime'] = time();
$re = M("user")->where(array('id' => $uid))->save($data);
if ($re) {
$notice['uid'] = $uid;
$notice['account'] = $userinfo['username'];
$notice['title'] = L('认证资料提交成功');
$notice['content'] = L('实名资料提成功,耐心等待管理员审核');
$notice['addtime'] = date("Y-m-d H:i:s", time());
$notice['status'] = 1;
M("notice")->add($notice);
$this->ajaxReturn(['code' => 1, 'info' => L('认证资料提交成功')]);
} else {
$this->ajaxReturn(['code' => 0, 'info' => L('认证资料提交失败')]);
}
}
//获取折合资产
public function getallzhehe()
{
$uid = userid();
// $minfo = M("user_coin")->where(array('userid'=>$uid))->find();
// $usdt = $minfo['usdt'] + $minfo['usdtd'];
// $money = M('levermoney')->where(['uid' => $uid])->find();
$allzhehe = session('user_price');
$this->ajaxReturn(['code' => 1, 'allzhehe' => $allzhehe]);
}
//获取单个币种资产(ttc)
public function getmoneyttc()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$ttcusdt = 0.01; //需要获取实时的行情
$re['num'] = $wallinfo['ttc'];
$re['numd'] = $wallinfo['ttcd'];
$re['zhe'] = $wallinfo['ttc'] * 0.01 + $wallinfo['ttcd'] * 0.01;
$re['code'] = 1;
session("ttczh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(atm)
public function getmoneyatm()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$atmusdt = 0.01; //需要获取实时的行情
$re['num'] = $wallinfo['atm'];
$re['numd'] = $wallinfo['atmd'];
$re['zhe'] = $wallinfo['atm'] * 0.01 + $wallinfo['atmd'] * 0.01;
$re['code'] = 1;
session("atmzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(usdz)
public function getmoneyusdz()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$where['name'] = "ukb_usdt";
$marketinfo = M("market")->where($where)->field("new_price")->find();
$usdzusdt = $marketinfo['new_price'];
$re['num'] = $wallinfo['ukb'];
$re['numd'] = $wallinfo['ukbd'];
$re['zhe'] = $wallinfo['ukb'] * $usdzusdt + $wallinfo['ukbd'] * $usdzusdt;
$re['code'] = 1;
session("usdzzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(usdz)
public function getmoneylever()
{
$uid = userid();
$wallinfo = M("levermoney")->where(array('uid' => $uid))->find();
$sy = 0;
$list = M('leverorder')->where(['uid' => $uid])->where(['status' => 2])->select();
foreach ($list as $item) {
if ($item['coinname'] == 'ukbusdt') {
$o_symbol = $item['symbol'];
$symbol_arr = explode('/', $o_symbol);
$symbol = strtolower($symbol_arr[0]) . "_" . strtolower($symbol_arr[1]);
$mlist = M("market")->where(array('name' => $symbol))->field("new_price,min_price")->find();
$close = $mlist['new_price'];
} else {
$url = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $item['coinname'];
$result = $this->getprice($url);
$pdata = $result['data'][0];
$close = $pdata['close'];//现价
}
$direction = $item['direction'];
if ($direction == 1) { //做多
$profit = sprintf("%.2f", ($close - $item['price']) * $item['num']);
} elseif ($direction == 2) { //做空
$profit = sprintf("%.2f", ($close - $item['price']) * $item['num']);
}
if ($profit >= 0) {
$sy += $profit;
} else {
$sy -= $profit;
}
}
$where['name'] = "ukb_usdt";
$marketinfo = M("market")->where($where)->field("new_price")->find();
$usdzusdt = $marketinfo['new_price'];
$money = M('leverorder')->where(['uid' => $uid])->where('status = 1 or status = 2')->sum('bond');
$re['num'] = $wallinfo['money'] + $sy;
$re['numd'] = $money;
$re['zhe'] = 0;
$re['code'] = 1;
session("lever", $re['num']);
$this->ajaxReturn($re);
}
//获取行情数据
public function getprice($api)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$result = json_decode(curl_exec($ch), true);
return $result;
}
//获取单个币种资产(ogo)
public function getmoneyogo()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=ogousdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['ogo'];
$re['numd'] = $wallinfo['ogod'];
$re['zhe'] = $wallinfo['ogo'] * $usdt_price + $wallinfo['ogod'] * $usdt_price;
$re['code'] = 1;
session("ogozh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(ht)
public function getmoneyht()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=htusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['ht'];
$re['numd'] = $wallinfo['htd'];
$re['zhe'] = $wallinfo['ht'] * $usdt_price + $wallinfo['htd'] * $usdt_price;
$re['code'] = 1;
session("htzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(itc)
public function getmoneyitc()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=itcusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['itc'];
$re['numd'] = $wallinfo['itcd'];
$re['zhe'] = $wallinfo['itc'] * $usdt_price + $wallinfo['itcd'] * $usdt_price;
$re['code'] = 1;
session("itczh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(jst)
public function getmoneyjst()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=jstusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['jst'];
$re['numd'] = $wallinfo['jstd'];
$re['zhe'] = $wallinfo['jst'] * $usdt_price + $wallinfo['jstd'] * $usdt_price;
$re['code'] = 1;
session("jstzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(flow)
public function getmoneyflow()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=flowusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['flow'];
$re['numd'] = $wallinfo['flowd'];
$re['zhe'] = $wallinfo['flow'] * $usdt_price + $wallinfo['flowd'] * $usdt_price;
$re['code'] = 1;
session("flowzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(shib)
public function getmoneyshib()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=shibusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['shib'];
$re['numd'] = $wallinfo['shibd'];
$re['zhe'] = $wallinfo['shib'] * $usdt_price + $wallinfo['shibd'] * $usdt_price;
$re['code'] = 1;
session("shibzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(fil)
public function getmoneyfil()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=filusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['fil'];
$re['numd'] = $wallinfo['fild'];
$re['zhe'] = $wallinfo['fil'] * $usdt_price + $wallinfo['fild'] * $usdt_price;
$re['code'] = 1;
session("filzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(iotx)
public function getmoneyiotx()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=iotxusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['iotx'];
$re['numd'] = $wallinfo['iotxd'];
$re['zhe'] = $wallinfo['iotx'] * $usdt_price + $wallinfo['iotxd'] * $usdt_price;
$re['code'] = 1;
session("iotxzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(xrp)
public function getmoneyxrp()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=xrpusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['xrp'];
$re['numd'] = $wallinfo['xrpd'];
$re['zhe'] = $wallinfo['xrp'] * $usdt_price + $wallinfo['xrpd'] * $usdt_price;
$re['code'] = 1;
session("xrpzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(trx)
public function getmoneytrx()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=trxusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['trx'];
$re['numd'] = $wallinfo['trxd'];
$re['zhe'] = $wallinfo['trx'] * $usdt_price + $wallinfo['trxd'] * $usdt_price;
$re['code'] = 1;
session("trxzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(ltc)
public function getmoneyltc()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=ltcusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['ltc'];
$re['numd'] = $wallinfo['ltcd'];
$re['zhe'] = $wallinfo['ltc'] * $usdt_price + $wallinfo['ltcd'] * $usdt_price;
$re['code'] = 1;
session("ltczh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(bch)
public function getmoneybch()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=bchusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['bch'];
$re['numd'] = $wallinfo['bchd'];
$re['zhe'] = $wallinfo['bch'] * $usdt_price + $wallinfo['bchd'] * $usdt_price;
$re['code'] = 1;
session("bchzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(doge)
public function getmoneydoge()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=dogeusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['doge'];
$re['numd'] = $wallinfo['doged'];
$re['zhe'] = $wallinfo['doge'] * $usdt_price + $wallinfo['doged'] * $usdt_price;
$re['code'] = 1;
session("dogezh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(eos)
public function getmoneyeos()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=eosusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['eos'];
$re['numd'] = $wallinfo['eosd'];
$re['zhe'] = $wallinfo['eos'] * $usdt_price + $wallinfo['eosd'] * $usdt_price;
$re['code'] = 1;
session("eoszh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(eth)
public function getmoneyeth()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=ethusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['eth'];
$re['numd'] = $wallinfo['ethd'];
$re['zhe'] = $wallinfo['eth'] * $usdt_price + $wallinfo['ethd'] * $usdt_price;
$re['code'] = 1;
session("ethzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(btc)
public function getmoneybtc()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=btcusdt";
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re['num'] = $wallinfo['btc'];
$re['numd'] = $wallinfo['btcd'];
$re['zhe'] = $wallinfo['btc'] * $usdt_price + $wallinfo['btcd'] * $usdt_price;
$re['code'] = 1;
session("btczh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取单个币种资产(usdt)
public function getmoneyusdt()
{
$uid = userid();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$re['num'] = $wallinfo['usdt'];
$re['numd'] = $wallinfo['usdtd'];
$re['zhe'] = $wallinfo['usdt'] + $wallinfo['usdtd'];
$re['code'] = 1;
session("usdtzh", $re['zhe']);
$this->ajaxReturn($re);
}
//获取资产列表
public function getmoneyinfo()
{
$uid = userid();
$coinlist = M("coin")->where(array('status' => 1))->field("name,id")->select();
$wallinfo = M("user_coin")->where(array('userid' => $uid))->find();
$allzhehe = 0;
if (!empty($coinlist)) {
foreach ($coinlist as $k => $v) {
$coinname = strtoupper($v['name']);
$symbol = $v['name'] . "usdt";
$coinnames = $v['name'];
$coinnamed = $v['name'] . "d";
//获取币的行情
//获取币的余额
if ($coinname != "USDT") {
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol;
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$usdt_price = $price_arr['close'];
$re[$k]['cid'] = $v['id'];
$re[$k]['cname'] = $coinname;
$re[$k]['num'] = $wallinfo[$coinnames];
$re[$k]['numd'] = $wallinfo[$coinnamed];
$re[$k]['zhe'] = $wallinfo[$coinnamed] * $usdt_price + $wallinfo[$coinnames] * $usdt_price;
} else {
$re[$k]['cid'] = $v['id'];
$re[$k]['cname'] = $coinname;
$re[$k]['num'] = $wallinfo['usdt'];
$re[$k]['numd'] = $wallinfo['usdtd'];
$re[$k]['zhe'] = $wallinfo['usdt'] + $wallinfo['usdtd'];
}
$allzhehe += $re[$k]['zhe'];
}
session("allzhehe", $allzhehe);
$this->ajaxReturn(['code' => 1, 'data' => $re]);
}
}
//获取单币种单价
public function getnewprice()
{
$coinname = trim(I('post.coinname'));
$num = 0;
if ($coinname == "UKB") {
$symbol = "ukb_usdt";
$mlist = M("market")->where(array('name' => $symbol))->field("new_price,min_price,max_price,faxingjia,volume")->find();
$open = $mlist['min_price'];//开盘价
$close = $mlist['new_price'] + $num;//现价
$lowhig = $close - $open; //涨跌
$change = round(($lowhig / $open * 100), 2); //涨跌幅
if ($change >= 0) {
$changestr = "+" . $change . "%";
} else {
$changestr = "" . $change . "%";
}
if ($close >= $open) {
$close = "" . $close . "";
} else {
$close = "" . $close . "";
}
} else {
$lowcoin = strtolower($coinname);
$symbol = $lowcoin . 'usdt';
$coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol;
$result = $this->get_maket_api($coinapi);
$price_arr = $result['data'][0];
$open = $price_arr['open'];//开盘价
$close = $price_arr['close'];//现价
$lowhig = $close - $open; //涨跌
$change = round(($lowhig / $open * 100), 2); //涨跌幅
if ($change >= 0) {
$changestr = "+" . $change . "%";
} else {
$changestr = "" . $change . "%";
}
if ($close >= $open) {
$close = "" . $close . "";
} else {
$close = "" . $close . "";
}
}
$data['code'] = 1;
$data['newprice'] = $close;
$data['changestr'] = $changestr;
$this->ajaxReturn($data);
}
//币种详情
public function coininfo()
{
$id = trim(I('get.cid'));
$cinfo = M("coin")->where(array('id' => $id))->find();
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 3, 'data' => '', 'info' => L('未登录')]);
}
$user = M('user_coin')->where(['userid' => $uid])->find();
if ($id == 30) {
$money = M('levermoney')->where(['uid' => $uid])->find();
$numd = M('leverorder')->where(['uid' => $uid])->where('status = 1 or status = 2')->sum('bond');
$order = M('leverorder')->where(['uid' => $uid])->where(['status' => 2])->select();
$orderPrice = 0;
foreach ($order as $vo) {
$oy_list = do_request(oy_url($vo['coinname'], 'api/v5/market/index-tickers?instId='), []);
$oy_list = $oy_list->data[0];
$close = $oy_list->idxPx;//现价
if ($vo['direction'] == 1) { //做多
$profit = sprintf("%.2f", ($close - $vo['price']) * $vo['num']);
} elseif ($vo['direction'] == 2) { //做空
$profit = sprintf("%.2f", ($vo['price'] - $close) * $vo['num']);
}
$orderPrice += $profit;
}
$data = [
'num' => $money['money'] + $orderPrice,
'numd' => $numd == false ? 0 : $numd,
'zhe' => $money['money'] + $orderPrice,
'name' => '合約賬戶',
'czstatus' => 2,
'txstatus' => 2,
];
} elseif ($id == 4) {
$data = [
'num' => $user[$cinfo['name']],
'numd' => $user[$cinfo['name'] . 'd'],
'zhe' => $user[$cinfo['name']],
'czstatus' => $cinfo['czstatus'],
'txstatus' => $cinfo['txstatus'],
];
$data['name'] = '資金賬戶';
}elseif ($id == 29) {
$marketinfo = M("market")->where(array('name'=>"gcb_usdt"))->find();
$data = [
'num' => $user[$cinfo['name']],
'numd' => $user[$cinfo['name'] . 'd'],
'zhe' => round($user[$cinfo['name']] * $marketinfo['new_price'], 6),
'czstatus' => $cinfo['czstatus'],
'txstatus' => $cinfo['txstatus'],
];
$data['name'] = $cinfo['title'];
} else {
$oy_list = do_request(oy_url($cinfo['name'], 'api/v5/market/ticker?instId='), []);
$oy_list = $oy_list->data[0];
$close = $oy_list->last;//现价
$data = [
'num' => $user[$cinfo['name']],
'numd' => $user[$cinfo['name'] . 'd'],
'zhe' => round($user[$cinfo['name']] * $close, 2),
'czstatus' => $cinfo['czstatus'],
'txstatus' => $cinfo['txstatus'],
];
$data['name'] = $cinfo['title'];
}
$this->ajaxReturn(['code' => 1, 'data' => $data, 'info' => '']);
}
//提币详情
public function txinfo()
{
$id = trim(I('get.oid'));
$info = M("myzc")->where(array('id' => $id))->find();
$this->ajaxReturn(['code' => 1, 'data' => $info]);
// $this->assign('info',$info);
// $this->display();
}
//提币列表
public function txlist()
{
$uid = userid();
$txlist = M("myzc")->where(array('userid' => $uid))->order('id desc')->select();
$this->ajaxReturn(['code' => 1, 'data' => $txlist]);
// $this->assign("txlist",$txlist);
// $this->display();
}
//提币处理
public function tbhandle()
{
// if($_POST){
$uid = userid();
$uinfo = M("user")->where(array('id' => $uid))->field("id,rzstatus,username,txstate,is_tax,taxstatus")->find();
if (empty($uinfo)) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先登陆')]);
}
if ($uinfo['rzstatus'] != 2) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先完成实名认证')]);
}
if ($uinfo['txstate'] != 1) {
$this->ajaxReturn(['code' => 0, 'info' => L('禁止提币')]);
}
//检查该会员是不是需要缴纳税金,如有需要检查有没有缴纳
if ($uinfo['is_tax'] == 1) {
if ($uinfo['taxstatus'] != 1) {
$this->ajaxReturn(['code' => 2, '請繳納稅金']);
}
}
$id = trim(I('get.id'));
if ($id == 5) {
$id = 4;
}
if ($id <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('参数错误')]);
}
$address = trim(I('get.address'));
if ($address == '' || $address == null) {
$this->ajaxReturn(['code' => 0, 'info' => L('请输入提币地址')]);
}
$num = trim(I('get.num'));
if ($num <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('请输入正确的额度')]);
}
$cinfo = M("coin")->where(array('id' => $id))->find();
if (empty($cinfo)) {
$this->ajaxReturn(['code' => 0, 'info' => L('参数错误')]);
}
if ($num < $cinfo['txminnum']) {
$this->ajaxReturn(['code' => 0, 'info' => L('不能低于最小提币值')]);
}
if ($num > $cinfo['txmaxnum']) {
$this->ajaxReturn(['code' => 0, 'info' => L('不能高于最大提币值')]);
}
$coinname = $cinfo['name'];
$minfo = M("user_coin")->where(array('userid' => $uid))->find();
$sxftype = $cinfo['sxftype'];
if ($sxftype == 1) {
$sxf = $num * $cinfo['txsxf'] / 100;
} elseif ($sxftype == 2) {
$sxf = $cinfo['txsxf_n'];
}
if ($sxf <= 0 || $sxf == '') {
$sxf = 0;
}
$tnum = $num - $sxf;
if ($minfo[$coinname] < $num) {
$this->ajaxReturn(['code' => 0, 'info' => L('账户余额不足')]);
}
$dec_re = M("user_coin")->where(array('userid' => $uid))->setDec($coinname, $num);
$data['userid'] = $uid;
$data['username'] = $uinfo['username'];
$data['coinname'] = $cinfo['name'];
$data['num'] = $num;
$data['fee'] = $sxf;
$data['mum'] = $tnum;
$data['address'] = $address;
$data['sort'] = 1;
$data['addtime'] = date("Y-m-d H:i:s", time());
$data['endtime'] = date("Y-m-d H:i:s", time());
$data['status'] = 1;
$result = M("myzc")->add($data);
//操作日志
$bill['uid'] = $uid;
$bill['username'] = $uinfo['username'];
$bill['num'] = $num;
$bill['coinname'] = $cinfo['name'];
$bill['afternum'] = $minfo[$coinname] - $num;
$bill['type'] = 2;
$bill['addtime'] = date("Y-m-d H:i:s", time());
$bill['st'] = 2;
$bill['remark'] = "提币申请";
$billre = M("bill")->add($bill);
if ($result && $dec_re && $billre) {
$this->ajaxReturn(['code' => 1, 'info' => L('提交成功')]);
} else {
$this->ajaxReturn(['code' => 0, 'info' => L('提交失败')]);
}
// }else{
//
// }
}
//判断是否绑定提币地址
public function getaddress()
{
if ($_POST) {
$id = trim(I('post.id'));
$coininfo = M("coin")->where(array('id' => $id))->field("id,name")->find();
if (empty($coininfo)) {
$this->ajaxReturn(['code' => 0]);
}
$coinname = $coininfo['name'];
$uid = userid();
$adrinfo = M("user_qianbao")->where(array('userid' => $uid, 'name' => $coinname))->order('id desc')->limit(1)->find();
if (!empty($adrinfo)) {
$this->ajaxReturn(['code' => 1]);
} else {
$this->ajaxReturn(['code' => 0]);
}
} else {
$this->ajaxReturn(['code' => 0]);
}
}
//添加地址处理
public function upplusaddress()
{
// if($_POST){
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 0, 'msg' => L('请先登陆')]);
}
$uinfo = M("user")->where(array('id' => $uid))->field("id,username")->find();
$address = trim(I('get.address'));
$remark = trim(I('get.remark'));
$oid = trim(I('get.oid'));
if ($oid <= 0) {
$this->ajaxReturn(['code' => 0, 'msg' => L('缺少重要参数')]);
}
if ($address == '') {
$this->ajaxReturn(['code' => 0, 'msg' => L('请输入提币地址')]);
}
if ($remark == '') {
$this->ajaxReturn(['code' => 0, 'msg' => L('请输入备注')]);
}
$cinfo = M("coin")->where(array('id' => $oid))->find();
$data['userid'] = $uid;
$data['coinname'] = $uinfo['username'];
$data['name'] = $cinfo['name'];
$data['remark'] = $remark;
$data['addr'] = $address;
$data['sort'] = 1;
$data['addtime'] = date("Y-m-d H:i:s", time());
$data['status'] = 1;
$result = M('user_qianbao')->add($data);
if ($result) {
$this->ajaxReturn(['code' => 1, 'msg' => L('添加成功')]);
} else {
$this->ajaxReturn(['code' => 0, 'msg' => L('添加失败')]);
}
}
//添加地址
public function plusaddress()
{
$id = trim(I('get.id'));
$cinfo = M("coin")->where(array('id' => $id))->find();
$this->assign('info', $cinfo);
$this->display();
}
//添加的提币的地址
public function txaddlist()
{
$id = trim(I('get.id'));
$cinfo = M("coin")->where(array('id' => $id))->find();
$coinname = $cinfo['name'];
$uid = userid();
$qblist = M("user_qianbao")->where(array('userid' => $uid, 'name' => $coinname))->order("id desc")->select();
$this->assign('qblist', $qblist);
$this->assign('id', $id);
$this->assign('coinname', $coinname);
$this->display();
}
//提币页面
public function txpage()
{
$id = trim(I('get.id'));
if ($id <= 0) {
$this->redirect('User/txcoin');
}
$info = M("coin")->where(array('id' => $id))->find();
if ($info['id'] == 5) {
$coinname = 'usdt';
} else {
$coinname = $info['name'];
}
$uid = userid();
$minfo = M("user_coin")->where(array('userid' => $uid))->find();
$money = $minfo[$coinname];
$adrinfo = M("user_qianbao")->where(array('userid' => $uid, 'name' => $coinname))->order('id desc')->limit(1)->find();
$data = [
'info' => $info,
'adrinfo' => $adrinfo,
'money' => $money,
];
$this->ajaxReturn(['code' => 1, 'data' => $data, 'info' => '']);
}
//提现币列表
public function txcoin()
{
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先登陆')]);
}
$clist = M("coin")->where(array('txstatus' => 1))->field("id,name,title")->select();
$minfo = M("user_coin")->where(array('userid' => $uid))->find();
if (!empty($clist)) {
foreach ($clist as $k => $v) {
if ($v['id'] == 5) {
$coinname = 'usdt';
} else {
$coinname = $v['name'];
}
$coin_num = $minfo[$coinname];
$data[$k]['cname'] = strtoupper($coinname);
$data[$k]['title'] = $v['title'];
$data[$k]['id'] = $v['id'];
$data[$k]['cnum'] = $coin_num;
}
}
$this->ajaxReturn(['code' => 1, 'data' => $data, 'info' => '']);
}
//提币地址管理
public function addresslist()
{
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先登陆')]);
}
$adrlist = M("user_qianbao")->where(array('uid' => $uid))->select();
$this->ajaxReturn(['code' => 1, 'data' => $adrlist, 'info' => '']);
}
//删除提币地址
public function deladdress($aid)
{
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先登陆')]);
}
$ainfo = M("user_qianbao")->where(array('id' => $aid))->find();
if (empty($ainfo)) {
$this->ajaxReturn(['code' => 0, 'info' => L('提币地址不存在')]);
}
$delre = M("user_qianbao")->where(array('id' => $aid))->delete();
if ($delre) {
$this->ajaxReturn(['code' => 1, 'info' => L('删除成功')]);
} else {
$this->ajaxReturn(['code' => 0, 'info' => L('删除失败')]);
}
}
//充值列表
public function czlist()
{
$uid = userid();
$mlist = M("recharge")->where(array('uid' => $uid))->order("id desc")->select();
foreach ($mlist as &$item) {
$item['payimg'] = 'https://' . $_SERVER['HTTP_HOST'] . '/Upload/public/' . $item['payimg'];
}
$this->ajaxReturn(['code' => 1, 'data' => $mlist, 'info' => '']);
}
public function czinfo()
{
$id = trim(I('get.oid'));
$uid = userid();
$info = M("recharge")->where(array('uid' => $uid, 'id' => $id))->order("id desc")->find();
$info['payimg'] = 'https://' . $_SERVER['HTTP_HOST'] . '/Upload/public/' . $info['payimg'];
$this->ajaxReturn(['code' => 1, 'data' => $info, 'info' => '']);
// if(empty($info)){
// $this->redirect('User/czlist');
// }
// $this->assign("info",$info);
// $this->display();
}
//上传转账号凭证
public function paycoin()
{
// if($_POST){
$uid = userid();
$uinfo = M("user")->where(array('id' => $uid))->field("id,username")->find();
if (empty($uinfo)) {
$this->ajaxReturn(['code' => 0, 'info' => L('请先登陆')]);
}
$cid = trim(I('get.cid'));
$zznum = trim(I('get.zznum'));
$payimg = trim(I('get.payimg'));
$coinname = trim(I('get.coinname'));
if ($zznum <= 0) {
$this->ajaxReturn(['code' => 0, 'info' => L('请输入正确充值数量')]);
}
if ($payimg == "") {
$this->ajaxReturn(['code' => 0, 'info' => L('请上传转账凭证')]);
}
if ($coinname == "") {
$this->ajaxReturn(['code' => 0, 'info' => L('缺少重要参数')]);
}
if ($cid == "") {
$this->ajaxReturn(['code' => 0, 'info' => L('缺少重要参数')]);
}
$cinfo = M("coin")->where(array('id' => $cid))->find();
$minnum = $cinfo['czminnum'];
if ($zznum < $minnum) {
$this->ajaxReturn(['code' => 0, 'info' => L('低于最低额度')]);
}
$data['uid'] = $uid;
$data['username'] = $uinfo['username'];
$data['coin'] = strtoupper($coinname);
$data['num'] = $zznum;
$data['addtime'] = date("Y-m-d H:i:s", time());
$data['updatetime'] = date("Y-m-d H:i:s", time());
$data['status'] = 1;
$data['payimg'] = $payimg;
$data['msg'] = '';
$result = M("recharge")->add($data);
if ($result) {
$this->ajaxReturn(['code' => 1, 'info' => L('凭证提交成功')]);
} else {
$this->ajaxReturn(['code' => 0, 'info' => L('凭证提交失败')]);
}
// }else{
// $this->ajaxReturn(['code'=>0,'info'=> L('参数错误')]);
// }
}
/* 币种列表页 */
public function qianbao_coin_list()
{
$this->display();
}
public function qianbaoadd()
{
$this->display();
}
//我的资产中心
public function index()
{
$uid = userid();
if ($uid <= 0) {
$this->redirect('Login/index');
}
$clist = M("coin")->where(array('status' => 1))->order('id asc')->field("id,name")->select();
$clist[] = [
'id' => 30,
'name' => 'Futures-USDT'
];
foreach ($clist as &$item) {
if ($item['id'] == 4) {
$item['name'] = 'Wallets-USDT';
}
}
$this->assign("list", $clist);
$this->display();
}
public function getsymbol()
{
$symbol = trim(I('post.symbol'));
$symbol = strtolower($symbol);
$map['name'] = array('like', "%$symbol%");
$info = M("coin")->where($map)->field("name,title,id")->find();
$uname = strtoupper($info['name']);
$info['uname'] = $uname;
//print_r($info);die;
$this->ajaxReturn(['code' => 1, 'info' => $info]);
}
//获取单个提币币种列表
public function getcoinnum()
{
$symbol = trim(I('post.symbol'));
$symbol = strtolower($symbol);
$map['name'] = array('like', "%$symbol%");
$info = M("coin")->where($map)->field("name,title,id")->find();
$coinname = $info['name'];
$uid = userid();
$minfo = M("user_coin")->where(array('userid' => $uid))->find();
if (!empty($minfo)) {
$cnum = $minfo[$coinname];
}
$data['cname'] = strtoupper($info['name']);
$data['title'] = $info['title'];
$data['cnum'] = $cnum;
$data['id'] = $info['id'];
$this->ajaxReturn(['code' => 1, 'info' => $data]);
}
//币种充值页面
public function czpage()
{
$id = trim(I('get.id'));
if ($id <= 0) {
$this->ajaxReturn(['code' => 2, 'data' => '', 'info' => '选择充值币种']);
}
$infos = M("coin")->where(array('id' => $id))->find();
if ($infos['czstatus'] != 1) {
$this->ajaxReturn(['code' => 2, 'data' => '', 'info' => '不支持充值']);
}
$this->ajaxReturn(['code' => 1, 'data' => $infos, 'info' => '']);
}
//充值币明细
public function czcoin()
{
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 3, 'data' => '', 'info' => L('未登录')]);
}
$name = I('get.name');
$where = [];
if ($name) $where[] = ['title' => strtoupper($name)];
$list = M("coin")->where(array('status' => 1))->where($where)->order('sort asc')->field("name,title,id,czstatus")->select();
foreach ($list as $k => $v) {
if ($v['name'] == 'ercus') {
unset($list[$k]);
}
}
$this->ajaxReturn(['code' => 1, 'data' => $list, 'info' => '']);
}
//获取行情数据
public function get_maket_api($api)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$result = json_decode(curl_exec($ch), true);
return $result;
}
public function login()
{
$this->display();
}
public function qianbao()
{
$this->display();
}
public function upqianbao()
{
}
public function delqianbao()
{
}
//会员登陆日志
public function log()
{
if (!userid()) {
redirect("/Login/index.html");
}
$where['status'] = array('egt', 0);
$where['userid'] = userid();
$Model = M('UserLog');
$count = $Model->db(1, 'DB_Read')->where($where)->count();
$Page = new \Think\Page($count, 10);
$show = $Page->show();
$list = $Model->db(1, 'DB_Read')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
$this->assign('list', $list);
$this->assign('page', $show);
$this->display();
}
//上传图片
public function recharge_img()
{
$upload = new \Think\Upload();
$upload->maxSize = 3145728;
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');
$upload->rootPath = './Upload/public/';
$upload->autoSub = false;
$info = $upload->upload();
$host = $_SERVER['HTTP_HOST'];
foreach ($info as $k => $v) {
$path = $v['savepath'] . $v['savename'];
$response = array(
'code' => 0,
'msg' => L('上传成功'),
'data' => array(
'src' => 'https://' . $host . '/Upload/public/' . $path,
'img' => $path
)
);
echo json_encode($response);
exit();
}
}
/**
* 资金列表
* @return void
*/
public function usercoin()
{
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 3, 'data' => '', 'info' => L('未登录')]);
}
$clist[] = [
'id' => 30,
'name' => '合約賬戶'
];
$clist = array_merge($clist, M("coin")->where(array('status' => 1))->order('id asc')->field("id,name")->select());
$user = M('user_coin')->where(['userid' => $uid])->find();
foreach ($clist as &$item) {
if ($item['id'] == 4) {
$item['name'] = '資金賬戶';
}
}
unset($clist[2]);
$price = 0;
foreach ($clist as &$item) {
if ($item['name'] == '合約賬戶') {
$money = M('levermoney')->where(['uid' => $uid])->find();
$numd = M('leverorder')->where(['uid' => $uid])->where('status = 1 or status = 2')->sum('bond');
$order = M('leverorder')->where(['uid' => $uid])->where(['status' => 2])->select();
$orderPrice = 0;
foreach ($order as $vo) {
$oy_list = do_request(oy_url($vo['coinname'], 'api/v5/market/ticker?instId='), []);
$oy_list = $oy_list->data[0];
$close = $oy_list->last;//现价
if ($vo['direction'] == 1) { //做多
$profit = sprintf("%.2f", ($close - $vo['price']) * $vo['num']);
} elseif ($vo['direction'] == 2) { //做空
$profit = sprintf("%.2f", ($vo['price'] - $close) * $vo['num']);
}
$orderPrice += $profit;
}
$item['data'] = [
'num' => $money['money'] + $orderPrice,
'numd' => $numd,
'zhe' => $money['money'] + $orderPrice,
];
$price += ($money['money'] + $orderPrice);
} elseif ($item['name'] == '資金賬戶') {
$item['data'] = [
'num' => $user['usdt'],
'numd' => $user['usdtd'],
'zhe' => $user['usdt'],
];
$price += ($user['usdt'] + $user['usdtd']);
}elseif ($item['name'] == 'gcb') {
$marketinfo = M("market")->where(array('name'=>"gcb_usdt"))->find();
$item['data'] = [
'num' => $user['gcb'],
'numd' => $user['gcbd'],
'zhe' => round($user['gcb'] * $marketinfo['new_price'], 6),
];
$price += ($user['gcb'] * $marketinfo['new_price']);
} else {
$oy_list = do_request(oy_url($item['name'], 'api/v5/market/ticker?instId='), []);
$oy_list = $oy_list->data[0];
$close = $oy_list->last;//现价
$item['data'] = [
'num' => $user[$item['name']],
'numd' => $user[$item['name'] . 'd'],
'zhe' => $user[$item['name']] * $close,
];
// $price += ($user[$item['name']]+$user[$item['name'].'d']);
$price += ($user[$item['name']] * $close);
}
}
session('user_price', $price);
$this->ajaxReturn(['code' => 1, 'data' => $clist, 'info' => '']);
}
public function bill()
{
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 3, 'data' => '', 'info' => L('未登录')]);
}
$name = trim(I('get.name'));
$page = I('get.page');
if (!$page) $page = 1;
$limit = I('get.limit');
if (!$limit) $limit = 10;
if ($name == '合約賬戶') {
$list = M('bill')->where(['uid' => $uid])->where(['coinname' => 'lever'])->order('id DESC')->page($page, $limit)->select();
} elseif ($name == '資金賬戶') {
$list = M('bill')->where(['uid' => $uid])->where(['coinname' => 'usdt'])->order('id DESC')->page($page, $limit)->select();
} else {
$list = M('bill')->where(['uid' => $uid])->where(['coinname' => strtolower($name)])->order('id DESC')->page($page, $limit)->select();
}
$this->ajaxReturn(['code' => 1, 'data' => $list, 'info' => '']);
}
public function userinfo()
{
$uid = userid();
if ($uid <= 0) {
$this->ajaxReturn(['code' => 3, 'data' => '', 'info' => L('未登录')]);
}
$list = M('user')->where(['id' => $uid])->field('id,username,phone,money,rzstatus,level,invit_1,invit_2,invit_3,status,txstate,invit,taxstatus,rzstatus,cardzm,cardfm,name,zhengjian')->find();
$icon = M('user_coin')->where(['userid' => $uid])->find();
$money = M('levermoney')->where(['uid' => $uid])->find();
if (!$money) $money['money'] = 0;
$list['usdt'] = $icon['usdt'];
$list['http'] = 'https://' . $_SERVER['HTTP_HOST'] . '/Upload/public/';
$order = M('leverorder')->where(['uid' => $uid])->where(['status' => 2])->select();
$orderPrice = 0;
foreach ($order as $vo) {
$oy_list = do_request(oy_url($vo['coinname'], 'api/v5/market/ticker?instId='), []);
$oy_list = $oy_list->data[0];
$close = $oy_list->last;//现价
if ($vo['direction'] == 1) { //做多
$profit = sprintf("%.2f", ($close - $vo['price']) * $vo['num']);
} elseif ($vo['direction'] == 2) { //做空
$profit = sprintf("%.2f", ($vo['price'] - $close) * $vo['num']);
}
$orderPrice += $profit;
}
$sy = $money['money'] + $orderPrice;
if ($sy <= 0) {
$sy = 0;
}
$list['money'] = $sy;
$this->ajaxReturn(['code' => 1, 'data' => $list, 'info' => '']);
}
}
?>