user()->id); if ($user === null || $user->status === UserModel::STATUS_DISABLED) { throw new RepositoryException('账号不存在或已被停用'); } return $user; } /** * 门店端前置校验:type=门店 且 store_id>0 且门店正常 */ protected function ensureStoreBound(UserModel $user): StoreModel { if ($user->store_id <= 0) { throw new RepositoryException('尚未绑定门店,请联系客服处理'); } $store = StoreModel::find($user->store_id); if ($store === null || $store->status !== StoreModel::STATUS_NORMAL) { throw new RepositoryException('门店不存在或已停用,请联系客服处理'); } return $store; } /** * 用户当前绑定的正常门店(未绑定/已停用返回 null,不抛错) * * 供商品浏览等「弱前置」场景使用:未绑定门店仍可浏览商品,仅价格不可见。 */ protected function boundStore(UserModel $user): ?StoreModel { if ($user->store_id <= 0) { return null; } $store = StoreModel::find($user->store_id); if ($store === null || $store->status !== StoreModel::STATUS_NORMAL) { return null; } return $store; } }