activity.go 97 KB

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