| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Console\Commands;
-
- use App\Models\Settings;
- use App\Models\UserGifts;
- use App\Models\Users;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use App\Api\Util\IM;
- class UpUserGuard extends Command
- {
- use IM;
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'love:UpUserGuard';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '每天凌晨1点系统更新守护';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $top=Settings::where('key','love.user.gift.top')->value('value');
- $min=Settings::where('key','love.min.rose.guard')->value('value');
- //1.更新所有用户
- $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();
- foreach ($list as $k=>$v) {//15天内收到礼物的用户
- //更新收礼物用户的守护
- $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();
- if($one&&$one->rose>$min) {
- Users::where('id',$v->to_uid)->update(['keep_from_uid'=>$one->uid]);
- $info = Cache::rememberForever('My'.$one->uid,function() use ($one){
- return Users::where('id',$one->uid)->first();
- });
- $this->portrait_set($one->uid,['Tag'=>'Tag_Profile_IM_SelfSignature','Value'=>$info->name]);
- Cache::forget('My'.$one->uid);
- }else{
- Users::where('id',$v->to_uid)->update(['keep_from_uid'=>0]);
- $this->portrait_set($one->uid,['Tag'=>'Tag_Profile_IM_SelfSignature','Value'=>'']);
- Cache::forget('My'.$one->uid);
- }
- Cache::forget('UserTop'.$v->to_uid);
- }
- }
- }
|