activity.go 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090
  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. func ActivityAttendanceDetail(cont context.Context) (err error) {
  1647. defer func() {
  1648. if err != nil {
  1649. fmt.Println("ActivityAttendanceDetail Err:" + err.Error())
  1650. go utils.SendAlarmMsg("同步进门财经数据失败", 2)
  1651. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ActivityAttendanceDetail ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1652. }
  1653. }()
  1654. configCode := "jin_meng_activity_id"
  1655. detail, err := models.GetConfigByCode(configCode)
  1656. if err != nil {
  1657. return err
  1658. }
  1659. fmt.Println(detail.ConfigValue)
  1660. mapActivityId := make(map[string]string)
  1661. sliceValue := strings.Split(detail.ConfigValue, ",")
  1662. for _, v := range sliceValue {
  1663. mapActivityId[v] = v
  1664. }
  1665. var activityIds string
  1666. var activityIdsLongTime string //可回放的会议,到会详情持续更新加入到不做14天限制的活动中
  1667. fmt.Println("开始同步")
  1668. dateTime := time.Now().AddDate(0, 0, -7).Format(utils.FormatDate)
  1669. dateNow := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  1670. startDate := dateTime + " 00:00:00"
  1671. endDate := dateNow + " 23:59:59"
  1672. //获取进门财经需要处理的活动
  1673. listActivityRoadshow, err := models.GetRoadshowDataListByDateTime(startDate, endDate)
  1674. if err != nil {
  1675. fmt.Println("GetRoadshowDataListByDateTime Err:", err.Error())
  1676. return err
  1677. }
  1678. for _, vAct := range listActivityRoadshow {
  1679. doTime := utils.TimeRemoveHms2(vAct.RoadshowBeginTime)
  1680. findStartDate := doTime + " 00:00:00"
  1681. findEndDate := doTime + " 23:59:59"
  1682. var roadshowTitle string
  1683. roadshowTitle = vAct.RoadshowTitle
  1684. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, "【", "", -1)
  1685. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, "】", "", -1)
  1686. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, " ", "", -1)
  1687. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, "-", "", -1)
  1688. vAct.RoadshowTitle = strings.Replace(vAct.RoadshowTitle, ":", "", -1)
  1689. nameSlice := strings.Split(vAct.RoadshowTitle, "|")
  1690. //fmt.Println(timeSlice[0])
  1691. //对于手动匹配到的活动数据也要更新
  1692. var activityName string
  1693. if len(nameSlice) >= 1 {
  1694. //if vAct.JmcjRoadshowTitle != "" {
  1695. // activityName = vAct.JmcjRoadshowTitle
  1696. //} else {
  1697. // activityName = nameSlice[len(nameSlice)-1]
  1698. //}
  1699. activityName = nameSlice[len(nameSlice)-1]
  1700. if activityName != "" {
  1701. //通过名称去找匹配的活动
  1702. activityDetail, _ := models.GetAddActivityInfoByTitle(activityName, findStartDate, findEndDate)
  1703. if activityDetail == nil {
  1704. continue
  1705. } else {
  1706. activityIds += strconv.Itoa(activityDetail.ActivityId) + ","
  1707. }
  1708. list, err := models.GetRoadshowDataList(roadshowTitle, findStartDate, findEndDate)
  1709. if err != nil {
  1710. fmt.Println("GetTacticsList Err:", err.Error())
  1711. return err
  1712. }
  1713. var isPlayback bool // 是否包含回放
  1714. needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
  1715. var mobileStr string
  1716. var mobileArr []string
  1717. if len(list) > 0 {
  1718. fmt.Println("原来的", vAct.RoadshowTitle)
  1719. fmt.Println("处理的", activityName)
  1720. for _, v := range list {
  1721. if v.UserPhone != "" {
  1722. item := new(models.CygxActivityAttendanceDetail)
  1723. item.ActivityId = activityDetail.ActivityId
  1724. item.RealName = v.UserName
  1725. item.Mobile = v.UserPhone
  1726. item.CompanyName = v.Company
  1727. //item.SellerName = sellerName
  1728. item.FirstMeetingTime = v.FirstWatchTime
  1729. item.LastMeetingTime = v.LastWatchTime
  1730. item.Duration = utils.GetAttendanceDetailSeconds(v.JoinTime)
  1731. if v.JoinType == 1 {
  1732. item.MeetingTypeStr = "网络"
  1733. } else {
  1734. item.MeetingTypeStr = "电话"
  1735. }
  1736. item.MeetingAuthentication = v.AuthInfo
  1737. if v.DataType == 1 {
  1738. item.MeetingStatusStr = "直播"
  1739. } else {
  1740. item.MeetingStatusStr = "回放"
  1741. isPlayback = true
  1742. }
  1743. item.Position = v.Occupation
  1744. item.UseridEntity = v.UseridEntity
  1745. item.ActivityTime = activityDetail.ActivityTime
  1746. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  1747. item.CreateTime = time.Now()
  1748. mobileStr += "'" + v.UserPhone + "'" + ","
  1749. mobileArr = append(mobileArr, v.UserPhone)
  1750. needAddAttendanc = append(needAddAttendanc, item)
  1751. }
  1752. }
  1753. if isPlayback && mapActivityId[strconv.Itoa(activityDetail.ActivityId)] == "" {
  1754. activityIdsLongTime += strconv.Itoa(activityDetail.ActivityId) + ","
  1755. }
  1756. mobileStr = strings.TrimRight(mobileStr, ",")
  1757. if mobileStr == "" {
  1758. mobileStr = "1"
  1759. }
  1760. listUser, err := models.GetWxUserOutboundMobile(mobileStr)
  1761. if err != nil {
  1762. fmt.Println("GetWxUserOutboundMobile Err:", err.Error())
  1763. return err
  1764. }
  1765. for k, v := range needAddAttendanc {
  1766. for _, v2 := range listUser {
  1767. if v2.OutboundMobile == v.Mobile || v2.Mobile == v.Mobile {
  1768. if needAddAttendanc[k].CompanyId == 0 {
  1769. needAddAttendanc[k].CompanyId = v2.CompanyId
  1770. needAddAttendanc[k].SellerName = v2.SellerName
  1771. needAddAttendanc[k].CompanyName = v2.CompanyName
  1772. needAddAttendanc[k].IsMeetingStr = 1
  1773. }
  1774. }
  1775. }
  1776. }
  1777. //fmt.Println(mobileStr)
  1778. //参会记录
  1779. err = models.AddAttendancDetail(needAddAttendanc, activityDetail.ActivityId, mobileStr)
  1780. if err != nil {
  1781. fmt.Println("AddAttendancDetail Err:", err.Error())
  1782. return err
  1783. }
  1784. ////处理是否限制报名
  1785. err = AddCygxActivityRestrictSignupByAdmin(activityDetail.ActivityId)
  1786. if err != nil {
  1787. fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
  1788. return err
  1789. }
  1790. go ActivityUserLabelLogAdd(activityDetail.ActivityId, mobileArr)
  1791. AddctivitySignupDetailByJmcj(needAddAttendanc, activityDetail.ActivityId)
  1792. }
  1793. }
  1794. }
  1795. }
  1796. //获取需要处理的活动
  1797. listActivity, err := models.GetActivityListByDateTime(startDate, endDate, activityIds, detail.ConfigValue)
  1798. if err != nil {
  1799. fmt.Println("GetTacticsList Err:", err.Error())
  1800. return err
  1801. }
  1802. //通过本地去找进门财经的数据
  1803. for _, vAct := range listActivity {
  1804. doTime := utils.TimeRemoveHms2(vAct.ActivityTime)
  1805. findStartDate := doTime + " 00:00:00"
  1806. findEndDate := doTime + " 23:59:59"
  1807. nameSlice := strings.Split(vAct.ActivityName, "】")
  1808. //对于手动匹配到的活动数据也要更新
  1809. var activityName string
  1810. if len(nameSlice) > 1 {
  1811. if vAct.JmcjRoadshowTitle != "" {
  1812. activityName = vAct.JmcjRoadshowTitle
  1813. } else {
  1814. activityName = nameSlice[len(nameSlice)-1]
  1815. }
  1816. //activityName = nameSlice[len(nameSlice)-1]
  1817. if activityName != "" {
  1818. list, err := models.GetRoadshowDataList(activityName, findStartDate, findEndDate)
  1819. if err != nil {
  1820. fmt.Println("GetTacticsList Err:", err.Error())
  1821. return err
  1822. }
  1823. var isPlayback bool // 是否包含回放
  1824. needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
  1825. var mobileStr string
  1826. var mobileArr []string
  1827. if len(list) > 0 {
  1828. fmt.Println("原来的1", vAct.ActivityName)
  1829. fmt.Println("处理的2", activityName)
  1830. for _, v := range list {
  1831. if v.UserPhone != "" {
  1832. item := new(models.CygxActivityAttendanceDetail)
  1833. item.ActivityId = vAct.ActivityId
  1834. item.RealName = v.UserName
  1835. item.Mobile = v.UserPhone
  1836. item.CompanyName = v.Company
  1837. //item.SellerName = sellerName
  1838. item.FirstMeetingTime = v.FirstWatchTime
  1839. item.LastMeetingTime = v.LastWatchTime
  1840. item.Duration = utils.GetAttendanceDetailSeconds(v.JoinTime)
  1841. if v.JoinType == 1 {
  1842. item.MeetingTypeStr = "网络"
  1843. } else {
  1844. item.MeetingTypeStr = "电话"
  1845. }
  1846. item.MeetingAuthentication = v.AuthInfo
  1847. if v.DataType == 1 {
  1848. item.MeetingStatusStr = "直播"
  1849. } else {
  1850. item.MeetingStatusStr = "回放"
  1851. isPlayback = true
  1852. }
  1853. item.Position = v.Occupation
  1854. item.UseridEntity = v.UseridEntity
  1855. item.ActivityTime = vAct.ActivityTime
  1856. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  1857. item.CreateTime = time.Now()
  1858. mobileStr += "'" + v.UserPhone + "'" + ","
  1859. mobileArr = append(mobileArr, v.UserPhone)
  1860. needAddAttendanc = append(needAddAttendanc, item)
  1861. }
  1862. }
  1863. if isPlayback && mapActivityId[strconv.Itoa(vAct.ActivityId)] == "" {
  1864. activityIdsLongTime += strconv.Itoa(vAct.ActivityId) + ","
  1865. }
  1866. mobileStr = strings.TrimRight(mobileStr, ",")
  1867. if mobileStr == "" {
  1868. mobileStr = "1"
  1869. }
  1870. listUser, err := models.GetWxUserOutboundMobile(mobileStr)
  1871. if err != nil {
  1872. fmt.Println("GetWxUserOutboundMobile Err:", err.Error())
  1873. return err
  1874. }
  1875. for k, v := range needAddAttendanc {
  1876. for _, v2 := range listUser {
  1877. if v2.OutboundMobile == v.Mobile || v2.Mobile == v.Mobile {
  1878. if needAddAttendanc[k].CompanyId == 0 {
  1879. needAddAttendanc[k].CompanyId = v2.CompanyId
  1880. needAddAttendanc[k].SellerName = v2.SellerName
  1881. needAddAttendanc[k].CompanyName = v2.CompanyName
  1882. needAddAttendanc[k].IsMeetingStr = 1
  1883. }
  1884. }
  1885. }
  1886. }
  1887. ////参会记录
  1888. err = models.AddAttendancDetail(needAddAttendanc, vAct.ActivityId, mobileStr)
  1889. if err != nil {
  1890. fmt.Println("AddAttendancDetail Err:", err.Error())
  1891. return err
  1892. }
  1893. ////处理是否限制报名
  1894. err = AddCygxActivityRestrictSignupByAdmin(vAct.ActivityId)
  1895. if err != nil {
  1896. fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
  1897. return err
  1898. }
  1899. activityIds += strconv.Itoa(vAct.ActivityId) + ","
  1900. go ActivityUserLabelLogAdd(vAct.ActivityId, mobileArr)
  1901. AddctivitySignupDetailByJmcj(needAddAttendanc, vAct.ActivityId)
  1902. }
  1903. }
  1904. }
  1905. }
  1906. if activityIdsLongTime != "" {
  1907. activityIdsLongTime = strings.TrimRight(activityIdsLongTime, ",")
  1908. activityIdsLongTime = detail.ConfigValue + "," + activityIdsLongTime
  1909. go models.UpdateConfigByCode(activityIdsLongTime, configCode)
  1910. }
  1911. activityIds = strings.TrimRight(activityIds, ",")
  1912. if activityIds != "" {
  1913. detailList, err := models.GetActivityAttendanceDetailList(activityIds)
  1914. if err != nil {
  1915. fmt.Println("GetActivityAttendanceDetailList Err:", err.Error())
  1916. return err
  1917. }
  1918. //添加报名日志 (下载使用)
  1919. err = models.AddCygxActivityMeetDetailLogOnlineByList(detailList, activityIds)
  1920. if err != nil {
  1921. fmt.Println("AddCygxActivityMeetDetailLogOnline Err:", err.Error())
  1922. return err
  1923. }
  1924. }
  1925. fmt.Println("结束路演同步")
  1926. return
  1927. }
  1928. // 查研观向处理活动用户限制报名
  1929. func AddCygxActivityRestrictSignupByAdmin(activityId int) (err error) {
  1930. defer func() {
  1931. if err != nil {
  1932. fmt.Println("err:", err)
  1933. go utils.SendAlarmMsg("查研观向处理活动用户限制报名失败,Err:"+err.Error()+"activityId"+strconv.Itoa(activityId), 3)
  1934. }
  1935. }()
  1936. activityInfo, e := models.GetAddActivityInfoById(activityId)
  1937. if e != nil {
  1938. err = errors.New("GetAddActivityInfoById" + e.Error())
  1939. return
  1940. }
  1941. if activityInfo == nil {
  1942. return
  1943. }
  1944. //不限制报名的不做爽约限制处理
  1945. //if activityInfo.IsLimitPeople > 0 {
  1946. //total, err := cygx.GetActivitySignupNomeetingCount(activityId)
  1947. if err != nil {
  1948. return
  1949. }
  1950. mobileList, _ := models.GetUserMeetingMobile(activityId)
  1951. var userIdArr []int
  1952. if len(mobileList) > 0 {
  1953. for _, v := range mobileList {
  1954. userIdArr = append(userIdArr, v.UserId)
  1955. }
  1956. lenuserIdArr := len(userIdArr)
  1957. var condition string
  1958. var pars []interface{}
  1959. condition = ` AND user_id IN (` + utils.GetOrmInReplace(lenuserIdArr) + `)`
  1960. pars = append(pars, userIdArr)
  1961. restrictSignupList, e := models.GetCygxActivityRestrictSignupList(condition, pars, 0, 9999)
  1962. if e != nil {
  1963. err = errors.New("GetCygxActivityRestrictSignupList" + e.Error())
  1964. return
  1965. }
  1966. //获取这些用户是否被加入到限制报名了
  1967. maptotalRestrict := make(map[int]bool)
  1968. for _, v := range restrictSignupList {
  1969. maptotalRestrict[v.UserId] = true
  1970. }
  1971. pars = make([]interface{}, 0)
  1972. 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) + `)`
  1973. pars = append(pars, userIdArr)
  1974. listSignup, e := models.GetActivitySignupInnerActivityList(condition, pars)
  1975. if e != nil && e.Error() != utils.ErrNoRow() {
  1976. err = errors.New("GetActivitySignupInnerActivityList" + e.Error())
  1977. return
  1978. }
  1979. mapNomeet := make(map[int]int)
  1980. if len(listSignup) > 0 {
  1981. for _, v := range listSignup {
  1982. mapNomeet[v.UserId]++
  1983. }
  1984. }
  1985. var userIdDelArr []int
  1986. for _, v := range mobileList {
  1987. //如果加入了爽约限制但是爽约次数少于3条就删除爽约记录
  1988. if maptotalRestrict[v.UserId] && mapNomeet[v.UserId] < 3 {
  1989. userIdDelArr = append(userIdDelArr, v.UserId)
  1990. }
  1991. }
  1992. if len(userIdDelArr) > 0 {
  1993. e = models.DeleteCygxActivityRestrictSignupByUserIds(userIdDelArr)
  1994. if e != nil {
  1995. err = errors.New("DeleteCygxActivityRestrictSignupByUserIds" + e.Error())
  1996. return
  1997. }
  1998. }
  1999. }
  2000. //if total == 0 {
  2001. // return
  2002. //}
  2003. //}
  2004. list, e := models.GetActivitySignupNomeetingCountList(activityId)
  2005. if e != nil {
  2006. err = errors.New("GetActivitySignupNomeetingCountList" + e.Error())
  2007. return
  2008. }
  2009. var userIdSiginArr []int
  2010. var items []*models.CygxActivitySignupBreak
  2011. for _, v := range list {
  2012. userIdSiginArr = append(userIdSiginArr, v.UserId)
  2013. //添加爽约记录
  2014. item := new(models.CygxActivitySignupBreak)
  2015. item.UserId = v.UserId
  2016. item.ActivityId = v.ActivityId
  2017. item.CreateTime = time.Now()
  2018. item.Mobile = v.Mobile
  2019. item.Email = v.Email
  2020. item.CompanyId = v.CompanyId
  2021. item.CompanyName = v.CompanyName
  2022. item.RealName = v.RealName
  2023. item.SellerName = v.SellerName
  2024. items = append(items, item)
  2025. }
  2026. if len(list) == 0 {
  2027. return
  2028. }
  2029. var itemsRestrict []*models.CygxActivityRestrictSignup
  2030. maptotalRestrict := make(map[int]bool)
  2031. lenuserIdSiginArr := len(userIdSiginArr)
  2032. var condition string
  2033. var pars []interface{}
  2034. condition = ` AND user_id IN (` + utils.GetOrmInReplace(lenuserIdSiginArr) + `)`
  2035. pars = append(pars, userIdSiginArr)
  2036. restrictSignupList, e := models.GetCygxActivityRestrictSignupList(condition, pars, 0, 9999)
  2037. if e != nil {
  2038. err = errors.New("GetCygxActivityRestrictSignupList" + e.Error())
  2039. return
  2040. }
  2041. //获取这些用户是否被加入到限制报名了
  2042. for _, v := range restrictSignupList {
  2043. maptotalRestrict[v.UserId] = true
  2044. }
  2045. pars = make([]interface{}, 0)
  2046. 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) + `)`
  2047. pars = append(pars, userIdSiginArr)
  2048. listSignup, e := models.GetActivitySignupInnerActivityList(condition, pars)
  2049. if e != nil && e.Error() != utils.ErrNoRow() {
  2050. err = errors.New("GetActivitySignupInnerActivityList" + e.Error())
  2051. return
  2052. }
  2053. mapNomeet := make(map[int]int)
  2054. if len(listSignup) > 0 {
  2055. for _, v := range listSignup {
  2056. mapNomeet[v.UserId]++
  2057. }
  2058. }
  2059. for _, v := range mobileList {
  2060. //如果加入了爽约限制但是爽约次数少于3条就删除爽约记录
  2061. if !maptotalRestrict[v.UserId] && mapNomeet[v.UserId] >= 3 {
  2062. itemRestrict := new(models.CygxActivityRestrictSignup)
  2063. itemRestrict.UserId = v.UserId
  2064. itemRestrict.CreateTime = time.Now()
  2065. itemRestrict.Mobile = v.Mobile
  2066. itemRestrict.Email = v.Email
  2067. itemRestrict.CompanyId = v.CompanyId
  2068. itemRestrict.CompanyName = v.CompanyName
  2069. itemRestrict.IsRestrict = 1
  2070. itemsRestrict = append(itemsRestrict, itemRestrict)
  2071. }
  2072. }
  2073. err = models.DeleteCygxActivitySignupBreakById(activityId)
  2074. if err != nil {
  2075. err = errors.New("DeleteCygxActivitySignupBreakById" + err.Error())
  2076. return
  2077. }
  2078. //添加爽约记录
  2079. if len(items) > 0 {
  2080. _, e = models.AddCygxActivitySignupBreakList(items)
  2081. if e != nil {
  2082. err = errors.New("AddCygxActivitySignupBreakList, Err: " + e.Error())
  2083. return
  2084. }
  2085. }
  2086. //添加报名限制
  2087. if len(itemsRestrict) > 0 {
  2088. _, e = models.AddCygxActivityRestrictSignupList(itemsRestrict)
  2089. if e != nil {
  2090. err = errors.New("AddCygxActivityRestrictSignupList, Err: " + e.Error())
  2091. return
  2092. }
  2093. }
  2094. return
  2095. }
  2096. // 判断预约纪要按钮是否显示
  2097. func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
  2098. if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
  2099. isShowAppointment = true
  2100. }
  2101. if activityTypeId == 5 && chartPermissionName == "医药" {
  2102. isShowAppointment = true
  2103. }
  2104. return
  2105. }
  2106. // 判断预约纪要按钮是否显示
  2107. func IsShowAppointmentByactivityInfo(item *models.ActivityDetail, chartPermissionName string) (isShowAppointment bool) {
  2108. activityTypeId := item.ActivityTypeId
  2109. if activityTypeId == 1 || activityTypeId == 3 || activityTypeId == 4 {
  2110. isShowAppointment = true
  2111. }
  2112. if activityTypeId == 5 && chartPermissionName == "医药" {
  2113. isShowAppointment = true
  2114. }
  2115. if activityTypeId == 2 && item.IsLimitPeople == 0 {
  2116. isShowAppointment = true
  2117. }
  2118. return
  2119. }
  2120. // 用户报告操作行为,模板消息推送 (先放在活动模块下,避免代码冲突)
  2121. func ArticleUserRemind(user *models.WxUserItem, articleDetail *models.ArticleDetail, source int) (err error) {
  2122. defer func() {
  2123. if err != nil {
  2124. go utils.SendAlarmMsg(" 用户报告操作行为,模板消息推送失败"+fmt.Sprint("UserId:", user.UserId, "ArticleId:", articleDetail.ArticleId), 2)
  2125. }
  2126. }()
  2127. countUser, err := models.GetUserRemind(user.UserId)
  2128. if err != nil {
  2129. return err
  2130. }
  2131. if countUser == 0 {
  2132. return err
  2133. }
  2134. var sourceMsg string
  2135. if source == 1 {
  2136. sourceMsg = "阅读报告"
  2137. } else {
  2138. sourceMsg = "收藏报告"
  2139. }
  2140. //获取销售手机号
  2141. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2142. if err != nil && err.Error() != utils.ErrNoRow() {
  2143. return err
  2144. }
  2145. if sellerItemQy != nil {
  2146. articleId := articleDetail.ArticleId
  2147. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  2148. if e != nil {
  2149. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  2150. return
  2151. }
  2152. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  2153. openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  2154. if err != nil {
  2155. err = errors.New("GetWxOpenIdByMobileList, Err: " + e.Error())
  2156. return err
  2157. }
  2158. var keyword1 string
  2159. var keyword2 string
  2160. keyword1 = articleDetail.Title
  2161. keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
  2162. SendWxMsgWithArticleUserRemind(keyword1, keyword2, openIdList, articleId)
  2163. if articleDetail.ArticleTypeId > 0 {
  2164. // 类目模版买方研选
  2165. openIdListMfyx, e := models.GetMfyxWxOpenIdByMobileList(sellerItemQy.Mobile)
  2166. if e != nil {
  2167. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  2168. return err
  2169. }
  2170. var redirectUrl string
  2171. keyword1 = utils.TruncateActivityNameString(user.RealName + "-" + user.CompanyName)
  2172. keyword2 = fmt.Sprint("互动提醒:", sourceMsg)
  2173. keyword3 := utils.TruncateActivityNameString(articleDetail.Title)
  2174. keyword4 := time.Now().Format(utils.FormatDateTimeMinute2)
  2175. redirectUrl = utils.WX_MSG_PATH_YX_ARTICLE_DETAIL + strconv.Itoa(articleId)
  2176. SendWxCategoryMsgWithActivityUserRemind(keyword1, keyword2, keyword3, keyword4, redirectUrl, openIdListMfyx, articleId)
  2177. }
  2178. }
  2179. return
  2180. }
  2181. // 用户活动操作行为,模板消息推送
  2182. func ActivityUserRemind(user *models.WxUserItem, activityDetail *models.ActivityDetail, source int) (err error) {
  2183. defer func() {
  2184. if err != nil {
  2185. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ActivityUserRemind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  2186. }
  2187. }()
  2188. //获取销售手机号
  2189. countUser, e := models.GetUserRemind(user.UserId)
  2190. if e != nil {
  2191. err = errors.New("GetUserRemind, Err: " + e.Error())
  2192. return
  2193. }
  2194. //获取销售手机号
  2195. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2196. if e != nil && e.Error() != utils.ErrNoRow() {
  2197. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  2198. return
  2199. }
  2200. if sellerItemQy == nil {
  2201. err = nil
  2202. return
  2203. }
  2204. //某销售下的所有客户活动报名/预约外呼时,模板消息提醒该销售(可设置销售范围,随时增减销售)
  2205. conf, e := models.GetConfigByCode("tpl_msg_seller_mobile")
  2206. if e != nil {
  2207. err = errors.New("GetConfigByCode, Err: " + e.Error())
  2208. return
  2209. }
  2210. //如果用户没有设置消息提醒,而且销售的手机号也没有添加到配置中,那么就不推送模版消息
  2211. if countUser == 0 && !strings.Contains(conf.ConfigValue, sellerItemQy.Mobile) {
  2212. err = nil
  2213. return
  2214. }
  2215. var sourceMsg string
  2216. if source == 1 {
  2217. sourceMsg = "预约外呼"
  2218. } else if source == 2 {
  2219. sourceMsg = "设置会议提醒"
  2220. } else if source == 3 {
  2221. sourceMsg = "预约纪要"
  2222. } else if source == 4 {
  2223. sourceMsg = "活动报名"
  2224. }
  2225. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  2226. if e != nil {
  2227. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  2228. return
  2229. }
  2230. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  2231. openIdList, e := models.GetUserRecordListByMobile(4, sllerAndShareMobiles)
  2232. if e != nil {
  2233. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error())
  2234. return err
  2235. }
  2236. var keyword1 string
  2237. var keyword2 string
  2238. keyword1 = activityDetail.ActivityName
  2239. keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
  2240. SendWxMsgWithActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
  2241. // 类目模版买方研选
  2242. if activityDetail.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  2243. openIdListMfyx, e := models.GetMfyxWxOpenIdByMobileList(sellerItemQy.Mobile)
  2244. if e != nil {
  2245. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  2246. return err
  2247. }
  2248. var redirectUrl string
  2249. keyword1 = utils.TruncateActivityNameString(user.RealName + "-" + user.CompanyName)
  2250. keyword2 = fmt.Sprint("互动提醒:", sourceMsg)
  2251. keyword3 := utils.TruncateActivityNameString(activityDetail.ActivityName)
  2252. keyword4 := time.Now().Format(utils.FormatDateTimeMinute2)
  2253. redirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId)
  2254. SendWxCategoryMsgWithActivityUserRemind(keyword1, keyword2, keyword3, keyword4, redirectUrl, openIdListMfyx, activityDetail.ActivityId)
  2255. }
  2256. return
  2257. }
  2258. // 用户专项调研操作行为,模板消息推送
  2259. //func SpecialActivityUserRemind(user *models.WxUserItem, activityDetail *models.CygxActivitySpecialDetail, source int) (err error) {
  2260. // defer func() {
  2261. // if err != nil {
  2262. // go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  2263. // go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  2264. // }
  2265. // }()
  2266. // countUser, err := models.GetUserRemind(user.UserId)
  2267. // if err != nil {
  2268. // return err
  2269. // }
  2270. // if countUser == 0 {
  2271. // return err
  2272. // }
  2273. // var sourceMsg string
  2274. // if source == 1 {
  2275. // sourceMsg = "预报名调研"
  2276. // }
  2277. // //获取销售手机号
  2278. // sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2279. // if err != nil && err.Error() != utils.ErrNoRow() {
  2280. // return err
  2281. // }
  2282. // if sellerItemQy != nil {
  2283. // openIdList, err := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
  2284. // if err != nil {
  2285. // fmt.Println(err)
  2286. // return err
  2287. // }
  2288. // var keyword1 string
  2289. // var keyword2 string
  2290. // keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:", sourceMsg)
  2291. // keyword2 = activityDetail.ResearchTheme
  2292. // SendWxMsgWithSpecialActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
  2293. // }
  2294. // return
  2295. //}
  2296. //func init() {
  2297. // DoActivityOnenIdWxTemplateMsg()
  2298. //}
  2299. // 周日下午四点半推送全部活动
  2300. func DoActivityOnenIdWxTemplateMsg(cont context.Context) (err error) {
  2301. var msg string
  2302. defer func() {
  2303. if err != nil {
  2304. go utils.SendAlarmMsg("周日下午四点半推送全部活动失败,DoActivityOnenIdWxTemplateMsg ErrMsg:"+err.Error(), 2)
  2305. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "DoActivityOnenIdWxTemplateMsg ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  2306. fmt.Println(err)
  2307. }
  2308. if msg != "" {
  2309. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  2310. }
  2311. }()
  2312. var condition string
  2313. var pars []interface{}
  2314. openidPowerListMobile, err := models.GetCygxUserRecordPower(condition, pars)
  2315. if err != nil {
  2316. return err
  2317. }
  2318. var mobileArr []string
  2319. for _, v := range openidPowerListMobile {
  2320. mobileArr = append(mobileArr, v.Mobile)
  2321. }
  2322. openidPowerList, err := models.GetWxOpenIdByMobileSliceList(mobileArr)
  2323. if err != nil {
  2324. return err
  2325. }
  2326. first := "近期所有行业活动预告,欢迎参与"
  2327. keyword1 := "下周活动预告"
  2328. keyword2 := "已发布"
  2329. keyword3 := ""
  2330. keyword4 := "点击查看下周活动列表"
  2331. SendActivityOnenIdWxTemplateMsg(first, keyword1, keyword2, keyword3, keyword4, openidPowerList)
  2332. return
  2333. }
  2334. func ActivityButtonShow(item *models.ActivityDetail) (activityDetail *models.ActivityDetail) {
  2335. if item.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  2336. item.IsResearch = true
  2337. }
  2338. activityDetail = item
  2339. //IsShowAppointment bool `description:"是否展示预约纪要"`
  2340. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  2341. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  2342. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  2343. //IsShowSignup bool `description:"是否展示我要报名"`
  2344. activityTypeIdMap := GetActivityTypeIdMap()
  2345. activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId] // 线上还是线下
  2346. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  2347. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  2348. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  2349. activityDetail.SiginupDeadline = ""
  2350. }
  2351. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  2352. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  2353. activityDetail.CancelDeadline = ""
  2354. }
  2355. activityTimeText := activityDetail.ActivityTimeText
  2356. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  2357. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  2358. activityDetail.ActivityTimeText = activityTimeText
  2359. if activityDetail.SourceType != 2 {
  2360. activityDetail.SourceType = 1
  2361. }
  2362. activityDetail.IsShowAppointment = false
  2363. //易董的操作按钮都隐藏
  2364. if activityDetail.YidongActivityId != "" {
  2365. activityDetail.SourceType = 1
  2366. activityDetail.IsShowSignup = false
  2367. activityDetail.IsShowDetails = true
  2368. activityDetail.IsExternalLabel = true
  2369. activityDetail.IsResearch = false
  2370. activityDetail.IsResearchSpecial = false
  2371. return
  2372. }
  2373. //专家电话会 1
  2374. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  2375. activityDetail.IsShowHelpSsk = true
  2376. }
  2377. //新的是否展示规则
  2378. if activityDetail.IsCanAppointmentMinutes == 1 {
  2379. activityDetail.IsShowAppointment = true
  2380. } else {
  2381. activityDetail.IsShowAppointment = false
  2382. }
  2383. if activityDetail.ActiveState == "1" {
  2384. //专家电话会 1
  2385. //专家电话会限制人数的展示我要报名,不限制的展示预约外外呼
  2386. if activityDetail.ActivityTypeId == 1 {
  2387. //articleDetail.IsShowOutboundCall = true
  2388. if activityDetail.LimitPeopleNum == 0 {
  2389. activityDetail.IsShowOutboundCall = true
  2390. //articleDetail.IsShowHelpSsk = true
  2391. } else {
  2392. activityDetail.IsShowSignup = true
  2393. }
  2394. activityDetail.IsShowMeetingReminder = true
  2395. activityDetail.IsShowHelpSsk = true
  2396. }
  2397. //分析师电话会 2
  2398. if activityDetail.ActivityTypeId == 2 {
  2399. if activityDetail.LimitPeopleNum == 0 {
  2400. activityDetail.IsShowOutboundCall = true
  2401. //articleDetail.IsShowHelpSsk = true
  2402. } else {
  2403. activityDetail.IsShowSignup = true
  2404. }
  2405. activityDetail.IsShowMeetingReminder = true
  2406. }
  2407. //公司调研电话会 3
  2408. if activityDetail.ActivityTypeId == 3 {
  2409. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  2410. activityDetail.IsShowSignup = true
  2411. } else {
  2412. activityDetail.IsShowMeetingReminder = true
  2413. activityDetail.IsShowOutboundCall = true
  2414. }
  2415. }
  2416. //公司线下调研 4
  2417. if activityDetail.ActivityTypeId == 4 {
  2418. activityDetail.IsShowSignup = true
  2419. }
  2420. //专家线下沙龙 5
  2421. if activityDetail.ActivityTypeId == 5 {
  2422. activityDetail.IsShowSignup = true
  2423. }
  2424. //分析师线下沙龙 6
  2425. if activityDetail.ActivityTypeId == 6 {
  2426. activityDetail.IsShowSignup = true
  2427. }
  2428. //分析师电话会(C类) 7
  2429. if activityDetail.ActivityTypeId == 7 {
  2430. activityDetail.IsShowSignup = true
  2431. activityDetail.IsShowMeetingReminder = true
  2432. activityDetail.ActivityTypeName = "分析师电话会"
  2433. }
  2434. //买方线下交流 8 // 查研观向 11.0
  2435. if activityDetail.ActivityTypeId == 8 {
  2436. activityDetail.IsShowSignup = true
  2437. }
  2438. }
  2439. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  2440. if activityDetail.IsYidongConduct {
  2441. activityDetail.IsShowSignup = true
  2442. activityDetail.IsShowOutboundCall = false
  2443. }
  2444. return
  2445. }
  2446. func ActivityArrButtonShow(items []*models.ActivityDetail) (activityDetails []*models.ActivityDetail) {
  2447. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  2448. activityTypeIdMap := GetActivityTypeIdMap()
  2449. for _, activityDetail := range items {
  2450. activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId] // 线上还是线下
  2451. if activityDetail.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  2452. activityDetail.IsResearch = true
  2453. }
  2454. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  2455. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] {
  2456. activityDetail.IsResearchSpecial = true
  2457. }
  2458. //IsShowAppointment bool `description:"是否展示预约纪要"`
  2459. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  2460. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  2461. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  2462. //IsShowSignup bool `description:"是否展示我要报名"`
  2463. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  2464. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  2465. activityDetail.SiginupDeadline = ""
  2466. }
  2467. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  2468. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  2469. activityDetail.CancelDeadline = ""
  2470. }
  2471. activityTimeText := activityDetail.ActivityTimeText
  2472. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  2473. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  2474. activityDetail.ActivityTimeText = activityTimeText
  2475. if activityDetail.SourceType != 2 {
  2476. activityDetail.SourceType = 1
  2477. }
  2478. activityDetail.IsShowAppointment = false
  2479. //易董的操作按钮都隐藏
  2480. if activityDetail.YidongActivityId != "" {
  2481. activityDetail.SourceType = 1
  2482. activityDetail.IsShowSignup = false
  2483. activityDetail.IsShowDetails = true
  2484. } else {
  2485. //专家电话会 1
  2486. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  2487. activityDetail.IsShowHelpSsk = true
  2488. }
  2489. //新的是否展示规则
  2490. if activityDetail.IsCanAppointmentMinutes == 1 {
  2491. activityDetail.IsShowAppointment = true
  2492. } else {
  2493. activityDetail.IsShowAppointment = false
  2494. }
  2495. if activityDetail.ActiveState == "1" {
  2496. //专家电话会 1
  2497. //专家电话会限制人数的展示我要报名,不限制的展示预约外外呼
  2498. if activityDetail.ActivityTypeId == 1 {
  2499. //articleDetail.IsShowOutboundCall = true
  2500. if activityDetail.LimitPeopleNum == 0 {
  2501. activityDetail.IsShowOutboundCall = true
  2502. //articleDetail.IsShowHelpSsk = true
  2503. } else {
  2504. activityDetail.IsShowSignup = true
  2505. }
  2506. activityDetail.IsShowMeetingReminder = true
  2507. activityDetail.IsShowHelpSsk = true
  2508. }
  2509. //分析师电话会 2
  2510. if activityDetail.ActivityTypeId == 2 {
  2511. if activityDetail.LimitPeopleNum == 0 {
  2512. activityDetail.IsShowOutboundCall = true
  2513. //articleDetail.IsShowHelpSsk = true
  2514. } else {
  2515. activityDetail.IsShowSignup = true
  2516. }
  2517. activityDetail.IsShowMeetingReminder = true
  2518. }
  2519. //公司调研电话会 3
  2520. if activityDetail.ActivityTypeId == 3 {
  2521. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  2522. activityDetail.IsShowSignup = true
  2523. } else {
  2524. activityDetail.IsShowMeetingReminder = true
  2525. activityDetail.IsShowOutboundCall = true
  2526. }
  2527. }
  2528. //公司线下调研 4
  2529. if activityDetail.ActivityTypeId == 4 {
  2530. activityDetail.IsShowSignup = true
  2531. }
  2532. //专家线下沙龙 5
  2533. if activityDetail.ActivityTypeId == 5 {
  2534. activityDetail.IsShowSignup = true
  2535. }
  2536. //分析师线下沙龙 6
  2537. if activityDetail.ActivityTypeId == 6 {
  2538. activityDetail.IsShowSignup = true
  2539. }
  2540. //分析师电话会(C类) 7
  2541. if activityDetail.ActivityTypeId == 7 {
  2542. activityDetail.IsShowSignup = true
  2543. activityDetail.IsShowMeetingReminder = true
  2544. activityDetail.ActivityTypeName = "分析师电话会"
  2545. }
  2546. //买方线下交流 8 // 查研观向 11.0
  2547. if activityDetail.ActivityTypeId == 8 {
  2548. activityDetail.IsShowSignup = true
  2549. }
  2550. }
  2551. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  2552. if activityDetail.IsYidongConduct {
  2553. activityDetail.IsShowSignup = true
  2554. activityDetail.IsShowOutboundCall = false
  2555. }
  2556. }
  2557. //如果是易董同步过来的,只展示外部资源标签
  2558. if activityDetail.YidongActivityId != "" {
  2559. activityDetail.IsExternalLabel = true
  2560. activityDetail.IsResearch = false
  2561. activityDetail.IsResearchSpecial = false
  2562. }
  2563. activityDetails = append(activityDetails, activityDetail)
  2564. }
  2565. return
  2566. }
  2567. // GetActivityNewLabelMap 获取活动【新】标签Map
  2568. func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) {
  2569. labelMap = make(map[int]bool, 0)
  2570. industryNewMap = make(map[int]bool, 0)
  2571. if len(activityIds) == 0 {
  2572. return
  2573. }
  2574. // 获取活动关联的产业
  2575. var groupCond string
  2576. var groupPars []interface{}
  2577. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 `
  2578. groupPars = append(groupPars, activityIds)
  2579. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  2580. if e != nil {
  2581. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  2582. return
  2583. }
  2584. activityIndustryMap := make(map[int][]int, 0)
  2585. industryIds := make([]int, 0)
  2586. for i := range groups {
  2587. industryIds = append(industryIds, groups[i].IndustrialManagementId)
  2588. activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId)
  2589. }
  2590. // 获取新产业Map
  2591. industryLabelMap, e := GetIndustryNewLabelMap(industryIds)
  2592. if e != nil {
  2593. err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  2594. return
  2595. }
  2596. // 判断活动是否为新
  2597. for k := range industryLabelMap {
  2598. for k2, v2 := range activityIndustryMap {
  2599. if labelMap[k2] {
  2600. continue
  2601. }
  2602. // 活动的产业ID中存在一个新产业即为新活动
  2603. if utils.InArrayByInt(v2, k) {
  2604. labelMap[k2] = true
  2605. }
  2606. }
  2607. }
  2608. ////产业关联的弘则报告发布日期在三个月以内的活动、产业显示 NEW标签
  2609. //articNewLabel, e := GetArticNewLabelWhithActivity3Month()
  2610. //if e != nil {
  2611. // err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  2612. // return
  2613. //}
  2614. //for k := range articNewLabel {
  2615. // labelMap[k] = true
  2616. //}
  2617. return
  2618. }
  2619. // GetActivityVoiceResp 处理活动音频回放
  2620. func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) {
  2621. activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId)
  2622. if err != nil && err.Error() != utils.ErrNoRow() {
  2623. return
  2624. }
  2625. mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq)
  2626. if len(activityVoiceList) > 0 {
  2627. for _, v := range activityVoiceList {
  2628. mapActivityVoice[v.ActivityId] = v
  2629. }
  2630. }
  2631. mapItem = mapActivityVoice
  2632. return
  2633. }
  2634. // AddActivitykeyWordSearch 添加活动搜索记录
  2635. func AddActivitykeyWordSearch(keyWordSearch string, user *models.WxUserItem) {
  2636. if keyWordSearch != "" {
  2637. keyWordItem := new(models.CygxUserSearchKeyWord)
  2638. keyWordItem.UserId = user.UserId
  2639. keyWordItem.KeyWord = keyWordSearch
  2640. keyWordItem.PageType = "ActivitSearch"
  2641. keyWordItem.CreateTime = time.Now()
  2642. go models.AddUserSearchKeyWord(keyWordItem)
  2643. }
  2644. }
  2645. // GetActivityVideoResp 处理活动视频频回放
  2646. func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) {
  2647. var condition string
  2648. var ativityVIdstr string
  2649. for _, v := range mapActivityId {
  2650. ativityVIdstr += strconv.Itoa(v) + ","
  2651. }
  2652. if ativityVIdstr == "" {
  2653. return
  2654. }
  2655. ativityVIdstr = strings.TrimRight(ativityVIdstr, ",")
  2656. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  2657. var pars []interface{}
  2658. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  2659. //condition += ` AND art.activity_time > ? `
  2660. //pars = append(pars, endTime)
  2661. videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000)
  2662. if e != nil && e.Error() != utils.ErrNoRow() {
  2663. err = e
  2664. return
  2665. }
  2666. mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp)
  2667. if len(videoList) > 0 {
  2668. for _, v := range videoList {
  2669. mapActivityVideo[v.ActivityId] = v
  2670. }
  2671. }
  2672. mapItem = mapActivityVideo
  2673. return
  2674. }
  2675. // 用户音视频回放操作操作行为,模板消息推送
  2676. func ActivityVideoUserRmind(user *models.WxUserItem, activityId, fileType int) (err error) {
  2677. defer func() {
  2678. if err != nil {
  2679. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  2680. }
  2681. }()
  2682. countUser, err := models.GetUserRemind(user.UserId)
  2683. if err != nil {
  2684. return err
  2685. }
  2686. if countUser == 0 {
  2687. return err
  2688. }
  2689. var first string
  2690. var keyword1 string
  2691. var keyword2 string
  2692. var keyword3 string
  2693. var keyword4 string
  2694. var remark string
  2695. //获取销售手机号
  2696. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2697. if err != nil && err.Error() != utils.ErrNoRow() {
  2698. return err
  2699. }
  2700. if sellerItemQy != nil {
  2701. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  2702. if e != nil {
  2703. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  2704. return
  2705. }
  2706. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  2707. openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  2708. if e != nil {
  2709. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  2710. return
  2711. }
  2712. //TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
  2713. if fileType == 1 {
  2714. activityInfo, e := models.GetCygxActivityVideoByActivityId(activityId)
  2715. if e != nil {
  2716. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  2717. return
  2718. }
  2719. if activityInfo == nil {
  2720. return
  2721. }
  2722. keyword1 = activityInfo.VideoName
  2723. keyword2 = fmt.Sprint("互动:播放视频,", user.RealName, "--", user.CompanyName)
  2724. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放视频")
  2725. } else {
  2726. activityInfo, e := models.GetCygxActivityVoiceByActivityId(activityId)
  2727. if e != nil {
  2728. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  2729. return
  2730. }
  2731. if activityInfo == nil {
  2732. return
  2733. }
  2734. keyword1 = activityInfo.VoiceName
  2735. keyword2 = fmt.Sprint("互动:播放音频,", user.RealName, "--", user.CompanyName)
  2736. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放音频")
  2737. }
  2738. //keyword2 = "__"
  2739. //remark = "点击查看活动详情"
  2740. openIdArr := make([]string, 0)
  2741. for _, v := range openIdList {
  2742. openIdArr = append(openIdArr, v.OpenId)
  2743. }
  2744. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  2745. sendInfo := new(SendWxTemplate)
  2746. sendInfo.First = first
  2747. sendInfo.Keyword1 = keyword1
  2748. sendInfo.Keyword2 = keyword2
  2749. sendInfo.Keyword3 = keyword3
  2750. sendInfo.Keyword4 = keyword4
  2751. sendInfo.Remark = remark
  2752. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  2753. sendInfo.RedirectUrl = redirectUrl
  2754. sendInfo.RedirectTarget = 3
  2755. sendInfo.Resource = strconv.Itoa(activityId)
  2756. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  2757. sendInfo.OpenIdArr = openIdArr
  2758. err = PublicSendTemplateMsg(sendInfo)
  2759. if err != nil {
  2760. return
  2761. }
  2762. }
  2763. return
  2764. }
  2765. // 解析活动填写的报告链接
  2766. func GetActivityReportLinkToArticleList(item *models.ActivityDetail) (items []*models.ActivityArticleResp, err error) {
  2767. reportLink := item.ReportLink
  2768. //处理活动的
  2769. var articleIds []int
  2770. var articleList []string
  2771. if strings.Contains(reportLink, ";") {
  2772. articleList = strings.Split(reportLink, ";")
  2773. } else {
  2774. articleList = strings.Split(reportLink, ";")
  2775. }
  2776. for _, v := range articleList {
  2777. linkList := strings.Split(v, "/")
  2778. if linkList[len(linkList)-1] != "" {
  2779. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  2780. articleIds = append(articleIds, linkArticleId)
  2781. }
  2782. }
  2783. lenarticleIds := len(articleIds)
  2784. if lenarticleIds == 0 {
  2785. return
  2786. }
  2787. var condition string
  2788. var pars []interface{}
  2789. pars = make([]interface{}, 0)
  2790. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
  2791. pars = append(pars, articleIds)
  2792. listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  2793. if e != nil {
  2794. err = errors.New("GetResourceDataList, Err: " + e.Error())
  2795. return
  2796. }
  2797. if len(listArticle) > 0 {
  2798. for _, v := range listArticle {
  2799. artItem := new(models.ActivityArticleResp)
  2800. artItem.ArticleId = v.ArticleId
  2801. artItem.Title = v.Title
  2802. items = append(items, artItem)
  2803. }
  2804. }
  2805. return
  2806. }
  2807. // GetActivityCityResp 获取活动关联城市,当同一个活动标签对应多个城市的时候,展示最近举办的活动
  2808. func GetActivityCityResp() (mapItem map[string]string, err error) {
  2809. activityList, err := models.GetActivityLabelListCity()
  2810. if err != nil && err.Error() != utils.ErrNoRow() {
  2811. return
  2812. }
  2813. mapActivityCity := make(map[string]string)
  2814. if len(activityList) > 0 {
  2815. for _, v := range activityList {
  2816. if v.ActivityTypeId == utils.C_CLASS_ACTIVITY_TYPE_ID {
  2817. v.ActivityTypeId = utils.ANALYST_TELL_ACTIVITY_TYPE_ID
  2818. }
  2819. //如果城市民称长度大于2,那么就不显示
  2820. if utf8.RuneCountInString(v.City) != 2 || mapActivityCity[fmt.Sprint(v.Label, "{|}", v.ActivityTypeId)] != "" {
  2821. continue
  2822. }
  2823. mapActivityCity[fmt.Sprint(v.Label, "{|}", v.ActivityTypeId)] = v.City
  2824. }
  2825. }
  2826. mapItem = mapActivityCity
  2827. return
  2828. }
  2829. // UpdateIsSendYidongSignUp更改活动是否向易董推送报名名单的状态
  2830. func UpdateIsSendYidongSignUp(activityId int) (err error) {
  2831. defer func() {
  2832. if err != nil {
  2833. fmt.Println(err)
  2834. go utils.SendAlarmMsg("更改活动是否向易董推送报名名单的状态,失败,活动ID:"+strconv.Itoa(activityId)+err.Error(), 2)
  2835. }
  2836. }()
  2837. err = models.UPdateSendedYiDongSignUp(activityId)
  2838. return
  2839. }
  2840. // 获取活动线上还是线下的类型
  2841. func GetActivityTypeIdMap() (mapResp map[int]int) {
  2842. var err error
  2843. defer func() {
  2844. if err != nil {
  2845. fmt.Println(err)
  2846. go utils.SendAlarmMsg("获取活动线上还是线下的类型,失败,GetActivityTypeIdMap:Err "+err.Error(), 2)
  2847. }
  2848. }()
  2849. list, e := models.GetActivityTypeList("")
  2850. if e != nil {
  2851. err = errors.New("GetActivityTypeList, Err: " + e.Error())
  2852. return
  2853. }
  2854. mapResp = make(map[int]int, 0)
  2855. for _, v := range list {
  2856. mapResp[v.ActivityTypeId] = v.ActivityType
  2857. }
  2858. return
  2859. }
  2860. // 获取活动封面图片
  2861. func GetActivityImgMap(items []*models.ActivityDetail) (mapResp map[int]*models.ActivityImgUrlMapResp) {
  2862. var err error
  2863. defer func() {
  2864. if err != nil {
  2865. fmt.Println(err)
  2866. go utils.SendAlarmMsg("获取活动封面图片,失败,GetActivityImgMap:Err "+err.Error(), 2)
  2867. }
  2868. }()
  2869. detail, e := models.GetConfigByCode("city_img_url")
  2870. if e != nil {
  2871. err = errors.New("GetConfigByCode city_img_url, Err: " + e.Error())
  2872. return
  2873. }
  2874. detailChart, e := models.GetConfigByCode("chart_img_url")
  2875. if e != nil {
  2876. err = errors.New("GetConfigByCode chart_img_url , Err: " + e.Error())
  2877. return
  2878. }
  2879. mapResp = make(map[int]*models.ActivityImgUrlMapResp, 0)
  2880. addressList := strings.Split(detail.ConfigValue, "{|}")
  2881. mapAddress := make(map[string]string)
  2882. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  2883. mapChart := make(map[string]string)
  2884. var cityName string
  2885. var chartName string
  2886. var imgUrl string
  2887. var imgUrlChart string
  2888. for _, v := range addressList {
  2889. vslice := strings.Split(v, "_")
  2890. cityName = vslice[0]
  2891. imgUrl = vslice[len(vslice)-1]
  2892. mapAddress[cityName] = imgUrl
  2893. }
  2894. for _, v := range chartList {
  2895. vslice := strings.Split(v, "_")
  2896. chartName = vslice[0]
  2897. imgUrlChart = vslice[len(vslice)-1]
  2898. mapChart[chartName] = imgUrlChart
  2899. }
  2900. for _, v := range items {
  2901. //fmt.Println(v.ChartPermissionName)
  2902. //if strings.Contains(v.ChartPermissionName, "研选") && v.ActivityTypeId == 1 {
  2903. // v.ImgUrlText = utils.YAN_XUAN_IMG
  2904. //}
  2905. item := new(models.ActivityImgUrlMapResp)
  2906. if v.ActivityType == 0 {
  2907. if mapAddress[v.City] != "" {
  2908. item.ImgUrl = mapAddress[v.City]
  2909. } else {
  2910. item.ImgUrl = mapAddress["其它"]
  2911. }
  2912. } else {
  2913. if mapChart[v.ChartPermissionName] != "" {
  2914. item.ImgUrl = mapChart[v.ChartPermissionName]
  2915. }
  2916. }
  2917. mapResp[v.ActivityId] = item
  2918. }
  2919. return
  2920. }