package gmodel import "context" // 查询 func (c *FsProductCollectionModel) FindOne(ctx context.Context, userId, guestId, productId int64) (resp *FsProductCollection, err error) { err = c.db.WithContext(ctx).Model(&FsProductCollection{}). Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId). Take(&resp).Error return resp, err } // 创建 func (c *FsProductCollectionModel) Create(ctx context.Context, data *FsProductCollection) error { return c.db.WithContext(ctx).Model(&FsProductCollection{}).Create(&data).Error } // 更新 func (c *FsProductCollectionModel) Update(ctx context.Context, userId, guestId, productId int64, data *FsProductCollection) error { return c.db.WithContext(ctx).Model(&FsProductCollection{}). Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId). Updates(&data).Error } // 删除 func (c *FsProductCollectionModel) Delete(ctx context.Context, userId, guestId, productId int64) error { return c.db.WithContext(ctx).Model(&FsProductCollection{}). Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId). Delete(&FsProductCollection{}).Error } // 删除 func (c *FsProductCollectionModel) Delete2(ctx context.Context, userId, guestId, id int64) error { return c.db.WithContext(ctx).Model(&FsProductCollection{}). Where("user_id = ? and guest_id = ? and id = ?", userId, guestId, id). Delete(&FsProductCollection{}).Error }