123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package service
- import (
- "context"
- "fmt"
- log "github.com/sirupsen/logrus"
- "time"
- "youngee_b_api/db"
- "youngee_b_api/model/gorm_model"
- "youngee_b_api/model/http_model"
- )
- var SubAccount *subaccount
- type subaccount struct {
- }
- // CreateSubAccount 新增子账号
- func (*subaccount) CreateSubAccount(ctx context.Context, request *http_model.AddNewSubAccountRequest) error {
- user := gorm_model.YounggeeUser{
- Phone: request.PhoneNumber,
- User: "1002",
- Username: request.PhoneNumber,
- Password: "1002",
- RealName: "",
- Role: "4",
- Email: "",
- LastLoginTime: time.Now().UTC().Local(),
- }
- userId, err := db.CreateUser(ctx, user)
- if err != nil {
- log.Infof("[CreateEnterpriseSubUser] fail,err:%+v", err)
- return err
- }
- fmt.Println("userId: ", userId)
- var curr = int(*userId)
- var newSubAccount = gorm_model.YounggeeSubAccount{
- PhoneNumber: request.PhoneNumber,
- SubAccountName: request.SubAccountName,
- JobId: request.JobId,
- EnterpriseId: request.EnterpriseId,
- AccountStatus: 1,
- UserId: curr,
- SubAccountType: 1,
- }
- err1 := db.CreateSubAccount(ctx, newSubAccount)
- if err1 != nil {
- return err1
- }
- return nil
- }
- // UpdateSubAccount 修改子账号信息
- func (*subaccount) UpdateSubAccount(ctx context.Context, request *http_model.UpdateJobRequest) error {
- //var newSubAccount = gorm_model.YounggeeSubAccount{}
- //err := db.UpdateSubAccount(ctx, newSubAccount)
- //if err != nil {
- // return err
- //}
- return nil
- }
- // DeleteSubAccount 删除子账号
- func (*subaccount) DeleteSubAccount(ctx context.Context, request http_model.DeleteSubAccountRequest) error {
- var newSubAccount = gorm_model.YounggeeSubAccount{
- SubAccountId: request.SubAccountId,
- }
- err := db.DeleteSubAccount(ctx, newSubAccount)
- if err != nil {
- return err
- }
- return nil
- }
- // FindSubAccountByEnterpriseId 根据商家ID查找包含的所有子账号信息
- func (*subaccount) FindSubAccountByEnterpriseId(ctx context.Context, request http_model.FindAllSubAccountRequest) (*http_model.FindAllSubAccountData, error) {
- var subAccountResp *http_model.FindAllSubAccountData
- subAccountResp = &http_model.FindAllSubAccountData{}
- // 1. 取出子账号基本信息
- newSubAccount, total, subaccountErr := db.FindSubAccountByEnterpriseId(ctx, request.EnterpriseId, request.JobId, request.AccountStatus)
- if subaccountErr != nil {
- return nil, subaccountErr
- }
- if newSubAccount != nil {
- for _, s := range newSubAccount {
- var subAccountInfo *http_model.FindAllSubAccountInfo
- subAccountInfo = &http_model.FindAllSubAccountInfo{}
- // fmt.Println("s:", s.SubAccountId)
- subAccountInfo.SubAccountId = s.SubAccountId
- subAccountInfo.SubAccountName = s.SubAccountName
- subAccountInfo.JobId = s.JobId
- subAccountInfo.UserId = s.UserId
- subAccountInfo.PhoneNumber = s.PhoneNumber
- subAccountInfo.EnterpriseId = s.EnterpriseId
- subAccountInfo.EnterpriseName = s.EnterpriseId
- subAccountInfo.AccountStatus = s.AccountStatus
- // 2. 岗位信息
- jobInfo, jobErr := db.FindJobByJobId(ctx, s.JobId)
- if jobErr != nil {
- return nil, jobErr
- }
- if jobInfo != nil {
- subAccountInfo.JobName = jobInfo.JobName
- }
- subAccountResp.SubAccountInfo = append(subAccountResp.SubAccountInfo, subAccountInfo)
- }
- }
- subAccountResp.Total = total
- return subAccountResp, nil
- }
|