12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?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()
- {
- //执行逻辑
- $user = Auth::guard('api')->user();
- $dream = $user->UserCareDream;
- 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,'',$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,'',$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[$user->id],$new_arr);
- $message = $item->name."已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
- $this->jPush($message,'',$user->id);
- }
- if( isset($message)){
- $arr = [
- 'user_id'=>0,
- 'message'=>$message,
- 'to_user_id'=>$user->id,
- 'dream_id'=>$item->id,
- ];
- SystemInfoModel::create($arr);
- }
- }
- }
- }
|