DreamDJS.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. $user = Auth::guard('api')->user();
  42. $dream = $user->UserCareDream;
  43. foreach ($dream as $item) {
  44. if (date('Y-m-d',$item->end_time) == date('Y-m-d',time()+1*24*3600)) {
  45. $message = $item->name.'过1天就要结束啦!';
  46. $this->jPush($message,'',$user->id);
  47. }
  48. if ( date('Y-m-d',time()+7*24*3600)== date('Y-m-d',$item->end_time)) {
  49. $message = $item->name.'过1周就要结束啦!';
  50. $this->jPush($message,'',$user->id);
  51. }
  52. if ( $item->end_time < date('Y-n-d H:i:s')) {
  53. $support_dream = SupportDreamModel::where('dream_id',$item->id)->get();
  54. $top = [] ;
  55. foreach ($support_dream as $item2) {
  56. if (!array_key_exists($item2->user_id,$top)) {
  57. $top[$item2->user_id] = $item2->score;
  58. }else{
  59. $top[$item2->user_id] += $item2->score;
  60. }
  61. }
  62. arsort($top);
  63. $new_arr = array_values($top);
  64. $key = array_search($top[$user->id],$new_arr);
  65. $message = $item->name."已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
  66. $this->jPush($message,'',$user->id);
  67. }
  68. if( isset($message)){
  69. $arr = [
  70. 'user_id'=>0,
  71. 'message'=>$message,
  72. 'to_user_id'=>$user->id,
  73. 'dream_id'=>$item->id,
  74. ];
  75. SystemInfoModel::create($arr);
  76. }
  77. }
  78. }
  79. }