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; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $order; protected $order; // Property to hold the order instance
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @param Order $order * @param Order $order The order that needs to be processed
*/ */
public function __construct(Order $order) public function __construct(Order $order)
{ {
$this->order = $order; $this->order = $order; // Initialize the order property
} }
/** /**
* Execute the job. * 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 * @return void
*/ */
public function handle() public function handle()
{ {
// 查询数据库最新状态 // Refresh the order instance from the database to get the latest status
$nowOrder = $this->order->refresh(); $nowOrder = $this->order->refresh();
// 如果现在还是没有付款,那么则取消订单 // Check if the current status is UN_PAY (unpaid)
if ($nowOrder->status == OrderStatusEnum::UN_PAY) { 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->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 ( if (
!is_null($this->order->coupon_id) && !is_null($this->order->coupon_id) && // Ensure a coupon ID exists
$coupon = UserHasCoupon::query()->find($this->order->coupon_id) $coupon = UserHasCoupon::query()->find($this->order->coupon_id) // Find the coupon in the database
) { ) {
// Reset the coupon usage timestamp
$coupon->used_at = null; $coupon->used_at = null;
$coupon->save(); $coupon->save(); // Save changes to the coupon
} }
// 回滚库存 // Rollback inventory for each order detail
$this->order $this->order
->details() ->details() // Get the order details
->with('product') ->with('product') // Eager load the associated product
->get() ->get() // Fetch the details
->map(function (OrderDetail $detail) { ->map(function (OrderDetail $detail) {
// For each order detail, increment the product's count by the ordered quantity
// 不回滚出售数量 $product = $detail->product; // Get the associated product
$product = $detail->product; $product->increment('count', $detail->number); // Increase product count
$product->increment('count', $detail->number);
}); });
} }
} }

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

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

Loading…
Cancel
Save