This commit is contained in:
eson 2023-08-30 11:04:54 +08:00
parent 9ecb04c98b
commit 71109d964b
5 changed files with 16 additions and 16 deletions

View File

@ -5,11 +5,11 @@ import "context"
// TODO: 使用model的属性做你想做的
func (u *FsBackendUserModel) FindUserByEmail(ctx context.Context, emailname string) (resp FsBackendUser, err error) {
err = u.db.WithContext(ctx).Model(&resp).Where("`email` = ?", emailname).Take(&resp).Error
err = u.db.WithContext(ctx).Model(&FsBackendUser{}).Where("`email` = ?", emailname).Take(&resp).Error
return resp, err
}
func (u *FsBackendUserModel) FindUserById(ctx context.Context, Id int64) (resp FsBackendUser, err error) {
err = u.db.WithContext(ctx).Model(&resp).Where("`id` = ? and status != ?", Id, 0).Take(&resp).Error
err = u.db.WithContext(ctx).Model(&FsBackendUser{}).Where("`id` = ? and status != ?", Id, 0).Take(&resp).Error
return resp, err
}

View File

@ -34,8 +34,8 @@ func (p *FsCloudPickUpModel) SavePickUpWithTransaction(ctx context.Context, pick
}
func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, userId int64, RelationID int64, cs *FsContactService) (cloudOrder *FsCloudPickUp, err error) {
err = p.db.WithContext(ctx).Model(cloudOrder).Transaction(func(tx *gorm.DB) error {
err = tx.Model(cloudOrder).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, RelationID).Take(&cloudOrder).Error
err = p.db.WithContext(ctx).Model(&FsCloudPickUp{}).Transaction(func(tx *gorm.DB) error {
err = tx.Model(&FsCloudPickUp{}).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, RelationID).Take(&cloudOrder).Error
if err != nil {
return err
}
@ -45,7 +45,7 @@ func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, us
*cs.RelationId = 0
}
return tx.Model(cs).Create(cs).Error
return tx.Model(&FsContactService{}).Create(cs).Error
})
return cloudOrder, err
}

View File

@ -38,7 +38,7 @@ func (o *FsOrderModel) Create(ctx context.Context, data *FsOrder) error {
func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userId int64, OrderId int64, cs *FsContactService) (order *FsOrder, err error) {
err = o.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
err = tx.Model(order).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
err = tx.Model(&FsOrder{}).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
if err != nil {
return err
}
@ -48,7 +48,7 @@ func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userI
*cs.RelationId = 0
}
return tx.Model(cs).Create(cs).Error
return tx.Model(&FsContactService{}).Create(cs).Error
})
return order, err
}

View File

@ -19,11 +19,11 @@ func (m *FsRefundReasonModel) Create(ctx context.Context, obj *FsRefundReason) e
}
func (m *FsRefundReasonModel) Update(ctx context.Context, obj *FsRefundReason) error {
return m.db.WithContext(ctx).Model(obj).Where("`id` = ?", obj.Id).Updates(obj).Error
return m.db.WithContext(ctx).Model(&FsRefundReason{}).Where("`id` = ?", obj.Id).Updates(obj).Error
}
func (m *FsRefundReasonModel) UpdateByRefundReasonId(ctx context.Context, obj *FsRefundReason) error {
return m.db.WithContext(ctx).Model(obj).Where("`refund_reason_id` = ?", obj.RefundReasonId).Updates(obj).Error
return m.db.WithContext(ctx).Model(&FsRefundReason{}).Where("`refund_reason_id` = ?", obj.RefundReasonId).Updates(obj).Error
}
func (m *FsRefundReasonModel) CreateOrUpdate(ctx context.Context, req *FsRefundReason) (resp *FsRefundReason, err error) {

View File

@ -41,7 +41,7 @@ func (u *FsUserModel) FindUserById(ctx context.Context, Id int64) (resp FsUser,
}
func (u *FsUserModel) FindUserByGoogleId(ctx context.Context, Id int64) (resp *FsUser, err error) {
err = u.db.WithContext(ctx).Model(resp).Where("`google_id` = ? and is_del = ?", Id, 0).Take(resp).Error
err = u.db.WithContext(ctx).Model(&FsUser{}).Where("`google_id` = ? and is_del = ?", Id, 0).Take(resp).Error
return resp, err
}
@ -102,7 +102,7 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg
err := u.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
googleId := token.Extend["google_id"].(int64)
err := tx.Model(user).Where("email = ?", token.Email).Take(user).Error
err := tx.Model(&FsUser{}).Where("email = ?", token.Email).Take(user).Error
if err != nil {
// 没有找到在数据库就创建注册
if err == gorm.ErrRecordNotFound {
@ -111,7 +111,7 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg
user.CreatedAt = &createAt
user.GoogleId = &googleId
user.PasswordHash = &token.Password
err = tx.Model(user).Create(user).Error
err = tx.Model(&FsUser{}).Create(user).Error
if err != nil {
return err
}
@ -124,7 +124,7 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg
// 如果已经存在,把谷歌id 加入到用户信息里
user.GoogleId = &googleId
return tx.Model(user).Update("google_id", user).Error
return tx.Model(&FsUser{}).Update("google_id", user).Error
})
if err != nil {
@ -148,7 +148,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
user = &FsUser{}
var err error
err = tx.Model(user).Where("email = ?", token.Email).Take(user).Error
err = tx.Model(&FsUser{}).Where("email = ?", token.Email).Take(user).Error
if err == gorm.ErrRecordNotFound {
FirstName := token.Extend["first_name"].(string)
@ -163,7 +163,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
user.FirstName = &FirstName
user.LastName = &LastName
err = tx.Model(user).Create(user).Error
err = tx.Model(&FsUser{}).Create(user).Error
if err != nil && err != gorm.ErrRecordNotFound {
logx.Error(err)
return err
@ -239,7 +239,7 @@ func (u *FsUserModel) DebugAuthDelete(ctx context.Context, email string) (err er
err = u.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
user := &FsUser{}
txUser := tx.Model(user)
txUser := tx.Model(&FsUser{})
err = txUser.Where("email = ?", email).Take(user).Error
if err == nil {
err = txUser.Where("email = ?", email).Delete(user).Error