123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- 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
- }
- var err error
- //如果是已经上传了音视的活动不记录
- if source == utils.CYGX_OBJ_ACTIVITY {
- totalvi, e := models.GetCygxActivityVideoCount(sourceId)
- if e != nil {
- err = errors.New("GetCygxActivityVideoCount, Err: " + e.Error())
- return
- }
- if totalvi > 0 {
- return
- }
- totalvo, e := models.GetCygxActivityVoiceCount(sourceId)
- if e != nil {
- err = errors.New("GetCygxActivityVoiceCount, Err: " + e.Error())
- return
- }
- if totalvo > 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)
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("记录分享来源失败 AddCygxUserAdminShareHistory, err:", err.Error(), "inviteShareCode:", inviteShareCode, "source", source), 2)
- }
- }()
- adminDetail, e := models.GetUserAdminShareCodeByShareCode(inviteShareCode)
- if e != nil {
- err = errors.New("GetUserAdminShareCodeByShareCode, 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_ACTIVITYVIDEO:
- item.Action = "查看活动回放"
- case utils.CYGX_OBJ_ACTIVITYVOICE:
- 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
- }
- // 根据分享码获取对应销售的ID以及姓名
- func GetAdminByInviteShareCode(inviteShareCode string) (shareName string, shareId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("记录分享来源失败 GetAdminByInviteShareCode, err:", err.Error()), 2)
- }
- }()
- adminDetail, e := models.GetUserAdminShareCodeByShareCode(inviteShareCode)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetUserAdminShareCodeByShareCode, Err: " + e.Error())
- return
- }
- if adminDetail == nil {
- return
- }
- shareId = adminDetail.SellerId
- shareName = adminDetail.SellerName
- return
- }
|