123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- <?php
- namespace Mobile\Controller;
- class OrepoolController extends MobileController
- {
- protected function _initialize()
- {
- parent::_initialize(); $allow_action=array("index","kjinfo","kjshare","buydzmining","buygxmining","profitline","profitlist");
- if(!in_array(ACTION_NAME,$allow_action)){
- $this->error(L("非法操作"));
- }
-
- }
-
- //矿机收益列表
- public function profitlist(){
- $uid = userid();
- if($uid <= 0){
- $this->redirect('Login/index');
- }
- $list = M("kjprofit")->where(array('uid'=>$uid))->order("day desc")->limit(50)->select();
- $this->assign('list',$list);
- $this->display();
- }
-
- //矿机收益曲线图
- public function profitline(){
- $id = trim(I('get.id'));
- $uid = userid();
- $d_arr = array();
- $t_arr = array();
- $profitobj = M("kjprofit");
- $list = $profitobj->where(array('uid'=>$uid,'kid'=>$id))->order("day asc")->limit(7)->select();
- foreach($list as $k=>$v){
- foreach($v as $key => $value){
- if($key == 'num'){
- $d_arr[] = $value;
- }
- if($key == 'day'){
- $t_arr[] = date("m-d",strtotime($value));
-
- }
- }
- }
- $this->assign("d_arr",$d_arr);
- $this->assign("t_arr",$t_arr);
- $polist = $profitobj->where(array('uid'=>$uid,'kid'=>$id))->order("day desc")->select();
- $this->assign('polist',$polist);
-
- $total = $profitobj->where(array('uid'=>$uid,'kid'=>$id))->sum(num);
- if($total <= 0){
- $total = "0.00";
- }
- $this->assign("total",$total);
- $info = $profitobj->where(array('uid'=>$uid,'kid'=>$id))->find();
- $coinname = strtoupper($info['coin']);
- $this->assign("coinname",$coinname);
- $this->display();
- }
-
- //购买共享矿机
- public function buygxmining(){
- if($_POST){
- $st = trim(I('post.st'));
- if($st != 8){
- $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
- }
- $uid = userid();
- $uinfo = M("user")->where(array('id'=>$uid))->field("id,username,rzstatus,is_tax,taxstatus")->find();
- if($uid <= 0 || empty($uinfo)){
- $this->ajaxReturn(['code'=>0,'msg'=> L('请先登陆')]);
- }
-
- if($uinfo['rzstatus'] != 2){
- $this->ajaxReturn(['code'=>0,'msg'=>L('请先完成实名认证')]);
- }
-
- //检查该会员是不是需要缴纳税金,如有需要检查有没有缴纳
- if($uinfo['is_tax'] == 1){
- if($uinfo['taxstatus'] != 1){
- $this->ajaxReturn(['code'=>3]);
- }
- }
-
- $sharbltxt = trim(I('post.sharbltxt'));
- if($sharbltxt <= 0 || $sharbltxt == null){
- $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
- }
-
-
-
-
- $kid = trim(I('post.kid'));
- $minfo = M("kuangji")->where(array('id'=>$kid))->find();
- if(empty($minfo)){
- $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
- }
- if($minfo['type'] != 2){
- $this->ajaxReturn(['code'=>0,'msg'=> L('不是共享矿机')]);
- }
- $fearr = explode('|',$minfo['sharebl']);
-
- $gxfe = trim(I('post.gxfe'));
- if($gxfe != $fearr[0] && $gxfe != $fearr[1]){
- $this->ajaxReturn(['code'=>0,'msg'=> L('选择的占比份额不正确')]);
- }
-
- $buyinfo = M("kjorder")->where(array('sharbltxt'=>$sharbltxt,'sharebl'=>$gxfe))->find();
- if(!empty($buyinfo)){
- $this->ajaxReturn(['code'=>0,'msg'=> L('不要重复购买')]);
- }
- //查矿机状态
- if($minfo['status'] != 1){
- $this->ajaxReturn(['code'=>0,'msg'=> L('矿机暂停出售')]);
- }
- if(($minfo['sellnum'] + $minfo['ycnum']) >= $minfo['allnum']){
- $this->ajaxReturn(['code'=>0,'msg'=> L('售机已售罄')]);
- }
-
- //查看该矿机购买上限
- $minecount = M("kjorder")->where(array('kid'=>$kid,'uid'=>$uid,'status'=>1))->count();
- if($minecount >= $minfo['buymax']){
- $this->ajaxReturn(['code'=>0,'msg'=> L('已达到限购数量')]);
- }
-
- //查会员购买资质
- $umoney = M("user_coin")->where(array('userid'=>$uid))->find();
- $buyask = $minfo['buyask'];
-
- //按持仓平台币数量
- if($buyask == 1){
- $ptcoin = strtolower(PT_COIN);
- $ptcoind = $ptcoin."d";
- if(($umoney[$ptcoin] + $umoney[$ptcoind]) < $minfo['asknum']){
- $this->ajaxReturn(['code'=>0,'msg'=> L('持有平台币额度不足')]);
- }
- //按直推人数
- }elseif($buyask == 2){
- $tzcount = M("user")->where(array('invit_1'=>$uid))->count();
- if($tzcount < $minfo['asknum']){
- $this->ajaxReturn(['code'=>0,'msg'=> L('直推人数未达要求')]);
- }
- }
- //查会员余额
- $pricecoin = $minfo['pricecoin'];
- $pricenum = $minfo['pricenum'];
- $tprice = $pricenum * $gxfe / 100;
- if($umoney[$pricecoin] < $tprice){
- $this->ajaxReturn(['code'=>0,'msg'=> L('账户余额不足')]);
- }
-
-
-
- //建仓矿机订单数据
- $odate['kid'] = $minfo['id'];
- $odate['type'] = 2;
- $odate['sharbltxt'] = $sharbltxt;
- $odate['sharebl'] = $gxfe;
- $odate['uid'] = $uid;
- $odate['username'] = $uinfo['username'];
- $odate['kjtitle'] = $minfo['title'];
- $odate['imgs'] = $minfo['imgs'];
- $odate['status'] = 1;
- $odate['cycle'] = $minfo['cycle'];
- $odate['synum'] = $minfo['cycle'];
- $odate['outtype'] = $minfo['outtype'];
- $odate['outcoin'] = $minfo['outcoin'];
- if($minfo['outtype'] == 1){//按产值收益
- $odate['outnum'] = '';
- $odate['outusdt'] = $minfo['dayoutnum'] * $gxfe / 100;
- }elseif($minfo['outtype'] == 2){//按币量收益
- $odate['outnum'] = $minfo['dayoutnum'] * $gxfe / 100;
- $odate['outusdt'] = '';
- }
- $odate['djout'] = $minfo['djout'];
- if($minfo['djout'] == 2){
- $odate['djnum'] = $minfo['djday'];
- }else{
- $odate['djnum'] = $minfo['djday'];
- }
- $odate['addtime'] = date("Y-m-d H:i:s",time());
- $odate['endtime'] = date("Y-m-d H:i:s",(time() + 86400 * $minfo['cycle']));
- $odate['intaddtime'] = time();
- $odate['intendtime'] = time() + 86400 * $minfo['cycle'];
- $adre = M("kjorder")->add($odate);
-
- //扣除会员额度
- $decre = M("user_coin")->where(array('userid'=>$uid))->setDec($pricecoin,$tprice);
-
- //写资金日志
- $billdata['uid'] = $uid;
- $billdata['username'] = $uinfo['username'];
- $billdata['num'] = $tprice;
- $billdata['coinname'] = $pricecoin;
- $billdata['afternum'] = $umoney[$pricecoin] - $tprice;
- $billdata['type'] = 5;
- $billdata['addtime'] = date("Y-m-d H:i:s",time());
- $billdata['st'] = 2;
- $billdata['remark'] = L('购买矿机');
- $billre = M("bill")->add($billdata);
-
- if($adre && $decre && $billre){
- //查看有没有购买奖励
- if($minfo['jlnum'] > 0){
- $jlcoin = $minfo['jlcoin'];
- $jlnum = $minfo['jlnum'] * $gxfe / 100;
- M("user_coin")->where(array('userid'=>$uid))->setInc($jlcoin,$jlnum);
- $jlbilldata['uid'] = $uid;
- $jlbilldata['username'] = $uinfo['username'];
- $jlbilldata['num'] = $jlnum;
- $jlbilldata['coinname'] = $jlcoin;
- $jlbilldata['afternum'] = $umoney[$jlcoin] + $jlnum;
- $jlbilldata['type'] = 6;
- $jlbilldata['addtime'] = date("Y-m-d H:i:s",time());
- $jlbilldata['st'] = 1;
- $jlbilldata['remark'] = L('购机奖励');
- M("bill")->add($jlbilldata);
-
- M("kuangji")->where(array('id'=>$kid))->setInc('sellnum',1);
- }
- $this->ajaxReturn(['code'=>1,'msg'=> L('购买成功')]);
- }else{
- $this->ajaxReturn(['code'=>1,'msg'=> L('购买失败')]);
- }
-
- }else{
- $this->ajaxReturn(['code'=>0,'msg'=> L('网络错误')]);
- }
- }
-
- //购买独资矿机
- public function buydzmining(){
- if($_POST){
- $ordernum = trim(I('post.ordernum'));
- $st = trim(I('post.st'));
- $kid = trim(I('post.kid'));
- if($st != 7){
- $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
- }
- $uid = userid();
- $uinfo = M("user")->where(array('id'=>$uid))->field("id,username,rzstatus,is_tax,taxstatus")->find();
- if($uid <= 0 || empty($uinfo)){
- $this->ajaxReturn(['code'=>0,'msg'=> L('请先登陆')]);
- }
-
- if($uinfo['rzstatus'] != 2){
- $this->ajaxReturn(['code'=>0,'msg'=>L('请先完成实名认证')]);
- }
-
- //检查该会员是不是需要缴纳税金,如有需要检查有没有缴纳
- if($uinfo['is_tax'] == 1){
- if($uinfo['taxstatus'] != 1){
- $this->ajaxReturn(['code'=>3]);
- }
- }
-
-
- $minfo = M("kuangji")->where(array('id'=>$kid))->find();
- if(empty($minfo)){
- $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
- }
-
- //查矿机状态
- if($minfo['status'] != 1){
- $this->ajaxReturn(['code'=>0,'msg'=> L('矿机暂停出售')]);
- }
- if(($minfo['sellnum'] + $minfo['ycnum']) >= $minfo['allnum']){
- $this->ajaxReturn(['code'=>0,'msg'=> L('售机已售罄')]);
- }
-
-
- //查看该矿机购买上限
- $minecount = M("kjorder")->where(array('kid'=>$kid,'uid'=>$uid,'status'=>1))->count();
- if($minecount >= $minfo['buymax']){
- $this->ajaxReturn(['code'=>0,'msg'=> L('已达到限购数量')]);
- }
-
-
-
- //查会员购买资质
- $umoney = M("user_coin")->where(array('userid'=>$uid))->find();
- $buyask = $minfo['buyask'];
-
- //按持仓平台币数量
- if($buyask == 1){
- $ptcoin = strtolower(PT_COIN);
- $ptcoind = $ptcoin."d";
- if(($umoney[$ptcoin] + $umoney[$ptcoind]) < $minfo['asknum']){
- $this->ajaxReturn(['code'=>0,'msg'=> L('持有平台币额度不足')]);
- }
-
- //按直推人数
- }elseif($buyask == 2){
- $tzcount = M("user")->where(array('invit_1'=>$uid))->count();
- if($tzcount < $minfo['asknum']){
- $this->ajaxReturn(['code'=>0,'msg'=> L('直推人数未达要求')]);
- }
- }
-
-
- //查会员余额
- $pricecoin = $minfo['pricecoin'];
-
- if($umoney[$pricecoin] < $ordernum){
- $this->ajaxReturn(['code'=>0,'msg'=> L('账户余额不足')]);
- }
-
-
- //建仓矿机订单数据
- $odate['kid'] = $minfo['id'];
- $odate['type'] = 1;
- $odate['sharebl'] = '';
- $odate['uid'] = $uid;
- $odate['username'] = $uinfo['username'];
- $odate['kjtitle'] = $minfo['title'];
- $odate['imgs'] = $minfo['imgs'];
- $odate['status'] = 1;
- $odate['cycle'] = $minfo['cycle'];
- $odate['synum'] = $minfo['cycle'];
- $odate['outtype'] = $minfo['outtype'];
- $odate['outcoin'] = $minfo['outcoin'];
- if($minfo['outtype'] == 1){//按产值收益
- $odate['outnum'] = '';
- $odate['outusdt'] = $ordernum / $minfo['pricenum'] * $minfo['dayoutnum'];
- }elseif($minfo['outtype'] == 2){//按币量收益
- $odate['outnum'] = $ordernum / $minfo['pricenum'] * $minfo['dayoutnum'];
- $odate['outusdt'] = '';
- }
- $odate['djout'] = $minfo['djout'];
- if($minfo['djout'] == 2){
- $odate['djnum'] = $minfo['djday'];
- }else{
- $odate['djnum'] = $minfo['djday'];
- }
- $odate['addtime'] = date("Y-m-d H:i:s",time());
- $odate['endtime'] = date("Y-m-d H:i:s",(time() + 86400 * $minfo['cycle']));
- $odate['intaddtime'] = time();
- $odate['intendtime'] = time() + 86400 * $minfo['cycle'];
- $odate['ordernum'] = $ordernum;
- $adre = M("kjorder")->add($odate);
-
- //扣除会员额度
- $buyprice = $minfo['pricenum']; //单价的币量
- $buycoin = $minfo['pricecoin']; //单价的币种
- $decre = M("user_coin")->where(array('userid'=>$uid))->setDec($buycoin,$ordernum);
- //写资金日志
- $billdata['uid'] = $uid;
- $billdata['username'] = $uinfo['username'];
- $billdata['num'] = $ordernum;
- $billdata['coinname'] = $buycoin;
- $billdata['afternum'] = $umoney[$buycoin] - $buyprice;
- $billdata['type'] = 5;
- $billdata['addtime'] = date("Y-m-d H:i:s",time());
- $billdata['st'] = 2;
- $billdata['remark'] = L('购买矿机');
- $billre = M("bill")->add($billdata);
- if($adre && $decre && $billre){
-
- //查看有没有购买奖励
- if($minfo['jlnum'] > 0){
- $jlcoin = $minfo['jlcoin'];
- $jlnum = $minfo['jlnum'];
-
- M("user_coin")->where(array('userid'=>$uid))->setInc($jlcoin,$jlnum);
- $jlbilldata['uid'] = $uid;
- $jlbilldata['username'] = $uinfo['username'];
- $jlbilldata['num'] = $ordernum;
- $jlbilldata['coinname'] = $jlcoin;
- $jlbilldata['afternum'] = $umoney[$jlcoin] + $jlnum;
- $jlbilldata['type'] = 6;
- $jlbilldata['addtime'] = date("Y-m-d H:i:s",time());
- $jlbilldata['st'] = 1;
- $jlbilldata['remark'] = L('购机奖励');
- M("bill")->add($jlbilldata);
-
- M("kuangji")->where(array('id'=>$kid))->setInc('sellnum',1);
-
- }
- $this->ajaxReturn(['code'=>1,'msg'=> L('购买成功')]);
- }else{
- $this->ajaxReturn(['code'=>1,'msg'=> L('购买失败')]);
- }
-
- }else{
- $this->ajaxReturn(['code'=>0,'msg'=> L('网络错误')]);
- }
- }
-
-
- //共享矿机第二份额度详情页面
- public function kjshare(){
- $oid = trim(I('get.oid'));
- $fe = trim(I('get.fe'));
- $sharbltxt = trim(I('get.sharbltxt'));
- $info = M("kuangji")->where(array('id'=>$oid))->find();
- $this->assign('info',$info);
-
- $kjorder = M("kjorder")->where(array('kid'=>$oid,'type'=>2))->find();
- if(!empty($kjorder)){
- $bfe = $kjorder['sharebl'];
- $fe = 100 - $bfe;
- }
- $this->assign("fe",$fe);
- $this->assign("sharbltxt",$sharbltxt);
- $this->display();
- }
-
- //矿机详情
- public function kjinfo(){
- $oid = trim(I('get.oid'));
- $info = M("kuangji")->where(array('id'=>$oid))->find();
- if($info['type'] == 2){
- $typearr = explode("|",$info['sharebl']);
- $info['fe1'] = $typearr[0];
- $info['fe2'] = $typearr[1];
- }
- $this->assign('info',$info);
-
- $uid = userid();
- if($uid <= 0 || $uid == ''){
- $uid = 0;
- }
- $this->assign('uid',$uid);
-
- $this->display();
- }
- //矿机首页面
- public function index(){
- //全部
- $alist = M("kuangji")->where(array('status'=>1,'rtype'=>1))->order("id asc")->select();
- //独资
- $blist = M("kuangji")->where(array('status'=>1,'type'=>1,'rtype'=>1))->order("id asc")->select();
- //共享
- $clist = M("kuangji")->where(array('status'=>1,'type'=>2,'rtype'=>1))->order("id asc")->select();
-
- //我的矿机
- $uid = userid();
- $mylist = M("kjorder")->where(array('uid'=>$uid))->order('id desc')->select();
- $num = 0;
- foreach ($mylist as $k =>$v){
- $num += $v['ordernum'];
- }
- $nums = round($num,2);
- $this->assign('num',$nums);
- $this->assign('mylist',$mylist);
- $this->assign('alist',$alist);
- $this->assign('blist',$blist);
- $this->assign('clist',$clist);
-
- $congif = M("config")->where(array('id'=>1))->field("webkj")->find();
- $webkj = $congif['webkj'];
- $this->assign('webkj',$webkj);
- $this->display();
- }
-
- }
- ?>
|