activity.go 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "unicode/utf8"
  11. )
  12. // 获取活动列表查询权限的SQL
  13. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  14. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  15. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  16. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  17. // @Param WhichTime query string false "已结束的时间筛选项 本周:1、上周:2 、本月:3、上月:4"
  18. // @Param Label query string false "搜索主题 多个用 , 隔开"
  19. // @Param PlayBack query int false "是否仅展示回放 1:是、0:否 默认0"
  20. // @Param KeyWord query string false "搜索关键词"
  21. // @Param ikType query int false "联想词类型 , 1不做联想,2,做除初始词的联想,3所有联想"
  22. func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermissionIds, whichDay, activeState, label string, isPower, source int, keyWord string, playBack, ikType int) (conditionActivity string, err error) {
  23. keyWordNoIk := keyWord
  24. adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
  25. if err != nil {
  26. return
  27. }
  28. userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
  29. if err != nil {
  30. return
  31. }
  32. //判断客户规模是否属于可见范围的活动
  33. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  34. if err != nil && err.Error() != utils.ErrNoRow() {
  35. return
  36. }
  37. isMaker := user.IsMaker
  38. slicePer := strings.Split(permissionStr, ",")
  39. var permissionSqlStr string
  40. var permissionNameStr string
  41. for _, v := range slicePer {
  42. if userType == 1 {
  43. //研选权限处理
  44. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  45. permissionNameStr += "'" + v + "',"
  46. }
  47. } else {
  48. permissionNameStr += "'" + v + "',"
  49. }
  50. }
  51. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  52. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  53. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  54. slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
  55. var permissionNameStrZhengShi string
  56. for _, v := range slicePerZhengShi {
  57. if userType == 1 {
  58. //研选权限处理
  59. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  60. permissionNameStrZhengShi += "'" + v + "',"
  61. }
  62. } else {
  63. permissionNameStrZhengShi += "'" + v + "',"
  64. }
  65. }
  66. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
  67. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
  68. permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
  69. mapUserType, e := GetActivityCcustomerTypeList()
  70. if e != nil {
  71. err = e
  72. return
  73. }
  74. var userTypeStr string
  75. userTypeStr = mapUserType[userType]
  76. // 查研观向7.4-始终查询宏观的权限(无论是否有权限)
  77. if permissionNameStr == `` {
  78. permissionNameStr = `'宏观'`
  79. } else {
  80. permissionNameStr += `, '宏观'`
  81. }
  82. var condition string
  83. var conditionAdmin string
  84. var conditionHz string // 弘则权限处理
  85. var sqlExport string // 专家权限处理
  86. //permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  87. sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  88. //if userType == 2 {
  89. // sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  90. //}
  91. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  92. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  93. }
  94. sqlExport += `) `
  95. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  96. if activityTypeId != "" {
  97. if activityTypeId == strconv.Itoa(utils.ANALYST_TELL_ACTIVITY_TYPE_ID) {
  98. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id IN (` + activityTypeId + "," + strconv.Itoa(utils.C_CLASS_ACTIVITY_TYPE_ID) + `)`
  99. } else {
  100. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id IN (` + activityTypeId + `)`
  101. }
  102. }
  103. //主题
  104. if label != "" {
  105. condition = ` AND art.label LIKE "%` + label + `%" `
  106. }
  107. if isPower == 1 {
  108. condition += permissionSqlStr
  109. }
  110. //行业名称
  111. if len(chartPermissionIds) > 0 {
  112. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  113. }
  114. //如果是PC的,则不看易董的
  115. if source == 1 {
  116. condition += ` AND art.yidong_activity_id = '' `
  117. }
  118. var conditionOr string
  119. if whichDay != "" {
  120. var startDate string
  121. var endDate string
  122. if whichDay == "1" {
  123. startDate = time.Now().Format(utils.FormatDate)
  124. endDate = startDate
  125. } else if whichDay == "2" {
  126. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  127. endDate = startDate
  128. } else if whichDay == "3" {
  129. startDate = utils.GetNowWeekMonday().Format(utils.FormatDate)
  130. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  131. } else if whichDay == "4" {
  132. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  133. endDate = utils.GetLastWeekSunday().Format(utils.FormatDate)
  134. } else if whichDay == "5" {
  135. startDate = utils.GetNowMonthFirstDay().Format(utils.FormatDate)
  136. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  137. } else if whichDay == "6" {
  138. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  139. endDate = utils.GetLastMonthLastDay().Format(utils.FormatDate)
  140. } else if whichDay == "1,2" {
  141. startDate = time.Now().Format(utils.FormatDate)
  142. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  143. } else if whichDay == "3,4" {
  144. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  145. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  146. } else if whichDay == "5,6" {
  147. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  148. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  149. } else {
  150. startDate = time.Now().Format(utils.FormatDate)
  151. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  152. }
  153. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  154. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  155. }
  156. //有搜索条件传过来时,不判进行状态条件
  157. if keyWord != "" {
  158. if ikType == 2 || ikType == 3 {
  159. keyWordArr, e := GetIndustryMapNameSliceV3(keyWord)
  160. if e != nil {
  161. err = errors.New("获取分词失败,GetIndustryMapNameSliceV3, Err: " + keyWord + e.Error())
  162. return
  163. }
  164. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  165. //var keywords string
  166. if len(keyWordArr) > 1 {
  167. if ikType == 2 {
  168. keyWord = KeyWordArrSqlRegexp(keyWordArr)
  169. condition += ` AND (art.label NOT LIKE '%` + keyWordNoIk + `%' AND art.activity_name NOT LIKE '%` + keyWordNoIk + `%' ) `
  170. } else if ikType == 3 {
  171. keyWord = KeyWordArrSqlRegexpAll(keyWordArr)
  172. }
  173. }
  174. }
  175. condition += ` AND (art.label REGEXP '` + keyWord + `' OR art.activity_name REGEXP '` + keyWord + `' ) `
  176. } else {
  177. if activeState != "" {
  178. // 默认查看未开始跟进行中
  179. if activeState == "1" {
  180. condition += ` AND art.active_state IN (1,2)`
  181. } else {
  182. condition += ` AND art.active_state IN (` + activeState + `)`
  183. }
  184. } else {
  185. condition += ` AND art.active_state IN (1,2)`
  186. }
  187. }
  188. if playBack == 1 {
  189. var pars []interface{}
  190. ativityVIdArry := make([]string, 0)
  191. voiceList, e := models.GetActivityVoiceListAll("", pars, 0, 1000)
  192. if e != nil && e.Error() != utils.ErrNoRow() {
  193. err = e
  194. return
  195. }
  196. for _, v := range voiceList {
  197. ativityVIdArry = append(ativityVIdArry, strconv.Itoa(v.ActivityId))
  198. }
  199. videoList, e := models.GetActivityVideoListAll("", pars, 0, 1000)
  200. if e != nil && e.Error() != utils.ErrNoRow() {
  201. err = e
  202. return
  203. }
  204. for _, v := range videoList {
  205. ativityVIdArry = append(ativityVIdArry, strconv.Itoa(v.ActivityId))
  206. }
  207. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  208. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  209. //condition += ` AND art.activity_time > '` + endTime + `' `
  210. if len(ativityVIdArry) > 0 {
  211. ativityVIdstr := strings.Join(ativityVIdArry, ",")
  212. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  213. } else {
  214. condition += ` AND art.activity_id = 0 `
  215. }
  216. }
  217. //查询全部可见的数据(是否全部客户可见)
  218. //condition += ` AND art.visible_range != 1 AND art.publish_status = 1 `
  219. condition += ` AND art.publish_status = 1 `
  220. //if adminIds == "" {
  221. // //condition += ` AND art.visible_range != 1 `
  222. //} else {
  223. // condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  224. //}
  225. if adminIds != "" {
  226. condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  227. }
  228. conditionHz = condition
  229. //活动仅决策人可见
  230. if isMaker == 0 {
  231. condition += ` AND art.is_maker_show = 0 `
  232. }
  233. conditionAdmin = condition + ` AND art.visible_range = 1 `
  234. //condition += ` AND art.visible_range != 1 `
  235. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  236. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  237. }
  238. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  239. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  240. }
  241. if userType == 1 {
  242. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  243. } else {
  244. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  245. }
  246. if userType == 6 || userType == 7 {
  247. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
  248. }
  249. if companyProduct != nil {
  250. if companyProduct.Scale != "" {
  251. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  252. }
  253. }
  254. if adminIds != "" {
  255. if userType == 3 {
  256. conditionAdmin += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  257. }
  258. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + userTypeStr + `%' ` + ` AND art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) `
  259. if companyProduct != nil {
  260. if companyProduct.Scale != "" {
  261. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%'` + ` AND art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) `
  262. }
  263. }
  264. }
  265. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  266. if e != nil {
  267. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  268. return
  269. }
  270. if conditionShengji != "" {
  271. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) `
  272. }
  273. if conditionZhengshi != "" {
  274. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) `
  275. }
  276. if conditionHangYe != "" {
  277. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) `
  278. }
  279. //弘则研究下的客户不做权限,限制,C类电话会,仅本组销售、部门管理员、admin、权益研究员账号能看到
  280. if user.CompanyId == utils.HZ_COMPANY_ID {
  281. mapMobile, e := GetAdminMobileMap()
  282. if e != nil {
  283. err = e
  284. return
  285. }
  286. if _, ok := mapMobile[user.Mobile]; ok {
  287. conditionOr += ` OR ( art.publish_status = 1 ` + conditionHz + `) `
  288. }
  289. }
  290. if userType == 3 {
  291. condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  292. }
  293. conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
  294. return
  295. }
  296. // 根据用户身份处理活动可见
  297. func ActivityConditioninitSql(user *models.WxUserItem, condition string, isPower int) (conditionActivity string, err error) {
  298. // cygx_10.9 未绑定联系方式的客户可以看到部分活动
  299. if user.UserId == 0 || user.CompanyId == 1 {
  300. 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
  301. return
  302. }
  303. condition += ` AND art.publish_status = 1 `
  304. conditionActivity = condition
  305. //弘则可以查看所有活动
  306. if GetBelongingRaiIt(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID {
  307. return
  308. }
  309. //adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
  310. //if err != nil {
  311. // return
  312. //}
  313. adminIds := GetSelleridWhichGroup(user.CompanyId, 2, user.Mobile)
  314. userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
  315. if err != nil {
  316. return
  317. }
  318. //判断客户规模是否属于可见范围的活动
  319. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  320. if err != nil && err.Error() != utils.ErrNoRow() {
  321. return
  322. }
  323. isMaker := user.IsMaker
  324. slicePer := strings.Split(permissionStr, ",")
  325. var permissionSqlStr string
  326. var permissionNameStr string
  327. for _, v := range slicePer {
  328. if userType == 1 {
  329. //研选权限处理
  330. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  331. permissionNameStr += "'" + v + "',"
  332. }
  333. } else {
  334. permissionNameStr += "'" + v + "',"
  335. }
  336. }
  337. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  338. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  339. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  340. slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
  341. var permissionNameStrZhengShi string
  342. for _, v := range slicePerZhengShi {
  343. if userType == 1 {
  344. //研选权限处理
  345. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  346. permissionNameStrZhengShi += "'" + v + "',"
  347. }
  348. } else {
  349. permissionNameStrZhengShi += "'" + v + "',"
  350. }
  351. }
  352. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
  353. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
  354. permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
  355. mapUserType, e := GetActivityCcustomerTypeList()
  356. if e != nil {
  357. err = e
  358. return
  359. }
  360. var userTypeStr string
  361. userTypeStr = mapUserType[userType]
  362. fmt.Println("userTypeStr", userTypeStr)
  363. // 查研观向7.4-始终查询宏观的权限(无论是否有权限)
  364. if permissionNameStr == `` {
  365. permissionNameStr = `'宏观'`
  366. } else {
  367. permissionNameStr += `, '宏观'`
  368. }
  369. var sqlExport string // 专家权限处理
  370. sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  371. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  372. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  373. }
  374. sqlExport += `) `
  375. if isPower == 1 {
  376. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  377. condition += permissionSqlStr
  378. }
  379. var conditionOr string
  380. //查询全部可见的数据(是否全部客户可见)
  381. if adminIds != "" {
  382. condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  383. }
  384. //活动仅决策人可见
  385. if isMaker == 0 {
  386. condition += ` AND art.is_maker_show = 0 `
  387. }
  388. //condition += ` AND art.visible_range != 1 `
  389. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  390. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  391. }
  392. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  393. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  394. }
  395. if userType == 1 {
  396. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  397. } else {
  398. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  399. }
  400. if userType == 6 || userType == 7 {
  401. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
  402. }
  403. if companyProduct != nil {
  404. if companyProduct.Scale != "" {
  405. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  406. }
  407. }
  408. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  409. if e != nil {
  410. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  411. return
  412. }
  413. // 升级客户可查看范围
  414. if conditionShengji != "" {
  415. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) `
  416. }
  417. // 正式客户可查看范围
  418. if conditionZhengshi != "" {
  419. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) `
  420. }
  421. // 行业客户可查看范围
  422. if conditionHangYe != "" {
  423. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) `
  424. }
  425. if userType == 3 {
  426. condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  427. }
  428. condition += ` AND art.is_limit_people = 1 `
  429. conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
  430. return
  431. }
  432. // 获取可见的活动
  433. func HandleActivityPowerList(listActivity []*models.CygxActivity, user *models.WxUserItem) (items []*models.CygxActivity, err error) {
  434. return
  435. }
  436. // 5.3版本活动标签字符串处理
  437. func LabelStr(label string, isShowSubjectName int, temporaryLabel string) (labelNew string) {
  438. slicebr := strings.Split(label, "-")
  439. if len(slicebr) > 1 {
  440. if isShowSubjectName == 1 {
  441. labelNew = slicebr[1]
  442. } else {
  443. labelNew = slicebr[0]
  444. }
  445. } else {
  446. labelNew = label
  447. }
  448. if temporaryLabel != "" {
  449. labelNew = temporaryLabel
  450. }
  451. return labelNew
  452. }
  453. // 列表
  454. func HandleActivityTypeHomeList(listType []*models.ActivityTypeHome, listActivity []*models.CygxActivity, user *models.WxUserItem) (items []*models.ActivityTypeHome, err error) {
  455. mapActivity := make(map[int][]*models.CygxActivityLabelList)
  456. activityIds := make([]int, 0) // 用于查询活动【新】标签Map
  457. for _, v := range listActivity {
  458. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  459. if v.ActivityTypeId == 7 {
  460. v.ActivityTypeId = 2
  461. }
  462. // 如果是买方线下交流的活动,合并到专家线下交流
  463. if v.ActivityTypeId == 8 {
  464. v.ActivityTypeId = 5
  465. }
  466. //if v.ActivityTypeId == 1 {
  467. activityIds = append(activityIds, v.ActivityId)
  468. //}
  469. }
  470. // 活动【新】标签Map
  471. newLabelMap, _, e := GetActivityNewLabelMap(activityIds)
  472. if e != nil {
  473. err = errors.New("获取产业新标签Map失败,GetActivityNewLabelMap Err: " + e.Error())
  474. return
  475. }
  476. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  477. mapkeyWord := make(map[string]string)
  478. for _, v := range listActivity {
  479. if v.Label == "" {
  480. continue
  481. }
  482. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  483. if v.ActivityTypeId == 7 {
  484. v.ActivityTypeId = 2
  485. }
  486. item := new(models.CygxActivityLabelList)
  487. item.IsResearchPoints = activityPointsByUserAllMap[v.ActivityId]
  488. item.KeyWord = LabelStr(v.Label, v.IsShowSubjectName, v.TemporaryLabel)
  489. if _, ok := mapkeyWord[fmt.Sprint(v.ActivityTypeId, "-", item.KeyWord)]; ok {
  490. continue
  491. }
  492. item.Resource = 1
  493. item.ActivityId = v.ActivityId
  494. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  495. item.IsResearch = true
  496. }
  497. //易董同步过来的活动只展示外部资源标签
  498. if v.YidongActivityId != "" {
  499. item.IsResearchPoints = false
  500. item.IsResearch = false
  501. }
  502. if v.IsExternalLabel > 0 {
  503. item.IsExternalLabel = true
  504. }
  505. //if v.IsResearchPoints > 0 {
  506. item.IsResearchPoints = activityPointsByUserAllMap[v.ActivityId]
  507. //}
  508. item.City = v.City
  509. if utf8.RuneCountInString(v.City) != 2 {
  510. item.City = ""
  511. }
  512. item.IsNew = newLabelMap[v.ActivityId]
  513. mapActivity[v.ActivityTypeId] = append(mapActivity[v.ActivityTypeId], item)
  514. mapkeyWord[fmt.Sprint(v.ActivityTypeId, "-", item.KeyWord)] = item.KeyWord
  515. }
  516. for _, v := range listType {
  517. v.Resource = 1
  518. if len(mapActivity[v.ActivityTypeId]) > 0 {
  519. v.List = mapActivity[v.ActivityTypeId]
  520. } else {
  521. v.List = make([]*models.CygxActivityLabelList, 0)
  522. }
  523. }
  524. items = listType
  525. return
  526. }
  527. // GetActivityVoiceResp 处理活动音频回放
  528. func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) {
  529. activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId)
  530. if err != nil && err.Error() != utils.ErrNoRow() {
  531. return
  532. }
  533. mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq)
  534. if len(activityVoiceList) > 0 {
  535. for _, v := range activityVoiceList {
  536. v.Type = 1 //活动音频为1
  537. mapActivityVoice[v.ActivityId] = v
  538. }
  539. }
  540. mapItem = mapActivityVoice
  541. return
  542. }
  543. // GetActivityVideoResp 处理活动视频频回放
  544. func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) {
  545. var condition string
  546. var ativityVIdstr string
  547. for _, v := range mapActivityId {
  548. ativityVIdstr += strconv.Itoa(v) + ","
  549. }
  550. if ativityVIdstr == "" {
  551. return
  552. }
  553. ativityVIdstr = strings.TrimRight(ativityVIdstr, ",")
  554. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  555. var pars []interface{}
  556. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  557. //condition += ` AND art.activity_time > ? `
  558. //pars = append(pars, endTime)
  559. videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000)
  560. if e != nil && e.Error() != utils.ErrNoRow() {
  561. err = e
  562. return
  563. }
  564. mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp)
  565. if len(videoList) > 0 {
  566. for _, v := range videoList {
  567. v.Type = 2 // 活动视频为 2
  568. mapActivityVideo[v.ActivityId] = v
  569. }
  570. }
  571. mapItem = mapActivityVideo
  572. return
  573. }
  574. func ActivityButtonShow(item *models.ActivityDetail, user *models.WxUserItem, permissionArr []string) (itemActivity *models.ActivityListResp) {
  575. activityDetail := item
  576. //IsShowAppointment bool `description:"是否展示预约纪要"`
  577. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  578. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  579. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  580. //IsShowSignup bool `description:"是否展示我要报名"`
  581. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  582. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  583. activityDetail.IsResearch = true
  584. }
  585. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  586. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] {
  587. activityDetail.IsResearchSpecial = true
  588. }
  589. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  590. activityDetail.SiginupDeadline = ""
  591. }
  592. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  593. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  594. activityDetail.CancelDeadline = ""
  595. }
  596. activityTimeText := activityDetail.ActivityTimeText
  597. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  598. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  599. activityDetail.ActivityTimeText = activityTimeText
  600. var yidongActivityUrl string
  601. activityDetail.IsShowAppointment = false
  602. //易董的操作按钮都隐藏
  603. if activityDetail.YidongActivityId != "" {
  604. activityDetail.IsShowSignup = false
  605. activityDetail.IsShowDetails = true
  606. if activityDetail.YidongActivityId != "" {
  607. ydTgc, _ := GetYiDongCreateUserInfo(user)
  608. yidongLongLink, _ := GetYiDongOriginalLink(activityDetail)
  609. if yidongLongLink != "" {
  610. yidongActivityUrl = yidongLongLink + "%26source=11%26fromHz=true%26tgc=" + ydTgc
  611. }
  612. }
  613. } else {
  614. //专家电话会 1
  615. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  616. activityDetail.IsShowHelpSsk = true
  617. }
  618. if activityDetail.ActiveState == "1" {
  619. //新的是否展示规则
  620. if activityDetail.IsCanAppointmentMinutes == 1 {
  621. activityDetail.IsShowAppointment = true
  622. }
  623. //专家电话会 1
  624. if activityDetail.ActivityTypeId == 1 {
  625. if activityDetail.LimitPeopleNum == 0 {
  626. activityDetail.IsShowOutboundCall = true
  627. } else {
  628. activityDetail.IsShowSignup = true
  629. }
  630. activityDetail.IsShowMeetingReminder = true
  631. activityDetail.IsShowHelpSsk = true
  632. }
  633. //分析师电话会 2
  634. if activityDetail.ActivityTypeId == 2 {
  635. if activityDetail.LimitPeopleNum == 0 {
  636. activityDetail.IsShowOutboundCall = true
  637. } else {
  638. activityDetail.IsShowSignup = true
  639. }
  640. activityDetail.IsShowMeetingReminder = true
  641. }
  642. if activityDetail.ActivityTypeId == 3 {
  643. //司调研电话会(3)、扣点的研选活动只展示我要报名
  644. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  645. activityDetail.IsShowSignup = true
  646. } else {
  647. activityDetail.IsShowMeetingReminder = true
  648. activityDetail.IsShowOutboundCall = true
  649. }
  650. }
  651. //公司线下调研 4
  652. if activityDetail.ActivityTypeId == 4 {
  653. activityDetail.IsShowSignup = true
  654. }
  655. //专家线下沙龙 5
  656. if activityDetail.ActivityTypeId == 5 {
  657. activityDetail.IsShowSignup = true
  658. }
  659. //分析师线下沙龙 6
  660. if activityDetail.ActivityTypeId == 6 {
  661. activityDetail.IsShowSignup = true
  662. }
  663. //分析师电话会(C类) 7
  664. if activityDetail.ActivityTypeId == 7 {
  665. activityDetail.IsShowSignup = true
  666. activityDetail.IsShowMeetingReminder = true
  667. }
  668. //买方线下交流 8 // 查研观向 11.0
  669. if activityDetail.ActivityTypeId == 8 {
  670. activityDetail.IsShowSignup = true
  671. }
  672. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  673. if activityDetail.IsYidongConduct {
  674. activityDetail.IsShowSignup = true
  675. activityDetail.IsShowOutboundCall = false
  676. }
  677. }
  678. }
  679. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  680. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  681. if e != nil {
  682. e = errors.New("获取用户权限失败, Err: " + e.Error())
  683. return
  684. }
  685. if utils.InArrayByStr(permissionArr, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
  686. permissionArr = append(permissionArr, utils.CHART_PERMISSION_NAME_MF_YANXUAN)
  687. }
  688. //如果是易董同步过来的,只展示外部资源标签
  689. if activityDetail.YidongActivityId != "" {
  690. activityDetail.IsExternalLabel = true
  691. activityDetail.IsResearch = false
  692. activityDetail.IsResearchSpecial = false
  693. }
  694. v := activityDetail
  695. itemActivity = &models.ActivityListResp{
  696. ActivityId: v.ActivityId,
  697. ActivityTypeId: v.ActivityTypeId,
  698. ActivityTypeName: v.ActivityTypeName,
  699. ChartPermissionId: v.ChartPermissionId,
  700. ChartPermissionName: v.ChartPermissionName,
  701. IsLimitPeople: v.IsLimitPeople,
  702. LimitPeopleNum: v.LimitPeopleNum,
  703. LastUpdatedTime: v.LastUpdatedTime,
  704. ActivityTime: v.ActivityTime,
  705. ActivityTimeText: v.ActivityTimeText,
  706. DistinguishedGuest: v.DistinguishedGuest,
  707. Host: v.Host,
  708. Speaker: v.Speaker,
  709. MainlandTell: v.MainlandTell,
  710. HongKongTell: v.HongKongTell,
  711. TaiwanTell: v.TaiwanTell,
  712. AmericaTell: v.AmericaTell,
  713. ParticipationCode: v.ParticipationCode,
  714. Theme: v.Theme,
  715. Expert: v.Expert,
  716. ActivityName: v.ActivityName,
  717. OnlineParticipation: v.OnlineParticipation,
  718. ReportLink: v.ReportLink,
  719. AppAttendance: v.AppAttendance,
  720. ConferencePassword: v.ConferencePassword,
  721. City: v.City,
  722. Address: v.Address,
  723. Highlights: v.Highlights,
  724. Remarks: v.Remarks,
  725. IsSignup: v.IsSignup,
  726. IsCancelMeetingReminder: v.IsCancelMeetingReminder,
  727. IsAppointment: v.IsAppointment,
  728. ActiveState: v.ActiveState,
  729. IsShowSustainable: v.IsShowSustainable,
  730. Description: v.Description,
  731. IsResearch: v.IsResearch,
  732. IsHideAppointment: v.IsHideAppointment,
  733. IsCClassMeeting: v.IsCClassMeeting,
  734. Label: v.Label,
  735. ImgUrl: v.ImgUrl,
  736. ImgUrlText: v.ImgUrlText,
  737. ActivityType: v.ActivityType,
  738. IsShowOutboundCall: v.IsShowOutboundCall,
  739. IsShowMeetingReminder: v.IsShowMeetingReminder,
  740. IsShowHelpSsk: v.IsShowHelpSsk,
  741. IsShowSignup: v.IsShowSignup,
  742. IsShowAppointment: v.IsShowAppointment,
  743. IsShowDetails: v.IsShowDetails,
  744. AudioLink: v.AudioLink,
  745. VoiceDetail: v.VoiceList,
  746. VideoDetail: v.VideoDetail,
  747. FileType: v.FileType,
  748. SourceType: v.SourceType,
  749. SignupNum: v.SignupNum,
  750. YidongActivityUrl: yidongActivityUrl,
  751. Explain: utils.ACtIVITY_SPECIAL_EXPLAIN,
  752. TripImgLink: v.TripImgLink,
  753. Days: v.Days,
  754. SignupType: v.SignupType,
  755. IsYidongConduct: v.IsYidongConduct,
  756. IsCanOutboundCall: v.IsCanOutboundCall,
  757. TencentConferenceNumber: v.TencentConferenceNumber,
  758. IsResearchSpecial: v.IsResearchSpecial,
  759. LinkParticipants: v.LinkParticipants,
  760. IsResearchPoints: v.IsResearchPoints,
  761. IsExternalLabel: v.IsExternalLabel,
  762. SiginupDeadline: v.SiginupDeadline,
  763. CancelDeadline: v.CancelDeadline,
  764. }
  765. au := new(models.UserPermissionAuthInfo)
  766. au.SellerName = authInfo.SellerName
  767. au.SellerMobile = authInfo.SellerMobile
  768. au.HasPermission = authInfo.HasPermission
  769. au.OperationMode = authInfo.OperationMode
  770. if au.HasPermission == 1 {
  771. // 非宏观权限进一步判断是否有权限
  772. if v.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, v.ChartPermissionName) {
  773. au.HasPermission = 2
  774. }
  775. //如果是易董的活动,主、副权限有一个满足即可 查研观向 11.0
  776. if v.YidongActivityId != "" {
  777. if utils.InArrayByStr(permissionArr, v.ChartPermissionName) || utils.InArrayByStr(permissionArr, v.ChartPermissionNameDeputy) {
  778. au.HasPermission = 1
  779. }
  780. }
  781. }
  782. // 无权限的弹框提示
  783. if au.HasPermission != 1 {
  784. if au.OperationMode == UserPermissionOperationModeCall {
  785. if v.FileType == 1 {
  786. au.PopupMsg = UserPermissionPopupMsgCallMicroVoice
  787. } else {
  788. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  789. }
  790. } else {
  791. if v.FileType == 1 {
  792. au.PopupMsg = UserPermissionPopupMsgApplyMicroVoice
  793. } else {
  794. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  795. }
  796. }
  797. }
  798. itemActivity.AuthInfo = au
  799. //处理用户已经报名了的行程
  800. var activityIds []int
  801. activityIds = append(activityIds, v.ActivityId)
  802. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  803. if e != nil {
  804. e = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  805. return
  806. }
  807. if _, ok := UserMap[v.ActivityId]; ok {
  808. itemActivity.IsTrip = 1
  809. }
  810. if itemActivity.Days == 0 {
  811. itemActivity.TripStatus = 1
  812. //activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  813. } else {
  814. itemActivity.TripStatus = 2
  815. //itemActivity.TripImgLink = itemActivity.TripImgLinkFix
  816. //activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  817. }
  818. return
  819. }
  820. func ActivityArrButtonShow(items []*models.ActivityDetail, user *models.WxUserItem, permissionArr []string) (itemsActivity []*models.ActivityListResp) {
  821. var activityIds []int
  822. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  823. if e != nil {
  824. e = errors.New("获取用户权限失败, Err: " + e.Error())
  825. return
  826. }
  827. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  828. for _, activityDetail := range items {
  829. //IsShowAppointment bool `description:"是否展示预约纪要"`
  830. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  831. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  832. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  833. //IsShowSignup bool `description:"是否展示我要报名"`
  834. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  835. activityDetail.IsResearch = true
  836. }
  837. //如果是 公司调研电话会:3,或 专家线下沙龙:5 而且 除易董同步过来的以外的研选类型活动
  838. //if (activityDetail.ActivityTypeId == 3 || activityDetail.ActivityTypeId == 5) && activityDetail.YidongActivityId == "" && strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  839. // activityDetail.IsResearchSpecial = true
  840. //}
  841. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  842. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] {
  843. activityDetail.IsResearchSpecial = true
  844. }
  845. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  846. activityDetail.SiginupDeadline = ""
  847. }
  848. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  849. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  850. activityDetail.CancelDeadline = ""
  851. }
  852. activityTimeText := activityDetail.ActivityTimeText
  853. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  854. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  855. activityDetail.ActivityTimeText = activityTimeText
  856. var yidongActivityUrl string
  857. activityDetail.IsShowAppointment = false
  858. //易董的操作按钮都隐藏
  859. if activityDetail.YidongActivityId != "" {
  860. activityDetail.IsShowSignup = false
  861. activityDetail.IsShowDetails = true
  862. activityDetail.IsYidongActivity = true
  863. //if activityDetail.YidongActivityId != "" {
  864. // ydTgc, _ := GetYiDongCreateUserInfo(user)
  865. // yidongLongLink, _ := GetYiDongOriginalLink(activityDetail)
  866. // if yidongLongLink != "" {
  867. // yidongActivityUrl = yidongLongLink + "%26source=11%26fromHz=true%26tgc=" + ydTgc
  868. // }
  869. //}
  870. } else {
  871. //专家电话会 1
  872. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  873. activityDetail.IsShowHelpSsk = true
  874. }
  875. if activityDetail.ActiveState == "1" {
  876. //新的是否展示规则
  877. if activityDetail.IsCanAppointmentMinutes == 1 {
  878. activityDetail.IsShowAppointment = true
  879. }
  880. //专家电话会 1
  881. if activityDetail.ActivityTypeId == 1 {
  882. if activityDetail.LimitPeopleNum == 0 {
  883. activityDetail.IsShowOutboundCall = true
  884. } else {
  885. activityDetail.IsShowSignup = true
  886. }
  887. activityDetail.IsShowMeetingReminder = true
  888. activityDetail.IsShowHelpSsk = true
  889. }
  890. //分析师电话会 2
  891. if activityDetail.ActivityTypeId == 2 {
  892. if activityDetail.LimitPeopleNum == 0 {
  893. activityDetail.IsShowOutboundCall = true
  894. } else {
  895. activityDetail.IsShowSignup = true
  896. }
  897. activityDetail.IsShowMeetingReminder = true
  898. }
  899. if activityDetail.ActivityTypeId == 3 {
  900. //司调研电话会(3)、扣点的研选活动只展示我要报名
  901. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  902. activityDetail.IsShowSignup = true
  903. } else {
  904. activityDetail.IsShowMeetingReminder = true
  905. activityDetail.IsShowOutboundCall = true
  906. }
  907. }
  908. //公司线下调研 4
  909. if activityDetail.ActivityTypeId == 4 {
  910. activityDetail.IsShowSignup = true
  911. }
  912. //专家线下沙龙 5
  913. if activityDetail.ActivityTypeId == 5 {
  914. activityDetail.IsShowSignup = true
  915. }
  916. //分析师线下沙龙 6
  917. if activityDetail.ActivityTypeId == 6 {
  918. activityDetail.IsShowSignup = true
  919. }
  920. //分析师电话会(C类) 7
  921. if activityDetail.ActivityTypeId == 7 {
  922. activityDetail.IsShowSignup = true
  923. activityDetail.IsShowMeetingReminder = true
  924. }
  925. //买方线下交流 8 // 查研观向 11.0
  926. if activityDetail.ActivityTypeId == 8 {
  927. activityDetail.IsShowSignup = true
  928. }
  929. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  930. if activityDetail.IsYidongConduct {
  931. activityDetail.IsShowSignup = true
  932. activityDetail.IsShowOutboundCall = false
  933. }
  934. }
  935. }
  936. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  937. v := activityDetail
  938. itemActivity := &models.ActivityListResp{
  939. ActivityId: v.ActivityId,
  940. ActivityTypeId: v.ActivityTypeId,
  941. ActivityTypeName: v.ActivityTypeName,
  942. ChartPermissionId: v.ChartPermissionId,
  943. ChartPermissionName: v.ChartPermissionName,
  944. IsLimitPeople: v.IsLimitPeople,
  945. LimitPeopleNum: v.LimitPeopleNum,
  946. LastUpdatedTime: v.LastUpdatedTime,
  947. ActivityTime: v.ActivityTime,
  948. ActivityTimeText: v.ActivityTimeText,
  949. DistinguishedGuest: v.DistinguishedGuest,
  950. Host: v.Host,
  951. Speaker: v.Speaker,
  952. MainlandTell: v.MainlandTell,
  953. HongKongTell: v.HongKongTell,
  954. TaiwanTell: v.TaiwanTell,
  955. AmericaTell: v.AmericaTell,
  956. ParticipationCode: v.ParticipationCode,
  957. Theme: v.Theme,
  958. Expert: v.Expert,
  959. ActivityName: v.ActivityName,
  960. OnlineParticipation: v.OnlineParticipation,
  961. ReportLink: v.ReportLink,
  962. AppAttendance: v.AppAttendance,
  963. ConferencePassword: v.ConferencePassword,
  964. City: v.City,
  965. Address: v.Address,
  966. Highlights: v.Highlights,
  967. Remarks: v.Remarks,
  968. IsSignup: v.IsSignup,
  969. IsCancelMeetingReminder: v.IsCancelMeetingReminder,
  970. IsAppointment: v.IsAppointment,
  971. ActiveState: v.ActiveState,
  972. IsShowSustainable: v.IsShowSustainable,
  973. Description: v.Description,
  974. IsResearch: v.IsResearch,
  975. IsHideAppointment: v.IsHideAppointment,
  976. IsCClassMeeting: v.IsCClassMeeting,
  977. Label: v.Label,
  978. ImgUrl: v.ImgUrl,
  979. ImgUrlText: v.ImgUrlText,
  980. ActivityType: v.ActivityType,
  981. IsShowOutboundCall: v.IsShowOutboundCall,
  982. IsShowMeetingReminder: v.IsShowMeetingReminder,
  983. IsShowHelpSsk: v.IsShowHelpSsk,
  984. IsShowSignup: v.IsShowSignup,
  985. IsShowAppointment: v.IsShowAppointment,
  986. IsShowDetails: v.IsShowDetails,
  987. AudioLink: v.AudioLink,
  988. VoiceDetail: v.VoiceList,
  989. VideoDetail: v.VideoDetail,
  990. FileType: v.FileType,
  991. SourceType: v.SourceType,
  992. SignupNum: v.SignupNum,
  993. YidongActivityUrl: yidongActivityUrl,
  994. Explain: utils.ACtIVITY_SPECIAL_EXPLAIN,
  995. TripImgLink: v.TripImgLink,
  996. Days: v.Days,
  997. SignupType: v.SignupType,
  998. IsYidongConduct: v.IsYidongConduct,
  999. IsCanOutboundCall: v.IsCanOutboundCall,
  1000. TencentConferenceNumber: v.TencentConferenceNumber,
  1001. IsResearchSpecial: v.IsResearchSpecial,
  1002. LinkParticipants: v.LinkParticipants,
  1003. IsResearchPoints: v.IsResearchPoints,
  1004. IsExternalLabel: v.IsExternalLabel,
  1005. SiginupDeadline: v.SiginupDeadline,
  1006. CancelDeadline: v.CancelDeadline,
  1007. IsYidongActivity: v.IsYidongActivity,
  1008. TopTime: v.TopTime,
  1009. }
  1010. au := new(models.UserPermissionAuthInfo)
  1011. au.SellerName = authInfo.SellerName
  1012. au.SellerMobile = authInfo.SellerMobile
  1013. au.HasPermission = authInfo.HasPermission
  1014. au.OperationMode = authInfo.OperationMode
  1015. if au.HasPermission == 1 {
  1016. // 非宏观权限进一步判断是否有权限
  1017. if v.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, v.ChartPermissionName) {
  1018. au.HasPermission = 2
  1019. }
  1020. //如果是易董的活动,主、副权限有一个满足即可 查研观向 11.0
  1021. if v.YidongActivityId != "" {
  1022. if utils.InArrayByStr(permissionArr, v.ChartPermissionName) || utils.InArrayByStr(permissionArr, v.ChartPermissionNameDeputy) {
  1023. au.HasPermission = 1
  1024. }
  1025. }
  1026. }
  1027. // 无权限的弹框提示
  1028. if au.HasPermission != 1 {
  1029. if au.OperationMode == UserPermissionOperationModeCall {
  1030. if v.FileType == 1 {
  1031. au.PopupMsg = UserPermissionPopupMsgCallMicroVoice
  1032. } else {
  1033. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  1034. }
  1035. } else {
  1036. if v.FileType == 1 {
  1037. au.PopupMsg = UserPermissionPopupMsgApplyMicroVoice
  1038. } else {
  1039. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  1040. }
  1041. }
  1042. }
  1043. //如果是易董同步过来的,只展示外部资源标签
  1044. if activityDetail.YidongActivityId != "" {
  1045. itemActivity.IsExternalLabel = true
  1046. itemActivity.IsResearch = false
  1047. itemActivity.IsResearchSpecial = false
  1048. }
  1049. itemActivity.AuthInfo = au
  1050. //处理用户已经报名了的行程
  1051. activityIds = append(activityIds, v.ActivityId)
  1052. itemsActivity = append(itemsActivity, itemActivity)
  1053. }
  1054. //处理专项调研
  1055. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  1056. if e != nil {
  1057. e = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  1058. return
  1059. }
  1060. for _, v := range itemsActivity {
  1061. if _, ok := UserMap[v.ActivityId]; ok {
  1062. v.IsTrip = 1
  1063. }
  1064. if v.Days == 0 {
  1065. v.TripStatus = 1
  1066. } else {
  1067. v.TripStatus = 2
  1068. }
  1069. }
  1070. return
  1071. }
  1072. func ActivityDetaailShow(activityInfo *models.ActivityListResp) (itemActivity *models.ActivityListResp, err error) {
  1073. itemActivity = activityInfo
  1074. if GetShowSustainable() && strings.Contains(itemActivity.ChartPermissionName, "研选") {
  1075. itemActivity.IsShowSustainable = true
  1076. }
  1077. if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
  1078. activityInfo.SignupNum = activityInfo.LimitPeopleNum
  1079. }
  1080. if activityInfo.ReportLink != "" {
  1081. artList, e := GetActivityReportLinkToArticleList(activityInfo)
  1082. if e != nil && e.Error() != utils.ErrNoRow() {
  1083. err = e
  1084. return
  1085. }
  1086. if len(artList) == 0 {
  1087. activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
  1088. } else {
  1089. activityInfo.ArticleList = artList
  1090. }
  1091. } else {
  1092. activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
  1093. }
  1094. activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
  1095. return
  1096. }
  1097. // GetActivityNewLabelMap 获取活动【新】标签Map
  1098. func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) {
  1099. labelMap = make(map[int]bool, 0)
  1100. industryNewMap = make(map[int]bool, 0)
  1101. if len(activityIds) == 0 {
  1102. return
  1103. }
  1104. // 获取活动关联的产业
  1105. var groupCond string
  1106. var groupPars []interface{}
  1107. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 `
  1108. groupPars = append(groupPars, activityIds)
  1109. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  1110. if e != nil {
  1111. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  1112. return
  1113. }
  1114. activityIndustryMap := make(map[int][]int, 0)
  1115. industryIds := make([]int, 0)
  1116. for i := range groups {
  1117. industryIds = append(industryIds, groups[i].IndustrialManagementId)
  1118. activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId)
  1119. }
  1120. // 获取新产业Map
  1121. industryLabelMap, e := GetIndustryNewLabelMap(industryIds)
  1122. if e != nil {
  1123. err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  1124. return
  1125. }
  1126. // 判断活动是否为新
  1127. for k := range industryLabelMap {
  1128. for k2, v2 := range activityIndustryMap {
  1129. if labelMap[k2] {
  1130. continue
  1131. }
  1132. // 活动的产业ID中存在一个新产业即为新活动
  1133. if utils.InArrayByInt(v2, k) {
  1134. labelMap[k2] = true
  1135. }
  1136. }
  1137. }
  1138. //
  1139. //////产业关联的弘则报告发布日期在三个月以内的活动、产业显示 NEW标签
  1140. //articNewLabel, e := GetArticNewLabelWhithActivity3Month()
  1141. //if e != nil {
  1142. // err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  1143. // return
  1144. //}
  1145. //for k := range articNewLabel {
  1146. // labelMap[k] = true
  1147. //}
  1148. return
  1149. }
  1150. // GetIndustryNewLabelMap 获取产业【新】标签Map
  1151. func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
  1152. labelMap = make(map[int]bool, 0)
  1153. industryIdLen := len(industryIds)
  1154. if industryIdLen == 0 {
  1155. return
  1156. }
  1157. // 获取产业关联的报告最早发布时间及最近的发布时间
  1158. var timeCond string
  1159. var timePars []interface{}
  1160. timeCond += ` AND b.publish_status = 1`
  1161. if industryIdLen > 0 {
  1162. timeCond += ` AND a.industrial_management_id IN (` + utils.GetOrmInReplace(industryIdLen) + `)`
  1163. timePars = append(timePars, industryIds)
  1164. }
  1165. //只要弘则报告,不要研选报告
  1166. timeCond += ` AND b.article_id < ? `
  1167. timePars = append(timePars, utils.SummaryArticleId)
  1168. industryTimeList, e := models.GetIndustryArticleMinMaxPublishTime(timeCond, timePars)
  1169. if e != nil {
  1170. err = errors.New("获取产业文章最大最小发布时间失败, Err: " + e.Error())
  1171. return
  1172. }
  1173. // 判断产业是否为新
  1174. nowTime := time.Now().Local()
  1175. threeMonthBefore := nowTime.AddDate(0, -3, 0)
  1176. nullTime, _ := time.ParseInLocation(utils.FormatDateTime, "0001-01-01 00:00:00", time.Local)
  1177. industryMap := make(map[int]*models.IndustryArticleMinMaxPublishTime, 0)
  1178. for i := range industryTimeList {
  1179. industryMap[industryTimeList[i].IndustrialManagementId] = industryTimeList[i]
  1180. }
  1181. for i := range industryIds {
  1182. iid := industryIds[i]
  1183. item := industryMap[iid]
  1184. if item != nil {
  1185. // 最早发布时间为空 / 最早发布时间在三个月前之后
  1186. if item.MinPublishTime.Equal(nullTime) || (item.MinPublishTime.After(threeMonthBefore)) {
  1187. labelMap[iid] = true
  1188. }
  1189. } else {
  1190. // 产业无报告, 则为新产业
  1191. labelMap[iid] = true
  1192. }
  1193. }
  1194. return
  1195. }
  1196. // GetSpecialDetailUserPower 处理用户查看详情的权限
  1197. func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.ActivityDetail) (havePower, isResearchSpecial bool, err error) {
  1198. var companyDetailStatus string
  1199. var userTypeStr string
  1200. userId := user.UserId
  1201. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  1202. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  1203. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityInfo.ActivityId] {
  1204. isResearchSpecial = true
  1205. }
  1206. //如果是弘则的用户或者宏观的权限不做校验
  1207. //if (GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID) || activityInfo.ChartPermissionName == utils.HONG_GUAN_NAME {
  1208. if GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID {
  1209. havePower = true
  1210. return
  1211. }
  1212. userType, permissionStr, permissionStrZhengShi, e := GetUserTypeZhengShi(user.CompanyId)
  1213. if e != nil {
  1214. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1215. return
  1216. }
  1217. //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  1218. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
  1219. if mfyxUserPermissionTotal == 1 {
  1220. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  1221. }
  1222. //如果正式权限有开通 研选扣点包 ,那么就拼接一个 研选订阅的权限
  1223. if strings.Contains(permissionStrZhengShi, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
  1224. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  1225. permissionStrZhengShi += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  1226. }
  1227. //如果测试权限有开通 研选扣点包 ,那么就拼接一个 研选订阅的权限
  1228. if strings.Contains(permissionStr, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
  1229. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  1230. }
  1231. //如果一个权限都没有就返回无权限
  1232. if permissionStr == "" {
  1233. return
  1234. }
  1235. //永续客户,无法查看研选权限,但是下面的联系人,单独开通研选后,也可以查看研选内容
  1236. if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && mfyxUserPermissionTotal == 0 {
  1237. havePower = false
  1238. return
  1239. }
  1240. permissionStr += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限
  1241. if permissionStrZhengShi == "" {
  1242. permissionStrZhengShi = utils.HONG_GUAN_NAME // 添加一个宏观权限
  1243. } else {
  1244. permissionStrZhengShi += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限
  1245. }
  1246. //如果是易董的活动,主、副权限有一个满足即可
  1247. if activityInfo.YidongActivityId != "" {
  1248. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) || strings.Contains(permissionStr, activityInfo.ChartPermissionNameDeputy) {
  1249. havePower = true
  1250. return
  1251. }
  1252. }
  1253. //如果权限不包含那么直接返回
  1254. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1255. return
  1256. } else {
  1257. havePower = true
  1258. }
  1259. //如果是 对用户的研选扣点的必须要有研选的正式权限
  1260. if activityInfo.IsResearchPoints {
  1261. //获取活动对用户要扣的点
  1262. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  1263. if e != nil {
  1264. err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error())
  1265. return
  1266. }
  1267. if userPointsNum > 0 {
  1268. //if !strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_YANXUAN) {
  1269. // //如果连试用权限都没有,那么久按照普通的研选样式展示
  1270. // isResearchSpecial = false
  1271. //}
  1272. if !strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  1273. havePower = false
  1274. return
  1275. }
  1276. }
  1277. }
  1278. //处理决策人可见权限
  1279. if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 {
  1280. havePower = false
  1281. return
  1282. }
  1283. // 处理本组可见权限
  1284. if activityInfo.VisibleRange == 1 {
  1285. adminIds, e := models.GetSelleridWhichGroup(user.CompanyId, 2)
  1286. if e != nil {
  1287. err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
  1288. return
  1289. }
  1290. haveVisibleRange := false
  1291. adminIdSlice := strings.Split(adminIds, ",")
  1292. for _, v := range adminIdSlice {
  1293. if v == strconv.Itoa(activityInfo.AdminId) {
  1294. haveVisibleRange = true
  1295. }
  1296. }
  1297. if activityInfo.AdminId > 0 {
  1298. adminGroup := GetAdminActivityPermission(activityInfo.AdminId)
  1299. for _, v := range adminGroup {
  1300. if v == activityInfo.AdminId {
  1301. haveVisibleRange = true
  1302. }
  1303. }
  1304. }
  1305. if !haveVisibleRange {
  1306. havePower = false
  1307. return
  1308. }
  1309. }
  1310. if permissionStr == "" {
  1311. return
  1312. }
  1313. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  1314. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  1315. havePower = true
  1316. return
  1317. }
  1318. //医药消费,科技,智造四大行业,验证主客观。如果主客观校验不通过,那么直接返回
  1319. if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) {
  1320. if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  1321. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  1322. havePower = true
  1323. } else {
  1324. havePower = false
  1325. }
  1326. } else {
  1327. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  1328. havePower = true
  1329. } else {
  1330. havePower = false
  1331. }
  1332. }
  1333. //如果主客观校验不通过,那么直接返回
  1334. if !havePower {
  1335. return
  1336. }
  1337. }
  1338. if activityInfo.LimitPeopleNum > 0 {
  1339. mapUserType, e := GetActivityCcustomerTypeList()
  1340. if e != nil {
  1341. err = e
  1342. return
  1343. }
  1344. userTypeStr = mapUserType[userType]
  1345. // 永续客户、大套餐客户、30W套餐客户可以查看行业升级套餐客户 权限
  1346. if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" {
  1347. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  1348. havePower = true
  1349. //return
  1350. }
  1351. }
  1352. } else {
  1353. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1354. havePower = true
  1355. return
  1356. }
  1357. }
  1358. //判断管理规模是否满足
  1359. companyProduct, e := models.GetCompanyProductDetail(user.CompanyId, 2)
  1360. if e != nil {
  1361. err = e
  1362. return
  1363. }
  1364. if companyProduct != nil && activityInfo.Scale != "" {
  1365. if strings.Contains(activityInfo.Scale, companyProduct.Scale) {
  1366. havePower = true
  1367. }
  1368. }
  1369. if user.CompanyId <= 1 {
  1370. return
  1371. } else {
  1372. if permissionStr == "" {
  1373. return
  1374. } else {
  1375. companyDetail, e := models.GetCompanyDetailById(user.CompanyId)
  1376. if e != nil {
  1377. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1378. return
  1379. }
  1380. if companyDetail == nil {
  1381. err = errors.New("客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId))
  1382. return
  1383. }
  1384. companyDetailStatus = companyDetail.Status
  1385. }
  1386. }
  1387. //宏观满足用户可见身份验证权限既满足 2023-9-18
  1388. if activityInfo.ChartPermissionId == 1 {
  1389. if activityInfo.LimitPeopleNum > 0 {
  1390. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  1391. havePower = true
  1392. return
  1393. }
  1394. } else {
  1395. havePower = true
  1396. return
  1397. }
  1398. }
  1399. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == 0 {
  1400. havePower = true
  1401. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  1402. havePower = true
  1403. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  1404. havePower = true
  1405. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  1406. havePower = true
  1407. }
  1408. fmt.Println(permissionStrZhengShi)
  1409. //if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1410. // havePower = true
  1411. // return
  1412. //}
  1413. if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" {
  1414. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  1415. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1416. havePower = true
  1417. return
  1418. }
  1419. } else {
  1420. if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  1421. havePower = true
  1422. return
  1423. }
  1424. }
  1425. }
  1426. permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId)
  1427. if errs != nil {
  1428. err = errs
  1429. return
  1430. }
  1431. //fmt.Println("主客观2", havePower)
  1432. //if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  1433. // havePower = true
  1434. //}
  1435. //fmt.Println("主客观3", havePower)
  1436. //处理升级权限以及用户身份的 双重判断
  1437. if activityInfo.CustomerTypeIds != "" {
  1438. if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" {
  1439. havePower = false
  1440. if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  1441. havePower = true
  1442. }
  1443. }
  1444. }
  1445. if havePower && activityInfo.LimitPeopleNum > 0 {
  1446. //对于一些特殊的活动,即使权限满足也不给查看
  1447. noPower, e := GetShareNoPowe(activityInfo, permissionStr, userType, user)
  1448. if e != nil {
  1449. err = errors.New("GetShareNoPowe, Err: " + e.Error())
  1450. return
  1451. }
  1452. if noPower {
  1453. havePower = false
  1454. }
  1455. }
  1456. return
  1457. }
  1458. // 校验被分享的用户是否有查看详情的权限
  1459. func GetShareNoPowe(activityInfo *models.ActivityDetail, permissionStr string, userType int, user *models.WxUserItem) (noPower bool, err error) {
  1460. //如果是弘则的就不进行可见权限校验
  1461. if user.CompanyId == utils.HZ_COMPANY_ID {
  1462. return
  1463. }
  1464. //var noPower bool
  1465. //if !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
  1466. // noPower = true
  1467. //}
  1468. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  1469. //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)) {
  1470. // noPower = true
  1471. //}
  1472. //if userType == 2 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  1473. // noPower = true
  1474. //}
  1475. //if userType == 3 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  1476. // noPower = true
  1477. //}
  1478. //if userType == 3 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  1479. // noPower = true
  1480. //}
  1481. if userType == 8 {
  1482. permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  1483. if errs != nil {
  1484. err = errs
  1485. return
  1486. }
  1487. if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) {
  1488. noPower = true
  1489. return
  1490. }
  1491. }
  1492. if !noPower {
  1493. noPower, err = CheckUserPowerByActivityChoose(user, activityInfo)
  1494. }
  1495. return
  1496. }
  1497. // 处理活动本组们是否决策人权限
  1498. func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *models.ActivityDetail) (noPower bool, err error) {
  1499. //处理 见范围 1,仅本组可见 、2,全部客户可见
  1500. if activityInfo.VisibleRange == 1 {
  1501. adminIds, errAdmin := models.GetSelleridWhichGroup(user.CompanyId, 2)
  1502. if errAdmin != nil {
  1503. err = errAdmin
  1504. return
  1505. }
  1506. sliceAdminIds := strings.Split(adminIds, ",")
  1507. var haveAdminId bool
  1508. for _, v := range sliceAdminIds {
  1509. if v == strconv.Itoa(activityInfo.AdminId) {
  1510. haveAdminId = true
  1511. }
  1512. }
  1513. if !haveAdminId {
  1514. noPower = true
  1515. }
  1516. }
  1517. //处理 是否仅决策人可见 0,否 、1,是
  1518. if activityInfo.IsMakerShow == 1 {
  1519. if user.IsMaker == 0 {
  1520. noPower = true
  1521. }
  1522. }
  1523. return
  1524. }
  1525. // 判断预约纪要按钮是否显示
  1526. func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
  1527. if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
  1528. isShowAppointment = true
  1529. }
  1530. if activityTypeId == 5 && chartPermissionName == "医药" {
  1531. isShowAppointment = true
  1532. }
  1533. return
  1534. }
  1535. // GetindustryVideoDetailById 通过视频ID获取视频详情
  1536. func GetActivityVideoDetailById(user *models.WxUserItem, videoId int) (industryVideo *models.CygxActivityVideoDetailResp, AuthInfo *models.UserPermissionAuthInfo, err error) {
  1537. total, e := models.GetActivityVideoByVideoIdCount(videoId)
  1538. if e != nil {
  1539. err = errors.New("获取活动的视频失败,GetActivityVideoByVideoIdCount " + e.Error())
  1540. return
  1541. }
  1542. if total == 0 {
  1543. err = errors.New("视频不存在,或已取消发布")
  1544. return
  1545. }
  1546. // 用户权限
  1547. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1548. if e != nil {
  1549. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  1550. return
  1551. }
  1552. videoSimple := new(models.CygxActivityVideoDetailResp)
  1553. // 权限
  1554. var au *models.UserPermissionAuthInfo
  1555. videoSimple, e = models.GetCygxActivityVideoById(videoId)
  1556. if e != nil {
  1557. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  1558. return
  1559. } else {
  1560. //videoSimple.Id = video.Id
  1561. //videoSimple.Title = video.Title
  1562. //videoSimple.ResourceUrl = video.ResourceUrl
  1563. //videoSimple.PlaySeconds = video.PlaySeconds
  1564. //videoSimple.ActivityId = video.ActivityId
  1565. //videoSimple.ChartPermissionId = video.ChartPermissionId
  1566. if videoSimple.BackgroundImg == "" {
  1567. // 获取默认图配置
  1568. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  1569. if e != nil {
  1570. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  1571. return
  1572. }
  1573. videoSimple.BackgroundImg = videoMap[videoSimple.ChartPermissionId]
  1574. }
  1575. au = new(models.UserPermissionAuthInfo)
  1576. au.SellerName = authInfo.SellerName
  1577. au.SellerMobile = authInfo.SellerMobile
  1578. au.HasPermission = authInfo.HasPermission
  1579. au.OperationMode = authInfo.OperationMode
  1580. if au.HasPermission == 1 {
  1581. // 非宏观权限进一步判断是否有权限
  1582. if videoSimple.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, videoSimple.ChartPermissionName) {
  1583. au.HasPermission = 2
  1584. }
  1585. }
  1586. // 无权限的弹框提示
  1587. if au.HasPermission != 1 {
  1588. if au.OperationMode == UserPermissionOperationModeCall {
  1589. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  1590. } else {
  1591. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  1592. }
  1593. videoSimple.ResourceUrl = ""
  1594. }
  1595. }
  1596. videoSimple.Type = 2
  1597. industryVideo = videoSimple
  1598. AuthInfo = au
  1599. return
  1600. }
  1601. // 用户活动操作行为,模板消息推送
  1602. func ActivityUserRemind(user *models.WxUserItem, activityDetail *models.ActivityDetail, source int) (err error) {
  1603. defer func() {
  1604. if err != nil {
  1605. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ActivityUserRemind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1606. }
  1607. }()
  1608. //获取销售手机号
  1609. countUser, e := models.GetUserRemind(user.UserId)
  1610. if e != nil {
  1611. err = errors.New("GetUserRemind, Err: " + e.Error())
  1612. return
  1613. }
  1614. //获取销售手机号
  1615. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1616. if e != nil && e.Error() != utils.ErrNoRow() {
  1617. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  1618. return
  1619. }
  1620. if sellerItemQy == nil {
  1621. err = nil
  1622. return
  1623. }
  1624. //某销售下的所有客户活动报名/预约外呼时,模板消息提醒该销售(可设置销售范围,随时增减销售)
  1625. conf, e := models.GetConfigByCode("tpl_msg_seller_mobile")
  1626. if e != nil {
  1627. err = errors.New("GetConfigByCode, Err: " + e.Error())
  1628. return
  1629. }
  1630. //如果用户没有设置消息提醒,而且销售的手机号也没有添加到配置中,那么就不推送模版消息
  1631. if countUser == 0 && !strings.Contains(conf.ConfigValue, sellerItemQy.Mobile) {
  1632. err = nil
  1633. return
  1634. }
  1635. var sourceMsg string
  1636. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  1637. if e != nil {
  1638. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  1639. return
  1640. }
  1641. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  1642. if source == 1 {
  1643. sourceMsg = "预约外呼"
  1644. } else if source == 2 {
  1645. sourceMsg = "设置会议提醒"
  1646. } else if source == 3 {
  1647. sourceMsg = "预约纪要"
  1648. } else if source == 4 {
  1649. sourceMsg = "活动报名"
  1650. }
  1651. openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  1652. if e != nil {
  1653. err = errors.New("GetWxOpenIdByMobileList, Err: " + e.Error())
  1654. return err
  1655. }
  1656. var keyword1 string
  1657. var keyword2 string
  1658. keyword1 = activityDetail.ActivityName
  1659. keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
  1660. SendWxMsgWithActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
  1661. // 类目模版买方研选
  1662. if activityDetail.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  1663. openIdListMfyx, e := models.GetMfyxWxOpenIdByMobileList(sllerAndShareMobiles)
  1664. if e != nil {
  1665. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  1666. return err
  1667. }
  1668. var redirectUrl string
  1669. keyword1 = utils.TruncateActivityNameString(user.RealName + "-" + user.CompanyName)
  1670. keyword2 = fmt.Sprint("互动提醒:", sourceMsg)
  1671. keyword3 := utils.TruncateActivityNameString(activityDetail.ActivityName)
  1672. keyword4 := time.Now().Format(utils.FormatDateTimeMinute2)
  1673. redirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId)
  1674. SendWxCategoryMsgWithActivityUserRemind(keyword1, keyword2, keyword3, keyword4, redirectUrl, openIdListMfyx, activityDetail.ActivityId)
  1675. }
  1676. return
  1677. }
  1678. // 用户音视频回放操作操作行为,模板消息推送
  1679. func ActivityVideoUserRmind(user *models.WxUserItem, activityId, fileType int) (err error) {
  1680. defer func() {
  1681. if err != nil {
  1682. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  1683. }
  1684. }()
  1685. countUser, err := models.GetUserRemind(user.UserId)
  1686. if err != nil {
  1687. return err
  1688. }
  1689. if countUser == 0 {
  1690. return err
  1691. }
  1692. var first string
  1693. var keyword1 string
  1694. var keyword2 string
  1695. var keyword3 string
  1696. var keyword4 string
  1697. var remark string
  1698. //获取销售手机号
  1699. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1700. if err != nil && err.Error() != utils.ErrNoRow() {
  1701. return err
  1702. }
  1703. if sellerItemQy != nil {
  1704. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  1705. if e != nil {
  1706. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  1707. return
  1708. }
  1709. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  1710. openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  1711. if e != nil {
  1712. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1713. return
  1714. }
  1715. //TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
  1716. if fileType == 1 {
  1717. activityInfo, e := models.GetCygxActivityVideoByActivityId(activityId)
  1718. if e != nil {
  1719. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  1720. return
  1721. }
  1722. if activityInfo == nil {
  1723. return
  1724. }
  1725. keyword1 = activityInfo.VideoName
  1726. keyword2 = fmt.Sprint("互动:播放视频,", user.RealName, "--", user.CompanyName)
  1727. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放视频")
  1728. } else {
  1729. activityInfo, e := models.GetCygxActivityVoiceByActivityId(activityId)
  1730. if e != nil {
  1731. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  1732. return
  1733. }
  1734. if activityInfo == nil {
  1735. return
  1736. }
  1737. keyword1 = activityInfo.VoiceName
  1738. keyword2 = fmt.Sprint("互动:播放音频,", user.RealName, "--", user.CompanyName)
  1739. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放音频")
  1740. }
  1741. //keyword2 = "__"
  1742. //remark = "点击查看活动详情"
  1743. openIdArr := make([]string, 0)
  1744. for _, v := range openIdList {
  1745. openIdArr = append(openIdArr, v.OpenId)
  1746. }
  1747. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  1748. sendInfo := new(SendWxTemplate)
  1749. sendInfo.First = first
  1750. sendInfo.Keyword1 = keyword1
  1751. sendInfo.Keyword2 = keyword2
  1752. sendInfo.Keyword3 = keyword3
  1753. sendInfo.Keyword4 = keyword4
  1754. sendInfo.Remark = remark
  1755. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  1756. sendInfo.RedirectUrl = redirectUrl
  1757. sendInfo.RedirectTarget = 3
  1758. sendInfo.Resource = strconv.Itoa(activityId)
  1759. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1760. sendInfo.OpenIdArr = openIdArr
  1761. err = PublicSendTemplateMsg(sendInfo)
  1762. if err != nil {
  1763. return
  1764. }
  1765. }
  1766. return
  1767. }
  1768. // 获取活动分享封面图片
  1769. func GetActivityShareImg(activityDetail *models.ActivityDetail) (shareImg string) {
  1770. var err error
  1771. defer func() {
  1772. if err != nil {
  1773. go utils.SendAlarmMsg(fmt.Sprint("获取活动分享封面图片失败Err:", err.Error(), "活动ID:", activityDetail.ActivityId), 2)
  1774. }
  1775. }()
  1776. activityTypeId := activityDetail.ActivityTypeId
  1777. chartPermissionId := activityDetail.ChartPermissionId
  1778. city := activityDetail.City
  1779. //分析师C类电话会,等于分析师电话会
  1780. if activityTypeId == 7 {
  1781. activityTypeId = 2
  1782. }
  1783. defaultCity := []string{"北京", "广州", "杭州", "南京", "上海", "深圳", "苏州"} //几个默认城市
  1784. if city != "" {
  1785. if !utils.InArrayByStr(defaultCity, city) {
  1786. city = "其他"
  1787. }
  1788. }
  1789. imgDetail, e := models.CygxActivityShareImgDetail(activityTypeId, chartPermissionId, city)
  1790. if e != nil {
  1791. err = errors.New("CygxActivityShareImgDetail, Err: " + e.Error())
  1792. return
  1793. }
  1794. shareImg = imgDetail.Img
  1795. return
  1796. }