123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <?php
- namespace App\Console;
- use App\Console\Commands\IntegralCommand;
- use App\Console\Commands\MakeHonorWallCommand;
- use App\Console\Commands\MakeNumOneLevelCommand;
- use App\Console\Commands\MakePKListCommand;
- use App\Console\Commands\MakeTopHundredCommand;
- use App\Console\Commands\SendMessageCourseCommand;
- use App\Jobs\SendMessageFive;
- use App\Jobs\SendMessageFour;
- use App\Jobs\SendMessageOne;
- use App\Jobs\SendMessageThree;
- use App\Jobs\SendMessageTwo;
- use App\Models\Basic;
- use App\Models\DwbsUser;
- use App\Models\Enroll;
- use App\Models\Glory;
- use App\Models\Intelog;
- use App\Models\InteReview;
- use App\Models\User;
- use GuzzleHttp\Client;
- use Illuminate\Console\Scheduling\Schedule;
- use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Str;
- use Intervention\Image\Facades\Image;
- class Kernel extends ConsoleKernel
- {
- /**
- * The Artisan commands provided by your application.
- *
- * @var array
- */
- protected $commands = [
- //
- ];
- /**
- * Define the application's command schedule.
- *
- * @param \Illuminate\Console\Scheduling\Schedule $schedule
- * @return void
- */
- protected function schedule(Schedule $schedule)
- {
- // $schedule->call(function (){
- // $enroll=Enroll::where('season',33)->where('status',0)->pluck('uid');
- // $ids=User::whereIn('id',$enroll)->pluck('dwbs_id');
- // $all=DwbsUser::whereIn('id',$ids)->get();
- // foreach ($all as $k=>$v){
- // User::where('dwbs_id',$v->id)->update(['avatar'=>$v->headimgurl]);
- // }
- // Log::error('结束数叔叔苏');
- // })->dailyAt('16:52');
- $schedule->call(function (){
- // Log::error('kaishi ');
- // $id=Enroll::where('season',35)->where('status',0)->pluck('uid')->toArray();
- // $ida=Enroll::where('season',36)->where('status',0)->pluck('uid')->toArray();
- // $idb=Enroll::where('season',37)->where('status',0)->pluck('uid')->toArray();
- //
- // $arr=array_intersect($id,$ida,$idb);
- //
- // $idA=Intelog::where('season',35)->whereIn('uid',$arr)
- // ->select(DB::raw('SUM(integral) as inte'),'uid')
- // ->GroupBy('uid')->Having('inte','<',200)->pluck('uid')->toArray();
- // $idB=Intelog::where('season',36)->whereIn('uid',$arr)
- // ->select(DB::raw('SUM(integral) as inte'),'uid')
- // ->GroupBy('uid')->Having('inte','<',200)->pluck('uid')->toArray();
- // $idC=Intelog::where('season',37)->whereIn('uid',$arr)
- // ->select(DB::raw('SUM(integral) as inte'),'uid')
- // ->GroupBy('uid')->Having('inte','<',200)->pluck('uid')->toArray();
- //
- // $arrs=array_intersect($idA,$idB,$idC);
- // $data=[];
- // foreach ($arrs as $k=>$v){
- // if ($k%100==0){
- // Log::error(22);
- // }
- //
- // $inteLogA=Intelog::where('season',35)->where('uid',$v)->sum('integral');
- // $inteLogB=Intelog::where('season',36)->where('uid',$v)->sum('integral');
- // if (($inteLogA+$inteLogB)<200){
- // $inteLogC=Intelog::where('season',37)->where('uid',$v)->sum('integral');
- // $inteLog=$inteLogA+$inteLogB+$inteLogC;
- // if ($inteLog>=200){
- // $user=User::find($v);
- // $Arr=[
- // '昵称'=>$user->nickname,
- // '手机号'=>$user->phone,
- // '学分'=>$inteLog,
- // '批发商'=>$user->up_name,
- // '战区'=>$user->war_names,
- // ];
- // $data[]=$Arr;
- // }
- // }
- //
- // }
- //
- // Cache::put('CacheData',$data,'100');
- // Log::error('huncun结束');
- })->dailyAt('11:24');
- // $schedule->command('inspire')
- // ->hourly();
- // $schedule->command(SendMessageCourseCommand::class)->everyMinute();
- $schedule->command(IntegralCommand::class)->dailyAt('16:21');
- //
- // $schedule->command(MakePKListCommand::class)->dailyAt('11:20');
- $schedule->command(MakeNumOneLevelCommand::class)->dailyAt('16:24');
- $schedule->command(MakeTopHundredCommand::class)->dailyAt('16:25');
- // $schedule->command(MakeHonorWallCommand::class)->dailyAt('14:46');
- // $schedule->call(function (){
- // $data=User::where('integral','>',0)->where('level_name','<>','政委')->get();
- // foreach ($data as $k=>$v){
- // $num1=InteReview::where('season',32)->where('uid',$v->id)->sum('integral');
- // User::where('id',$v->id)->update(['total'=>$num1/10]);
- // }
- // })->dailyAt('14:41');
- // $schedule->call(function (){
- // $enroll=Enroll::where('season',38)->where('status',0)->pluck('uid');
- // User::whereNotIn('id',$enroll)->where('level_name',"<>",'政委')->update(['integral'=>0]);
- // })->dailyAt('14:58');
- // $schedule->call(function (){
- // Log::error('saiji 结束了啊啊 是啊');
- // $id=Enroll::where('season',42)->where('status',0)->pluck('uid');
- //// User::whereNotIn('id',$id)->whereIn('level_name',['经销商','批发商'])->update(['integral'=>0]);
- // foreach ($id as $k=>$v){
- // $re=Glory::where('season',41)->where('uid',$v)->first();
- // if ($re){
- // if ($re->integral<200){
- // $res=User::where('id',$v)->first();
- // $res->inte_num=$re->integral;
- // $res->integral=$res->integral+$re->integral;
- // $res->save();
- // }
- // }
- //
- // }
- // Log::error('结束了啊啊 是啊');
- // })->dailyAt('11:27');
- $schedule->call(function (){
- $user=User::where('level_name','批发商')->get();
- foreach ($user as $k=>$v){
- $re=DB::table('service')->where('phone',$v->phone)->first();
- if ($re){
- User::where('id',$v->id)->update(['war_names'=>$re->war_names]);
- }
- }
- })->dailyAt('11:42');
- // $schedule->call(function (){
- // $j_ids=User::where('level_name','经销商')->pluck('id');
- // $z_ids=User::where('level_name','销售员')->pluck('id');
- // $c_ids=User::where('level_name','批发商')->pluck('id');
- // $j_u=Glory::where('season',27)->whereIn('uid',$j_ids)->with(['user'])->OrderByDesc('integral')->limit(1)->first();
- // $z_u=Glory::where('season',27)->whereIn('uid',$z_ids)->with(['user'])->OrderByDesc('integral')->limit(1)->first();
- // $c_u=Glory::where('season',27)->whereIn('uid',$c_ids)->with(['user'])->OrderByDesc('integral')->limit(1)->first();
- // $a_us=Glory::where('season',27)->whereIn('uid',$j_ids)->with(['user'])->where('uid','<>',$j_u->uid)->where('uid','<>',$z_u->uid)->where('uid','<>',$c_u->uid)->orderByDesc('integral')->limit(80)->get();
- // foreach ($a_us as $k=>$v){
- // $path=$this->Image($v->user);
- // DB::table('honor_wall')->insert(['season'=>27,'type'=>0,'imgurl'=>$path,'user_id'=>$v->uid]);
- // }
- // $j_path=$this->Image($j_u->user);
- // $z_path=$this->Image($z_u->user);
- // $c_path=$this->Image($c_u->user);
- // DB::table('honor_wall')->insert(['season'=>27,'type'=>1,'imgurl'=>$j_path,'user_id'=>$j_u->uid]);
- // DB::table('honor_wall')->insert(['season'=>27,'type'=>1,'imgurl'=>$z_path,'user_id'=>$z_u->uid]);
- // DB::table('honor_wall')->insert(['season'=>27,'type'=>1,'imgurl'=>$c_path,'user_id'=>$c_u->uid]);
- // })->dailyAt('15:42');
- // $schedule->call(function (){
- // echo md5(base64_encode(md5("123456")).'576hbgh6');
- // });
- // $schedule->call(function (){
- // $user=User::where('level_name','批发商')->get();
- // foreach ($user as $k=>$v){
- // User::where('up_phone',$v->phone)->update(['up_name'=>$v->nickname]);
- // }
- // })->everyMinute();
- // $schedule->call(function (){
- //// $monolog = Log::getMonolog();
- //// $monolog->popHandler();
- //// Log::useFiles(storage_path('logs/job/error.log'));
- //// Log::info('test');
- //
- // $data=DB::table('fail')->where('season','=',20)
- // ->where('status','=',1)
- // ->where('type','=',1)
- // ->select('number','id')
- // ->get();
- // foreach ($data as $k=>$v){
- // $re=DB::table('inte_review')->where('season','=',20)
- // ->where('number',$v->number)->first();
- // if (!$re){
- // DB::table('review_log')->insert(['number'=>$v->number,'inte_id'=>$v->id]);
- // }
- // }
- // })->everyMinute();
- // $schedule->call(function (){
- // $ids=User::where('level_name','政委')->pluck('id')->toArray();
- // $re=Glory::where('season','>=',26)->whereNotIn('uid',$ids)->get();
- // foreach ($re as $k=>$v){
- // if ($k%1000==0){
- // Log::error('已经进行至:'.$k);
- // }
- // $num_one=InteReview::where('uid',$v->uid)->where('season',$v->season)->sum('type_one');
- // $num_two=InteReview::where('uid',$v->uid)->where('season',$v->season)->sum('type_two');
- // $num_three=InteReview::where('uid',$v->uid)->where('season',$v->season)->sum('type_three');
- // $num_four=InteReview::where('uid',$v->uid)->where('season',$v->season)->sum('type_four');
- // Glory::where('id',$v->id)->update(['hard'=>$num_one,'simple'=>$num_two,'old'=>$num_three,'newold'=>$num_four]);
- // }
- // })->everyMinute();
- // $schedule->call(function (){
- // $user=DB::connection('mysql_dwbs')->table('users')->where('level',3)->whereNull('deleted_at')->get();
- // foreach ($user as $k=>$v){
- // $re=DB::table('service')->where('phone',$v->mobile)->first();
- // if (!$re){
- // Log::error($v->mobile);
- // }
- // }
- // })->everyMinute();
- }
- /**
- * Register the commands for the application.
- *
- * @return void
- */
- protected function commands()
- {
- $this->load(__DIR__.'/Commands');
- require base_path('routes/console.php');
- }
- public function Image($arr){
- $bg_img=Image::make(public_path().'/bk.png');
- $name=$this->filterEmoji($arr->nickname);
- if (mb_strlen($name)==2){
- $name=mb_substr($name,0,1).' '.mb_substr($name,1,1);
- }elseif (mb_strlen($name)>4){
- $name=mb_substr($name,0,4);
- }
- $bg_img->text($name, 215, 395,function ($font){
- $font->file(public_path().'/ziti/ht.otf');
- $font->size(25);
- $font->color('000');
- $font->angle(0);
- });
- $client=new Client();
- try{
- $avatar=$client->get($arr->avatar);
- $avatars=$avatar->getBody()->getContents();
- }catch (\Exception $exception){
- $avatars=Image::make(public_path().'/logo3.png');
- }
- $img2 = Image::make($avatars);
- $img3=$this->bg_resize($img2);
- $bg_img->insert($img3,'',123,130);
- $folder_name = "uploads/images/rankImg/" . date("Ym/d", time());
- // 文件具体存储的物理路径,`public_path()` 获取的是 `public` 文件夹的物理路径。
- // 值如:/home/vagrant/Code/larabbs/public/uploads/images/avatars/201709/21/
- $upload_path = 'public/' . $folder_name;
- // 获取文件的后缀名,因图片从剪贴板里黏贴时后缀名为空,所以此处确保后缀一直存在
- $extension = 'png';
- // 拼接文件名,加前缀是为了增加辨析度,前缀可以是相关数据模型的 ID
- // 值如:1_1493521050_7BVc9v9ujP.png
- $filename = Str::random(10).'.' . $extension;
- // $filename = 1 . '_' . time() . '_' . str_random(10) . '.' . $extension;
- File::isDirectory($upload_path) or File::makeDirectory($upload_path, 077, true, true);
- // 将图片移动到我们的目标存储路径中
- // $bg_img->save($upload_path . '/' . $filename);
- $bg_img->save(public_path().'/'.$upload_path.'/'.$filename);
- $rank_path=env('APP_URL').'/'.$upload_path.'/'.$filename;
- return $rank_path;
- }
- public function bg_resize($img2){
- $img2 = $img2->resize(210, 210);
- $r = $img2->width() / 2;
- $img3 = Image::canvas(210, 210);
- for ($x = 0; $x < $img2->width(); $x++) {
- for ($y = 0; $y < $img2->height(); $y++) {
- if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
- $c = $img2->pickColor($x, $y, 'array');
- $img3->pixel($c, $x, $y);
- }
- }
- }
- return $img3;
- }
- function filterEmoji($str=''){
- $str = json_encode($str);
- $str = json_decode(preg_replace("#(\\\ud[0-9a-f]{3})#i", "", $str));
- return $str;
- }
- }
|