OrepoolController.class.php 16 KB

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