OrepoolController.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <?php
  2. namespace Home\Controller;
  3. class OrepoolController extends HomeController
  4. {
  5. protected function _initialize()
  6. {
  7. parent::_initialize(); $allow_action=array("index","kjinfo","kjshare","buydzmining","buygxmining","profitline","profitlist","normalmin","overduemin");
  8. if(!in_array(ACTION_NAME,$allow_action)){
  9. $this->error(L("非法操作"));
  10. }
  11. }
  12. //我的运行中的矿机
  13. public function normalmin(){
  14. $uid = userid();
  15. if($uid <= 0){
  16. $this->redirect('Login/index');
  17. }
  18. $list = M("kjorder")->where(array('uid'=>$uid,'status'=>1))->select();
  19. $this->assign('list',$list);
  20. $this->display();
  21. }
  22. //我的过期的矿机
  23. public function overduemin(){
  24. $uid = userid();
  25. if($uid <= 0){
  26. $this->redirect('Login/index');
  27. }
  28. $where['uid'] = $uid;
  29. $where['status'] = array('neq',1);
  30. $list = M("kjorder")->where($where)->select();
  31. $this->assign('list',$list);
  32. $this->display();
  33. }
  34. //矿机收益列表
  35. public function profitlist(){
  36. $uid = userid();
  37. if($uid <= 0){
  38. $this->redirect('Login/index');
  39. }
  40. $list = M("kjprofit")->where(array('uid'=>$uid))->order("day desc")->limit(50)->select();
  41. $nowtime = date("Y-m-d",time());
  42. foreach($list as $key =>$vo){
  43. if($vo['day'] < $nowtime){
  44. $list[$key]['status'] = 1;
  45. }else{
  46. $list[$key]['status'] = 2;
  47. }
  48. }
  49. $this->assign('list',$list);
  50. $this->display();
  51. }
  52. //矿机收益曲线图
  53. public function profitline(){
  54. $id = trim(I('get.id'));
  55. $uid = userid();
  56. $d_arr = array();
  57. $t_arr = array();
  58. $profitobj = M("kjprofit");
  59. $list = $profitobj->where(array('uid'=>$uid,'kid'=>$id))->order("day asc")->limit(7)->select();
  60. foreach($list as $k=>$v){
  61. foreach($v as $key => $value){
  62. if($key == 'num'){
  63. $d_arr[] = $value;
  64. }
  65. if($key == 'day'){
  66. $t_arr[] = date("m-d",strtotime($value));
  67. }
  68. }
  69. }
  70. $this->assign("d_arr",$d_arr);
  71. $this->assign("t_arr",$t_arr);
  72. $polist = $profitobj->where(array('uid'=>$uid,'kid'=>$id))->order("day desc")->select();
  73. $this->assign('polist',$polist);
  74. $total = $profitobj->where(array('uid'=>$uid,'kid'=>$id))->sum(num);
  75. if($total <= 0){
  76. $total = "0.00";
  77. }
  78. $this->assign("total",$total);
  79. $info = $profitobj->where(array('uid'=>$uid,'kid'=>$id))->find();
  80. $coinname = strtoupper($info['coin']);
  81. $this->assign("coinname",$coinname);
  82. $this->display();
  83. }
  84. //购买共享矿机
  85. public function buygxmining(){
  86. if($_POST){
  87. $st = trim(I('post.st'));
  88. if($st != 8){
  89. $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
  90. }
  91. $uid = userid();
  92. $uinfo = M("user")->where(array('id'=>$uid))->field("id,username,rzstatus,is_tax,taxstatus")->find();
  93. if($uid <= 0 || empty($uinfo)){
  94. $this->ajaxReturn(['code'=>0,'msg'=> L('请先登陆')]);
  95. }
  96. if($uinfo['rzstatus'] != 2){
  97. $this->ajaxReturn(['code'=>0,'msg'=>L('请先完成实名认证')]);
  98. }
  99. //检查该会员是不是需要缴纳税金,如有需要检查有没有缴纳
  100. if($uinfo['is_tax'] == 1){
  101. if($uinfo['taxstatus'] != 1){
  102. $this->ajaxReturn(['code'=>3]);
  103. }
  104. }
  105. $sharbltxt = trim(I('post.sharbltxt'));
  106. if($sharbltxt <= 0 || $sharbltxt == null){
  107. $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
  108. }
  109. $kid = trim(I('post.kid'));
  110. $minfo = M("kuangji")->where(array('id'=>$kid))->find();
  111. if(empty($minfo)){
  112. $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
  113. }
  114. if($minfo['type'] != 2){
  115. $this->ajaxReturn(['code'=>0,'msg'=> L('不是共享矿机')]);
  116. }
  117. $fearr = explode('|',$minfo['sharebl']);
  118. $gxfe = trim(I('post.gxfe'));
  119. if($gxfe != $fearr[0] && $gxfe != $fearr[1]){
  120. $this->ajaxReturn(['code'=>0,'msg'=> L('选择的占比份额不正确')]);
  121. }
  122. $buyinfo = M("kjorder")->where(array('sharbltxt'=>$sharbltxt,'sharebl'=>$gxfe))->find();
  123. if(!empty($buyinfo)){
  124. $this->ajaxReturn(['code'=>0,'msg'=> L('不要重复购买')]);
  125. }
  126. //查矿机状态
  127. if($minfo['status'] != 1){
  128. $this->ajaxReturn(['code'=>0,'msg'=> L('矿机暂停出售')]);
  129. }
  130. if(($minfo['sellnum'] + $minfo['ycnum']) >= $minfo['allnum']){
  131. $this->ajaxReturn(['code'=>0,'msg'=> L('售机已售罄')]);
  132. }
  133. //查看该矿机购买上限
  134. $minecount = M("kjorder")->where(array('kid'=>$kid,'uid'=>$uid,'status'=>1))->count();
  135. if($minecount >= $minfo['buymax']){
  136. $this->ajaxReturn(['code'=>0,'msg'=> L('已达到限购数量')]);
  137. }
  138. //查会员购买资质
  139. $umoney = M("user_coin")->where(array('userid'=>$uid))->find();
  140. $buyask = $minfo['buyask'];
  141. //按持仓平台币数量
  142. if($buyask == 1){
  143. $ptcoin = strtolower(PT_COIN);
  144. $ptcoind = $ptcoin."d";
  145. if(($umoney[$ptcoin] + $umoney[$ptcoind]) < $minfo['asknum']){
  146. $this->ajaxReturn(['code'=>0,'msg'=> L('持有平台币额度不足')]);
  147. }
  148. //按直推人数
  149. }elseif($buyask == 2){
  150. $tzcount = M("user")->where(array('invit_1'=>$uid))->count();
  151. if($tzcount < $minfo['asknum']){
  152. $this->ajaxReturn(['code'=>0,'msg'=> L('直推人数未达要求')]);
  153. }
  154. }
  155. //查会员余额
  156. $pricecoin = $minfo['pricecoin'];
  157. $pricenum = $minfo['pricenum'];
  158. $tprice = $pricenum * $gxfe / 100;
  159. if($umoney[$pricecoin] < $tprice){
  160. $this->ajaxReturn(['code'=>0,'msg'=> L('账户余额不足')]);
  161. }
  162. //建仓矿机订单数据
  163. $odate['kid'] = $minfo['id'];
  164. $odate['type'] = 2;
  165. $odate['sharbltxt'] = $sharbltxt;
  166. $odate['sharebl'] = $gxfe;
  167. $odate['uid'] = $uid;
  168. $odate['username'] = $uinfo['username'];
  169. $odate['kjtitle'] = $minfo['title'];
  170. $odate['imgs'] = $minfo['imgs'];
  171. $odate['status'] = 1;
  172. $odate['cycle'] = $minfo['cycle'];
  173. $odate['synum'] = $minfo['cycle'];
  174. $odate['outtype'] = $minfo['outtype'];
  175. $odate['outcoin'] = $minfo['outcoin'];
  176. if($minfo['outtype'] == 1){//按产值收益
  177. $odate['outnum'] = '';
  178. $odate['outusdt'] = $minfo['dayoutnum'] * $gxfe / 100;
  179. }elseif($minfo['outtype'] == 2){//按币量收益
  180. $odate['outnum'] = $minfo['dayoutnum'] * $gxfe / 100;
  181. $odate['outusdt'] = '';
  182. }
  183. $odate['djout'] = $minfo['djout'];
  184. if($minfo['djout'] == 2){
  185. $odate['djnum'] = $minfo['djday'];
  186. }else{
  187. $odate['djnum'] = $minfo['djday'];
  188. }
  189. $odate['addtime'] = date("Y-m-d H:i:s",time());
  190. $odate['endtime'] = date("Y-m-d H:i:s",(time() + 86400 * $minfo['cycle']));
  191. $odate['intaddtime'] = time();
  192. $odate['intendtime'] = time() + 86400 * $minfo['cycle'];
  193. $adre = M("kjorder")->add($odate);
  194. //扣除会员额度
  195. $decre = M("user_coin")->where(array('userid'=>$uid))->setDec($pricecoin,$tprice);
  196. //写资金日志
  197. $billdata['uid'] = $uid;
  198. $billdata['username'] = $uinfo['username'];
  199. $billdata['num'] = $tprice;
  200. $billdata['coinname'] = $pricecoin;
  201. $billdata['afternum'] = $umoney[$pricecoin] - $tprice;
  202. $billdata['type'] = 5;
  203. $billdata['addtime'] = date("Y-m-d H:i:s",time());
  204. $billdata['st'] = 2;
  205. $billdata['remark'] = L('购买矿机');
  206. $billre = M("bill")->add($billdata);
  207. if($adre && $decre && $billre){
  208. //查看有没有购买奖励
  209. if($minfo['jlnum'] > 0){
  210. $jlcoin = $minfo['jlcoin'];
  211. $jlnum = $minfo['jlnum'] * $gxfe / 100;
  212. M("user_coin")->where(array('userid'=>$uid))->setInc($jlcoin,$jlnum);
  213. $jlbilldata['uid'] = $uid;
  214. $jlbilldata['username'] = $uinfo['username'];
  215. $jlbilldata['num'] = $jlnum;
  216. $jlbilldata['coinname'] = $jlcoin;
  217. $jlbilldata['afternum'] = $umoney[$jlcoin] + $jlnum;
  218. $jlbilldata['type'] = 6;
  219. $jlbilldata['addtime'] = date("Y-m-d H:i:s",time());
  220. $jlbilldata['st'] = 1;
  221. $jlbilldata['remark'] = L('购机奖励');
  222. M("bill")->add($jlbilldata);
  223. M("kuangji")->where(array('id'=>$kid))->setInc('sellnum',1);
  224. }
  225. $this->ajaxReturn(['code'=>1,'msg'=> L('购买成功')]);
  226. }else{
  227. $this->ajaxReturn(['code'=>1,'msg'=> L('购买失败')]);
  228. }
  229. }else{
  230. $this->ajaxReturn(['code'=>0,'msg'=> L('网络错误')]);
  231. }
  232. }
  233. //购买独资矿机
  234. public function buydzmining(){
  235. if($_POST){
  236. $st = trim(I('post.st'));
  237. $kid = trim(I('post.kid'));
  238. if($st != 7){
  239. $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
  240. }
  241. $uid = userid();
  242. $uinfo = M("user")->where(array('id'=>$uid))->field("id,username,rzstatus,is_tax,taxstatus")->find();
  243. if($uid <= 0 || empty($uinfo)){
  244. $this->ajaxReturn(['code'=>0,'msg'=> L('请先登陆')]);
  245. }
  246. if($uinfo['rzstatus'] != 2){
  247. $this->ajaxReturn(['code'=>0,'msg'=>L('请先完成实名认证')]);
  248. }
  249. //检查该会员是不是需要缴纳税金,如有需要检查有没有缴纳
  250. if($uinfo['is_tax'] == 1){
  251. if($uinfo['taxstatus'] != 1){
  252. $this->ajaxReturn(['code'=>3]);
  253. }
  254. }
  255. $minfo = M("kuangji")->where(array('id'=>$kid))->find();
  256. if(empty($minfo)){
  257. $this->ajaxReturn(['code'=>0,'msg'=> L('参数错误')]);
  258. }
  259. //查矿机状态
  260. if($minfo['status'] != 1){
  261. $this->ajaxReturn(['code'=>0,'msg'=> L('矿机暂停出售')]);
  262. }
  263. if(($minfo['sellnum'] + $minfo['ycnum']) >= $minfo['allnum']){
  264. $this->ajaxReturn(['code'=>0,'msg'=> L('售机已售罄')]);
  265. }
  266. //查看该矿机购买上限
  267. $minecount = M("kjorder")->where(array('kid'=>$kid,'uid'=>$uid,'status'=>1))->count();
  268. if($minecount >= $minfo['buymax']){
  269. $this->ajaxReturn(['code'=>0,'msg'=> L('已达到限购数量')]);
  270. }
  271. //查会员购买资质
  272. $umoney = M("user_coin")->where(array('userid'=>$uid))->find();
  273. $buyask = $minfo['buyask'];
  274. //按持仓平台币数量
  275. if($buyask == 1){
  276. $ptcoin = strtolower(PT_COIN);
  277. $ptcoind = $ptcoin."d";
  278. if($umoney[$ptcoin] + $umoney[$ptcoind] < $minfo['asknum']){
  279. $this->ajaxReturn(['code'=>0,'msg'=> L('持有平台币额度不足')]);
  280. }
  281. //按直推人数
  282. }elseif($buyask == 2){
  283. $tzcount = M("user")->where(array('invit_1'=>$uid))->count();
  284. if($tzcount < $minfo['asknum']){
  285. $this->ajaxReturn(['code'=>0,'msg'=> L('直推人数未达要求')]);
  286. }
  287. }
  288. //查会员余额
  289. $pricecoin = $minfo['pricecoin'];
  290. if($umoney[$pricecoin] < $minfo['pricenum']){
  291. $this->ajaxReturn(['code'=>0,'msg'=> L('账户余额不足')]);
  292. }
  293. //建仓矿机订单数据
  294. $odate['kid'] = $minfo['id'];
  295. $odate['type'] = 1;
  296. $odate['sharebl'] = '';
  297. $odate['sharebl'] = '';
  298. $odate['uid'] = $uid;
  299. $odate['username'] = $uinfo['username'];
  300. $odate['kjtitle'] = $minfo['title'];
  301. $odate['imgs'] = $minfo['imgs'];
  302. $odate['status'] = 1;
  303. $odate['cycle'] = $minfo['cycle'];
  304. $odate['synum'] = $minfo['cycle'];
  305. $odate['outtype'] = $minfo['outtype'];
  306. $odate['outcoin'] = $minfo['outcoin'];
  307. if($minfo['outtype'] == 1){//按产值收益
  308. $odate['outnum'] = '';
  309. $odate['outusdt'] = $minfo['dayoutnum'];
  310. }elseif($minfo['outtype'] == 2){//按币量收益
  311. $odate['outnum'] = $minfo['dayoutnum'];
  312. $odate['outusdt'] = '';
  313. }
  314. $odate['djout'] = $minfo['djout'];
  315. if($minfo['djout'] == 2){
  316. $odate['djnum'] = $minfo['djday'];
  317. }else{
  318. $odate['djnum'] = $minfo['djday'];
  319. }
  320. $odate['addtime'] = date("Y-m-d H:i:s",time());
  321. $odate['endtime'] = date("Y-m-d H:i:s",(time() + 86400 * $minfo['cycle']));
  322. $odate['intaddtime'] = time();
  323. $odate['intendtime'] = time() + 86400 * $minfo['cycle'];
  324. $adre = M("kjorder")->add($odate);
  325. //扣除会员额度
  326. $buyprice = $minfo['pricenum']; //单价的币量
  327. $buycoin = $minfo['pricecoin']; //单价的币种
  328. $decre = M("user_coin")->where(array('userid'=>$uid))->setDec($buycoin,$buyprice);
  329. //写资金日志
  330. $billdata['uid'] = $uid;
  331. $billdata['username'] = $uinfo['username'];
  332. $billdata['num'] = $buyprice;
  333. $billdata['coinname'] = $buycoin;
  334. $billdata['afternum'] = $umoney[$buycoin] - $buyprice;
  335. $billdata['type'] = 5;
  336. $billdata['addtime'] = date("Y-m-d H:i:s",time());
  337. $billdata['st'] = 2;
  338. $billdata['remark'] = L('购买矿机');
  339. $billre = M("bill")->add($billdata);
  340. if($adre && $decre && $billre){
  341. //查看有没有购买奖励
  342. if($minfo['jlnum'] > 0){
  343. $jlcoin = $minfo['jlcoin'];
  344. $jlnum = $minfo['jlnum'];
  345. M("user_coin")->where(array('userid'=>$uid))->setInc($jlcoin,$jlnum);
  346. $jlbilldata['uid'] = $uid;
  347. $jlbilldata['username'] = $uinfo['username'];
  348. $jlbilldata['num'] = $jlnum;
  349. $jlbilldata['coinname'] = $jlcoin;
  350. $jlbilldata['afternum'] = $umoney[$jlcoin] + $jlnum;
  351. $jlbilldata['type'] = 6;
  352. $jlbilldata['addtime'] = date("Y-m-d H:i:s",time());
  353. $jlbilldata['st'] = 1;
  354. $jlbilldata['remark'] = L('购机奖励');
  355. M("bill")->add($jlbilldata);
  356. M("kuangji")->where(array('id'=>$kid))->setInc('sellnum',1);
  357. }
  358. $this->ajaxReturn(['code'=>1,'msg'=> L('购买成功')]);
  359. }else{
  360. $this->ajaxReturn(['code'=>1,'msg'=> L('购买失败')]);
  361. }
  362. }else{
  363. $this->ajaxReturn(['code'=>0,'msg'=> L('网络错误')]);
  364. }
  365. }
  366. //共享矿机第二份额度详情页面
  367. public function kjshare(){
  368. $oid = trim(I('get.oid'));
  369. $fe = trim(I('get.fe'));
  370. $sharbltxt = trim(I('get.sharbltxt'));
  371. $info = M("kuangji")->where(array('id'=>$oid))->find();
  372. $this->assign('info',$info);
  373. $kjorder = M("kjorder")->where(array('kid'=>$oid,'type'=>2))->find();
  374. if(!empty($kjorder)){
  375. $bfe = $kjorder['sharebl'];
  376. $fe = 100 - $bfe;
  377. }
  378. $this->assign("fe",$fe);
  379. $this->assign("sharbltxt",$sharbltxt);
  380. $this->display();
  381. }
  382. //矿机详情
  383. public function kjinfo(){
  384. $oid = trim(I('get.id'));
  385. $info = M("kuangji")->where(array('id'=>$oid))->find();
  386. if($info['type'] == 2){
  387. $typearr = explode("|",$info['sharebl']);
  388. $info['fe1'] = $typearr[0];
  389. $info['fe2'] = $typearr[1];
  390. }
  391. $this->assign('info',$info);
  392. $uid = userid();
  393. if($uid <= 0 || $uid == ''){
  394. $uid = 0;
  395. }
  396. $this->assign('uid',$uid);
  397. $this->display();
  398. }
  399. //矿机首页面
  400. public function index(){
  401. //全部
  402. $alist = M("kuangji")->where(array('status'=>1,'rtype'=>1))->order("id asc")->select();
  403. //独资
  404. $blist = M("kuangji")->where(array('status'=>1,'type'=>1,'rtype'=>1))->order("id asc")->select();
  405. //共享
  406. $clist = M("kuangji")->where(array('status'=>1,'type'=>2,'rtype'=>1))->order("id asc")->select();
  407. //我的矿机
  408. $uid = userid();
  409. $mylist = M("kjorder")->where(array('uid'=>$uid))->order('id desc')->select();
  410. $this->assign('mylist',$mylist);
  411. $this->assign('alist',$alist);
  412. $this->assign('blist',$blist);
  413. $this->assign('clist',$clist);
  414. $congif = M("config")->where(array('id'=>1))->field("webkj")->find();
  415. $webkj = $congif['webkj'];
  416. $this->assign('webkj',$webkj);
  417. $this->display();
  418. }
  419. }
  420. ?>