|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "hongze/hz_crm_api/models/cygx"
|
|
|
"hongze/hz_crm_api/services/alarm_msg"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
"io/ioutil"
|
|
@@ -11,6 +12,7 @@ import (
|
|
|
"net/url"
|
|
|
"sort"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -265,3 +267,88 @@ func GetSign(params map[string]string) (paramStr string) {
|
|
|
params["appId"] = utils.COMEIN_APPID
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+type ComeinUpdateActivityPublishReq struct {
|
|
|
+ Action string `description:"publish新增 edit修改 delete:删除" json:"action"`
|
|
|
+ Module string `description:"活动:activities" json:"module"`
|
|
|
+ EntityId int `description:"对应activityId" json:"entity_id"`
|
|
|
+}
|
|
|
+
|
|
|
+type ComeinUpdateActivityPublishResp struct {
|
|
|
+ Code string `json:"code"`
|
|
|
+ Msg string `json:"msg"`
|
|
|
+ Errordesc string `json:"errordesc"`
|
|
|
+ Errorcode string `json:"errorcode"`
|
|
|
+ TipType string `json:"tipType"`
|
|
|
+}
|
|
|
+
|
|
|
+// 活动更新,同步到进门财经
|
|
|
+func ComeinUpdateActivityPublish(activityId int, action string) {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go alarm_msg.SendAlarmMsg(fmt.Sprint("活动更新,同步到进门财经接口失败,activityId:", activityId, "action", action)+err.Error(), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ if action != "delete" {
|
|
|
+ activityInfo, e := cygx.GetAddActivityInfoById(activityId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New(fmt.Sprint("活动更新,同步到进门财经接口失败 GetAddActivityInfoById:", e.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
|
|
|
+ return //研选活动不同步
|
|
|
+ }
|
|
|
+ }
|
|
|
+ postUrl := utils.COMEIN_ACTIVITY_URL + "/open-brm/hz-data/change-notice"
|
|
|
+ params := ComeinUpdateActivityPublishReq{
|
|
|
+ Action: action,
|
|
|
+ Module: "activities",
|
|
|
+ EntityId: activityId,
|
|
|
+ }
|
|
|
+ postData, e := json.Marshal(params)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New(fmt.Sprint("活动更新,同步到进门财经接口失败 Marshal:", e.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ method := "POST"
|
|
|
+ client := &http.Client{}
|
|
|
+ req, e := http.NewRequest(method, postUrl, strings.NewReader(string(postData)))
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New(fmt.Sprint("活动更新,同步到进门财经接口失败 NewRequest:", e.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ req.Header.Add("Content-Type", "application/json")
|
|
|
+ res, e := client.Do(req)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New(fmt.Sprint("活动更新,同步到进门财经接口失败 client:", e.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, e := ioutil.ReadAll(res.Body)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New(fmt.Sprint("活动更新,同步到进门财经接口失败 ReadAll:", e.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ itemApiLog := new(cygx.CygxThreeApiLog)
|
|
|
+ itemApiLog.CreateTime = time.Now()
|
|
|
+ itemApiLog.Source = 1
|
|
|
+ itemApiLog.Url = postUrl
|
|
|
+ itemApiLog.Body = string(postData)
|
|
|
+ itemApiLog.Result = string(body)
|
|
|
+ go cygx.AddCygxThreeApiLog(itemApiLog)
|
|
|
+ var ComeinResp *ComeinUpdateActivityPublishResp
|
|
|
+ e = json.Unmarshal(body, &ComeinResp)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New(fmt.Sprint("活动更新,同步到进门财经接口失败 Unmarshal:", e.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if ComeinResp.Code != "0" {
|
|
|
+ err = errors.New(fmt.Sprint("活动更新,同步到进门财经接口失败 Code:", ComeinResp.Code))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println(string(body))
|
|
|
+ return
|
|
|
+}
|