123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/models/company"
- "hongze/hongze_clpt/utils"
- "strconv"
- "strings"
- "time"
- )
- func SpecialTripPopupMsg(activityInfo *models.CygxActivitySpecialDetail, user *models.WxUserItem) (signupStatus int, popupMsg, popupMsg2 string, err error) {
- //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
- signupStatus = 1
- resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
- if time.Now().After(resultTime.Add(-time.Minute * 60)) {
- signupStatus = 4
- popupMsg = "活动开始前1小时内无法报名,请联系对口销售处理"
- return
- }
- errMsg, e := CheckTripRemainingtimesBycompany(user, activityInfo)
- if e != nil {
- err = errors.New("获取客户剩余报名次数失败 GetActivitySpecialUserType, Err: " + e.Error())
- return
- }
- if errMsg != "" {
- popupMsg = errMsg
- signupStatus = 3
- return
- }
- var condition string
- var pars []interface{}
- condition += ` AND activity_id = ? AND is_cancel = 0 `
- pars = append(pars, activityInfo.ActivityId)
- tripTota, e := models.GetActivitySpecialTripCountByActivityId(condition, pars)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
- return
- }
- if activityInfo.LimitPeopleNum-tripTota < 1 {
- signupStatus = 2
- popupMsg = "此活动报名人数已满,请留意下期活动"
- return
- }
- //signupStatus = 4
- popupMsg = "感谢参与,本次报名会扣除一次贵司在弘则的调研点数。"
- popupMsg2 = "由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。"
- return
- }
- // 获取用户剩余报名次数
- // 获取用户剩余报名次数
- func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, tripRemaining int, err error) {
- //获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户 8:行业升级套餐客户
- msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
- //var tripTota int
- //var airborneTota int
- //userType, _, e := GetActivitySpecialUserType(user.CompanyId)
- userType, _, e := GetUserType(user.CompanyId)
- if e != nil {
- err = errors.New("获取客户身份信息失败 GetActivitySpecialUserType, Err: " + e.Error())
- return
- }
- if userType == 0 {
- errMsg = msgTemplate
- return
- } else if userType == 1 {
- tripRemaining = 999
- return
- } else if userType == 2 {
- var condition string
- var pars []interface{}
- condition += ` AND company_id = ? `
- pars = append(pars, user.CompanyId)
- //airborneTota, e = models.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
- //if e != nil {
- // err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
- // return
- //}
- //condition += ` AND is_valid = 1 `
- //查询当年的数据
- condition += ` AND create_time >= ? `
- pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
- listTripBill, e := models.GetCygxActivitySpecialTripBill(condition, pars)
- if e != nil {
- err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
- return
- }
- var TripBillNum int
- for _, v := range listTripBill {
- TripBillNum += v.BillDetailed
- }
- var packageType int
- //大套餐客户,数据库添加标识,
- companyUserTypeDetail, errs := models.GetCygxCompanyUserType(user.CompanyId)
- if errs != nil && errs.Error() != utils.ErrNoRow() {
- err = errs
- return
- }
- if companyUserTypeDetail != nil {
- packageType = companyUserTypeDetail.PackageType
- if companyUserTypeDetail.CustomerTypeId != 0 {
- userType = companyUserTypeDetail.CustomerTypeId
- return
- }
- }
- packageTypeMap := map[int]int{1: 16, 2: 10}
- totalTrip := packageTypeMap[packageType]
- //tripRemaining = 10 - airborneTota + TripBillNum
- tripRemaining = totalTrip + TripBillNum
- if tripRemaining <= 0 {
- errMsg = msgTemplate
- return
- }
- //tripRemaining = 12 - tripTota
- } else {
- var condition string
- var pars []interface{}
- condition += ` AND company_id = ? `
- pars = append(pars, user.CompanyId)
- condition += ` AND chart_permission_id = ? `
- pars = append(pars, activityInfo.ChartPermissionId)
- //airborneTota, e = models.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
- //if e != nil {
- // err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
- // return
- //}
- //查询当年的数据
- condition += ` AND create_time >= ? `
- pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
- listTripBill, e := models.GetCygxActivitySpecialTripBill(condition, pars)
- if e != nil {
- err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
- return
- }
- var TripBillNum int
- for _, v := range listTripBill {
- TripBillNum += v.BillDetailed
- }
- //tripRemaining = 5 - airborneTota + TripBillNum
- tripRemaining = 5 + TripBillNum
- if tripRemaining <= 0 {
- errMsg = msgTemplate
- return
- }
- }
- return
- }
- // 校验是否还有剩余次数
- func CheckTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, err error) {
- msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
- companyId := user.CompanyId
- chartPermissionName := activityInfo.ChartPermissionName
- companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
- if e != nil {
- err = errors.New("GetCompanyDetailByIdGroup, Err:" + e.Error())
- return
- }
- //永续客户不限制次数
- if companyDetail.Status == utils.COMPANY_STATUS_FOREVER {
- return
- }
- var condition string
- var pars []interface{}
- condition = " AND company_id = ? AND points > 0 ORDER BY chart_permission_id DESC "
- pars = append(pars, companyId)
- activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
- return
- }
- //如果没有剩余的点数,就返回
- if len(activitySpecialPermissionPointsList) == 0 {
- errMsg = msgTemplate
- return
- }
- //判断是不是策略、固收、周期行业的活动,如果不是策略就获取对应行业的点数 ,策略的任何一个行业有剩余点数都能参加
- //if chartPermissionName != utils.CE_LUE_NAME && chartPermissionName != utils.GU_SHOU_NAME && chartPermissionName != utils.ZHOU_QI_NAME {
- if !utils.InArrayByStr(utils.ACTIVITY_SPECIAL_TRIP_PERMISSION_NAME_OTHER, activityInfo.ChartPermissionName) {
- return
- } else {
- for _, v := range activitySpecialPermissionPointsList {
- if v.ChartPermissionName == chartPermissionName || v.ChartPermissionId == 0 {
- return
- } // 如果对应行业有剩余次数,或者是属于大套餐且有次数,那么校验也通过
- }
- }
- return
- }
- // GetSpecialBillMaxChartPermissionId 获取专项调研剩余点数最多的行业
- func GetSpecialBillMaxChartPermissionId(user *models.WxUserItem) (maxChartPermissionId int, maxChartPermissionName string, err error) {
- companyId := user.CompanyId
- var condition string
- var pars []interface{}
- condition = " AND company_id = ? AND points > 0 ORDER BY points DESC LIMIT 1 "
- pars = append(pars, companyId)
- activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
- return
- }
- for _, v := range activitySpecialPermissionPointsList {
- maxChartPermissionId = v.ChartPermissionId
- maxChartPermissionName = v.ChartPermissionName
- }
- return
- }
- // DeductTripRemainingtimesByUser 扣除用户专项调研剩余次数
- func DeductTripRemainingtimesByUser(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (err error) {
- msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
- companyId := user.CompanyId
- //chartPermissionName := activityInfo.ChartPermissionName
- companyProduct, e := company.GetCompanyProductByCompanyIdAndProductId(companyId, utils.COMPANY_PRODUCT_RAI_ID)
- if e != nil {
- err = errors.New("GetCompanyProductByCompanyIdAndProductId, Err:" + e.Error())
- return
- }
- var condition string
- var pars []interface{}
- var maxChartPermissionId int // 剩余点数最多的行业
- var points int // 剩余点数
- var activitySpecialPermissionPointsList []*models.CygxActivitySpecialPermissionPoints
- //永续客户不限次数需要单独处理
- if companyProduct.Status == utils.COMPANY_STATUS_FOREVER {
- condition = " AND company_id = ? ORDER BY points DESC LIMIT 1 "
- pars = append(pars, companyId)
- activitySpecialPermissionPointsList, e = models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
- return
- }
- //如果永续客户不存在单独的行业剩余点数记录,那么就添加一条 -1 的记录作为初始化数据
- if len(activitySpecialPermissionPointsList) == 0 {
- item := new(models.CygxActivitySpecialPermissionPoints)
- item.CompanyId = companyProduct.CompanyId
- item.Points = -1
- item.CompanyName = companyProduct.CompanyName
- //item.ChartPermissionId = activityInfo.ChartPermissionId
- //item.ChartPermissionName = activityInfo.ChartPermissionName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- e = models.AddCygxActivitySpecialPermissionPoints(item)
- if e != nil {
- err = errors.New("AddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
- return
- }
- return
- }
- } else {
- condition = " AND company_id = ? AND points > 0 ORDER BY points DESC LIMIT 1 "
- pars = append(pars, companyId)
- //判断是不是策略、固收、周期行业的活动,如果不是策略就获取对应行业的点数 ,策略的任何一个行业有剩余点数都能参加
- //if chartPermissionName != utils.CE_LUE_NAME && chartPermissionName != utils.GU_SHOU_NAME && chartPermissionName != utils.ZHOU_QI_NAME {
- if !utils.InArrayByStr(utils.ACTIVITY_SPECIAL_TRIP_PERMISSION_NAME_OTHER, activityInfo.ChartPermissionName) {
- pars = make([]interface{}, 0)
- condition = " AND company_id = ? AND ( chart_permission_id = ? OR chart_permission_id =0 ) AND points > 0 ORDER BY points DESC LIMIT 1 "
- pars = append(pars, companyId, activityInfo.ChartPermissionId)
- }
- activitySpecialPermissionPointsList, e = models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
- return
- }
- }
- //如果没有剩余的点数,就返回
- if len(activitySpecialPermissionPointsList) == 0 {
- err = errors.New(msgTemplate)
- return
- }
- for _, v := range activitySpecialPermissionPointsList {
- maxChartPermissionId = v.ChartPermissionId
- points = v.Points - 1
- }
- //更新对应行业剩余点数
- e = models.UpdateCygxActivitySpecialPermissionPoints(points, companyId, maxChartPermissionId)
- if e != nil {
- err = errors.New("UpdateCygxActivitySpecialPermissionPoints, Err:" + e.Error())
- return
- }
- return
- }
- // RebateTripRemainingtimesByUser 返点用户专项调研剩余次数
- func RebateTripRemainingtimesByUser(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (err error) {
- companyId := user.CompanyId
- chartPermissionName := activityInfo.ChartPermissionName
- var condition string
- var pars []interface{}
- condition = " AND company_id = ? ORDER BY points DESC LIMIT 1 "
- pars = append(pars, companyId)
- //判断是不是策略、固收行业的活动,如果不是策略就获取对应行业的点数 ,策略的任何一个行业有剩余点数都能参加
- //if chartPermissionName != utils.CE_LUE_NAME && chartPermissionName != utils.GU_SHOU_NAME && chartPermissionName != utils.ZHOU_QI_NAME {
- if !utils.InArrayByStr(utils.ACTIVITY_SPECIAL_TRIP_PERMISSION_NAME_OTHER, chartPermissionName) {
- pars = make([]interface{}, 0)
- condition = " AND company_id = ? AND ( chart_permission_id = ? OR chart_permission_id = 0 ) LIMIT 1 "
- pars = append(pars, companyId, activityInfo.ChartPermissionId)
- } else {
- lastTripBill, e := models.GetCygxActivitySpecialTripBillLastDetialByActivityId(activityInfo.ActivityId, user.UserId)
- if e != nil {
- err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
- return
- }
- pars = make([]interface{}, 0)
- condition = " AND company_id = ? AND ( chart_permission_id = ? OR chart_permission_id = 0 ) LIMIT 1 "
- pars = append(pars, companyId, lastTripBill.ChartPermissionId)
- }
- activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
- return
- }
- var maxChartPermissionId int // 剩余点数最多的行业(返点行业)
- var points int // 剩余点数
- for _, v := range activitySpecialPermissionPointsList {
- maxChartPermissionId = v.ChartPermissionId
- points = v.Points + 1
- }
- //更新对应行业剩余点数
- e = models.UpdateCygxActivitySpecialPermissionPoints(points, companyId, maxChartPermissionId)
- if e != nil {
- err = errors.New("UpdateCygxActivitySpecialPermissionPoints, Err:" + e.Error())
- return
- }
- return
- }
- // 预处理专项调研流水明细表描述内容
- //func HandleActivitySpecialTripBillTotalText(user *models.WxUserItem) (totalText string, err error) {
- // companyId := user.CompanyId
- // companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
- // if e != nil {
- // err = errors.New("GetCompanyDetailByIdGroup, Err:" + e.Error())
- // return
- // }
- // //永续客户不限制次数
- // if companyDetail.Status == utils.COMPANY_STATUS_FOREVER {
- // totalText = "0次"
- // return
- // }
- // var condition string
- // var pars []interface{}
- // pars = make([]interface{}, 0)
- // condition = " AND company_id = ? AND points != 0 ORDER BY chart_permission_id DESC "
- // pars = append(pars, companyId)
- // activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
- // if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
- // return
- // }
- //
- // var itemBillTotal []string
- // for _, v := range activitySpecialPermissionPointsList {
- // if v.ChartPermissionId > 0 {
- // itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次")) // 行业套餐客户展示规则
- // }
- // if v.ChartPermissionId == 0 {
- // totalText = fmt.Sprint(v.Points, "次") // 大套餐客户展示规则
- // }
- // }
- // if len(itemBillTotal) > 0 {
- // totalText = strings.Join(itemBillTotal, "+")
- // }
- // fmt.Println(totalText)
- // return
- //}
- // 预处理专项调研流水明细表描述内容
- func HandleActivitySpecialTripBillTotalText(companyId int) (totalText string, err error) {
- //companyId := user.CompanyId
- companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
- if e != nil {
- err = errors.New("GetCompanyDetailByIdGroup, Err:" + e.Error())
- return
- }
- var condition string
- var pars []interface{}
- pars = make([]interface{}, 0)
- condition = " AND company_id = ? AND points != 0 ORDER BY chart_permission_id DESC "
- pars = append(pars, companyId)
- activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
- return
- }
- //永续客户次数累加
- if companyDetail.Status == utils.COMPANY_STATUS_FOREVER {
- var points int
- for _, v := range activitySpecialPermissionPointsList {
- points += v.Points
- }
- totalText = fmt.Sprint(points, "次") //追加永续客户展示规则(2024-02-23)
- return
- }
- var itemBillTotal []string
- itemBillTotalMap := make(map[string]string)
- for _, v := range activitySpecialPermissionPointsList {
- if v.ChartPermissionId > 0 {
- itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次")) // 行业套餐客户展示规则
- itemBillTotalMap[v.ChartPermissionName] = fmt.Sprint(v.ChartPermissionName, v.Points, "次")
- }
- if v.ChartPermissionId == 0 {
- totalText = fmt.Sprint(v.Points, "次") // 大套餐客户展示规则,
- }
- }
- if len(itemBillTotal) > 0 {
- permissionNameSlice := []string{"医药", "消费", "科技", "智造"}
- var itemBillTotalNew []string
- for _, v := range permissionNameSlice {
- if itemBillTotalMap[v] == "" {
- itemBillTotalNew = append(itemBillTotalNew, fmt.Sprint(v, "0次"))
- } else {
- itemBillTotalNew = append(itemBillTotalNew, itemBillTotalMap[v])
- }
- }
- totalText = strings.Join(itemBillTotalNew, "+")
- }
- return
- }
- // 用户搜专项调研操作操作行为,模板消息推送
- func ActivitySpecialUserRmind(user *models.WxUserItem, activityId, TripStatus int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("用户搜专项调研操作操作行为,模板消息推送失败"+err.Error(), 2)
- }
- }()
- countUser, err := models.GetUserRemind(user.UserId)
- if err != nil {
- return err
- }
- if countUser == 0 {
- return err
- }
- var first string
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var remark string
- //获取销售手机号
- sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- if sellerItemQy != nil {
- sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
- if e != nil {
- err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
- return
- }
- sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
- openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- activityInfo, e := models.GetCygxActivitySpecialDetailById(user.UserId, activityId)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
- return
- }
- if activityInfo == nil {
- return
- }
- //TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
- if TripStatus == 1 {
- first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:专项调研预报名")
- } else {
- first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:活动报名")
- }
- keyword1 = activityInfo.ResearchTheme
- keyword2 = "__"
- remark = "点击查看活动详情"
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
- sendInfo := new(SendWxTemplate)
- sendInfo.First = first
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- sendInfo.Remark = remark
- sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(activityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- err = PublicSendTemplateMsg(sendInfo)
- if err != nil {
- return
- }
- }
- return
- }
- // GetChartPermissionSpecialSurplusByCompany 获取公司专项调研次数-分品种
- func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tripRemaining int, mapChartName map[string]int, err error) {
- companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
- if e != nil {
- err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
- }
- if companyDetail == nil {
- return
- }
- if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
- return
- }
- var specialSurplus string
- if companyDetail.Status == "永续" {
- specialSurplus = "不限次数"
- }
- //chartMap := map[int]string{utils.YI_YAO_ID:utils.YI_YAO_NAME, utils.XIAO_FEI_ID:utils.XIAO_FEI_NAME, utils.KE_JI_ID:utils.KE_JI_NAME, utils.ZHI_ZAO_ID:utils.ZHI_ZAO_NAME}
- //chartNumMap := map[int]int{utils.YI_YAO_ID:0, utils.XIAO_FEI_ID:0, utils.KE_JI_ID:0, utils.ZHI_ZAO_ID:0}
- chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
- if companyDetail.Status == "正式" {
- //var packageType int
- userType, _, _ = GetUserType(companyId)
- var condition string
- var pars []interface{}
- condition += ` AND company_id = ? `
- pars = append(pars, companyId)
- //查询当年的数据
- condition += ` AND b.create_time >= ? `
- pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
- listTripBill, e := models.GetCygxActivitySpecialTripBillList(condition, pars)
- if e != nil {
- err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
- return
- }
- //// 获取继承点数
- //inheritList, e := models.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
- //if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
- //}
- if userType == 2 {
- var tripBillNum int
- for _, v := range listTripBill {
- //if v.ActivityId == 0 {
- // continue
- //}
- tripBillNum += v.BillDetailed
- }
- //if len(inheritList) > 0 {
- // for _, v := range inheritList {
- // if v.ChartPermissionId == 0 {
- // tripBillNum += v.Points
- // }
- // }
- //}
- tripRemaining = tripBillNum
- if tripRemaining < 0 {
- tripRemaining = 0
- }
- } else {
- list, e := models.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
- }
- if len(list) == 0 {
- return
- }
- var chartPermissionIdSlice []string
- mapChartName = make(map[string]int)
- mapUpgradeId := make(map[int]int)
- mapPermissionNameTrip := make(map[string]int)
- mapInheritChartName := make(map[string]int)
- //mapPermissionName := make(map[int]string)
- for _, v := range list {
- chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
- //是升级套餐才有点数
- if v.IsUpgrade == 1 {
- mapUpgradeId[v.ChartPermissionId] = 1
- }
- }
- chartList := make([]*models.ChartPermission, 0)
- if len(chartPermissionIdSlice) > 0 {
- chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
- if e != nil {
- err = errors.New("获取品种信息失败, Err:" + e.Error())
- return
- }
- }
- if len(chartList) == 0 {
- return
- }
- for _, v := range listTripBill {
- if v.ActivityId == 0 {
- continue
- }
- mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
- }
- for _, v := range chartList {
- //如果是升级则加点
- if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
- mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
- } else {
- mapChartName[v.PermissionName] = mapPermissionNameTrip[v.PermissionName]
- }
- }
- // 通过继承获得的加点
- //for _, v := range inheritList {
- // mapInheritChartName[v.ChartPermissionName] = v.Points
- //}
- for k, _ := range chartNameMap {
- if _, ok := mapChartName[k]; ok {
- if inherit, ok2 := mapInheritChartName[k]; ok2 {
- mapChartName[k] += inherit
- }
- }
- }
- for k, v := range mapChartName {
- if v > 0 {
- specialSurplus += k + strconv.Itoa(v) + "次+"
- }
- }
- specialSurplus = strings.TrimRight(specialSurplus, "+")
- }
- }
- return
- }
- // 确定行程用户报名模版消息推送
- func ActivitySpecialUserAddTrip(user *models.WxUserItem, activityId int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("确定行程用户报名模版消息推送,模板消息推送失败"+err.Error(), 2)
- }
- }()
- var first string
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var remark string
- //获取销售手机号
- sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- cnf, _ := models.GetConfigByCode("tpl_msg")
- if cnf != nil && sellerItemQy != nil {
- openIdList, e := models.GetWxOpenIdByMobileList(cnf.ConfigValue + "," + sellerItemQy.Mobile)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- activityInfo, e := models.GetCygxActivitySpecialDetailById(user.UserId, activityId)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
- return
- }
- if activityInfo == nil {
- return
- }
- keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, "(所属销售:", sellerItemQy.RealName, ")")
- keyword2 = user.Mobile
- keyword3 = time.Now().Format(utils.FormatDateTime)
- keyword4 = "报名专项调研【" + activityInfo.ResearchTheme + "】 "
- remark = ""
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
- sendInfo := new(SendWxTemplate)
- sendInfo.First = first
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- sendInfo.Remark = remark
- sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(activityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- err = PublicSendTemplateMsg(sendInfo)
- if err != nil {
- return
- }
- }
- return
- }
|