123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Console\Commands;
- use App\Models\DreamInfoModel;
- use App\Models\SupportDreamModel;
- use App\Models\SystemInfoModel;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Auth;
- use App\Helper\JpushHelper;
- class DreamDJS extends Command
- {
- use JpushHelper;
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'DreamDJS';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- //执行逻辑
- $dream = DreamInfoModel::orderBy('end_time','desc')->get();
- foreach ($dream as $item) {
- if (date('Y-m-d',$item->end_time) == date('Y-m-d',time()+1*24*3600)) {
- $message = $item->name.'过1天就要结束啦!';
- $this->jPush($message,'',$item->user_id);
- }
- if ( date('Y-m-d',time()+7*24*3600)== date('Y-m-d',$item->end_time)) {
- $message = $item->name.'过1周就要结束啦!';
- $this->jPush($message,'',$item->user_id);
- }
- if ( $item->end_time < date('Y-n-d H:i:s')) {
- $support_dream = SupportDreamModel::where('dream_id',$item->id)->get();
- $top = [] ;
- foreach ($support_dream as $item2) {
- if (!array_key_exists($item2->user_id,$top)) {
- $top[$item2->user_id] = $item2->score;
- }else{
- $top[$item2->user_id] += $item2->score;
- }
- }
- arsort($top);
- $new_arr = array_values($top);
- $key = array_search($top[$item->user_id],$new_arr);
- $message = $item->name."已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
- $this->jPush($message,'',$item->user_id);
- }
- if( isset($message)){
- $arr = [
- 'user_id'=>0,
- 'message'=>$message,
- 'to_user_id'=>$item->user_id,
- 'dream_id'=>$item->id,
- ];
- SystemInfoModel::create($arr);
- }
- }
- }
- }
|