Index.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. $maxId = $this->recordModel->max('id');
  31. $recorddata= $this->recordModel
  32. ->field('sum(income) as income ,uid as id')
  33. ->where("id", "<=", $maxId)
  34. ->where(['status'=>0])
  35. ->group('uid')
  36. ->select();
  37. $temp=$userids=[];
  38. $returndata='1';
  39. Db::startTrans();
  40. if($recorddata){
  41. $returndata='12';
  42. foreach ($recorddata as $key=>$val){
  43. $temp[$val['id']]=$val['income'];
  44. $userids[]=$val['id'];
  45. }
  46. $admindata=db('admin')->where(['id'=>['in',$userids]])->select();
  47. $upincome=[];
  48. foreach ($admindata as $k=>$vl){
  49. if(isset($temp[$vl['id']])){
  50. $upincome[]=['id'=>$vl['id'],'money'=>$vl['money']+$temp[$vl['id']]];
  51. }
  52. }
  53. if($upincome){
  54. $returndata='123';
  55. $this->adminModel->saveAll($upincome);
  56. $this->recordModel->where("id", "<=", $maxId)->where(['status'=>0])->update(['status'=>1]);
  57. }
  58. }
  59. Db::commit();
  60. return $returndata;
  61. }
  62. /**
  63. * 跑链接收益
  64. *
  65. */
  66. public function runrecord()
  67. {
  68. $nowtime = time();
  69. $spacetime = 10 * 60;
  70. $returndata='';
  71. $userdata = db('admin')->field("id")
  72. ->where(['livetime'=>['gt', $nowtime - $spacetime]])
  73. ->where(['incomeendtime'=>['gt', $nowtime]])
  74. ->select();
  75. Db::startTrans();
  76. if (!$userdata) {
  77. $returndata= 'no data';
  78. } else {
  79. // Db::startTrans();
  80. $userids = array_column($userdata, 'id');
  81. $userlink = db('userlink')
  82. ->join(['fa_link'], 'fa_userlink.link_id = fa_link.id')
  83. ->field("fa_link.link as link,
  84. fa_link.id as link_id,
  85. fa_userlink.uid as uid,
  86. fa_userlink.id as userlinkid,
  87. fa_userlink.income as income,
  88. fa_link.minincome as minincome,
  89. fa_link.maxincome as maxincome
  90. ")->where(['uid'=>['in', $userids]])->select();
  91. if (!$userlink) {
  92. $returndata='no data1';
  93. } else {
  94. $savedata =$userlinkdata= [];
  95. foreach ($userlink as $key => $val) {
  96. $income=mt_rand($val['minincome'] * 10000, $val['maxincome'] * 10000) / 10000;
  97. $savedata[] = ['income' => $income,
  98. 'time' => $nowtime,
  99. 'link' => $val['link'],
  100. 'uid' => $val['uid'],
  101. 'status' => 0
  102. ];
  103. $userlinkdata[]=['id'=>$val['userlinkid'],'income'=>$val['income']+$income];
  104. }
  105. print_r($userlinkdata);
  106. print_r($savedata);
  107. // $this->userlinkModel->saveAll($userlinkdata);
  108. // $this->recordModel->saveAll($savedata);
  109. $returndata= 'insert ' . count($savedata) . ' record';
  110. }
  111. // Db::commit();
  112. }
  113. return $returndata;
  114. }
  115. public function oldrecord()
  116. {
  117. $beginYesterday=mktime(0,0,0,date('m'),date('d') - 1,date('Y'));
  118. $endYesterday = mktime(0,0,0,date('m'),date('d'),date('Y'));
  119. // 统计前面的收益
  120. $total = Record::where('time', ">=", $beginYesterday)
  121. ->where("time", '<', $endYesterday)
  122. ->field('sum(income) as income, count(id) as num,uid as id')
  123. ->group("uid")
  124. ->select();
  125. $date = date("Y-m-d", $beginYesterday);
  126. Db::startTrans();
  127. foreach ($total as $item)
  128. {
  129. DayRecord::create([
  130. "uid" => $item->id,
  131. "addtime" => $date,
  132. "link_num" => $item->num,
  133. "income" => bcmul('1', $item->income, 4)
  134. ]);
  135. }
  136. Record::where('time', ">=", $beginYesterday)
  137. ->where("time", '<', $endYesterday)
  138. ->where('status', 1)
  139. ->delete();
  140. Db::commit();
  141. // $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
  142. // $userlink = db('userlink')->select();
  143. // $uplink=[];
  144. // foreach ($userlink as $key=>$val){
  145. // if($val['dayincome']>0){
  146. // $uplinktemp=[
  147. // 'id'=>$val['id'],
  148. // 'dayincome'=>0,
  149. // 'oldincome'=>$val['dayincome'],
  150. // ];
  151. // if($val['endtime']<$beginYesterday){
  152. // $uplinktemp['oldincome']=0;
  153. // }
  154. // $uplink[]= $uplinktemp;
  155. // }
  156. // }
  157. // $this->userlinkModel->saveAll($uplink);
  158. }
  159. }