error("非法操作!"); } } //永续合约自动结算 public function AutoCloseOrder() { $list = M("leverorder")->where(array('status' => 2))->select(); if (!empty($list)) { $sysinfo = M("leversetting")->where(array('id' => 1))->find(); $lever_fee = $sysinfo['lever_fee'];//费率 $new_close = []; foreach ($list as $key => $vo) { $id = $vo['id']; $uid = $vo['uid']; $uinfo = M("user")->where(array('id' => $uid))->field("id,username")->find(); // $minfo = M("user_coin")->where(array('userid' => $uid))->find(); // $bond_money_info = M("levermoney")->where(array('uid' => $uid))->find(); $lowercoin = $vo['coinname']; $user = M('levermoney')->where(['uid' => $uid])->find(); if (!isset($new_close[$vo['coinname']])) { if ($lowercoin == 'ukbusdt') { $o_symbol = $vo['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 { $oy_list = do_request(oy_url($vo['coinname'], 'api/v5/market/ticker?instId='), []); $oy_list = $oy_list->data[0]; // $url = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$lowercoin; // $result = $this->getprice($url); // $pdata = $result['data'][0]; $close = $oy_list->last;//现价 $new_close[$vo['coinname']] = $close; } } else { $close = $new_close[$vo['coinname']]; } if ($close) { $price = $vo['price']; //开仓价格 $direction = $vo['direction']; //交易方向 $zsprice = $vo['zsprice']; //止损价格 $zyprice = $vo['zyprice']; //止盈价格 if ($zyprice > 0) { if ($direction == 1) { // 买多 if ($close >= $zyprice) { //收益计算 //例:BTC/USDT永续合约开多仓100张,成交价格为10000 USDT,以11000 USDT价格平仓, //则:平仓盈亏 = 收益(平仓) =( 11000 – 10000 )* 100 * 0.001 = 100 USDT。 $profit = sprintf("%.2f", ($close - $price) * $vo['num']); $tprofit = abs($profit); $data['pc_price'] = $close; $data['status'] = 3; $data['yk_status'] = 1; $data['ylmoney'] = $tprofit; $data['endtime'] = date("Y-m-d H:i:s", time()); $result = M("leverorder")->where(array('id' => $id))->save($data); $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $tprofit; $ubill['coinname'] = "lever"; $ubill['afternum'] = $user['money'] + $tprofit; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = L('合约交易止盈平仓盈利收益'); $ubillre = M("bill")->add($ubill); $bond_ubill = [ 'uid' => $uid, 'username' => $uinfo['username'], 'num' => $vo['bond'], 'coinname' => 'usdt', 'afternum' => $user['money'] + $vo['bond'], 'type' => 25, 'addtime' => date("Y-m-d H:i:s", time()), 'st' => 1, 'remark' => '合約交易止盈平倉返還佔用合約' ];// 扣除合约保证金 M("levermoney")->where(array('uid' => $uid))->setInc('money', $vo['bond']); M("levermoney")->where(array('uid' => $uid))->setDec('moneyd', $vo['bond']); M("bill")->add($bond_ubill); if ($result && $ubillre) { M("levermoney")->where(array('uid' => $uid))->setInc('money', $tprofit); echo "=订单ID:" . $id . ",止盈平仓="; } } } elseif ($direction == 2) { //买空 if ($close <= $zyprice) { $profit = sprintf("%.2f", ($price - $close) * $vo['num']); $tprofit = abs($profit); $data['pc_price'] = $close; $data['status'] = 3; $data['yk_status'] = 1; $data['ylmoney'] = $tprofit; $data['endtime'] = date("Y-m-d H:i:s", time()); $result = M("leverorder")->where(array('id' => $id))->save($data); $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $tprofit; $ubill['coinname'] = "lever"; $ubill['afternum'] = $user['money'] + $tprofit; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = L('合约交易止盈平仓盈利收益'); $ubillre = M("bill")->add($ubill); $bond_ubill = [ 'uid' => $uid, 'username' => $uinfo['username'], 'num' => $vo['bond'], 'coinname' => 'usdt', 'afternum' => $user['money'] + $vo['bond'], 'type' => 25, 'addtime' => date("Y-m-d H:i:s", time()), 'st' => 1, 'remark' => '合約交易止盈平倉返還佔用合約' ];// 扣除合约保证金 M("levermoney")->where(array('uid' => $uid))->setInc('money', $vo['bond']); M("levermoney")->where(array('uid' => $uid))->setDec('moneyd', $vo['bond']); M("bill")->add($bond_ubill); if ($result && $ubillre) { M("levermoney")->where(array('uid' => $uid))->setInc('money', $tprofit); echo "=订单ID:" . $id . ",止盈平仓="; } } } } if ($zsprice > 0) { if ($direction == 1) { // 买多 if ($close <= $zsprice) { //收益计算 //例:BTC/USDT永续合约开多仓100张,成交价格为10000 USDT,以11000 USDT价格平仓, //则:平仓盈亏 = 收益(平仓) =( 11000 – 10000 )* 100 * 0.001 = 100 USDT。 $profit = sprintf("%.2f", ($close - $price) * $vo['num']); $tprofit = abs($profit); if ($tprofit < $user['money']) { //亏损小于保证金 $data['pc_price'] = $close; $data['status'] = 3; $data['yk_status'] = 2; $data['ylmoney'] = $tprofit; $data['endtime'] = date("Y-m-d H:i:s", time()); $bond = ($user['money'] + $vo['bond']) - $tprofit; $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $vo['bond']; $ubill['afternum'] = $user['money'] + $vo['bond']; $ubill['coinname'] = "lever"; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = '合約交易止損平倉返回保證金'; $ubillre = M("bill")->add($ubill); $ubill['num'] = $tprofit; $ubill['afternum'] = $bond; $ubill['coinname'] = "lever"; $ubill['st'] = 2; $ubill['remark'] = '合約交易止損平倉虧損'; $ubillre = M("bill")->add($ubill); M("leverorder")->where(array('id' => $id))->save($data); M("levermoney")->where(['uid' => $uid])->setInc('money', $vo['bond']); M("levermoney")->where(['uid' => $uid])->setDec('money', $tprofit); M("levermoney")->where(array('uid' => $uid))->setDec('moneyd', $vo['bond']); echo "=订单ID:" . $id . ",止损平仓="; } else { if ($user['money'] + $vo['bond'] >= $tprofit) { $user_bond = $vo['bond'] - ($tprofit - $user['money']); $data['pc_price'] = $close; $data['status'] = 3; $data['yk_status'] = 2; $data['ylmoney'] = $tprofit; $data['endtime'] = date("Y-m-d H:i:s", time()); $bond = $tprofit - $vo['bond']; $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $user_bond; $ubill['afternum'] = $user_bond; $ubill['coinname'] = "lever"; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = '合約交易止損平倉退回剩餘保證金'; $ubillre = M("bill")->add($ubill); $ubill['num'] = $user['money']; $ubill['afternum'] = 0; $ubill['type'] = 20; $ubill['st'] = 2; $ubill['remark'] = '合約交易手動平倉虧損'; M("leverorder")->where(array('id' => $id))->save($data); M("levermoney")->where(['uid' => $uid])->setInc('money', $user_bond); M("levermoney")->where(array('uid' => $uid))->setDec('money', $user['money']); M("levermoney")->where(array('uid' => $uid))->setDec('moneyd', $vo['bond']); echo "=订单ID:" . $id . ",止损平仓="; } else { $data['pc_price'] = $close; $data['status'] = 3; $data['yk_status'] = 2; $data['ylmoney'] = $tprofit; $data['endtime'] = date("Y-m-d H:i:s", time()); $bond = $tprofit - $vo['bond']; $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $user['money']; $ubill['afternum'] = 0; $ubill['coinname'] = "lever"; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = '合約交易ID' . $vo['id'] . '止損平倉扣除完保證金,並扣除合約帳戶'; $ubillre = M("bill")->add($ubill); M("leverorder")->where(array('id' => $id))->save($data); M("levermoney")->where(['uid' => $uid])->setDec('money', $user['money']); M("levermoney")->where(array('uid' => $uid))->setDec('moneyd', $vo['bond']); echo "=订单ID:" . $id . ",止损平仓="; } } } } elseif ($direction == 2) { //买空 if ($close >= $zsprice) { $profit = sprintf("%.2f", ($price - $close) * $vo['num']); $tprofit = abs($profit); if ($tprofit < $user['money']) { //亏损小于保证金 $data['pc_price'] = $close; $data['status'] = 3; $data['yk_status'] = 2; $data['ylmoney'] = $tprofit; $data['endtime'] = date("Y-m-d H:i:s", time()); $bond = ($user['money'] + $vo['bond']) - $tprofit; $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $vo['bond']; $ubill['afternum'] = $user['money'] + $vo['bond']; $ubill['coinname'] = "lever"; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = '合約交易止損平倉返回保證金'; $ubillre = M("bill")->add($ubill); $ubill['num'] = $tprofit; $ubill['afternum'] = $bond; $ubill['coinname'] = "lever"; $ubill['st'] = 2; $ubill['remark'] = '合約交易止損平倉虧損'; $ubillre = M("bill")->add($ubill); M("leverorder")->where(array('id' => $id))->save($data); M("levermoney")->where(['uid' => $uid])->setInc('money', $vo['bond']); M("levermoney")->where(['uid' => $uid])->setDec('money', $tprofit); M("levermoney")->where(array('uid' => $uid))->setDec('moneyd', $vo['bond']); echo "=订单ID:" . $id . ",止损平仓="; } else { if ($user['money'] + $vo['bond'] >= $tprofit) { $user_bond = $vo['bond'] - ($tprofit - $user['money']); $data['pc_price'] = $close; $data['status'] = 3; $data['yk_status'] = 2; $data['ylmoney'] = $tprofit; $data['endtime'] = date("Y-m-d H:i:s", time()); $bond = $tprofit - $vo['bond']; $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $user_bond; $ubill['afternum'] = $user_bond; $ubill['coinname'] = "lever"; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = '合約交易止損平倉退回剩餘保證金'; $ubillre = M("bill")->add($ubill); $ubill['num'] = $user['money']; $ubill['afternum'] = 0; $ubill['type'] = 20; $ubill['st'] = 2; $ubill['remark'] = '合約交易手動平倉虧損'; M("leverorder")->where(array('id' => $id))->save($data); M("levermoney")->where(['uid' => $uid])->setInc('money', $user_bond); M("levermoney")->where(array('uid' => $uid))->setDec('money', $user['money']); M("levermoney")->where(array('uid' => $uid))->setDec('moneyd', $vo['bond']); echo "=订单ID:" . $id . ",止损平仓="; } else { $data['pc_price'] = $close; $data['status'] = 3; $data['yk_status'] = 2; $data['ylmoney'] = $tprofit; $data['endtime'] = date("Y-m-d H:i:s", time()); $bond = $tprofit - $vo['bond']; $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $user['money']; $ubill['afternum'] = 0; $ubill['coinname'] = "lever"; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = '合約交易ID' . $vo['id'] . '止損平倉扣除完保證金,並扣除合約帳戶'; $ubillre = M("bill")->add($ubill); M("leverorder")->where(array('id' => $id))->save($data); M("levermoney")->where(['uid' => $uid])->setDec('money', $user['money']); M("levermoney")->where(array('uid' => $uid))->setDec('moneyd', $vo['bond']); echo "=订单ID:" . $id . ",止损平仓="; } } } } } if ($zsprice == 0) { if ($direction == 1) { $profit_fd = sprintf("%.2f", ($close - $price) * $vo['num']); if ($profit_fd < 0) { if (abs($profit_fd) > ($user['money'] + $user['moneyd'])) { $data['pc_price'] = $close; $data['status'] = 4; $data['yk_status'] = 2; $data['ylmoney'] = $profit_fd; $data['endtime'] = date("Y-m-d H:i:s", time()); $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $user['money']; $ubill['afternum'] = 0; $ubill['coinname'] = "lever"; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = '合約交易ID' . $vo['id'] . '爆倉'; $ubillre = M("bill")->add($ubill); M("leverorder")->where(array('id' => $id))->save($data); M("levermoney")->where(['uid' => $uid])->save(['money' => 0, 'moneyd' => 0]); $pc_list = M('leverorder')->where(['uid' => $uid])->where(['status' => 2])->select(); foreach ($pc_list as $item) { $direction = $item['direction']; if ($direction == 1) { //做多 $profit = sprintf("%.2f", ($close - $item['price']) * $item['num']); } elseif ($direction == 2) { //做空 $profit = sprintf("%.2f", ($item['price'] - $close) * $item['num']); } if ($profit >= 0) { $yk_status = 1; } else { $yk_status = 2; } $tprofit = abs($profit); $datas['pc_price'] = $close; $datas['status'] = 3; $datas['yk_status'] = $yk_status; $datas['ylmoney'] = $tprofit; $datas['endtime'] = date("Y-m-d H:i:s", time()); $result = M("leverorder")->where(array('id' => $item['id'], 'status' => 2))->save($datas); $user = M('levermoney')->where(['uid' => $uid])->find(); if ($result) { if ($profit >= 0) { M("levermoney")->where(array('uid' => $uid))->setInc('money', $tprofit); $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $tprofit; $ubill['coinname'] = "lever"; $ubill['afternum'] = $user['money'] + $tprofit; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = L('合约交易自動平仓盈利收益'); $ubillre = M("bill")->add($ubill); } } } echo "=订单ID:" . $id . ",爆仓="; } } elseif ($direction == 2) { $profit_fd = sprintf("%.2f", ($price - $close) * $vo['num']); if ($profit_fd < 0) { if (abs($profit_fd) > ($vo['bond'] + $user['moneyd'])) { $data['pc_price'] = $close; $data['status'] = 4; $data['yk_status'] = 2; $data['ylmoney'] = $profit_fd; $data['endtime'] = date("Y-m-d H:i:s", time()); $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $user['money']; $ubill['afternum'] = 0; $ubill['coinname'] = "lever"; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = '合約交易ID' . $vo['id'] . '爆倉'; $ubillre = M("bill")->add($ubill); M("leverorder")->where(array('id' => $id))->save($data); M("levermoney")->where(['uid' => $uid])->save(['money' => 0, 'moneyd' => 0]); $pc_list = M('leverorder')->where(['uid' => $uid])->where(['status' => 2])->select(); foreach ($pc_list as $item) { $direction = $item['direction']; if ($direction == 1) { //做多 $profit = sprintf("%.2f", ($close - $item['price']) * $item['num']); } elseif ($direction == 2) { //做空 $profit = sprintf("%.2f", ($item['price'] - $close) * $item['num']); } if ($profit >= 0) { $yk_status = 1; } else { $yk_status = 2; } $tprofit = abs($profit); $datas['pc_price'] = $close; $datas['status'] = 3; $datas['yk_status'] = $yk_status; $datas['ylmoney'] = $tprofit; $datas['endtime'] = date("Y-m-d H:i:s", time()); $result = M("leverorder")->where(array('id' => $item['id'], 'status' => 2))->save($datas); $user = M('levermoney')->where(['uid' => $uid])->find(); if ($result) { if ($profit >= 0) { M("levermoney")->where(array('uid' => $uid))->setInc('money', $tprofit); $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $tprofit; $ubill['coinname'] = "lever"; $ubill['afternum'] = $user['money'] + $tprofit; $ubill['type'] = 20; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 1; $ubill['remark'] = L('合约交易自動平仓盈利收益'); $ubillre = M("bill")->add($ubill); } } } echo "=订单ID:" . $id . ",爆仓="; } } } } } // echo "正常请求".$close; } else { echo "未获取到参数" . $id; } } } } //永续合约委托定单自动建仓 public function AutoCreateOrder() { $list = M("leverorder")->where(array('status' => 1))->select(); if (!empty($list)) { $sysinfo = M("leversetting")->where(array('id' => 1))->find(); $lever_fee = $sysinfo['lever_fee'];//费率 foreach ($list as $key => $vo) { $id = $vo['id']; $uid = $vo['uid']; $uinfo = M("user")->where(array('id' => $uid))->field("id,username")->find(); $minfo = M("user_coin")->where(array('userid' => $uid))->find(); $usermoney = M('levermoney')->where(['uid' => $uid])->find(); $lowercoin = $vo['coinname']; if ($lowercoin == 'ukbusdt') { $o_symbol = $vo['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 { $oy_list = do_request(oy_url($vo['coinname'], 'api/v5/market/ticker?instId='), []); $oy_list = $oy_list->data[0]; $close = $oy_list->last;//现价 } if ($close) { //手续费计算(开仓价格 * 开仓数量 * 手续费率) ,开仓时扣除手续费 $wt_price = $vo['wt_price']; //委托价格 $direction = $vo['direction']; //交易方向 if ($direction == 1) { //做多(上涨) 当前价小于等于委托价格就开仓 要跌了才开仓 if ($close <= $wt_price) { $data['fee'] = $fee = $vo['fee']; if ($usermoney['money'] >= $fee) { $data['price'] = $close; $data['status'] = 2; $data['addtime'] = date("Y-m-d H:i:s", time()); $re_a = M("leverorder")->where(array('id' => $id))->save($data); $re_b = M("levermoney")->where(array('uid' => $uid))->setDec('money', $fee); $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $fee; $ubill['coinname'] = "lever"; $ubill['afternum'] = $usermoney['money'] - $fee; $ubill['type'] = 25; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 2; $ubill['remark'] = L('合约交易开仓手续费'); $re_c = M("bill")->add($ubill); if ($re_a && $re_b && $re_c) { echo "=订单ID:" . $id . ",开仓成功="; } } else { echo "=订单ID:" . $id . ",手续费不足="; } } else { echo "=订单ID:" . $id . ",做多,价格不合适="; } } else if ($direction == 2) { //做空(下跌) 当前价大于等于委托价格就开仓 要涨了才开仓 if ($close >= $wt_price) { $data['fee'] = $fee = $vo['fee']; if ($usermoney['money'] >= $fee) { $data['price'] = $close; $data['status'] = 2; $data['addtime'] = date("Y-m-d H:i:s", time()); $re_a = M("leverorder")->where(array('id' => $id))->save($data); $re_b = M("levermoney")->where(array('uid' => $uid))->setDec('money', $fee); $ubill['uid'] = $uid; $ubill['username'] = $uinfo['username']; $ubill['num'] = $fee; $ubill['coinname'] = "usdt"; $ubill['afternum'] = $usermoney['money'] - $fee; $ubill['type'] = 25; $ubill['addtime'] = date("Y-m-d H:i:s", time()); $ubill['st'] = 2; $ubill['remark'] = L('合约交易开仓手续费'); $re_c = M("bill")->add($ubill); if ($re_a && $re_b && $re_c) { echo "=订单ID:" . $id . ",开仓成功="; } } else { echo "=订单ID:" . $id . ",手续费不足="; } } else { echo "=订单ID:" . $id . ",做空,价格不合适="; } } }else{ echo "未获取到参数"; } } } } //自动释放冻结的认购币,设置计划任务,每天执行一次 public function releaseissue() { $nowday = date("Y-m-d", time()); $map['status'] = 1; $map['endday'] = array('elt', $nowday); $list = M("issue_log")->where($map)->select(); if (!empty($list)) { foreach ($list as $key => $vo) { $id = $vo['id']; $uid = $vo['uid']; $num = $vo['num']; $cname = trim($vo['coinname']); $cnamed = trim($vo['coinname']) . "d"; //修改记录状态 $result = M("issue_log")->where(array('id' => $id))->save(array('status' => 2)); if ($result) { $minfo = M("user_coin")->where(array('userid' => $uid))->find(); //扣除冻结的资产 M("user_coin")->where(array('userid' => $uid))->setDec($cnamed, $num); //增加可用资产的数量 M("user_coin")->where(array('userid' => $uid))->setInc($cname, $num); //写入日志 $data['uid'] = $uid; $data['username'] = $vo['account']; $data['num'] = $num; $data['coinname'] = $cname; $data['afternum'] = $minfo[$cname] + $num; $data['type'] = 18; $data['addtime'] = date("Y-m-d H:i:s", time()); $data['st'] = 1; $data['remark'] = L("认购资产释放"); M("bill")->add($data); echo "==认购记录ID:" . $id . "释放成功"; } else { echo "==认购记录ID:" . $id . "释放失败"; } } } else { echo "==没有可释放认购记录=="; } } //委托订单自动交易 //设置成5-10秒执行一次的计划任务 public function autoxjtade() { $list = M("bborder")->where(array('ordertype' => 1, 'status' => 1))->select(); if (!empty($list)) { foreach ($list as $k => $v) { $type = $v['type']; $uid = $v['uid']; $id = $v['id']; $symbol = strtolower($v['coin']) . 'usdt'; $lowercoin = strtolower($v['coin']); //限价单价 $xjprice = $v['xjprice']; $sxfbl = $v['sxfbl']; if ($lowercoin == "ukb") { $priceinfo = M("market")->where(array('name' => "ukb_usdt"))->field("new_price")->find(); $newprice = $priceinfo['new_price']; }else if ($lowercoin == "gcb") { $priceinfo = M("market")->where(array('name' => "gcb_usdt"))->field("new_price")->find(); $newprice = $priceinfo['new_price']; } else { //获取当前行情价 $oy_list = do_request(oy_url(strtolower($v['coin']), 'api/v5/market/ticker?instId='), []); $oy_list = $oy_list->data[0]; $newprice = $oy_list->last;//现价 // $coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol; // $newprice = $this->getnewprice($coinapi); } if ($newprice){ //买入,当行情价小于等于限价时则交易 $minfo = M("user_coin")->where(array('userid' => $uid))->find(); if ($type == 1) { $usdtnum = $v['usdtnum']; if ($newprice <= $xjprice) { //计算能够买到的量 $buy_coinnum = sprintf("%.8f", ($usdtnum / $newprice)); //手续费 $fee = $buy_coinnum * $sxfbl / 100; //实际到账号的金额 $tcoinnum = $buy_coinnum - $fee; //更新订单 $data['coinnum'] = $tcoinnum; $data['price'] = $newprice; $data['tradetime'] = date("Y-m-d H:i:s", time()); $data['fee'] = $fee; $data['status'] = 2; $savere = M("bborder")->where(array('id' => $id))->save($data); //增加购买数量并写入日志 $incre = M("user_coin")->where(array('userid' => $uid))->setInc($lowercoin, $tcoinnum); $cincbill['uid'] = $uid; $cincbill['username'] = $v['account']; $cincbill['num'] = $tcoinnum; $cincbill['coinname'] = $lowercoin; $cincbill['afternum'] = $minfo[$lowercoin] + $tcoinnum; $cincbill['type'] = 10; $cincbill['addtime'] = date("Y-m-d H:i:s", time()); $cincbill['st'] = 1; $cincbill['remark'] = L('币币交易限价购买委托成交'); $cincre = M("bill")->add($cincbill); //扣除冻结的USDT并写入日志 $decre = M("user_coin")->where(array('userid' => $uid))->setDec("usdtd", $usdtnum); $uincbill['uid'] = $uid; $uincbill['username'] = $v['account']; $uincbill['num'] = $usdtnum; $uincbill['coinname'] = "usdt"; $uincbill['afternum'] = $minfo['usdt']; $uincbill['type'] = 9; $uincbill['addtime'] = date("Y-m-d H:i:s", time()); $uincbill['st'] = 2; $uincbill['remark'] = L('币币交易限价购买委托成交'); $uincre = M("bill")->add($uincbill); if ($savere && $cincre && $uincre) { $notice['uid'] = $uid; $notice['account'] = $v['account']; $notice['title'] = L('币币交易限价委托交易'); $notice['content'] = L('币币交易限价购买委托订单购买成功'); $notice['addtime'] = date("Y-m-d H:i:s", time()); $notice['status'] = 1; M("notice")->add($notice); echo "==委托订单ID:" . $id . ",购买成功=="; } } else { echo "==委托订单ID:" . $id . ",没有达到限价购买价格=="; } //卖出,当行情价大于等于限价时则交易 } elseif ($type == 2) { $coinnum = $v['coinnum']; if ($newprice >= $xjprice) { //求出卖出所得的USDT量 $allusdt = sprintf("%.8f", ($coinnum * $newprice)); //求出手续费 $fee = $allusdt * $sxfbl / 100; //求出实际到账USDT量 $tusdtnum = $allusdt - $fee; //更新订单 $data['usdtnum'] = $tusdtnum; $data['price'] = $newprice; $data['tradetime'] = date("Y-m-d H:i:s", time()); $data['fee'] = $fee; $data['status'] = 2; $savere = M("bborder")->where(array('id' => $id))->save($data); //增加卖出所得的USDT量并写入日志 $incre = M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $tusdtnum); $uincbill['uid'] = $uid; $uincbill['username'] = $v['account']; $uincbill['num'] = $tusdtnum; $uincbill['coinname'] = 'usdt'; $uincbill['afternum'] = $minfo['usdt'] + $tusdtnum; $uincbill['type'] = 9; $uincbill['addtime'] = date("Y-m-d H:i:s", time()); $uincbill['st'] = 1; $uincbill['remark'] = L('币币交易限价出售委托成交'); $uincre = M("bill")->add($uincbill); //扣除冻结的卖出币量并写入日志 $decre = M("user_coin")->where(array('userid' => $uid))->setDec($lowercoin . "d", $coinnum); $cincbill['uid'] = $uid; $cincbill['username'] = $v['account']; $cincbill['num'] = $coinnum; $cincbill['coinname'] = $lowercoin; $cincbill['afternum'] = $minfo[$lowercoin] - $coinnum; $cincbill['type'] = 10; $cincbill['addtime'] = date("Y-m-d H:i:s", time()); $cincbill['st'] = 2; $cincbill['remark'] = L('币币交易限价出售委托成交'); $cincre = M("bill")->add($cincbill); if ($savere && $cincre && $uincre) { $notice['uid'] = $uid; $notice['account'] = $v['account']; $notice['title'] = L('币币交易限价委托交易'); $notice['content'] = L('币币交易限价购买委托订单出售成功'); $notice['addtime'] = date("Y-m-d H:i:s", time()); $notice['status'] = 1; M("notice")->add($notice); echo "==委托订单ID:" . $id . ",出售成功=="; } } else { echo "==委托订单ID:" . $id . ",没有达到限价出售价格=="; } } }else{ echo "未获取到参数"; } } } else { echo "没有限价委托可交易!"; } } //释放冻结的矿机收益币 //设置一天执行一次的计划任务 public function releasedjprofit() { $nowday = date("Y-m-d", time()); $where['thawday'] = array('elt', $nowday); $where['status'] = array('eq', 1); $list = M("djprofit")->where($where)->select(); if (!empty($list)) { foreach ($list as $key => $vo) { $id = $vo['id']; $uid = $vo['uid']; $username = $vo['username']; $num = $vo['num']; $coinname = trim($vo['coin']); $minfo = M("user_coin")->where(array('userid' => $uid))->find(); //修改冻结状态 M("djprofit")->where(array('id' => $id))->save(array('status' => 2)); //添加财务日志 $billdata['uid'] = $uid; $billdata['username'] = $username; $billdata['num'] = $num; $billdata['coinname'] = $coinname; $billdata['afternum'] = $minfo[$coinname] + $num; $billdata['type'] = 8; $billdata['addtime'] = date("Y-m-d H:i:s", time()); $billdata['st'] = 1; $billdata['remark'] = L('释放冻结收益'); M("bill")->add($billdata); //增加会员资产,减少冻结额度 $coinname_d = $coinname . "d"; M("user_coin")->where(array('userid' => $uid))->setDec($coinname_d, $num); M("user_coin")->where(array('userid' => $uid))->setInc($coinname, $num); $notice['uid'] = $uid; $notice['account'] = $username; $notice['title'] = L('释放冻结收益'); $notice['content'] = L('您冻结的矿机收益释放成功,可以交易'); $notice['addtime'] = date("Y-m-d H:i:s", time()); $notice['status'] = 1; M("notice")->add($notice); echo "==ID:" . $id . "释放" . $num . $coinname . "成功=="; echo "
"; } } else { echo "====没有可释放的冻结记录===="; } } //共享矿机自动结算收益,设置一天执行一次的计划任务 public function authsharesjsy() { $kjlist = M("kjorder")->where(array('status' => 1, 'type' => 2))->select(); if (!empty($kjlist)) { foreach ($kjlist as $key => $vo) { $id = $vo['id']; $uid = $vo['uid']; $username = $vo['username']; $minfo = M("user_coin")->where(array('userid' => $uid))->find(); $kid = $vo['kid']; $nowdate = date("Y-m-d", time()); $profitinfo = M("kjprofit")->where(array('uid' => $uid, 'kid' => $id, 'day' => $nowdate))->find(); if (empty($profitinfo)) { $sharbltxt = $vo['sharbltxt']; if ($sharbltxt <= 0) { echo "===共享矿机ID" . $id . "共享码有误==="; } else { $sharekj = M("kjorder")->where(array('sharbltxt' => $sharbltxt))->count(); if ($sharekj >= 2) { //查找矿机收益的类型以及查找收益是否需要冻结及冻结天数 $outtype = $vo['outtype']; if ($outtype == 1) {//按产值需要查找产出币种的最新行情 $coinname = strtolower(trim($vo['outcoin'])); $outnum = $vo['outusdt']; $symbol = $coinname . 'usdt'; $coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol; $newprice = $this->getnewprice($coinapi); $tcoinnum = sprintf("%.6f", ($outnum / $newprice)); //实际产生的币量,保留6位小数 } elseif ($outtype == 2) { $coinname = strtolower(trim($vo['outcoin'])); $tcoinnum = $vo['outnum']; } $djout = $vo['djout'];//1冻结2不冻结 $djday = $vo['djnum'];//冻结天数 //写入矿机收益日志 $kjprofit_d['uid'] = $uid; $kjprofit_d['username'] = $username; $kjprofit_d['kid'] = $id; $kjprofit_d['ktitle'] = $vo['kjtitle']; $kjprofit_d['num'] = $tcoinnum; $kjprofit_d['coin'] = $coinname; $kjprofit_d['addtime'] = date("Y-m-d H:i:s", time()); $kjprofit_d['day'] = date("Y-m-d", time()); M("kjprofit")->add($kjprofit_d); if ($djout == 2) { $coin_d = $coinname . "d"; M("user_coin")->where(array('userid' => $uid))->setInc($coin_d, $tcoinnum); $djprofit_d['uid'] = $uid; $djprofit_d['username'] = $username; $djprofit_d['num'] = $tcoinnum; $djprofit_d['coin'] = $coinname; $djprofit_d['status'] = 1; $djprofit_d['addtime'] = date("Y-m-d H:i:s", time()); $djprofit_d['addday'] = date("Y-m-d", time()); $djprofit_d['thawtime'] = date("Y-m-d H:i:s", (time() + 86400 * $djday)); $djprofit_d['thawday'] = date("Y-m-d", (time() + 86400 * $djday)); $djprofit_d['remark'] = L('冻结矿机释放收益'); M("djprofit")->add($djprofit_d); //写资金日志 $billdata['uid'] = $uid; $billdata['username'] = $username; $billdata['num'] = $tcoinnum; $billdata['coinname'] = $coinname; $billdata['afternum'] = $minfo[$coin_d] + $tcoinnum; $billdata['type'] = 7; $billdata['addtime'] = date("Y-m-d H:i:s", time()); $billdata['st'] = 1; $billdata['remark'] = L('矿机收益释放冻结'); M("bill")->add($billdata); $notice['uid'] = $uid; $notice['account'] = $username; $notice['title'] = L('矿机收益'); $notice['content'] = L('今日矿机收益已成功到账,请注册查收'); $notice['addtime'] = date("Y-m-d H:i:s", time()); $notice['status'] = 1; M("notice")->add($notice); } elseif ($djout == 1) { M("user_coin")->where(array('userid' => $uid))->setInc($coinname, $tcoinnum); //写资金日志 $billdata['uid'] = $uid; $billdata['username'] = $username; $billdata['num'] = $tcoinnum; $billdata['coinname'] = $coinname; $billdata['afternum'] = $minfo[$coinname] + $tcoinnum; $billdata['type'] = 8; $billdata['addtime'] = date("Y-m-d H:i:s", time()); $billdata['st'] = 1; $billdata['remark'] = L('矿机收益释放'); M("bill")->add($billdata); } //修改矿机收益次数 M("kjorder")->where(array('id' => $id))->setDec("synum", 1); $reinfo = M("kjorder")->where(array('id' => $id))->find(); if ($reinfo['synum'] < 1) { M("kjorder")->where(array('id' => $id))->save(array('status' => 3)); } echo "==共享矿机ID:" . $kid . "收益成功=="; echo "
"; } else { echo "===共享矿机ID" . $id . "另一部分没有购买,不能收益==="; } } } else { echo "==矿机ID:" . $kid . "不能重复收益=="; echo "
"; } } } } //独资矿机自动收益,每天执行一次 //设置一天执行一次的计划任务 public function autokjsy() { $kjlist = M("kjorder")->where(array('status' => 1, 'type' => 1))->select(); if (!empty($kjlist)) { foreach ($kjlist as $key => $vo) { $id = $vo['id']; $uid = $vo['uid']; $username = $vo['username']; $minfo = M("user_coin")->where(array('userid' => $uid))->find(); $kid = $vo['kid']; $nowdate = date("Y-m-d", time()); $profitinfo = M("kjprofit")->where(array('uid' => $uid, 'kid' => $id, 'day' => $nowdate))->find(); if (empty($profitinfo)) { //查找矿机收益的类型以及查找收益是否需要冻结及冻结天数 $outtype = $vo['outtype']; if ($outtype == 1) {//按产值需要查找产出币种的最新行情 $coinname = strtolower(trim($vo['outcoin'])); $outnum = $vo['outusdt']; $symbol = $coinname . 'usdt'; $coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol; $newprice = $this->getnewprice($coinapi); $tcoinnum = sprintf("%.6f", ($outnum / $newprice)); //实际产生的币量,保留6位小数 } elseif ($outtype == 2) { $coinname = strtolower(trim($vo['outcoin'])); $tcoinnum = $vo['outnum']; } $djout = $vo['djout'];//1冻结2不冻结 $djday = $vo['djnum'];//冻结天数 //写入矿机收益日志 $kjprofit_d['uid'] = $uid; $kjprofit_d['username'] = $username; $kjprofit_d['kid'] = $id; $kjprofit_d['ktitle'] = $vo['kjtitle']; $kjprofit_d['num'] = $tcoinnum; $kjprofit_d['coin'] = $coinname; $kjprofit_d['addtime'] = date("Y-m-d H:i:s", time()); $kjprofit_d['day'] = date("Y-m-d", time()); M("kjprofit")->add($kjprofit_d); if ($djout == 2) { $coin_d = $coinname . "d"; M("user_coin")->where(array('userid' => $uid))->setInc($coin_d, $tcoinnum); $djprofit_d['uid'] = $uid; $djprofit_d['username'] = $username; $djprofit_d['num'] = $tcoinnum; $djprofit_d['coin'] = $coinname; $djprofit_d['status'] = 1; $djprofit_d['addtime'] = date("Y-m-d H:i:s", time()); $djprofit_d['addday'] = date("Y-m-d", time()); $djprofit_d['thawtime'] = date("Y-m-d H:i:s", (time() + 86400 * $djday)); $djprofit_d['thawday'] = date("Y-m-d", (time() + 86400 * $djday)); $djprofit_d['remark'] = L('冻结矿机释放收益'); M("djprofit")->add($djprofit_d); //写资金日志 $billdata['uid'] = $uid; $billdata['username'] = $username; $billdata['num'] = $tcoinnum; $billdata['coinname'] = $coinname; $billdata['afternum'] = $minfo[$coin_d] + $tcoinnum; $billdata['type'] = 7; $billdata['addtime'] = date("Y-m-d H:i:s", time()); $billdata['st'] = 1; $billdata['remark'] = L('矿机收益释放冻结'); M("bill")->add($billdata); $notice['uid'] = $uid; $notice['account'] = $username; $notice['title'] = L('矿机收益'); $notice['content'] = L('今日矿机收益已成功到账,请注册查收'); $notice['addtime'] = date("Y-m-d H:i:s", time()); $notice['status'] = 1; M("notice")->add($notice); } elseif ($djout == 1) { M("user_coin")->where(array('userid' => $uid))->setInc($coinname, $tcoinnum); //写资金日志 $billdata['uid'] = $uid; $billdata['username'] = $username; $billdata['num'] = $tcoinnum; $billdata['coinname'] = $coinname; $billdata['afternum'] = $minfo[$coinname] + $tcoinnum; $billdata['type'] = 8; $billdata['addtime'] = date("Y-m-d H:i:s", time()); $billdata['st'] = 1; $billdata['remark'] = L('矿机收益释放'); M("bill")->add($billdata); } //修改矿机收益次数 M("kjorder")->where(array('id' => $id))->setDec("synum", 1); $reinfo = M("kjorder")->where(array('id' => $id))->find(); if ($reinfo['synum'] < 1) { M("kjorder")->where(array('id' => $id))->save(array('status' => 3)); } echo "==矿机ID:" . $kid . "收益成功=="; echo "
"; } else { echo "==矿机ID:" . $kid . "不能重复收益=="; echo "
"; } } } else { echo "++||没有正常运行的矿机||++"; } } //休验订单自动按风控比例设置订单的盈亏比例 //设置成5-10秒执行一次的计划任务 public function setwl_ty() { $map['status'] = 1; $map['kongyk'] = 0; $orderobj = M("tyhyorder"); $count = $orderobj->where($map)->count(); $setting = M("hysetting")->where(array('id' => 1))->field("hy_fkgl")->find(); if ($setting['hy_fkgl'] > 0) { $ylcount = intval($count * $setting['hy_fkgl'] / 100); $kscount = $count - $ylcount; if ($ylcount > 0) { $yllist = $orderobj->where($map)->order("num asc")->limit($ylcount)->select(); if (!empty($yllist)) { foreach ($yllist as $k => $v) { $yid = $v['id']; $orderobj->where(array('id' => $yid))->save(array('kongyk' => 1)); echo "订单ID:" . $yid . "设为盈利=="; } } } if ($kscount > 0) { $kslist = $orderobj->where($map)->order("num asc")->limit($kscount)->select(); if (!empty($kslist)) { foreach ($kslist as $k => $v) { $kid = $v['id']; $orderobj->where(array('id' => $kid))->save(array('kongyk' => 2)); echo "订单ID:" . $kid . "设为亏损=="; } } } } echo "操作成功"; } //自动按风控比例设置订单的盈亏比例 //设置成5-10秒执行一次的计划任务 public function setwl() { $map['status'] = 1; $map['kongyk'] = 0; $orderobj = M("hyorder"); $count = $orderobj->where($map)->count(); $setting = M("hysetting")->where(array('id' => 1))->field("hy_fkgl")->find(); if ($setting['hy_fkgl'] > 0) { $ylcount = intval($count * $setting['hy_fkgl'] / 100); $kscount = $count - $ylcount; if ($ylcount > 0) { $yllist = $orderobj->where($map)->order("num asc")->limit($ylcount)->select(); if (!empty($yllist)) { foreach ($yllist as $k => $v) { $yid = $v['id']; $orderobj->where(array('id' => $yid))->save(array('kongyk' => 1)); echo "订单ID:" . $yid . "设为盈利=="; } } } if ($kscount > 0) { $kslist = $orderobj->where($map)->order("num asc")->limit($kscount)->select(); if (!empty($kslist)) { foreach ($kslist as $k => $v) { $kid = $v['id']; $orderobj->where(array('id' => $kid))->save(array('kongyk' => 2)); echo "订单ID:" . $kid . "设为亏损=="; } } } } echo "操作成功"; } //自动结算合约订单 public function hycarryout_ty() { $nowtime = time(); $map['status'] = 1; $map['intselltime'] = array('elt', $nowtime); $orderobj = M("tyhyorder"); $list = $orderobj->where($map)->select(); if (!empty($list)) { foreach ($list as $key => $vo) { $coinname = $vo['coinname']; $coinarr = explode("/", $coinname); $symbol = strtolower($coinarr[0]) . strtolower($coinarr[1]); $coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol; $newprice = $this->getnewprice($coinapi); $randnum = "0." . rand(1000, 9999); $buyprice = $vo['buyprice']; $otype = $vo['hyzd']; //合约方向 $dkong = $vo['kongyk']; //单控设置 $uid = $vo['uid'];//会员ID $id = $vo['id'];//记录ID $num = $vo['num']; $hybl = $vo['hybl']; //收益比例 $ylnum = $num * ($hybl / 100); //盈利金额 $money = $num + $ylnum;//本金+盈利金额 //$dkong分三种情况 1、0表示随行情,1表示盈利 2 表示亏损 //盈利时增加$money,,亏损时亏本金 if ($dkong == 0) { //买涨 if ($otype == 1) { //买跌 if ($newprice > $buyprice) { //盈利 //增加资产 //M("user_coin")->where(array('userid'=>$uid))->setInc("usdt",$money); M("user")->where(array('id' => $uid))->setInc("money", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $newprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 //$this->addlog($uid,$vo['username'],$money); } else {//亏损 //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $newprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } elseif ($otype == 2) { //买跌 if ($newprice < $buyprice) { //盈利 //增加资产 //M("user_coin")->where(array('userid'=>$uid))->setInc("usdt",$money); M("user")->where(array('id' => $uid))->setInc("money", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $newprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 //$this->addlog($uid,$vo['username'],$money); } else {//亏损 //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $newprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } } elseif ($dkong == 1) {//单控盈利 if ($otype == 1) {//买涨 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $newprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //增加资产 //M("user_coin")->where(array('userid'=>$uid))->setInc("usdt",$money); M("user")->where(array('id' => $uid))->setInc("money", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 //$this->addlog($uid,$vo['username'],$money); } elseif ($otype == 2) {//买跌 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //增加资产 //M("user_coin")->where(array('userid'=>$uid))->setInc("usdt",$money); M("user")->where(array('id' => $uid))->setInc("money", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 //$this->addlog($uid,$vo['username'],$money); } } elseif ($dkong == 2) { if ($otype == 1) {//买涨 //买涨,指定亏损,结算价格要低于买入价格 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } elseif ($otype == 2) {//买跌 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $buyprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } echo "==订单ID:" . $id . "出售成功=="; } } else { echo "没有订单可以结算!"; } } //自动结算体验合约订单 public function hycarryout_ty_old() { $nowtime = time(); $map['status'] = 1; $map['intselltime'] = array('elt', $nowtime); $orderobj = M("tyhyorder"); $list = $orderobj->where($map)->select(); //获取合约参数 $setting = M("hysetting")->where(array('id' => 1))->field("hy_ksid,hy_ylid,hy_fkgl")->find(); //指定盈利ID组 $winarr = explode(',', $setting['hy_ylid']); //指定亏损ID组 $lossarr = explode(',', $setting['hy_ksid']); //风控比例组 $fkarr = explode(',', $setting['hy_fkgl']); if (!empty($list)) { foreach ($list as $key => $vo) { $coinname = $vo['coinname']; $coinarr = explode("/", $coinname); $symbol = strtolower($coinarr[0]) . strtolower($coinarr[1]); $coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol; $newprice = $this->getnewprice($coinapi); $randnum = "0." . rand(1000, 9999); $buyprice = $vo['buyprice']; $otype = $vo['hyzd']; //合约方向 $dkong = $vo['kongyk']; //单控设置 $uid = $vo['uid'];//会员ID $id = $vo['id'];//记录ID $num = $vo['num']; $hybl = $vo['hybl']; $ylnum = $num * ($hybl / 100); $money = $num + $ylnum;//盈利金额 //买涨 if ($otype == 1) { if (in_array($uid, $winarr)) {//如果有指定盈利ID,则按盈利结算 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $newprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //增加资产 //M("user_coin")->where(array('userid'=>$uid))->setInc("usdt",$money); M("user")->where(array('id' => $uid))->setInc("money", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 //$this->addlog($uid,$vo['username'],$money); } elseif (in_array($uid, $lossarr)) {//如果有指定亏损ID,则按亏损结算 //买涨,指定亏损,结算价格要低于买入价格 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } else {//如果未指定盈利和亏损,则按单控的计算 if ($dkong == 1) {//盈利 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $newprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } // echo '买入价格:'.$buyprice; // echo "
"; // echo '结算价格:'.$sellprice;die; //增加资产 //M("user_coin")->where(array('userid'=>$uid))->setInc("usdt",$money); M("user")->where(array('id' => $uid))->setInc("money", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 //$this->addlog($uid,$vo['username'],$money); } elseif ($dkong == 2) {//亏损 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } // echo '买入价格:'.$buyprice; // echo "
"; // echo '结算价格:'.$sellprice;die; //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } //买跌 } elseif ($otype == 2) { if (in_array($uid, $winarr)) {//如果有指定盈利ID,则按盈利结算 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //增加资产 //M("user_coin")->where(array('userid'=>$uid))->setInc("usdt",$money); M("user")->where(array('id' => $uid))->setInc("money", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 //$this->addlog($uid,$vo['username'],$money); } elseif (in_array($uid, $lossarr)) {//如果有指定亏损ID,则按亏损结算 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $buyprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } else {//如果未指定盈利和亏损,则按单控的计算 if ($dkong == 1) {//盈利 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //增加资产 //M("user_coin")->where(array('userid'=>$uid))->setInc("usdt",$money); M("user")->where(array('id' => $uid))->setInc("money", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 //$this->addlog($uid,$vo['username'],$money); } elseif ($dkong == 2) {//亏损 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $buyprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } } echo "==订单ID:" . $id . "出售成功=="; } } else { echo "没有订单可以结算!"; } } //自动结算合约订单 public function hycarryout() { $nowtime = time(); $map['status'] = 1; $map['intselltime'] = array('elt', $nowtime); $orderobj = M("hyorder"); $list = $orderobj->where($map)->select(); if (!empty($list)) { foreach ($list as $key => $vo) { $coinname = $vo['coinname']; $coinarr = explode("/", $coinname); $symbol = strtolower($coinarr[0]) . strtolower($coinarr[1]); $coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol; $newprice = $this->getnewprice($coinapi); $randnum = "0." . rand(1000, 9999); $buyprice = $vo['buyprice']; $otype = $vo['hyzd']; //合约方向 $dkong = $vo['kongyk']; //单控设置 $uid = $vo['uid'];//会员ID $id = $vo['id'];//记录ID $num = $vo['num']; $hybl = $vo['hybl']; //收益比例 $ylnum = $num * ($hybl / 100); //盈利金额 $money = $num + $ylnum;//本金+盈利金额 //$dkong分三种情况 1、0表示随行情,1表示盈利 2 表示亏损 //盈利时增加$money,,亏损时亏本金 if ($dkong == 0) { //买涨 if ($otype == 1) { //买跌 if ($newprice > $buyprice) { //盈利 //增加资产 M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $newprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 $this->addlog($uid, $vo['username'], $money); } else {//亏损 //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $newprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } elseif ($otype == 2) { //买跌 if ($newprice < $buyprice) { //盈利 //增加资产 M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $newprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 $this->addlog($uid, $vo['username'], $money); } else {//亏损 //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $newprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } } elseif ($dkong == 1) {//单控盈利 if ($otype == 1) {//买涨 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $newprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //增加资产 M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 $this->addlog($uid, $vo['username'], $money); } elseif ($otype == 2) {//买跌 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //增加资产 M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 $this->addlog($uid, $vo['username'], $money); } } elseif ($dkong == 2) { if ($otype == 1) {//买涨 //买涨,指定亏损,结算价格要低于买入价格 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } elseif ($otype == 2) {//买跌 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $buyprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } echo "==订单ID:" . $id . "出售成功=="; } } else { echo "没有订单可以结算!"; } } //自动结算合约订单 public function hycarryout____old() { $nowtime = time(); $map['status'] = 1; $map['intselltime'] = array('elt', $nowtime); $orderobj = M("hyorder"); $list = $orderobj->where($map)->select(); //获取合约参数 $setting = M("hysetting")->where(array('id' => 1))->field("hy_ksid,hy_ylid,hy_fkgl")->find(); //指定盈利ID组 $winarr = explode(',', $setting['hy_ylid']); //指定亏损ID组 $lossarr = explode(',', $setting['hy_ksid']); //风控比例组 $fkarr = explode(',', $setting['hy_fkgl']); if (!empty($list)) { foreach ($list as $key => $vo) { $coinname = $vo['coinname']; $coinarr = explode("/", $coinname); $symbol = strtolower($coinarr[0]) . strtolower($coinarr[1]); $coinapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=" . $symbol; $newprice = $this->getnewprice($coinapi); $randnum = "0." . rand(1000, 9999); $buyprice = $vo['buyprice']; $otype = $vo['hyzd']; //合约方向 $dkong = $vo['kongyk']; //单控设置 $uid = $vo['uid'];//会员ID $id = $vo['id'];//记录ID $num = $vo['num']; $hybl = $vo['hybl']; $ylnum = $num * ($hybl / 100); $money = $num + $ylnum;//盈利金额 //买涨 if ($otype == 1) { if (in_array($uid, $winarr)) {//如果有指定盈利ID,则按盈利结算 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $newprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //增加资产 M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 $this->addlog($uid, $vo['username'], $money); } elseif (in_array($uid, $lossarr)) {//如果有指定亏损ID,则按亏损结算 //买涨,指定亏损,结算价格要低于买入价格 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } else {//如果未指定盈利和亏损,则按单控的计算 if ($dkong == 1) {//盈利 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $newprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } // echo '买入价格:'.$buyprice; // echo "
"; // echo '结算价格:'.$sellprice;die; //增加资产 M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 $this->addlog($uid, $vo['username'], $money); } elseif ($dkong == 2) {//亏损 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } // echo '买入价格:'.$buyprice; // echo "
"; // echo '结算价格:'.$sellprice;die; //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } //买跌 } elseif ($otype == 2) { if (in_array($uid, $winarr)) {//如果有指定盈利ID,则按盈利结算 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //增加资产 M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 $this->addlog($uid, $vo['username'], $money); } elseif (in_array($uid, $lossarr)) {//如果有指定亏损ID,则按亏损结算 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $buyprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } else {//如果未指定盈利和亏损,则按单控的计算 if ($dkong == 1) {//盈利 if ($newprice > $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice == $buyprice) { $sellprice = $buyprice - $randnum; } elseif ($newprice < $buyprice) { $sellprice = $newprice; } //增加资产 M("user_coin")->where(array('userid' => $uid))->setInc("usdt", $money); //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 1; $sd['sellprice'] = $sellprice; $sd['ploss'] = $ylnum; $orderobj->where(array('id' => $id))->save($sd); //写财务日志 $this->addlog($uid, $vo['username'], $money); } elseif ($dkong == 2) {//亏损 if ($newprice > $buyprice) { $sellprice = $newprice; } elseif ($newprice == $buyprice) { $sellprice = $buyprice + $randnum; } elseif ($newprice < $buyprice) { $sellprice = $buyprice + $randnum; } //修改订单状态 $sd['status'] = 2; $sd['is_win'] = 2; $sd['sellprice'] = $sellprice; $sd['ploss'] = $num; $orderobj->where(array('id' => $id))->save($sd); } } } echo "==订单ID:" . $id . "出售成功=="; } } else { echo "没有订单可以结算!"; } } //写财务日志 public function addlog($uid, $username, $money) { $minfo = M("user_coin")->where(array('userid' => $uid))->find(); $data['uid'] = $uid; $data['username'] = $username; $data['num'] = $money; $data['coinname'] = "usdt"; $data['afternum'] = $minfo['usdt'] + $money; $data['type'] = 4; $data['addtime'] = date("Y-m-d H:i:s", time()); $data['st'] = 1; $data['remark'] = L('合约出售'); M("bill")->add($data); $notice['uid'] = $uid; $notice['account'] = $username; $notice['title'] = L('快速合约交易'); $notice['content'] = L('快速合约已平仓,请及时加仓'); $notice['addtime'] = date("Y-m-d H:i:s", time()); $notice['status'] = 1; M("notice")->add($notice); } //获取行情数据 public function getnewprice($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); $price_arr = $result['data'][0]; $close = $price_arr['close'];//现价 return $close; } public function ups_and_downs() { $coin = M('coin')->where(['type' => 2, 'status' => 1])->select(); $delete = M('trade_log')->where('addtime < '.(time()-600))->delete(); foreach ($coin as $item) { $name = $item['name'] . '_' . 'usdt'; $market = M('market')->where(['name' => $name])->find(); $trade_list = M('trade_json')->where(['type' => 1])->order('id DESC')->find();// k线15分钟 $trade_list1 = M('trade_json')->where(['type' => 15])->order('id DESC')->find();// k线15分钟 $trade_list2 = M('trade_json')->where(['type' => 30])->order('id DESC')->find();// k线30分钟 $trade_list3 = M('trade_json')->where(['type' => 60])->order('id DESC')->find();// k线1小时 $trade_list4 = M('trade_json')->where(['type' => 240])->order('id DESC')->find();// k线4小时 $trade_list5 = M('trade_json')->where(['type' => 1440])->order('id DESC')->find();// k线1天 if ($market['zhang'] and $market['die']) { //同时设置涨跌幅 $zd = rand(1, 2); //1涨幅2下跌 if ($zd == 1) { $zf = $this->randomFloat(0, $market['zhang']); // 涨幅价格 $price = $market['new_price'] + ($market['new_price'] * ($zf / 100));//最新涨幅价格 if ($market['max_price'] < $price) { $market['max_price'] = $price; M('market')->where(['id' => $market['id']])->save(['max_price' => $price]); } } else { $xd = $this->randomFloat(0, $market['die']); // 下跌价格 $price = $market['new_price'] - ($market['new_price'] * ($xd / 100));//最新下跌价格 if ($market['min_price'] > $price) { $market['min_price'] = $price; M('market')->where(['id' => $market['id']])->save(['min_price' => $price]); } } M('market')->where(['id' => $market['id']])->save(['new_price' => $price]); if ($market['hou_time'] < strtotime('today')) { M('market')->where(['id' => $market['id']])->save(['hou_price' => $price, 'hou_time' => strtotime('today'), 'max_day' => $price, 'min_day' => $price]); } }else{ if ($market['zhang'] > 0 and $market['die'] == 0){ $zf = $this->randomFloat(0, $market['zhang']); // 涨幅价格 $price = $market['new_price'] + ($market['new_price'] * ($zf / 100));//最新涨幅价格 if ($market['max_price'] < $price) { $market['max_price'] = $price; M('market')->where(['id' => $market['id']])->save(['max_price' => $price]); } M('market')->where(['id' => $market['id']])->save(['new_price' => $price]); if ($market['hou_time'] < strtotime('today')) { M('market')->where(['id' => $market['id']])->save(['hou_price' => $price, 'hou_time' => strtotime('today'), 'max_day' => $price, 'min_day' => $price]); } } if ($market['zhang'] == 0 and $market['die'] > 0){ $xd = $this->randomFloat(0, $market['die']); // 下跌价格 $price = $market['new_price'] - ($market['new_price'] * ($xd / 100));//最新下跌价格 if ($market['min_price'] > $price) { $market['min_price'] = $price; M('market')->where(['id' => $market['id']])->save(['min_price' => $price]); } M('market')->where(['id' => $market['id']])->save(['new_price' => $price]); if ($market['hou_time'] < strtotime('today')) { M('market')->where(['id' => $market['id']])->save(['hou_price' => $price, 'hou_time' => strtotime('today'), 'max_day' => $price, 'min_day' => $price]); } } } if ($price){ $price = round($price, 6); $sd = $this->randomFloat($market['sdlow_num'], $market['sdhigh_num']); for ($i = 0; $i <= $sd; $i ++){ M('trade_log')->add([ 'market' => $name, 'price' => $price, 'num' => $this->randomFloat(0, 1), 'mum' => $this->randomFloat(0, 1), 'addtime' => time() - rand(1, 10), 'type' => rand(1, 2) ]); } if ($price > $market['max_day']){ M('market')->where(['id' => $market['id']])->save(['max_day' => $price]); } if ($price < $market['min_day']){ M('market')->where(['id' => $market['id']])->save(['min_day' => $price]); } if ($price > $market['max_price']){ M('market')->where(['id' => $market['id']])->save(['max_price' => $price]); $market['max_price'] = $price; } if ($price < $market['min_price']){ M('market')->where(['id' => $market['id']])->save(['min_price' => $price]); $market['min_price'] = $price; } if ($trade_list) { $data = json_decode($trade_list['data']); $time = $trade_list['addtime'] + ($trade_list['type'] * 60); if ($time <= time()) { M('market')->where(['id' => $market['id']])->save(['max_price' => $price]); M('market')->where(['id' => $market['id']])->save(['min_price' => $price]); $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $data[4], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 1, 'addtime' => time() ]; M('trade_json')->add($json); } } else { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $market['new_price'], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 1, 'addtime' => time() ]; M('trade_json')->add($json); } if ($trade_list1) { $data = json_decode($trade_list1['data']); $time = $trade_list1['addtime'] + ($trade_list1['type'] * 60); if ($time <= time()) { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $data[4], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 15, 'addtime' => time() ]; M('trade_json')->add($json); } } else { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $market['new_price'], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 15, 'addtime' => time() ]; M('trade_json')->add($json); } if ($trade_list2) { $data = json_decode($trade_list2['data']); $time = $trade_list2['addtime'] + ($trade_list2['type'] * 60); if ($time <= time()) { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $data[4], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 30, 'addtime' => time() ]; M('trade_json')->add($json); } } else { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $market['new_price'], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 30, 'addtime' => time() ]; M('trade_json')->add($json); } if ($trade_list3) { $data = json_decode($trade_list3['data']); $time = $trade_list3['addtime'] + ($trade_list3['type'] * 60); if ($time <= time()) { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $data[4], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 60, 'addtime' => time() ]; M('trade_json')->add($json); } } else { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $market['new_price'], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 60, 'addtime' => time() ]; M('trade_json')->add($json); } if ($trade_list4) { $data = json_decode($trade_list4['data']); $time = $trade_list4['addtime'] + ($trade_list4['type'] * 60); if ($time <= time()) { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $data[4], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 240, 'addtime' => time() ]; M('trade_json')->add($json); } } else { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $market['new_price'], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 240, 'addtime' => time() ]; M('trade_json')->add($json); } if ($trade_list5) { $data = json_decode($trade_list5['data']); $time = $trade_list5['addtime'] + ($trade_list5['type'] * 60); if ($time <= time()) { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $data[4], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 1440, 'addtime' => time() ]; M('trade_json')->add($json); } } else { $json = [ 'market' => $name, 'data' => json_encode([ time() * 1000, $market['new_price'], $market['max_price'], $market['min_price'], $price, $this->randomFloat(0, $market['sdhigh_num']) ]), 'type' => 1440, 'addtime' => time() ]; M('trade_json')->add($json); } } } echo '自动增长'; } function randomFloat($min = 0, $max = 1) { $num = $min + mt_rand() / mt_getrandmax() * ($max - $min); return sprintf("%.4f", $num); //控制小数后几位 } } ?>