<?php
namespace App\Console\Commands;

use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Models\WxUserImg;
use App\Services\UploadServer;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class UploadOOSImg extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'UploadOOSImg';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '上传云图片';
    /**
     * @var ActivityOrder
     */

    /**
     * Create a new command instance.
     * @param ProductOrder $productOrder
     * @param ScoreDetail $scoreDetail
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        set_time_limit(0);
        $this->line('开始');
        $imgs = WxUserImg::where('is_upload', 0)->where('status',1)->select('id','loacl_url','img_url','is_upload')->limit(100)->get();

        foreach($imgs as $img){
            if($img->loacl_url != ''){
                $url = UploadServer::getUploadAliyun('aldzn-img', $img->loacl_url,public_path().'/'.$img->loacl_url);
                if($url){
                    $img->is_upload = 1;
                    $img->img_url = $url;
                    $img->save();
                    if($img->loacl_url != '' && file_exists(public_path().'/'.$img->loacl_url)) unlink(public_path().'/'.$img->loacl_url);
                }
            }
        }
        $this->line('结束');
    }

}