|
|
@@ -18,6 +18,36 @@ class IsExpiredValidator extends Validator
|
|
|
*/
|
|
|
public function validate(mixed $value, array $data): bool
|
|
|
{
|
|
|
+ if (empty($value)) {
|
|
|
+ $this->setError('物品ID不能为空');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $itemUser = ItemUser::find($value);
|
|
|
+ if (!$itemUser) {
|
|
|
+ $this->setError('物品不存在');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 检查item_user表的过期时间
|
|
|
+ if (!is_null($itemUser->expire_at)) {
|
|
|
+ if (now()->gt($itemUser->expire_at)) {
|
|
|
+ $this->setError('物品已过期');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 检查item表的全局过期时间
|
|
|
+ $item = $itemUser->item;
|
|
|
+ if ($item->isExpired()) {
|
|
|
+ $this->setError('物品已全局过期');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|