浏览代码

Merge branch 'mfyx_3.0' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 11 月之前
父节点
当前提交
800ce20999

+ 13 - 5
controllers/yanxuan_special.go

@@ -204,7 +204,7 @@ func (this *YanxuanSpecialController) Detail() {
 
 	//如果状态未审核通过,而且查看的不是本人,不是审核人员,就无法查看详情
 	var configCode string
-	configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
+	configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
 	cnf, err := models.GetConfigByCode(configCode)
 	if err != nil {
 		br.Msg = "获取失败"
@@ -452,6 +452,7 @@ func (this *YanxuanSpecialController) Save() {
 		go services.SendWxMsgSpecialFollow(req.Id)                     //研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
 		go services.SendWxMsgSpecialAuthor(req.Id, 2)                  //研选专栏审核完成时,给提交人发送模板消息
 		go services.UdpateYanxuanSpecialauthorArticleNum(authorUserId) //  更新作者发布文章的数量
+		go services.MakeYanxuanSpecialMomentsImg(specialId)            //  生成研选专栏分享到朋友圈的图片
 	} else {
 		if req.DoType == 2 {
 			go services.SendReviewTemplateMsgAdmin(specialId)
@@ -560,6 +561,7 @@ func (this *YanxuanSpecialController) Enable() {
 	go services.EsAddYanxuanSpecial(req.Id)                                               //  写入es 综合搜索
 	go services.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) //  添加审核记录日志
 	go services.UdpateYanxuanSpecialauthorArticleNum(detail.UserId)                       //  更新作者发布文章的数量
+	go services.MakeYanxuanSpecialMomentsImg(req.Id)                                      //  生成研选专栏分享到朋友圈的图片
 	br.Msg = "审批成功"
 	br.Ret = 200
 	br.Success = true
@@ -601,12 +603,15 @@ func (this *YanxuanSpecialController) Collect() {
 	}
 	var sellerName string
 	sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
-	if err != nil {
+	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "查询栏目详情失败!"
 		br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
 		return
 	}
-	sellerName = sellerItemQy.RealName
+	if sellerItemQy != nil {
+		sellerName = sellerItemQy.RealName
+	}
+
 	if req.Status == 1 {
 		item := models.CygxYanxuanSpecialCollect{
 			UserId:           user.UserId,
@@ -784,12 +789,15 @@ func (this *YanxuanSpecialController) Follow() {
 	}
 	var sellerName string
 	sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
-	if err != nil {
+	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "查询栏目详情失败!"
 		br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
 		return
 	}
-	sellerName = sellerItemQy.RealName
+	if sellerItemQy != nil {
+		sellerName = sellerItemQy.RealName
+	}
+
 	if req.Status == 1 {
 		item := models.CygxYanxuanSpecialFollow{
 			UserId:           user.UserId,

+ 9 - 0
models/cygx_yanxuan_special.go

@@ -357,3 +357,12 @@ func UpdateYanxuanSpecialarticleCollectNum(collectNum, id int) (err error) {
 	_, err = o.Raw(sql, collectNum, id).Exec()
 	return
 }
+
+// 添加朋友圈分享封面图片
+func UpdateYanxuanSpecialMomentsImg(momentsImg string, id int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special SET moments_img = ?  WHERE id = ? `
+	_, err = o.Raw(sql, momentsImg, id).Exec()
+	return
+}

+ 8 - 0
models/cygx_yanxuan_special_user.go

@@ -261,3 +261,11 @@ func UpdateYanxuanSpecialauthorUvUm(pv, userId int) (err error) {
 	_, err = o.Raw(sql, pv, userId).Exec()
 	return
 }
+
+// 更新作者分享到朋友圈的封面图片
+func UpdateYanxuanSpecialauthorMomentsImg(momentsImg string, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_yanxuan_special_author SET moments_img = ?  WHERE user_id = ? `
+	_, err = o.Raw(sql, momentsImg, userId).Exec()
+	return
+}

+ 1 - 1
services/config.go

@@ -120,7 +120,7 @@ func CheckYxSpecialIsApprovalPersonnel(mobile string) (isApprovalPersonnel bool)
 	}()
 	var configCode string
 	//获取配置项里面审核人员的手机号
-	configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
+	configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
 	cnf, e := models.GetConfigByCode(configCode)
 	if e != nil {
 		err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)

+ 3 - 3
services/cygx_yanxuan_special.go

@@ -97,7 +97,7 @@ func SendWxMsgSpecialFollow(specialId int) (err error) {
 	return
 }
 
-// SendReviewTemplateMsgAdmin 提交审核时给王芳,汪洋发消息
+// SendReviewTemplateMsgAdmin 提交审核时给王芳,葛琳发消息
 func SendReviewTemplateMsgAdmin(specialId int) (err error) {
 	defer func() {
 		if err != nil {
@@ -105,8 +105,8 @@ func SendReviewTemplateMsgAdmin(specialId int) (err error) {
 		}
 	}()
 	var configCode string
-	//如果是研选的就推送给汪洋跟王芳,否则就推送给王芳
-	configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
+	//研选专栏修改之后给这些手机号推送审核模版消息
+	configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
 	cnf, e := models.GetConfigByCode(configCode)
 	if e != nil {
 		err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)

+ 249 - 0
services/html2Img.go

@@ -0,0 +1,249 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"io/ioutil"
+	"net/http"
+	"strconv"
+	"strings"
+)
+
+var (
+	ServerUrl                = "http://127.0.0.1:5008/"
+	Cygx_activity_sigin_html = "cygx_activity_sigin_html"
+	Cygx_mp3_html            = "cygx_mp3_html"
+	Cygx_mp4_html            = "cygx_mp4_html"
+)
+
+type Html2ImgResp struct {
+	Code int    `json:"code"`
+	Msg  string `json:"msg"`
+	Data string `json:"data"`
+}
+
+// postHtml2Img 请求htm2img接口
+func postHtml2Img(param map[string]interface{}) (resp *Html2ImgResp, err error) {
+	// 目前仅此处调用该接口,暂不加授权、校验等
+	postUrl := ServerUrl + "htm2img"
+	postData, err := json.Marshal(param)
+	if err != nil {
+		return
+	}
+	result, err := Html2ImgHttpPost(postUrl, string(postData), "application/json")
+	if err != nil {
+		return
+	}
+	if err = json.Unmarshal(result, &resp); err != nil {
+		return
+	}
+	return resp, nil
+}
+
+// Html2ImgHttpPost post请求
+func Html2ImgHttpPost(url, postData string, params ...string) ([]byte, error) {
+	body := ioutil.NopCloser(strings.NewReader(postData))
+	client := &http.Client{}
+	req, err := http.NewRequest("POST", url, body)
+	if err != nil {
+		return nil, err
+	}
+	contentType := "application/x-www-form-urlencoded;charset=utf-8"
+	if len(params) > 0 && params[0] != "" {
+		contentType = params[0]
+	}
+	req.Header.Set("Content-Type", contentType)
+	resp, err := client.Do(req)
+	if err != nil {
+		return nil, err
+	}
+	defer resp.Body.Close()
+	b, err := ioutil.ReadAll(resp.Body)
+	fmt.Println("HttpPost:" + string(b))
+	return b, err
+}
+
+//func init() {
+//	MakeYanxuanSpecialMomentsImg(185)
+//}
+
+// 生成研选专栏分享到朋友圈的图片
+func MakeYanxuanSpecialMomentsImg(specialId int) (imgUrl string) {
+	var err error
+	//time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go utils.SendAlarmMsg("生成研选专栏分享到朋友圈的图片,MakeYanxuanSpecialMomentsImg Err:"+err.Error()+"专栏ID"+strconv.Itoa(specialId), 3)
+		}
+	}()
+	detail, e := models.GetYanxuanSpecialById(specialId, 0)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialById, Err: " + e.Error())
+		return
+	}
+	go GetYanxuanSpecialAuthoListMomentsImg() //有专栏生成的时候,最新专栏列表封面图
+	configCode := "yanxuan_special_moments_img_html"
+	detailConfig, e := models.GetConfigByCode(configCode)
+	if e != nil {
+		err = errors.New("GetCygxConfigDetailByCode 获取生成研选专栏分享到朋友圈的图片格式信息失败, Err: " + e.Error())
+		return
+	}
+	var typeName, content string
+	if detail.Type == 1 {
+		typeName = "笔记"
+	} else {
+		typeName = "观点"
+	}
+	content, _ = GetReportContentTextSubNew(detail.Content)
+	configValue := detailConfig.ConfigValue
+	configValue = strings.Replace(configValue, "{{HeadImg}}", detail.HeadImg, -1)
+	configValue = strings.Replace(configValue, "{{NickName}}", detail.NickName, -1)
+	configValue = strings.Replace(configValue, "{{TypeName}}", typeName, -1)
+	configValue = strings.Replace(configValue, "{{PublishTime}}", detail.PublishTime, -1)
+	configValue = strings.Replace(configValue, "{{Title}}", detail.Title, -1)
+	configValue = strings.Replace(configValue, "{{Content}}", content, -1)
+
+	htm2ImgReq := make(map[string]interface{})
+	htm2ImgReq["html_content"] = configValue
+	htm2ImgReq["width"] = 2250
+	htm2ImgReq["height"] = 3813
+	res, err := postHtml2Img(htm2ImgReq)
+	if err != nil || res == nil {
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	if res.Code != 200 {
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	imgUrl = res.Data
+
+	err = models.UpdateYanxuanSpecialMomentsImg(imgUrl, specialId)
+
+	return
+}
+
+// 生成研选专栏列表分享到朋友圈的图片
+func GetYanxuanSpecialAuthoListMomentsImg() (imgUrl string) {
+	var err error
+	//time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go utils.SendAlarmMsg("生成研选专栏分享到朋友圈的图片,MakeArticleMomentsImg Err:"+err.Error(), 3)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition += ` AND  a.nick_name <> ''   `
+	condition += `	ORDER BY latest_publish_time DESC`
+	list, e := models.GetYanxuanSpecialAuthorList(condition, pars, 0, 1)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialAuthorList, Err: " + e.Error())
+		return
+	}
+
+	var SpecialName, HeadImg, NickName, Introduction, PublishTime, Title string
+	var userIds []int
+	for _, v := range list {
+		SpecialName = v.SpecialName
+		HeadImg = v.HeadImg
+		NickName = v.NickName
+		Introduction = v.Introduction
+		userIds = append(userIds, v.UserId)
+	}
+	bestNew := GetBestNewYanxuanSpecialByUserId(userIds)
+	for _, v := range list {
+		if bestNew[v.UserId] != nil {
+			PublishTime = bestNew[v.UserId].PublishTime
+			Title = bestNew[v.UserId].Title
+		}
+	}
+	configCode := "special_author_list_moments_img_html"
+	detailConfig, e := models.GetConfigByCode(configCode)
+	if e != nil {
+		err = errors.New("GetCygxConfigDetailByCode 获取生成研选专栏分享到朋友圈的图片格式信息失败, Err: " + e.Error())
+		return
+	}
+	configValue := detailConfig.ConfigValue
+	configValue = strings.Replace(configValue, "{{SpecialName}}", SpecialName, -1)
+	configValue = strings.Replace(configValue, "{{HeadImg}}", HeadImg, -1)
+	configValue = strings.Replace(configValue, "{{NickName}}", NickName, -1)
+	configValue = strings.Replace(configValue, "{{Introduction}}", Introduction, -1)
+	configValue = strings.Replace(configValue, "{{PublishTime}}", PublishTime, -1)
+	configValue = strings.Replace(configValue, "{{Title}}", Title, -1)
+
+	htm2ImgReq := make(map[string]interface{})
+	htm2ImgReq["html_content"] = configValue
+	htm2ImgReq["width"] = 2250
+	htm2ImgReq["height"] = 3813
+	res, err := postHtml2Img(htm2ImgReq)
+	if err != nil || res == nil {
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	if res.Code != 200 {
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	imgUrl = res.Data
+	configCodeUpdate := "special_author_list_moments_img"
+	err = models.UpdateConfigByCode(imgUrl, configCodeUpdate)
+	return
+}
+
+// 生成研选专栏分享到朋友圈的图片
+func GetYanxuanSpecialAuthoMomentsImg(userId int) (imgUrl string) {
+	var err error
+	//time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go utils.SendAlarmMsg("生成研选专栏分享到朋友圈的图片,MakeArticleMomentsImg Err:"+err.Error()+"用户ID"+strconv.Itoa(userId), 3)
+		}
+	}()
+
+	articleInfo, e := models.GetYanxuanSpecialAuthor(userId, 0, "")
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialAuthor, Err: " + e.Error())
+		return
+	}
+
+	configCode := "special_author_moments_img_html"
+	detailConfig, e := models.GetConfigByCode(configCode)
+	if e != nil {
+		err = errors.New("GetCygxConfigDetailByCode 获取生成研选专栏分享到朋友圈的图片格式信息失败, Err: " + e.Error())
+		return
+	}
+	configValue := detailConfig.ConfigValue
+	configValue = strings.Replace(configValue, "{{HeadImg}}", articleInfo.HeadImg, -1)
+	configValue = strings.Replace(configValue, "{{SpecialName}}", articleInfo.SpecialName, -1)
+	configValue = strings.Replace(configValue, "{{NickName}}", articleInfo.NickName, -1)
+	configValue = strings.Replace(configValue, "{{SpecialArticleNum}}", strconv.Itoa(articleInfo.SpecialArticleNum), -1)
+	configValue = strings.Replace(configValue, "{{CollectNum}}", strconv.Itoa(articleInfo.CollectNum), -1)
+	configValue = strings.Replace(configValue, "{{FollowNum}}", strconv.Itoa(articleInfo.FollowNum), -1)
+	configValue = strings.Replace(configValue, "{{Introduction}}", articleInfo.Introduction, -1)
+
+	htm2ImgReq := make(map[string]interface{})
+	htm2ImgReq["html_content"] = configValue
+	htm2ImgReq["width"] = 2250
+	htm2ImgReq["height"] = 3813
+	res, err := postHtml2Img(htm2ImgReq)
+	if err != nil || res == nil {
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	if res.Code != 200 {
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	imgUrl = res.Data
+	err = models.UpdateYanxuanSpecialauthorMomentsImg(imgUrl, userId)
+	fmt.Println(imgUrl)
+	return
+
+}

+ 3 - 3
utils/config.go

@@ -146,8 +146,8 @@ func init() {
 	SummaryArticleId = 1000000         //手动添加的纪要库开始ID
 	YanxSummaryPermissionId = 1001     //研选纪要分类ID
 	YanxViewpointPermissionId = 1002   //研选观点分类ID
-	WxMsgTemplateIdAskMsgMobileAll = "15557270714,18767183922,18621268829,18955528215"
-	WxMsgTemplateIdAskMsgMobilePublic = "15557270714,18767183922,18621268829" // 沈涛:18767183922、 王芳:18621268829
+	WxMsgTemplateIdAskMsgMobileAll = "15557270714,18767183922,18621268829"
+	WxMsgTemplateIdAskMsgMobilePublic = "15557270714,18767183922,18621268829"
 	HtgjDefaultSaleName = "王芳"
 	HtgjSalt = "HTGJ&HZ"
 	HtgjName = "海通国际"
@@ -181,7 +181,7 @@ func init() {
 		WxMsgTemplateIdArticleUserRemind = "fxnlsjx-gm3dAZVJf6f3w27wA7anETl42kexXLP8FDs"
 		WxMsgTemplateIdAskMsgMobile = ""
 		//ActSendMsgMobile = "15618524605"
-		ActSendMsgMobile = "18955528215" // 汪洋手机号
+		ActSendMsgMobile = "15557270714" // 汪洋手机号
 		ArticleTaskClassMobile = "15557270714,18767183922,15216736473,15000123056,18701809782,17706316791,18652179672"
 
 		ShangHaiCrmApiLink = "https://crm.hzinsights.com/"

+ 6 - 5
utils/constants.go

@@ -221,11 +221,12 @@ const (
 )
 
 const (
-	TPL_MSG_WANG_YANG                  = "tpl_msg_wang_yang"           //汪洋手机号地址参数
-	TPL_MSG_WANG_FANG_WANG_YANG        = "tpl_msg_wang_fang_wang_yang" //权限模板消息接收人,王芳,汪洋
-	TPL_MSG                            = "tpl_msg"                     //王芳手机号地址参数
-	TPL_MSG_NEI_RONG_ZU                = "tpl_msg_nei_rong_zu"         //内容组四人
-	CYGX_TAG_HOT_ACTIVITY_ID    string = "cygx_tag_hot_activity_id"    //标签管理自定义的热门活动ID
+	TPL_MSG_WANG_YANG                        = "tpl_msg_wang_yang"                 //汪洋手机号地址参数
+	TPL_MSG_WANG_FANG_WANG_YANG              = "tpl_msg_wang_fang_wang_yang"       //权限模板消息接收人,王芳,汪洋
+	TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL        = "tpl_msg_yan_xuan_special_approval" //研选专栏修改之后给这些手机号推送审核模版消息
+	TPL_MSG                                  = "tpl_msg"                           //王芳手机号地址参数
+	TPL_MSG_NEI_RONG_ZU                      = "tpl_msg_nei_rong_zu"               //内容组四人
+	CYGX_TAG_HOT_ACTIVITY_ID          string = "cygx_tag_hot_activity_id"          //标签管理自定义的热门活动ID
 )
 
 const (