作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !2693
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Project;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Models\Product\Product;
  7 +use App\Services\ProjectServer;
  8 +use Illuminate\Console\Command;
  9 +use Illuminate\Support\Facades\DB;
  10 +
  11 +class ThumbProjectImage extends Command
  12 +{
  13 + /**
  14 + * The name and signature of the console command.
  15 + *
  16 + * @var string
  17 + */
  18 + protected $signature = 'thumb_project_image {project_id}';
  19 +
  20 + /**
  21 + * The console command description.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $description = '处理项目产品缩略图';
  26 +
  27 + public function handle()
  28 + {
  29 + $project_id = $this->argument('project_id');
  30 +
  31 + if ($project_id > 0) {
  32 + //指定项目
  33 + ProjectServer::useProject($project_id);
  34 +
  35 + Product::select(['id', 'thumb'])->chunk(100, function ($products) {
  36 + foreach ($products as $product) {
  37 + $thumb = $product->thumb;
  38 + if (isset($thumb['url']) && $thumb['url']) {
  39 + $thumb['url'] = thumbImageByUrl($thumb['url']);
  40 + $product->thumb = Arr::a2s($thumb);
  41 + $product->save();
  42 + }
  43 + }
  44 + });
  45 +
  46 + DB::disconnect('custom_mysql');
  47 +
  48 + $this->output('project_id:' . $project_id . ' | success');
  49 + } else {
  50 + //TODO:所有项目
  51 + }
  52 + }
  53 +
  54 +
  55 + /**
  56 + * 输出处理日志
  57 + * @param $message
  58 + * @return bool
  59 + */
  60 + public function output($message)
  61 + {
  62 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  63 + return true;
  64 + }
  65 +}