Browse Source

Merge branch 'need/cygx_1006' of http://8.136.199.33:3000/hongze/hongze_web_mfyx into debug

zhangchuanxing 4 months ago
parent
commit
9e614fe96a

+ 3 - 1
controllers/yanxuan_special.go

@@ -326,7 +326,7 @@ func (this *YanxuanSpecialNoLoginController) Detail() {
 
 	yanxuanDetail.HasPermission = hasPermission
 	resp.HasPermission = hasPermission
-
+	item.Pv += item.HzPv // 添加弘则PV
 	//字段兼容
 	resp.CygxYanxuanSpecialItem = *item
 	resp.Docs = yanxuanDetail.Docs
@@ -569,6 +569,7 @@ func (this *YanxuanSpecialController) Save() {
 		go services.UdpateYanxuanSpecialauthorArticleNum(authorUserId) //  更新作者发布文章的数量
 		go services.SendWxCategoryMsgSpecialAuthor(req.Id, 1)          //研选专栏审核完成时,给提交人发送类目模板消息
 		go services.SendWxCategoryMsgSpecialFollow(req.Id)             // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
+		go services.MakeYanxuanSpecialMomentsImg(specialId)            //  生成研选专栏分享到朋友圈的图片
 	} else {
 		if req.DoType == 2 {
 			go services.SendReviewTemplateMsgAdmin(specialId)
@@ -682,6 +683,7 @@ func (this *YanxuanSpecialController) Enable() {
 	go services.EsAddYanxuanSpecial(req.Id)                                               //  写入es 综合搜索
 	go services.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) //  写入es 综合搜索
 	go services.UdpateYanxuanSpecialauthorArticleNum(detail.UserId)                       //  更新作者发布文章的数量
+	go services.MakeYanxuanSpecialMomentsImg(req.Id)                                      //  生成研选专栏分享到朋友圈的图片
 	br.Msg = "审批成功"
 	br.Ret = 200
 	br.Success = true

+ 19 - 0
models/cygx_seller_mobile_map.go

@@ -0,0 +1,19 @@
+package models
+
+import "github.com/beego/beego/v2/client/orm"
+
+//权益销售手机号映射关系表
+
+type CygxSellerMobileMap struct {
+	RealName       string `description:"销售姓名"`
+	Mobile         string `description:"销售手机号"`
+	ServerRealName string `description:"服务销售姓名"`
+	ServerMobile   string `description:"服务销售手机号"`
+}
+
+func GetCygxSellerMobileMap() (items []*CygxSellerMobileMap, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *  FROM cygx_seller_mobile_map  LIMIT  100 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 26 - 0
models/cygx_yanxuan_special.go

@@ -61,6 +61,7 @@ type CygxYanxuanSpecialItem struct {
 	Annotation          string   `description:"核心观点"`
 	Pv                  int      `description:"Pv"`
 	Uv                  int      `description:"Uv"`
+	HzPv                int      `description:"HzPv"`
 	BodyHighlight       []string `description:"搜索高亮展示结果"`
 	LabelKeywordImgLink string   `description:"标签关键词ico"`
 	LikeCount           int      `comment:"点赞数量"`
@@ -322,6 +323,14 @@ func UpdateYanxuanSpecialPv(id int) (err error) {
 	return
 }
 
+// UpdateYanxuanSpecialHzPv 修改研选专栏的阅读弘则Pv
+func UpdateYanxuanSpecialHzPv(id int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_yanxuan_special SET hz_pv=hz_pv+1 WHERE id = ? `
+	_, err = o.Raw(sql, id).Exec()
+	return
+}
+
 // UpdateYanxuanSpecialUv 修改研选专栏的阅读Uv
 func UpdateYanxuanSpecialUv(id int) (err error) {
 	o := orm.NewOrm()
@@ -330,6 +339,14 @@ func UpdateYanxuanSpecialUv(id int) (err error) {
 	return
 }
 
+// UpdateYanxuanSpecialHzUv 修改研选专栏的阅读弘则Uv
+func UpdateYanxuanSpecialHzUv(id int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_yanxuan_special SET hz_uv=hz_uv+1 WHERE id = ? `
+	_, err = o.Raw(sql, id).Exec()
+	return
+}
+
 // 增加收藏数量
 func UpdateYanxuanSpecialarticleCollectNumIncrease(id int) (err error) {
 	o := orm.NewOrm()
@@ -356,3 +373,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

@@ -284,3 +284,11 @@ func UdpateYanxuanSpecialauthorArticleNum(articleNum, userId int) (err error) {
 	_, err = o.Raw(sql, articleNum, 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
+}

+ 30 - 5
services/cygx_yanxuan_special_company.go

@@ -155,6 +155,22 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err err
 					return
 				}
 			}
+		} else {
+			//专栏Pv数量进行加一
+			e = models.UpdateYanxuanSpecialHzPv(specialId)
+			if e != nil {
+				err = errors.New("UpdateYanxuanSpecialHzPv, Err: " + e.Error())
+				return
+			}
+
+			//如果没有阅读过,那么就给专栏文章的UV、作者的UV进行加一
+			if totalRecord == 0 {
+				e = models.UpdateYanxuanSpecialHzUv(specialId)
+				if e != nil {
+					err = errors.New("UpdateYanxuanSpecialHzUv, Err: " + e.Error())
+					return
+				}
+			}
 		}
 	}
 
@@ -195,16 +211,25 @@ func GetYanxuanSpecialRecordByYanxuanSpecialId(articleIds []int) (mapResp map[in
 	}
 	var condition string
 	var pars []interface{}
-	condition = ` AND yanxuan_special_id IN (` + utils.GetOrmInReplace(lenIds) + `) `
+	//condition = ` AND yanxuan_special_id IN (` + utils.GetOrmInReplace(lenIds) + `) `
+	//pars = append(pars, articleIds)
+	//listPv, e := models.GetCygxYanxuanSpecialRecordListPv(condition, pars)
+	//if e != nil {
+	//	err = errors.New("GetCygxArticleHistoryRecordNewpvListPvCy, Err: " + e.Error())
+	//	return
+	//}
+
+	condition += ` AND id  IN (` + utils.GetOrmInReplace(lenIds) + `) `
 	pars = append(pars, articleIds)
-	listPv, e := models.GetCygxYanxuanSpecialRecordListPv(condition, pars)
-	if e != nil {
-		err = errors.New("GetCygxArticleHistoryRecordNewpvListPvCy, Err: " + e.Error())
+	listPv, e := models.GetYanxuanSpecialListBycondition(condition, pars, 0, lenIds)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetYanxuanSpecialListBycondition, Err: " + e.Error())
 		return
 	}
+
 	mapResp = make(map[int]int, 0)
 	for _, v := range listPv {
-		mapResp[v.YanxuanSpecialId] = v.Pv
+		mapResp[v.Id] = v.Pv + v.HzPv
 	}
 	return
 }

+ 253 - 0
services/html2Img.go

@@ -0,0 +1,253 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hongze/hongze_web_mfyx/models"
+	"hongze/hongze_web_mfyx/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 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() //有专栏生成的时候,最新专栏列表封面图
+	//go GetYanxuanSpecialAuthoMomentsImg(detail.UserId) // 有专栏生成的时候,最新wen
+	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 {
+		err = errors.New("html转图片失败: " + err.Error())
+		return
+	}
+	if res == nil {
+		err = errors.New("html转图片失败: ")
+		return
+	}
+	if res.Code != 200 {
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	imgUrl = res.Data
+	err = models.UpdateYanxuanSpecialMomentsImg(imgUrl, specialId)
+	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
+
+}
+
+// 生成研选专栏分享到朋友圈的图片
+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 {
+		err = errors.New("html转图片失败: " + err.Error())
+		return
+	}
+
+	if res == nil {
+		err = errors.New("html转图片失败: ")
+		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
+}

+ 1 - 1
services/wechat.go

@@ -133,7 +133,7 @@ type WxUserDetail struct {
 func GetWxAccessTokenByMfyx() (accessTokenStr string, err error) {
 	//缓存校验
 	if utils.RunMode == "release" {
-		cacheKey := "mfyx_gzh_wxtoken"
+		cacheKey := "mfyx_wxtoken"
 		accessTokenStr, _ = utils.Rc.RedisString(cacheKey)
 		if accessTokenStr != "" {
 			return

+ 11 - 0
services/wechat_send_category_template_msg.go

@@ -796,6 +796,17 @@ func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, com
 					err = errors.New("GetSellerByAdminId, Err: " + e.Error())
 					return
 				}
+				listSellerMobile, e := models.GetCygxSellerMobileMap()
+				if e != nil {
+					err = errors.New("GetCygxSellerMobileMap, Err: " + e.Error())
+					return
+				}
+				//mapMobile := make(map[string]string)
+				for _, vm := range listSellerMobile {
+					if adminShare.Mobile == vm.ServerMobile {
+						adminShare.Mobile = vm.Mobile
+					}
+				}
 				mobileOpenid = sealldetail.Mobile + "," + adminShare.Mobile
 			} else {
 				mobileOpenid = sealldetail.Mobile

+ 11 - 0
services/wechat_send_msg.go

@@ -136,6 +136,17 @@ func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod,
 				err = errors.New("GetSellerByAdminId, Err: " + e.Error())
 				return
 			}
+			listSellerMobile, e := models.GetCygxSellerMobileMap()
+			if e != nil {
+				err = errors.New("GetCygxSellerMobileMap, Err: " + e.Error())
+				return
+			}
+			//mapMobile := make(map[string]string)
+			for _, vm := range listSellerMobile {
+				if adminShare.Mobile == vm.ServerMobile {
+					adminShare.Mobile = vm.Mobile
+				}
+			}
 			mobileOpenid = sealldetail.Mobile + "," + adminShare.Mobile
 		} else {
 			mobileOpenid = sealldetail.Mobile