'integer', ]; /** * 获取关联的限购配置 * * @return BelongsTo */ public function purchaseLimit(): BelongsTo { return $this->belongsTo(ShopPurchaseLimit::class, 'limit_id'); } /** * 增加计数 * * @param int $count 增加的数量 * @return bool */ public function incrementCount(int $count = 1): bool { $this->current_count += $count; return $this->save(); } /** * 重置计数 * * @return bool */ public function resetCount(): bool { $this->current_count = 0; $this->last_reset_time = now(); return $this->save(); } /** * 检查是否达到限制 * * @return bool */ public function isLimitReached(): bool { $limit = $this->purchaseLimit; if (!$limit) { return false; } return $this->current_count >= $limit->max_quantity; } /** * 获取剩余可购买数量 * * @return int */ public function getRemainingQuantity(): int { $limit = $this->purchaseLimit; if (!$limit) { return 0; } return max(0, $limit->max_quantity - $this->current_count); } }