package db import ( "context" "fmt" "youngee_b_api/model/gorm_model" ) // CreateSubAccount 新建子账号 func CreateSubAccount(ctx context.Context, account gorm_model.YounggeeSubAccount) error { db := GetWriteDB(ctx) err := db.Create(&account).Error if err != nil { return err } return nil } // UpdateSubAccount 更新子账号 func UpdateSubAccount(ctx context.Context, account gorm_model.YounggeeSubAccount) error { db := GetWriteDB(ctx) whereCondition := gorm_model.YounggeeSubAccount{SubAccountId: account.SubAccountId} err := db.Model(&gorm_model.YounggeeSubAccount{}).Where(whereCondition).Updates(account).Error if err != nil { return err } return nil } // DeleteSubAccount 删除子账号 func DeleteSubAccount(ctx context.Context, account gorm_model.YounggeeSubAccount) error { db := GetWriteDB(ctx) whereCondition := gorm_model.YounggeeSubAccount{SubAccountId: account.SubAccountId} err := db.Where(whereCondition).Delete(&gorm_model.YounggeeSubAccount{}).Error if err != nil { return err } return nil } // FindSubAccountByPhone 根据手机号码查询子账号 func FindSubAccountByPhone(ctx context.Context, phone string) (*gorm_model.YounggeeSubAccount, error) { db := GetReadDB(ctx) var total int64 var subAccount *gorm_model.YounggeeSubAccount whereCondition := gorm_model.YounggeeSubAccount{PhoneNumber: phone, SubAccountType: 1} err := db.Model(gorm_model.YounggeeSubAccount{}).Where(whereCondition).Find(&subAccount).Count(&total).Error if err != nil { return nil, err } fmt.Println(total) if total == 0 { return nil, err } return subAccount, nil } // FindSubAccountByEnterpriseId 根据商家ID查找包含的所有子账号信息 func FindSubAccountByEnterpriseId(ctx context.Context, enterpriseId string, jobId int, accountStatus int) ([]*gorm_model.YounggeeSubAccount, int64, error) { db := GetReadDB(ctx) var total int64 var subAccount []*gorm_model.YounggeeSubAccount whereCondition := gorm_model.YounggeeSubAccount{EnterpriseId: enterpriseId, SubAccountType: 1, JobId: jobId, AccountStatus: accountStatus} err := db.Model(gorm_model.YounggeeSubAccount{}).Where(whereCondition).Find(&subAccount).Count(&total).Error if err != nil { return nil, 0, err } if total == 0 { return nil, 0, err } return subAccount, total, nil }