소스 검색

feat(limit-purchase): 新增商品限购规则关联功能

- 创建商品限购规则关联表 goods_limit_purchase_rule
- 添加商品ID与限购规则ID的关联字段
- 设置唯一索引 uk_goods_id 确保商品限购规则唯一性
- 添加普通索引 idx_rule_id 提高查询效率
- 新增 GoodsLimitPurchaseRuleModel 模型类
- 新增 GoodsLimitPurchaseRuleEntity 实体类
- 实现商品与限购规则的基础关联逻辑
runphp 3 달 전
부모
커밋
da673924c4

+ 25 - 0
database/migrations/20251208203054_goods_limit_purchase_rule.php

@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+
+use Phinx\Migration\AbstractMigration;
+
+final class GoodsLimitPurchaseRule extends AbstractMigration
+{
+    public function change(): void
+    {
+        $this->table('goods_limit_purchase_rule', ['comment' => '商品限购规则关联表'])
+            ->addColumn('goods_id', 'integer', [
+                'signed'  => false,
+                'comment' => '商品ID',
+            ])
+            ->addColumn('rule_id', 'integer', [
+                'signed'  => false,
+                'comment' => '限购规则ID',
+            ])
+            ->addTimestamps('create_time', 'update_time')
+            ->addIndex(['goods_id'], ['unique' => true, 'name' => 'uk_goods_id'])
+            ->addIndex(['rule_id'], ['name' => 'idx_rule_id'])
+            ->create();
+    }
+}

+ 17 - 0
src/Entity/GoodsLimitPurchaseRuleEntity.php

@@ -0,0 +1,17 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\LimitPurchase\Entity;
+
+use SixShop\Core\Entity\BaseEntity;
+use SixShop\LimitPurchase\Model\GoodsLimitPurchaseRuleModel;
+
+/**
+ * 商品限购规则关联实体类
+ * 用于管理商品与限购规则的关联关系
+ * @mixin GoodsLimitPurchaseRuleModel
+ */
+class GoodsLimitPurchaseRuleEntity extends BaseEntity
+{
+    //
+}

+ 29 - 0
src/Model/GoodsLimitPurchaseRuleModel.php

@@ -0,0 +1,29 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\LimitPurchase\Model;
+
+use think\Model;
+use think\model\concern\SoftDelete;
+
+/**
+ * 商品限购规则关联模型
+ *
+ * @property int $id 主键
+ * @property int $goods_id 商品ID
+ * @property int $rule_id 限购规则ID
+ */
+class GoodsLimitPurchaseRuleModel extends Model
+{
+    /**
+     * 获取模型选项
+     *
+     * @return array
+     */
+    protected function getOptions(): array
+    {
+        return [
+            'name' => 'goods_limit_purchase_rule',
+        ];
+    }
+}