Index.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\DayRecord;
  4. use app\admin\model\Record;
  5. use app\common\controller\Api;
  6. use think\Db;
  7. /**
  8. * 首页接口
  9. */
  10. class Index extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. public function _initialize()
  15. {
  16. $this->recordModel= new \app\admin\model\greenroom\Record;
  17. $this->adminModel= new \app\admin\model\Admin;
  18. $this->userlinkModel= new \app\admin\model\greenroom\Userlink;
  19. }
  20. /**
  21. * 首页
  22. *
  23. */
  24. public function index()
  25. {
  26. $this->success('请求成功');
  27. }
  28. //跟新收益
  29. public function upincome(){
  30. $recorddata= $this->recordModel->field('sum(income) as income ,uid as id')->where(['status'=>0])->group('uid')->select();
  31. $temp=$userids=[];
  32. $returndata='1';
  33. if($recorddata){
  34. $returndata='12';
  35. foreach ($recorddata as $key=>$val){
  36. $temp[$val['id']]=$val['income'];
  37. $userids[]=$val['id'];
  38. }
  39. $admindata=db('admin')->where(['id'=>['in',$userids]])->select();
  40. $upincome=[];
  41. foreach ($admindata as $k=>$vl){
  42. if(isset($temp[$vl['id']])){
  43. $upincome[]=['id'=>$vl['id'],'money'=>$vl['money']+$temp[$vl['id']]];
  44. }
  45. }
  46. if($upincome){
  47. $returndata='123';
  48. $this->adminModel->saveAll($upincome);
  49. }
  50. }
  51. return $returndata;
  52. }
  53. /**
  54. * 跑链接收益
  55. *
  56. */
  57. public function runrecord()
  58. {
  59. $nowtime = time();
  60. $spacetime = 10 * 60;
  61. $returndata='';
  62. $userdata = db('admin')->field("id")
  63. ->where(['livetime'=>['gt', $nowtime - $spacetime]])
  64. ->where(['incomeendtime'=>['gt', $nowtime]])
  65. ->select();
  66. if (!$userdata) {
  67. $returndata= 'no data';
  68. } else {
  69. $userids = array_column($userdata, 'id');
  70. $userlink = db('userlink')
  71. ->join(['fa_link'], 'fa_userlink.link_id = fa_link.id')
  72. ->field("fa_link.link as link,
  73. fa_link.id as link_id,
  74. fa_userlink.uid as uid,
  75. fa_link.minincome as minincome,
  76. fa_link.maxincome as maxincome
  77. ")->where(['uid'=>['in', $userids]])->select();
  78. if (!$userlink) {
  79. $returndata='no data1';
  80. } else {
  81. $savedata = [];
  82. foreach ($userlink as $key => $val) {
  83. $savedata[] = ['income' => mt_rand($val['minincome'] * 10000, $val['maxincome'] * 10000) / 10000,
  84. 'time' => $nowtime,
  85. 'link' => $val['link'],
  86. 'uid' => $val['uid'],
  87. 'status' => 0
  88. ];
  89. }
  90. $this->recordModel->saveAll($savedata);
  91. $returndata= 'insert ' . count($savedata) . ' record';
  92. }
  93. }
  94. return $returndata;
  95. }
  96. public function oldrecord()
  97. {
  98. $beginYesterday=mktime(0,0,0,date('m'),date('d') - 1,date('Y'));
  99. $endYesterday = mktime(0,0,0,date('m'),date('d'),date('Y'));
  100. // 统计前面的收益
  101. $total = Record::where('time', ">=", $beginYesterday)
  102. ->where("time", '<', $endYesterday)
  103. ->field('sum(income) as income, count(id) as num,uid as id')
  104. ->group("uid")
  105. ->select();
  106. $date = date("Y-m-d", $beginYesterday);
  107. Db::startTrans();
  108. foreach ($total as $item)
  109. {
  110. DayRecord::create([
  111. "uid" => $item->id,
  112. "addtime" => $date,
  113. "link_num" => $item->num,
  114. "income" => bcmul('1', $item->income, 4)
  115. ]);
  116. }
  117. Record::where('time', ">=", $beginYesterday)
  118. ->where("time", '<', $endYesterday)->delete();
  119. Db::commit();
  120. // $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
  121. // $userlink = db('userlink')->select();
  122. // $uplink=[];
  123. // foreach ($userlink as $key=>$val){
  124. // if($val['dayincome']>0){
  125. // $uplinktemp=[
  126. // 'id'=>$val['id'],
  127. // 'dayincome'=>0,
  128. // 'oldincome'=>$val['dayincome'],
  129. // ];
  130. // if($val['endtime']<$beginYesterday){
  131. // $uplinktemp['oldincome']=0;
  132. // }
  133. // $uplink[]= $uplinktemp;
  134. // }
  135. // }
  136. // $this->userlinkModel->saveAll($uplink);
  137. }
  138. }