SendProduct.php 3.6 KB
<?php
/**
 * @remark :
 * @name   :SendProduct.php
 * @author :lyh
 * @method :post
 * @time   :2024/8/30 14:41
 */

namespace App\Console\Commands\Product;

use App\Models\Blog\Blog;
use App\Models\Domain\DomainInfo;
use App\Models\News\News;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '自动发布--根据发布时间发布产品';

    /**
     * @remark :发布
     * @name   :handle
     * @author :lyh
     * @method :post
     * @time   :2024/8/30 14:42
     */
    public function handle(){
        $projectModel = new Project();
        $list = $projectModel->list(['deleted_status'=>0]);
        $data = [];
        foreach ($list as $v){
            echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
            ProjectServer::useProject($v['id']);
            $domainModel = new DomainInfo();
            $domain = $domainModel->getProjectIdDomain($v['id']);
            if(empty($domain)){
                continue;
            }
            $arr1 = $this->sendProduct();
            $arr2 = $this->sendBlog();
            $arr3 = $this->sendNews();
            $c_url = $domain.'api/update_page/';
            $param = [
                'project_id' => $this->user['project_id'],
                'type' => 1,
                'route' => 3,
                'url' => array_merge($arr1,$arr2,$arr3),
                'language'=> [],
                'is_sitemap' => 0
            ];
            http_post($c_url, json_encode($param));
            //TODO::通知C端生成界面
            DB::disconnect('custom_mysql');
        }
        echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
    }

    /**
     * @remark :发布产品
     * @name   :sendProduct
     * @author :lyh
     * @method :post
     * @time   :2024/8/30 14:44
     */
    public function sendProduct(){
        $start_date = date('Y-m-d H:i:s');
        $end_date = date('Y-m-d 23:59:59');
        $productModel = new Product();
        $arr = $productModel->formatQuery(['send_time'=>['between',[$start_date,$end_date]],'status'=>3])->pluck('route');
        $productModel->edit(['status'=>1],['send_time'=>['between',[$start_date,$end_date]],'status'=>3]);
        return $arr;
    }

    /**
     * @remark :定时发布博客
     * @name   :sendBlog
     * @author :lyh
     * @method :post
     * @time   :2024/8/30 15:19
     */
    public function sendBlog(){
        $start_date = date('Y-m-d H:i:s');
        $end_date = date('Y-m-d 23:59:59');
        $blogModel = new Blog();
        $arr = $blogModel->formatQuery(['release_at'=>['between',[$start_date,$end_date]],'status'=>3])->pluck('url');
        $blogModel->edit(['status'=>1],['release_at'=>['between',[$start_date,$end_date]],'status'=>3]);
        return $arr;
    }

    /**
     * @remark :定时发布新闻
     * @name   :sendNews
     * @author :lyh
     * @method :post
     * @time   :2024/8/30 15:19
     */
    public function sendNews(){
        $start_date = date('Y-m-d H:i:s');
        $end_date = date('Y-m-d 23:59:59');
        $newsModel = new News();
        $arr = $newsModel->formatQuery(['release_at'=>['between',[$start_date,$end_date]],'status'=>3])->pluck('url');
        $newsModel->edit(['status'=>1],['release_at'=>['between',[$start_date,$end_date]],'status'=>3]);
        return $arr;
    }
}