DreamDJS.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\DreamInfoModel;
  4. use App\Models\SupportDreamModel;
  5. use App\Models\SystemInfoModel;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Auth;
  8. use App\Helper\JpushHelper;
  9. class DreamDJS extends Command
  10. {
  11. use JpushHelper;
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'DreamDJS';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'Command description';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. //执行逻辑
  41. $dream = DreamInfoModel::orderBy('end_time','desc')->get();
  42. foreach ($dream as $item) {
  43. if (date('Y-m-d',$item->end_time) == date('Y-m-d',time()+1*24*3600)) {
  44. $message = $item->name.'过1天就要结束啦!';
  45. $this->jPush($message,'',$item->user_id);
  46. }
  47. if ( date('Y-m-d',time()+7*24*3600)== date('Y-m-d',$item->end_time)) {
  48. $message = $item->name.'过1周就要结束啦!';
  49. $this->jPush($message,'',$item->user_id);
  50. }
  51. if ( $item->end_time < date('Y-n-d H:i:s')) {
  52. $support_dream = SupportDreamModel::where('dream_id',$item->id)->get();
  53. $top = [] ;
  54. foreach ($support_dream as $item2) {
  55. if (!array_key_exists($item2->user_id,$top)) {
  56. $top[$item2->user_id] = $item2->score;
  57. }else{
  58. $top[$item2->user_id] += $item2->score;
  59. }
  60. }
  61. arsort($top);
  62. $new_arr = array_values($top);
  63. $key = array_search($top[$item->user_id],$new_arr);
  64. $message = $item->name."已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
  65. $this->jPush($message,'',$item->user_id);
  66. }
  67. if( isset($message)){
  68. $arr = [
  69. 'user_id'=>0,
  70. 'message'=>$message,
  71. 'to_user_id'=>$item->user_id,
  72. 'dream_id'=>$item->id,
  73. ];
  74. SystemInfoModel::create($arr);
  75. }
  76. }
  77. }
  78. }