pull/4/head
parent
d0eae0fcb2
commit
73ffb0e3c3
@ -1,44 +1,47 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Admin\Extensions;
|
||||
|
||||
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Contracts\Support\Renderable; // 引入 Renderable 接口
|
||||
|
||||
class Div implements Renderable
|
||||
{
|
||||
|
||||
protected $id;
|
||||
protected $width = '100%';
|
||||
protected $height = '300px';
|
||||
protected $id; // div 元素的 ID
|
||||
protected $width = '100%'; // div 元素的宽度,默认值为 100%
|
||||
protected $height = '300px'; // div 元素的高度,默认值为 300px
|
||||
|
||||
/**
|
||||
* Div constructor.
|
||||
*
|
||||
* @param $id
|
||||
* @param string $width
|
||||
* @param string $height
|
||||
* @param string $id div 元素的 ID
|
||||
* @param string|null $width div 元素的宽度,默认为 null
|
||||
* @param string|null $height div 元素的高度,默认为 null
|
||||
*/
|
||||
public function __construct($id, $width = null, $height = null)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->id = $id; // 设置 div 的 ID
|
||||
|
||||
// 如果提供了宽度,则设置宽度
|
||||
if (!is_null($width)) {
|
||||
$this->width = $width;
|
||||
$this->width = $width; // 更新 div 的宽度
|
||||
}
|
||||
|
||||
// 如果提供了高度,则设置高度
|
||||
if (!is_null($height)) {
|
||||
$this->height = $height;
|
||||
$this->height = $height; // 更新 div 的高度
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 渲染 div 元素的 HTML.
|
||||
*
|
||||
* @return string 返回包含 div 的 HTML 字符串
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
// 使用 heredoc 语法返回包含 div 的 HTML 代码
|
||||
return <<<div
|
||||
<div id="{$this->id}" style="width: {$this->width}; height: {$this->height}"></div>
|
||||
div;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,69 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Admin\Extensions;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use Encore\Admin\Form\Field;
|
||||
use Illuminate\Support\Collection; // 引入集合类
|
||||
use Encore\Admin\Form\Field; // 引入表单字段基类
|
||||
|
||||
class WangEditor extends Field
|
||||
{
|
||||
protected $view = 'admin.wang-editor';
|
||||
protected $view = 'admin.wang-editor'; // 定义视图文件路径
|
||||
|
||||
// 引入 WangEditor 的 CSS 文件
|
||||
protected static $css = [
|
||||
'/vendor/wangEditor-3.1.1/release/wangEditor.css',
|
||||
];
|
||||
|
||||
// 引入 WangEditor 的 JS 文件
|
||||
protected static $js = [
|
||||
'/vendor/wangEditor-3.1.1/release/wangEditor.js',
|
||||
];
|
||||
|
||||
/**
|
||||
* 渲染 WangEditor 编辑器.
|
||||
*
|
||||
* @return string 返回渲染后的 HTML
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
// 格式化字段名称
|
||||
$name = $this->formatName($this->column);
|
||||
// 获取 CSRF 令牌
|
||||
$token = csrf_token();
|
||||
// 定义上传图片的服务器地址
|
||||
$url = admin_base_path('upload/editor');
|
||||
|
||||
// 定义 JavaScript 代码,初始化 WangEditor
|
||||
$this->script = <<<EOT
|
||||
|
||||
var E = window.wangEditor
|
||||
var editor = new E('#{$this->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
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Transforms;
|
||||
namespace App\Admin\Transforms; // 定义命名空间
|
||||
|
||||
use App\Enums\OrderPayTypeEnum; // 引入订单支付类型枚举类
|
||||
use App\Enums\OrderShipStatusEnum; // 引入订单发货状态枚举类(未使用)
|
||||
use App\Enums\OrderStatusEnum; // 引入订单状态枚举类(未使用)
|
||||
use App\Enums\OrderTypeEnum; // 引入订单类型枚举类(未使用)
|
||||
use App\Models\Order; // 引入订单模型(未使用)
|
||||
|
||||
use App\Enums\OrderPayTypeEnum;
|
||||
use App\Enums\OrderShipStatusEnum;
|
||||
use App\Enums\OrderStatusEnum;
|
||||
use App\Enums\OrderTypeEnum;
|
||||
use App\Models\Order;
|
||||
|
||||
/**
|
||||
* 订单支付类型转换类
|
||||
*
|
||||
* 该类用于将订单支付类型的枚举值转换为可读的字符串形式。
|
||||
*/
|
||||
class OrderPayTypeTransform implements Transform
|
||||
{
|
||||
/**
|
||||
* 将支付类型转换为对应的可读字符串
|
||||
*
|
||||
* @param mixed $type 支付类型的枚举值
|
||||
* @return string 返回对应的支付方式名称
|
||||
*/
|
||||
public static function trans($type)
|
||||
{
|
||||
$text = '';
|
||||
$text = ''; // 初始化返回的字符串
|
||||
|
||||
// 根据支付类型的枚举值进行判断并设置对应的字符串
|
||||
if ($type == OrderPayTypeEnum::ALI) {
|
||||
$text = '支付宝';
|
||||
$text = '支付宝'; // 支付宝支付
|
||||
} elseif ($type == OrderPayTypeEnum::WECHAT) {
|
||||
$text = '微信';
|
||||
$text = '微信'; // 微信支付
|
||||
}
|
||||
|
||||
return $text;
|
||||
return $text; // 返回转换后的支付方式名称
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Transforms;
|
||||
namespace App\Admin\Transforms; // 定义命名空间
|
||||
|
||||
use App\Enums\OrderShipStatusEnum; // 引入订单发货状态枚举类
|
||||
use App\Enums\OrderStatusEnum; // 引入订单状态枚举类(未使用)
|
||||
use App\Enums\OrderTypeEnum; // 引入订单类型枚举类(未使用)
|
||||
use App\Models\Order; // 引入订单模型(未使用)
|
||||
|
||||
use App\Enums\OrderShipStatusEnum;
|
||||
use App\Enums\OrderStatusEnum;
|
||||
use App\Enums\OrderTypeEnum;
|
||||
use App\Models\Order;
|
||||
|
||||
/**
|
||||
* 订单发货状态转换类
|
||||
*
|
||||
* 该类用于将订单发货状态的枚举值转换为可读的字符串形式。
|
||||
*/
|
||||
class OrderShipStatusTransform implements Transform
|
||||
{
|
||||
/**
|
||||
* 将发货状态转换为对应的可读字符串
|
||||
*
|
||||
* @param mixed $status 发货状态的枚举值
|
||||
* @return string 返回对应的发货状态名称
|
||||
*/
|
||||
public static function trans($status)
|
||||
{
|
||||
// 根据发货状态的枚举值进行判断并设置对应的字符串
|
||||
switch ($status) {
|
||||
|
||||
case OrderShipStatusEnum::PENDING:
|
||||
$text = '未发货';
|
||||
$text = '未发货'; // 订单尚未发货
|
||||
break;
|
||||
case OrderShipStatusEnum::DELIVERED:
|
||||
$text = '待收货';
|
||||
$text = '待收货'; // 订单已发货,等待用户收货
|
||||
break;
|
||||
case OrderShipStatusEnum::RECEIVED:
|
||||
$text = '已收货';
|
||||
$text = '已收货'; // 用户已确认收货
|
||||
break;
|
||||
default:
|
||||
$text = '未知状态';
|
||||
$text = '未知状态'; // 未知的发货状态
|
||||
break;
|
||||
}
|
||||
|
||||
return $text;
|
||||
return $text; // 返回转换后的发货状态名称
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Transforms;
|
||||
namespace App\Admin\Transforms; // 定义命名空间
|
||||
|
||||
use App\Enums\OrderShipStatusEnum; // 引入订单发货状态枚举类(未使用)
|
||||
use App\Enums\OrderStatusEnum; // 引入订单状态枚举类
|
||||
use App\Enums\OrderTypeEnum; // 引入订单类型枚举类(未使用)
|
||||
use App\Models\Order; // 引入订单模型(未使用)
|
||||
|
||||
use App\Enums\OrderShipStatusEnum;
|
||||
use App\Enums\OrderStatusEnum;
|
||||
use App\Enums\OrderTypeEnum;
|
||||
use App\Models\Order;
|
||||
|
||||
/**
|
||||
* 订单状态转换类
|
||||
*
|
||||
* 该类用于将订单状态的枚举值转换为可读的字符串形式。
|
||||
*/
|
||||
class OrderStatusTransform implements Transform
|
||||
{
|
||||
/**
|
||||
* 将订单状态转换为对应的可读字符串
|
||||
*
|
||||
* @param mixed $status 订单状态的枚举值
|
||||
* @return string 返回对应的订单状态名称
|
||||
*/
|
||||
public static function trans($status)
|
||||
{
|
||||
// 根据订单状态的枚举值进行判断并设置对应的字符串
|
||||
switch ($status) {
|
||||
|
||||
case OrderStatusEnum::UN_PAY_CANCEL:
|
||||
$text = '取消';
|
||||
$text = '取消'; // 订单已被取消
|
||||
break;
|
||||
case OrderStatusEnum::REFUND:
|
||||
$text = '退款';
|
||||
$text = '退款'; // 订单已退款
|
||||
break;
|
||||
case OrderStatusEnum::APPLY_REFUND:
|
||||
$text = '申请退款';
|
||||
$text = '申请退款'; // 用户已申请退款
|
||||
break;
|
||||
case OrderStatusEnum::UN_PAY:
|
||||
$text = '未支付';
|
||||
$text = '未支付'; // 订单尚未支付
|
||||
break;
|
||||
case OrderStatusEnum::PAID:
|
||||
$text = '已支付';
|
||||
$text = '已支付'; // 订单已成功支付
|
||||
break;
|
||||
case OrderStatusEnum::TIMEOUT_CANCEL:
|
||||
$text = '超时未付款系统自动取消';
|
||||
$text = '超时未付款系统自动取消'; // 订单因超时未付款被系统自动取消
|
||||
break;
|
||||
case OrderStatusEnum::COMPLETED:
|
||||
$text = '完成';
|
||||
$text = '完成'; // 订单已完成
|
||||
break;
|
||||
default:
|
||||
$text = '未知状态';
|
||||
$text = '未知状态'; // 未知的订单状态
|
||||
break;
|
||||
}
|
||||
|
||||
return $text;
|
||||
return $text; // 返回转换后的订单状态名称
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Transforms;
|
||||
namespace App\Admin\Transforms; // 定义命名空间
|
||||
|
||||
use App\Enums\OrderShipStatusEnum; // 引入订单发货状态枚举类(未使用)
|
||||
use App\Enums\OrderStatusEnum; // 引入订单状态枚举类(未使用)
|
||||
use App\Enums\OrderTypeEnum; // 引入订单类型枚举类
|
||||
use App\Models\Order; // 引入订单模型(未使用)
|
||||
|
||||
use App\Enums\OrderShipStatusEnum;
|
||||
use App\Enums\OrderStatusEnum;
|
||||
use App\Enums\OrderTypeEnum;
|
||||
use App\Models\Order;
|
||||
|
||||
/**
|
||||
* 订单类型转换类
|
||||
*
|
||||
* 该类用于将订单类型的枚举值转换为可读的字符串形式。
|
||||
*/
|
||||
class OrderTypeTransform implements Transform
|
||||
{
|
||||
/**
|
||||
* 将订单类型转换为对应的可读字符串
|
||||
*
|
||||
* @param mixed $type 订单类型的枚举值
|
||||
* @return string 返回对应的订单类型名称
|
||||
*/
|
||||
public static function trans($type)
|
||||
{
|
||||
// 默认状态为'未知'
|
||||
$text = '未知';
|
||||
|
||||
// 根据订单类型的枚举值进行判断并设置对应的字符串
|
||||
if ($type == OrderTypeEnum::COMMON) {
|
||||
$text = '普通订单';
|
||||
$text = '普通订单'; // 订单类型为普通订单
|
||||
} elseif ($type == OrderTypeEnum::SEC_KILL) {
|
||||
$text = '秒杀订单';
|
||||
$text = '秒杀订单'; // 订单类型为秒杀订单
|
||||
}
|
||||
|
||||
return $text;
|
||||
return $text; // 返回转换后的订单类型名称
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Transforms;
|
||||
|
||||
namespace App\Admin\Transforms; // 定义命名空间
|
||||
|
||||
/**
|
||||
* 转换接口
|
||||
*
|
||||
* 该接口定义了一个转换方法,所有实现此接口的类都需提供具体的转换逻辑。
|
||||
*/
|
||||
interface Transform
|
||||
{
|
||||
/**
|
||||
* 转换方法
|
||||
*
|
||||
* @param mixed $trans 需要转换的值,可以是任何类型
|
||||
* @return mixed 返回转换后的值,类型可以根据具体实现而定
|
||||
*/
|
||||
public static function trans($trans);
|
||||
}
|
||||
|
@ -1,24 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Transforms;
|
||||
namespace App\Admin\Transforms; // 定义命名空间
|
||||
|
||||
use App\Enums\UserSexEnum; // 引入用户性别枚举类
|
||||
use App\Enums\UserStatusEnum; // 引入用户状态枚举类(未使用)
|
||||
use App\Models\User; // 引入用户模型(未使用)
|
||||
|
||||
use App\Enums\UserSexEnum;
|
||||
use App\Enums\UserStatusEnum;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* 用户性别转换类
|
||||
*
|
||||
* 该类用于将用户性别的枚举值转换为可读的字符串形式。
|
||||
*/
|
||||
class UserSexTransform implements Transform
|
||||
{
|
||||
/**
|
||||
* 将用户性别转换为对应的可读字符串
|
||||
*
|
||||
* @param mixed $sex 用户性别的枚举值
|
||||
* @return string 返回对应的用户性别名称
|
||||
*/
|
||||
public static function trans($sex)
|
||||
{
|
||||
// 默认状态为'未知'
|
||||
$text = '未知';
|
||||
|
||||
// 根据用户性别的枚举值进行判断并设置对应的字符串
|
||||
if ($sex == UserSexEnum::MAN) {
|
||||
$text = '男';
|
||||
$text = '男'; // 用户性别为男性
|
||||
} elseif ($sex == UserSexEnum::WOMAN) {
|
||||
$text = '女';
|
||||
$text = '女'; // 用户性别为女性
|
||||
}
|
||||
|
||||
return $text;
|
||||
return $text; // 返回转换后的用户性别名称
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Transforms;
|
||||
namespace App\Admin\Transforms; // 定义命名空间
|
||||
|
||||
use App\Enums\UserStatusEnum; // 引入用户状态枚举类(未使用)
|
||||
|
||||
use App\Enums\UserStatusEnum;
|
||||
|
||||
/**
|
||||
* 是/否转换类
|
||||
*
|
||||
* 该类用于将布尔值转换为相应的图标表示形式。
|
||||
*/
|
||||
class YesNoTransform implements Transform
|
||||
{
|
||||
/**
|
||||
* 将布尔值转换为对应的图标表示
|
||||
*
|
||||
* @param bool $is 布尔值,用于表示是或否
|
||||
* @return string 返回相应的 HTML 图标字符串
|
||||
*/
|
||||
public static function trans($is)
|
||||
{
|
||||
// 返回对应的图标,绿色勾表示“是”,红色叉表示“否”
|
||||
return $is
|
||||
? "<i style='color: green;' class=\"fa fa-check-circle\" aria-hidden=\"true\"></i>"
|
||||
: "<i style='color: red;' class=\"fa fa-times\" aria-hidden=\"true\"></i>";
|
||||
? "<i style='color: green;' class=\"fa fa-check-circle\" aria-hidden=\"true\"></i>" // 当 $is 为 true 时,返回绿色勾图标
|
||||
: "<i style='color: red;' class=\"fa fa-times\" aria-hidden=\"true\"></i>"; // 当 $is 为 false 时,返回红色叉图标
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +1,83 @@
|
||||
<?php
|
||||
|
||||
use App\Admin\Controllers\CouponLogController;
|
||||
use Illuminate\Routing\Router;
|
||||
use App\Admin\Controllers\CouponLogController; // 引入优惠券日志控制器
|
||||
use Illuminate\Routing\Router; // 引入路由器类
|
||||
|
||||
// 注册管理后台的认证路由
|
||||
Admin::registerAuthRoutes();
|
||||
|
||||
// 定义路由组
|
||||
Route::group([
|
||||
'prefix' => 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 路由
|
||||
});
|
||||
|
@ -1,117 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\SearchAble\ElasticSearchTrait;
|
||||
use Elasticsearch\ClientBuilder;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use App\Models\Product; // 引入商品模型
|
||||
use App\Models\SearchAble\ElasticSearchTrait; // 引入 Elasticsearch 特性
|
||||
use Elasticsearch\ClientBuilder; // 引入 Elasticsearch 客户端构建器
|
||||
use Illuminate\Console\Command; // 引入 Laravel 命令基类
|
||||
use Illuminate\Database\Eloquent\Collection; // 引入 Eloquent 集合类
|
||||
|
||||
/**
|
||||
* 将商品添加到 Elasticsearch 搜索的控制台命令
|
||||
*
|
||||
* 该命令用于将商品数据添加到 Elasticsearch 的全文索引中。
|
||||
*/
|
||||
class AddShopToEsSearchCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'add:shop-to-search';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '把商品添加到全文索引';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* 执行控制台命令.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
|
||||
try {
|
||||
|
||||
// 检查 Elasticsearch 服务器是否可用
|
||||
ElasticSearchTrait::client()->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('索引生成完毕'); // 输出完成信息
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Console\Command; // 引入 Laravel 命令基类
|
||||
|
||||
/**
|
||||
* 基础控制台命令类
|
||||
*
|
||||
* 该类提供了一个基础命令实现,包含执行 shell 命令并打印输出的功能。
|
||||
*/
|
||||
class BaseCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:base';
|
||||
protected $signature = 'moon:base'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'don`t use';
|
||||
protected $description = 'don`t use'; // 描述该命令的用途,当前设置为“不建议使用”
|
||||
|
||||
/**
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行 shell 命令并打印输出
|
||||
*
|
||||
* @param string $command 要执行的 shell 命令
|
||||
* @return void
|
||||
*/
|
||||
public function execShellWithPrint($command)
|
||||
{
|
||||
$this->info('----------'); // 打印分隔线
|
||||
$this->info($command); // 打印要执行的命令
|
||||
|
||||
$this->info('----------');
|
||||
$this->info($command);
|
||||
|
||||
// 执行 shell 命令并获取输出
|
||||
$output = shell_exec($command);
|
||||
|
||||
$this->info($output);
|
||||
$this->info($output); // 打印命令的输出结果
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,44 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
/**
|
||||
* 缓存优化控制台命令
|
||||
*
|
||||
* 该命令用于优化配置和路由缓存,以提高网站的运行速度。
|
||||
*/
|
||||
class CacheOptimize extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:cache';
|
||||
protected $signature = 'moon:cache'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Cache routing, configure information, to speed up the website running speed';
|
||||
protected $description = 'Cache routing, configure information, to speed up the website running speed'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行缓存命令
|
||||
*
|
||||
* 该方法用于处理缓存优化的逻辑,包括优化配置和路由缓存。
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// 优化配置
|
||||
$this->call('config:cache');
|
||||
// 优化路由
|
||||
$this->call('route:cache');
|
||||
// 优化配置并缓存配置文件
|
||||
$this->call('config:cache'); // 调用 Laravel 的 config:cache 命令
|
||||
|
||||
// 优化路由并缓存路由信息
|
||||
$this->call('route:cache'); // 调用 Laravel 的 route:cache 命令
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
/**
|
||||
* 清除缓存控制台命令
|
||||
*
|
||||
* 该命令用于清除应用程序中的缓存信息,包括配置缓存、路由缓存和视图缓存。
|
||||
*/
|
||||
class ClearCache extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:clear';
|
||||
protected $signature = 'moon:clear'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'clear moon:cache cache information';
|
||||
protected $description = 'clear moon:cache cache information'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有缓存
|
||||
*
|
||||
* 该方法用于处理缓存清除的逻辑,包括清除配置缓存、路由缓存和视图缓存。
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->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 命令
|
||||
}
|
||||
}
|
||||
|
@ -1,66 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use Illuminate\Filesystem\Filesystem; // 引入 Filesystem 类
|
||||
use Illuminate\Support\Facades\Storage; // 引入 Storage 门面(未使用,可以考虑移除)
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* 复制文件控制台命令
|
||||
*
|
||||
* 该命令用于将所有上传的静态资源复制到公共存储目录。
|
||||
*/
|
||||
class CopyFile extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:copy';
|
||||
protected $signature = 'moon:copy'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Copy all upload static resources';
|
||||
protected $description = 'Copy all upload static resources'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* 文件系统实例
|
||||
*
|
||||
* @var Filesystem
|
||||
*/
|
||||
protected $filesystem;
|
||||
protected $filesystem; // 声明文件系统实例变量
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @param Filesystem $filesystem
|
||||
* @param Filesystem $filesystem 文件系统实例
|
||||
*/
|
||||
public function __construct(Filesystem $filesystem)
|
||||
{
|
||||
$this->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'); // 命令执行成功后的提示信息
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use App\Models\SiteCount;
|
||||
use App\Services\SiteCountService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\SiteCount; // 引入 SiteCount 模型
|
||||
use App\Services\SiteCountService; // 引入 SiteCountService 服务
|
||||
use Carbon\Carbon; // 引入 Carbon 日期处理库
|
||||
use Illuminate\Console\Command; // 引入 Laravel 的 Command 基类
|
||||
use Illuminate\Support\Facades\Cache; // 引入 Cache 门面(未使用,可以考虑移除)
|
||||
|
||||
/**
|
||||
* 统计站点数据控制台命令
|
||||
*
|
||||
* 该命令用于统计站点数据,执行时会将统计数据记录到前一天。
|
||||
*/
|
||||
class CountSite extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:count-site';
|
||||
protected $signature = 'moon:count-site'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '统计数据,直接执行会统计到昨天';
|
||||
protected $description = '统计数据,直接执行会统计到昨天'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* 执行控制台命令
|
||||
*
|
||||
* @param SiteCountService $service
|
||||
* 该方法执行统计逻辑,统计前一天的数据并保存到数据库。
|
||||
*
|
||||
* @param SiteCountService $service 站点统计服务实例
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(SiteCountService $service)
|
||||
{
|
||||
// 每天凌晨统计昨天的数据
|
||||
$date = Carbon::now()->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()); // 记录操作日志,包含统计的数据
|
||||
}
|
||||
}
|
||||
|
@ -1,92 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use App\Models\Seckill;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Models\Seckill; // 引入 Seckill 模型
|
||||
use Carbon\Carbon; // 引入 Carbon 日期处理库
|
||||
use Illuminate\Console\Command; // 引入 Laravel 的 Command 基类
|
||||
use Illuminate\Support\Facades\Redis; // 引入 Redis 门面
|
||||
|
||||
/**
|
||||
* 删除过期秒杀数据控制台命令
|
||||
*
|
||||
* 该命令用于删除过期的秒杀数据,并将相关库存数量回滚到商品中。
|
||||
*/
|
||||
class DelExpireSecKill extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:del-seckills';
|
||||
protected $signature = 'moon:del-seckills'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* 删除过期的秒杀
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'delete expire seckills';
|
||||
protected $description = 'delete expire seckills'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* 执行控制台命令
|
||||
*
|
||||
* 该方法执行删除过期秒杀数据的逻辑,并回滚相关库存。
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$rollbacks = collect();
|
||||
$rollbacks = collect(); // 创建一个集合,用于存储回滚的秒杀记录
|
||||
|
||||
// 查出已经过期确没有回滚过的秒杀,
|
||||
// 查出已经过期且没有回滚过的秒杀
|
||||
Seckill::query()
|
||||
->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()); // 记录系统回滚操作的日志
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,46 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use Illuminate\Support\Facades\Storage; // 引入 Storage 门面
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* 删除文件控制台命令
|
||||
*
|
||||
* 该命令用于删除所有上传的静态资源文件。
|
||||
*/
|
||||
class DeleteFile extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:delete';
|
||||
protected $signature = 'moon:delete'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete all upload static resources';
|
||||
protected $description = 'Delete all upload static resources'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除静态资源文件
|
||||
*
|
||||
* 该方法执行删除操作,删除指定的静态资源目录及其内容。
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Storage::deleteDirectory('public' . DIRECTORY_SEPARATOR . config('web.upload.list'));
|
||||
Storage::deleteDirectory('public' . DIRECTORY_SEPARATOR . config('web.upload.detail'));
|
||||
// 删除上传列表目录
|
||||
Storage::deleteDirectory('public' . DIRECTORY_SEPARATOR . config('web.upload.list')); // 根据配置删除上传列表目录
|
||||
|
||||
// 删除上传详情目录
|
||||
Storage::deleteDirectory('public' . DIRECTORY_SEPARATOR . config('web.upload.detail')); // 根据配置删除上传详情目录
|
||||
|
||||
$this->info('delete file success');
|
||||
// 输出成功信息
|
||||
$this->info('delete file success'); // 命令执行成功后的提示信息
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Models\User; // 引入 User 模型
|
||||
use Illuminate\Console\Command; // 引入 Laravel 的 Command 基类
|
||||
use Illuminate\Database\Eloquent\Model; // 引入 Eloquent 模型基类
|
||||
use Illuminate\Support\Collection; // 引入 Collection 类
|
||||
|
||||
/**
|
||||
* 导出数据库命令
|
||||
*
|
||||
* 该命令用于将用户数据导出到 JSON 文件中。
|
||||
*/
|
||||
class ExportDatabaseCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:export';
|
||||
protected $signature = 'moon:export'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '导出数据到 json 文件';
|
||||
protected $description = '导出数据到 json 文件'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* 执行控制台命令
|
||||
*
|
||||
* 该方法执行导出用户数据的逻辑,将数据保存为 JSON 格式。
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// 查询所有用户并按创建时间升序排列
|
||||
$users = User::query()
|
||||
->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 数据到文件
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use App\Mail\SubscribesNotice;
|
||||
use App\Models\Subscribe;
|
||||
use Illuminate\Console\Command;
|
||||
use Mail;
|
||||
use App\Mail\SubscribesNotice; // 引入订阅通知邮件类
|
||||
use App\Models\Subscribe; // 引入订阅模型
|
||||
use Illuminate\Console\Command; // 引入 Laravel 的 Command 基类
|
||||
use Mail; // 引入 Mail 门面
|
||||
|
||||
/**
|
||||
* 发送订阅邮件命令
|
||||
*
|
||||
* 该命令用于向所有已订阅用户发送通知邮件。
|
||||
*/
|
||||
class SendSubscribeEmail extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:send-subscribes';
|
||||
protected $signature = 'moon:send-subscribes'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
protected $description = '发送订阅通知邮件'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* 执行控制台命令
|
||||
*
|
||||
* 该方法执行发送订阅邮件的逻辑,包括查询订阅用户和发送邮件。
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$mails = Subscribe::query()->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());
|
||||
}
|
||||
}
|
||||
|
@ -1,78 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
use App\Models\Product;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\Product; // 引入 Product 模型
|
||||
use Carbon\Carbon; // 引入 Carbon 日期处理库
|
||||
use Illuminate\Console\Command; // 引入 Laravel 的 Command 基类
|
||||
use Illuminate\Support\Facades\Cache; // 引入 Cache 门面
|
||||
|
||||
class SyncProducViewCommand extends Command
|
||||
/**
|
||||
* 同步商品浏览量命令
|
||||
*
|
||||
* 该命令用于同步前一天的商品浏览量,并更新数据库中的相关记录。
|
||||
*/
|
||||
class SyncProductViewCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:sync-product_view';
|
||||
protected $signature = 'moon:sync-product_view'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
protected $description = '同步商品浏览量'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* 执行控制台命令
|
||||
*
|
||||
* 该方法执行同步商品浏览量的逻辑,包括获取前一天的浏览量并更新数据库。
|
||||
*
|
||||
* @return mixed
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$yesterday = Carbon::yesterday()->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]); // 记录同步的日期
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,48 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
namespace App\Console\Commands; // 定义命名空间
|
||||
|
||||
/**
|
||||
* 卸载商城项目命令
|
||||
*
|
||||
* 该命令用于卸载商城项目,包括清理缓存、重置数据库迁移和删除上传的静态资源。
|
||||
*/
|
||||
class UninstallShop extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* 控制台命令的名称和签名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'moon:uninstall';
|
||||
protected $signature = 'moon:uninstall'; // 定义命令的名称和签名
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* 控制台命令的描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '卸载商城项目';
|
||||
protected $description = '卸载商城项目'; // 描述该命令的用途
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* 创建一个新的命令实例.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* 执行控制台命令
|
||||
*
|
||||
* 该方法执行卸载商城项目的逻辑,依次调用其他命令来完成任务。
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// 调用清理命令,清除缓存
|
||||
$this->call('moon:clear');
|
||||
|
||||
// 调用迁移重置命令,重置数据库迁移
|
||||
$this->call('migrate:reset');
|
||||
|
||||
// delete all upload static resources
|
||||
// 删除所有上传的静态资源
|
||||
$this->call('moon:delete');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue