zhangchuanxing 12 цаг өмнө
parent
commit
d8bddec439

+ 11 - 1
controllers/cygx/activity.go

@@ -8,6 +8,7 @@ import (
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/cygx"
 	"hongze/hz_crm_api/services"
+	comeinService "hongze/hz_crm_api/services/comein"
 	cygxService "hongze/hz_crm_api/services/cygx"
 	"hongze/hz_crm_api/services/elastic"
 	"hongze/hz_crm_api/utils"
@@ -825,6 +826,7 @@ func (this *ActivityCoAntroller) PreserveAndPublish() {
 				go cygxService.YanXuanActivityPointsBillActivityPublishAndCancel(v, AdminUser.AdminId, 1) //活动发布以及取消发布处理研选扣
 				go elastic.AddComprehensiveActivity(v)
 				go cygxService.MakeActivityMomentsImg(v) //生成活动分享到朋友圈的图片
+				go comeinService.ComeinUpdateActivityPublish(v, "publish")
 				//}()
 			}
 			go cygxService.MakeActivitySigninImg(v)
@@ -838,6 +840,7 @@ func (this *ActivityCoAntroller) PreserveAndPublish() {
 		}
 		cygxService.UpdateActivityResourceData(req.ActivityId) //写入首页最新  cygx_resource_data 表
 		go cygxService.MakeActivityMomentsImg(req.ActivityId)  //生成活动分享到朋友圈的图片
+		go comeinService.ComeinUpdateActivityPublish(req.ActivityId, "edit")
 		//如果二次编辑的时候,取消了易董办会选项,那么就对易董发送取消发布到广场的通知
 		if req.IsYidongConduct == 0 {
 			go cygxService.YiDongUpdateActivityStatus(activityId)
@@ -854,6 +857,11 @@ func (this *ActivityCoAntroller) PreserveAndPublish() {
 	br.IsAddLog = true
 }
 
+//func init() {
+//	fmt.Println("222")
+//	comeinService.ComeinUpdateActivityPublish(3001, "edit")
+//}
+
 // @Title 活动列表
 // @Description 获取活动列表接口
 // @Param   PageSize   query   int  true       "每页数据条数"
@@ -1353,7 +1361,8 @@ func (this *ActivityCoAntroller) PublishAndCancel() {
 	}
 	go cygxService.YanXuanActivityPointsBillActivityPublishAndCancel(activityId, AdminUser.AdminId, item.PublishStatus) //活动发布以及取消发布处理研选扣点
 	go elastic.AddComprehensiveActivity(activityId)                                                                     // 同步Es添加活动
-	go cygxService.UpdateActivityResourceData(activityId)                                                               //写入首页最新  cygx_resource_data 表
+	go cygxService.UpdateActivityResourceData(activityId)
+	go comeinService.ComeinUpdateActivityPublish(activityId, "edit")
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"
@@ -1425,6 +1434,7 @@ func (this *ActivityCoAntroller) Delete() {
 		br.ErrMsg = "删除信息失败,Err:" + err.Error()
 		return
 	}
+	go comeinService.ComeinUpdateActivityPublish(activityId, "delete")
 	//添加操作日志记录
 
 	br.Ret = 200

+ 87 - 0
services/comein/comein.go

@@ -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
+}

+ 8 - 4
utils/config.go

@@ -66,6 +66,7 @@ var (
 	CYGX_MFYX_URL                            string //查研观向web端网址
 	WxMfyxAppId                              string //买方研选小程序APPID
 	WxMfyxAppSecret                          string //买方研选小程序 秘钥
+	JinMenCaiJingUrl                         string //进门财经请求域名
 
 	WxMsgCategoryTemplateIdActivityChangeApply       string //买方研选活动变更通知-类目模板ID
 	WxMsgCategoryTemplateIdActivityCancleApply       string //买方研选活动取消通知-类目模板ID
@@ -139,9 +140,10 @@ var (
 
 // 进门财经账号信息
 var (
-	COMEIN_URL      string
-	COMEIN_APPID    string
-	COMEIN_SECREKEY string
+	COMEIN_URL          string
+	COMEIN_APPID        string
+	COMEIN_SECREKEY     string
+	COMEIN_ACTIVITY_URL string //权益同步活动使用
 )
 
 // 公共api内部服务调用
@@ -430,7 +432,7 @@ func WxDebug() {
 	//内部员测试公众号(弘则科技)
 	{
 		AdminWxAppId = "wxe0d0a4d892da28a3"
-    	AdminWxAppSecret = "b88ac96aef1852fa0b8902c321ed4bf8"
+		AdminWxAppSecret = "b88ac96aef1852fa0b8902c321ed4bf8"
 	}
 }
 
@@ -511,10 +513,12 @@ func ComeinOpenApiConfig() {
 		COMEIN_URL = "https://server.comein.cn/comein/index.php"
 		COMEIN_APPID = "39b48779-debd-446a-a303-900322d8e356"
 		COMEIN_SECREKEY = "9102a767f20f11ecb5d6b8599f142ed4"
+		COMEIN_ACTIVITY_URL = "https://server.comein.cn/comein/institutioncenter"
 	} else {
 		COMEIN_URL = "https://testserver.comein.cn/comein/index.php"
 		COMEIN_APPID = "7b966708-4a8b-4d24-9066-fe29920e7eee"
 		COMEIN_SECREKEY = "76e004876fae4b3c8721a3f4c2d115da"
+		COMEIN_ACTIVITY_URL = "https://testserver.comein.cn/comein/institutioncenter"
 	}
 }