UpUserGuard.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Settings;
  4. use App\Models\UserGifts;
  5. use App\Models\Users;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Cache;
  8. use Illuminate\Support\Facades\DB;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. use App\Api\Util\IM;
  12. class UpUserGuard extends Command
  13. {
  14. use IM;
  15. /**
  16. * The name and signature of the console command.
  17. *
  18. * @var string
  19. */
  20. protected $signature = 'love:UpUserGuard';
  21. /**
  22. * The console command description.
  23. *
  24. * @var string
  25. */
  26. protected $description = '每天凌晨1点系统更新守护';
  27. /**
  28. * Create a new command instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. parent::__construct();
  35. }
  36. /**
  37. * Execute the console command.
  38. *
  39. * @return mixed
  40. */
  41. public function handle()
  42. {
  43. $top=Settings::where('key','love.user.gift.top')->value('value');
  44. $min=Settings::where('key','love.min.rose.guard')->value('value');
  45. //1.更新所有用户
  46. $list=UserGifts::select('to_uid')->groupBy('to_uid')->whereDate('created_at','>',date('Y-m-d',strtotime("-{$top} day")))->whereDate('created_at','<=',date('Y-m-d'))->get();
  47. foreach ($list as $k=>$v) {//15天内收到礼物的用户
  48. //更新收礼物用户的守护
  49. $one=UserGifts::select('uid',DB::raw('SUM(rose) as rose'))->where('to_uid',$v->to_uid)->whereDate('created_at','>',date('Y-m-d',strtotime("-{$top} day")))->whereDate('created_at','<=',date('Y-m-d'))->groupBy('uid')->orderBy(DB::raw('SUM(rose) as rose'),'desc')->first();
  50. if($one&&$one->rose>$min) {
  51. Users::where('id',$v->to_uid)->update(['keep_from_uid'=>$one->uid]);
  52. $info = Cache::rememberForever('My'.$one->uid,function() use ($one){
  53. return Users::where('id',$one->uid)->first();
  54. });
  55. $this->portrait_set($one->uid,['Tag'=>'Tag_Profile_IM_SelfSignature','Value'=>$info->name]);
  56. Cache::forget('My'.$one->uid);
  57. }else{
  58. Users::where('id',$v->to_uid)->update(['keep_from_uid'=>0]);
  59. $this->portrait_set($one->uid,['Tag'=>'Tag_Profile_IM_SelfSignature','Value'=>'']);
  60. Cache::forget('My'.$one->uid);
  61. }
  62. Cache::forget('UserTop'.$v->to_uid);
  63. }
  64. }
  65. }