activity.go 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/utils"
  9. "os"
  10. "path/filepath"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "unicode/utf8"
  15. )
  16. // 修改活动状态
  17. func UpdateActivitySattus(cont context.Context) (err error) {
  18. //defer func() {
  19. // if err != nil {
  20. // fmt.Println("同步失败,Err:", err.Error())
  21. // }
  22. //}()
  23. go models.UpdateActivitySattusToHaveInHand()
  24. go models.UpdateActivitySattusToComplete()
  25. return
  26. }
  27. // 推送会议开始消息提醒60分钟前
  28. func SendActivityBeginMsg(cont context.Context) (err error) {
  29. //func SendActivityBeginMsg() (err error) {
  30. defer func() {
  31. if err != nil {
  32. go utils.SendAlarmMsg("60分钟会议消息提醒失败"+err.Error(), 2)
  33. fmt.Println("发送失败,Err:", err.Error())
  34. }
  35. }()
  36. endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
  37. listActivity, err := models.GetActivitySendMsgListAll(endDate)
  38. fmt.Println(len(listActivity))
  39. if err != nil {
  40. fmt.Println("GetActivitySendMsgListAll Err:", err.Error())
  41. return
  42. }
  43. if len(listActivity) == 0 {
  44. return
  45. }
  46. //var remark = "点击查看活动详情"
  47. var signupIds string
  48. for _, v := range listActivity {
  49. signupIds += strconv.Itoa(v.Id) + ","
  50. //var reserveResults string
  51. //var first string
  52. openIdItem := new(models.OpenIdList)
  53. openIdItem.OpenId = v.OpenId
  54. openIdItem.UserId = v.UserId
  55. openIdList := make([]*models.OpenIdList, 0)
  56. openIdList = append(openIdList, openIdItem)
  57. //if v.FailType == 0 {
  58. // reserveResults = "成功"
  59. //} else if v.FailType == 1 {
  60. // reserveResults = "失败(总人数已满)"
  61. //} else if v.FailType == 2 {
  62. // reserveResults = "失败(单机构超限制)"
  63. //} else if v.FailType == 3 {
  64. // reserveResults = "失败(爽约次数超限)"
  65. //}
  66. //reserveResults = "--"
  67. //first = "将在1小时后开始"
  68. //SendWxMsgWithFrequency(first, v.ActivityName, reserveResults, v.ActivityTimeText, v.Address, remark, openIdList, v.ActivityId)
  69. SendWxMsgWithFrequencyBycategory(v.ActivityName, v.ActivityTime, openIdList, v.ActivityId)
  70. }
  71. if len(signupIds) == 0 {
  72. return
  73. }
  74. signupIds = strings.TrimRight(signupIds, ",")
  75. err = models.UPdateSendedMsgStatus(signupIds)
  76. if err != nil {
  77. var msg string
  78. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  79. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  80. }
  81. return
  82. }
  83. //func init() {
  84. // SendActivityBeginMsgMeeting()
  85. //}
  86. // 推送会议开始消息提醒15分钟前
  87. func SendActivityBeginMsgMeeting(cont context.Context) (err error) {
  88. //func SendActivityBeginMsgMeeting() (err error) {
  89. defer func() {
  90. if err != nil {
  91. //go utils.SendAlarmMsg("15分钟会议消息提醒失败", 2)
  92. go utils.SendAlarmMsg(fmt.Sprint("15分钟会议消息提醒失败 SendActivityBeginMsgMeeting Err:", err.Error()), 2)
  93. //fmt.Println("发送失败,Err:", err.Error())
  94. }
  95. }()
  96. var condition string
  97. var pars []interface{}
  98. endDate := time.Now().Add(+time.Minute * 15).Format(utils.FormatDateTime)
  99. condition = ` AND activity_time <= ? AND activity_time >= NOW() AND publish_status = 1 `
  100. pars = append(pars, endDate)
  101. listActivity, e := models.GetCygxActivityList(condition, pars, 0, 100000)
  102. if e != nil && e.Error() != utils.ErrNoRow() {
  103. err = errors.New("GetCygxActivityList, Err: " + e.Error())
  104. return
  105. }
  106. if len(listActivity) == 0 {
  107. return
  108. }
  109. //var signupIds string
  110. //var remark = "点击查看活动详情"
  111. var activityIds []int
  112. //同一时间举办的活动不多所以这里循环查询
  113. for _, v := range listActivity {
  114. activityIds = append(activityIds, v.ActivityId)
  115. var mobiles []string
  116. pars = make([]interface{}, 0)
  117. condition = ` AND activity_id = ? AND is_send_wx_msg = 0 `
  118. pars = append(pars, v.ActivityId)
  119. //获取设置消息提醒的用户列表
  120. listxReminder, e := models.GetCygxReminderListByUser(condition, pars)
  121. if e != nil {
  122. err = errors.New("GetCygxReminderListByUser, Err: " + e.Error())
  123. return
  124. }
  125. for _, vReminder := range listxReminder {
  126. mobiles = append(mobiles, vReminder.Mobile)
  127. }
  128. pars = make([]interface{}, 0)
  129. condition = ` AND do_fail_type = 0 AND activity_id = ? AND signup_type = 1 AND is_send_wx_msg = 0 `
  130. pars = append(pars, v.ActivityId)
  131. //获取设置预约外呼的用户列表
  132. listSignup, e := models.GetActivitySignupList(condition, pars)
  133. if e != nil && e.Error() != utils.ErrNoRow() {
  134. err = errors.New("GetActivitySignupList, Err: " + e.Error())
  135. return
  136. }
  137. for _, vSignup := range listSignup {
  138. mobiles = append(mobiles, vSignup.Mobile)
  139. }
  140. //获取这些手机号对应的Openid
  141. listOpenid, e := models.GetUserRecordListByMobileArr(mobiles)
  142. if e != nil && e.Error() != utils.ErrNoRow() {
  143. err = errors.New("GetUserRecordListByMobileArr, Err: " + e.Error())
  144. return
  145. }
  146. openIdList := make([]*models.OpenIdList, 0)
  147. for _, vOpenid := range listOpenid {
  148. openIdItem := new(models.OpenIdList)
  149. openIdItem.OpenId = vOpenid.OpenId
  150. openIdItem.UserId = vOpenid.UserId
  151. openIdList = append(openIdList, openIdItem)
  152. }
  153. //var reserveResults string
  154. //var keyword2 string
  155. //reserveResults = "--"
  156. //keyword2 = "将在15分钟后开始"
  157. //SendWxMsgWithFrequency(keyword2, v.ActivityName, reserveResults, v.ActivityTimeText, "--", remark, openIdList, v.ActivityId)
  158. SendWxMsgWithFrequencyBycategory(v.ActivityName, v.ActivityTime, openIdList, v.ActivityId)
  159. }
  160. err = models.UpdateSendedMsgMeetingSendWxMsg(activityIds)
  161. return
  162. }
  163. // 预约外呼名单,会前1小时自动发送邮件给专家组
  164. func SendEmailFileToExpert(cont context.Context) (err error) {
  165. var msg string
  166. var touser string
  167. defer func() {
  168. if err != nil {
  169. fmt.Println("err:", err)
  170. go utils.SendAlarmMsg("预约外呼名单,会前1小时自动发送邮件给专家组失败"+err.Error()+msg, 2)
  171. }
  172. }()
  173. endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
  174. total, e := models.GetCountActivityIdToSendFile(endDate)
  175. if e != nil && e.Error() != utils.ErrNoRow() {
  176. err = errors.New("GetCountActivityIdToSendFile" + e.Error())
  177. return
  178. }
  179. if total == 0 {
  180. fmt.Println("发送附件完成0")
  181. return nil
  182. }
  183. listActivity, e := models.GetActivityIdToSendFile(endDate)
  184. if e != nil && e.Error() != utils.ErrNoRow() {
  185. err = errors.New("GetActivityIdToSendFile" + e.Error())
  186. return
  187. }
  188. if len(listActivity) == 0 {
  189. return
  190. }
  191. var activityIds []int
  192. for _, v := range listActivity {
  193. activityIds = append(activityIds, v.ActivityId)
  194. }
  195. for _, v := range listActivity {
  196. //time.Sleep(30 * time.Second) //延时30秒,避免邮件发送不成功
  197. activityInfo, e := models.GetAddActivityInfoById(v.ActivityId)
  198. if e != nil {
  199. err = errors.New("GetAddActivityInfoById" + e.Error())
  200. return
  201. }
  202. list, e := models.GetSignupExport(v.ActivityId)
  203. if e != nil {
  204. err = errors.New("GetSignupExport" + e.Error())
  205. return
  206. }
  207. var companyIds []int
  208. for _, vSin := range list {
  209. companyIds = append(companyIds, vSin.CompanyId)
  210. }
  211. sellNameMap := GetSellNameMapByCompanyIds(companyIds)
  212. //创建excel
  213. dir, errFile := os.Executable()
  214. exPath := filepath.Dir(dir)
  215. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
  216. xlsxFile := xlsx.NewFile()
  217. if errFile != nil {
  218. msg = "生成文件失败Err:" + errFile.Error()
  219. return
  220. }
  221. style := xlsx.NewStyle()
  222. alignment := xlsx.Alignment{
  223. Horizontal: "center",
  224. Vertical: "center",
  225. WrapText: true,
  226. }
  227. style.Alignment = alignment
  228. style.ApplyAlignment = true
  229. sheet, errFile := xlsxFile.AddSheet("外呼名单")
  230. if errFile != nil {
  231. msg = "新增Sheet失败,Err:" + errFile.Error()
  232. return
  233. }
  234. //设置宽度
  235. _ = sheet.SetColWidth(1, 1, 15)
  236. _ = sheet.SetColWidth(3, 3, 30)
  237. //标头
  238. rowTitle := sheet.AddRow()
  239. cellA := rowTitle.AddCell()
  240. cellA.Value = "姓名"
  241. cellB := rowTitle.AddCell()
  242. cellB.Value = "外呼号码"
  243. cellC := rowTitle.AddCell()
  244. cellC.Value = "国际代码"
  245. cellD := rowTitle.AddCell()
  246. cellD.Value = "公司名称"
  247. cellE := rowTitle.AddCell()
  248. cellE.Value = "所属销售"
  249. for _, item := range list {
  250. row := sheet.AddRow()
  251. cellA := row.AddCell()
  252. cellA.Value = item.RealName
  253. cellB := row.AddCell()
  254. cellB.Value = item.OutboundMobile
  255. cellC := row.AddCell()
  256. if item.CountryCode == "" {
  257. cellC.Value = "86"
  258. } else {
  259. cellC.Value = item.CountryCode
  260. }
  261. cellD := row.AddCell()
  262. cellD.Value = item.CompanyName
  263. cellE := row.AddCell()
  264. cellE.Value = sellNameMap[item.CompanyId]
  265. }
  266. errFile = xlsxFile.Save(downLoadnFilePath)
  267. if errFile != nil {
  268. msg = "保存文件失败Err:" + errFile.Error()
  269. return
  270. }
  271. title := activityInfo.ActivityName + "外呼名单"
  272. content := "外呼名单详情"
  273. fileName := downLoadnFilePath
  274. if activityInfo.ChartPermissionName == "科技" {
  275. touser = utils.EmailTechnology
  276. } else if activityInfo.ChartPermissionName == "医药" {
  277. touser = utils.EmailMedicine
  278. } else if activityInfo.ChartPermissionName == "消费" {
  279. touser = utils.EmailConsumption
  280. } else if activityInfo.ChartPermissionName == "智造" {
  281. touser = utils.EmailZhizao
  282. } else if activityInfo.ChartPermissionName == "策略" {
  283. touser = utils.EmailStrategy
  284. } else if strings.Contains(activityInfo.ChartPermissionName, "研选") {
  285. touser = utils.EmailExpert
  286. }
  287. sub := strings.Index(touser, ";")
  288. if sub >= 0 {
  289. spArr := strings.Split(touser, ";")
  290. for _, v := range spArr {
  291. utils.SendEmailByHongze(title, content, v, fileName, title+".xlsx")
  292. }
  293. }
  294. os.Remove(downLoadnFilePath)
  295. e = models.UPdateActivityIdToSendFile(v.ActivityId)
  296. if e != nil {
  297. go utils.SendAlarmMsg("UPdateActivityIdToSendFile err"+e.Error(), 2)
  298. }
  299. //sendResult := utils.SendEmailByHongze(title, content, touser, fileName, title+".xlsx")
  300. //if sendResult {
  301. // errFile = models.UPdateActivityIdToSendFile(v.ActivityId)
  302. // if errFile != nil {
  303. // msg = "获取失败,Err:" + errFile.Error()
  304. // return
  305. // }
  306. // os.Remove(downLoadnFilePath)
  307. //} else {
  308. // go utils.SendAlarmMsg("发送附件模版消息失败"+activityInfo.ActivityName, 2)
  309. // utils.FileLog.Info("发送附件模版消息失败,Err:%s", activityInfo.ActivityName)
  310. //}
  311. }
  312. return
  313. }
  314. func EditOutboundMobile(cont context.Context) (err error) {
  315. defer func() {
  316. if err != nil {
  317. fmt.Println("发送失败,Err:", err.Error())
  318. }
  319. }()
  320. list, err := models.GetActivitySignupListAll()
  321. if err != nil {
  322. fmt.Println("GetActivitySendMsgListAll Err:", err.Error())
  323. return
  324. }
  325. for _, v := range list {
  326. err = models.UPdateSignup(v)
  327. fmt.Println("修改:", strconv.Itoa(v.Id))
  328. if err != nil {
  329. fmt.Println("发送失败,Err:", err.Error()+strconv.Itoa(v.Id))
  330. }
  331. }
  332. fmt.Println("修改完成")
  333. return
  334. }
  335. // 同步用户绑定手机号以及区号
  336. func EditUserOutboundMobile(cont context.Context) (err error) {
  337. defer func() {
  338. if err != nil {
  339. fmt.Println("发送失败,Err:", err.Error())
  340. }
  341. }()
  342. list, err := models.GetUserListAll()
  343. if err != nil {
  344. fmt.Println("GetActivitySendMsgListAll Err:", err.Error())
  345. return
  346. }
  347. for _, v := range list {
  348. err = models.UPdateUserCountryCode(v)
  349. fmt.Println("修改:", strconv.Itoa(v.UserId))
  350. if err != nil {
  351. fmt.Println("发送失败,Err:", err.Error()+strconv.Itoa(v.UserId))
  352. }
  353. }
  354. fmt.Println("修改完成")
  355. return
  356. }
  357. // 获取 用户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户
  358. func GetUserType(companyId int) (userType int, permissionStrnew string, err error) {
  359. var permissionStr, permissionZhengShiStr string
  360. if companyId <= 1 {
  361. userType = 0
  362. } else {
  363. total, errs := models.GetCountCompanyDetailByIdGroup(companyId)
  364. if errs != nil {
  365. err = errs
  366. return
  367. }
  368. if total == 0 {
  369. userType = 0
  370. } else {
  371. companyDetail, errs := models.GetCompanyDetailByIdGroup(companyId)
  372. if errs != nil {
  373. err = errs
  374. return
  375. }
  376. permissionStr, errs = models.GetCompanyPermission(companyId)
  377. if errs != nil {
  378. err = errs
  379. return
  380. }
  381. permissionStrnew = permissionStr
  382. //大套餐客户,数据库添加标识,
  383. companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
  384. if errs != nil && errs.Error() != utils.ErrNoRow() {
  385. err = errs
  386. return
  387. }
  388. if companyUserTypeDetail != nil {
  389. if companyUserTypeDetail.CustomerTypeId != 0 {
  390. userType = companyUserTypeDetail.CustomerTypeId
  391. return
  392. }
  393. }
  394. permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
  395. if errs != nil {
  396. err = errs
  397. return
  398. }
  399. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
  400. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  401. if companyDetail.Status == "永续" {
  402. userType = 1
  403. } else if companyDetail.Status == "试用" {
  404. userType = 5
  405. } else if companyDetail.Status == "冻结" {
  406. userType = 6
  407. } else if companyDetail.Status == "流失" {
  408. userType = 7
  409. }
  410. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  411. if userType == 0 && companyDetail.Status == "正式" {
  412. var permissionZhegnshiNum int
  413. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  414. permissionZhegnshiNum++
  415. }
  416. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  417. permissionZhegnshiNum++
  418. }
  419. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  420. permissionZhegnshiNum++
  421. }
  422. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  423. permissionZhegnshiNum++
  424. }
  425. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  426. permissionZhegnshiNum++
  427. }
  428. if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
  429. permissionZhegnshiNum++
  430. }
  431. //if permissionZhegnshiNum == 6 {
  432. // userType = 2
  433. //} else
  434. //大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
  435. if permissionZhegnshiNum >= 4 {
  436. userType = 10
  437. } else {
  438. userType = 3
  439. }
  440. }
  441. }
  442. }
  443. permissionStrnew = permissionStr
  444. return
  445. }
  446. func GetUserTypeZhengShi(companyId int) (userType int, permissionStrnew, permissionStrZhengShinew string, err error) {
  447. var permissionStr, permissionZhengShiStr string
  448. if companyId <= 1 {
  449. userType = 0
  450. } else {
  451. total, errs := models.GetCountCompanyDetailByIdGroup(companyId)
  452. if errs != nil {
  453. err = errs
  454. return
  455. }
  456. if total == 0 {
  457. userType = 0
  458. } else {
  459. companyDetail, errs := models.GetCompanyDetailByIdGroup(companyId)
  460. if errs != nil {
  461. err = errs
  462. return
  463. }
  464. permissionStr, errs = models.GetCompanyPermission(companyId)
  465. if errs != nil {
  466. err = errs
  467. return
  468. }
  469. permissionStrnew = permissionStr
  470. permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
  471. if errs != nil {
  472. err = errs
  473. return
  474. }
  475. permissionStrZhengShinew = permissionZhengShiStr
  476. //大套餐客户,数据库添加标识,
  477. companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
  478. if errs != nil && errs.Error() != utils.ErrNoRow() {
  479. err = errs
  480. return
  481. }
  482. if companyUserTypeDetail != nil {
  483. if companyUserTypeDetail.CustomerTypeId != 0 {
  484. userType = companyUserTypeDetail.CustomerTypeId
  485. return
  486. }
  487. }
  488. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
  489. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  490. if companyDetail.Status == "永续" {
  491. userType = 1
  492. } else if companyDetail.Status == "试用" {
  493. userType = 5
  494. } else if companyDetail.Status == "冻结" {
  495. userType = 6
  496. } else if companyDetail.Status == "流失" {
  497. userType = 7
  498. }
  499. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  500. if userType == 0 && companyDetail.Status == "正式" {
  501. var permissionZhegnshiNum int
  502. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  503. permissionZhegnshiNum++
  504. }
  505. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  506. permissionZhegnshiNum++
  507. }
  508. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  509. permissionZhegnshiNum++
  510. }
  511. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  512. permissionZhegnshiNum++
  513. }
  514. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  515. permissionZhegnshiNum++
  516. }
  517. if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
  518. permissionZhegnshiNum++
  519. }
  520. //if permissionZhegnshiNum == 6 {
  521. // userType = 2
  522. //} else
  523. //大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
  524. if permissionZhegnshiNum >= 4 {
  525. userType = 10
  526. } else {
  527. userType = 3
  528. }
  529. }
  530. }
  531. }
  532. permissionStrnew = permissionStr
  533. permissionStrZhengShinew = permissionZhengShiStr
  534. return
  535. }
  536. // GetSpecialDetailUserPower 处理用户查看详情的权限
  537. func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.ActivityDetail) (havePower, isResearchSpecial bool, err error) {
  538. var companyDetailStatus string
  539. var userTypeStr string
  540. userId := user.UserId
  541. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  542. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  543. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityInfo.ActivityId] {
  544. isResearchSpecial = true
  545. }
  546. //如果是弘则的用户或者宏观的权限不做校验
  547. //if (GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID) || activityInfo.ChartPermissionName == utils.HONG_GUAN_NAME {
  548. if GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID {
  549. havePower = true
  550. return
  551. }
  552. userType, permissionStr, permissionStrZhengShi, e := GetUserTypeZhengShi(user.CompanyId)
  553. if e != nil {
  554. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  555. return
  556. }
  557. //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  558. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
  559. if mfyxUserPermissionTotal == 1 {
  560. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  561. }
  562. //如果正式权限有开通 研选扣点包 ,那么就拼接一个 研选订阅的权限
  563. if strings.Contains(permissionStrZhengShi, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
  564. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  565. permissionStrZhengShi += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  566. }
  567. //如果测试权限有开通 研选扣点包 ,那么就拼接一个 研选订阅的权限
  568. if strings.Contains(permissionStr, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
  569. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  570. }
  571. //如果一个权限都没有就返回无权限
  572. if permissionStr == "" {
  573. return
  574. }
  575. //永续客户,无法查看研选权限,但是下面的联系人,单独开通研选后,也可以查看研选内容
  576. if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && mfyxUserPermissionTotal == 0 {
  577. havePower = false
  578. return
  579. }
  580. permissionStr += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限
  581. if permissionStrZhengShi == "" {
  582. permissionStrZhengShi = utils.HONG_GUAN_NAME // 添加一个宏观权限
  583. } else {
  584. permissionStrZhengShi += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限
  585. }
  586. //如果是易董的活动,主、副权限有一个满足即可
  587. if activityInfo.YidongActivityId != "" {
  588. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) || strings.Contains(permissionStr, activityInfo.ChartPermissionNameDeputy) {
  589. havePower = true
  590. return
  591. }
  592. }
  593. //如果权限不包含那么直接返回
  594. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  595. return
  596. }
  597. //如果是 对用户的研选扣点的必须要有研选的正式权限
  598. if activityInfo.IsResearchPoints {
  599. //获取活动对用户要扣的点
  600. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  601. if e != nil {
  602. err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error())
  603. return
  604. }
  605. if userPointsNum > 0 {
  606. //if !strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_YANXUAN) {
  607. // //如果连试用权限都没有,那么久按照普通的研选样式展示
  608. // isResearchSpecial = false
  609. //}
  610. if !strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  611. havePower = false
  612. return
  613. }
  614. }
  615. }
  616. //处理决策人可见权限
  617. if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 {
  618. havePower = false
  619. return
  620. }
  621. // 处理本组可见权限
  622. if activityInfo.VisibleRange == 1 {
  623. //adminIds, e := models.GetSelleridWhichGroup(user.CompanyId, 2)
  624. //if e != nil {
  625. // err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
  626. // return
  627. //}
  628. adminIds := GetSelleridWhichGroup(user.CompanyId, 2, user.Mobile)
  629. haveVisibleRange := false
  630. adminIdSlice := strings.Split(adminIds, ",")
  631. for _, v := range adminIdSlice {
  632. if v == strconv.Itoa(activityInfo.AdminId) {
  633. haveVisibleRange = true
  634. }
  635. }
  636. if !haveVisibleRange {
  637. havePower = false
  638. return
  639. }
  640. }
  641. if permissionStr == "" {
  642. return
  643. }
  644. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  645. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  646. havePower = true
  647. return
  648. }
  649. //医药消费,科技,智造四大行业,验证主客观。如果主客观校验不通过,那么直接返回
  650. if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) {
  651. if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  652. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  653. havePower = true
  654. } else {
  655. havePower = false
  656. }
  657. } else {
  658. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  659. havePower = true
  660. } else {
  661. havePower = false
  662. }
  663. }
  664. if !havePower {
  665. return
  666. }
  667. }
  668. if activityInfo.LimitPeopleNum > 0 {
  669. mapUserType, e := GetActivityCcustomerTypeList()
  670. if e != nil {
  671. err = e
  672. return
  673. }
  674. userTypeStr = mapUserType[userType]
  675. // 永续客户、大套餐客户、30W套餐客户可以查看行业升级套餐客户 权限
  676. if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" {
  677. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  678. havePower = true
  679. //return
  680. }
  681. }
  682. } else {
  683. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  684. havePower = true
  685. return
  686. }
  687. }
  688. //判断管理规模是否满足
  689. companyProduct, e := models.GetCompanyProductDetail(user.CompanyId, 2)
  690. if e != nil {
  691. err = e
  692. return
  693. }
  694. if companyProduct != nil && activityInfo.Scale != "" {
  695. if strings.Contains(activityInfo.Scale, companyProduct.Scale) {
  696. havePower = true
  697. }
  698. }
  699. if user.CompanyId <= 1 {
  700. return
  701. } else {
  702. if permissionStr == "" {
  703. return
  704. } else {
  705. companyDetail, e := models.GetCompanyDetailById(user.CompanyId)
  706. if e != nil {
  707. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  708. return
  709. }
  710. if companyDetail == nil {
  711. err = errors.New("客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId))
  712. return
  713. }
  714. companyDetailStatus = companyDetail.Status
  715. }
  716. }
  717. //宏观满足用户可见身份验证权限既满足 2023-9-18
  718. if activityInfo.ChartPermissionId == 1 {
  719. if activityInfo.LimitPeopleNum > 0 {
  720. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  721. havePower = true
  722. return
  723. }
  724. } else {
  725. havePower = true
  726. return
  727. }
  728. }
  729. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == 0 {
  730. havePower = true
  731. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  732. havePower = true
  733. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  734. havePower = true
  735. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  736. havePower = true
  737. }
  738. //fmt.Println(permissionStrZhengShi)
  739. //if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  740. // havePower = true
  741. // return
  742. //}
  743. if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" {
  744. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  745. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  746. havePower = true
  747. return
  748. }
  749. } else {
  750. if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  751. havePower = true
  752. return
  753. }
  754. }
  755. }
  756. permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId)
  757. if errs != nil {
  758. err = errs
  759. return
  760. }
  761. //fmt.Println("主客观2", havePower)
  762. //if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  763. // havePower = true
  764. //}
  765. //fmt.Println("主客观3", havePower)
  766. //处理升级权限以及用户身份的 双重判断
  767. if activityInfo.CustomerTypeIds != "" {
  768. if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" {
  769. havePower = false
  770. if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  771. havePower = true
  772. }
  773. }
  774. }
  775. if havePower && activityInfo.LimitPeopleNum > 0 {
  776. //对于一些特殊的活动,即使权限满足也不给产看
  777. noPower, e := GetShareNoPowe(activityInfo, permissionStr, userType, user)
  778. if e != nil {
  779. err = errors.New("GetShareNoPowe, Err: " + e.Error())
  780. return
  781. }
  782. if noPower {
  783. havePower = false
  784. }
  785. }
  786. return
  787. }
  788. // 校验被分享的用户是否有查看详情的权限
  789. func GetShareNoPowe(activityInfo *models.ActivityDetail, permissionStr string, userType int, user *models.WxUserItem) (noPower bool, err error) {
  790. //如果是弘则的就不进行可见权限校验
  791. if user.CompanyId == utils.HZ_COMPANY_ID {
  792. return
  793. }
  794. //var noPower bool
  795. //if !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
  796. // noPower = true
  797. //}
  798. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  799. //if userType == 2 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  800. // noPower = true
  801. //}
  802. //if userType == 2 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  803. // noPower = true
  804. //}
  805. //if userType == 3 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  806. // noPower = true
  807. //}
  808. //if userType == 3 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  809. // noPower = true
  810. //}
  811. fmt.Println(userType)
  812. if userType == 8 {
  813. permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  814. if errs != nil {
  815. err = errs
  816. return
  817. }
  818. if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) {
  819. noPower = true
  820. return
  821. }
  822. }
  823. if !noPower {
  824. noPower, err = CheckUserPowerByActivityChoose(user, activityInfo)
  825. }
  826. return
  827. }
  828. // 处理活动本组们是否决策人权限
  829. func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *models.ActivityDetail) (noPower bool, err error) {
  830. //处理 见范围 1,仅本组可见 、2,全部客户可见
  831. if activityInfo.VisibleRange == 1 {
  832. //adminIds, errAdmin := models.GetSelleridWhichGroup(user.CompanyId, 2)
  833. //if errAdmin != nil {
  834. // err = errAdmin
  835. // return
  836. //}
  837. adminIds := GetSelleridWhichGroup(user.CompanyId, 2, user.Mobile)
  838. sliceAdminIds := strings.Split(adminIds, ",")
  839. var haveAdminId bool
  840. for _, v := range sliceAdminIds {
  841. if v == strconv.Itoa(activityInfo.AdminId) {
  842. haveAdminId = true
  843. }
  844. }
  845. if !haveAdminId {
  846. noPower = true
  847. }
  848. }
  849. //处理 是否仅决策人可见 0,否 、1,是
  850. if activityInfo.IsMakerShow == 1 {
  851. if user.IsMaker == 0 {
  852. noPower = true
  853. }
  854. }
  855. return
  856. }
  857. // 校验用户报名的权限
  858. func GetHavePower(activityInfo *models.ActivityDetail, permissionStr, companyDetailStatus string, userType int) (havePower bool, err error) {
  859. // 查研观向7.4-宏观活动不作权限限制
  860. if activityInfo.ChartPermissionId == 1 {
  861. havePower = true
  862. return
  863. }
  864. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == 0 {
  865. havePower = true
  866. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  867. havePower = true
  868. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  869. havePower = true
  870. //} else if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
  871. // havePower = true
  872. //} else if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  873. // havePower = true
  874. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  875. havePower = true
  876. }
  877. if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  878. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  879. havePower = true
  880. }
  881. } else {
  882. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  883. havePower = true
  884. }
  885. }
  886. if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  887. havePower = true
  888. }
  889. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  890. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  891. havePower = true
  892. }
  893. return
  894. }
  895. // 获取活动列表查询权限的SQL
  896. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  897. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  898. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  899. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  900. // @Param IsPower query int false "是否选择有权限行业 ,1是 0 否 默认0"
  901. // @Param Label query string false "搜索主题 多个用 , 隔开"
  902. // @Param PlayBack query int false "是否仅展示回放 1:是、0:否 默认0"
  903. // @Param KeyWord query string false "搜索关键词 多个用 , 隔开"
  904. // @Param ikType query int false "联想词类型 , 1不做联想,2,做除初始词的联想,3所有联想"
  905. func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermissionIds, whichDay, activeState, label string, isPower, source int, keyWord string, playBack, ikType int) (conditionActivity string, err error) {
  906. keyWordNoIk := keyWord
  907. //adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
  908. //if err != nil {
  909. // return
  910. //}
  911. adminIds := GetSelleridWhichGroup(user.CompanyId, 2, user.Mobile)
  912. userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
  913. if err != nil {
  914. return
  915. }
  916. //判断客户规模是否属于可见范围的活动
  917. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  918. if err != nil && err.Error() != utils.ErrNoRow() {
  919. return
  920. }
  921. isMaker := user.IsMaker
  922. slicePer := strings.Split(permissionStr, ",")
  923. var permissionSqlStr string
  924. var permissionNameStr string
  925. for _, v := range slicePer {
  926. if userType == 1 {
  927. //研选权限处理
  928. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  929. permissionNameStr += "'" + v + "',"
  930. }
  931. } else {
  932. permissionNameStr += "'" + v + "',"
  933. }
  934. }
  935. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  936. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  937. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  938. slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
  939. var permissionNameStrZhengShi string
  940. for _, v := range slicePerZhengShi {
  941. if userType == 1 {
  942. //研选权限处理
  943. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  944. permissionNameStrZhengShi += "'" + v + "',"
  945. }
  946. } else {
  947. permissionNameStrZhengShi += "'" + v + "',"
  948. }
  949. }
  950. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
  951. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
  952. permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
  953. mapUserType, e := GetActivityCcustomerTypeList()
  954. if e != nil {
  955. err = e
  956. return
  957. }
  958. var userTypeStr string
  959. userTypeStr = mapUserType[userType]
  960. // 查研观向7.4-始终查询宏观的权限(无论是否有权限)
  961. if permissionNameStr == `` {
  962. permissionNameStr = `'宏观'`
  963. } else {
  964. permissionNameStr += `, '宏观'`
  965. }
  966. var condition string
  967. var conditionAdmin string
  968. var conditionHz string // 弘则权限处理
  969. var sqlExport string // 专家权限处理
  970. //permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  971. sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  972. //if userType == 2 {
  973. // sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  974. //}
  975. //if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  976. // sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  977. //}
  978. sqlExport += `) `
  979. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  980. if activityTypeId != "" {
  981. if activityTypeId == strconv.Itoa(utils.ANALYST_TELL_ACTIVITY_TYPE_ID) {
  982. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id IN (` + activityTypeId + "," + strconv.Itoa(utils.C_CLASS_ACTIVITY_TYPE_ID) + `)`
  983. } else {
  984. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id IN (` + activityTypeId + `)`
  985. }
  986. }
  987. //主题
  988. if label != "" {
  989. condition = ` AND art.label LIKE "%` + label + `%" `
  990. }
  991. if isPower == 1 {
  992. condition += permissionSqlStr
  993. }
  994. //行业名称
  995. if len(chartPermissionIds) > 0 {
  996. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  997. }
  998. //如果是PC的,则不看易董的
  999. if source == 1 {
  1000. condition += ` AND art.yidong_activity_id = '' `
  1001. }
  1002. var conditionOr string
  1003. if whichDay != "" {
  1004. var startDate string
  1005. var endDate string
  1006. if whichDay == "1" {
  1007. startDate = time.Now().Format(utils.FormatDate)
  1008. endDate = startDate
  1009. } else if whichDay == "2" {
  1010. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1011. endDate = startDate
  1012. } else if whichDay == "3" {
  1013. startDate = utils.GetNowWeekMonday().Format(utils.FormatDate)
  1014. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  1015. } else if whichDay == "4" {
  1016. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  1017. endDate = utils.GetLastWeekSunday().Format(utils.FormatDate)
  1018. } else if whichDay == "5" {
  1019. startDate = utils.GetNowMonthFirstDay().Format(utils.FormatDate)
  1020. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  1021. } else if whichDay == "6" {
  1022. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  1023. endDate = utils.GetLastMonthLastDay().Format(utils.FormatDate)
  1024. } else if whichDay == "1,2" {
  1025. startDate = time.Now().Format(utils.FormatDate)
  1026. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1027. } else if whichDay == "3,4" {
  1028. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  1029. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  1030. } else if whichDay == "5,6" {
  1031. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  1032. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  1033. } else {
  1034. startDate = time.Now().Format(utils.FormatDate)
  1035. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1036. }
  1037. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  1038. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  1039. }
  1040. //有搜索条件传过来时,不判进行状态条件
  1041. if keyWord != "" {
  1042. if ikType == 2 || ikType == 3 {
  1043. keyWordArr, e := GetIndustryMapNameSliceV3(keyWord)
  1044. if e != nil {
  1045. err = errors.New("获取分词失败,GetIndustryMapNameSliceV3, Err: " + keyWord + e.Error())
  1046. return
  1047. }
  1048. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  1049. //var keywords string
  1050. if len(keyWordArr) > 1 {
  1051. if ikType == 2 {
  1052. keyWord = KeyWordArrSqlRegexp(keyWordArr)
  1053. condition += ` AND (art.label NOT LIKE '%` + keyWordNoIk + `%' AND art.activity_name NOT LIKE '%` + keyWordNoIk + `%' ) `
  1054. } else if ikType == 3 {
  1055. keyWord = KeyWordArrSqlRegexpAll(keyWordArr)
  1056. }
  1057. }
  1058. }
  1059. condition += ` AND (art.label REGEXP '` + keyWord + `' OR art.activity_name REGEXP '` + keyWord + `' ) `
  1060. } else {
  1061. if activeState != "" {
  1062. // 默认查看未开始跟进行中
  1063. if activeState == "1" {
  1064. condition += ` AND art.active_state IN (1,2)`
  1065. } else {
  1066. condition += ` AND art.active_state IN (` + activeState + `)`
  1067. }
  1068. } else {
  1069. condition += ` AND art.active_state IN (1,2)`
  1070. }
  1071. }
  1072. if playBack == 1 {
  1073. var pars []interface{}
  1074. ativityVIdArry := make([]string, 0)
  1075. voiceList, e := models.GetActivityVoiceListAll("", pars, 0, 1000)
  1076. if e != nil && e.Error() != utils.ErrNoRow() {
  1077. err = e
  1078. return
  1079. }
  1080. for _, v := range voiceList {
  1081. ativityVIdArry = append(ativityVIdArry, strconv.Itoa(v.ActivityId))
  1082. }
  1083. videoList, e := models.GetActivityVideoListAll("", pars, 0, 1000)
  1084. if e != nil && e.Error() != utils.ErrNoRow() {
  1085. err = e
  1086. return
  1087. }
  1088. for _, v := range videoList {
  1089. ativityVIdArry = append(ativityVIdArry, strconv.Itoa(v.ActivityId))
  1090. }
  1091. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  1092. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  1093. //condition += ` AND art.activity_time > '` + endTime + `' `
  1094. if len(ativityVIdArry) > 0 {
  1095. ativityVIdstr := strings.Join(ativityVIdArry, ",")
  1096. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  1097. } else {
  1098. condition += ` AND art.activity_id = 0 `
  1099. }
  1100. }
  1101. //查询全部可见的数据(是否全部客户可见)
  1102. //condition += ` AND art.visible_range != 1 AND art.publish_status = 1 `
  1103. condition += ` AND art.publish_status = 1 `
  1104. if adminIds == "" {
  1105. //condition += ` AND art.visible_range != 1 `
  1106. } else {
  1107. condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  1108. }
  1109. conditionHz = condition
  1110. //活动仅决策人可见
  1111. if isMaker == 0 {
  1112. condition += ` AND art.is_maker_show = 0 `
  1113. }
  1114. conditionAdmin = condition + ` AND art.visible_range = 1 `
  1115. //condition += ` AND art.visible_range != 1 `
  1116. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1117. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1118. }
  1119. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1120. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1121. }
  1122. if userType == 1 {
  1123. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1124. } else {
  1125. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1126. }
  1127. if userType == 6 || userType == 7 {
  1128. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
  1129. }
  1130. if companyProduct != nil {
  1131. if companyProduct.Scale != "" {
  1132. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  1133. }
  1134. }
  1135. if adminIds != "" {
  1136. if userType == 3 {
  1137. conditionAdmin += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  1138. }
  1139. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + userTypeStr + `%' ` + ` AND art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) `
  1140. if companyProduct != nil {
  1141. if companyProduct.Scale != "" {
  1142. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%'` + ` AND art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) `
  1143. }
  1144. }
  1145. }
  1146. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  1147. if e != nil {
  1148. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  1149. return
  1150. }
  1151. if conditionShengji != "" {
  1152. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) `
  1153. }
  1154. if conditionZhengshi != "" {
  1155. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) `
  1156. }
  1157. if conditionHangYe != "" {
  1158. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) `
  1159. }
  1160. //弘则研究下的客户不做权限,限制,C类电话会,仅本组销售、部门管理员、admin、权益研究员账号能看到
  1161. if user.CompanyId == utils.HZ_COMPANY_ID {
  1162. mapMobile, e := GetAdminMobileMap()
  1163. if e != nil {
  1164. err = e
  1165. return
  1166. }
  1167. if _, ok := mapMobile[user.Mobile]; ok {
  1168. conditionOr += ` OR ( art.publish_status = 1 ` + conditionHz + `) `
  1169. }
  1170. }
  1171. if userType == 3 {
  1172. condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  1173. }
  1174. conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
  1175. return
  1176. }
  1177. // 根据用户身份处理活动可见
  1178. func ActivityConditioninitSql(user *models.WxUserItem, condition string, isPower int) (conditionActivity string, err error) {
  1179. //未登录的用户也可以查看所有活动v12.2.1
  1180. if user.UserId == 0 {
  1181. conditionActivity = ` AND art.publish_status = 1 AND art.yidong_activity_id = '' ` + condition
  1182. return
  1183. }
  1184. // cygx_10.9 未绑定联系方式的客户可以看到部分活动
  1185. if user.UserId == 0 || user.CompanyId == 1 {
  1186. conditionActivity = ` AND art.publish_status = 1 AND art.visible_range != 1 AND (art.is_limit_people = 0 OR (art.is_limit_people=1 AND art.is_all_customer_type=1)) ` + condition
  1187. return
  1188. }
  1189. condition += ` AND art.publish_status = 1 `
  1190. conditionActivity = condition
  1191. //弘则可以查看所有活动
  1192. if (GetBelongingRaiIt(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID) || user.UserId == 0 {
  1193. return
  1194. }
  1195. //adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
  1196. //if err != nil {
  1197. // return
  1198. //}
  1199. adminIds := GetSelleridWhichGroup(user.CompanyId, 2, user.Mobile)
  1200. userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
  1201. if err != nil {
  1202. return
  1203. }
  1204. //判断客户规模是否属于可见范围的活动
  1205. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  1206. if err != nil && err.Error() != utils.ErrNoRow() {
  1207. return
  1208. }
  1209. isMaker := user.IsMaker
  1210. slicePer := strings.Split(permissionStr, ",")
  1211. var permissionSqlStr string
  1212. var permissionNameStr string
  1213. for _, v := range slicePer {
  1214. if userType == 1 {
  1215. //研选权限处理
  1216. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  1217. permissionNameStr += "'" + v + "',"
  1218. }
  1219. } else {
  1220. permissionNameStr += "'" + v + "',"
  1221. }
  1222. }
  1223. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  1224. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  1225. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  1226. slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
  1227. var permissionNameStrZhengShi string
  1228. for _, v := range slicePerZhengShi {
  1229. if userType == 1 {
  1230. //研选权限处理
  1231. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  1232. permissionNameStrZhengShi += "'" + v + "',"
  1233. }
  1234. } else {
  1235. permissionNameStrZhengShi += "'" + v + "',"
  1236. }
  1237. }
  1238. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
  1239. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
  1240. permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
  1241. mapUserType, e := GetActivityCcustomerTypeList()
  1242. if e != nil {
  1243. err = e
  1244. return
  1245. }
  1246. var userTypeStr string
  1247. userTypeStr = mapUserType[userType]
  1248. // 查研观向7.4-始终查询宏观的权限(无论是否有权限)
  1249. if permissionNameStr == `` {
  1250. permissionNameStr = `'宏观'`
  1251. } else {
  1252. permissionNameStr += `, '宏观'`
  1253. }
  1254. var sqlExport string // 专家权限处理
  1255. sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  1256. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  1257. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  1258. }
  1259. sqlExport += `) `
  1260. if isPower == 1 {
  1261. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  1262. condition += permissionSqlStr
  1263. }
  1264. var conditionOr string
  1265. //查询全部可见的数据(是否全部客户可见)
  1266. if adminIds != "" {
  1267. condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  1268. }
  1269. //活动仅决策人可见
  1270. if isMaker == 0 {
  1271. condition += ` AND art.is_maker_show = 0 `
  1272. }
  1273. //condition += ` AND art.visible_range != 1 `
  1274. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1275. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1276. }
  1277. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1278. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1279. }
  1280. if userType == 1 {
  1281. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1282. } else {
  1283. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1284. }
  1285. if userType == 6 || userType == 7 {
  1286. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
  1287. }
  1288. if companyProduct != nil {
  1289. if companyProduct.Scale != "" {
  1290. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  1291. }
  1292. }
  1293. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  1294. if e != nil {
  1295. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  1296. return
  1297. }
  1298. // 升级客户可查看范围
  1299. if conditionShengji != "" {
  1300. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) `
  1301. }
  1302. // 正式客户可查看范围
  1303. if conditionZhengshi != "" {
  1304. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) `
  1305. }
  1306. // 行业客户可查看范围
  1307. if conditionHangYe != "" {
  1308. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) `
  1309. }
  1310. if userType == 3 {
  1311. condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  1312. }
  1313. condition += ` AND art.is_limit_people = 1 `
  1314. conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
  1315. return
  1316. }
  1317. // 研选系列专家电话会,会前1小时将问题列表发送给邮箱
  1318. func SendEmailFileForAskMsgResearch(cont context.Context) (err error) {
  1319. var msg string
  1320. //var touser string
  1321. defer func() {
  1322. if err != nil {
  1323. go utils.SendAlarmMsg("发送附件模版消息失败", 2)
  1324. go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  1325. }
  1326. if msg != "" {
  1327. go utils.SendAlarmMsg(msg, 2)
  1328. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1329. }
  1330. }()
  1331. endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
  1332. condition := `AND a.activity_type_id = 1 AND a.chart_permission_id = 31 `
  1333. total, err := models.GetCountActivityResearchToSendFile(condition, endDate)
  1334. if total == 0 {
  1335. fmt.Println("发送附件完成0")
  1336. return nil
  1337. }
  1338. if err != nil {
  1339. msg = "发送附件模版消息失败 Err:" + err.Error()
  1340. return
  1341. }
  1342. listActivity, err := models.GetActivityResearchToSendFile(condition, endDate)
  1343. if err != nil {
  1344. msg = "发送附件模版消息失败 Err:" + err.Error()
  1345. return
  1346. }
  1347. for _, v := range listActivity {
  1348. activityInfo, _ := models.GetAddActivityInfoById(v.ActivityId)
  1349. if activityInfo == nil {
  1350. msg = "活动不存在,Err:activityId:" + strconv.Itoa(v.ActivityId)
  1351. return
  1352. }
  1353. list, errFile := models.GetActivityMsgExport(v.ActivityId)
  1354. if errFile != nil {
  1355. msg = "获取失败,Err:" + errFile.Error()
  1356. return
  1357. }
  1358. for _, v2 := range list {
  1359. user, e := models.GetWxUserItemByUserId(v2.UserId)
  1360. if e != nil && e.Error() != utils.ErrNoRow() {
  1361. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  1362. return err
  1363. }
  1364. //获取销售信息
  1365. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(v2.CompanyId, 2)
  1366. if e != nil && e.Error() != utils.ErrNoRow() {
  1367. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  1368. return
  1369. }
  1370. //如果是研选的就推送给汪洋
  1371. cnf, e := models.GetConfigByCode(utils.TPL_MSG_WANG_YANG)
  1372. if e != nil {
  1373. err = errors.New("GetConfigByCode, Err: " + e.Error())
  1374. return
  1375. }
  1376. //给汪洋推送消息
  1377. if sellerItem != nil {
  1378. openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  1379. if openIpItem != nil && openIpItem.OpenId != "" {
  1380. SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
  1381. }
  1382. }
  1383. //给所属销售推送消息
  1384. if sellerItem != nil {
  1385. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  1386. if openIpItem != nil && openIpItem.OpenId != "" {
  1387. SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
  1388. }
  1389. }
  1390. }
  1391. errFile = models.UPdateActivityMsgToSendFile(v.ActivityId)
  1392. if errFile != nil {
  1393. msg = "获取失败,Err:" + errFile.Error()
  1394. return
  1395. }
  1396. }
  1397. return
  1398. }
  1399. // 非研选系列专家电话会,根据主持人姓名,会前15分钟将问题列表发送给至该主持人对应邮箱
  1400. func SendEmailFileForAskMsg(cont context.Context) (err error) {
  1401. var msg string
  1402. //var touser string
  1403. defer func() {
  1404. if err != nil {
  1405. go utils.SendAlarmMsg("发送附件模版消息失败", 2)
  1406. go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  1407. }
  1408. if msg != "" {
  1409. go utils.SendAlarmMsg(msg, 2)
  1410. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1411. }
  1412. }()
  1413. endDate := time.Now().Add(+time.Minute * 15).Format(utils.FormatDateTime)
  1414. condition := `AND a.activity_type_id = 1 AND a.chart_permission_id != 31 `
  1415. total, err := models.GetCountActivityResearchToSendFile(condition, endDate)
  1416. if total == 0 {
  1417. fmt.Println("发送附件完成0")
  1418. return nil
  1419. }
  1420. if err != nil {
  1421. msg = "发送附件模版消息失败 Err:" + err.Error()
  1422. return
  1423. }
  1424. listActivity, err := models.GetActivityResearchToSendFile(condition, endDate)
  1425. if err != nil {
  1426. msg = "发送附件模版消息失败 Err:" + err.Error()
  1427. return
  1428. }
  1429. listEmail, errEmail := models.GetAskEmail()
  1430. if errEmail != nil {
  1431. msg = "获取失败,Err:" + errEmail.Error()
  1432. return
  1433. }
  1434. for _, v := range listActivity {
  1435. activityInfo, _ := models.GetAddActivityInfoById(v.ActivityId)
  1436. if activityInfo == nil {
  1437. msg = "活动不存在,Err:activityId:" + strconv.Itoa(v.ActivityId)
  1438. return
  1439. }
  1440. list, errFile := models.GetActivityMsgExport(v.ActivityId)
  1441. if errFile != nil {
  1442. msg = "获取失败,Err:" + errFile.Error()
  1443. return
  1444. }
  1445. for _, v2 := range list {
  1446. user, err := models.GetWxUserItemByUserId(v2.UserId)
  1447. if err != nil && err.Error() != utils.ErrNoRow() {
  1448. return err
  1449. }
  1450. var sendMobile string
  1451. for _, vEmail := range listEmail {
  1452. if strings.Index(activityInfo.Host, vEmail.Name) > 0 {
  1453. sendMobile = vEmail.Mobile
  1454. }
  1455. }
  1456. //获取销售信息
  1457. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(v2.CompanyId, 2)
  1458. if err != nil && err.Error() != utils.ErrNoRow() {
  1459. return err
  1460. }
  1461. //给研究员推送模板消息
  1462. if sellerItem != nil {
  1463. openIpItem, _ := models.GetUserRecordByMobile(4, sendMobile)
  1464. if openIpItem != nil && openIpItem.OpenId != "" {
  1465. //SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", v2.CreateTime, v2.Content, activityInfo.ActivityName, activityInfo.ActivityId, openIpItem)
  1466. //SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName, "所属销售:"+sellerItem.RealName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo)
  1467. SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
  1468. }
  1469. }
  1470. //给销售推送模板消息
  1471. if sellerItem != nil {
  1472. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  1473. if openIpItem != nil && openIpItem.OpenId != "" {
  1474. //SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", v2.CreateTime, v2.Content, activityInfo.ActivityName, activityInfo.ActivityId, openIpItem)
  1475. //SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName, "所属销售:"+sellerItem.RealName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo)
  1476. SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
  1477. }
  1478. }
  1479. }
  1480. errFile = models.UPdateActivityMsgToSendFile(v.ActivityId)
  1481. if errFile != nil {
  1482. msg = "获取失败,Err:" + errFile.Error()
  1483. return
  1484. }
  1485. }
  1486. return
  1487. }
  1488. // 活动标签字符串处理
  1489. func LabelStr(label string) (labelNew string) {
  1490. slicebr := strings.Split(label, "-")
  1491. if len(slicebr) < 2 {
  1492. labelNew = label
  1493. } else {
  1494. labelNew = slicebr[1]
  1495. }
  1496. return labelNew
  1497. }
  1498. // 5.3版本活动标签字符串处理
  1499. func LabelStrV5(label string, isShowSubjectName int, temporaryLabel string) (labelNew string) {
  1500. slicebr := strings.Split(label, "-")
  1501. if len(slicebr) > 1 {
  1502. if isShowSubjectName == 1 {
  1503. labelNew = slicebr[1]
  1504. } else {
  1505. labelNew = slicebr[0]
  1506. }
  1507. } else {
  1508. labelNew = label
  1509. }
  1510. if temporaryLabel != "" {
  1511. labelNew = temporaryLabel
  1512. }
  1513. return labelNew
  1514. }
  1515. func ActivityAttendanceDetail(cont context.Context) (err error) {
  1516. defer func() {
  1517. if err != nil {
  1518. fmt.Println("ActivityAttendanceDetail Err:" + err.Error())
  1519. go utils.SendAlarmMsg("同步进门财经数据失败", 2)
  1520. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ActivityAttendanceDetail ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1521. }
  1522. }()
  1523. configCode := "jin_meng_activity_id"
  1524. detail, err := models.GetConfigByCode(configCode)
  1525. if err != nil {
  1526. return err
  1527. }
  1528. fmt.Println(detail.ConfigValue)
  1529. mapActivityId := make(map[string]string)
  1530. sliceValue := strings.Split(detail.ConfigValue, ",")
  1531. for _, v := range sliceValue {
  1532. mapActivityId[v] = v
  1533. }
  1534. var activityIds string
  1535. var activityIdsLongTime string //可回放的会议,到会详情持续更新加入到不做14天限制的活动中
  1536. fmt.Println("开始同步")
  1537. dateTime := time.Now().AddDate(0, 0, -7).Format(utils.FormatDate)
  1538. dateNow := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  1539. startDate := dateTime + " 00:00:00"
  1540. endDate := dateNow + " 23:59:59"
  1541. //获取进门财经需要处理的活动
  1542. listActivityRoadshow, err := models.GetRoadshowDataListByDateTime(startDate, endDate)
  1543. if err != nil {
  1544. fmt.Println("GetRoadshowDataListByDateTime Err:", err.Error())
  1545. return err
  1546. }
  1547. for _, vAct := range listActivityRoadshow {
  1548. doTime := utils.TimeRemoveHms2(vAct.RoadshowBeginTime)
  1549. findStartDate := doTime + " 00:00:00"
  1550. findEndDate := doTime + " 23:59:59"
  1551. var roadshowTitle string
  1552. roadshowTitle = vAct.RoadshowTitle
  1553. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, "【", "", -1)
  1554. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, "】", "", -1)
  1555. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, " ", "", -1)
  1556. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, "-", "", -1)
  1557. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, ":", "", -1)
  1558. nameSlice := strings.Split(vAct.RoadshowTitle, "|")
  1559. //fmt.Println(timeSlice[0])
  1560. //对于手动匹配到的活动数据也要更新
  1561. var activityName string
  1562. if len(nameSlice) >= 1 {
  1563. //if vAct.JmcjRoadshowTitle != "" {
  1564. // activityName = vAct.JmcjRoadshowTitle
  1565. //} else {
  1566. // activityName = nameSlice[len(nameSlice)-1]
  1567. //}
  1568. activityName = nameSlice[len(nameSlice)-1]
  1569. if activityName != "" {
  1570. //通过名称去找匹配的活动
  1571. activityDetail, _ := models.GetAddActivityInfoByTitle(activityName, findStartDate, findEndDate)
  1572. if activityDetail == nil {
  1573. continue
  1574. } else {
  1575. activityIds += strconv.Itoa(activityDetail.ActivityId) + ","
  1576. }
  1577. list, err := models.GetRoadshowDataList(roadshowTitle, findStartDate, findEndDate)
  1578. if err != nil {
  1579. fmt.Println("GetTacticsList Err:", err.Error())
  1580. return err
  1581. }
  1582. var isPlayback bool // 是否包含回放
  1583. needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
  1584. var mobileStr string
  1585. var mobileArr []string
  1586. if len(list) > 0 {
  1587. fmt.Println("原来的", vAct.RoadshowTitle)
  1588. fmt.Println("处理的", activityName)
  1589. for _, v := range list {
  1590. if v.UserPhone != "" {
  1591. item := new(models.CygxActivityAttendanceDetail)
  1592. item.ActivityId = activityDetail.ActivityId
  1593. item.RealName = v.UserName
  1594. item.Mobile = v.UserPhone
  1595. item.CompanyName = v.Company
  1596. //item.SellerName = sellerName
  1597. item.FirstMeetingTime = v.FirstWatchTime
  1598. item.LastMeetingTime = v.LastWatchTime
  1599. item.Duration = utils.GetAttendanceDetailSeconds(v.JoinTime)
  1600. if v.JoinType == 1 {
  1601. item.MeetingTypeStr = "网络"
  1602. } else {
  1603. item.MeetingTypeStr = "电话"
  1604. }
  1605. item.MeetingAuthentication = v.AuthInfo
  1606. if v.DataType == 1 {
  1607. item.MeetingStatusStr = "直播"
  1608. } else {
  1609. item.MeetingStatusStr = "回放"
  1610. isPlayback = true
  1611. }
  1612. item.Position = v.Occupation
  1613. item.UseridEntity = v.UseridEntity
  1614. item.ActivityTime = activityDetail.ActivityTime
  1615. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  1616. item.CreateTime = time.Now()
  1617. mobileStr += "'" + v.UserPhone + "'" + ","
  1618. mobileArr = append(mobileArr, v.UserPhone)
  1619. needAddAttendanc = append(needAddAttendanc, item)
  1620. }
  1621. }
  1622. if isPlayback && mapActivityId[strconv.Itoa(activityDetail.ActivityId)] == "" {
  1623. activityIdsLongTime += strconv.Itoa(activityDetail.ActivityId) + ","
  1624. }
  1625. mobileStr = strings.TrimRight(mobileStr, ",")
  1626. if mobileStr == "" {
  1627. mobileStr = "1"
  1628. }
  1629. listUser, err := models.GetWxUserOutboundMobile(mobileStr)
  1630. if err != nil {
  1631. fmt.Println("GetWxUserOutboundMobile Err:", err.Error())
  1632. return err
  1633. }
  1634. for k, v := range needAddAttendanc {
  1635. for _, v2 := range listUser {
  1636. if v2.OutboundMobile == v.Mobile || v2.Mobile == v.Mobile {
  1637. if needAddAttendanc[k].CompanyId == 0 {
  1638. needAddAttendanc[k].CompanyId = v2.CompanyId
  1639. needAddAttendanc[k].SellerName = v2.SellerName
  1640. needAddAttendanc[k].CompanyName = v2.CompanyName
  1641. needAddAttendanc[k].IsMeetingStr = 1
  1642. }
  1643. }
  1644. }
  1645. }
  1646. //fmt.Println(mobileStr)
  1647. //参会记录
  1648. err = models.AddAttendancDetail(needAddAttendanc, activityDetail.ActivityId, mobileStr)
  1649. if err != nil {
  1650. fmt.Println("AddAttendancDetail Err:", err.Error())
  1651. return err
  1652. }
  1653. ////处理是否限制报名
  1654. err = AddCygxActivityRestrictSignupByAdmin(activityDetail.ActivityId)
  1655. if err != nil {
  1656. fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
  1657. return err
  1658. }
  1659. go ActivityUserLabelLogAdd(activityDetail.ActivityId, mobileArr)
  1660. AddctivitySignupDetailByJmcj(needAddAttendanc, activityDetail.ActivityId)
  1661. }
  1662. }
  1663. }
  1664. }
  1665. //获取需要处理的活动
  1666. listActivity, err := models.GetActivityListByDateTime(startDate, endDate, activityIds, detail.ConfigValue)
  1667. if err != nil {
  1668. fmt.Println("GetTacticsList Err:", err.Error())
  1669. return err
  1670. }
  1671. //通过本地去找进门财经的数据
  1672. for _, vAct := range listActivity {
  1673. doTime := utils.TimeRemoveHms2(vAct.ActivityTime)
  1674. findStartDate := doTime + " 00:00:00"
  1675. findEndDate := doTime + " 23:59:59"
  1676. nameSlice := strings.Split(vAct.ActivityName, "】")
  1677. //对于手动匹配到的活动数据也要更新
  1678. var activityName string
  1679. if len(nameSlice) > 1 {
  1680. if vAct.JmcjRoadshowTitle != "" {
  1681. activityName = vAct.JmcjRoadshowTitle
  1682. } else {
  1683. activityName = nameSlice[len(nameSlice)-1]
  1684. }
  1685. //activityName = nameSlice[len(nameSlice)-1]
  1686. if activityName != "" {
  1687. list, err := models.GetRoadshowDataList(activityName, findStartDate, findEndDate)
  1688. if err != nil {
  1689. fmt.Println("GetTacticsList Err:", err.Error())
  1690. return err
  1691. }
  1692. var isPlayback bool // 是否包含回放
  1693. needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
  1694. var mobileStr string
  1695. var mobileArr []string
  1696. if len(list) > 0 {
  1697. fmt.Println("原来的1", vAct.ActivityName)
  1698. fmt.Println("处理的2", activityName)
  1699. for _, v := range list {
  1700. if v.UserPhone != "" {
  1701. item := new(models.CygxActivityAttendanceDetail)
  1702. item.ActivityId = vAct.ActivityId
  1703. item.RealName = v.UserName
  1704. item.Mobile = v.UserPhone
  1705. item.CompanyName = v.Company
  1706. //item.SellerName = sellerName
  1707. item.FirstMeetingTime = v.FirstWatchTime
  1708. item.LastMeetingTime = v.LastWatchTime
  1709. item.Duration = utils.GetAttendanceDetailSeconds(v.JoinTime)
  1710. if v.JoinType == 1 {
  1711. item.MeetingTypeStr = "网络"
  1712. } else {
  1713. item.MeetingTypeStr = "电话"
  1714. }
  1715. item.MeetingAuthentication = v.AuthInfo
  1716. if v.DataType == 1 {
  1717. item.MeetingStatusStr = "直播"
  1718. } else {
  1719. item.MeetingStatusStr = "回放"
  1720. isPlayback = true
  1721. }
  1722. item.Position = v.Occupation
  1723. item.UseridEntity = v.UseridEntity
  1724. item.ActivityTime = vAct.ActivityTime
  1725. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  1726. item.CreateTime = time.Now()
  1727. mobileStr += "'" + v.UserPhone + "'" + ","
  1728. mobileArr = append(mobileArr, v.UserPhone)
  1729. needAddAttendanc = append(needAddAttendanc, item)
  1730. }
  1731. }
  1732. if isPlayback && mapActivityId[strconv.Itoa(vAct.ActivityId)] == "" {
  1733. activityIdsLongTime += strconv.Itoa(vAct.ActivityId) + ","
  1734. }
  1735. mobileStr = strings.TrimRight(mobileStr, ",")
  1736. if mobileStr == "" {
  1737. mobileStr = "1"
  1738. }
  1739. listUser, err := models.GetWxUserOutboundMobile(mobileStr)
  1740. if err != nil {
  1741. fmt.Println("GetWxUserOutboundMobile Err:", err.Error())
  1742. return err
  1743. }
  1744. for k, v := range needAddAttendanc {
  1745. for _, v2 := range listUser {
  1746. if v2.OutboundMobile == v.Mobile || v2.Mobile == v.Mobile {
  1747. if needAddAttendanc[k].CompanyId == 0 {
  1748. needAddAttendanc[k].CompanyId = v2.CompanyId
  1749. needAddAttendanc[k].SellerName = v2.SellerName
  1750. needAddAttendanc[k].CompanyName = v2.CompanyName
  1751. needAddAttendanc[k].IsMeetingStr = 1
  1752. }
  1753. }
  1754. }
  1755. }
  1756. ////参会记录
  1757. err = models.AddAttendancDetail(needAddAttendanc, vAct.ActivityId, mobileStr)
  1758. if err != nil {
  1759. fmt.Println("AddAttendancDetail Err:", err.Error())
  1760. return err
  1761. }
  1762. ////处理是否限制报名
  1763. err = AddCygxActivityRestrictSignupByAdmin(vAct.ActivityId)
  1764. if err != nil {
  1765. fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
  1766. return err
  1767. }
  1768. activityIds += strconv.Itoa(vAct.ActivityId) + ","
  1769. go ActivityUserLabelLogAdd(vAct.ActivityId, mobileArr)
  1770. AddctivitySignupDetailByJmcj(needAddAttendanc, vAct.ActivityId)
  1771. }
  1772. }
  1773. }
  1774. }
  1775. if activityIdsLongTime != "" {
  1776. activityIdsLongTime = strings.TrimRight(activityIdsLongTime, ",")
  1777. activityIdsLongTime = detail.ConfigValue + "," + activityIdsLongTime
  1778. go models.UpdateConfigByCode(activityIdsLongTime, configCode)
  1779. }
  1780. activityIds = strings.TrimRight(activityIds, ",")
  1781. if activityIds != "" {
  1782. detailList, err := models.GetActivityAttendanceDetailList(activityIds)
  1783. if err != nil {
  1784. fmt.Println("GetActivityAttendanceDetailList Err:", err.Error())
  1785. return err
  1786. }
  1787. //添加报名日志 (下载使用)
  1788. err = models.AddCygxActivityMeetDetailLogOnlineByList(detailList, activityIds)
  1789. if err != nil {
  1790. fmt.Println("AddCygxActivityMeetDetailLogOnline Err:", err.Error())
  1791. return err
  1792. }
  1793. }
  1794. fmt.Println("结束路演同步")
  1795. return
  1796. }
  1797. // 查研观向处理活动用户限制报名
  1798. func AddCygxActivityRestrictSignupByAdmin(activityId int) (err error) {
  1799. defer func() {
  1800. if err != nil {
  1801. fmt.Println("err:", err)
  1802. go utils.SendAlarmMsg("查研观向处理活动用户限制报名失败,Err:"+err.Error()+"activityId"+strconv.Itoa(activityId), 3)
  1803. }
  1804. }()
  1805. activityInfo, e := models.GetAddActivityInfoById(activityId)
  1806. if e != nil {
  1807. err = errors.New("GetAddActivityInfoById" + e.Error())
  1808. return
  1809. }
  1810. if activityInfo == nil {
  1811. return
  1812. }
  1813. //不限制报名的不做爽约限制处理
  1814. //if activityInfo.IsLimitPeople > 0 {
  1815. //total, err := cygx.GetActivitySignupNomeetingCount(activityId)
  1816. if err != nil {
  1817. return
  1818. }
  1819. mobileList, _ := models.GetUserMeetingMobile(activityId)
  1820. var userIdArr []int
  1821. if len(mobileList) > 0 {
  1822. for _, v := range mobileList {
  1823. userIdArr = append(userIdArr, v.UserId)
  1824. }
  1825. lenuserIdArr := len(userIdArr)
  1826. var condition string
  1827. var pars []interface{}
  1828. condition = ` AND user_id IN (` + utils.GetOrmInReplace(lenuserIdArr) + `)`
  1829. pars = append(pars, userIdArr)
  1830. restrictSignupList, e := models.GetCygxActivityRestrictSignupList(condition, pars, 0, 9999)
  1831. if e != nil {
  1832. err = errors.New("GetCygxActivityRestrictSignupList" + e.Error())
  1833. return
  1834. }
  1835. //获取这些用户是否被加入到限制报名了
  1836. maptotalRestrict := make(map[int]bool)
  1837. for _, v := range restrictSignupList {
  1838. maptotalRestrict[v.UserId] = true
  1839. }
  1840. pars = make([]interface{}, 0)
  1841. condition = ` AND a.is_limit_people = 1 AND v.is_meeting = 0 AND v.do_fail_type = 0 AND v.user_id IN (` + utils.GetOrmInReplace(lenuserIdArr) + `)`
  1842. pars = append(pars, userIdArr)
  1843. listSignup, e := models.GetActivitySignupInnerActivityList(condition, pars)
  1844. if e != nil && e.Error() != utils.ErrNoRow() {
  1845. err = errors.New("GetActivitySignupInnerActivityList" + e.Error())
  1846. return
  1847. }
  1848. mapNomeet := make(map[int]int)
  1849. if len(listSignup) > 0 {
  1850. for _, v := range listSignup {
  1851. mapNomeet[v.UserId]++
  1852. }
  1853. }
  1854. var userIdDelArr []int
  1855. for _, v := range mobileList {
  1856. //如果加入了爽约限制但是爽约次数少于3条就删除爽约记录
  1857. if maptotalRestrict[v.UserId] && mapNomeet[v.UserId] < 3 {
  1858. userIdDelArr = append(userIdDelArr, v.UserId)
  1859. }
  1860. }
  1861. if len(userIdDelArr) > 0 {
  1862. e = models.DeleteCygxActivityRestrictSignupByUserIds(userIdDelArr)
  1863. if e != nil {
  1864. err = errors.New("DeleteCygxActivityRestrictSignupByUserIds" + e.Error())
  1865. return
  1866. }
  1867. }
  1868. }
  1869. //if total == 0 {
  1870. // return
  1871. //}
  1872. //}
  1873. list, e := models.GetActivitySignupNomeetingCountList(activityId)
  1874. if e != nil {
  1875. err = errors.New("GetActivitySignupNomeetingCountList" + e.Error())
  1876. return
  1877. }
  1878. var userIdSiginArr []int
  1879. var items []*models.CygxActivitySignupBreak
  1880. for _, v := range list {
  1881. userIdSiginArr = append(userIdSiginArr, v.UserId)
  1882. //添加爽约记录
  1883. item := new(models.CygxActivitySignupBreak)
  1884. item.UserId = v.UserId
  1885. item.ActivityId = v.ActivityId
  1886. item.CreateTime = time.Now()
  1887. item.Mobile = v.Mobile
  1888. item.Email = v.Email
  1889. item.CompanyId = v.CompanyId
  1890. item.CompanyName = v.CompanyName
  1891. item.RealName = v.RealName
  1892. item.SellerName = v.SellerName
  1893. items = append(items, item)
  1894. }
  1895. if len(list) == 0 {
  1896. return
  1897. }
  1898. var itemsRestrict []*models.CygxActivityRestrictSignup
  1899. maptotalRestrict := make(map[int]bool)
  1900. lenuserIdSiginArr := len(userIdSiginArr)
  1901. var condition string
  1902. var pars []interface{}
  1903. condition = ` AND user_id IN (` + utils.GetOrmInReplace(lenuserIdSiginArr) + `)`
  1904. pars = append(pars, userIdSiginArr)
  1905. restrictSignupList, e := models.GetCygxActivityRestrictSignupList(condition, pars, 0, 9999)
  1906. if e != nil {
  1907. err = errors.New("GetCygxActivityRestrictSignupList" + e.Error())
  1908. return
  1909. }
  1910. //获取这些用户是否被加入到限制报名了
  1911. for _, v := range restrictSignupList {
  1912. maptotalRestrict[v.UserId] = true
  1913. }
  1914. pars = make([]interface{}, 0)
  1915. condition = ` AND a.is_limit_people = 1 AND v.is_meeting = 0 AND v.do_fail_type = 0 AND user_id IN (` + utils.GetOrmInReplace(lenuserIdSiginArr) + `)`
  1916. pars = append(pars, userIdSiginArr)
  1917. listSignup, e := models.GetActivitySignupInnerActivityList(condition, pars)
  1918. if e != nil && e.Error() != utils.ErrNoRow() {
  1919. err = errors.New("GetActivitySignupInnerActivityList" + e.Error())
  1920. return
  1921. }
  1922. mapNomeet := make(map[int]int)
  1923. if len(listSignup) > 0 {
  1924. for _, v := range listSignup {
  1925. mapNomeet[v.UserId]++
  1926. }
  1927. }
  1928. for _, v := range mobileList {
  1929. //如果加入了爽约限制但是爽约次数少于3条就删除爽约记录
  1930. if !maptotalRestrict[v.UserId] && mapNomeet[v.UserId] >= 3 {
  1931. itemRestrict := new(models.CygxActivityRestrictSignup)
  1932. itemRestrict.UserId = v.UserId
  1933. itemRestrict.CreateTime = time.Now()
  1934. itemRestrict.Mobile = v.Mobile
  1935. itemRestrict.Email = v.Email
  1936. itemRestrict.CompanyId = v.CompanyId
  1937. itemRestrict.CompanyName = v.CompanyName
  1938. itemRestrict.IsRestrict = 1
  1939. itemsRestrict = append(itemsRestrict, itemRestrict)
  1940. }
  1941. }
  1942. err = models.DeleteCygxActivitySignupBreakById(activityId)
  1943. if err != nil {
  1944. err = errors.New("DeleteCygxActivitySignupBreakById" + err.Error())
  1945. return
  1946. }
  1947. //添加爽约记录
  1948. if len(items) > 0 {
  1949. _, e = models.AddCygxActivitySignupBreakList(items)
  1950. if e != nil {
  1951. err = errors.New("AddCygxActivitySignupBreakList, Err: " + e.Error())
  1952. return
  1953. }
  1954. }
  1955. //添加报名限制
  1956. if len(itemsRestrict) > 0 {
  1957. _, e = models.AddCygxActivityRestrictSignupList(itemsRestrict)
  1958. if e != nil {
  1959. err = errors.New("AddCygxActivityRestrictSignupList, Err: " + e.Error())
  1960. return
  1961. }
  1962. }
  1963. return
  1964. }
  1965. // 判断预约纪要按钮是否显示
  1966. func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
  1967. if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
  1968. isShowAppointment = true
  1969. }
  1970. if activityTypeId == 5 && chartPermissionName == "医药" {
  1971. isShowAppointment = true
  1972. }
  1973. return
  1974. }
  1975. // 判断预约纪要按钮是否显示
  1976. func IsShowAppointmentByactivityInfo(item *models.ActivityDetail, chartPermissionName string) (isShowAppointment bool) {
  1977. activityTypeId := item.ActivityTypeId
  1978. if activityTypeId == 1 || activityTypeId == 3 || activityTypeId == 4 {
  1979. isShowAppointment = true
  1980. }
  1981. if activityTypeId == 5 && chartPermissionName == "医药" {
  1982. isShowAppointment = true
  1983. }
  1984. if activityTypeId == 2 && item.IsLimitPeople == 0 {
  1985. isShowAppointment = true
  1986. }
  1987. return
  1988. }
  1989. // 用户报告操作行为,模板消息推送 (先放在活动模块下,避免代码冲突)
  1990. func ArticleUserRemind(user *models.WxUserItem, articleDetail *models.ArticleDetail, source int) (err error) {
  1991. defer func() {
  1992. if err != nil {
  1993. go utils.SendAlarmMsg(" 用户报告操作行为,模板消息推送失败"+fmt.Sprint("UserId:", user.UserId, "ArticleId:", articleDetail.ArticleId), 2)
  1994. }
  1995. }()
  1996. countUser, err := models.GetUserRemind(user.UserId)
  1997. if err != nil {
  1998. return err
  1999. }
  2000. if countUser == 0 {
  2001. return err
  2002. }
  2003. var sourceMsg string
  2004. if source == 1 {
  2005. sourceMsg = "阅读报告"
  2006. } else {
  2007. sourceMsg = "收藏报告"
  2008. }
  2009. //获取销售手机号
  2010. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2011. if err != nil && err.Error() != utils.ErrNoRow() {
  2012. return err
  2013. }
  2014. if sellerItemQy != nil {
  2015. openIdList, err := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
  2016. if err != nil {
  2017. fmt.Println(err)
  2018. return err
  2019. }
  2020. var keyword1 string
  2021. var keyword2 string
  2022. keyword1 = articleDetail.Title
  2023. keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
  2024. SendWxMsgWithArticleUserRemind(keyword1, keyword2, openIdList, articleDetail.ArticleId)
  2025. }
  2026. return
  2027. }
  2028. // 用户活动操作行为,模板消息推送
  2029. func ActivityUserRemind(user *models.WxUserItem, activityDetail *models.ActivityDetail, source int) (err error) {
  2030. defer func() {
  2031. if err != nil {
  2032. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ActivityUserRemind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  2033. }
  2034. }()
  2035. //获取销售手机号
  2036. countUser, e := models.GetUserRemind(user.UserId)
  2037. if e != nil {
  2038. err = errors.New("GetUserRemind, Err: " + e.Error())
  2039. return
  2040. }
  2041. // 如果是买方研选下的专家沙龙,同时推给内容组四人
  2042. if activityDetail.ActivityTypeId == 5 {
  2043. go SendNeiRongZuActivitieSignTemplateMsg(user, activityDetail)
  2044. }
  2045. //获取销售手机号
  2046. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2047. if e != nil && e.Error() != utils.ErrNoRow() {
  2048. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  2049. return
  2050. }
  2051. if sellerItemQy == nil {
  2052. err = nil
  2053. return
  2054. }
  2055. //某销售下的所有客户活动报名/预约外呼时,模板消息提醒该销售(可设置销售范围,随时增减销售)
  2056. conf, e := models.GetConfigByCode("tpl_msg_seller_mobile")
  2057. if e != nil {
  2058. err = errors.New("GetConfigByCode, Err: " + e.Error())
  2059. return
  2060. }
  2061. //如果用户没有设置消息提醒,而且销售的手机号也没有添加到配置中,那么就不推送模版消息
  2062. if countUser == 0 && !strings.Contains(conf.ConfigValue, sellerItemQy.Mobile) {
  2063. err = nil
  2064. return
  2065. }
  2066. var sourceMsg string
  2067. if source == 1 {
  2068. sourceMsg = "预约外呼"
  2069. } else if source == 2 {
  2070. sourceMsg = "设置会议提醒"
  2071. } else if source == 3 {
  2072. sourceMsg = "预约纪要"
  2073. } else if source == 4 {
  2074. sourceMsg = "活动报名"
  2075. }
  2076. openIdList, e := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
  2077. if e != nil {
  2078. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error())
  2079. return err
  2080. }
  2081. var keyword1 string
  2082. var keyword2 string
  2083. keyword1 = activityDetail.ActivityName
  2084. keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
  2085. SendWxMsgWithActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
  2086. return
  2087. }
  2088. // 用户专项调研操作行为,模板消息推送
  2089. func SpecialActivityUserRemind(user *models.WxUserItem, activityDetail *models.CygxActivitySpecialDetail, source int) (err error) {
  2090. defer func() {
  2091. if err != nil {
  2092. go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  2093. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  2094. }
  2095. }()
  2096. countUser, err := models.GetUserRemind(user.UserId)
  2097. if err != nil {
  2098. return err
  2099. }
  2100. if countUser == 0 {
  2101. return err
  2102. }
  2103. var sourceMsg string
  2104. if source == 1 {
  2105. sourceMsg = "预报名调研"
  2106. }
  2107. //获取销售手机号
  2108. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2109. if err != nil && err.Error() != utils.ErrNoRow() {
  2110. return err
  2111. }
  2112. if sellerItemQy != nil {
  2113. openIdList, err := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
  2114. if err != nil {
  2115. fmt.Println(err)
  2116. return err
  2117. }
  2118. var keyword1 string
  2119. var keyword2 string
  2120. keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:", sourceMsg)
  2121. keyword2 = activityDetail.ResearchTheme
  2122. SendWxMsgWithSpecialActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
  2123. }
  2124. return
  2125. }
  2126. //func init() {
  2127. // DoActivityOnenIdWxTemplateMsg()
  2128. //}
  2129. // 周日下午四点半推送全部活动
  2130. func DoActivityOnenIdWxTemplateMsg(cont context.Context) (err error) {
  2131. var msg string
  2132. defer func() {
  2133. if err != nil {
  2134. go utils.SendAlarmMsg("周日下午四点半推送全部活动失败,DoActivityOnenIdWxTemplateMsg ErrMsg:"+err.Error(), 2)
  2135. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "DoActivityOnenIdWxTemplateMsg ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  2136. fmt.Println(err)
  2137. }
  2138. if msg != "" {
  2139. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  2140. }
  2141. }()
  2142. var condition string
  2143. var pars []interface{}
  2144. openidPowerListMobile, err := models.GetCygxUserRecordPower(condition, pars)
  2145. if err != nil {
  2146. return err
  2147. }
  2148. var mobileArr []string
  2149. for _, v := range openidPowerListMobile {
  2150. mobileArr = append(mobileArr, v.Mobile)
  2151. }
  2152. openidPowerList, err := models.GetWxOpenIdByMobileSliceList(mobileArr)
  2153. if err != nil {
  2154. return err
  2155. }
  2156. first := "近期所有行业活动预告,欢迎参与"
  2157. keyword1 := "下周活动预告"
  2158. keyword2 := "已发布"
  2159. keyword3 := ""
  2160. keyword4 := "点击查看下周活动列表"
  2161. SendActivityOnenIdWxTemplateMsg(first, keyword1, keyword2, keyword3, keyword4, openidPowerList)
  2162. return
  2163. }
  2164. func ActivityButtonShow(item *models.ActivityDetail) (activityDetail *models.ActivityDetail) {
  2165. if item.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  2166. item.IsResearch = true
  2167. }
  2168. activityDetail = item
  2169. //IsShowAppointment bool `description:"是否展示预约纪要"`
  2170. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  2171. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  2172. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  2173. //IsShowSignup bool `description:"是否展示我要报名"`
  2174. activityTypeIdMap := GetActivityTypeIdMap()
  2175. activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId] // 线上还是线下
  2176. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  2177. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  2178. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  2179. activityDetail.SiginupDeadline = ""
  2180. }
  2181. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  2182. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  2183. activityDetail.CancelDeadline = ""
  2184. }
  2185. activityTimeText := activityDetail.ActivityTimeText
  2186. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  2187. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  2188. activityDetail.ActivityTimeText = activityTimeText
  2189. if activityDetail.SourceType != 2 {
  2190. activityDetail.SourceType = 1
  2191. }
  2192. activityDetail.IsShowAppointment = false
  2193. //易董的操作按钮都隐藏
  2194. if activityDetail.YidongActivityId != "" {
  2195. activityDetail.SourceType = 1
  2196. activityDetail.IsShowSignup = false
  2197. activityDetail.IsShowDetails = true
  2198. activityDetail.IsExternalLabel = true
  2199. activityDetail.IsResearch = false
  2200. activityDetail.IsResearchSpecial = false
  2201. return
  2202. }
  2203. //专家电话会 1
  2204. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  2205. activityDetail.IsShowHelpSsk = true
  2206. }
  2207. //新的是否展示规则
  2208. if activityDetail.IsCanAppointmentMinutes == 1 {
  2209. activityDetail.IsShowAppointment = true
  2210. } else {
  2211. activityDetail.IsShowAppointment = false
  2212. }
  2213. if activityDetail.ActiveState == "1" {
  2214. //专家电话会 1
  2215. //专家电话会限制人数的展示我要报名,不限制的展示预约外外呼
  2216. if activityDetail.ActivityTypeId == 1 {
  2217. //articleDetail.IsShowOutboundCall = true
  2218. if activityDetail.LimitPeopleNum == 0 {
  2219. activityDetail.IsShowOutboundCall = true
  2220. //articleDetail.IsShowHelpSsk = true
  2221. } else {
  2222. activityDetail.IsShowSignup = true
  2223. }
  2224. activityDetail.IsShowMeetingReminder = true
  2225. activityDetail.IsShowHelpSsk = true
  2226. }
  2227. //分析师电话会 2
  2228. if activityDetail.ActivityTypeId == 2 {
  2229. if activityDetail.LimitPeopleNum == 0 {
  2230. activityDetail.IsShowOutboundCall = true
  2231. //articleDetail.IsShowHelpSsk = true
  2232. } else {
  2233. activityDetail.IsShowSignup = true
  2234. }
  2235. activityDetail.IsShowMeetingReminder = true
  2236. }
  2237. //公司调研电话会 3
  2238. if activityDetail.ActivityTypeId == 3 {
  2239. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  2240. activityDetail.IsShowSignup = true
  2241. } else {
  2242. activityDetail.IsShowMeetingReminder = true
  2243. activityDetail.IsShowOutboundCall = true
  2244. }
  2245. }
  2246. //公司线下调研 4
  2247. if activityDetail.ActivityTypeId == 4 {
  2248. activityDetail.IsShowSignup = true
  2249. }
  2250. //专家线下沙龙 5
  2251. if activityDetail.ActivityTypeId == 5 {
  2252. activityDetail.IsShowSignup = true
  2253. }
  2254. //分析师线下沙龙 6
  2255. if activityDetail.ActivityTypeId == 6 {
  2256. activityDetail.IsShowSignup = true
  2257. }
  2258. //分析师电话会(C类) 7
  2259. if activityDetail.ActivityTypeId == 7 {
  2260. activityDetail.IsShowSignup = true
  2261. activityDetail.IsShowMeetingReminder = true
  2262. activityDetail.ActivityTypeName = "分析师电话会"
  2263. }
  2264. //买方线下交流 8 // 查研观向 11.0
  2265. if activityDetail.ActivityTypeId == 8 {
  2266. activityDetail.IsShowSignup = true
  2267. }
  2268. }
  2269. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  2270. if activityDetail.IsYidongConduct {
  2271. activityDetail.IsShowSignup = true
  2272. activityDetail.IsShowOutboundCall = false
  2273. }
  2274. return
  2275. }
  2276. func ActivityArrButtonShow(items []*models.ActivityDetail) (activityDetails []*models.ActivityDetail) {
  2277. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  2278. activityTypeIdMap := GetActivityTypeIdMap()
  2279. for _, activityDetail := range items {
  2280. activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId] // 线上还是线下
  2281. if activityDetail.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  2282. activityDetail.IsResearch = true
  2283. }
  2284. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  2285. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] {
  2286. activityDetail.IsResearchSpecial = true
  2287. }
  2288. //IsShowAppointment bool `description:"是否展示预约纪要"`
  2289. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  2290. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  2291. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  2292. //IsShowSignup bool `description:"是否展示我要报名"`
  2293. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  2294. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  2295. activityDetail.SiginupDeadline = ""
  2296. }
  2297. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  2298. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  2299. activityDetail.CancelDeadline = ""
  2300. }
  2301. activityTimeText := activityDetail.ActivityTimeText
  2302. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  2303. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  2304. activityDetail.ActivityTimeText = activityTimeText
  2305. if activityDetail.SourceType != 2 {
  2306. activityDetail.SourceType = 1
  2307. }
  2308. activityDetail.IsShowAppointment = false
  2309. //易董的操作按钮都隐藏
  2310. if activityDetail.YidongActivityId != "" {
  2311. activityDetail.SourceType = 1
  2312. activityDetail.IsShowSignup = false
  2313. activityDetail.IsShowDetails = true
  2314. } else {
  2315. //专家电话会 1
  2316. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  2317. activityDetail.IsShowHelpSsk = true
  2318. }
  2319. //新的是否展示规则
  2320. if activityDetail.IsCanAppointmentMinutes == 1 {
  2321. activityDetail.IsShowAppointment = true
  2322. } else {
  2323. activityDetail.IsShowAppointment = false
  2324. }
  2325. if activityDetail.ActiveState == "1" {
  2326. //专家电话会 1
  2327. //专家电话会限制人数的展示我要报名,不限制的展示预约外外呼
  2328. if activityDetail.ActivityTypeId == 1 {
  2329. //articleDetail.IsShowOutboundCall = true
  2330. if activityDetail.LimitPeopleNum == 0 {
  2331. activityDetail.IsShowOutboundCall = true
  2332. //articleDetail.IsShowHelpSsk = true
  2333. } else {
  2334. activityDetail.IsShowSignup = true
  2335. }
  2336. activityDetail.IsShowMeetingReminder = true
  2337. activityDetail.IsShowHelpSsk = true
  2338. }
  2339. //分析师电话会 2
  2340. if activityDetail.ActivityTypeId == 2 {
  2341. if activityDetail.LimitPeopleNum == 0 {
  2342. activityDetail.IsShowOutboundCall = true
  2343. //articleDetail.IsShowHelpSsk = true
  2344. } else {
  2345. activityDetail.IsShowSignup = true
  2346. }
  2347. activityDetail.IsShowMeetingReminder = true
  2348. }
  2349. //公司调研电话会 3
  2350. if activityDetail.ActivityTypeId == 3 {
  2351. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  2352. activityDetail.IsShowSignup = true
  2353. } else {
  2354. activityDetail.IsShowMeetingReminder = true
  2355. activityDetail.IsShowOutboundCall = true
  2356. }
  2357. }
  2358. //公司线下调研 4
  2359. if activityDetail.ActivityTypeId == 4 {
  2360. activityDetail.IsShowSignup = true
  2361. }
  2362. //专家线下沙龙 5
  2363. if activityDetail.ActivityTypeId == 5 {
  2364. activityDetail.IsShowSignup = true
  2365. }
  2366. //分析师线下沙龙 6
  2367. if activityDetail.ActivityTypeId == 6 {
  2368. activityDetail.IsShowSignup = true
  2369. }
  2370. //分析师电话会(C类) 7
  2371. if activityDetail.ActivityTypeId == 7 {
  2372. activityDetail.IsShowSignup = true
  2373. activityDetail.IsShowMeetingReminder = true
  2374. activityDetail.ActivityTypeName = "分析师电话会"
  2375. }
  2376. //买方线下交流 8 // 查研观向 11.0
  2377. if activityDetail.ActivityTypeId == 8 {
  2378. activityDetail.IsShowSignup = true
  2379. }
  2380. }
  2381. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  2382. if activityDetail.IsYidongConduct {
  2383. activityDetail.IsShowSignup = true
  2384. activityDetail.IsShowOutboundCall = false
  2385. }
  2386. }
  2387. //如果是易董同步过来的,只展示外部资源标签
  2388. if activityDetail.YidongActivityId != "" {
  2389. activityDetail.IsExternalLabel = true
  2390. activityDetail.IsResearch = false
  2391. activityDetail.IsResearchSpecial = false
  2392. }
  2393. activityDetails = append(activityDetails, activityDetail)
  2394. }
  2395. return
  2396. }
  2397. // GetActivityNewLabelMap 获取活动【新】标签Map
  2398. func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) {
  2399. labelMap = make(map[int]bool, 0)
  2400. industryNewMap = make(map[int]bool, 0)
  2401. if len(activityIds) == 0 {
  2402. return
  2403. }
  2404. // 获取活动关联的产业
  2405. var groupCond string
  2406. var groupPars []interface{}
  2407. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 `
  2408. groupPars = append(groupPars, activityIds)
  2409. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  2410. if e != nil {
  2411. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  2412. return
  2413. }
  2414. activityIndustryMap := make(map[int][]int, 0)
  2415. industryIds := make([]int, 0)
  2416. for i := range groups {
  2417. industryIds = append(industryIds, groups[i].IndustrialManagementId)
  2418. activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId)
  2419. }
  2420. // 获取新产业Map
  2421. industryLabelMap, e := GetIndustryNewLabelMap(industryIds)
  2422. if e != nil {
  2423. err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  2424. return
  2425. }
  2426. // 判断活动是否为新
  2427. for k := range industryLabelMap {
  2428. for k2, v2 := range activityIndustryMap {
  2429. if labelMap[k2] {
  2430. continue
  2431. }
  2432. // 活动的产业ID中存在一个新产业即为新活动
  2433. if utils.InArrayByInt(v2, k) {
  2434. labelMap[k2] = true
  2435. }
  2436. }
  2437. }
  2438. ////产业关联的弘则报告发布日期在三个月以内的活动、产业显示 NEW标签
  2439. //articNewLabel, e := GetArticNewLabelWhithActivity3Month()
  2440. //if e != nil {
  2441. // err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  2442. // return
  2443. //}
  2444. //for k := range articNewLabel {
  2445. // labelMap[k] = true
  2446. //}
  2447. return
  2448. }
  2449. // GetActivityVoiceResp 处理活动音频回放
  2450. func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) {
  2451. activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId)
  2452. if err != nil && err.Error() != utils.ErrNoRow() {
  2453. return
  2454. }
  2455. mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq)
  2456. if len(activityVoiceList) > 0 {
  2457. for _, v := range activityVoiceList {
  2458. mapActivityVoice[v.ActivityId] = v
  2459. }
  2460. }
  2461. mapItem = mapActivityVoice
  2462. return
  2463. }
  2464. // AddActivitykeyWordSearch 添加活动搜索记录
  2465. func AddActivitykeyWordSearch(keyWordSearch string, user *models.WxUserItem) {
  2466. if keyWordSearch != "" {
  2467. keyWordItem := new(models.CygxUserSearchKeyWord)
  2468. keyWordItem.UserId = user.UserId
  2469. keyWordItem.KeyWord = keyWordSearch
  2470. keyWordItem.PageType = "ActivitSearch"
  2471. keyWordItem.CreateTime = time.Now()
  2472. go models.AddUserSearchKeyWord(keyWordItem)
  2473. }
  2474. }
  2475. // GetActivityVideoResp 处理活动视频频回放
  2476. func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) {
  2477. var condition string
  2478. var ativityVIdstr string
  2479. for _, v := range mapActivityId {
  2480. ativityVIdstr += strconv.Itoa(v) + ","
  2481. }
  2482. if ativityVIdstr == "" {
  2483. return
  2484. }
  2485. ativityVIdstr = strings.TrimRight(ativityVIdstr, ",")
  2486. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  2487. var pars []interface{}
  2488. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  2489. //condition += ` AND art.activity_time > ? `
  2490. //pars = append(pars, endTime)
  2491. videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000)
  2492. if e != nil && e.Error() != utils.ErrNoRow() {
  2493. err = e
  2494. return
  2495. }
  2496. mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp)
  2497. if len(videoList) > 0 {
  2498. for _, v := range videoList {
  2499. mapActivityVideo[v.ActivityId] = v
  2500. }
  2501. }
  2502. mapItem = mapActivityVideo
  2503. return
  2504. }
  2505. // 用户音视频回放操作操作行为,模板消息推送
  2506. func ActivityVideoUserRmind(user *models.WxUserItem, activityId, fileType int) (err error) {
  2507. defer func() {
  2508. if err != nil {
  2509. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  2510. }
  2511. }()
  2512. countUser, err := models.GetUserRemind(user.UserId)
  2513. if err != nil {
  2514. return err
  2515. }
  2516. if countUser == 0 {
  2517. return err
  2518. }
  2519. var first string
  2520. var keyword1 string
  2521. var keyword2 string
  2522. var keyword3 string
  2523. var keyword4 string
  2524. var remark string
  2525. //获取销售手机号
  2526. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2527. if err != nil && err.Error() != utils.ErrNoRow() {
  2528. return err
  2529. }
  2530. if sellerItemQy != nil {
  2531. openIdList, e := models.GetWxOpenIdByMobileList(sellerItemQy.Mobile)
  2532. if e != nil {
  2533. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  2534. return
  2535. }
  2536. //TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
  2537. if fileType == 1 {
  2538. activityInfo, e := models.GetCygxActivityVideoByActivityId(activityId)
  2539. if e != nil {
  2540. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  2541. return
  2542. }
  2543. if activityInfo == nil {
  2544. return
  2545. }
  2546. keyword1 = activityInfo.VideoName
  2547. keyword2 = fmt.Sprint("互动:播放视频,", user.RealName, "--", user.CompanyName)
  2548. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放视频")
  2549. } else {
  2550. activityInfo, e := models.GetCygxActivityVoiceByActivityId(activityId)
  2551. if e != nil {
  2552. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  2553. return
  2554. }
  2555. if activityInfo == nil {
  2556. return
  2557. }
  2558. keyword1 = activityInfo.VoiceName
  2559. keyword2 = fmt.Sprint("互动:播放音频,", user.RealName, "--", user.CompanyName)
  2560. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放音频")
  2561. }
  2562. //keyword2 = "__"
  2563. //remark = "点击查看活动详情"
  2564. openIdArr := make([]string, 0)
  2565. for _, v := range openIdList {
  2566. openIdArr = append(openIdArr, v.OpenId)
  2567. }
  2568. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  2569. sendInfo := new(SendWxTemplate)
  2570. sendInfo.First = first
  2571. sendInfo.Keyword1 = keyword1
  2572. sendInfo.Keyword2 = keyword2
  2573. sendInfo.Keyword3 = keyword3
  2574. sendInfo.Keyword4 = keyword4
  2575. sendInfo.Remark = remark
  2576. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  2577. sendInfo.RedirectUrl = redirectUrl
  2578. sendInfo.RedirectTarget = 3
  2579. sendInfo.Resource = strconv.Itoa(activityId)
  2580. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  2581. sendInfo.OpenIdArr = openIdArr
  2582. err = PublicSendTemplateMsg(sendInfo)
  2583. if err != nil {
  2584. return
  2585. }
  2586. }
  2587. return
  2588. }
  2589. // 解析活动填写的报告链接
  2590. func GetActivityReportLinkToArticleList(item *models.ActivityDetail) (items []*models.ActivityArticleResp, err error) {
  2591. reportLink := item.ReportLink
  2592. //处理活动的
  2593. var articleIds []int
  2594. var articleList []string
  2595. if strings.Contains(reportLink, ";") {
  2596. articleList = strings.Split(reportLink, ";")
  2597. } else {
  2598. articleList = strings.Split(reportLink, ";")
  2599. }
  2600. for _, v := range articleList {
  2601. linkList := strings.Split(v, "/")
  2602. if linkList[len(linkList)-1] != "" {
  2603. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  2604. articleIds = append(articleIds, linkArticleId)
  2605. }
  2606. }
  2607. lenarticleIds := len(articleIds)
  2608. if lenarticleIds == 0 {
  2609. return
  2610. }
  2611. var condition string
  2612. var pars []interface{}
  2613. pars = make([]interface{}, 0)
  2614. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
  2615. pars = append(pars, articleIds)
  2616. listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  2617. if e != nil {
  2618. err = errors.New("GetResourceDataList, Err: " + e.Error())
  2619. return
  2620. }
  2621. if len(listArticle) > 0 {
  2622. for _, v := range listArticle {
  2623. artItem := new(models.ActivityArticleResp)
  2624. artItem.ArticleId = v.ArticleId
  2625. artItem.Title = v.Title
  2626. items = append(items, artItem)
  2627. }
  2628. }
  2629. return
  2630. }
  2631. // GetActivityCityResp 获取活动关联城市,当同一个活动标签对应多个城市的时候,展示最近举办的活动
  2632. func GetActivityCityResp() (mapItem map[string]string, err error) {
  2633. activityList, err := models.GetActivityLabelListCity()
  2634. if err != nil && err.Error() != utils.ErrNoRow() {
  2635. return
  2636. }
  2637. mapActivityCity := make(map[string]string)
  2638. if len(activityList) > 0 {
  2639. for _, v := range activityList {
  2640. if v.ActivityTypeId == utils.C_CLASS_ACTIVITY_TYPE_ID {
  2641. v.ActivityTypeId = utils.ANALYST_TELL_ACTIVITY_TYPE_ID
  2642. }
  2643. //如果城市民称长度大于2,那么就不显示
  2644. if utf8.RuneCountInString(v.City) != 2 || mapActivityCity[fmt.Sprint(v.Label, "{|}", v.ActivityTypeId)] != "" {
  2645. continue
  2646. }
  2647. mapActivityCity[fmt.Sprint(v.Label, "{|}", v.ActivityTypeId)] = v.City
  2648. }
  2649. }
  2650. mapItem = mapActivityCity
  2651. return
  2652. }
  2653. // UpdateIsSendYidongSignUp更改活动是否向易董推送报名名单的状态
  2654. func UpdateIsSendYidongSignUp(activityId int) (err error) {
  2655. defer func() {
  2656. if err != nil {
  2657. fmt.Println(err)
  2658. go utils.SendAlarmMsg("更改活动是否向易董推送报名名单的状态,失败,活动ID:"+strconv.Itoa(activityId)+err.Error(), 2)
  2659. }
  2660. }()
  2661. err = models.UPdateSendedYiDongSignUp(activityId)
  2662. return
  2663. }
  2664. // 获取活动线上还是线下的类型
  2665. func GetActivityTypeIdMap() (mapResp map[int]int) {
  2666. var err error
  2667. defer func() {
  2668. if err != nil {
  2669. fmt.Println(err)
  2670. go utils.SendAlarmMsg("获取活动线上还是线下的类型,失败,GetActivityTypeIdMap:Err "+err.Error(), 2)
  2671. }
  2672. }()
  2673. list, e := models.GetActivityTypeList("")
  2674. if e != nil {
  2675. err = errors.New("GetActivityTypeList, Err: " + e.Error())
  2676. return
  2677. }
  2678. mapResp = make(map[int]int, 0)
  2679. for _, v := range list {
  2680. mapResp[v.ActivityTypeId] = v.ActivityType
  2681. }
  2682. return
  2683. }