sub_account.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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: 3}
  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. }
  52. // FindSubAccountById 根据Id查询子账号
  53. func FindSubAccountById(ctx context.Context, subAccountId int) (*gorm_model.YounggeeSubAccount, error) {
  54. db := GetReadDB(ctx)
  55. var total int64
  56. var subAccount *gorm_model.YounggeeSubAccount
  57. whereCondition := gorm_model.YounggeeSubAccount{SubAccountId: subAccountId, SubAccountType: 1}
  58. err := db.Model(gorm_model.YounggeeSubAccount{}).Where(whereCondition).Find(&subAccount).Count(&total).Error
  59. if err != nil {
  60. return nil, err
  61. }
  62. fmt.Println(total)
  63. if total == 0 {
  64. return nil, err
  65. }
  66. return subAccount, nil
  67. }