123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038 |
- package services
- import (
- "context"
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "strconv"
- "strings"
- "time"
- )
- //func init() {
- // UpdateCygxActivitySpecialSignupNum()
- //}
- // 修改专项调研,用户与公司的参与数量
- func UpdateCygxActivitySpecialSignupNum(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("修改活动状态至进行中失败"+err.Error(), 2)
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至进行中失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- //根据手机号分组获取列表以及数量
- var condition string
- var pars []interface{}
- condition += ` AND s.create_time < ? `
- pars = append(pars, time.Now().Format(utils.FormatDate))
- listSpecial, err := models.GetActivityListSpecialGroupByMobile(condition, pars)
- if err != nil {
- return err
- }
- var mapMobile []string
- for _, v := range listSpecial {
- mapMobile = append(mapMobile, v.Mobile)
- }
- //根据手机号获取这些用户的信息
- userList, err := models.GetWxUserByMobiles(mapMobile)
- if err != nil {
- return err
- }
- //更改这些手机对应的关注关注数量
- err = models.UpdateActivitySpecialSignupNumMulti(listSpecial)
- if err != nil {
- return err
- }
- //更改这些手机对应的公司ID
- err = models.UpdateActivitySpecialSignupCompanyIdMulti(userList)
- if err != nil {
- return err
- }
- //根据CompanyId分组获取列表以及数量
- listSpecialByCompanyId, err := models.GetActivityListSpecialGroupByCompanyId(condition, pars)
- if err != nil {
- return err
- }
- //更改这些公司对应的关注关注数量
- err = models.UpdateActivitySpecialSignupCompanyNumMulti(listSpecialByCompanyId)
- if err != nil {
- return err
- }
- fmt.Println("UpdateCygxActivitySpecialSignupNum end")
- return
- }
- // 处理专项调研的展示
- func GetActivityLabelSpecialList(user *models.WxUserItem, isPower int, chartPermissionIds, permissionNameStr string) (item *models.ActivityTypeHome, err error) {
- itemList := new(models.ActivityTypeHome)
- if user.CompanyId <= 1 {
- itemList.List = make([]*models.CygxActivityLabelList, 0)
- item = itemList
- return
- }
- userType, e := GetSpecialUserType(user)
- if e != nil {
- err = errors.New("GetSpecialUserType, Err: " + e.Error())
- return
- }
- if userType == 0 {
- itemList.List = make([]*models.CygxActivityLabelList, 0)
- item = itemList
- return
- }
- companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
- return
- }
- //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
- var condition string
- if companyDetail.Status == "永续" {
- condition, e = HandleActivityLabelSpecialPermission(user)
- if e != nil {
- err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
- return
- }
- } else {
- condition, e = HandleActivityLabelSpecialTripPermission(user)
- if e != nil {
- err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
- return
- }
- }
- var pars []interface{}
- condition += ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
- //行业名称
- if isPower == 1 {
- condition += ` AND art.chart_permission_name IN (` + permissionNameStr + `) `
- }
- if chartPermissionIds != "" {
- condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `) `
- }
- conditionTrip := condition
- conditionTrip += ` AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
- conditionTrip += ` AND art.days > 0 ORDER BY art.activity_time ASC `
- specialList, err := models.GetActivityLabelSpecialListAll(conditionTrip, pars, 0, 8)
- if err != nil {
- return
- }
- //if len(specialList) < 8 {
- // conditionTrip += ` AND art.days = 0 ORDER BY art.last_updated_time DESC`
- condition += ` AND art.days = 0 ORDER BY art.last_updated_time DESC`
- specialListNotrip, e := models.GetActivityLabelSpecialListAll(condition, pars, 0, 20)
- if e != nil {
- err = e
- return
- }
- for _, v := range specialListNotrip {
- specialList = append(specialList, v)
- }
- //}
- for k2, v2 := range specialList {
- if v2.Days == 0 {
- specialList[k2].TripStatus = 1
- } else {
- specialList[k2].TripStatus = 2
- }
- specialList[k2].KeyWord = LabelStrV5(v2.KeyWord, v2.IsShowSubjectName, v2.TemporaryLabel)
- specialList[k2].ImgUrlBg = "https://hzstatic.hzinsights.com/static/temp/20220426202204/20220426/XDLLsjC9XAAy8LIzQr7GsjrBbtX6.png"
- specialList[k2].ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl3
- }
- itemList.ActivityTypeName = "专项产业调研"
- itemList.Resource = 2
- itemList.List = specialList
- itemList.ActivityTypeId = 7
- itemList.ImgUrl = utils.ACTIVITY_ZXDY_ImgUrl1
- itemList.ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl2
- item = itemList
- return
- }
- // HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql 永续
- func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition string, err error) {
- permissionStr, e := GetCompanyPermission(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyPermission, Err: " + e.Error())
- return
- }
- userType, e := GetSpecialUserType(user)
- if e != nil {
- err = errors.New("GetSpecialUserType, Err: " + e.Error())
- return
- }
- slicePer := strings.Split(permissionStr, ",")
- var permissionSqlStr string
- for _, v := range slicePer {
- if userType == 1 {
- if !strings.Contains(v, "研选") {
- permissionSqlStr += "'" + v + "',"
- }
- } else {
- permissionSqlStr += "'" + v + "',"
- }
- }
- permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
- condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
- if permissionSqlStr != "" {
- condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
- }
- condition += ` AND art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
- return
- }
- // HandleActivityLabelSpecialPermisseion 处理专项产业调研的查询权限sql
- func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (condition string, err error) {
- permissionStr, e := GetCompanyPermission(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyPermission, Err: " + e.Error())
- return
- }
- userType, e := GetSpecialUserType(user)
- if e != nil {
- err = errors.New("GetSpecialUserType, Err: " + e.Error())
- return
- }
- slicePer := strings.Split(permissionStr, ",")
- var permissionSqlStr string
- for _, v := range slicePer {
- if userType == 1 {
- if !strings.Contains(v, "研选") {
- permissionSqlStr += "'" + v + "',"
- }
- } else {
- permissionSqlStr += "'" + v + "',"
- }
- }
- permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
- condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
- if permissionSqlStr != "" {
- condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
- }
- condition += ` AND art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
- return
- }
- // 获取预报名列表
- func GetActivitySpecialPrepareList(user *models.WxUserItem, startSize, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, totalPrepare int, err error) {
- companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
- return
- }
- //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
- var condition string
- if companyDetail.Status == "永续" {
- condition, e = HandleActivityLabelSpecialPermission(user)
- if e != nil {
- err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
- return
- }
- } else {
- condition, e = HandleActivityLabelSpecialTripPermission(user)
- if e != nil {
- err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
- return
- }
- }
- var pars []interface{}
- condition += ` AND art.days = 0 AND art.publish_status = 1 AND art.is_offline = 0 `
- if keywords != "" {
- keywords = "%" + keywords + "%"
- condition += ` AND art.research_theme LIKE ? `
- pars = append(pars, keywords)
- }
- totalPrepare, e = models.GetActivitySpecialCount(condition, pars)
- if e != nil {
- err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
- return
- }
- condition += ` ORDER BY art.last_updated_time DESC `
- list, e = models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, pageSize)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
- return
- }
- return
- }
- /*
- 确定行程的查询 GetActivityLabelSpecialConfirmList
- state 进行状态 1:未开始,2:进行中,3:已结束,4:未开始、进行中 不传默认查询全部items []*CygxActivitySpecialDetail
- */
- func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, pageSize, state int, keywords string) (list []*models.CygxActivitySpecialDetail, totalConfirm int, err error) {
- //var condition string
- companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
- return
- }
- if companyDetail == nil {
- return
- }
- //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
- var condition string
- if companyDetail.Status == "永续" {
- condition, e = HandleActivityLabelSpecialPermission(user)
- if e != nil {
- err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
- return
- }
- } else {
- condition, e = HandleActivityLabelSpecialTripPermission(user)
- if e != nil {
- err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
- return
- }
- }
- var pars []interface{}
- condition += ` AND art.days >0 AND art.publish_status =1 AND art.is_offline = 0 `
- if state == 1 {
- condition += ` AND art.activity_time > ? `
- pars = append(pars, time.Now())
- }
- if state == 2 {
- condition += ` AND art.activity_time < ? `
- pars = append(pars, time.Now())
- condition += ` AND art.activity_time_end > ? `
- pars = append(pars, time.Now())
- }
- if state == 3 {
- condition += ` AND art.activity_time_end < ? `
- pars = append(pars, time.Now())
- }
- if state == 4 {
- condition += ` AND art.activity_time_end > ? `
- pars = append(pars, time.Now())
- }
- if keywords != "" {
- keywords = "%" + keywords + "%"
- condition += ` AND art.research_theme LIKE ? `
- pars = append(pars, keywords)
- }
- totalConfirm, e = models.GetActivitySpecialCount(condition, pars)
- if e != nil {
- err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
- return
- }
- condition += ` ORDER BY art.activity_time ASC `
- list, e = models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, pageSize)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
- return
- }
- var activityIds []int
- for k, v := range list {
- resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
- resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
- if resultTimeStart.After(time.Now()) {
- list[k].ActiveState = 1
- } else if time.Now().After(resultTimeEnd) {
- list[k].ActiveState = 3
- } else {
- list[k].ActiveState = 2
- }
- if list[k].Days == 0 {
- list[k].TripStatus = 1
- } else {
- list[k].TripStatus = 2
- }
- activityIds = append(activityIds, v.ActivityId)
- }
- //处理用户已经报名了的行程
- UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
- if e != nil {
- err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
- return
- }
- for k, v := range list {
- if _, ok := UserMap[v.ActivityId]; ok {
- list[k].IsTrip = 1
- }
- }
- return
- }
- // 获取用户已经报名的活动
- func GetSpecialTripUserMap(activityIds []int, userId int) (mapUserId map[int]int, err error) {
- var condition string
- var pars []interface{}
- activityIdsLen := len(activityIds)
- if activityIdsLen > 0 {
- condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
- pars = append(pars, activityIds)
- }
- condition += ` AND user_id = ? AND is_cancel = 0 `
- pars = append(pars, userId)
- list, e := models.GetCygxActivitySpecialTripList(condition, pars)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
- return
- }
- mapUid := make(map[int]int)
- for _, v := range list {
- mapUid[v.ActivityId] = v.UserId
- }
- mapUserId = mapUid
- return
- }
- // 获取用户已经报名的活动数量
- func GetSpecialTripUserSchedule(userId int) (total int, err error) {
- var condition string
- var pars []interface{}
- condition += ` AND t.user_id = ? AND t.is_cancel = 0 `
- pars = append(pars, userId)
- condition += ` AND a.activity_time_end >= ? `
- pars = append(pars, time.Now())
- condition += ` AND is_valid = 1 `
- total, err = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
- return
- }
- // GetActivitySpecialList 获取专项调研列表
- func GetActivitySpecialList(user *models.WxUserItem, currentIndex, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, total int, err error) {
- listConfirm, totalConfirm, e := GetActivityLabelSpecialConfirmList(user, (currentIndex-1)*pageSize, pageSize, 4, keywords)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetActivityLabelSpecialConfirmList11, Err: " + e.Error())
- return
- }
- if totalConfirm == 0 {
- return
- }
- if currentIndex == 1 && len(listConfirm) > 0 {
- listConfirm[0].Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
- }
- list = listConfirm
- total = totalConfirm
- var startSizePrepare, pageSizePrepare int
- //全是确定行程的查询数据
- if totalConfirm >= currentIndex*pageSize {
- startSizePrepare = 0
- pageSizePrepare = 0
- } else if totalConfirm > (currentIndex-1)*pageSize && totalConfirm < currentIndex*pageSize {
- //一半确认行程一半预报名
- startSizePrepare = 0
- pageSizePrepare = pageSize - len(listConfirm)
- } else {
- //全是预报名
- startSizePrepare = (currentIndex-1)*pageSize - totalConfirm
- pageSizePrepare = pageSize - len(listConfirm)
- }
- listPrepare, totalPrepare, e := GetActivitySpecialPrepareList(user, startSizePrepare, pageSizePrepare, keywords)
- if e != nil {
- err = errors.New("GetActivityLabelSpecialConfirmList, Err: " + e.Error())
- return
- }
- if len(listPrepare) > 0 {
- for _, v := range listPrepare {
- list = append(list, v)
- }
- if startSizePrepare == 0 {
- listPrepare[0].Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
- }
- }
- total = totalConfirm + totalPrepare
- //处理封面图片
- detail, e := models.GetConfigByCode("city_img_url")
- if e != nil {
- err = errors.New("GetConfigByCode, Err: " + e.Error())
- return
- }
- detailChart, e := models.GetConfigByCode("chart_img_url")
- if e != nil {
- err = errors.New("GetConfigByCode, Err: " + e.Error())
- return
- }
- addressList := strings.Split(detail.ConfigValue, "{|}")
- mapAddress := make(map[string]string)
- chartList := strings.Split(detailChart.ConfigValue, "{|}")
- mapChart := make(map[string]string)
- var cityName string
- var chartName string
- var imgUrl string
- var imgUrlChart string
- for _, v := range addressList {
- vslice := strings.Split(v, "_")
- cityName = vslice[0]
- imgUrl = vslice[len(vslice)-1]
- mapAddress[cityName] = imgUrl
- }
- for _, v := range chartList {
- vslice := strings.Split(v, "_")
- chartName = vslice[0]
- imgUrlChart = vslice[len(vslice)-1]
- mapChart[chartName] = imgUrlChart
- }
- for k, v := range list {
- //list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
- if mapChart[v.ChartPermissionName] != "" {
- list[k].ImgUrl = mapChart[v.ChartPermissionName]
- }
- list[k].ActivityTypeName = "专项调研"
- if list[k].Days == 0 {
- list[k].TripStatus = 1
- } else {
- list[k].TripStatus = 2
- list[k].TripImgLink = list[k].TripImgLinkFix
- }
- }
- return
- }
- // HandleActivitySpecialShow 处理活动的状态
- func HandleActivitySpecialShow(activityDetail *models.CygxActivitySpecialDetail, user *models.WxUserItem) (item *models.CygxActivitySpecialDetail, err error) {
- var activityIds []int
- resultTimeStart := utils.StrTimeToTime(activityDetail.ActivityTime) //时间字符串格式转时间格式
- resultTimeEnd := utils.StrTimeToTime(activityDetail.ActivityTimeEnd) //时间字符串格式转时间格式
- if resultTimeStart.After(time.Now()) {
- activityDetail.ActiveState = 1
- } else if time.Now().After(resultTimeEnd) {
- activityDetail.ActiveState = 3
- } else {
- activityDetail.ActiveState = 2
- }
- activityIds = append(activityIds, activityDetail.ActivityId)
- //处理用户已经报名了的行程
- UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
- if e != nil {
- err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
- return
- }
- if activityDetail.Days == 0 {
- activityDetail.TripStatus = 1
- activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
- } else {
- activityDetail.TripStatus = 2
- activityDetail.TripImgLink = activityDetail.TripImgLinkFix
- activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
- }
- if _, ok := UserMap[activityDetail.ActivityId]; ok {
- activityDetail.IsTrip = 1
- }
- item = activityDetail
- return
- }
- // 活动与专项调研搜索 GetActivitySpecialSearcheList
- func GetActivitySpecialSearcheList(user *models.WxUserItem, condition string, startSize, pageSize int, keywords string) (items []*models.ActivityDetail, total int, err error) {
- var conditionSpecil string
- var pars, parsSpecil []interface{}
- keyword := keywords
- if keywords != "" {
- keywords = "%" + keywords + "%"
- conditionSpecil += ` AND art.days > 0 AND (art.research_theme LIKE ? OR art.label LIKE ? OR art.industrial_name LIKE ? OR art.industrial_subject_name LIKE ? ) `
- parsSpecil = append(parsSpecil, keywords, keywords, keywords, keywords)
- }
- list, totalSearche, e := models.GetActivitySpecialSearcheList(condition, pars, conditionSpecil, parsSpecil, startSize, pageSize)
- if e != nil {
- err = errors.New("GetActivitySpecialSearcheList, Err: " + e.Error())
- return
- }
- keyWordArr, e := GetIndustryMapNameSliceV3(keywords)
- if e != nil {
- err = errors.New("GetActivityonditionList, Err: " + e.Error())
- return
- }
- var totalIk int
- if len(keyWordArr) > 1 {
- // 查询IK分词后那一部分的数据
- conditionActivityIk, e := GetActivityonditionList(user, "", "", "", "", "", 0, 1, keyword, 0, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetActivityonditionList, Err: " + e.Error())
- return
- }
- conditionActivityIk += " AND art.is_limit_people = 1 AND art.publish_status = 1 "
- totalIk, e = models.GetActivityCount(conditionActivityIk, 0, pars, 0)
- if e != nil {
- err = errors.New("GetActivityonditionList, Err: " + e.Error())
- return
- }
- keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
- startSizeIk := startSize - totalSearche
- if startSizeIk < 0 {
- startSizeIk = 0
- }
- var pageSizeIk int
- pageSizeIk = pageSize - len(list)
- if pageSizeIk > 0 {
- //搜索关键词联想
- conditionActivityIk += ` ORDER BY art.activity_time DESC , art.active_state ASC `
- listIk, e := models.GetActivityListNew(conditionActivityIk, pars, user.UserId, startSizeIk, pageSizeIk, 0, 0, "")
- if e != nil {
- err = errors.New("GetActivityonditionList, Err: " + e.Error())
- return
- }
- for _, item := range listIk {
- list = append(list, item)
- }
- }
- }
- total = totalSearche + totalIk
- items, e = HandleActivityListButton(list, user)
- if e != nil {
- err = errors.New("HandleActivityListButton, Err: " + e.Error())
- return
- }
- return
- }
- // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
- func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew string, err error) {
- var permissionStr string
- if companyId <= 1 {
- userType = 0
- } else {
- total, e := models.GetCountCompanyDetailByIdGroupTrip(companyId)
- if e != nil {
- err = errors.New("GetCountCompanyDetailByIdGroupTrip, Err: " + e.Error())
- return
- }
- if total == 0 {
- userType = 0
- } else {
- companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
- if e != nil {
- err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
- return
- }
- permissionStr, e = models.GetCompanyPermissionByUserTrip(companyId)
- if e != nil {
- err = errors.New("GetCompanyPermissionByUserTrip, Err: " + e.Error())
- return
- }
- //permissionZhengShiStr, e = models.GetCompanyPermissionByUserZhengShiTrip(companyId)
- //if e != nil {
- // err = errors.New("GetCompanyPermissionByUserZhengShiTrip, Err: " + e.Error())
- // return
- //}
- //大套餐客户定义:医药、消费、科技、智造。4个行业中为升级,策略是正式,属于大套餐客户
- if companyDetail.Status == "永续" {
- userType = 1
- } else if companyDetail.Status == "试用" {
- userType = 5
- } else if companyDetail.Status == "正式" {
- if permissionStr == "专家" {
- userType = 4
- } else if strings.Count(permissionStr, "医药") == 2 && strings.Count(permissionStr, "消费") == 2 && strings.Count(permissionStr, "科技") == 2 && strings.Count(permissionStr, "智造") == 2 && strings.Count(permissionStr, "策略") == 1 {
- userType = 2
- } else {
- userType = 3
- }
- if userType == 3 {
- if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
- userType = 4
- }
- }
- } else if companyDetail.Status == "冻结" {
- userType = 6
- } else if companyDetail.Status == "流失" {
- userType = 7
- }
- }
- }
- permissionStrnew = permissionStr
- return
- }
- // GetSpecialUserType 获取专项产业调研的用户身份类型
- // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
- func GetSpecialUserType(user *models.WxUserItem) (userType int, err error) {
- companyId := user.CompanyId
- companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
- return
- }
- if companyDetail == nil {
- return
- }
- if companyId <= 1 {
- userType = 0
- } else {
- if companyDetail.Status == "永续" {
- userType = 1
- } else {
- if companyDetail.Status == "正式" {
- list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
- }
- if len(list) == 0 {
- userType = 9
- }
- if len(list) == 4 {
- totalName, e := models.GetCompanyPermissionNameCheck(companyId, 2, "策略")
- if e != nil {
- err = errors.New("获取品种信息失败, Err:" + e.Error())
- return
- }
- if totalName > 0 {
- userType = 2
- } else {
- userType = 8
- }
- } else {
- userType = 8
- }
- } else if companyDetail.Status == "试用" {
- userType = 5
- }
- }
- }
- return
- }
- // GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
- func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (havePower bool, err error) {
- permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
- return
- }
- fmt.Println(permissionStr)
- //如果没有对应的升级权限,则返回
- if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
- return
- }
- userType, e := GetSpecialUserType(user)
- if e != nil {
- err = errors.New("GetSpecialUserType, Err: " + e.Error())
- return
- }
- if userType == 0 {
- return
- }
- var pars []interface{}
- var condition string
- var userTypes string
- condition += ` AND art.publish_status = 1 AND art.is_offline = 0 `
- userTypes = "%" + strconv.Itoa(userType) + "%"
- condition += ` AND art.customer_type_ids LIKE ? `
- pars = append(pars, userTypes)
- condition += ` AND art.activity_id = ? `
- pars = append(pars, activityInfo.ActivityId)
- total, e := models.GetActivitySpecialCount(condition, pars)
- if e != nil {
- err = errors.New("GetSpecialUserType, Err: " + e.Error())
- return
- }
- if total == 1 {
- havePower = true
- }
- return
- }
- // 预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳
- func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail) (err error) {
- activityId := activityInfo.ActivityId
- var msg string
- defer func() {
- if err != nil {
- go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
- go utils.SendAlarmMsg(fmt.Sprint("预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳消息发送失败", activityInfo.ResearchTheme, ", activityId"), 2)
- utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
- }
- }()
- var first string
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var remark string
- adminUser, e := models.GetSellerByAdminId(activityInfo.AdminId)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- cnf, _ := models.GetConfigByCode("tpl_msg")
- mobile := adminUser.Mobile + "," + cnf.ConfigValue
- specialSignupList, e := models.GetActivityListSpecialByActivityId(activityId)
- if e != nil {
- err = errors.New("GetActivityListSpecialAll, Err: " + e.Error())
- return
- }
- for _, v := range specialSignupList {
- keyword1 += "【" + v.RealName + "--" + v.CompanyName + "】"
- }
- openIdList, e := models.GetWxOpenIdByMobileList(mobile)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- first = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
- keyword3 = "-"
- keyword2 = "-"
- keyword4 = activityInfo.ResearchTheme
- 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.WxMsgTemplateIdAskMsgXzs
- 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
- }
- // SendWxMsgActivitySpecialTwoDays 活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
- func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
- var msg string
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
- go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
- utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
- }
- }()
- twoDayTime := time.Now().AddDate(0, 0, 2)
- startTime := twoDayTime.Format(utils.FormatDate) + " 00:00:00"
- endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
- var condition string
- var pars []interface{}
- condition = ` AND days >0 AND activity_time BETWEEN ? AND ? `
- pars = append(pars, startTime, endTime)
- listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- if len(listActivitySpecial) == 0 {
- return
- }
- var activityIds []int
- for _, v := range listActivitySpecial {
- activityIds = append(activityIds, v.ActivityId)
- condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
- pars = make([]interface{}, 0)
- listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
- return
- }
- if len(listSpecialTrip) == 0 {
- return
- }
- var mobile string
- var companyIds []int
- for _, vT := range listSpecialTrip {
- mobile += "'" + vT.Mobile + "',"
- companyIds = append(companyIds, vT.CompanyId)
- }
- mobile = strings.TrimRight(mobile, ",")
- openIdList, e := models.GetWxOpenIdByMobileList(mobile)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- first := "【" + v.ResearchTheme + "】专项调研将在两天后进行,如不能参加,请及时取消报名"
- keyword1 := v.ResearchTheme
- keyword2 := "已报名"
- keyword3 := v.ActivityTimeTextByDay
- keyword4 := "线上"
- if v.SpecialType == 2 {
- keyword4 = v.City
- }
- remark := "点击查看活动详情"
- SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
- //活动开始前两天08:00,提醒报名客户的对口销售
- companyIdsLen := len(companyIds)
- if companyIdsLen == 0 {
- continue
- } else {
- pars = make([]interface{}, 0)
- condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
- pars = append(pars, companyIds)
- listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
- return
- }
- if len(listSeller) == 0 {
- continue
- }
- type SllerData struct {
- Openid string `description:"Openid"`
- Keyword string `description:"Keyword "`
- }
- mapSller := make(map[string]string)
- mapSllerOpenid := make(map[string]string)
- for _, vS := range listSeller {
- for _, vT := range listSpecialTrip {
- if vT.CompanyId == vS.CompanyId {
- mapSller[vS.Mobile] += "【" + vT.RealName + "--" + vT.CompanyName + "】"
- mapSllerOpenid[vS.Mobile] = vS.OpenId
- }
- }
- }
- for k, vM := range mapSller {
- first = "【" + v.ResearchTheme + "】专项调研将在两天后进行,请及时提醒您的报名客户"
- keyword2 = vM
- openIdList = make([]*models.OpenIdList, 0)
- openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
- SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
- }
- }
- }
- return
- }
- // SendWxMsgActivitySpecialCancel 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
- func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
- var msg string
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
- go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
- utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
- }
- }()
- dayTime3 := time.Now().AddDate(0, 0, 3)
- startTime := dayTime3.Format(utils.FormatDate) + " 00:00:00"
- endTime := dayTime3.Format(utils.FormatDate) + " 23:59:59"
- dayTime4 := time.Now().AddDate(0, 0, 4)
- startTime4 := dayTime4.Format(utils.FormatDate) + " 00:00:00"
- endTime4 := dayTime4.Format(utils.FormatDate) + " 23:59:59"
- var condition string
- var pars []interface{}
- condition = ` AND days >0 AND activity_time BETWEEN ? AND ? AND special_type= 1 `
- pars = append(pars, startTime, endTime)
- condition += ` OR ( days >0 AND activity_time BETWEEN ? AND ? AND special_type= 2 ) `
- pars = append(pars, startTime4, endTime4)
- listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- if len(listActivitySpecial) == 0 {
- return
- }
- var activityIds []int
- for _, v := range listActivitySpecial {
- activityIds = append(activityIds, v.ActivityId)
- condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
- pars = make([]interface{}, 0)
- listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
- if e != nil {
- err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
- return
- }
- if v.SpecialType == 1 {
- if len(listSpecialTrip) >= 10 {
- continue
- }
- }
- if v.SpecialType == 2 {
- if len(listSpecialTrip) >= 7 {
- continue
- }
- }
- e = models.UpdateActivitySpecialPublishStatus(0, v.ActivityId)
- if e != nil {
- err = errors.New("UpdateActivitySpecialPublishStatus,自动取消专项调研日程失败 Err: " + e.Error() + strconv.Itoa(v.ActivityId))
- return
- }
- if len(listSpecialTrip) < 0 {
- return
- }
- var mobile string
- var companyIds []int
- for _, vT := range listSpecialTrip {
- mobile += "'" + vT.Mobile + "',"
- companyIds = append(companyIds, vT.CompanyId)
- }
- mobile = strings.TrimRight(mobile, ",")
- openIdList, e := models.GetWxOpenIdByMobileList(mobile)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- first := "【" + v.ResearchTheme + "】专项调研因专家安排变动,本次调研活动延期举办,具体时间另行通知"
- keyword1 := v.ResearchTheme
- keyword2 := "已取消"
- keyword3 := ""
- keyword4 := ""
- remark := ""
- openIdArr := make([]string, 0)
- for _, vOpenid := range openIdList {
- openIdArr = append(openIdArr, vOpenid.OpenId)
- }
- companyIdsLen := len(companyIds)
- if len(companyIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
- pars = append(pars, companyIds)
- listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
- return
- }
- if len(listSeller) > 0 {
- for _, vOpenid := range listSeller {
- openIdArr = append(openIdArr, vOpenid.OpenId)
- }
- }
- }
- redirectUrl := ""
- 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(v.ActivityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- fmt.Println(sendInfo)
- err = PublicSendTemplateMsg(sendInfo)
- }
- return
- }
|