MakeNumOneLevelCommand.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Middleware\EncryptCookies;
  4. use App\Models\Basic;
  5. use App\Models\DwbsUser;
  6. use App\Models\Enroll;
  7. use App\Models\Intelog;
  8. use App\Models\RankDays;
  9. use App\Models\RankTemplate;
  10. use App\Models\User;
  11. use Carbon\Carbon;
  12. use Illuminate\Console\Command;
  13. use Illuminate\Support\Facades\DB;
  14. use Illuminate\Support\Facades\Log;
  15. use Intervention\Image\Facades\Image;
  16. class MakeNumOneLevelCommand extends Command
  17. {
  18. /**
  19. * The name and signature of the console command.
  20. *
  21. * @var string
  22. */
  23. protected $signature = 'command:name';
  24. /**
  25. * The console command description.
  26. *
  27. * @var string
  28. */
  29. protected $description = 'Command description';
  30. /**
  31. * Create a new command instance.
  32. *
  33. * @return void
  34. */
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. }
  39. /**
  40. * Execute the console command.
  41. *
  42. * @return mixed
  43. */
  44. public function handle()
  45. {
  46. $start_time=Carbon::yesterday();
  47. $end_time=Carbon::today();
  48. $season=Basic::where('keys','season')->value('value');
  49. $season_start=Basic::where('keys','round_start_time')->value('value');
  50. $season_end=Basic::where('keys','round_end_time')->value('value');
  51. $time=Carbon::now()->timestamp;
  52. if ($time>$season_start && $time<$season_end){
  53. $crown_ids=User::where('integral','>',0)->where('level_name','批发商')->pluck('id');
  54. $crown_inte=Intelog::where('season',$season)->where('type',1)
  55. ->whereIn('uid',$crown_ids)->whereBetween('time',[strtotime($start_time),strtotime($end_time)-1])
  56. ->select(DB::raw('SUM(integral) as all_integral'),'uid')->orderByDesc('all_integral')->groupBy('uid')
  57. ->limit(1)->get();
  58. $re=Intelog::where('season',$season)->where('type',1)
  59. ->whereIn('uid',$crown_ids)->whereBetween('time',[strtotime($start_time),strtotime($end_time)-1])
  60. ->select(DB::raw('SUM(integral) as all_integral'),'uid')->orderByDesc('all_integral')->groupBy('uid')
  61. ->Having('all_integral','=',$crown_inte[0]->all_integral)->get();
  62. foreach ($re as $k=>$v){
  63. $this->GetImg($v->uid,'3',$season);
  64. }
  65. $jingli_ids=User::where('integral','>',0)->where('level_name','经销商')->pluck('id');
  66. $jingli_inte=Intelog::where('season',$season)->where('type',1)
  67. ->whereIn('uid',$jingli_ids)->whereBetween('time',[strtotime($start_time),strtotime($end_time)-1])
  68. ->select(DB::raw('SUM(integral) as all_integral'),'uid')
  69. ->orderByDesc('all_integral')->groupBy('uid')->limit(1)->get();
  70. $res=Intelog::where('season',$season)->where('type',1)
  71. ->whereIn('uid',$jingli_ids)->whereBetween('time',[strtotime($start_time),strtotime($end_time)-1])
  72. ->select(DB::raw('SUM(integral) as all_integral'),'uid')
  73. ->orderByDesc('all_integral')->groupBy('uid')->Having('all_integral','=',$jingli_inte[0]->all_integral)->get();
  74. foreach ($res as $k=>$v){
  75. $this->GetImg($v->uid,'2',$season);
  76. }
  77. $zhuguan_ids=User::where('integral','>',0)->where('level_name','销售员')->pluck('id');
  78. $zhuguan_inte=Intelog::where('season',$season)->where('type',1)
  79. ->whereIn('uid',$zhuguan_ids)->whereBetween('time',[strtotime($start_time),strtotime($end_time)-1])
  80. ->select(DB::raw('SUM(integral) as all_integral'),'uid')
  81. ->orderByDesc('all_integral')->groupBy('uid')->limit(1)->get();
  82. $zhuguan_re=Intelog::where('season',$season)->where('type',1)
  83. ->whereIn('uid',$zhuguan_ids)->whereBetween('time',[strtotime($start_time),strtotime($end_time)-1])
  84. ->select(DB::raw('SUM(integral) as all_integral'),'uid')
  85. ->orderByDesc('all_integral')->groupBy('uid')->Having('all_integral','=',$zhuguan_inte[0]->all_integral)->get();
  86. foreach ($zhuguan_re as $k=>$v){
  87. $this->GetImg($v->uid,'1',$season);
  88. }
  89. }
  90. Log::error('生成每日排名第一成功');
  91. }
  92. public function GetImg($phone,$level,$season){
  93. $user=User::where('id',$phone)->first();
  94. $dw_user=DwbsUser::find($user->dwbs_id);
  95. $name=$dw_user->remark_name==null?$dw_user->nickname:$dw_user->remark_name;
  96. $url=RankTemplate::where('level',$level)->where('season',$season)->where('type',2)->where('url_type',0)->value('url');
  97. $Image=Image::make($url);
  98. $logo_url=RankTemplate::where('type',2)->where('season',$season)->where('url_type',1)->value('url');
  99. $logo=Image::make($logo_url);
  100. try {
  101. // $avatar=mb_substr($user->avatar);
  102. $avatar=mb_substr($user->avatar,0,-3).'0';
  103. $avatar=Image::make($avatar)->resize(725,725);;
  104. } catch (\Exception $exception) {
  105. try{
  106. $avatar = Image::make($dw_user->headimgurl)->resize(725,725);
  107. }catch (\Exception $exception){
  108. $avatar = Image::make(public_path() . '/logo3.png');
  109. }
  110. }
  111. $avatar=$this->bg_resize($avatar);
  112. $Image->insert($avatar,'',190,635);
  113. $Image->insert($logo);
  114. $name=$this->filterEmoji($name);
  115. $length=mb_strlen($name);
  116. if ($length>=6){
  117. $name=mb_substr($name,0,6);
  118. $h=835-40;
  119. $y=80;
  120. }elseif($length==5){
  121. $h=835-20;
  122. $y=80;
  123. }elseif ($length==4){
  124. $h=835;
  125. $y=80;
  126. }elseif($length==3){
  127. $h=835+40;
  128. $y=120;
  129. }elseif($length==2){
  130. $h=835+80;
  131. $y=160;
  132. }else{
  133. $h=835+160;
  134. $y=0;
  135. }
  136. for ($i=0;$i<$length;$i++){
  137. $Image->text(mb_substr($name,$i,1),951,$h+$i*$y,function ($font){
  138. $font->file(public_path().'/ziti/ht.otf');
  139. $font->size(73);
  140. $font->color('FFF');
  141. $font->angle(0);
  142. });
  143. }
  144. $time=date('m月d日',time()-24*3600);
  145. $Image->text($time,150,450,function ($font){
  146. $font->file(public_path().'/uploads/images/background/zi.otf');
  147. $font->size(174);
  148. $font->color('FFF');
  149. $font->angle(0);
  150. });
  151. $folder_name = "uploads/images/rankImg/" . date("Ym/d", time());
  152. // 文件具体存储的物理路径,`public_path()` 获取的是 `public` 文件夹的物理路径。
  153. // 值如:/home/vagrant/Code/larabbs/public/uploads/images/avatars/201709/21/
  154. $upload_path = '/public/' . $folder_name;
  155. // 获取文件的后缀名,因图片从剪贴板里黏贴时后缀名为空,所以此处确保后缀一直存在
  156. $extension = 'png';
  157. // 拼接文件名,加前缀是为了增加辨析度,前缀可以是相关数据模型的 ID
  158. // 值如:1_1493521050_7BVc9v9ujP.png
  159. $filename = $level . '_' . time() . '_' . str_random(10) . '.' . $extension;
  160. if (!file_exists(public_path($upload_path))) {
  161. mkdir(public_path($upload_path), 0777, true);
  162. }
  163. // File::isDirectory(public_path().$upload_path) or File::makeDirectory(public_path().$upload_path,077,true,true);
  164. // 将图片移动到我们的目标存储路径中
  165. $Image->save(public_path().$upload_path.'/'.$filename);
  166. $rank_path=env('APP_URL').$upload_path.'/'.$filename;
  167. $rank_days=new RankDays();
  168. $rank_days->season=$season;
  169. $rank_days->level=$level;
  170. $rank_days->type=2;
  171. $rank_days->img_url=$rank_path;
  172. $rank_days->user_ids=json_encode([$user->id]);
  173. $rank_days->time=Carbon::today()->toDateString();
  174. $rank_days->save();
  175. }
  176. public function bg_resize($img2)
  177. {
  178. $img2 = $img2->resize(700, 700);
  179. $r = $img2->width() / 2;
  180. $img3 = Image::canvas(700, 700);
  181. for ($x = 0; $x < $img2->width(); $x++) {
  182. for ($y = 0; $y < $img2->height(); $y++) {
  183. if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
  184. $c = $img2->pickColor($x, $y, 'array');
  185. $img3->pixel($c, $x, $y);
  186. }
  187. }
  188. }
  189. return $img3;
  190. }
  191. function filterEmoji($str=''){
  192. $str = json_encode($str);
  193. $str = json_decode(preg_replace("#(\\\ud[0-9a-f]{3})#i", "", $str));
  194. return $str;
  195. }
  196. }