Pārlūkot izejas kodu

Merge branch 'cygx/cygx_14_6_v2' of http://8.136.199.33:3000/hongze/hz_crm_api

zhangchuanxing 1 nedēļu atpakaļ
vecāks
revīzija
858bb2fc98

+ 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

+ 8 - 0
controllers/cygx/report_selection.go

@@ -10,6 +10,7 @@ import (
 	"hongze/hz_crm_api/models/cygx"
 	"hongze/hz_crm_api/models/system"
 	"hongze/hz_crm_api/services"
+	comeinService "hongze/hz_crm_api/services/comein"
 	cygxService "hongze/hz_crm_api/services/cygx"
 	"hongze/hz_crm_api/utils"
 	"os"
@@ -175,6 +176,10 @@ func (this *ReportSelectionController) PreserveAndPublish() {
 			br.ErrMsg = "发布失败,Err:" + err.Error()
 			return
 		}
+
+		if detail.PublishStatus == 1 && detail.VisibleRange == 1 {
+			go comeinService.ComeinUpdateReportSelectionPublish(req.ArticleId, "edit")
+		}
 	}
 	//if req.DoType == 1 {
 	//cygxService.DoThisWeekLastWeekWxTemplateMsg(itemCrs.Title, itemCrs.PublishDate.Format(utils.FormatDateTime), itemCrs.ProductDescription, req.ArticleId, 1)
@@ -959,10 +964,13 @@ func (this *ReportSelectionController) VisibleRange() {
 		if detail.IsSendWxMsg == 0 {
 			cygxService.DoThisWeekLastWeekWxTemplateMsg(detail.Title, detail.PublishDate, detail.ProductDescription, req.ArticleId, 1)
 		}
+
+		go comeinService.ComeinUpdateReportSelectionPublish(articleId, "publish")
 	} else {
 		item.AdminId = detail.AdminId
 		item.AdminName = detail.AdminName
 		item.VisibleRange = 0
+		go comeinService.ComeinUpdateReportSelectionPublish(articleId, "delete")
 	}
 	err = cygx.ReportSelectionVisibleRange(item)
 	if err != nil {

+ 1 - 0
models/cygx/activity_signup.go

@@ -95,6 +95,7 @@ type CygxAppointmentList struct {
 	SignupType          int    `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
 	YidongExamineStatus int    `description:"易董活动报名审核状态0审核中,1:审核通过、2审核不通过"`
 	Email               string `description:"邮箱"`
+	ThreeSource         int    `description:"三方来源,1进门财经"`
 }
 
 type CygxSignupUser struct {

+ 148 - 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,149 @@ 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
+}
+
+// 重点公司报告更新,同步到进门财经
+func ComeinUpdateReportSelectionPublish(articleId int, action string) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("活动更新,同步到进门财经接口失败,articleId:", articleId, "action", action)+err.Error(), 3)
+		}
+	}()
+
+	postUrl := utils.COMEIN_ACTIVITY_URL + "/open-brm/hz-data/change-notice"
+	params := ComeinUpdateActivityPublishReq{
+		Action:   action,
+		Module:   "key_company_reports",
+		EntityId: articleId,
+	}
+	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
+}

+ 7 - 3
utils/config.go

@@ -67,6 +67,7 @@ var (
 	CYGX_MFYX_URL                              string //查研观向web端网址
 	WxMfyxAppId                                string //买方研选小程序APPID
 	WxMfyxAppSecret                            string //买方研选小程序 秘钥
+	JinMenCaiJingUrl                           string //进门财经请求域名
 
 	WxMsgCategoryTemplateIdActivityChangeApply       string //买方研选活动变更通知-类目模板ID
 	WxMsgCategoryTemplateIdActivityCancleApply       string //买方研选活动取消通知-类目模板ID
@@ -140,9 +141,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内部服务调用
@@ -515,10 +517,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"
 	}
 }