CREATE TABLE "act_sale_code" (
     "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
     "merchant_id" int4 NOT NULL,
     "panini_base_id" int4 NOT NULL,
     "code" varchar(64),
     "remark" text,
     "status" int4 DEFAULT 0,
     "create_time" timestamp,
     PRIMARY KEY ("id")
);


CREATE INDEX "gsc-mid-pid" ON "act_sale_code" USING btree (
    "merchant_id","panini_base_id"
);

CREATE INDEX "gsc-code" ON "act_sale_code" USING btree ( "code" );


CREATE TABLE "sale_code_record" (
   "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "type" varchar(32) DEFAULT 'group',
   "ref_id" int4 NOT NULL,
   "code_id" int4 NOT NULL,
   "code" varchar(64),
   "img" text,
   "verify_time" timestamp,
   "status" int4 DEFAULT 0,
   "remark" text,
   "create_time" timestamp,
   PRIMARY KEY ("id")
);

CREATE INDEX "gcr-cid-gid" ON "sale_code_record" USING btree (
     "type","ref_id","code_id"
);

COMMENT ON COLUMN "sale_code_record"."type" IS '类型:默认拼团:group';

COMMENT ON COLUMN "sale_code_record"."ref_id" IS '关联商品id,根据type判断';

COMMENT ON COLUMN "sale_code_record"."status" IS '状态:默认0:绑定,1:已核销';
