yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/ctyun/crm.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ctyun
    16  
    17  import (
    18  	"yunion.io/x/jsonutils"
    19  	"yunion.io/x/pkg/errors"
    20  )
    21  
    22  type SCrmUser struct {
    23  	LoginName   string `json:"loginName"`
    24  	LoginEmail  string `json:"loginEmail"`
    25  	RootUserid  string `json:"rootUserid"`
    26  	CreateDate  int64  `json:"createDate"`
    27  	AccountType int64  `json:"accountType"`
    28  	Status      int64  `json:"status"`
    29  	Province    string `json:"province"`
    30  	City        string `json:"city"`
    31  	Mobilephone string `json:"mobilephone"`
    32  	Postpaid    int64  `json:"postpaid"`
    33  	Channel     int64  `json:"channel"`
    34  	AuditStatus string `json:"auditStatus"`
    35  	AuditMsg    string `json:"auditMsg"`
    36  }
    37  
    38  func (self *SRegion) getCustiomInfo(t string, crmBizId string, accountId string) jsonutils.JSONObject {
    39  	if len(t) == 0 {
    40  		return nil
    41  	}
    42  
    43  	customeInfo := jsonutils.NewDict()
    44  	//customeInfo.Set("name", jsonutils.NewString(""))
    45  	//customeInfo.Set("email", jsonutils.NewString(""))
    46  	//customeInfo.Set("phone", jsonutils.NewString(""))
    47  	indentity := jsonutils.NewDict()
    48  	if len(crmBizId) > 0 {
    49  		indentity.Set("crmBizId", jsonutils.NewString(crmBizId))
    50  	}
    51  
    52  	if len(accountId) > 0 {
    53  		indentity.Set("accountId", jsonutils.NewString(accountId))
    54  	}
    55  
    56  	if len(t) > 0 {
    57  		customeInfo.Set("type", jsonutils.NewString(t))
    58  		customeInfo.Set("identity", indentity)
    59  	}
    60  
    61  	return customeInfo
    62  }
    63  
    64  func (self *SRegion) GetCrmUser(t string, crmBizId string, accountId string) (*SCrmUser, error) {
    65  	params := map[string]string{
    66  		"regionId": self.GetId(),
    67  	}
    68  
    69  	customInfo := self.getCustiomInfo(t, crmBizId, accountId)
    70  	if customInfo != nil {
    71  		params["customInfo"] = customInfo.String()
    72  	}
    73  
    74  	resp, err := self.client.DoGet("/apiproxy/v3/queryCRM", params)
    75  	if err != nil {
    76  		return nil, errors.Wrap(err, "Region.queryCRM.DoGet")
    77  	}
    78  
    79  	user := &SCrmUser{}
    80  	err = resp.Unmarshal(user, "returnObj")
    81  	if err != nil {
    82  		return nil, errors.Wrap(err, "Region.queryCRM.Unmarshal")
    83  	}
    84  
    85  	return user, nil
    86  }