Merge branch 'feature/mhw-v1.01' of gitee.com:fusenpack/fusenapi into feature/mhw-v1.01

This commit is contained in:
momo
2023-09-15 17:59:04 +08:00
25 changed files with 270 additions and 94 deletions

View File

@@ -18,12 +18,15 @@ func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...s
err = db.Take(&resp).Error
return resp, err
}
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string, fields ...string) (resp []FsProduct, err error) {
if len(productIds) == 0 {
return
}
db := p.db.Model(&FsProduct{}).WithContext(ctx).
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 1)
if len(fields) > 0 {
db = db.Select(fields[0])
}
switch sort {
case "sort-asc":
db = db.Order("`sort` ASC")

View File

@@ -23,11 +23,11 @@ func (p *FsProductPriceModel) GetSimplePriceListByProductIds(ctx context.Context
}
return
}
func (p *FsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []int64) (resp []FsProductPrice, err error) {
if len(sizeIds) == 0 {
func (p *FsProductPriceModel) GetPriceListByProductIdsSizeIds(ctx context.Context, productIds, sizeIds []int64) (resp []FsProductPrice, err error) {
if len(sizeIds) == 0 || len(productIds) == 0 {
return
}
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `status` = ? ", sizeIds, 1).Find(&resp).Error
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `product_id` in (?) and `status` = ? ", sizeIds, productIds, 1).Find(&resp).Error
if err != nil {
return nil, err
}
@@ -71,6 +71,11 @@ func (p *FsProductPriceModel) GetPriceListByProductIds(ctx context.Context, prod
}
return
}
func (p *FsProductPriceModel) FindOneBySizeId(ctx context.Context, sizeId int64) (resp *FsProductPrice, err error) {
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).
Where("`size_id` = ? and `status` = ?", sizeId, 1).Take(&resp).Error
return resp, err
}
// 产品价格
type ProductPrice struct {

View File

@@ -33,17 +33,22 @@ func (s *FsShoppingCartModel) FineOneUserCart(ctx context.Context, id, userId in
// 创建
func (s *FsShoppingCartModel) Create(ctx context.Context, data *FsShoppingCart) error {
return s.db.WithContext(ctx).Create(&data).Error
return s.db.WithContext(ctx).Model(&FsShoppingCart{}).Create(&data).Error
}
// 删除
func (s *FsShoppingCartModel) Delete(ctx context.Context, id, userId int64) error {
return s.db.WithContext(ctx).Model(&FsShoppingCart{}).Where("user_id = ? and id = ?", userId, id).Delete(&FsShoppingCart{}).Error
}
// 更新
func (s *FsShoppingCartModel) Update(ctx context.Context, id, userId int64, data *FsShoppingCart) error {
return s.db.WithContext(ctx).Where("user_id = ? and id = ?", userId, id).Updates(&data).Error
return s.db.WithContext(ctx).Model(&FsShoppingCart{}).Where("user_id = ? and id = ?", userId, id).Updates(&data).Error
}
// 获取用户购物车数量
func (s *FsShoppingCartModel) CountUserCart(ctx context.Context, userId int64) (total int64, err error) {
err = s.db.WithContext(ctx).Where("user_id = ?", userId).Limit(1).Count(&total).Error
err = s.db.WithContext(ctx).Model(&FsShoppingCart{}).Where("user_id = ?", userId).Limit(1).Count(&total).Error
return total, err
}
@@ -52,7 +57,7 @@ func (s *FsShoppingCartModel) GetAllByIds(ctx context.Context, ids []int64, sort
if len(ids) == 0 {
return
}
db := s.db.WithContext(ctx).Where("id in (?)", ids)
db := s.db.WithContext(ctx).Model(&FsShoppingCart{}).Where("id in (?)", ids)
if len(fields) > 0 {
db = db.Select(fields[0])
}
@@ -74,7 +79,7 @@ type GetAllCartsByParamReq struct {
}
func (s *FsShoppingCartModel) GetAllCartsByParam(ctx context.Context, req GetAllCartsByParamReq) (resp []FsShoppingCart, total int64, err error) {
db := s.db.WithContext(ctx)
db := s.db.WithContext(ctx).Model(&FsShoppingCart{})
if req.UserId > 0 {
db = db.Where("user_id = ?", req.UserId)
}