Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/debug' into debug

zwxi 1 anno fa
parent
commit
1250470e61

+ 4 - 0
controllers/article.go

@@ -217,6 +217,10 @@ func (this *ArticleController) Detail() {
 	if detail.ArticleTypeId == 14 {
 		detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈  查研观向11.0
 	}
+	if user.UserId == 0 {
+		hasPermission = 1
+	}
+
 	resp.HasPermission = hasPermission
 	resp.HaveResearch = haveResearch
 

+ 9 - 7
controllers/user.go

@@ -47,7 +47,6 @@ func (this *UserController) Login() {
 		br.Ret = 408
 		return
 	}
-	inviteShareCode := req.InviteShareCode
 	unionId := this.User.UnionId
 	openId := this.User.OpenId
 	if unionId == "" {
@@ -115,7 +114,7 @@ func (this *UserController) Login() {
 	if len(req.Mobile) >= 11 && req.CountryCode == "" {
 		req.CountryCode = "86"
 	}
-	user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
+	user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode, req.InviteShareCode)
 	if err != nil {
 		br.Msg = "登录失败"
 		br.ErrMsg = "绑定手机号失败:" + err.Error()
@@ -191,9 +190,6 @@ func (this *UserController) Login() {
 
 	{
 		services.UpdateCygxSubscribe(userId, unionId) //先关注后登录,更新用户是否关注过查研观向小助手公众号
-		if inviteShareCode != "" {                    //记录分享来源
-			go services.AddCygxUserAdminShareHistory(user, "login", "", inviteShareCode, 0) //记录分享来源
-		}
 	}
 
 	resp := new(models.LoginResp)
@@ -345,13 +341,19 @@ func (this *UserController) Detail() {
 					}
 
 					companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
-					if err != nil {
+					if err != nil && err.Error() != utils.ErrNoRow() {
 						br.Msg = "获取信息失败"
 						br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
 						return
 					}
+					var isSuspend int
+					if companyProduct == nil {
+						isSuspend = 1
+					} else {
+						isSuspend = companyProduct.IsSuspend
+					}
 
-					if len(companyReportPermissionList) == 0 || companyProduct.IsSuspend == 1 {
+					if len(companyReportPermissionList) == 0 || isSuspend == 1 {
 						hasPermission = 1
 					} else {
 						//有研选订阅或研选扣点包任意一项试用权限,即为试用客户,期限显示两项合并之后的最长时间

+ 1 - 5
controllers/wechat.go

@@ -431,17 +431,13 @@ func (this *WechatController) Getuserphonenumber() {
 		return
 	}
 
-	user, err = services.BindWxUser(openId, mobile, "", countryCode)
+	user, err = services.BindWxUser(openId, mobile, "", countryCode, inviteShareCode)
 	if err != nil {
 		br.Msg = "登录失败"
 		br.ErrMsg = "绑定手机号失败:" + err.Error()
 		return
 	}
 
-	if inviteShareCode != "" { //记录分享来源
-		go services.AddCygxUserAdminShareHistory(user, "login", "", inviteShareCode, 0) //记录分享来源
-	}
-
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "登录成功"

+ 51 - 6
controllers/yanxuan_special.go

@@ -146,6 +146,7 @@ func (this *BaseAuthMobileController) List() {
 // @Title 专栏详情
 // @Description 专栏详情
 // @Param   IsSendWx   query   int  false       "是否是通过微信模版进来的 1是,其它否"
+// @Param   InviteShareCode   query   string  false       "销售账号邀请码"
 // @Param   Id   query   int  true       "详情ID"
 // @Success 200 {object} models.AddEnglishReportResp
 // @router /detail [get]
@@ -165,7 +166,7 @@ func (this *BaseAuthMobileController) Detail() {
 
 	specialId, _ := this.GetInt("Id", 0)
 	isSendWx, _ := this.GetInt("IsSendWx", 0)
-
+	inviteShareCode := this.GetString("InviteShareCode")
 	if specialId <= 0 {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误"
@@ -181,7 +182,10 @@ func (this *BaseAuthMobileController) Detail() {
 	if item.MyCollectNum > 0 {
 		item.IsCollect = 1
 	}
-
+	//记录分享来源
+	if inviteShareCode != "" {
+		go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_YANXUANSPECIAL, item.Title, inviteShareCode, specialId)
+	}
 	var resp models.CygxYanxuanSpecialResp
 	resp.HasPermission = 1
 	resp.CygxYanxuanSpecialItem = *item
@@ -610,12 +614,14 @@ func (this *YanxuanSpecialController) Collect() {
 	var sellerName string
 	if user.CompanyId > 1 {
 		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 {
@@ -793,12 +799,14 @@ func (this *YanxuanSpecialController) Follow() {
 	var sellerName string
 	if user.CompanyId > 1 {
 		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{
@@ -1022,6 +1030,7 @@ func (this *YanxuanSpecialController) AuthorList() {
 	}
 	resp := new(models.SpecialAuthorListResp)
 	isAuthor, _ := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
+	resp.MomentsImg = services.GetSpecialAuthorListMomentsImg()  //获取作者列表朋友圈分享封面图
 	resp.IsAuthor = isAuthor
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp.List = list
@@ -1340,3 +1349,39 @@ Loop:
 	br.Msg = "操作成功"
 	br.Data = resp
 }
+
+// @Title 获取专栏朋友圈封面详情
+// @Description 获取专栏朋友圈封面详情接口
+// @Param   UserId   query   int  false       "用户ID,等于0列表详情,大于0作者详情"
+// @Success 200 {object} models.AddEnglishReportResp
+// @router /moments_img [get]
+func (this *YanxuanSpecialController) MomentsImg() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.User
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	type imgUrlResp struct {
+		MomentsImg string // 分享图片
+	}
+	var imgUrl string
+	userId, _ := this.GetInt("UserId", 0)
+	if userId == 0 {
+		imgUrl = services.GetYanxuanSpecialAuthoListMomentsImg()
+	} else {
+		imgUrl = services.GetYanxuanSpecialAuthoMomentsImg(userId)
+	}
+	resp := new(imgUrlResp)
+	resp.MomentsImg = imgUrl
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 5 - 3
models/cygx_yanxuan_special_user.go

@@ -46,6 +46,7 @@ type CygxYanxuanSpecialAuthorItem struct {
 	LatestPublishDate    string                              // 最近更新时间
 	IsFollow             int                                 // 是否已关注 1已关注 0 未关注
 	HasChangeHeadImg     int                                 // 是否更换过默认头像 1是,0否
+	MomentsImg           string                              `description:"分享到朋友圈的封面图片"`
 	YanxuanSpecialCenter *CygxYanxuanSpecialCenterAuthorResp // 研选专栏文章内容
 }
 
@@ -149,9 +150,10 @@ WHERE 1= 1 `
 }
 
 type SpecialAuthorListResp struct {
-	Paging   *paging.PagingItem `description:"分页数据"`
-	List     []*CygxYanxuanSpecialAuthorItem
-	IsAuthor bool
+	Paging     *paging.PagingItem `description:"分页数据"`
+	List       []*CygxYanxuanSpecialAuthorItem
+	IsAuthor   bool
+	MomentsImg string `description:"分享到朋友圈的封面图片"`
 }
 
 type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {

+ 9 - 0
routers/commentsRouter.go

@@ -916,6 +916,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:YanxuanSpecialController"],
+        beego.ControllerComments{
+            Method: "MomentsImg",
+            Router: `/moments_img`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:YanxuanSpecialController"],
         beego.ControllerComments{
             Method: "Record",

+ 1 - 0
services/activity.go

@@ -549,6 +549,7 @@ func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *model
 
 // 根据用户身份处理活动可见
 func ActivityConditioninitSql(user *models.WxUserItem, condition string, isPower int) (conditionActivity string, err error) {
+	condition += "  AND  IF ( art.is_limit_people  = 1 ,  art.customer_type_ids != '' ,1=1  )  "
 	//未登录的用户也可以查看所有活动v12.2.1
 	if user.UserId == 0 {
 		conditionActivity = ` AND art.publish_status = 1   AND art.yidong_activity_id = ''  ` + condition

+ 25 - 0
services/cygx_yanxuan_special.go

@@ -504,3 +504,28 @@ func UdpateYanxuanSpecialauthorArticleNum(authoruserId int) {
 	}
 	return
 }
+
+// 获取作者列表朋友圈分享封面图
+func GetSpecialAuthorListMomentsImg() (imgUrl string) {
+	var err error
+	//time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go utils.SendAlarmMsg("获取作者列表朋友圈分享封面图,GetSpecialAuthorListMomentsImg Err:"+err.Error(), 3)
+		}
+	}()
+	configCode := "special_author_list_moments_img"
+	detailConfig, e := models.GetConfigByCode(configCode)
+	if e != nil {
+		err = errors.New("GetConfigByCode 获取作者列表朋友圈分享封面图, Err: " + e.Error())
+		return
+	}
+	imgUrl = detailConfig.ConfigValue
+	fmt.Println(imgUrl)
+	return
+}
+
+//func init() {
+//	GetSpecialAuthorListMomentsImg()
+//}

+ 189 - 0
services/html2Img.go

@@ -0,0 +1,189 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hongze/hongze_mfyx/models"
+	"hongze/hongze_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 init() {
+//	GetYanxuanSpecialAuthoMomentsImg(53559)
+//}
+
+// 生成研选专栏分享到朋友圈的图片
+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
+	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("GetYanxuanSpecialAuthor, 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
+	return
+}

+ 6 - 1
services/user.go

@@ -170,7 +170,7 @@ func formatWxUser(wxUser *models.WxUserItem, platform int) {
 }
 
 // 用户绑定
-func BindWxUser(openid, mobile, email, countryCode string) (wxUser *models.WxUserItem, err error) {
+func BindWxUser(openid, mobile, email, countryCode, inviteShareCode string) (wxUser *models.WxUserItem, err error) {
 	if mobile == "" && email == "" {
 		err = errors.New("手机号或邮箱必填一个")
 		return
@@ -229,6 +229,11 @@ func BindWxUser(openid, mobile, email, countryCode string) (wxUser *models.WxUse
 		user.UserId = int(tmpUserId)
 		userId = int(tmpUserId)
 		wxUser, err = models.GetWxUserItemByUserId(userId)
+
+		if inviteShareCode != "" { //记录分享来源
+			go AddCygxUserAdminShareHistory(wxUser, "login", "", inviteShareCode, 0) //记录分享来源
+		}
+
 	} else {
 		userId = wxUser.UserId
 		err = models.BindUserOutboundMobile(mobile, countryCode, userId)

+ 2 - 0
services/user_admin_share.go

@@ -86,6 +86,8 @@ func AddCygxUserAdminShareHistory(user *models.WxUserItem, source, sourceTitle,
 		item.Action = "查看活动"
 	case utils.CYGX_OBJ_ARTICLE:
 		item.Action = "查看报告"
+	case utils.CYGX_OBJ_YANXUANSPECIAL:
+		item.Action = "查看专栏"
 	case "login":
 		item.Action = "注册"
 	}