|
@@ -338,3 +338,222 @@ func (l *loginAuth) SubAccountAuthCode(ctx context.Context, req *http_model.AddN
|
|
|
}
|
|
|
return 0, nil
|
|
|
}
|
|
|
+
|
|
|
+// UpdateEnterpriseAccountInfo 更新商家账号信息
|
|
|
+func (l *loginAuth) UpdateEnterpriseAccountInfo(ctx context.Context, req *http_model.UpdateAccountInfoRequest) (*http_model.UpdateAccountInfoData, int, error) {
|
|
|
+
|
|
|
+ var supplierUserInfo *http_model.UpdateAccountInfoData
|
|
|
+ supplierUserInfo = &http_model.UpdateAccountInfoData{}
|
|
|
+ supplierUserInfo.EnterpriseName = req.EnterpriseName
|
|
|
+ supplierUserInfo.Avatar = req.Avatar
|
|
|
+ supplierUserInfo.Phone = req.Phone
|
|
|
+ supplierUserInfo.SubAccountName = req.SubAccountName
|
|
|
+
|
|
|
+ if req.SubAccountId == 0 {
|
|
|
+ // 商家主账号
|
|
|
+ // 1. 若修改绑定手机号
|
|
|
+ if req.Phone != "" {
|
|
|
+ // 1.1. 校验验证码
|
|
|
+ vCode, err := l.getSessionCode(ctx, req.Phone)
|
|
|
+ if err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ if vCode != req.Code {
|
|
|
+ return nil, 1, nil
|
|
|
+ }
|
|
|
+ // 1.2. 手机号是否已经被其他主账号绑定
|
|
|
+ enterpriseNum, enterpriseNumErr := db.CountEnterpriseUserByPhone(ctx, req.Phone)
|
|
|
+ if enterpriseNumErr != nil {
|
|
|
+ // log.Infof("[GetSupplierAccountInfo] fail,err:%+v", supplierNumErr)
|
|
|
+ return nil, 0, enterpriseNumErr
|
|
|
+ }
|
|
|
+ if enterpriseNum != 0 {
|
|
|
+ return nil, 2, nil
|
|
|
+ }
|
|
|
+ // 1.3. 手机号是否被子账号绑定
|
|
|
+ subAccountNum, SubAccountErr := db.CountSubAccountUserByPhone(ctx, req.Phone)
|
|
|
+ if SubAccountErr != nil {
|
|
|
+ // log.Infof("[GetSupplierAccountInfo] fail,err:%+v", SubAccountErr)
|
|
|
+ return nil, 0, SubAccountErr
|
|
|
+ }
|
|
|
+ if subAccountNum != 0 {
|
|
|
+ return nil, 3, nil
|
|
|
+ }
|
|
|
+ // 1.4. 修改Enterprise信息
|
|
|
+ var enterpriseInfo *gorm_model.Enterprise
|
|
|
+ enterpriseInfo = &gorm_model.Enterprise{}
|
|
|
+ enterpriseInfo.EnterpriseID = req.EnterpriseId
|
|
|
+ enterpriseInfo.EnterpriseName = req.EnterpriseName
|
|
|
+ enterpriseInfo.Avatar = req.Avatar
|
|
|
+ enterpriseInfo.Phone = req.Phone
|
|
|
+ updateEnterpriseErr := db.UpdateEnterpriseById(ctx, enterpriseInfo)
|
|
|
+ if updateEnterpriseErr != nil {
|
|
|
+ // log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateEnterpriseErr)
|
|
|
+ return nil, 0, updateEnterpriseErr
|
|
|
+ }
|
|
|
+ // 1.5. 修改User表信息
|
|
|
+ enterpriseInfoQuery, enterpriseInfoQueryErr := db.GetEnterpriseByEnterpriseID(ctx, enterpriseInfo.EnterpriseID)
|
|
|
+ if enterpriseInfoQueryErr != nil {
|
|
|
+ // log.Infof("[GetSupplierAccountInfo] fail,err:%+v", supplierInfoQueryErr)
|
|
|
+ return nil, 0, enterpriseInfoQueryErr
|
|
|
+ }
|
|
|
+ if enterpriseInfoQuery != nil {
|
|
|
+ var userInfo *gorm_model.YounggeeUser
|
|
|
+ userInfo = &gorm_model.YounggeeUser{}
|
|
|
+ userInfo.ID = enterpriseInfoQuery.UserID
|
|
|
+ userInfo.Phone = enterpriseInfoQuery.Phone
|
|
|
+ userInfo.Username = enterpriseInfoQuery.Phone
|
|
|
+ updateUserInfoErr := db.UpdateUserById(ctx, userInfo)
|
|
|
+ if updateUserInfoErr != nil {
|
|
|
+ // log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateUserInfoErr)
|
|
|
+ return nil, 0, updateUserInfoErr
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ var enterpriseInfo *gorm_model.Enterprise
|
|
|
+ enterpriseInfo = &gorm_model.Enterprise{}
|
|
|
+ enterpriseInfo.EnterpriseID = req.EnterpriseId
|
|
|
+ enterpriseInfo.EnterpriseName = req.EnterpriseName
|
|
|
+ enterpriseInfo.Avatar = req.Avatar
|
|
|
+ enterpriseInfo.Phone = req.Phone
|
|
|
+ updateEnterpriseErr := db.UpdateEnterpriseById(ctx, enterpriseInfo)
|
|
|
+ if updateEnterpriseErr != nil {
|
|
|
+ // log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateEnterpriseErr)
|
|
|
+ return nil, 0, updateEnterpriseErr
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 商家子账号
|
|
|
+ var subAccountInfo *gorm_model.YounggeeSubAccount
|
|
|
+ subAccountInfo = &gorm_model.YounggeeSubAccount{}
|
|
|
+ subAccountInfo.SubAccountType = 3
|
|
|
+ subAccountInfo.EnterpriseId = req.EnterpriseId
|
|
|
+ subAccountInfo.SubAccountId = req.SubAccountId
|
|
|
+ subAccountInfo.SubAccountName = req.SubAccountName
|
|
|
+ subAccountInfo.Avatar = req.Avatar
|
|
|
+ subAccountInfo.PhoneNumber = req.Phone
|
|
|
+ updateSubAccountErr := db.UpdateSubAccount(ctx, subAccountInfo)
|
|
|
+ if updateSubAccountErr != nil {
|
|
|
+ // log.Infof("[GetSupplierAccountInfo] fail,err:%+v", updateSubAccountErr)
|
|
|
+ return nil, 0, updateSubAccountErr
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return supplierUserInfo, 0, nil
|
|
|
+}
|
|
|
+
|
|
|
+// UpdateEnterpriseContactInfo 更新商家联系方式
|
|
|
+func (l *loginAuth) UpdateEnterpriseContactInfo(ctx context.Context, req *http_model.UpdateContactInfoRequest) (*http_model.UpdateContactInfoData, bool, error) {
|
|
|
+
|
|
|
+ var contactInfo *http_model.UpdateContactInfoData
|
|
|
+ contactInfo = &http_model.UpdateContactInfoData{}
|
|
|
+
|
|
|
+ // 主账号
|
|
|
+ if req.SubAccountId == 0 {
|
|
|
+ // 1. 若更新联系电话则需要验证码校验
|
|
|
+ if req.ContactPhone != "" {
|
|
|
+ vcode, err := l.getSessionCode(ctx, req.ContactPhone)
|
|
|
+ if err != nil {
|
|
|
+ return nil, false, err
|
|
|
+ }
|
|
|
+ // fmt.Printf("缓存的验证码 vcode: %v,实际填入的 code:%v", vcode, req.Code)
|
|
|
+ if vcode != req.Code {
|
|
|
+ // 验证码错误
|
|
|
+ return nil, true, err
|
|
|
+ }
|
|
|
+ var enterpriseInfo *gorm_model.Enterprise
|
|
|
+ enterpriseInfo = &gorm_model.Enterprise{}
|
|
|
+ enterpriseInfo.ContactPhone = req.ContactPhone
|
|
|
+ enterpriseInfo.EnterpriseID = req.EnterpriseId
|
|
|
+ updateEnterpriseErr := db.UpdateEnterpriseById(ctx, enterpriseInfo)
|
|
|
+ if updateEnterpriseErr != nil {
|
|
|
+ // log.Infof("[updateEnterpriseErr] fail,err:%+v", updateEnterpriseErr)
|
|
|
+ return nil, false, updateEnterpriseErr
|
|
|
+ }
|
|
|
+ contactInfo.ContactPhone = req.ContactPhone
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 微信二维码更新
|
|
|
+ if req.WechatQRCode != "" {
|
|
|
+ var enterpriseInfo *gorm_model.Enterprise
|
|
|
+ enterpriseInfo = &gorm_model.Enterprise{}
|
|
|
+ enterpriseInfo.WechatQrCode = req.WechatQRCode
|
|
|
+ enterpriseInfo.EnterpriseID = req.EnterpriseId
|
|
|
+ updateEnterpriseErr := db.UpdateEnterpriseById(ctx, enterpriseInfo)
|
|
|
+ if updateEnterpriseErr != nil {
|
|
|
+ // log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateEnterpriseErr)
|
|
|
+ return nil, false, updateEnterpriseErr
|
|
|
+ }
|
|
|
+ contactInfo.WechatQRCode = req.WechatQRCode
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 微信号码更新
|
|
|
+ if req.WechatNumber != "" {
|
|
|
+ var enterpriseInfo *gorm_model.Enterprise
|
|
|
+ enterpriseInfo = &gorm_model.Enterprise{}
|
|
|
+ enterpriseInfo.WechatNumber = req.WechatNumber
|
|
|
+ enterpriseInfo.EnterpriseID = req.EnterpriseId
|
|
|
+ updateEnterpriseErr := db.UpdateEnterpriseById(ctx, enterpriseInfo)
|
|
|
+ if updateEnterpriseErr != nil {
|
|
|
+ // log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateEnterpriseErr)
|
|
|
+ return nil, false, updateEnterpriseErr
|
|
|
+ }
|
|
|
+ contactInfo.WechatNumber = req.WechatNumber
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 子账号
|
|
|
+ // 1. 若更新联系电话则需要验证码校验
|
|
|
+ if req.ContactPhone != "" {
|
|
|
+ vcode, err := l.getSessionCode(ctx, req.ContactPhone)
|
|
|
+ if err != nil {
|
|
|
+ return nil, false, err
|
|
|
+ }
|
|
|
+ // fmt.Printf("缓存的验证码 vcode: %v,实际填入的 code:%v", vcode, req.Code)
|
|
|
+ if vcode != req.Code {
|
|
|
+ // 验证码错误
|
|
|
+ return nil, true, err
|
|
|
+ }
|
|
|
+ var subAccountInfo *gorm_model.YounggeeSubAccount
|
|
|
+ subAccountInfo = &gorm_model.YounggeeSubAccount{}
|
|
|
+ subAccountInfo.ContactPhone = req.ContactPhone
|
|
|
+ subAccountInfo.SubAccountId = req.SubAccountId
|
|
|
+ updateSupplierErr := db.UpdateSubAccount(ctx, subAccountInfo)
|
|
|
+ if updateSupplierErr != nil {
|
|
|
+ // log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
|
|
|
+ return nil, false, updateSupplierErr
|
|
|
+ }
|
|
|
+ contactInfo.ContactPhone = req.ContactPhone
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 微信二维码更新
|
|
|
+ if req.WechatQRCode != "" {
|
|
|
+ var subAccountInfo *gorm_model.YounggeeSubAccount
|
|
|
+ subAccountInfo = &gorm_model.YounggeeSubAccount{}
|
|
|
+ subAccountInfo.WechatQRCode = req.WechatQRCode
|
|
|
+ subAccountInfo.SubAccountId = req.SubAccountId
|
|
|
+ updateSupplierErr := db.UpdateSubAccount(ctx, subAccountInfo)
|
|
|
+ if updateSupplierErr != nil {
|
|
|
+ // log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
|
|
|
+ return nil, false, updateSupplierErr
|
|
|
+ }
|
|
|
+ contactInfo.WechatQRCode = req.WechatQRCode
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 微信号码更新
|
|
|
+ if req.WechatNumber != "" {
|
|
|
+ var subAccountInfo *gorm_model.YounggeeSubAccount
|
|
|
+ subAccountInfo = &gorm_model.YounggeeSubAccount{}
|
|
|
+ subAccountInfo.WechatNumber = req.WechatNumber
|
|
|
+ subAccountInfo.SubAccountId = req.SubAccountId
|
|
|
+ updateSupplierErr := db.UpdateSubAccount(ctx, subAccountInfo)
|
|
|
+ if updateSupplierErr != nil {
|
|
|
+ // log.Infof("[UpdateSupplierContactInfo] fail,err:%+v", updateSupplierErr)
|
|
|
+ return nil, false, updateSupplierErr
|
|
|
+ }
|
|
|
+ contactInfo.WechatNumber = req.WechatNumber
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return contactInfo, true, nil
|
|
|
+}
|