作者 李美松

v6优化程序 定时任务优化

@@ -7,6 +7,7 @@ use App\Models\ProjectAssociation\ProjectAssociation; @@ -7,6 +7,7 @@ use App\Models\ProjectAssociation\ProjectAssociation;
7 use App\Services\CosService; 7 use App\Services\CosService;
8 use Barryvdh\DomPDF\Facade\Pdf; 8 use Barryvdh\DomPDF\Facade\Pdf;
9 use Illuminate\Console\Command; 9 use Illuminate\Console\Command;
  10 +use Illuminate\Support\Facades\DB;
10 11
11 class GeneratePdfData extends Command 12 class GeneratePdfData extends Command
12 { 13 {
@@ -66,15 +67,22 @@ class GeneratePdfData extends Command @@ -66,15 +67,22 @@ class GeneratePdfData extends Command
66 sleep(60); 67 sleep(60);
67 return 0; 68 return 0;
68 } 69 }
69 - $pdfFile = new PdfFile();  
70 - $bool = $pdfFile->saveData(['pid' => $list->id]);  
71 - if (!$bool) {  
72 - $this->error('生成v6绑定的aicc用户的pdf备用数据添加失败');  
73 - return 0; 70 + DB::beginTransaction();
  71 + try {
  72 + $pdfFile = new PdfFile();
  73 + $bool = $pdfFile->saveData(['pid' => $list->id]);
  74 + if (!$bool) {
  75 + $this->error('生成v6绑定的aicc用户的pdf备用数据添加失败');
  76 + return 0;
  77 + }
  78 + $list->m_status = $month;
  79 + $list->save();
  80 + DB::commit();
  81 + $this->info('生成v6绑定的aicc用户的pdf备用数据添加成功 - ' . $list->id);
  82 + } catch (\Exception $exception) {
  83 + DB::rollBack();
  84 + $this->error('生成v6绑定的aicc用户的pdf备用数据添加失败 - ' . $list->id);
74 } 85 }
75 - $list->m_status = $month;  
76 - $list->save();  
77 - $this->info('生成v6绑定的aicc用户的pdf备用数据添加成功');  
78 return 0; 86 return 0;
79 } 87 }
80 } 88 }
@@ -5,9 +5,11 @@ namespace App\Console\Commands\GeneratePDF; @@ -5,9 +5,11 @@ namespace App\Console\Commands\GeneratePDF;
5 use App\Models\File\PdfFile; 5 use App\Models\File\PdfFile;
6 use App\Models\ProjectAssociation\ProjectAssociation; 6 use App\Models\ProjectAssociation\ProjectAssociation;
7 use App\Services\CosService; 7 use App\Services\CosService;
  8 +use App\Services\ProjectServer;
8 use Barryvdh\DomPDF\Facade\Pdf; 9 use Barryvdh\DomPDF\Facade\Pdf;
9 use Illuminate\Console\Command; 10 use Illuminate\Console\Command;
10 use Illuminate\Http\File; 11 use Illuminate\Http\File;
  12 +use Illuminate\Support\Facades\DB;
