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()
|
||||
//开启事务
|
||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||
canteenProductModel = gmodel.NewFsCanteenProductModel(tx)
|
||||
sort := int64(0)
|
||||
//新的变更记录
|
||||
mapUpdateCanteenPid := make(map[int64]struct{})
|
||||
|
@ -73,12 +72,12 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
|||
}
|
||||
if v.Id > 0 { //更新
|
||||
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,
|
||||
Sid: &v.SId,
|
||||
Sort: &sort,
|
||||
ProductId: sizeInfo.ProductId,
|
||||
})
|
||||
}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -86,7 +85,7 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
|||
}
|
||||
//新增
|
||||
addStatus := int64(1)
|
||||
err = canteenProductModel.Create(l.ctx, &gmodel.FsCanteenProduct{
|
||||
err = tx.WithContext(l.ctx).Model(&gmodel.FsCanteenProduct{}).Create(&gmodel.FsCanteenProduct{
|
||||
SizeId: &v.SizeId,
|
||||
Sid: &v.SId,
|
||||
Sort: &sort,
|
||||
|
@ -94,7 +93,7 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
|||
Ctime: &now,
|
||||
CanteenType: &req.Id,
|
||||
ProductId: sizeInfo.ProductId,
|
||||
})
|
||||
}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -110,9 +109,9 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
|||
return nil
|
||||
}
|
||||
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,
|
||||
}); err != nil {
|
||||
}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -91,7 +91,6 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
subTotalPrice := int64(0)
|
||||
//开启事物
|
||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||
shoppingCartModel := gmodel.NewFsShoppingCartModel(tx)
|
||||
for _, cart := range carts {
|
||||
modelInfo, ok := mapModel[*cart.ModelId]
|
||||
if !ok {
|
||||
|
@ -138,7 +137,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
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)
|
||||
return errors.New(fmt.Sprintf("failed to update cart`s purchase quantity:%d", cart.Id))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user