sub_account.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package db
  2. import (
  3. "context"
  4. "fmt"
  5. "youngee_b_api/model/gorm_model"
  6. )
  7. // CreateSubAccount 新建子账号
  8. func CreateSubAccount(ctx context.Context, account gorm_model.YounggeeSubAccount) error {
  9. db := GetWriteDB(ctx)
  10. err := db.Create(&account).Error
  11. if err != nil {
  12. return err
  13. }
  14. return nil
  15. }
  16. // UpdateSubAccount 更新子账号
  17. func UpdateSubAccount(ctx context.Context, account gorm_model.YounggeeSubAccount) error {
  18. db := GetWriteDB(ctx)
  19. whereCondition := gorm_model.YounggeeSubAccount{SubAccountId: account.SubAccountId}
  20. err := db.Model(&gorm_model.YounggeeSubAccount{}).Where(whereCondition).Updates(account).Error
  21. if err != nil {
  22. return err
  23. }
  24. return nil
  25. }
  26. // DeleteSubAccount 删除子账号
  27. func DeleteSubAccount(ctx context.Context, account gorm_model.YounggeeSubAccount) error {
  28. db := GetWriteDB(ctx)
  29. whereCondition := gorm_model.YounggeeSubAccount{SubAccountId: account.SubAccountId}
  30. err := db.Where(whereCondition).Delete(&gorm_model.YounggeeSubAccount{}).Error
  31. if err != nil {
  32. return err
  33. }
  34. return nil
  35. }
  36. // FindSubAccountByPhone 根据手机号码查询子账号
  37. func FindSubAccountByPhone(ctx context.Context, phone string) (*gorm_model.YounggeeSubAccount, error) {
  38. db := GetReadDB(ctx)
  39. var total int64
  40. var subAccount *gorm_model.YounggeeSubAccount
  41. whereCondition := gorm_model.YounggeeSubAccount{PhoneNumber: phone, SubAccountType: 1}
  42. err := db.Model(gorm_model.YounggeeSubAccount{}).Where(whereCondition).Find(&subAccount).Count(&total).Error
  43. if err != nil {
  44. return nil, err
  45. }
  46. fmt.Println(total)
  47. if total == 0 {
  48. return nil, err
  49. }
  50. return subAccount, nil
  51. }