浏览代码

Merge branch 'master' of http://8.136.199.33:3000/cxzhang/hongze_mfyx into mfyx_2.0

xingzai 11 月之前
父节点
当前提交
93008bab35

+ 6 - 0
controllers/activity.go

@@ -309,6 +309,7 @@ func (this *ActivityCoAntroller) ScheduleList() {
 // @Description 获取活动详情接口
 // @Param   ActivityId   query   int  true       "活动ID"
 // @Param   IsSendWx   query   int  false       "是否是通过微信模版进来的 1是,其它否"
+// @Param   InviteShareCode   query   string  false       "销售账号邀请码"
 // @Success Ret=200 {object} models.CygxActivityResp
 // @router /detail [get]
 func (this *ActivityCoAntroller) Detail() {
@@ -331,6 +332,7 @@ func (this *ActivityCoAntroller) Detail() {
 		br.Msg = "请输入活动ID"
 		return
 	}
+	inviteShareCode := this.GetString("InviteShareCode")
 	resp := new(models.CygxActivityResp)
 	activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -343,6 +345,10 @@ func (this *ActivityCoAntroller) Detail() {
 		br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
 		return
 	}
+	//记录分享来源
+	if inviteShareCode != "" {
+		go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_ACTIVITY, activityInfo.ActivityName, inviteShareCode, activityId)
+	}
 	// 判断是否属于研选类型的活动
 	if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
 		resp.IsResearch = true

+ 6 - 1
controllers/article.go

@@ -41,6 +41,7 @@ type ArticleControllerMobile struct {
 // @Description 获取报告详情接口
 // @Param   ArticleId   query   int  true       "报告ID"
 // @Param   IsSendWx   query   int  false       "是否是通过微信模版进来的 1是,其它否"
+// @Param   InviteShareCode   query   string  false       "销售账号邀请码"
 // @Success 200 {object} models.ArticleDetailResp
 // @router /detail [get]
 func (this *ArticleController) Detail() {
@@ -65,6 +66,7 @@ func (this *ArticleController) Detail() {
 		br.ErrMsg = "文章不存在,文章ID错误"
 		return
 	}
+	inviteShareCode := this.GetString("InviteShareCode")
 	detail := new(models.ArticleDetail)
 	hasPermission := 0
 	var haveResearch bool
@@ -76,7 +78,10 @@ func (this *ArticleController) Detail() {
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
-
+	//记录分享来源
+	if inviteShareCode != "" {
+		go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_ARTICLE, detail.Title, inviteShareCode, articleId)
+	}
 	detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
 	detail.Body = html.UnescapeString(detail.Body)
 	detail.Body = strings.Replace(detail.Body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)

+ 14 - 7
controllers/user.go

@@ -47,7 +47,6 @@ func (this *UserController) Login() {
 		br.Ret = 408
 		return
 	}
-
 	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()
@@ -189,9 +188,8 @@ func (this *UserController) Login() {
 		}
 	}
 
-	//先关注后登录,更新用户是否关注过查研观向小助手公众号
 	{
-		services.UpdateCygxSubscribe(userId, unionId)
+		services.UpdateCygxSubscribe(userId, unionId) //先关注后登录,更新用户是否关注过查研观向小助手公众号
 	}
 
 	resp := new(models.LoginResp)
@@ -343,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 {
 						//有研选订阅或研选扣点包任意一项试用权限,即为试用客户,期限显示两项合并之后的最长时间
@@ -407,7 +411,6 @@ func (this *UserController) Detail() {
 	if detail.Headimgurl == "" {
 		detail.Headimgurl = utils.DefaultHeadimgurl
 	}
-
 	if user.Mobile != "" {
 		userCard, err := order.GetCygxOrderUserCardDetailByMobile(user.Mobile)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -424,6 +427,10 @@ func (this *UserController) Detail() {
 				detail.UserCardEndDate = userCard.EndDate.Format(utils.FormatDate)
 			}
 		}
+
+		if detail.Mobile != "" {
+			detail.InviteShareCode = services.GetInviteShareCode(detail.Mobile) //判断用户是否属于销售,并且获取对应加密的分享码
+		}
 	}
 	br.Ret = 200
 	br.Success = true

+ 3 - 1
controllers/wechat.go

@@ -388,6 +388,7 @@ func (this *WechatCommonController) GetSmsCode() {
 // @Title 微信获取用户绑定的手机号
 // @Description 微信获取用户绑定的手机号接口
 // @Param   Code   query   string  true       "微信唯一编码code"
+// @Param   InviteShareCode   query   string  false       "销售账号邀请码"
 // @Success 200 {object} models.WxLoginResp
 // @router /getuserphonenumber [get]
 func (this *WechatController) Getuserphonenumber() {
@@ -409,6 +410,7 @@ func (this *WechatController) Getuserphonenumber() {
 		br.ErrMsg = "Code 为空"
 		return
 	}
+	inviteShareCode := this.GetString("InviteShareCode")
 
 	wxitem, err := services.Getuserphonenumber(code)
 	if err != nil {
@@ -429,7 +431,7 @@ 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()

+ 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
@@ -605,12 +609,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 {
@@ -788,12 +794,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{
@@ -1017,6 +1025,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
@@ -1335,3 +1344,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 = "获取成功"
+}

+ 1 - 0
models/activity.go

@@ -239,6 +239,7 @@ type ActivityDetail struct {
 	TopTime                   int                        `description:"置顶时间"`
 	LabelKeyword              string                     `description:"标签关键词"`
 	LabelKeywordImgLink       string                     `description:"标签关键词ico"`
+	MomentsImg                string                     `description:"分享到朋友圈的封面图片"`
 }
 type ListArticleActivity struct {
 	Title   string `description:"文章标题"`

+ 1 - 0
models/article.go

@@ -185,6 +185,7 @@ type ArticleDetail struct {
 	MatchTypeName            string `description:"匹配类型"`
 	Stock                    string `description:"个股标签"`
 	Frequency                string `description:"更新周期(策略平台字段)"`
+	MomentsImg               string `description:"分享到朋友圈的封面图片"`
 }
 
 type ArticleDetailFileLink struct {

+ 1 - 0
models/cygx_yanxuan_special.go

@@ -57,6 +57,7 @@ type CygxYanxuanSpecialItem struct {
 	Docs            []Doc
 	Pv              string `description:"Pv"`
 	Uv              string `description:"Uv"`
+	MomentsImg      string `description:"分享到朋友圈的封面图片"`
 }
 
 type CygxYanxuanSpecialResp struct {

+ 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 {

+ 2 - 0
models/db.go

@@ -177,6 +177,8 @@ func init() {
 		new(CygxAskserieVideoCollect),
 		new(CygxVoiceAndVideoHistory),
 		new(CygxArticleAndYanxuanRecord),
+		new(CygxUserAdminShareHistory),
+		new(CygxUserAdminShareCode),
 		new(AliyunOcrLog),
 	)
 

+ 8 - 6
models/user.go

@@ -30,6 +30,7 @@ type UserDetail struct {
 	StartDate           string  `description:"开始日期"`
 	EndDate             string  `description:"结束日期"`
 	CompanyPointsNum    float64 `description:"公司剩余点数"`
+	InviteShareCode     string  `description:"销售账号邀请码"`
 	UserCardType        int     `description:"权益卡类型,0:未开通、1日卡、2月卡"`
 	UserCardEndDate     string  `description:"权益卡有效期"`
 }
@@ -65,12 +66,13 @@ type UserPermission struct {
 }
 
 type LoginReq struct {
-	LoginType     int    `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"`
-	Mobile        string `description:"手机号"`
-	Email         string `description:"邮箱"`
-	VCode         string `description:"验证码"`
-	CountryCode   string `description:"区号"`
-	ShareUserCode string `description:"分享人的分享码"`
+	LoginType       int    `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"`
+	Mobile          string `description:"手机号"`
+	Email           string `description:"邮箱"`
+	VCode           string `description:"验证码"`
+	CountryCode     string `description:"区号"`
+	ShareUserCode   string `description:"分享人的分享码"`
+	InviteShareCode string `description:"销售账号邀请码"`
 }
 
 func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {

+ 37 - 0
models/user_admin_share_code.go

@@ -0,0 +1,37 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserAdminShareCode struct {
+	UserAdminCodeId int       `orm:"column(user_admin_share_code_id);pk";comment:"主键ID"`
+	SellerName      string    `comment:"所属销售"`
+	SellerId        int       `comment:"所属销售id"`
+	Mobile          string    `comment:"手机号"`
+	CreateTime      time.Time `comment:"创建时间"`
+	ModifyTime      time.Time `comment:"修改时间"`
+	ShareCode       string    `comment:"分享码,对seller_id进行MD5加密的结果"`
+}
+
+// 获取数量
+func GetCygxUserAdminShareCodeByShareCodeCount(chareCode string) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_admin_share_code WHERE  share_code  = ? `
+	err = o.Raw(sqlCount, chareCode).QueryRow(&count)
+	return
+}
+
+func AddCygxUserAdminShareCode(item *CygxUserAdminShareCode) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+func GetUserAdminShareCodeByShareCode(shareCode string) (item *CygxUserAdminShareCode, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT  * FROM cygx_user_admin_share_code  WHERE   share_code  = ? `
+	err = o.Raw(sql, shareCode).QueryRow(&item)
+	return
+}

+ 33 - 0
models/user_admin_share_history.go

@@ -0,0 +1,33 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserAdminShareHistory struct {
+	UserAdminShareHistoryId int       `orm:"column(user_admin_share_history_id);pk";comment:"主键ID"`
+	Action                  string    `comment:"动作内容"`
+	UserId                  int       `comment:"用户ID"`
+	Mobile                  string    `comment:"手机号"`
+	Email                   string    `comment:"邮箱"`
+	CompanyId               int       `comment:"公司ID"`
+	CompanyName             string    `comment:"公司名称"`
+	RealName                string    `comment:"用户实际名称"`
+	SellerName              string    `comment:"所属销售名称"`
+	SellerId                int       `comment:"所属销售ID"`
+	ShareId                 int       `comment:"分享人ID"`
+	ShareName               string    `comment:"分享人姓名"`
+	Source                  string    `comment:"来源(article, activity, login)"`
+	SourceId                int       `comment:"来源 ID"`
+	SourceTitle             string    `comment:"来源名称,活动或者报告标题"`
+	RegisterPlatform        int       `comment:"注册平台(1: 小程序, 2: 网页)"`
+	CreateTime              time.Time `comment:"创建时间"`
+	ModifyTime              time.Time `comment:"修改时间"`
+}
+
+func AddCygxUserAdminShareHistory(item *CygxUserAdminShareHistory) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}

+ 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

@@ -548,6 +548,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)

+ 118 - 0
services/user_admin_share.go

@@ -0,0 +1,118 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_mfyx/models"
+	"hongze/hongze_mfyx/utils"
+	"strconv"
+	"time"
+)
+
+// 判断用户是否属于销售,并且获取对应加密的分享码
+func GetInviteShareCode(mobile string) (inviteShareCode string) {
+	if mobile == "" {
+		return
+	}
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("判断用户是否属于销售,并且获取对应加密的分享码失败 GetInviteShareCode, err:", err.Error()), 2)
+		}
+	}()
+	adminDetail, e := models.GetSysAdminByMobile(mobile)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetSysAdminByMobile, Err: " + e.Error())
+		return
+	}
+	if adminDetail == nil {
+		return
+	}
+	inviteShareCode = utils.MD5(strconv.Itoa(adminDetail.AdminId)) //MD5 对ID进行加密
+	total, e := models.GetCygxUserAdminShareCodeByShareCodeCount(inviteShareCode)
+	if e != nil {
+		err = errors.New("GetCygxUserAdminShareCodeByShareCodeCount, Err: " + e.Error())
+		return
+	}
+	//如果不存在就新增一个
+	if total == 0 {
+		item := new(models.CygxUserAdminShareCode)
+		item.SellerName = adminDetail.RealName
+		item.SellerId = adminDetail.AdminId
+		item.Mobile = adminDetail.Mobile
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		item.ShareCode = inviteShareCode
+		e = models.AddCygxUserAdminShareCode(item)
+		if e != nil {
+			err = errors.New("AddCygxUserAdminShareCode, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}
+
+// 记录分享来源
+func AddCygxUserAdminShareHistory(user *models.WxUserItem, source, sourceTitle, inviteShareCode string, sourceId int) {
+	if inviteShareCode == "" {
+		return
+	}
+	if user.UserId == 0 {
+		return
+	}
+	//3秒之内多次请求,不重复记录
+	key := "CYGX_" + source + "_" + strconv.Itoa(sourceId) + "_" + strconv.Itoa(user.UserId)
+	if utils.Rc.IsExist(key) {
+		return
+	}
+	utils.Rc.Put(key, 1, 3*time.Second)
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("记录分享来源失败 AddCygxUserAdminShareHistory, err:", err.Error()), 2)
+		}
+	}()
+	adminDetail, e := models.GetUserAdminShareCodeByShareCode(inviteShareCode)
+	if e != nil {
+		err = errors.New("GetSysAdminByMobile, Err: " + e.Error())
+		return
+	}
+	if adminDetail == nil {
+		return
+	}
+	item := new(models.CygxUserAdminShareHistory)
+	switch source {
+	case utils.CYGX_OBJ_ACTIVITY:
+		item.Action = "查看活动"
+	case utils.CYGX_OBJ_ARTICLE:
+		item.Action = "查看报告"
+	case utils.CYGX_OBJ_YANXUANSPECIAL:
+		item.Action = "查看专栏"
+	case "login":
+		item.Action = "注册"
+	}
+	item.UserId = user.UserId
+	item.Mobile = user.Mobile
+	item.Email = user.Email
+	item.CompanyId = user.CompanyId
+	item.CompanyName = user.CompanyName
+	item.RealName = user.RealName
+	item.SellerName, item.SellerId = GetSellerName(user) // 销售姓名
+	item.Source = source
+	item.SourceId = sourceId
+	item.SourceTitle = sourceTitle
+	item.ShareId = adminDetail.SellerId
+	item.ShareName = adminDetail.SellerName
+	item.RegisterPlatform = utils.REGISTER_PLATFORM
+	item.CreateTime = time.Now()
+	item.ModifyTime = time.Now()
+
+	e = models.AddCygxUserAdminShareHistory(item)
+	if e != nil {
+		err = errors.New("AddCygxUserAdminShareHistory, Err: " + e.Error())
+		return
+	}
+	return
+}