fix
This commit is contained in:
@@ -1,2 +1,31 @@
|
||||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (p *FsCloudPickUpModel) SavePickUpWithTransaction(ctx context.Context, pickUpData *FsCloudPickUp, stockList []FsUserStock, pickUpDetailAddList []FsCloudPickUpDetail) error {
|
||||
return p.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
//保存总提单信息
|
||||
if err := tx.Model(&FsCloudPickUp{}).Create(&pickUpData).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
//更新云仓库存
|
||||
for _, v := range stockList {
|
||||
if err := tx.Model(&FsUserStock{}).Where("`id` = ?", v.Id).Updates(&v).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
//添加提单详情
|
||||
for _, v := range pickUpDetailAddList {
|
||||
v.PickId = &pickUpData.Id //外面没赋值在这需要赋值
|
||||
if err := tx.Model(&FsCloudPickUpDetail{}).Create(&v).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,2 +1,24 @@
|
||||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (s *FsUserStockModel) GetUserAllStockByIds(ctx context.Context, ids []int64, userId int64) (resp []FsUserStock, err error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if userId <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
err = s.db.WithContext(ctx).Model(&FsUserStock{}).Where("`id` in (?) and `user_id` = ?", ids, userId).Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (s *FsUserStockModel) FindOne(ctx context.Context, id int64, userId int64, lock ...bool) (resp *FsUserStock, err error) {
|
||||
db := s.db.WithContext(ctx).Model(&FsUserStock{}).Where("`id` = ? and `user_id` = ?", id, userId)
|
||||
if len(lock) != 0 && lock[0] {
|
||||
db = db.Set("gorm:query_option", "FOR UPDATE")
|
||||
}
|
||||
err = db.First(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user