Compare commits

...

6 Commits

Author SHA1 Message Date
HYJ 337d0faae6 i
8 months ago
HYJ 7d2de61990 y
8 months ago
HYJ 83fa45aef5 p
8 months ago
HYJ 87ec971162
8 months ago
HYJ 019a95d00a
8 months ago
HYJ bc65a79818
8 months ago

@ -16,56 +16,57 @@ class CancelUnPayOrder implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $order;
protected $order; // Property to hold the order instance
/**
* Create a new job instance.
*
* @param Order $order
* @param Order $order The order that needs to be processed
*/
public function __construct(Order $order)
{
$this->order = $order;
$this->order = $order; // Initialize the order property
}
/**
* Execute the job.
*
* This method is called when the job is processed. It checks the status of the order
* and cancels it if it remains unpaid.
*
* @return void
*/
public function handle()
{
// 查询数据库最新状态
// Refresh the order instance from the database to get the latest status
$nowOrder = $this->order->refresh();
// 如果现在还是没有付款,那么则取消订单
// Check if the current status is UN_PAY (unpaid)
if ($nowOrder->status == OrderStatusEnum::UN_PAY) {
// 如果订单还是没有付款
// 未付款设置为取消状态,
// Update the order status to UN_PAY_CANCEL (cancelled due to non-payment)
$this->order->status = OrderStatusEnum::UN_PAY_CANCEL;
$this->order->save();
$this->order->save(); // Save the updated order status
// 回退优惠券
// Process coupon rollback if a coupon was used
if (
!is_null($this->order->coupon_id) &&
$coupon = UserHasCoupon::query()->find($this->order->coupon_id)
!is_null($this->order->coupon_id) && // Ensure a coupon ID exists
$coupon = UserHasCoupon::query()->find($this->order->coupon_id) // Find the coupon in the database
) {
// Reset the coupon usage timestamp
$coupon->used_at = null;
$coupon->save();
$coupon->save(); // Save changes to the coupon
}
// 回滚库存
// Rollback inventory for each order detail
$this->order
->details()
->with('product')
->get()
->details() // Get the order details
->with('product') // Eager load the associated product
->get() // Fetch the details
->map(function (OrderDetail $detail) {
// 不回滚出售数量
$product = $detail->product;
$product->increment('count', $detail->number);
// For each order detail, increment the product's count by the ordered quantity
$product = $detail->product; // Get the associated product
$product->increment('count', $detail->number); // Increase product count
});
}
}

@ -16,27 +16,29 @@ class InstallShopWarn implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $user;
protected $user; // 存储用户实例的属性
/**
* Create a new job instance.
* 创建一个新的任务实例。
*
* @param User $user
* @param User $user 用户对象
*/
public function __construct(User $user)
{
$this->user = $user;
$this->user = $user; // 初始化用户属性
}
/**
* Execute the job.
* 执行任务。
*
* 此方法在处理任务时调用,用于记录网站启动信息。
*
* @return void
*/
public function handle()
{
$time = date('Y-m-d H:i:s');
$msg = '网站已启动|启动时间: ' . $time;
Log::info($msg);
$time = date('Y-m-d H:i:s'); // 获取当前时间
$msg = '网站已启动|启动时间: ' . $time; // 构建日志消息
Log::info($msg); // 将消息记录到日志中
}
}

@ -42,6 +42,8 @@ class RemindUsersHasSeckill implements ShouldQueue
// 拿出收藏的用户
$product = $this->seckill->product;
$product->users()
->get()
->map(function (User $user) use ($product) {
@ -50,5 +52,14 @@ class RemindUsersHasSeckill implements ShouldQueue
});
}
}

Loading…
Cancel
Save