Index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 首页接口
  6. */
  7. class Index extends Api
  8. {
  9. protected $noNeedLogin = ['*'];
  10. protected $noNeedRight = ['*'];
  11. public function _initialize()
  12. {
  13. $this->recordModel= new \app\admin\model\greenroom\Record;
  14. $this->adminModel= new \app\admin\model\Admin;
  15. $this->userlinkModel= new \app\admin\model\greenroom\Userlink;
  16. }
  17. /**
  18. * 首页
  19. *
  20. */
  21. public function index()
  22. {
  23. $this->success('请求成功');
  24. }
  25. /**
  26. * 跑链接收益
  27. *
  28. */
  29. public function runrecord()
  30. {
  31. $userlink = db('userlink')
  32. ->join(['fa_link'], 'fa_userlink.link_id = fa_link.id')
  33. ->field(
  34. "fa_link.link as link,
  35. fa_link.id as link_id,
  36. fa_link.minincome as minincome,
  37. fa_link.maxincome as maxincome
  38. ")->group("link_id")->select();
  39. $record=[];
  40. $nowtime =date("Y-m-d h:i:s");
  41. $unixtime=time();
  42. foreach ($userlink as $key=>$val){
  43. $income = mt_rand ($val['minincome']*10000,$val['maxincome']*10000)/10000;
  44. $record[$val['link_id']]=[
  45. 'link'=>$val['link'],
  46. 'time'=>$nowtime,
  47. 'income'=>$income
  48. ];
  49. }
  50. if($record){
  51. $this->recordModel->saveAll($record,true);
  52. }
  53. $where=['incomeendtime'=>['gt',$unixtime]];
  54. $usedata = db('admin')->field("money,id")->where($where)->select();
  55. $buylink = db('userlink')->field("id,uid,link_id,income,dayincome,oldincome")->select();
  56. $addincome=$linkincome=[];
  57. foreach ($buylink as $key=>$val){
  58. $addincome[$val['uid']]=isset($addincome[$val['uid']])?$addincome[$val['uid']]+$record[$val['link_id']]['income']:$record[$val['link_id']]['income'];
  59. $linkincome[$val['uid']][$val['id']]['income']=$val['income']+$record[$val['link_id']]['income'];
  60. $linkincome[$val['uid']][$val['id']]['dayincome']=$val['dayincome']+$record[$val['link_id']]['income'];
  61. }
  62. $upincome=[];
  63. $upuserlink=[];
  64. foreach ($usedata as $k=>$vl){
  65. if(isset($addincome[$vl['id']])){
  66. $upincome[]=['id'=>$vl['id'],
  67. 'money'=>$vl['money']+$addincome[$val['uid']]
  68. ];
  69. }
  70. if(isset($linkincome[$vl['id']])){
  71. foreach ($linkincome[$vl['id']] as $key=>$val){
  72. $upuserlink[$key]=$val;
  73. $upuserlink[$key]['id']=$key;
  74. $upuserlink[$key]['endtime']=$unixtime;
  75. }
  76. }
  77. if($upincome){
  78. $this->adminModel->saveAll($upincome);
  79. $this->userlinkModel->saveAll($upuserlink);
  80. }
  81. }
  82. }
  83. public function oldrecord()
  84. {
  85. $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
  86. $userlink = db('userlink')->select();
  87. $uplink=[];
  88. foreach ($userlink as $key=>$val){
  89. if($val['dayincome']>0){
  90. $uplinktemp=[
  91. 'id'=>$val['id'],
  92. 'dayincome'=>0,
  93. 'oldincome'=>$val['dayincome'],
  94. ];
  95. if($val['endtime']<$beginYesterday){
  96. $uplinktemp['oldincome']=0;
  97. }
  98. $uplink[]= $uplinktemp;
  99. }
  100. }
  101. $this->userlinkModel->saveAll($uplink);
  102. }
  103. }