From 73ffb0e3c3c6b852a5ce8fb23722b54e661a448b Mon Sep 17 00:00:00 2001 From: chen <3147481720@qq.com> Date: Tue, 17 Dec 2024 20:54:13 +0800 Subject: [PATCH] 1 --- app/Admin/Extensions/Div.php | 37 ++++---- app/Admin/Extensions/WangEditor.php | 53 +++++++---- .../Transforms/OrderPayTypeTransform.php | 33 ++++--- .../Transforms/OrderShipStatusTransform.php | 34 ++++--- app/Admin/Transforms/OrderStatusTransform.php | 42 +++++---- app/Admin/Transforms/OrderTypeTransform.php | 30 ++++-- app/Admin/Transforms/Transform.php | 14 ++- app/Admin/Transforms/UserSexTransform.php | 28 ++++-- app/Admin/Transforms/YesNoTransform.php | 21 ++++- app/Admin/routes.php | 91 ++++++++++--------- .../Commands/AddShopToEsSearchCommand.php | 91 ++++++++----------- app/Console/Commands/BaseCommand.php | 40 +++++--- app/Console/Commands/CacheOptimize.php | 31 ++++--- app/Console/Commands/ClearCache.php | 32 +++++-- app/Console/Commands/CopyFile.php | 61 +++++++------ app/Console/Commands/CountSite.php | 51 +++++++---- app/Console/Commands/DelExpireScoreData.php | 47 ++++++---- app/Console/Commands/DelExpireSecKill.php | 88 +++++++++--------- app/Console/Commands/DeleteFile.php | 34 ++++--- .../Commands/ExportDatabaseCommand.php | 44 +++++---- app/Console/Commands/InstallShop.php | 59 +++++++----- app/Console/Commands/SendSubscribeEmail.php | 45 ++++++--- .../Commands/SyncProducViewCommand.php | 77 +++++++--------- app/Console/Commands/UninstallShop.php | 32 ++++--- app/Console/Commands/UpdateCacheHomeData.php | 74 ++++++++------- app/Console/Kernel.php | 47 ++++++---- 26 files changed, 715 insertions(+), 521 deletions(-) diff --git a/app/Admin/Extensions/Div.php b/app/Admin/Extensions/Div.php index 1841d52..1c5f263 100644 --- a/app/Admin/Extensions/Div.php +++ b/app/Admin/Extensions/Div.php @@ -1,44 +1,47 @@ id = $id; + $this->id = $id; // 设置 div 的 ID - if (! is_null($width)) { - $this->width = $width; + // 如果提供了宽度,则设置宽度 + if (!is_null($width)) { + $this->width = $width; // 更新 div 的宽度 } - if (! is_null($height)) { - $this->height = $height; + // 如果提供了高度,则设置高度 + if (!is_null($height)) { + $this->height = $height; // 更新 div 的高度 } } - + /** + * 渲染 div 元素的 HTML. + * + * @return string 返回包含 div 的 HTML 字符串 + */ public function render() { + // 使用 heredoc 语法返回包含 div 的 HTML 代码 return <<
div; - } } diff --git a/app/Admin/Extensions/WangEditor.php b/app/Admin/Extensions/WangEditor.php index 18a99a4..e02b150 100644 --- a/app/Admin/Extensions/WangEditor.php +++ b/app/Admin/Extensions/WangEditor.php @@ -1,56 +1,69 @@ formatName($this->column); + // 获取 CSRF 令牌 $token = csrf_token(); + // 定义上传图片的服务器地址 $url = admin_base_path('upload/editor'); + // 定义 JavaScript 代码,初始化 WangEditor $this->script = <<id}'); -editor.customConfig.zIndex = 0 -editor.customConfig.uploadFileName = 'pictures[]' +var E = window.wangEditor; // 获取 WangEditor 对象 +var editor = new E('#{$this->id}'); // 创建编辑器实例,绑定到指定的 HTML 元素 +editor.customConfig.zIndex = 0; // 设置编辑器的 z-index +editor.customConfig.uploadFileName = 'pictures[]'; // 设置上传文件的名称 + // 配置服务器端地址 -editor.customConfig.uploadImgServer = '{$url}' +editor.customConfig.uploadImgServer = '{$url}'; // 设置图片上传的服务器地址 editor.customConfig.uploadImgParams = { - _token: '{$token}' -} -// 文件改变添加内容到隐藏域 + _token: '{$token}' // 设置上传参数,包括 CSRF 令牌 +}; + +// 文件改变时,将 HTML 内容添加到隐藏域 editor.customConfig.onchange = function (html) { - $('input[name=\'$name\']').val(html); + $('input[name=\'$name\']').val(html); // 更新隐藏域的值为编辑器内容 } + // 监听上传错误 editor.customConfig.uploadImgHooks = { fail: function (xhr, editor) { - var response = $.parseJSON(xhr.response); - - alert(response.msg); + var response = $.parseJSON(xhr.response); // 解析服务器返回的 JSON + alert(response.msg); // 弹出错误信息 } -} -editor.create() +}; + +editor.create(); // 创建编辑器实例 EOT; - return parent::render(); + + return parent::render(); // 调用父类的 render 方法,返回最终的 HTML } } diff --git a/app/Admin/Transforms/OrderPayTypeTransform.php b/app/Admin/Transforms/OrderPayTypeTransform.php index fc5db64..9704e79 100644 --- a/app/Admin/Transforms/OrderPayTypeTransform.php +++ b/app/Admin/Transforms/OrderPayTypeTransform.php @@ -1,26 +1,37 @@ " - : ""; + ? "" // 当 $is 为 true 时,返回绿色勾图标 + : ""; // 当 $is 为 false 时,返回红色叉图标 } } diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 2487053..594f8fa 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -1,76 +1,83 @@ config('admin.route.prefix'), - 'namespace' => config('admin.route.namespace'), - 'middleware' => config('admin.route.middleware'), + 'prefix' => config('admin.route.prefix'), // 路由前缀 + 'namespace' => config('admin.route.namespace'), // 控制器命名空间 + 'middleware' => config('admin.route.middleware'), // 中间件 ], function (Router $router) { + // 设置默认的 404 错误页面 $router->fallback('HomeController@noFound'); + // 首页路由 $router->get('/', 'HomeController@index'); - // 覆盖默认的用户管理 + // 覆盖默认的用户管理路由 $router->get('auth/users', 'AdminController@index'); - // 覆盖默认的操作日志 + // 覆盖默认的操作日志路由 $router->get('auth/logs', 'AdminController@indexLogs'); - // 系统的配置 + // 系统配置相关路由 $router->resource('settings', 'SettingController')->only('index', 'store'); - // 商品上架下架 + // 商品上架和下架操作 $router->get('products/{id}/push', 'ProductController@pushProduct'); - // 分类 - // 商品 - // 秒杀的商品管理 - $router->resource('categories', 'CategoryController'); - $router->resource('products', 'ProductController'); - $router->resource('seckills', 'SeckillController')->only('index', 'create', 'store', 'destroy'); + // 分类管理 + // 商品管理 + // 秒杀商品管理 + $router->resource('categories', 'CategoryController'); // 分类资源路由 + $router->resource('products', 'ProductController'); // 商品资源路由 + $router->resource('seckills', 'SeckillController')->only('index', 'create', 'store', 'destroy'); // 秒杀活动的资源路由 - // 商品发货 - // 管理员帮忙确认收货 + // 订单发货相关路由 + // 管理员确认订单发货 $router->post('orders/{order}/ship', 'OrderController@ship'); + // 确认发货状态 $router->patch('orders/{order}/shipped', 'OrderController@confirmShip'); - // 退款 - // 订单 - // 评论 - $router->get('orders/{order}/refund', 'OrderController@refund'); - $router->resource('orders', 'OrderController'); - $router->resource('comments', 'CommentController'); + // 退款相关路由 + // 订单相关路由 + // 评论管理路由 + $router->get('orders/{order}/refund', 'OrderController@refund'); // 退款请求 + $router->resource('orders', 'OrderController'); // 订单资源路由 + $router->resource('comments', 'CommentController'); // 评论资源路由 - // 会员管理 - $router->resource('users', 'UserController'); + // 会员管理相关路由 + $router->resource('users', 'UserController'); // 用户资源路由 // 积分日志 - $router->get('score_logs', 'ScoreLogController@index'); + $router->get('score_logs', 'ScoreLogController@index'); // 积分日志查看 + // 用户购物车数据 - $router->get('cars', 'CarController@index'); - // 用户收藏数据 - $router->get('user_like_products', 'ProductLikeController@index'); + $router->get('cars', 'CarController@index'); // 购物车数据查看 + // 用户收藏数据 + $router->get('user_like_products', 'ProductLikeController@index'); // 用户收藏的产品 - // 积分规则, 积分等级 - $router->resource('score_rules', 'ScoreRuleController'); - $router->resource('levels', 'LevelController'); + // 积分规则和积分等级管理 + $router->resource('score_rules', 'ScoreRuleController'); // 积分规则资源路由 + $router->resource('levels', 'LevelController'); // 积分等级资源路由 // 优惠券管理 - $router->resource('coupon_templates', 'CouponTemplateController'); - // 优惠券 - $router->resource('coupon_logs', 'CouponLogController')->only('index'); - // 优惠券兑换码 - $router->resource('coupon_codes', 'CouponCodeController')->only('index', 'create', 'store', 'destroy'); + $router->resource('coupon_templates', 'CouponTemplateController'); // 优惠券模板资源路由 + // 优惠券日志 + $router->resource('coupon_logs', 'CouponLogController')->only('index'); // 优惠券日志查看 + // 优惠券兑换码管理 + $router->resource('coupon_codes', 'CouponCodeController')->only('index', 'create', 'store', 'destroy'); // 兑换码资源路由 + + // 文章通知管理 + $router->resource('article_notifications', 'ArticleNotificationController')->only('index', 'create', 'store', 'show', 'destroy'); // 文章通知资源路由 - // 发布文章通知 - $router->resource('article_notifications', 'ArticleNotificationController')->only('index', 'create', 'store', 'show', 'destroy'); + // 富文本编辑器图片上传 + $router->post('upload/editor', 'UploadController@uploadByEditor'); // 图片上传路由 - // 富文本图片上传 - $router->post('upload/editor', 'UploadController@uploadByEditor'); // 通过分类异步加载商品下拉列表 - $router->get('api/products', 'CategoryController@getProducts'); + $router->get('api/products', 'CategoryController@getProducts'); // 获取产品列表的 API 路由 }); diff --git a/app/Console/Commands/AddShopToEsSearchCommand.php b/app/Console/Commands/AddShopToEsSearchCommand.php index f156835..b796b93 100644 --- a/app/Console/Commands/AddShopToEsSearchCommand.php +++ b/app/Console/Commands/AddShopToEsSearchCommand.php @@ -1,117 +1,98 @@ ping([ 'client' => [ - 'timeout' => 5, - - 'connect_timeout' => 5 + 'timeout' => 5, // 设置请求超时时间 + 'connect_timeout' => 5 // 设置连接超时时间 ] ]); } catch (\Exception $exception) { - - - + // 捕获连接异常并输出错误信息 $this->info($exception->getMessage()); - - - - $this->info('无法连接到 elasticse - - - - arch 服务器,请配置 config/elasticsearch.php 文件'); - + $this->info('无法连接到 Elasticsearch 服务器,请配置 config/elasticsearch.php 文件'); $this->info('默认使用 MySQL 的模糊搜索'); $this->info('配置完毕后可运行: php artisan add:shop-to-search 添加索引'); - - - - return; + return; // 退出命令 } - // 新建商品索引 if (Product::indexExists()) { - - - + // 如果索引已存在,则删除索引 Product::deleteIndex(); $this->info('删除索引'); } + // 创建新的索引 Product::createIndex(); $this->info('新建索引成功'); - - // 开始导入数据 - $query = Product::query(); + $query = Product::query(); // 创建商品查询 - $count = $query->count(); - $handle = 0; + $count = $query->count(); // 获取商品总数 + $handle = 0; // 初始化处理计数 + // 使用 chunk 方法分批处理商品数据 $query->with('category')->chunk(1000, function (Collection $models) use ($count, &$handle) { - + // 遍历每个商品模型 $models->map(function (Product $product) use ($count, &$handle) { - + // 将商品添加到索引 $product->addToIndex($product->getSearchData()); - - ++ $handle; - echo "\r {$handle}/$count"; + ++$handle; // 处理计数加一 + echo "\r {$handle}/$count"; // 输出当前处理进度 }); }); + echo PHP_EOL; // 换行 - - echo PHP_EOL; - - $this->info('索引生成完毕'); + $this->info('索引生成完毕'); // 输出完成信息 } } diff --git a/app/Console/Commands/BaseCommand.php b/app/Console/Commands/BaseCommand.php index 900f338..759e8f0 100644 --- a/app/Console/Commands/BaseCommand.php +++ b/app/Console/Commands/BaseCommand.php @@ -1,40 +1,54 @@ info('----------'); // 打印分隔线 + $this->info($command); // 打印要执行的命令 - $this->info('----------'); - $this->info($command); - + // 执行 shell 命令并获取输出 $output = shell_exec($command); - $this->info($output); + $this->info($output); // 打印命令的输出结果 } - } diff --git a/app/Console/Commands/CacheOptimize.php b/app/Console/Commands/CacheOptimize.php index d447a20..5ad15fa 100644 --- a/app/Console/Commands/CacheOptimize.php +++ b/app/Console/Commands/CacheOptimize.php @@ -1,44 +1,51 @@ call('config:cache'); - // 优化路由 - $this->call('route:cache'); + // 优化配置并缓存配置文件 + $this->call('config:cache'); // 调用 Laravel 的 config:cache 命令 + + // 优化路由并缓存路由信息 + $this->call('route:cache'); // 调用 Laravel 的 route:cache 命令 } } diff --git a/app/Console/Commands/ClearCache.php b/app/Console/Commands/ClearCache.php index 0820a0d..1ca96a6 100644 --- a/app/Console/Commands/ClearCache.php +++ b/app/Console/Commands/ClearCache.php @@ -1,42 +1,54 @@ call('config:clear'); - $this->call('route:clear'); - $this->call('view:clear'); + // 清除配置缓存 + $this->call('config:clear'); // 调用 Laravel 的 config:clear 命令 + + // 清除路由缓存 + $this->call('route:clear'); // 调用 Laravel 的 route:clear 命令 + + // 清除视图缓存 + $this->call('view:clear'); // 调用 Laravel 的 view:clear 命令 } } diff --git a/app/Console/Commands/CopyFile.php b/app/Console/Commands/CopyFile.php index 38a15db..4b38875 100644 --- a/app/Console/Commands/CopyFile.php +++ b/app/Console/Commands/CopyFile.php @@ -1,66 +1,75 @@ filesystem = $filesystem; + $this->filesystem = $filesystem; // 注入 Filesystem 实例 - parent::__construct(); + parent::__construct(); // 调用父类构造函数 } /** * 把静态资源发布到 public/storage 目录 * + * 该方法执行复制静态资源的逻辑,包括产品图片、默认头像和其他静态图片。 + * * @return mixed */ public function handle() { - // 图片的静态目录 - $from = storage_path('app/resources/products'); - $to = storage_path('app/public/products'); - $this->filesystem->copyDirectory($from, $to); + // 定义图片的静态目录及目标目录 + $from = storage_path('app/resources/products'); // 源目录:产品图片 + $to = storage_path('app/public/products'); // 目标目录:公共产品图片 + $this->filesystem->copyDirectory($from, $to); // 复制产品图片目录 - // 默认头像 - $from = storage_path('app/resources/avatars'); - $to = storage_path('app/public/avatars'); - $this->filesystem->copyDirectory($from, $to); + // 复制默认头像 + $from = storage_path('app/resources/avatars'); // 源目录:默认头像 + $to = storage_path('app/public/avatars'); // 目标目录:公共头像 + $this->filesystem->copyDirectory($from, $to); // 复制默认头像目录 - // 默认头像 - $from = storage_path('app/resources/images'); - $to = storage_path('app/public/images'); - $this->filesystem->copyDirectory($from, $to); + // 复制其他静态图片 + $from = storage_path('app/resources/images'); // 源目录:其他静态图片 + $to = storage_path('app/public/images'); // 目标目录:公共静态图片 + $this->filesystem->copyDirectory($from, $to); // 复制其他静态图片目录 - $this->info('copy file success'); + // 输出成功信息 + $this->info('copy file success'); // 命令执行成功后的提示信息 } } diff --git a/app/Console/Commands/CountSite.php b/app/Console/Commands/CountSite.php index ad732de..99b5112 100644 --- a/app/Console/Commands/CountSite.php +++ b/app/Console/Commands/CountSite.php @@ -1,59 +1,70 @@ subDay(1)->toDateString(); + // 获取昨天的日期 + $date = Carbon::now()->subDay(1)->toDateString(); // 获取当前日期并减去一天 /** * 防止一天运行多次,所以采用增加 * * @var $site SiteCount */ - $site = SiteCount::query()->firstOrNew(compact('date')); - $site = $service->syncByCache($site, true); - $site->save(); + // 查找或创建一个新的 SiteCount 实例,基于日期 + $site = SiteCount::query()->firstOrNew(compact('date')); // 如果没有记录则创建新记录 + + // 使用服务同步数据并保存 + $site = $service->syncByCache($site, true); // 同步数据,传入 $site 实例和强制更新标志 + $site->save(); // 保存统计数据到数据库 - createSystemLog('系统统计站点数据', $site->toArray()); + // 记录系统日志 + createSystemLog('系统统计站点数据', $site->toArray()); // 记录操作日志,包含统计的数据 } } diff --git a/app/Console/Commands/DelExpireScoreData.php b/app/Console/Commands/DelExpireScoreData.php index 44990dc..92e0186 100644 --- a/app/Console/Commands/DelExpireScoreData.php +++ b/app/Console/Commands/DelExpireScoreData.php @@ -1,41 +1,47 @@ subDay()->toDateString(); + $yesterday = Carbon::today()->subDay()->toDateString(); // 获取昨天的日期字符串 - $serve = new ScoreLogServe(); + // 创建 ScoreLogServe 实例 + $serve = new ScoreLogServe(); // 实例化服务以处理积分日志 - Cache::delete($serve->loginKey($yesterday)); + // 删除缓存中的过期积分数据 + Cache::delete($serve->loginKey($yesterday)); // 根据昨天的日期生成键并删除对应的缓存数据 - createSystemLog("系统删除{$yesterday}过期积分统计数据", ['date' => $yesterday]); + // 记录系统日志 + createSystemLog("系统删除{$yesterday}过期积分统计数据", ['date' => $yesterday]); // 记录删除操作的日志 } } diff --git a/app/Console/Commands/DelExpireSecKill.php b/app/Console/Commands/DelExpireSecKill.php index a7fbf4d..c008592 100644 --- a/app/Console/Commands/DelExpireSecKill.php +++ b/app/Console/Commands/DelExpireSecKill.php @@ -1,92 +1,96 @@ where('is_rollback', 0) - ->where('end_at', '<', Carbon::now()->toDateTimeString()) - ->get() + ->where('is_rollback', 0) // 选择未回滚的秒杀 + ->where('end_at', '<', Carbon::now()->toDateTimeString()) // 选择已过期的秒杀 + ->get() // 获取符合条件的秒杀记录 ->map(function (Seckill $seckill) use ($rollbacks) { // 1. 回滚数量到商品 // 2. 设置为过期 - $product = $seckill->product()->first(); + $product = $seckill->product()->first(); // 获取与秒杀相关联的商品 - - // 获取 redis 数量 - $jsonSeckill = Redis::get($seckill->getRedisModelKey()); - $redisSeckill = json_decode($jsonSeckill, true); - // 获取剩余秒杀量 - $surplus = Redis::llen($seckill->getRedisQueueKey()); + // 获取 Redis 中的秒杀数量 + $jsonSeckill = Redis::get($seckill->getRedisModelKey()); // 从 Redis 获取秒杀数据 + $redisSeckill = json_decode($jsonSeckill, true); // 将 JSON 数据解码为数组 + // 获取剩余的秒杀量 + $surplus = Redis::llen($seckill->getRedisQueueKey()); // 从 Redis 获取剩余秒杀量 // 恢复剩余的库存量 // 恢复库存数量 - if ($redisSeckill['sale_count'] != 0) { - $product->increment('sale_count', $redisSeckill['sale_count']); + if ($redisSeckill['sale_count'] != 0) { // 如果 Redis 中的销售数量不为零 + $product->increment('sale_count', $redisSeckill['sale_count']); // 增加商品的销售数量 } - if ($surplus != 0) { - $product->increment('count', $surplus); + if ($surplus != 0) { // 如果剩余秒杀量不为零 + $product->increment('count', $surplus); // 增加商品的总库存数量 } + // 同步 Redis 数据到数据库中 + $seckill->sale_count += $redisSeckill['sale_count']; // 更新秒杀的销售数量 + $seckill->rollback_count += $surplus; // 更新秒杀的回滚数量 + $seckill->is_rollback = 1; // 标记为已回滚 + $seckill->save(); // 保存更新后的秒杀记录 - // 同步 redis 数据到数据库中 - $seckill->sale_count += $redisSeckill['sale_count']; - $seckill->rollback_count += $surplus; - $seckill->is_rollback = 1; - $seckill->save(); - - $rollbacks->push($seckill); + $rollbacks->push($seckill); // 将已回滚的秒杀记录添加到集合中 // 删除掉秒杀数据 - $ids = Redis::connection()->keys("seckills:{$seckill->id}:*"); - Redis::del($ids); + $ids = Redis::connection()->keys("seckills:{$seckill->id}:*"); // 获取与秒杀相关的所有 Redis 键 + Redis::del($ids); // 删除这些 Redis 键 }); - if ($rollbacks->isNotEmpty()) { - - createSystemLog('系统回滚秒杀数据', $rollbacks->toArray()); + if ($rollbacks->isNotEmpty()) { // 如果有回滚的秒杀记录 + createSystemLog('系统回滚秒杀数据', $rollbacks->toArray()); // 记录系统回滚操作的日志 } } } diff --git a/app/Console/Commands/DeleteFile.php b/app/Console/Commands/DeleteFile.php index 9ac5590..b9e6fcb 100644 --- a/app/Console/Commands/DeleteFile.php +++ b/app/Console/Commands/DeleteFile.php @@ -1,46 +1,56 @@ info('delete file success'); + // 输出成功信息 + $this->info('delete file success'); // 命令执行成功后的提示信息 } } diff --git a/app/Console/Commands/ExportDatabaseCommand.php b/app/Console/Commands/ExportDatabaseCommand.php index b6aae85..f2b2899 100644 --- a/app/Console/Commands/ExportDatabaseCommand.php +++ b/app/Console/Commands/ExportDatabaseCommand.php @@ -1,56 +1,64 @@ oldest() - ->get() + ->oldest() // 按照创建时间升序排列 + ->get() // 获取所有用户记录 ->transform(function (User $user) { - // 先排除自身主键 - $user->offsetUnset($user->getKeyName()); + $user->offsetUnset($user->getKeyName()); // 从用户模型中移除主键字段 - return $user; + return $user; // 返回处理后的用户对象 }); - file_put_contents(\UsersTableSeeder::DATA_PATH, $users->toJson(JSON_UNESCAPED_UNICODE)); + // 将用户数据转换为 JSON 格式并写入指定文件 + file_put_contents(\UsersTableSeeder::DATA_PATH, $users->toJson(JSON_UNESCAPED_UNICODE)); // 保存 JSON 数据到文件 } } diff --git a/app/Console/Commands/InstallShop.php b/app/Console/Commands/InstallShop.php index 0a98115..19d70c1 100644 --- a/app/Console/Commands/InstallShop.php +++ b/app/Console/Commands/InstallShop.php @@ -1,71 +1,80 @@ call('key:generate'); + // 删除上一次保留的数据表 - $this->call('migrate:reset'); + $this->call('migrate:reset'); // 重置数据库迁移,删除所有表 + // 删除上一次保留的文件 - $this->call('moon:delete'); - - + $this->call('moon:delete'); // 删除之前的文件或数据 + + // 禁止在安装过程中将产品添加到搜索索引 Product::$addToSearch = false; - + /**************************************** * 1. 迁移数据表 * 2. 数据库迁移 * 3. 复制静态资源 * 4. 创建软链接 - */ - $this->call('migrate'); - $this->call('db:seed'); - $this->call('moon:copy'); - $this->call('storage:link'); + ****************************************/ + $this->call('migrate'); // 执行数据库迁移,创建所需的数据表 + $this->call('db:seed'); // 填充数据库,插入初始数据 + $this->call('moon:copy'); // 复制静态资源到公共目录 + $this->call('storage:link'); // 创建存储目录的软链接,以便访问存储的文件 + + // 更新首页数据,防止上一次遗留数据的影响 + $this->call('moon:update-home'); // 更新首页相关数据 - // 更新首页数据,防止上一次遗留 - $this->call('moon:update-home'); - // 生成全文索引 - $this->call('add:shop-to-search'); + $this->call('add:shop-to-search'); // 为商城产品生成搜索索引 // 直接开启监听队列 // $this->info('queue starting please don`t close cmd windows!!!'); - // $this->call('queue:work', ['--tries' => '3']); + // $this->call('queue:work', ['--tries' => '3']); // 启动队列工作进程,处理队列任务 } } diff --git a/app/Console/Commands/SendSubscribeEmail.php b/app/Console/Commands/SendSubscribeEmail.php index 136c1c6..4c14bf5 100644 --- a/app/Console/Commands/SendSubscribeEmail.php +++ b/app/Console/Commands/SendSubscribeEmail.php @@ -1,55 +1,70 @@ where('is_subscribe', 1)->pluck('email'); + // 查询所有已订阅的用户邮箱 + $mails = Subscribe::query() + ->where('is_subscribe', 1) // 只选择已订阅的用户 + ->pluck('email'); // 获取邮箱地址列表 + // 遍历每个邮箱并发送通知邮件 $mails->map(function ($realMail) { - + // 对邮箱进行加密处理 $email = encrypt($realMail); + // 生成包含加密邮箱的邮件链接 $url = route('site.email', compact('email')); - // 不要一次 to 多个用户,会暴露其他人的邮箱 + + // 发送邮件给当前用户 + // 不要一次发送给多个用户,以免暴露其他人的邮箱 Mail::to($realMail)->send(new SubscribesNotice($url)); }); + // 记录系统日志,记录发送的用户信息 createSystemLog('系统发送订阅消息, 发送的用户:' . $mails->implode(', '), $mails->toArray()); } } diff --git a/app/Console/Commands/SyncProducViewCommand.php b/app/Console/Commands/SyncProducViewCommand.php index ec0fe30..2e0f0d7 100644 --- a/app/Console/Commands/SyncProducViewCommand.php +++ b/app/Console/Commands/SyncProducViewCommand.php @@ -1,78 +1,69 @@ toDateStr - - - - - ing(); - - $products = Product::query()->where('today_has_view', 1)->get(); - + // 获取昨天的日期字符串 + $yesterday = Carbon::yesterday()->toDateString(); // 获取昨天的日期,格式为 YYYY-MM-DD + // 查询所有今天有浏览量记录的商品 + $products = Product::query()->where('today_has_view', 1)->get(); // 获取所有今天有浏览量的商品 + // 遍历每个商品并更新浏览量 $products->map(function (Product $product) use ($yesterday) { - - - - - + // 从缓存中取出前一天的浏览量,默认值为 0 $viewCount = Cache::pull($product->getViewCountKey($yesterday), 0); - $product->view_count += $vi - ewCount; - $product->today_has_view = 0; - $product->save(); + // 更新商品的浏览量 + $product->view_count += $viewCount; // 累加前一天的浏览量 + $product->today_has_view = 0; // 重置今天的浏览量标记 + $product->save(); // 保存更新后的商品信息 }); - - - createSystemLog("系统同步{$yesterday}商品浏览量", ['date' => $yesterday]); + // 记录系统日志,记录同步操作的信息 + createSystemLog("系统同步{$yesterday}商品浏览量", ['date' => $yesterday]); // 记录同步的日期 } - - } diff --git a/app/Console/Commands/UninstallShop.php b/app/Console/Commands/UninstallShop.php index bfaff6f..b4269ef 100644 --- a/app/Console/Commands/UninstallShop.php +++ b/app/Console/Commands/UninstallShop.php @@ -1,48 +1,54 @@ call('moon:clear'); + + // 调用迁移重置命令,重置数据库迁移 $this->call('migrate:reset'); - // delete all upload static resources + // 删除所有上传的静态资源 $this->call('moon:delete'); } } diff --git a/app/Console/Commands/UpdateCacheHomeData.php b/app/Console/Commands/UpdateCacheHomeData.php index 774eb81..bb5d23d 100644 --- a/app/Console/Commands/UpdateCacheHomeData.php +++ b/app/Console/Commands/UpdateCacheHomeData.php @@ -1,72 +1,70 @@ command(SendSubscribeEmail::class)->saturdays()->at('8:00'); - // 每天统计注册人数, 销售数量 + + // 每天凌晨 1 点统计注册人数和销售数量 $schedule->command(CountSite::class)->dailyAt('01:00'); - // 每小时执行一次, 回滚秒杀过期的数据 + + // 每小时执行一次,回滚秒杀过期的数据 $schedule->command(DelExpireSecKill::class)->hourly(); - // 每天夜里十二点执行删除昨天过期的积分数据 + // 每天午夜 12 点删除昨天过期的积分数据 $schedule->command(DelExpireScoreData::class)->dailyAt('00:00'); - // 每天夜里十二点同步商品浏览量 + + // 每天午夜 12 点 10 分同步商品浏览量 $schedule->command(SyncProducViewCommand::class)->dailyAt('00:10'); // 每分钟更新一次首页数据 @@ -47,14 +56,16 @@ class Kernel extends ConsoleKernel } /** - * Register the commands for the application. + * 注册应用程序的命令 * * @return void */ protected function commands() { + // 加载命令目录下的所有命令 $this->load(__DIR__.'/Commands'); + // 引入控制台路由文件 require base_path('routes/console.php'); } }