根据用户反馈,对商店限购功能进行了以下重要修正:
app/Module/Shop/AdminControllers/Api/ShopItemSelectController.phpmax_buy 字段应该被新的限购系统完全替代ShopItem 模型中移除 max_buy 字段定义canUserPurchaseWithLimits 方法中移除 max_buy 检查逻辑max_buy 相关的显示和表单字段max_buy 字段app/Module/Shop/Models/ShopItem.php)// 移除字段定义
- * @property int $max_buy 最大购买数量(0表示无限制)
// 移除 fillable 中的字段
- 'max_buy',
// 移除验证逻辑中的 max_buy 检查
- // 检查传统的总购买限制
- if ($this->max_buy > 0) {
- $boughtCount = $this->getUserBoughtCount($userId);
- $remainingQuantity = $this->max_buy - $boughtCount;
-
- if ($quantity > $remainingQuantity) {
- return [false, "超出购买限制,最多还能购买{$remainingQuantity}个", $remainingQuantity];
- }
- }
app/Module/Shop/AdminControllers/ShopItemController.php)// 移除表格列
- $grid->column('max_buy', '总限购')->display(function ($maxBuy) {
- return $maxBuy > 0 ? $maxBuy : '无限制';
- });
// 移除详情页字段
- $show->field('max_buy', '总购买限制')->as(function ($maxBuy) {
- return $maxBuy > 0 ? $maxBuy : '无限制';
- });
// 移除表单字段
- $form->number('max_buy', '总购买限制')->min(0)->default(0)->help('用户总共可购买的最大数量,0表示无限制');
app/Module/Shop/AdminControllers/ShopPurchaseLimitController.php)// 简化商品选择,移除API依赖
$form->select('shop_item_id', '商品')
->options(ShopItem::where('is_active', true)->pluck('name', 'id'))
->required()
->help('选择要设置限购的商品');
app/Module/Shop/Providers/ShopServiceProvider.php)// 移除API路由
- // API路由
- $router->get('shop/items/select', [\App\Module\Shop\AdminControllers\Api\ShopItemSelectController::class, 'select']);
- $router->get('shop/items/{id}/info', [\App\Module\Shop\AdminControllers\Api\ShopItemSelectController::class, 'info']);
-- 删除 max_buy 字段
ALTER TABLE `kku_shop_items` DROP COLUMN `max_buy`;
max_buy 字段已从数据库表中成功删除max_single_buy 字段app/Module/Shop/AdminControllers/Api/ShopItemSelectController.php - 不需要的API控制器app/Module/Shop/Databases/GenerateSql/remove_shop_items_max_buy_field.sql - 删除字段的SQL脚本app/Module/Shop/Docs/后台管理部署说明.mdAiWork/2024年12月/28日1430-商店限购功能优化.mdmax_buy商品限购系统
├── 单次购买限制 (max_single_buy 字段)
└── 周期性限购 (ShopPurchaseLimit 表)
├── 永久限购 (替代原 max_buy)
├── 每日限购
├── 每周限购
├── 每月限购
└── 每年限购
kku_shop_items - 包含 max_single_buy,已移除 max_buykku_shop_purchase_limits - 限购配置表kku_shop_user_purchase_counters - 用户购买计数表# 如果是新部署
mysql -u用户名 -p数据库名 < app/Module/Shop/Databases/GenerateSql/shop_purchase_limits.sql
mysql -u用户名 -p数据库名 < app/Module/Shop/Databases/GenerateSql/shop_user_purchase_counters.sql
# 如果是从旧系统升级(已执行)
mysql -u用户名 -p数据库名 < app/Module/Shop/Databases/GenerateSql/remove_shop_items_max_buy_field.sql
php artisan admin:insert-shop-purchase-limit-menu
php artisan route:clear
php artisan config:clear
max_single_buy 字段ShopPurchaseLimit 配置经过修正,商店限购功能现在:
新的限购系统比原来的 max_buy 字段更加灵活和强大,能够满足各种复杂的业务需求。