fix
This commit is contained in:
parent
982f5e1df9
commit
ab472a32f6
|
@ -61,7 +61,6 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
||||||
now := time.Now().UTC().Unix()
|
now := time.Now().UTC().Unix()
|
||||||
//开启事务
|
//开启事务
|
||||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||||
canteenProductModel = gmodel.NewFsCanteenProductModel(tx)
|
|
||||||
sort := int64(0)
|
sort := int64(0)
|
||||||
//新的变更记录
|
//新的变更记录
|
||||||
mapUpdateCanteenPid := make(map[int64]struct{})
|
mapUpdateCanteenPid := make(map[int64]struct{})
|
||||||
|
@ -73,12 +72,12 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
||||||
}
|
}
|
||||||
if v.Id > 0 { //更新
|
if v.Id > 0 { //更新
|
||||||
mapUpdateCanteenPid[v.Id] = struct{}{}
|
mapUpdateCanteenPid[v.Id] = struct{}{}
|
||||||
err = canteenProductModel.UpdateById(l.ctx, v.Id, &gmodel.FsCanteenProduct{
|
err = tx.WithContext(l.ctx).Model(&gmodel.FsCanteenProduct{}).Where("id = ?", v.Id).Updates(&gmodel.FsCanteenProduct{
|
||||||
SizeId: &v.SizeId,
|
SizeId: &v.SizeId,
|
||||||
Sid: &v.SId,
|
Sid: &v.SId,
|
||||||
Sort: &sort,
|
Sort: &sort,
|
||||||
ProductId: sizeInfo.ProductId,
|
ProductId: sizeInfo.ProductId,
|
||||||
})
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -86,7 +85,7 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
||||||
}
|
}
|
||||||
//新增
|
//新增
|
||||||
addStatus := int64(1)
|
addStatus := int64(1)
|
||||||
err = canteenProductModel.Create(l.ctx, &gmodel.FsCanteenProduct{
|
err = tx.WithContext(l.ctx).Model(&gmodel.FsCanteenProduct{}).Create(&gmodel.FsCanteenProduct{
|
||||||
SizeId: &v.SizeId,
|
SizeId: &v.SizeId,
|
||||||
Sid: &v.SId,
|
Sid: &v.SId,
|
||||||
Sort: &sort,
|
Sort: &sort,
|
||||||
|
@ -94,7 +93,7 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
||||||
Ctime: &now,
|
Ctime: &now,
|
||||||
CanteenType: &req.Id,
|
CanteenType: &req.Id,
|
||||||
ProductId: sizeInfo.ProductId,
|
ProductId: sizeInfo.ProductId,
|
||||||
})
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -110,9 +109,9 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
delStatus := int64(0)
|
delStatus := int64(0)
|
||||||
if err = canteenProductModel.UpdateByIdArr(l.ctx, diffCanteenProductId, &gmodel.FsCanteenProduct{
|
if err = tx.WithContext(l.ctx).Model(&gmodel.FsCanteenProduct{}).Where("id in (?)", diffCanteenProductId).Updates(&gmodel.FsCanteenProduct{
|
||||||
Status: &delStatus,
|
Status: &delStatus,
|
||||||
}); err != nil {
|
}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -91,7 +91,6 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||||
subTotalPrice := int64(0)
|
subTotalPrice := int64(0)
|
||||||
//开启事物
|
//开启事物
|
||||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||||
shoppingCartModel := gmodel.NewFsShoppingCartModel(tx)
|
|
||||||
for _, cart := range carts {
|
for _, cart := range carts {
|
||||||
modelInfo, ok := mapModel[*cart.ModelId]
|
modelInfo, ok := mapModel[*cart.ModelId]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -138,7 +137,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||||
subTotalPrice += totalPrice
|
subTotalPrice += totalPrice
|
||||||
}
|
}
|
||||||
//更新购物车购买数量
|
//更新购物车购买数量
|
||||||
if err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, updData); err != nil {
|
if err = tx.WithContext(l.ctx).Model(&gmodel.FsShoppingCart{}).Where("id = ? and user_id = ?", cart.Id, userinfo.UserId).Updates(updData).Error; err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return errors.New(fmt.Sprintf("failed to update cart`s purchase quantity:%d", cart.Id))
|
return errors.New(fmt.Sprintf("failed to update cart`s purchase quantity:%d", cart.Id))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user