跳至主要內容

盲盒详情页

起凡大约 4 分钟

盲盒详情页

首页
首页
商品详情对话框
商品详情对话框

表设计

订单详情页中多了商品信息,一个盲盒可以关联多个商品,商品可以被多个盲盒关联。

商品表

create table product
(
    id             varchar(36)    not null
        primary key,
    created_time   datetime(6)    not null,
    edited_time    datetime(6)    not null,
    creator_id     varchar(36)    not null,
    editor_id      varchar(36)    not null,
    name           varchar(255)   not null comment '名称',
    price          decimal(10, 2) not null comment '价格',
    cover          varchar(255)   not null comment '封面',
    brand          varchar(255)   not null comment '品牌',
    specifications text           not null comment '规格参数',
    quality_type   varchar(32)    not null comment '品质类型(普通款,隐藏款,超神款)'
    category_id    varchar(36)    not null comment '类别id(未用)',
    description    text           not null comment '描述(未用)',
    tags           varchar(255)   not null comment '标签(未用)',
    attributes     text           not null comment '属性(未用)',
)
    comment '商品表';

盲盒商品关系表

create table mystery_box_product_rel
(
    id             varchar(32) not null
        primary key,
    created_time   datetime(6) not null,
    edited_time    datetime(6) not null,
    creator_id     varchar(32) not null,
    editor_id      varchar(32) not null,
    mystery_box_id varchar(32) not null comment '盲盒',
    product_id     varchar(32) not null comment '商品'
)
    comment '盲盒-商品中间表';

通过下面的sql即可查询出盲盒内的商品

select t1.*, t3.*
from mystery_box t1
         left join mystery_box_product_rel t2 on t1.id = t2.mystery_box_id
         left join product t3 on t2.product_id = t3.id
where t1.id = 'ebf8f84d60814944a847e0de4bb1d8b4' -- 盲盒id

盲盒信息

ts
// -----盲盒详情,含商品信息-----
const box =
  ref<MysteryBoxDto["MysteryBoxRepository/COMPLEX_FETCHER_FOR_FRONT"]>();
Taro.useLoad(({id}) => {
  api.mysteryBoxForFrontController.findById({ id }).then((res) => {
    res.products = res.products.sort((a, b) => a.price - b.price);
    box.value = res;
  });
});
// -----盲盒详情,含商品信息-----

// -----商品详情对话框-----
type Product =
  MysteryBoxDto["MysteryBoxRepository/COMPLEX_FETCHER_FOR_FRONT"]["products"][0];
const dialogVisible = ref(false);
const activeProduct = ref<Product>();
const handleProductClick = (product: Product) => {
  activeProduct.value = product;
  dialogVisible.value = true;
};
// -----商品详情对话框-----