11 13
12 class ProjectFilePDF extends Command 14 class ProjectFilePDF extends Command
13 { 15 {
@@ -48,7 +50,6 @@ class ProjectFilePDF extends Command @@ -48,7 +50,6 @@ class ProjectFilePDF extends Command
48 50
49 public function handle() 51 public function handle()
50 { 52 {
51 -  
52 // 开始时间 53 // 开始时间
53 $startTime = microtime(true); 54 $startTime = microtime(true);
54 55
@@ -105,8 +106,14 @@ class ProjectFilePDF extends Command @@ -105,8 +106,14 @@ class ProjectFilePDF extends Command
105 $friend_id = $isExists->friend_id; 106 $friend_id = $isExists->friend_id;
106 // todo 根据项目查询数据 107 // todo 根据项目查询数据
107 $project_data = []; 108 $project_data = [];
108 - $html = $this->html($project_data);  
109 - $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id); 109 + //获取当前数据详情
  110 + $res = ProjectServer::useProject($project_id);
  111 + if ($res) {
  112 + $project_data = [];
  113 + }
  114 + DB::disconnect('custom_mysql');
  115 + $html = $this->html($project_data);
  116 + $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
110 117
111 if ($count == 2) { 118 if ($count == 2) {
112 $list->is_pdf = PdfFile::GENERATE_OTHER_PDF; 119 $list->is_pdf = PdfFile::GENERATE_OTHER_PDF;
@@ -169,7 +176,14 @@ class ProjectFilePDF extends Command @@ -169,7 +176,14 @@ class ProjectFilePDF extends Command
169 */ 176 */
170 protected function html($item) 177 protected function html($item)
171 { 178 {
172 - $font_path = storage_path('fonts\msyh.ttf');  
173 - return '<html><head><title>Laravel</title><meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'/><style>body{ font-family: \'msyh\'; } @font-face { font-family: \'msyh\'; font-style: normal; font-weight: normal; src: url(' . $font_path . ') format(\'truetype\'); }</style></head><body><div class=\'container\'><div class=\'content\'><p style=\'font-family: msyh, DejaVu Sans,sans-serif;\'>献给母亲的爱</p><div style=\'font-family: msyh, DejaVu Sans,sans-serif;\' class=\'title\'>Laravel 5中文测试sdsd</div><div class=\'title\'>测试三askjdhfkjasdhf</div></div></div></body></html>'; 179 + $html = @file_get_contents(dirname(__FILE__) . '/pdf_template.html');
  180 + if (empty($html)) {
  181 + return '';
  182 + }
  183 + $rep = [
  184 + 'ENTRY_NAME' => '测试项目',
  185 + 'NUMBER' => 1000,
  186 + ];
  187 + return str_replace(array_keys($rep), array_values($rep), $html);
174 } 188 }
175 } 189 }
  1 +<!DOCTYPE html>
  2 +<html lang="en">
  3 +<head>
  4 + <meta charset="UTF-8">
  5 + <title>网站数据</title>
  6 + <style>
  7 + @font-face {
  8 + font-family: 'msyh';
  9 + font-style: normal;
  10 + font-weight: normal;
  11 + src: url(../../../../storage/fonts/msyh.ttf) format('truetype');
  12 + }
  13 + body {
  14 + font-family: 'msyh';
  15 + }
  16 +
  17 + </style>
  18 +</head>
  19 +<body>
  20 + 项目名称:ENTRY_NAME<br>
  21 + 数量:NUMBER
  22 +</body>
  23 +</html>
@@ -7,7 +7,70 @@ use App\Models\Base; @@ -7,7 +7,70 @@ use App\Models\Base;
7 use Illuminate\Database\Eloquent\SoftDeletes; 7 use Illuminate\Database\Eloquent\SoftDeletes;
8 8
9 /** 9 /**
  10 + * App\Models\Product\Product
  11 + *
10 * @method static get() 12 * @method static get()
  13 + * @property int $id
  14 + * @property int $project_id
  15 + * @property string $title
  16 + * @property string $thumb 封面
  17 + * @property mixed|null $gallery 图集
  18 + * @property mixed|null $attrs 属性参数
  19 + * @property string|null $attr_id 通用参数
  20 + * @property string|null $category_id 分类 多个,号隔开
  21 + * @property string|null $keyword_id 关键词标签 多个,号隔开
  22 + * @property string|null $intro 简介
  23 + * @property string|null $content 详情
  24 + * @property mixed|null $describe 描述
  25 + * @property string $describe_id 通用描述
  26 + * @property mixed|null $seo_mate seo tdk
  27 + * @property string $related_product_id 相关产品 多个,号隔开
  28 + * @property int $sort 排序
  29 + * @property int $status 状态 0草稿 1已上架 2已下架
  30 + * @property int $created_uid 创建者
  31 + * @property \Illuminate\Support\Carbon|null $created_at
  32 + * @property \Illuminate\Support\Carbon|null $updated_at
  33 + * @property \Illuminate\Support\Carbon|null $deleted_at
  34 + * @property string|null $route 路由
  35 + * @property mixed|null $icon 图标
  36 + * @property string|null $product_type 产品类型:1,一般产品;2:推荐产品(recommend);3:热销产品(hot)
  37 + * @property int $is_upgrade 0:6.0 1:4.0,5.0升级
  38 + * @property string|null $send_time 发布时间
  39 + * @property int|null $six_read 1:导入数据可按6.0显示
  40 + * @method \Illuminate\Database\Eloquent\Builder|Product newModelQuery()
  41 + * @method \Illuminate\Database\Eloquent\Builder|Product newQuery()
  42 + * @method \Illuminate\Database\Eloquent\Builder|Product onlyTrashed()
  43 + * @method static \Illuminate\Database\Eloquent\Builder|Product query()
  44 + * @method \Illuminate\Database\Eloquent\Builder|Product whereAttrId($value)
  45 + * @method \Illuminate\Database\Eloquent\Builder|Product whereAttrs($value)
  46 + * @method \Illuminate\Database\Eloquent\Builder|Product whereCategoryId($value)
  47 + * @method \Illuminate\Database\Eloquent\Builder|Product whereContent($value)
  48 + * @method \Illuminate\Database\Eloquent\Builder|Product whereCreatedAt($value)
  49 + * @method \Illuminate\Database\Eloquent\Builder|Product whereCreatedUid($value)
  50 + * @method \Illuminate\Database\Eloquent\Builder|Product whereDeletedAt($value)
  51 + * @method \Illuminate\Database\Eloquent\Builder|Product whereDescribe($value)
  52 + * @method \Illuminate\Database\Eloquent\Builder|Product whereDescribeId($value)
  53 + * @method \Illuminate\Database\Eloquent\Builder|Product whereGallery($value)
  54 + * @method \Illuminate\Database\Eloquent\Builder|Product whereIcon($value)
  55 + * @method \Illuminate\Database\Eloquent\Builder|Product whereId($value)
  56 + * @method \Illuminate\Database\Eloquent\Builder|Product whereIntro($value)
  57 + * @method \Illuminate\Database\Eloquent\Builder|Product whereIsUpgrade($value)
  58 + * @method \Illuminate\Database\Eloquent\Builder|Product whereKeywordId($value)
  59 + * @method \Illuminate\Database\Eloquent\Builder|Product whereProductType($value)
  60 + * @method \Illuminate\Database\Eloquent\Builder|Product whereProjectId($value)
  61 + * @method \Illuminate\Database\Eloquent\Builder|Product whereRelatedProductId($value)
  62 + * @method \Illuminate\Database\Eloquent\Builder|Product whereRoute($value)
  63 + * @method \Illuminate\Database\Eloquent\Builder|Product whereSendTime($value)
  64 + * @method \Illuminate\Database\Eloquent\Builder|Product whereSeoMate($value)
  65 + * @method \Illuminate\Database\Eloquent\Builder|Product whereSixRead($value)
  66 + * @method \Illuminate\Database\Eloquent\Builder|Product whereSort($value)
  67 + * @method \Illuminate\Database\Eloquent\Builder|Product whereStatus($value)
  68 + * @method \Illuminate\Database\Eloquent\Builder|Product whereThumb($value)
  69 + * @method \Illuminate\Database\Eloquent\Builder|Product whereTitle($value)
  70 + * @method \Illuminate\Database\Eloquent\Builder|Product whereUpdatedAt($value)
  71 + * @method \Illuminate\Database\Eloquent\Builder|Product withTrashed()
  72 + * @method \Illuminate\Database\Eloquent\Builder|Product withoutTrashed()
  73 + * @mixin \Eloquent
11 */ 74 */
12 class Product extends Base 75 class Product extends Base
13 { 76 {