<?php    
    namespace App\Console\Commands;
    use App\Models\Prod\Prod;
    use Illuminate\Console\Command;
    use Illuminate\Support\Facades\Log;
    class Create_Baidu_Txt extends Command
    {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'CreateBaiduTxt';
        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = '生成百度收录资源文件链接';
        /**
         * Create a new command instance.
         *
         * @return void
         */
        public function __construct()
        {
            parent::__construct();
        }
        /**
         * Execute the console command.
         *
         * @return mixed
         */
        public function handle()
        {
            //
            Log::info('CreateBaiduTxt', ['start']);
            $i = 1;
            Prod::select('id', 'cas')->where('status', 1)->orderBy('id', 'asc')->chunk(50000, function ($prods) use (&$i) {
                $urls = [];
                foreach ($prods as $prod) {
                    echo $prod->id . PHP_EOL;
                    $urls[] = 'http://www.zhangzhengshan.com/products/' . $prod->cas . '.html';
                }
                file_put_contents('public/sitemap_' . $i . '.txt', implode("\n", $urls));
                $i++;
            });
            Log::info('CreateBaiduTxt', ['end']);
        }
    }

最终生成的效果

sitemap.png

sitemap_url.png

提交百度链接

微信图片_20210219105526.png