runrecord.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\admin\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. class runrecord extends Command
  7. {
  8. protected $model = null;
  9. protected function configure()
  10. {
  11. $this
  12. ->setName('runrecord')
  13. ->addArgument('action',Argument::OPTIONAL,'run action')
  14. ->setDescription('命令行执行定时任务'); //运行 "php think list" 时的简短描述
  15. }
  16. protected function execute(Input $input, Output $output)
  17. {
  18. $this->recordModel= new \app\admin\model\greenroom\Record;
  19. $nowtime = time();
  20. $spacetime = 10 * 60;
  21. $action= $input->getArgument('action');
  22. switch ($action){
  23. case "upincome"://更新用户收益
  24. while (true) {
  25. $recorddata= $this->recordModel->field('sum(income) as income ,uid as id')->where(['status'=>0])->group('uid')->select();
  26. $temp=$userids=[];
  27. $returndata='1';
  28. if($recorddata){
  29. $returndata='12';
  30. foreach ($recorddata as $key=>$val){
  31. $temp[$val['id']]=$val['income'];
  32. $userids[]=$val['id'];
  33. }
  34. $admindata=db('fa_admin')->where(['id'=>['in',$userids]])->select();
  35. $upincome=[];
  36. foreach ($admindata as $k=>$vl){
  37. if(isset($temp[$vl['id']])){
  38. $upincome[]=['id'=>$vl['id'],'money'=>$vl['money']+$temp[$vl['id']]];
  39. }
  40. }
  41. if($upincome){
  42. $returndata='123';
  43. $this->adminModel->saveAll($upincome);
  44. }
  45. }
  46. $output->writeln($returndata);
  47. sleep(600);
  48. }
  49. break;
  50. case "runrecord"://记录广告收益
  51. while (true) {
  52. $returndata='';
  53. $userdata = db('fa_admin')->field("id")
  54. ->where(['livetime', 'gt', $nowtime - $spacetime])
  55. ->where(['incomeendtime', 'gt', $nowtime])
  56. ->select();
  57. if (!$userdata) {
  58. $returndata= 'no data';
  59. } else {
  60. $userids = array_column($userdata, 'id');
  61. $userlink = db('userlink')
  62. ->join(['fa_link'], 'fa_userlink.link_id = fa_link.id')
  63. ->field("fa_link.link as link,
  64. fa_link.id as link_id,
  65. fa_link.minincome as minincome,
  66. fa_link.maxincome as maxincome
  67. ")->where(['uid'=>['in', $userids]])->select();
  68. if (!$userlink) {
  69. $returndata='no data1';
  70. } else {
  71. $savedata = [];
  72. foreach ($userlink as $key => $val) {
  73. $savedata[] = ['income' => mt_rand($val['minincome'] * 10000, $val['maxincome'] * 10000) / 10000,
  74. 'time' => $nowtime,
  75. 'link' => $val['link'],
  76. 'uid' => $val['uid'],
  77. 'status' => 0
  78. ];
  79. }
  80. $this->recordModel->saveAll($savedata);
  81. $returndata= 'insert ' . count($savedata) . ' record';
  82. }
  83. }
  84. $output->writeln($returndata);
  85. sleep(60);
  86. }
  87. break;
  88. }
  89. }
  90. }