activity.go 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812
  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. if activityDetail.IsZoom == 1 {
  2134. activityDetail.IsShowMeetingReminder = true
  2135. if activityDetail.LimitPeopleNum == 0 {
  2136. activityDetail.IsShowOutboundCall = false
  2137. }
  2138. }
  2139. }
  2140. //公司线下调研 4
  2141. if activityDetail.ActivityTypeId == 4 {
  2142. activityDetail.IsShowSignup = true
  2143. }
  2144. //专家线下沙龙 5
  2145. if activityDetail.ActivityTypeId == 5 {
  2146. activityDetail.IsShowSignup = true
  2147. }
  2148. //分析师线下沙龙 6
  2149. if activityDetail.ActivityTypeId == 6 {
  2150. activityDetail.IsShowSignup = true
  2151. }
  2152. //分析师电话会(C类) 7
  2153. if activityDetail.ActivityTypeId == 7 {
  2154. activityDetail.IsShowSignup = true
  2155. activityDetail.IsShowMeetingReminder = true
  2156. activityDetail.ActivityTypeName = "分析师电话会"
  2157. }
  2158. //买方线下交流 8 // 查研观向 11.0
  2159. if activityDetail.ActivityTypeId == 8 {
  2160. activityDetail.IsShowSignup = true
  2161. }
  2162. }
  2163. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  2164. if activityDetail.IsYidongConduct {
  2165. activityDetail.IsShowSignup = true
  2166. activityDetail.IsShowOutboundCall = false
  2167. }
  2168. return
  2169. }
  2170. func ActivityArrButtonShow(items []*models.ActivityDetail) (activityDetails []*models.ActivityDetail) {
  2171. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  2172. activityTypeIdMap := GetActivityTypeIdMap()
  2173. for _, activityDetail := range items {
  2174. activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId] // 线上还是线下
  2175. if activityDetail.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  2176. activityDetail.IsResearch = true
  2177. }
  2178. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  2179. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] {
  2180. activityDetail.IsResearchSpecial = true
  2181. }
  2182. //IsShowAppointment bool `description:"是否展示预约纪要"`
  2183. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  2184. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  2185. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  2186. //IsShowSignup bool `description:"是否展示我要报名"`
  2187. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  2188. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  2189. activityDetail.SiginupDeadline = ""
  2190. }
  2191. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  2192. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  2193. activityDetail.CancelDeadline = ""
  2194. }
  2195. activityTimeText := activityDetail.ActivityTimeText
  2196. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  2197. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  2198. activityDetail.ActivityTimeText = activityTimeText
  2199. if activityDetail.SourceType != 2 {
  2200. activityDetail.SourceType = 1
  2201. }
  2202. activityDetail.IsShowAppointment = false
  2203. //易董的操作按钮都隐藏
  2204. if activityDetail.YidongActivityId != "" {
  2205. activityDetail.SourceType = 1
  2206. activityDetail.IsShowSignup = false
  2207. activityDetail.IsShowDetails = true
  2208. } else {
  2209. //专家电话会 1
  2210. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  2211. activityDetail.IsShowHelpSsk = true
  2212. }
  2213. //新的是否展示规则
  2214. if activityDetail.IsCanAppointmentMinutes == 1 {
  2215. activityDetail.IsShowAppointment = true
  2216. } else {
  2217. activityDetail.IsShowAppointment = false
  2218. }
  2219. if activityDetail.ActiveState == "1" {
  2220. //专家电话会 1
  2221. //专家电话会限制人数的展示我要报名,不限制的展示预约外外呼
  2222. if activityDetail.ActivityTypeId == 1 {
  2223. //articleDetail.IsShowOutboundCall = true
  2224. if activityDetail.LimitPeopleNum == 0 {
  2225. activityDetail.IsShowOutboundCall = true
  2226. //articleDetail.IsShowHelpSsk = true
  2227. } else {
  2228. activityDetail.IsShowSignup = true
  2229. }
  2230. activityDetail.IsShowMeetingReminder = true
  2231. activityDetail.IsShowHelpSsk = true
  2232. }
  2233. //分析师电话会 2
  2234. if activityDetail.ActivityTypeId == 2 {
  2235. if activityDetail.LimitPeopleNum == 0 {
  2236. activityDetail.IsShowOutboundCall = true
  2237. //articleDetail.IsShowHelpSsk = true
  2238. } else {
  2239. activityDetail.IsShowSignup = true
  2240. }
  2241. activityDetail.IsShowMeetingReminder = true
  2242. }
  2243. //公司调研电话会 3
  2244. if activityDetail.ActivityTypeId == 3 {
  2245. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  2246. activityDetail.IsShowSignup = true
  2247. } else {
  2248. activityDetail.IsShowMeetingReminder = true
  2249. activityDetail.IsShowOutboundCall = true
  2250. }
  2251. if activityDetail.IsZoom == 1 {
  2252. activityDetail.IsShowMeetingReminder = true
  2253. if activityDetail.LimitPeopleNum == 0 {
  2254. activityDetail.IsShowOutboundCall = false
  2255. }
  2256. }
  2257. }
  2258. //公司线下调研 4
  2259. if activityDetail.ActivityTypeId == 4 {
  2260. activityDetail.IsShowSignup = true
  2261. }
  2262. //专家线下沙龙 5
  2263. if activityDetail.ActivityTypeId == 5 {
  2264. activityDetail.IsShowSignup = true
  2265. }
  2266. //分析师线下沙龙 6
  2267. if activityDetail.ActivityTypeId == 6 {
  2268. activityDetail.IsShowSignup = true
  2269. }
  2270. //分析师电话会(C类) 7
  2271. if activityDetail.ActivityTypeId == 7 {
  2272. activityDetail.IsShowSignup = true
  2273. activityDetail.IsShowMeetingReminder = true
  2274. activityDetail.ActivityTypeName = "分析师电话会"
  2275. }
  2276. //买方线下交流 8 // 查研观向 11.0
  2277. if activityDetail.ActivityTypeId == 8 {
  2278. activityDetail.IsShowSignup = true
  2279. }
  2280. }
  2281. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  2282. if activityDetail.IsYidongConduct {
  2283. activityDetail.IsShowSignup = true
  2284. activityDetail.IsShowOutboundCall = false
  2285. }
  2286. }
  2287. //如果是易董同步过来的,只展示外部资源标签
  2288. if activityDetail.YidongActivityId != "" {
  2289. activityDetail.IsExternalLabel = true
  2290. activityDetail.IsResearch = false
  2291. activityDetail.IsResearchSpecial = false
  2292. }
  2293. activityDetails = append(activityDetails, activityDetail)
  2294. }
  2295. return
  2296. }
  2297. // GetActivityNewLabelMap 获取活动【新】标签Map
  2298. func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) {
  2299. labelMap = make(map[int]bool, 0)
  2300. industryNewMap = make(map[int]bool, 0)
  2301. if len(activityIds) == 0 {
  2302. return
  2303. }
  2304. // 获取活动关联的产业
  2305. var groupCond string
  2306. var groupPars []interface{}
  2307. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 `
  2308. groupPars = append(groupPars, activityIds)
  2309. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  2310. if e != nil {
  2311. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  2312. return
  2313. }
  2314. activityIndustryMap := make(map[int][]int, 0)
  2315. industryIds := make([]int, 0)
  2316. for i := range groups {
  2317. industryIds = append(industryIds, groups[i].IndustrialManagementId)
  2318. activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId)
  2319. }
  2320. // 获取新产业Map
  2321. industryLabelMap, e := GetIndustryNewLabelMap(industryIds)
  2322. if e != nil {
  2323. err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  2324. return
  2325. }
  2326. // 判断活动是否为新
  2327. for k := range industryLabelMap {
  2328. for k2, v2 := range activityIndustryMap {
  2329. if labelMap[k2] {
  2330. continue
  2331. }
  2332. // 活动的产业ID中存在一个新产业即为新活动
  2333. if utils.InArrayByInt(v2, k) {
  2334. labelMap[k2] = true
  2335. }
  2336. }
  2337. }
  2338. ////产业关联的弘则报告发布日期在三个月以内的活动、产业显示 NEW标签
  2339. //articNewLabel, e := GetArticNewLabelWhithActivity3Month()
  2340. //if e != nil {
  2341. // err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  2342. // return
  2343. //}
  2344. //for k := range articNewLabel {
  2345. // labelMap[k] = true
  2346. //}
  2347. return
  2348. }
  2349. // GetActivityVoiceResp 处理活动音频回放
  2350. func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) {
  2351. activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId)
  2352. if err != nil && err.Error() != utils.ErrNoRow() {
  2353. return
  2354. }
  2355. mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq)
  2356. if len(activityVoiceList) > 0 {
  2357. for _, v := range activityVoiceList {
  2358. mapActivityVoice[v.ActivityId] = v
  2359. }
  2360. }
  2361. mapItem = mapActivityVoice
  2362. return
  2363. }
  2364. // AddActivitykeyWordSearch 添加活动搜索记录
  2365. func AddActivitykeyWordSearch(keyWordSearch string, user *models.WxUserItem) {
  2366. if keyWordSearch != "" {
  2367. keyWordItem := new(models.CygxUserSearchKeyWord)
  2368. keyWordItem.UserId = user.UserId
  2369. keyWordItem.KeyWord = keyWordSearch
  2370. keyWordItem.PageType = "ActivitSearch"
  2371. keyWordItem.CreateTime = time.Now()
  2372. go models.AddUserSearchKeyWord(keyWordItem)
  2373. }
  2374. }
  2375. // GetActivityVideoResp 处理活动视频频回放
  2376. func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) {
  2377. var condition string
  2378. var ativityVIdstr string
  2379. for _, v := range mapActivityId {
  2380. ativityVIdstr += strconv.Itoa(v) + ","
  2381. }
  2382. if ativityVIdstr == "" {
  2383. return
  2384. }
  2385. ativityVIdstr = strings.TrimRight(ativityVIdstr, ",")
  2386. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  2387. var pars []interface{}
  2388. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  2389. //condition += ` AND art.activity_time > ? `
  2390. //pars = append(pars, endTime)
  2391. videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000)
  2392. if e != nil && e.Error() != utils.ErrNoRow() {
  2393. err = e
  2394. return
  2395. }
  2396. mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp)
  2397. if len(videoList) > 0 {
  2398. for _, v := range videoList {
  2399. mapActivityVideo[v.ActivityId] = v
  2400. }
  2401. }
  2402. mapItem = mapActivityVideo
  2403. return
  2404. }
  2405. // 用户音视频回放操作操作行为,模板消息推送
  2406. func ActivityVideoUserRmind(user *models.WxUserItem, activityId, fileType int) (err error) {
  2407. defer func() {
  2408. if err != nil {
  2409. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  2410. }
  2411. }()
  2412. countUser, err := models.GetUserRemind(user.UserId)
  2413. if err != nil {
  2414. return err
  2415. }
  2416. if countUser == 0 {
  2417. return err
  2418. }
  2419. var first string
  2420. var keyword1 string
  2421. var keyword2 string
  2422. var keyword3 string
  2423. var keyword4 string
  2424. var remark string
  2425. //获取销售手机号
  2426. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2427. if err != nil && err.Error() != utils.ErrNoRow() {
  2428. return err
  2429. }
  2430. if sellerItemQy != nil {
  2431. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  2432. if e != nil {
  2433. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  2434. return
  2435. }
  2436. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  2437. openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  2438. if e != nil {
  2439. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  2440. return
  2441. }
  2442. //TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
  2443. if fileType == 1 {
  2444. activityInfo, e := models.GetCygxActivityVideoByActivityId(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.VideoName
  2453. keyword2 = fmt.Sprint("互动:播放视频,", user.RealName, "--", user.CompanyName)
  2454. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放视频")
  2455. } else {
  2456. activityInfo, e := models.GetCygxActivityVoiceByActivityId(activityId)
  2457. if e != nil {
  2458. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  2459. return
  2460. }
  2461. if activityInfo == nil {
  2462. return
  2463. }
  2464. keyword1 = activityInfo.VoiceName
  2465. keyword2 = fmt.Sprint("互动:播放音频,", user.RealName, "--", user.CompanyName)
  2466. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放音频")
  2467. }
  2468. //keyword2 = "__"
  2469. //remark = "点击查看活动详情"
  2470. openIdArr := make([]string, 0)
  2471. for _, v := range openIdList {
  2472. openIdArr = append(openIdArr, v.OpenId)
  2473. }
  2474. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  2475. sendInfo := new(SendWxTemplate)
  2476. sendInfo.First = first
  2477. sendInfo.Keyword1 = keyword1
  2478. sendInfo.Keyword2 = keyword2
  2479. sendInfo.Keyword3 = keyword3
  2480. sendInfo.Keyword4 = keyword4
  2481. sendInfo.Remark = remark
  2482. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  2483. sendInfo.RedirectUrl = redirectUrl
  2484. sendInfo.RedirectTarget = 3
  2485. sendInfo.Resource = strconv.Itoa(activityId)
  2486. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  2487. sendInfo.OpenIdArr = openIdArr
  2488. err = PublicSendTemplateMsg(sendInfo)
  2489. if err != nil {
  2490. return
  2491. }
  2492. }
  2493. return
  2494. }
  2495. // 解析活动填写的报告链接
  2496. func GetActivityReportLinkToArticleList(item *models.ActivityDetail) (items []*models.ActivityArticleResp, err error) {
  2497. reportLink := item.ReportLink
  2498. //处理活动的
  2499. var articleIds []int
  2500. var articleList []string
  2501. if strings.Contains(reportLink, ";") {
  2502. articleList = strings.Split(reportLink, ";")
  2503. } else {
  2504. articleList = strings.Split(reportLink, ";")
  2505. }
  2506. for _, v := range articleList {
  2507. linkList := strings.Split(v, "/")
  2508. if linkList[len(linkList)-1] != "" {
  2509. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  2510. articleIds = append(articleIds, linkArticleId)
  2511. }
  2512. }
  2513. lenarticleIds := len(articleIds)
  2514. if lenarticleIds == 0 {
  2515. return
  2516. }
  2517. var condition string
  2518. var pars []interface{}
  2519. pars = make([]interface{}, 0)
  2520. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
  2521. pars = append(pars, articleIds)
  2522. listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  2523. if e != nil {
  2524. err = errors.New("GetResourceDataList, Err: " + e.Error())
  2525. return
  2526. }
  2527. if len(listArticle) > 0 {
  2528. for _, v := range listArticle {
  2529. artItem := new(models.ActivityArticleResp)
  2530. artItem.ArticleId = v.ArticleId
  2531. artItem.Title = v.Title
  2532. items = append(items, artItem)
  2533. }
  2534. }
  2535. return
  2536. }
  2537. // GetActivityCityResp 获取活动关联城市,当同一个活动标签对应多个城市的时候,展示最近举办的活动
  2538. func GetActivityCityResp() (mapItem map[string]string, err error) {
  2539. activityList, err := models.GetActivityLabelListCity()
  2540. if err != nil && err.Error() != utils.ErrNoRow() {
  2541. return
  2542. }
  2543. mapActivityCity := make(map[string]string)
  2544. if len(activityList) > 0 {
  2545. for _, v := range activityList {
  2546. if v.ActivityTypeId == utils.C_CLASS_ACTIVITY_TYPE_ID {
  2547. v.ActivityTypeId = utils.ANALYST_TELL_ACTIVITY_TYPE_ID
  2548. }
  2549. //如果城市民称长度大于2,那么就不显示
  2550. if utf8.RuneCountInString(v.City) != 2 || mapActivityCity[fmt.Sprint(v.Label, "{|}", v.ActivityTypeId)] != "" {
  2551. continue
  2552. }
  2553. mapActivityCity[fmt.Sprint(v.Label, "{|}", v.ActivityTypeId)] = v.City
  2554. }
  2555. }
  2556. mapItem = mapActivityCity
  2557. return
  2558. }
  2559. // UpdateIsSendYidongSignUp更改活动是否向易董推送报名名单的状态
  2560. func UpdateIsSendYidongSignUp(activityId int) (err error) {
  2561. defer func() {
  2562. if err != nil {
  2563. fmt.Println(err)
  2564. go utils.SendAlarmMsg("更改活动是否向易董推送报名名单的状态,失败,活动ID:"+strconv.Itoa(activityId)+err.Error(), 2)
  2565. }
  2566. }()
  2567. err = models.UPdateSendedYiDongSignUp(activityId)
  2568. return
  2569. }
  2570. // 获取活动线上还是线下的类型
  2571. func GetActivityTypeIdMap() (mapResp map[int]int) {
  2572. var err error
  2573. defer func() {
  2574. if err != nil {
  2575. fmt.Println(err)
  2576. go utils.SendAlarmMsg("获取活动线上还是线下的类型,失败,GetActivityTypeIdMap:Err "+err.Error(), 2)
  2577. }
  2578. }()
  2579. list, e := models.GetActivityTypeList("")
  2580. if e != nil {
  2581. err = errors.New("GetActivityTypeList, Err: " + e.Error())
  2582. return
  2583. }
  2584. mapResp = make(map[int]int, 0)
  2585. for _, v := range list {
  2586. mapResp[v.ActivityTypeId] = v.ActivityType
  2587. }
  2588. return
  2589. }
  2590. // 获取活动封面图片
  2591. func GetActivityImgMap(items []*models.ActivityDetail) (mapResp map[int]*models.ActivityImgUrlMapResp) {
  2592. var err error
  2593. defer func() {
  2594. if err != nil {
  2595. fmt.Println(err)
  2596. go utils.SendAlarmMsg("获取活动封面图片,失败,GetActivityImgMap:Err "+err.Error(), 2)
  2597. }
  2598. }()
  2599. detail, e := models.GetConfigByCode("city_img_url")
  2600. if e != nil {
  2601. err = errors.New("GetConfigByCode city_img_url, Err: " + e.Error())
  2602. return
  2603. }
  2604. detailChart, e := models.GetConfigByCode("chart_img_url")
  2605. if e != nil {
  2606. err = errors.New("GetConfigByCode chart_img_url , Err: " + e.Error())
  2607. return
  2608. }
  2609. mapResp = make(map[int]*models.ActivityImgUrlMapResp, 0)
  2610. addressList := strings.Split(detail.ConfigValue, "{|}")
  2611. mapAddress := make(map[string]string)
  2612. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  2613. mapChart := make(map[string]string)
  2614. var cityName string
  2615. var chartName string
  2616. var imgUrl string
  2617. var imgUrlChart string
  2618. for _, v := range addressList {
  2619. vslice := strings.Split(v, "_")
  2620. cityName = vslice[0]
  2621. imgUrl = vslice[len(vslice)-1]
  2622. mapAddress[cityName] = imgUrl
  2623. }
  2624. for _, v := range chartList {
  2625. vslice := strings.Split(v, "_")
  2626. chartName = vslice[0]
  2627. imgUrlChart = vslice[len(vslice)-1]
  2628. mapChart[chartName] = imgUrlChart
  2629. }
  2630. for _, v := range items {
  2631. //fmt.Println(v.ChartPermissionName)
  2632. //if strings.Contains(v.ChartPermissionName, "研选") && v.ActivityTypeId == 1 {
  2633. // v.ImgUrlText = utils.YAN_XUAN_IMG
  2634. //}
  2635. item := new(models.ActivityImgUrlMapResp)
  2636. if v.ActivityType == 0 {
  2637. if mapAddress[v.City] != "" {
  2638. item.ImgUrl = mapAddress[v.City]
  2639. } else {
  2640. item.ImgUrl = mapAddress["其它"]
  2641. }
  2642. } else {
  2643. if mapChart[v.ChartPermissionName] != "" {
  2644. item.ImgUrl = mapChart[v.ChartPermissionName]
  2645. }
  2646. }
  2647. mapResp[v.ActivityId] = item
  2648. }
  2649. return
  2650. }