Compare commits

..

No commits in common. '337d0faae6ef5bb9d80012a941ecf5d0d19cd6a0' and '27c81b89a9f44dc7e3d7b08f14028ce8ff49b03e' have entirely different histories.

@ -16,57 +16,56 @@ class CancelUnPayOrder implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $order; // Property to hold the order instance protected $order;
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @param Order $order The order that needs to be processed * @param Order $order
*/ */
public function __construct(Order $order) public function __construct(Order $order)
{ {
$this->order = $order; // Initialize the order property $this->order = $order;
} }
/** /**
* 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(); // Save the updated order status $this->order->save();
// Process coupon rollback if a coupon was used // 回退优惠券
if ( if (
!is_null($this->order->coupon_id) && // Ensure a coupon ID exists !is_null($this->order->coupon_id) &&
$coupon = UserHasCoupon::query()->find($this->order->coupon_id) // Find the coupon in the database $coupon = UserHasCoupon::query()->find($this->order->coupon_id)
) { ) {
// Reset the coupon usage timestamp
$coupon->used_at = null; $coupon->used_at = null;
$coupon->save(); // Save changes to the coupon $coupon->save();
} }
// Rollback inventory for each order detail // 回滚库存
$this->order $this->order
->details() // Get the order details ->details()
->with('product') // Eager load the associated product ->with('product')
->get() // Fetch the details ->get()
->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->increment('count', $detail->number); // Increase product count $product = $detail->product;
$product->increment('count', $detail->number);
}); });
} }
} }

@ -16,29 +16,27 @@ 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,8 +42,6 @@ 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) {
@ -52,14 +50,5 @@ class RemindUsersHasSeckill implements ShouldQueue
}); });
} }
} }

Loading…
Cancel
Save