作者 lyh

gx定时发布产品

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :SendProduct.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/8/30 14:41
  8 + */
  9 +
  10 +namespace App\Console\Commands\Product;
  11 +
  12 +use App\Models\Blog\Blog;
  13 +use App\Models\Domain\DomainInfo;
  14 +use App\Models\News\News;
  15 +use App\Models\Product\Product;
  16 +use App\Models\Project\Project;
  17 +use App\Services\ProjectServer;
  18 +use Illuminate\Console\Command;
  19 +use Illuminate\Support\Facades\DB;
  20 +
  21 +class SendProduct extends Command
  22 +{
  23 + /**
  24 + * The name and signature of the console command.
  25 + *
  26 + * @var string
  27 + */
  28 + protected $signature = 'send_product';
  29 +
  30 + /**
  31 + * The console command description.
  32 + *
  33 + * @var string
  34 + */
  35 + protected $description = '根据发布时间发布产品';
  36 +
  37 + /**
  38 + * @remark :发布
  39 + * @name :handle
  40 + * @author :lyh
  41 + * @method :post
  42 + * @time :2024/8/30 14:42
  43 + */
  44 + public function handle(){
  45 + $projectModel = new Project();
  46 + $list = $projectModel->list(['deleted_status'=>0]);
  47 + $data = [];
  48 + foreach ($list as $v){
  49 + echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
  50 + ProjectServer::useProject($v['id']);
  51 + $domainModel = new DomainInfo();
  52 + $domain = $domainModel->getProjectIdDomain($v['id']);
  53 + if(empty($domain)){
  54 + continue;
  55 + }
  56 + $arr1 = $this->sendProduct();
  57 + $arr2 = $this->sendBlog();
  58 + $arr3 = $this->sendNews();
  59 + $c_url = $domain.'api/update_page/';
  60 + $param = [
  61 + 'project_id' => $this->user['project_id'],
  62 + 'type' => 1,
  63 + 'route' => 3,
  64 + 'url' => array_merge($arr1,$arr2,$arr3),
  65 + 'language'=> [],
  66 + 'is_sitemap' => 0
  67 + ];
  68 + http_post($c_url, json_encode($param));
  69 + //TODO::通知C端生成界面
  70 + DB::disconnect('custom_mysql');
  71 + }
  72 + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
  73 + }
  74 +
  75 + /**
  76 + * @remark :发布产品
  77 + * @name :sendProduct
  78 + * @author :lyh
  79 + * @method :post
  80 + * @time :2024/8/30 14:44
  81 + */
  82 + public function sendProduct(){
  83 + $start_date = date('Y-m-d H:i:s');
  84 + $end_date = date('Y-m-d 23:59:59');
  85 + $productModel = new Product();
  86 + $arr = $productModel->formatQuery(['send_time'=>['between',[$start_date,$end_date]],'status'=>0])->pluck('route');
  87 + $productModel->edit(['status'=>1],['send_time'=>['between',[$start_date,$end_date]],'status'=>0]);
  88 + return $arr;
  89 + }
  90 +
  91 + /**
  92 + * @remark :定时发布博客
  93 + * @name :sendBlog
  94 + * @author :lyh
  95 + * @method :post
  96 + * @time :2024/8/30 15:19
  97 + */
  98 + public function sendBlog(){
  99 + $start_date = date('Y-m-d H:i:s');
  100 + $end_date = date('Y-m-d 23:59:59');
  101 + $blogModel = new Blog();
  102 + $arr = $blogModel->formatQuery(['send_time'=>['between',[$start_date,$end_date]],'status'=>0])->pluck('url');
  103 + $blogModel->edit(['status'=>1],['release_at'=>['between',[$start_date,$end_date]],'status'=>0]);
  104 + return $arr;
  105 + }
  106 +
  107 + /**
  108 + * @remark :定时发布新闻
  109 + * @name :sendNews
  110 + * @author :lyh
  111 + * @method :post
  112 + * @time :2024/8/30 15:19
  113 + */
  114 + public function sendNews(){
  115 + $start_date = date('Y-m-d H:i:s');
  116 + $end_date = date('Y-m-d 23:59:59');
  117 + $newsModel = new News();
  118 + $arr = $newsModel->formatQuery(['send_time'=>['between',[$start_date,$end_date]],'status'=>0])->pluck('url');
  119 + $newsModel->edit(['status'=>1],['release_at'=>['between',[$start_date,$end_date]],'status'=>0]);
  120 + return $arr;
  121 + }
  122 +}