作者 唐旭辉

紧急更新 合伙人新增类型:业务-产品应用合伙人

@@ -32,7 +32,8 @@ func (command CreatePartnerInfoCommand) ValidateCommand() error { @@ -32,7 +32,8 @@ func (command CreatePartnerInfoCommand) ValidateCommand() error {
32 } 32 }
33 if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 || 33 if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 ||
34 command.PartnerCategory == domain.PARTNER_CATEGORY_2 || 34 command.PartnerCategory == domain.PARTNER_CATEGORY_2 ||
35 - command.PartnerCategory == domain.PARTNER_CATEGORY_3) { 35 + command.PartnerCategory == domain.PARTNER_CATEGORY_3 ||
  36 + command.PartnerCategory == domain.PARTNER_CATEGORY_4) {
36 return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误") 37 return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
37 } 38 }
38 if len(command.PartnerName) == 0 { 39 if len(command.PartnerName) == 0 {
@@ -28,7 +28,8 @@ func (command *UpdatePartnerInfoCommand) ValidateCommand() error { @@ -28,7 +28,8 @@ func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
28 } 28 }
29 if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 || 29 if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 ||
30 command.PartnerCategory == domain.PARTNER_CATEGORY_2 || 30 command.PartnerCategory == domain.PARTNER_CATEGORY_2 ||
31 - command.PartnerCategory == domain.PARTNER_CATEGORY_3) { 31 + command.PartnerCategory == domain.PARTNER_CATEGORY_3 ||
  32 + command.PartnerCategory == domain.PARTNER_CATEGORY_4) {
32 return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误") 33 return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
33 } 34 }
34 if command.RegionInfo == nil { 35 if command.RegionInfo == nil {
@@ -7,8 +7,28 @@ const SERVICE_NAME = "partnermg" @@ -7,8 +7,28 @@ const SERVICE_NAME = "partnermg"
7 var LOG_LEVEL = "debug" 7 var LOG_LEVEL = "debug"
8 var LOG_File = "./logs/partnermg.log" 8 var LOG_File = "./logs/partnermg.log"
9 9
  10 +var (
  11 + UCENTER_HOST = "http://suplus-ucenter-dev.fjmaimaimai.com" //统一用户中心地址
  12 + UCENTER_SECRET = "cykbjnfqgctn"
  13 + UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b"
  14 + UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735"
  15 +)
  16 +
10 func init() { 17 func init() {
11 if os.Getenv("LOG_LEVEL") != "" { 18 if os.Getenv("LOG_LEVEL") != "" {
12 LOG_LEVEL = os.Getenv("LOG_LEVEL") 19 LOG_LEVEL = os.Getenv("LOG_LEVEL")
13 } 20 }
  21 + if os.Getenv("UCENTER_HOST") != "" {
  22 + LOG_LEVEL = os.Getenv("UCENTER_HOST")
  23 + }
  24 + if os.Getenv("UCENTER_SECRET") != "" {
  25 + LOG_LEVEL = os.Getenv("UCENTER_SECRET")
  26 + }
  27 + if os.Getenv("UCENTER_APP_KEY") != "" {
  28 + LOG_LEVEL = os.Getenv("UCENTER_APP_KEY")
  29 + }
  30 + if os.Getenv("UCENTER_CHECK_ALT") != "" {
  31 + LOG_LEVEL = os.Getenv("UCENTER_CHECK_ALT")
  32 + }
  33 +
14 } 34 }
@@ -11,12 +11,12 @@ const ( @@ -11,12 +11,12 @@ const (
11 PARTNER_STATUS_YES int = 1 11 PARTNER_STATUS_YES int = 1
12 ) 12 )
13 13
14 -//合伙类别 (1.事业合伙人 2.业务合伙人 4.研发合伙人)  
15 -//按二进制位区分:001 = 1; 010 = 2; 100=4 14 +//合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人)
16 const ( 15 const (
17 PARTNER_CATEGORY_1 int = 1 16 PARTNER_CATEGORY_1 int = 1
18 PARTNER_CATEGORY_2 int = 2 17 PARTNER_CATEGORY_2 int = 2
19 - PARTNER_CATEGORY_3 int = 4 18 + PARTNER_CATEGORY_3 int = 3
  19 + PARTNER_CATEGORY_4 int = 4
20 ) 20 )
21 21
22 //partnerCategoryMap 合伙类别键值对 (只读,请勿在运行时修改) 22 //partnerCategoryMap 合伙类别键值对 (只读,请勿在运行时修改)
@@ -24,6 +24,7 @@ var partnerCategoryMap = map[int]string{ @@ -24,6 +24,7 @@ var partnerCategoryMap = map[int]string{
24 PARTNER_CATEGORY_1: "事业合伙人", 24 PARTNER_CATEGORY_1: "事业合伙人",
25 PARTNER_CATEGORY_2: "业务合伙人", 25 PARTNER_CATEGORY_2: "业务合伙人",
26 PARTNER_CATEGORY_3: "研发合伙人", 26 PARTNER_CATEGORY_3: "研发合伙人",
  27 + PARTNER_CATEGORY_4: "业务-产品应用合伙人",
27 } 28 }
28 29
29 type PartnerInfo struct { 30 type PartnerInfo struct {
1 package service_gateway 1 package service_gateway
2 2
3 import ( 3 import (
4 - "encoding/json"  
5 - "fmt"  
6 - "strconv"  
7 - "strings"  
8 "time" 4 "time"
9 -  
10 - "github.com/astaxie/beego/httplib"  
11 ) 5 )
12 6
13 type httplibBaseServiceGateway struct { 7 type httplibBaseServiceGateway struct {
@@ -15,48 +9,3 @@ type httplibBaseServiceGateway struct { @@ -15,48 +9,3 @@ type httplibBaseServiceGateway struct {
15 connectTimeout time.Duration 9 connectTimeout time.Duration
16 readWriteTimeout time.Duration 10 readWriteTimeout time.Duration
17 } 11 }
18 -  
19 -func (serviceGateway *httplibBaseServiceGateway) createRequest(url string, method string) *httplib.BeegoHTTPRequest {  
20 - var request *httplib.BeegoHTTPRequest  
21 - switch method {  
22 - case "get":  
23 - request = httplib.Get(url)  
24 - break  
25 - case "post":  
26 - request = httplib.Post(url)  
27 - break  
28 - case "put":  
29 - request = httplib.Put(url)  
30 - break  
31 - case "delete":  
32 - request = httplib.Delete(url)  
33 - break  
34 - case "head":  
35 - request = httplib.Head(url)  
36 - break  
37 - default:  
38 - request = httplib.Get(url)  
39 - }  
40 - return request.SetTimeout(serviceGateway.connectTimeout, serviceGateway.readWriteTimeout)  
41 -}  
42 -  
43 -func (serviceGateway *httplibBaseServiceGateway) responseHandle(response map[string]interface{}) (map[string]interface{}, error) {  
44 - data := make(map[string]interface{})  
45 - var err error  
46 - if code, ok := response["code"]; ok {  
47 - code := code.(float64)  
48 - if code == 0 {  
49 - data = response["data"].(map[string]interface{})  
50 - } else {  
51 - msg := response["msg"].(string)  
52 - err = fmt.Errorf(strings.Join([]string{strconv.FormatFloat(code, 'f', -1, 64), msg}, " "))  
53 - }  
54 - } else {  
55 - jsonBytes, marshalErr := json.Marshal(response)  
56 - if marshalErr != nil {  
57 - err = marshalErr  
58 - }  
59 - err = fmt.Errorf("无法解析的网关服务数据返回格式:%s", string(jsonBytes))  
60 - }  
61 - return data, err  
62 -}  
  1 +package service_gateway
  2 +
  3 +import (
  4 + "crypto/sha1"
  5 + "fmt"
  6 + "net/http"
  7 + "time"
  8 +
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
  10 +)
  11 +
  12 +type MmmUserCenterServiceGateway struct {
  13 + httplibBaseServiceGateway
  14 +}
  15 +
  16 +func NewMmmUserCenterServiceGateway() *MmmUserCenterServiceGateway {
  17 + return &MmmUserCenterServiceGateway{
  18 + httplibBaseServiceGateway{
  19 + baseURL: constant.UCENTER_HOST,
  20 + connectTimeout: 100 * time.Second,
  21 + readWriteTimeout: 30 * time.Second,
  22 + }}
  23 +}
  24 +
  25 +func (gateway MmmUserCenterServiceGateway) buildHeader() http.Header {
  26 + var h = http.Header{}
  27 + nowTime := fmt.Sprint(time.Now().Unix())
  28 + str := fmt.Sprintf("%s%s%s", nowTime, constant.UCENTER_SECRET, constant.UCENTER_CHECK_ALT)
  29 + bt := sha1.Sum([]byte(str))
  30 + checksum := fmt.Sprintf("%x", bt)
  31 + h.Set("Content-Type", "application/json")
  32 + h.Set("appKey", constant.UCENTER_APP_KEY)
  33 + h.Set("nonce", "")
  34 + h.Set("curTime", nowTime)
  35 + h.Set("checkSum", checksum)
  36 + h.Set("Accept", "application/json")
  37 + return h
  38 +}
  39 +
  40 +type ResponseLogin struct {
  41 + Code int `json:"code"`
  42 + Msg string `json:"msg"`
  43 + Data struct {
  44 + Id int64 `json:"id"` //统一用户中心的id,对应本系统中users表的open_id
  45 + Phone string `json:"phone"`
  46 + NickName string `json:"nickname"` //昵称
  47 + Avatar string `json:"avatar"` //头像
  48 + Imtoken string `json:"imtoken"` //网易云imtoken
  49 + Accid int64 `json:"accid"` //网易云id
  50 + CustomerAccount int64 `json:"customerAccount"` //客服id
  51 + CompanyId int64 `json:"companyId"` //总后台的公司id
  52 + Muid int64 `json:"muid"` //企业平台的用户id,对应本系统中users表的id
  53 + } `json:"data"`
  54 +}
  55 +
  56 +func (gateway MmmUserCenterServiceGateway) RequestUCenterLoginBySecret(secret string) (*ResponseLogin, error) {
  57 + // param := map[string]interface{}{
  58 + // "type": 3, //登录方式 固定值
  59 + // "secret": url.QueryEscape(secret), //必要的转换
  60 + // }
  61 + // url := "/auth/serverLogin"
  62 + // httpRequest := gateway.createRequest(url, "post")
  63 + // httpRequest.
  64 + return nil, nil
  65 +}