Kernel.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. namespace App\Console;
  3. use App\Console\Commands\IntegralCommand;
  4. use App\Console\Commands\MakeHonorWallCommand;
  5. use App\Console\Commands\MakeNumOneLevelCommand;
  6. use App\Console\Commands\MakePKListCommand;
  7. use App\Console\Commands\MakeTopHundredCommand;
  8. use App\Console\Commands\SendMessageCourseCommand;
  9. use App\Jobs\SendMessageFive;
  10. use App\Jobs\SendMessageFour;
  11. use App\Jobs\SendMessageOne;
  12. use App\Jobs\SendMessageThree;
  13. use App\Jobs\SendMessageTwo;
  14. use App\Models\Basic;
  15. use App\Models\DwbsUser;
  16. use App\Models\Enroll;
  17. use App\Models\Glory;
  18. use App\Models\Intelog;
  19. use App\Models\InteReview;
  20. use App\Models\User;
  21. use GuzzleHttp\Client;
  22. use Illuminate\Console\Scheduling\Schedule;
  23. use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
  24. use Illuminate\Support\Facades\Cache;
  25. use Illuminate\Support\Facades\DB;
  26. use Illuminate\Support\Facades\File;
  27. use Illuminate\Support\Facades\Log;
  28. use Illuminate\Support\Str;
  29. use Intervention\Image\Facades\Image;
  30. class Kernel extends ConsoleKernel
  31. {
  32. /**
  33. * The Artisan commands provided by your application.
  34. *
  35. * @var array
  36. */
  37. protected $commands = [
  38. //
  39. ];
  40. /**
  41. * Define the application's command schedule.
  42. *
  43. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  44. * @return void
  45. */
  46. protected function schedule(Schedule $schedule)
  47. {
  48. // $schedule->call(function (){
  49. // $enroll=Enroll::where('season',33)->where('status',0)->pluck('uid');
  50. // $ids=User::whereIn('id',$enroll)->pluck('dwbs_id');
  51. // $all=DwbsUser::whereIn('id',$ids)->get();
  52. // foreach ($all as $k=>$v){
  53. // User::where('dwbs_id',$v->id)->update(['avatar'=>$v->headimgurl]);
  54. // }
  55. // Log::error('结束数叔叔苏');
  56. // })->dailyAt('16:52');
  57. $schedule->call(function (){
  58. // Log::error('kaishi ');
  59. // $id=Enroll::where('season',35)->where('status',0)->pluck('uid')->toArray();
  60. // $ida=Enroll::where('season',36)->where('status',0)->pluck('uid')->toArray();
  61. // $idb=Enroll::where('season',37)->where('status',0)->pluck('uid')->toArray();
  62. //
  63. // $arr=array_intersect($id,$ida,$idb);
  64. //
  65. // $idA=Intelog::where('season',35)->whereIn('uid',$arr)
  66. // ->select(DB::raw('SUM(integral) as inte'),'uid')
  67. // ->GroupBy('uid')->Having('inte','<',200)->pluck('uid')->toArray();
  68. // $idB=Intelog::where('season',36)->whereIn('uid',$arr)
  69. // ->select(DB::raw('SUM(integral) as inte'),'uid')
  70. // ->GroupBy('uid')->Having('inte','<',200)->pluck('uid')->toArray();
  71. // $idC=Intelog::where('season',37)->whereIn('uid',$arr)
  72. // ->select(DB::raw('SUM(integral) as inte'),'uid')
  73. // ->GroupBy('uid')->Having('inte','<',200)->pluck('uid')->toArray();
  74. //
  75. // $arrs=array_intersect($idA,$idB,$idC);
  76. // $data=[];
  77. // foreach ($arrs as $k=>$v){
  78. // if ($k%100==0){
  79. // Log::error(22);
  80. // }
  81. //
  82. // $inteLogA=Intelog::where('season',35)->where('uid',$v)->sum('integral');
  83. // $inteLogB=Intelog::where('season',36)->where('uid',$v)->sum('integral');
  84. // if (($inteLogA+$inteLogB)<200){
  85. // $inteLogC=Intelog::where('season',37)->where('uid',$v)->sum('integral');
  86. // $inteLog=$inteLogA+$inteLogB+$inteLogC;
  87. // if ($inteLog>=200){
  88. // $user=User::find($v);
  89. // $Arr=[
  90. // '昵称'=>$user->nickname,
  91. // '手机号'=>$user->phone,
  92. // '学分'=>$inteLog,
  93. // '批发商'=>$user->up_name,
  94. // '战区'=>$user->war_names,
  95. // ];
  96. // $data[]=$Arr;
  97. // }
  98. // }
  99. //
  100. // }
  101. //
  102. // Cache::put('CacheData',$data,'100');
  103. // Log::error('huncun结束');
  104. })->dailyAt('11:24');
  105. // $schedule->command('inspire')
  106. // ->hourly();
  107. // $schedule->command(SendMessageCourseCommand::class)->everyMinute();
  108. $schedule->command(IntegralCommand::class)->dailyAt('16:21');
  109. //
  110. // $schedule->command(MakePKListCommand::class)->dailyAt('11:20');
  111. $schedule->command(MakeNumOneLevelCommand::class)->dailyAt('16:24');
  112. $schedule->command(MakeTopHundredCommand::class)->dailyAt('16:25');
  113. // $schedule->command(MakeHonorWallCommand::class)->dailyAt('14:46');
  114. // $schedule->call(function (){
  115. // $data=User::where('integral','>',0)->where('level_name','<>','政委')->get();
  116. // foreach ($data as $k=>$v){
  117. // $num1=InteReview::where('season',32)->where('uid',$v->id)->sum('integral');
  118. // User::where('id',$v->id)->update(['total'=>$num1/10]);
  119. // }
  120. // })->dailyAt('14:41');
  121. // $schedule->call(function (){
  122. // $enroll=Enroll::where('season',38)->where('status',0)->pluck('uid');
  123. // User::whereNotIn('id',$enroll)->where('level_name',"<>",'政委')->update(['integral'=>0]);
  124. // })->dailyAt('14:58');
  125. // $schedule->call(function (){
  126. // Log::error('saiji 结束了啊啊 是啊');
  127. // $id=Enroll::where('season',42)->where('status',0)->pluck('uid');
  128. //// User::whereNotIn('id',$id)->whereIn('level_name',['经销商','批发商'])->update(['integral'=>0]);
  129. // foreach ($id as $k=>$v){
  130. // $re=Glory::where('season',41)->where('uid',$v)->first();
  131. // if ($re){
  132. // if ($re->integral<200){
  133. // $res=User::where('id',$v)->first();
  134. // $res->inte_num=$re->integral;
  135. // $res->integral=$res->integral+$re->integral;
  136. // $res->save();
  137. // }
  138. // }
  139. //
  140. // }
  141. // Log::error('结束了啊啊 是啊');
  142. // })->dailyAt('11:27');
  143. $schedule->call(function (){
  144. $user=User::where('level_name','批发商')->get();
  145. foreach ($user as $k=>$v){
  146. $re=DB::table('service')->where('phone',$v->phone)->first();
  147. if ($re){
  148. User::where('id',$v->id)->update(['war_names'=>$re->war_names]);
  149. }
  150. }
  151. })->dailyAt('11:42');
  152. // $schedule->call(function (){
  153. // $j_ids=User::where('level_name','经销商')->pluck('id');
  154. // $z_ids=User::where('level_name','销售员')->pluck('id');
  155. // $c_ids=User::where('level_name','批发商')->pluck('id');
  156. // $j_u=Glory::where('season',27)->whereIn('uid',$j_ids)->with(['user'])->OrderByDesc('integral')->limit(1)->first();
  157. // $z_u=Glory::where('season',27)->whereIn('uid',$z_ids)->with(['user'])->OrderByDesc('integral')->limit(1)->first();
  158. // $c_u=Glory::where('season',27)->whereIn('uid',$c_ids)->with(['user'])->OrderByDesc('integral')->limit(1)->first();
  159. // $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();
  160. // foreach ($a_us as $k=>$v){
  161. // $path=$this->Image($v->user);
  162. // DB::table('honor_wall')->insert(['season'=>27,'type'=>0,'imgurl'=>$path,'user_id'=>$v->uid]);
  163. // }
  164. // $j_path=$this->Image($j_u->user);
  165. // $z_path=$this->Image($z_u->user);
  166. // $c_path=$this->Image($c_u->user);
  167. // DB::table('honor_wall')->insert(['season'=>27,'type'=>1,'imgurl'=>$j_path,'user_id'=>$j_u->uid]);
  168. // DB::table('honor_wall')->insert(['season'=>27,'type'=>1,'imgurl'=>$z_path,'user_id'=>$z_u->uid]);
  169. // DB::table('honor_wall')->insert(['season'=>27,'type'=>1,'imgurl'=>$c_path,'user_id'=>$c_u->uid]);
  170. // })->dailyAt('15:42');
  171. // $schedule->call(function (){
  172. // echo md5(base64_encode(md5("123456")).'576hbgh6');
  173. // });
  174. // $schedule->call(function (){
  175. // $user=User::where('level_name','批发商')->get();
  176. // foreach ($user as $k=>$v){
  177. // User::where('up_phone',$v->phone)->update(['up_name'=>$v->nickname]);
  178. // }
  179. // })->everyMinute();
  180. // $schedule->call(function (){
  181. //// $monolog = Log::getMonolog();
  182. //// $monolog->popHandler();
  183. //// Log::useFiles(storage_path('logs/job/error.log'));
  184. //// Log::info('test');
  185. //
  186. // $data=DB::table('fail')->where('season','=',20)
  187. // ->where('status','=',1)
  188. // ->where('type','=',1)
  189. // ->select('number','id')
  190. // ->get();
  191. // foreach ($data as $k=>$v){
  192. // $re=DB::table('inte_review')->where('season','=',20)
  193. // ->where('number',$v->number)->first();
  194. // if (!$re){
  195. // DB::table('review_log')->insert(['number'=>$v->number,'inte_id'=>$v->id]);
  196. // }
  197. // }
  198. // })->everyMinute();
  199. // $schedule->call(function (){
  200. // $ids=User::where('level_name','政委')->pluck('id')->toArray();
  201. // $re=Glory::where('season','>=',26)->whereNotIn('uid',$ids)->get();
  202. // foreach ($re as $k=>$v){
  203. // if ($k%1000==0){
  204. // Log::error('已经进行至:'.$k);
  205. // }
  206. // $num_one=InteReview::where('uid',$v->uid)->where('season',$v->season)->sum('type_one');
  207. // $num_two=InteReview::where('uid',$v->uid)->where('season',$v->season)->sum('type_two');
  208. // $num_three=InteReview::where('uid',$v->uid)->where('season',$v->season)->sum('type_three');
  209. // $num_four=InteReview::where('uid',$v->uid)->where('season',$v->season)->sum('type_four');
  210. // Glory::where('id',$v->id)->update(['hard'=>$num_one,'simple'=>$num_two,'old'=>$num_three,'newold'=>$num_four]);
  211. // }
  212. // })->everyMinute();
  213. // $schedule->call(function (){
  214. // $user=DB::connection('mysql_dwbs')->table('users')->where('level',3)->whereNull('deleted_at')->get();
  215. // foreach ($user as $k=>$v){
  216. // $re=DB::table('service')->where('phone',$v->mobile)->first();
  217. // if (!$re){
  218. // Log::error($v->mobile);
  219. // }
  220. // }
  221. // })->everyMinute();
  222. }
  223. /**
  224. * Register the commands for the application.
  225. *
  226. * @return void
  227. */
  228. protected function commands()
  229. {
  230. $this->load(__DIR__.'/Commands');
  231. require base_path('routes/console.php');
  232. }
  233. public function Image($arr){
  234. $bg_img=Image::make(public_path().'/bk.png');
  235. $name=$this->filterEmoji($arr->nickname);
  236. if (mb_strlen($name)==2){
  237. $name=mb_substr($name,0,1).' '.mb_substr($name,1,1);
  238. }elseif (mb_strlen($name)>4){
  239. $name=mb_substr($name,0,4);
  240. }
  241. $bg_img->text($name, 215, 395,function ($font){
  242. $font->file(public_path().'/ziti/ht.otf');
  243. $font->size(25);
  244. $font->color('000');
  245. $font->angle(0);
  246. });
  247. $client=new Client();
  248. try{
  249. $avatar=$client->get($arr->avatar);
  250. $avatars=$avatar->getBody()->getContents();
  251. }catch (\Exception $exception){
  252. $avatars=Image::make(public_path().'/logo3.png');
  253. }
  254. $img2 = Image::make($avatars);
  255. $img3=$this->bg_resize($img2);
  256. $bg_img->insert($img3,'',123,130);
  257. $folder_name = "uploads/images/rankImg/" . date("Ym/d", time());
  258. // 文件具体存储的物理路径,`public_path()` 获取的是 `public` 文件夹的物理路径。
  259. // 值如:/home/vagrant/Code/larabbs/public/uploads/images/avatars/201709/21/
  260. $upload_path = 'public/' . $folder_name;
  261. // 获取文件的后缀名,因图片从剪贴板里黏贴时后缀名为空,所以此处确保后缀一直存在
  262. $extension = 'png';
  263. // 拼接文件名,加前缀是为了增加辨析度,前缀可以是相关数据模型的 ID
  264. // 值如:1_1493521050_7BVc9v9ujP.png
  265. $filename = Str::random(10).'.' . $extension;
  266. // $filename = 1 . '_' . time() . '_' . str_random(10) . '.' . $extension;
  267. File::isDirectory($upload_path) or File::makeDirectory($upload_path, 077, true, true);
  268. // 将图片移动到我们的目标存储路径中
  269. // $bg_img->save($upload_path . '/' . $filename);
  270. $bg_img->save(public_path().'/'.$upload_path.'/'.$filename);
  271. $rank_path=env('APP_URL').'/'.$upload_path.'/'.$filename;
  272. return $rank_path;
  273. }
  274. public function bg_resize($img2){
  275. $img2 = $img2->resize(210, 210);
  276. $r = $img2->width() / 2;
  277. $img3 = Image::canvas(210, 210);
  278. for ($x = 0; $x < $img2->width(); $x++) {
  279. for ($y = 0; $y < $img2->height(); $y++) {
  280. if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
  281. $c = $img2->pickColor($x, $y, 'array');
  282. $img3->pixel($c, $x, $y);
  283. }
  284. }
  285. }
  286. return $img3;
  287. }
  288. function filterEmoji($str=''){
  289. $str = json_encode($str);
  290. $str = json_decode(preg_replace("#(\\\ud[0-9a-f]{3})#i", "", $str));
  291. return $str;
  292. }
  293. }