123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- package cygx
- import (
- "errors"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- func ConvertActivityTitmeYMD(TitmeYMD string) (titmeYMDNew string) {
- titmeYMDNew = TitmeYMD
- titmeYMDNew = strings.Replace(titmeYMDNew, "/", "月", -1)
-
-
-
-
-
-
-
- titmeYMDNew = strings.Replace(titmeYMDNew, "SUN", "日", -1)
- titmeYMDNew = strings.Replace(titmeYMDNew, "MON", "日", -1)
- titmeYMDNew = strings.Replace(titmeYMDNew, "TUE", "日", -1)
- titmeYMDNew = strings.Replace(titmeYMDNew, "WED", "日", -1)
- titmeYMDNew = strings.Replace(titmeYMDNew, "THU", "日", -1)
- titmeYMDNew = strings.Replace(titmeYMDNew, "FRI", "日", -1)
- titmeYMDNew = strings.Replace(titmeYMDNew, "SAT", "日", -1)
- titmeYMDNew = strconv.Itoa(time.Now().Year()) + "年" + titmeYMDNew
- return
- }
- func ConvertActivityTitmeHM(titmeHM string) (titmeHMNew string) {
- titmeHMNew = titmeHM
-
- var amOrPm string
- if strings.Contains(titmeHM, "PM") {
-
- amOrPm = "PM"
- } else {
- amOrPm = "AM"
- }
- titmeHM = strings.Replace(titmeHM, "AM", "", -1)
- titmeHM = strings.Replace(titmeHM, "PM", "", -1)
- sliceHm := strings.Split(titmeHM, ":")
- if len(sliceHm) != 2 {
- return
- }
- hourNum, _ := strconv.Atoi(sliceHm[0])
- minute := sliceHm[1]
- titmeHMNew = strconv.Itoa(hourNum) + ":" + minute + " " + amOrPm
- return
- }
- var ActivityOcrTemplate = "<p>【小范围公司线上交流】{{COMPANY}}</p><p>时间:{{TIME}}</p><p>嘉宾:IR</p><p>主持人:IR</p><p>链接参会:(会前一天下午更新)</p><p>备注:</p><p>1、请先报名,我们将于会议前一天提供【Webex】入会链接(可电话拨入or网络端参会);</p><p>2、会议语言:{{LANGUAGE}};</p><p>3、本场会议报名截止时间为会议开始前一天下午3点半;</p><p>4、本次会议扣0.5次研选服务点。</p>"
- func MakeActivityReqText(list []*cygx.AliyunOcrTextActivityResp) (req cygx.ActivityRep, err error, errMsg string) {
- for _, v := range list {
- ActivityOcrTmp := ActivityOcrTemplate
- sliceCompany := strings.Split(v.Company, "(")
- company := sliceCompany[0]
-
- ActivityOcrTmp = strings.Replace(ActivityOcrTmp, "{{COMPANY}}", v.Company, -1)
- v.TitmeYMD = strings.Replace(v.TitmeYMD, "年", "-", -1)
- v.TitmeYMD = strings.Replace(v.TitmeYMD, "月", "-", -1)
- v.TitmeYMD = strings.Replace(v.TitmeYMD, "日", "", -1)
- weeknum := utils.StrDateTimeToWeek(v.TitmeYMD + " 00:00:00")
- havePm := strings.Contains(v.TitmeHM, "PM")
- var activityTime string
- activityTime = strings.Replace(v.TitmeHM, " ", "", -1)
- activityTime = strings.Replace(activityTime, "AM", "", -1)
- activityTime = strings.Replace(activityTime, "PM", "", -1)
- activityTime = v.TitmeYMD + " " + activityTime + ":00"
- resultTime := utils.StrTimeToTime(activityTime)
- var amOrPm string
- if havePm {
-
- slicePm := strings.Split(v.TitmeHM, ":")
- for sk, sv := range slicePm {
-
- if sk == 0 && sv != "12" {
- resultTime = resultTime.Add(12 * time.Hour)
- activityTime = resultTime.Format(utils.FormatDateTime)
- }
- }
- amOrPm = "PM"
- } else {
- amOrPm = "AM"
- }
- var condition string
- var pars []interface{}
- condition = " AND activity_type_id = 3 AND activity_time = ? AND temporary_label = ? "
- pars = append(pars, activityTime, company)
- total, e := cygx.GetActivityCount(condition, pars)
- if e != nil {
- err = errors.New("GetActivityCount,Err" + e.Error())
- return
- }
- if total > 0 {
- errMsg = "相同时段已存在对应活动"
- return
- }
- ActivityOcrTmp = strings.Replace(ActivityOcrTmp, "{{TIME}}", v.TitmeYMD+"("+weeknum+")"+resultTime.Format(utils.FormatTimeHm)+amOrPm, -1)
- if !utils.CheckStrHaveLetter(company) {
- ActivityOcrTmp = strings.Replace(ActivityOcrTmp, "{{LANGUAGE}}", "中文", -1)
- } else {
- ActivityOcrTmp = strings.Replace(ActivityOcrTmp, "{{LANGUAGE}}", "英文", -1)
- }
- req.Body += ActivityOcrTmp + "<hr>"
- label := new(cygx.ActivityGroupIndustrialRep)
- label.TemporaryLabel = company
- req.List = append(req.List, label)
- }
-
- req.Body = strings.TrimRight(req.Body, "<hr>")
- req.DoType = 1
- req.ActivityTypeId = 3
- req.PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
- req.CustomerTypeIds = "1,2,8,10,3,9,5,6,7"
- req.IsAllCustomerType = 1
- req.LimitPeopleNum = 10
- req.LabelType = 1
- req.VisibleRange = 2
- req.IsResearchPoints = 1
- req.IsNeedEmail = 1
- req.IsShowHz = 1
-
- pointsSet := new(cygx.CygxActivityPointsSetRsq)
- pointsSet.PointsObject = "1"
- pointsSet.UserPointsNum = "0.5"
- pointsSet.PointsType = "1"
- pointsSet.CompanyPointsNum = "0"
- pointsSet.CancelDeadlineType = "1"
- req.PointsSet = pointsSet
- return
- }
- func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *cygx.CygxActivityVoice, itemVideo *cygx.CygxActivityVideo) (err error) {
- if activityInfo.ActiveState != 3 {
- return
- }
- activityId := activityInfo.ActivityId
- var condition string
- var pars []interface{}
-
- if itemVoice.ActivityId > 0 {
- condition = " AND activity_id = ? "
- pars = append(pars, activityId)
- total, e := cygx.GetCygxActivityVoiceCount(condition, pars)
- if e != nil {
- err = errors.New("GetCygxActivityVoiceCount" + e.Error())
- return
- }
- activityId := itemVoice.ActivityId
-
- activityInfo, e := cygx.GetAddActivityInfoById(activityId)
- if e != nil {
- err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
- return
- }
-
- if (activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 7) && activityInfo.IsYidongConduct == 1 {
- itemVoice.FileType = 1
- } else {
- itemVoice.FileType = 2
- }
- shareImg, _ := MakeCygxMp3HtmlImg(itemVoice.VoicePlaySeconds)
- itemVoice.ShareImg = shareImg
- itemVoice.VoiceName = utils.RemoveFileSuffixName(itemVoice.VoiceName)
-
- if total == 0 {
- newId, e := cygx.AddCygxActivityVoice(itemVoice)
- if e != nil {
- err = errors.New("GetCygxActivityVoiceCount" + e.Error())
- return
- }
- go UpdateActivityVoiceResourceData(int(newId))
- go SendWxMsgWithUpdateActivityVideoAndVoice(activityId, itemVoice.VoiceName)
- } else {
-
- voiceDetail, e := cygx.GetCygxActivityVoiceReqDetailByActivityId(activityId)
- if e != nil {
- err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error())
- return
- }
-
- if voiceDetail.IsByHand == 1 {
- itemVoice.FileType = voiceDetail.FileType
- }
- e = cygx.UpdateCygxActivityVoice(itemVoice)
- if e != nil {
- err = errors.New("UpdateCygxActivityVoice" + e.Error())
- return
- }
- go UpdateActivityVoiceResourceData(voiceDetail.ActivityVoiceId)
- }
- } else {
- voiceDetail, e := cygx.GetCygxActivityVoiceReqDetail(activityId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error())
- return
- }
- if voiceDetail != nil {
- e = cygx.DeleteCygxActivityVoice(activityId)
- if e != nil {
- err = errors.New("DeleteCygxActivityVoice" + e.Error())
- return
- }
- go UpdateActivityVoiceResourceData(voiceDetail.ActivityVoiceId)
- }
- }
-
- if itemVideo.ActivityId > 0 {
- condition = " AND art.activity_id = ? "
- pars = append(pars, activityId)
- total, e := cygx.GetActivityVideoCount(condition, pars)
- if e != nil {
- err = errors.New("GetActivityVideoCount" + e.Error())
- return
- }
- activityId := itemVideo.ActivityId
-
- activityInfo, e := cygx.GetAddActivityInfoById(activityId)
- if e != nil {
- err = errors.New("GetAddActivityInfoById, Err: " + e.Error())
- return
- }
-
- if (activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 7) && activityInfo.IsYidongConduct == 1 {
- itemVideo.FileType = 1
- } else {
- itemVideo.FileType = 2
- }
- shareImg, _ := MakeCygxMp4HtmlImg(itemVideo.VideoDuration)
- itemVideo.ShareImg = shareImg
- itemVideo.VideoName = utils.RemoveFileSuffixName(itemVideo.VideoName)
-
- var newOssUrl string
- newOssUrl = strings.Replace(itemVideo.VideoUrl, "https://hzstatic.hzinsights.com", "https://hzchart.oss-accelerate.aliyuncs.com", -1)
- itemVideo.VideoUrl = newOssUrl
-
- if total == 0 {
- newId, e := cygx.AddCygxActivityVideo(itemVideo)
- if e != nil {
- err = errors.New("AddCygxActivityVideo" + e.Error())
- return
- }
- go UpdateActivityVideoResourceData(int(newId))
- go SendWxMsgWithUpdateActivityVideoAndVoice(activityId, itemVideo.VideoName)
- } else {
-
- videoDetail, e := cygx.GetCygxActivityVideoReqDetail(activityId)
- if e != nil {
- err = errors.New("GetCygxActivityVideoReqDetail" + e.Error())
- return
- }
-
- if videoDetail.IsByHand == 1 {
- itemVideo.FileType = videoDetail.FileType
- }
- e = cygx.UpdateCygxActivityVideo(itemVideo)
- if e != nil {
- err = errors.New("UpdateCygxActivityVideo" + e.Error())
- return
- }
- go UpdateActivityVideoResourceData(videoDetail.VideoId)
- }
- } else {
-
- videoDetail, e := cygx.GetCygxActivityVideoReqDetail(activityId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivityVideoReqDetail" + e.Error())
- return
- }
- if videoDetail != nil {
- e = cygx.DeleteCygxActivityVideo(activityId)
- if e != nil {
- err = errors.New("DeleteCygxActivityVideo" + e.Error())
- return
- }
- go UpdateActivityVideoResourceData(videoDetail.VideoId)
- }
- }
- return
- }
|