activity.go 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  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. condition += ` AND art.publish_status = 1 `
  299. conditionActivity = condition
  300. //弘则可以查看所有活动
  301. if GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID {
  302. return
  303. }
  304. adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
  305. if err != nil {
  306. return
  307. }
  308. userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
  309. if err != nil {
  310. return
  311. }
  312. //判断客户规模是否属于可见范围的活动
  313. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  314. if err != nil && err.Error() != utils.ErrNoRow() {
  315. return
  316. }
  317. isMaker := user.IsMaker
  318. slicePer := strings.Split(permissionStr, ",")
  319. var permissionSqlStr string
  320. var permissionNameStr string
  321. for _, v := range slicePer {
  322. if userType == 1 {
  323. //研选权限处理
  324. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  325. permissionNameStr += "'" + v + "',"
  326. }
  327. } else {
  328. permissionNameStr += "'" + v + "',"
  329. }
  330. }
  331. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  332. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  333. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  334. slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
  335. var permissionNameStrZhengShi string
  336. for _, v := range slicePerZhengShi {
  337. if userType == 1 {
  338. //研选权限处理
  339. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  340. permissionNameStrZhengShi += "'" + v + "',"
  341. }
  342. } else {
  343. permissionNameStrZhengShi += "'" + v + "',"
  344. }
  345. }
  346. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
  347. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
  348. permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
  349. mapUserType, e := GetActivityCcustomerTypeList()
  350. if e != nil {
  351. err = e
  352. return
  353. }
  354. var userTypeStr string
  355. userTypeStr = mapUserType[userType]
  356. fmt.Println("userTypeStr", userTypeStr)
  357. // 查研观向7.4-始终查询宏观的权限(无论是否有权限)
  358. if permissionNameStr == `` {
  359. permissionNameStr = `'宏观'`
  360. } else {
  361. permissionNameStr += `, '宏观'`
  362. }
  363. var sqlExport string // 专家权限处理
  364. sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  365. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  366. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  367. }
  368. sqlExport += `) `
  369. if isPower == 1 {
  370. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  371. condition += permissionSqlStr
  372. }
  373. var conditionOr string
  374. //查询全部可见的数据(是否全部客户可见)
  375. if adminIds != "" {
  376. condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  377. }
  378. //活动仅决策人可见
  379. if isMaker == 0 {
  380. condition += ` AND art.is_maker_show = 0 `
  381. }
  382. //condition += ` AND art.visible_range != 1 `
  383. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  384. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  385. }
  386. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  387. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  388. }
  389. if userType == 1 {
  390. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  391. } else {
  392. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  393. }
  394. if userType == 6 || userType == 7 {
  395. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
  396. }
  397. if companyProduct != nil {
  398. if companyProduct.Scale != "" {
  399. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  400. }
  401. }
  402. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  403. if e != nil {
  404. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  405. return
  406. }
  407. // 升级客户可查看范围
  408. if conditionShengji != "" {
  409. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) `
  410. }
  411. // 正式客户可查看范围
  412. if conditionZhengshi != "" {
  413. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) `
  414. }
  415. // 行业客户可查看范围
  416. if conditionHangYe != "" {
  417. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) `
  418. }
  419. if userType == 3 {
  420. condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  421. }
  422. condition += ` AND art.is_limit_people = 1 `
  423. conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
  424. return
  425. }
  426. // 获取可见的活动
  427. func HandleActivityPowerList(listActivity []*models.CygxActivity, user *models.WxUserItem) (items []*models.CygxActivity, err error) {
  428. return
  429. }
  430. // 5.3版本活动标签字符串处理
  431. func LabelStr(label string, isShowSubjectName int, temporaryLabel string) (labelNew string) {
  432. slicebr := strings.Split(label, "-")
  433. if len(slicebr) > 1 {
  434. if isShowSubjectName == 1 {
  435. labelNew = slicebr[1]
  436. } else {
  437. labelNew = slicebr[0]
  438. }
  439. } else {
  440. labelNew = label
  441. }
  442. if temporaryLabel != "" {
  443. labelNew = temporaryLabel
  444. }
  445. return labelNew
  446. }
  447. // 列表
  448. func HandleActivityTypeHomeList(listType []*models.ActivityTypeHome, listActivity []*models.CygxActivity, user *models.WxUserItem) (items []*models.ActivityTypeHome, err error) {
  449. mapActivity := make(map[int][]*models.CygxActivityLabelList)
  450. activityIds := make([]int, 0) // 用于查询活动【新】标签Map
  451. for _, v := range listActivity {
  452. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  453. if v.ActivityTypeId == 7 {
  454. v.ActivityTypeId = 2
  455. }
  456. //if v.ActivityTypeId == 1 {
  457. activityIds = append(activityIds, v.ActivityId)
  458. //}
  459. }
  460. // 活动【新】标签Map
  461. newLabelMap, _, e := GetActivityNewLabelMap(activityIds)
  462. if e != nil {
  463. err = errors.New("获取产业新标签Map失败,GetActivityNewLabelMap Err: " + e.Error())
  464. return
  465. }
  466. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  467. mapkeyWord := make(map[string]string)
  468. for _, v := range listActivity {
  469. if v.Label == "" {
  470. continue
  471. }
  472. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  473. if v.ActivityTypeId == 7 {
  474. v.ActivityTypeId = 2
  475. }
  476. item := new(models.CygxActivityLabelList)
  477. item.KeyWord = LabelStr(v.Label, v.IsShowSubjectName, v.TemporaryLabel)
  478. if _, ok := mapkeyWord[fmt.Sprint(v.ActivityTypeId, "-", item.KeyWord)]; ok {
  479. continue
  480. }
  481. item.Resource = 1
  482. item.ActivityId = v.ActivityId
  483. if v.IsExternalLabel > 0 {
  484. item.IsExternalLabel = true
  485. }
  486. //if v.IsResearchPoints > 0 {
  487. item.IsResearchPoints = activityPointsByUserAllMap[v.ActivityId]
  488. //}
  489. item.City = v.City
  490. if utf8.RuneCountInString(v.City) != 2 {
  491. item.City = ""
  492. }
  493. item.IsNew = newLabelMap[v.ActivityId]
  494. mapActivity[v.ActivityTypeId] = append(mapActivity[v.ActivityTypeId], item)
  495. mapkeyWord[fmt.Sprint(v.ActivityTypeId, "-", item.KeyWord)] = item.KeyWord
  496. }
  497. for _, v := range listType {
  498. v.Resource = 1
  499. if len(mapActivity[v.ActivityTypeId]) > 0 {
  500. v.List = mapActivity[v.ActivityTypeId]
  501. } else {
  502. v.List = make([]*models.CygxActivityLabelList, 0)
  503. }
  504. }
  505. items = listType
  506. return
  507. }
  508. // GetActivityVoiceResp 处理活动音频回放
  509. func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) {
  510. activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId)
  511. if err != nil && err.Error() != utils.ErrNoRow() {
  512. return
  513. }
  514. mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq)
  515. if len(activityVoiceList) > 0 {
  516. for _, v := range activityVoiceList {
  517. mapActivityVoice[v.ActivityId] = v
  518. }
  519. }
  520. mapItem = mapActivityVoice
  521. return
  522. }
  523. // GetActivityVideoResp 处理活动视频频回放
  524. func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) {
  525. var condition string
  526. var ativityVIdstr string
  527. for _, v := range mapActivityId {
  528. ativityVIdstr += strconv.Itoa(v) + ","
  529. }
  530. if ativityVIdstr == "" {
  531. return
  532. }
  533. ativityVIdstr = strings.TrimRight(ativityVIdstr, ",")
  534. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  535. var pars []interface{}
  536. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  537. //condition += ` AND art.activity_time > ? `
  538. //pars = append(pars, endTime)
  539. videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000)
  540. if e != nil && e.Error() != utils.ErrNoRow() {
  541. err = e
  542. return
  543. }
  544. mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp)
  545. if len(videoList) > 0 {
  546. for _, v := range videoList {
  547. mapActivityVideo[v.ActivityId] = v
  548. }
  549. }
  550. mapItem = mapActivityVideo
  551. return
  552. }
  553. func ActivityButtonShow(item *models.ActivityDetail, user *models.WxUserItem, permissionArr []string) (itemActivity *models.ActivityListResp) {
  554. activityDetail := item
  555. //IsShowAppointment bool `description:"是否展示预约纪要"`
  556. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  557. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  558. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  559. //IsShowSignup bool `description:"是否展示我要报名"`
  560. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  561. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  562. activityDetail.IsResearch = true
  563. }
  564. //如果是 公司调研电话会:3,或 专家线下沙龙:5 而且 除易董同步过来的以外的研选类型活动,必须要有研选的正式权限
  565. if (activityDetail.ActivityTypeId == 3 || activityDetail.ActivityTypeId == 5) && activityDetail.YidongActivityId == "" && strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && utils.InArrayByStr(permissionArr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  566. activityDetail.IsResearchSpecial = true
  567. }
  568. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  569. activityDetail.SiginupDeadline = ""
  570. }
  571. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  572. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  573. activityDetail.CancelDeadline = ""
  574. }
  575. activityTimeText := activityDetail.ActivityTimeText
  576. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  577. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  578. activityDetail.ActivityTimeText = activityTimeText
  579. var yidongActivityUrl string
  580. activityDetail.IsShowAppointment = false
  581. //易董的操作按钮都隐藏
  582. if activityDetail.YidongActivityId != "" {
  583. activityDetail.IsShowSignup = false
  584. activityDetail.IsShowDetails = true
  585. if activityDetail.YidongActivityId != "" {
  586. ydTgc, _ := GetYiDongCreateUserInfo(user)
  587. yidongLongLink, _ := GetYiDongOriginalLink(activityDetail)
  588. if yidongLongLink != "" {
  589. yidongActivityUrl = yidongLongLink + "%26source=11%26fromHz=true%26tgc=" + ydTgc
  590. }
  591. }
  592. } else {
  593. //专家电话会 1
  594. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  595. activityDetail.IsShowHelpSsk = true
  596. }
  597. if activityDetail.ActiveState == "1" {
  598. //新的是否展示规则
  599. if activityDetail.IsCanAppointmentMinutes == 1 {
  600. activityDetail.IsShowAppointment = true
  601. }
  602. //专家电话会 1
  603. if activityDetail.ActivityTypeId == 1 {
  604. if activityDetail.LimitPeopleNum == 0 {
  605. activityDetail.IsShowOutboundCall = true
  606. } else {
  607. activityDetail.IsShowSignup = true
  608. }
  609. activityDetail.IsShowMeetingReminder = true
  610. activityDetail.IsShowHelpSsk = true
  611. }
  612. //分析师电话会 2
  613. if activityDetail.ActivityTypeId == 2 {
  614. if activityDetail.LimitPeopleNum == 0 {
  615. activityDetail.IsShowOutboundCall = true
  616. } else {
  617. activityDetail.IsShowSignup = true
  618. }
  619. activityDetail.IsShowMeetingReminder = true
  620. }
  621. if activityDetail.ActivityTypeId == 3 {
  622. //司调研电话会(3)、扣点的研选活动只展示我要报名
  623. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  624. activityDetail.IsShowSignup = true
  625. } else {
  626. activityDetail.IsShowMeetingReminder = true
  627. activityDetail.IsShowOutboundCall = true
  628. }
  629. }
  630. //公司线下调研 4
  631. if activityDetail.ActivityTypeId == 4 {
  632. activityDetail.IsShowSignup = true
  633. }
  634. //专家线下沙龙 5
  635. if activityDetail.ActivityTypeId == 5 {
  636. activityDetail.IsShowSignup = true
  637. }
  638. //分析师线下沙龙 6
  639. if activityDetail.ActivityTypeId == 6 {
  640. activityDetail.IsShowSignup = true
  641. }
  642. //分析师电话会(C类) 7
  643. if activityDetail.ActivityTypeId == 7 {
  644. activityDetail.IsShowSignup = true
  645. activityDetail.IsShowMeetingReminder = true
  646. }
  647. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  648. if activityDetail.IsYidongConduct {
  649. activityDetail.IsShowSignup = true
  650. activityDetail.IsShowOutboundCall = false
  651. }
  652. }
  653. }
  654. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  655. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  656. if e != nil {
  657. e = errors.New("获取用户权限失败, Err: " + e.Error())
  658. return
  659. }
  660. v := activityDetail
  661. itemActivity = &models.ActivityListResp{
  662. ActivityId: v.ActivityId,
  663. ActivityTypeId: v.ActivityTypeId,
  664. ActivityTypeName: v.ActivityTypeName,
  665. ChartPermissionId: v.ChartPermissionId,
  666. ChartPermissionName: v.ChartPermissionName,
  667. IsLimitPeople: v.IsLimitPeople,
  668. LimitPeopleNum: v.LimitPeopleNum,
  669. LastUpdatedTime: v.LastUpdatedTime,
  670. ActivityTime: v.ActivityTime,
  671. ActivityTimeText: v.ActivityTimeText,
  672. DistinguishedGuest: v.DistinguishedGuest,
  673. Host: v.Host,
  674. Speaker: v.Speaker,
  675. MainlandTell: v.MainlandTell,
  676. HongKongTell: v.HongKongTell,
  677. TaiwanTell: v.TaiwanTell,
  678. AmericaTell: v.AmericaTell,
  679. ParticipationCode: v.ParticipationCode,
  680. Theme: v.Theme,
  681. Expert: v.Expert,
  682. ActivityName: v.ActivityName,
  683. OnlineParticipation: v.OnlineParticipation,
  684. ReportLink: v.ReportLink,
  685. AppAttendance: v.AppAttendance,
  686. ConferencePassword: v.ConferencePassword,
  687. City: v.City,
  688. Address: v.Address,
  689. Highlights: v.Highlights,
  690. Remarks: v.Remarks,
  691. IsSignup: v.IsSignup,
  692. IsCancelMeetingReminder: v.IsCancelMeetingReminder,
  693. IsAppointment: v.IsAppointment,
  694. ActiveState: v.ActiveState,
  695. IsShowSustainable: v.IsShowSustainable,
  696. Description: v.Description,
  697. IsResearch: v.IsResearch,
  698. IsHideAppointment: v.IsHideAppointment,
  699. IsCClassMeeting: v.IsCClassMeeting,
  700. Label: v.Label,
  701. ImgUrl: v.ImgUrl,
  702. ImgUrlText: v.ImgUrlText,
  703. ActivityType: v.ActivityType,
  704. IsShowOutboundCall: v.IsShowOutboundCall,
  705. IsShowMeetingReminder: v.IsShowMeetingReminder,
  706. IsShowHelpSsk: v.IsShowHelpSsk,
  707. IsShowSignup: v.IsShowSignup,
  708. IsShowAppointment: v.IsShowAppointment,
  709. IsShowDetails: v.IsShowDetails,
  710. AudioLink: v.AudioLink,
  711. VoiceDetail: v.VoiceList,
  712. VideoDetail: v.VideoDetail,
  713. FileType: v.FileType,
  714. SourceType: v.SourceType,
  715. SignupNum: v.SignupNum,
  716. YidongActivityUrl: yidongActivityUrl,
  717. Explain: utils.ACtIVITY_SPECIAL_EXPLAIN,
  718. TripImgLink: v.TripImgLink,
  719. Days: v.Days,
  720. SignupType: v.SignupType,
  721. IsYidongConduct: v.IsYidongConduct,
  722. IsCanOutboundCall: v.IsCanOutboundCall,
  723. TencentConferenceNumber: v.TencentConferenceNumber,
  724. IsResearchSpecial: v.IsResearchSpecial,
  725. LinkParticipants: v.LinkParticipants,
  726. IsResearchPoints: v.IsResearchPoints,
  727. IsExternalLabel: v.IsExternalLabel,
  728. SiginupDeadline: v.SiginupDeadline,
  729. CancelDeadline: v.CancelDeadline,
  730. }
  731. au := new(models.UserPermissionAuthInfo)
  732. au.SellerName = authInfo.SellerName
  733. au.SellerMobile = authInfo.SellerMobile
  734. au.HasPermission = authInfo.HasPermission
  735. au.OperationMode = authInfo.OperationMode
  736. if au.HasPermission == 1 {
  737. // 非宏观权限进一步判断是否有权限
  738. if v.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, v.ChartPermissionName) {
  739. au.HasPermission = 2
  740. }
  741. }
  742. // 无权限的弹框提示
  743. if au.HasPermission != 1 {
  744. if au.OperationMode == UserPermissionOperationModeCall {
  745. if v.FileType == 1 {
  746. au.PopupMsg = UserPermissionPopupMsgCallMicroVoice
  747. } else {
  748. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  749. }
  750. } else {
  751. if v.FileType == 1 {
  752. au.PopupMsg = UserPermissionPopupMsgApplyMicroVoice
  753. } else {
  754. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  755. }
  756. }
  757. }
  758. itemActivity.AuthInfo = au
  759. //处理用户已经报名了的行程
  760. var activityIds []int
  761. activityIds = append(activityIds, v.ActivityId)
  762. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  763. if e != nil {
  764. e = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  765. return
  766. }
  767. if _, ok := UserMap[v.ActivityId]; ok {
  768. itemActivity.IsTrip = 1
  769. }
  770. if itemActivity.Days == 0 {
  771. itemActivity.TripStatus = 1
  772. //activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  773. } else {
  774. itemActivity.TripStatus = 2
  775. //itemActivity.TripImgLink = itemActivity.TripImgLinkFix
  776. //activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  777. }
  778. return
  779. }
  780. func ActivityDetaailShow(activityInfo *models.ActivityListResp) (itemActivity *models.ActivityListResp, err error) {
  781. itemActivity = activityInfo
  782. if GetShowSustainable() && strings.Contains(itemActivity.ChartPermissionName, "研选") {
  783. itemActivity.IsShowSustainable = true
  784. }
  785. if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
  786. activityInfo.SignupNum = activityInfo.LimitPeopleNum
  787. }
  788. if activityInfo.ReportLink != "" {
  789. artList, e := GetActivityReportLinkToArticleList(activityInfo)
  790. if e != nil && e.Error() != utils.ErrNoRow() {
  791. err = e
  792. return
  793. }
  794. if len(artList) == 0 {
  795. activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
  796. } else {
  797. activityInfo.ArticleList = artList
  798. }
  799. } else {
  800. activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
  801. }
  802. activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
  803. return
  804. }
  805. // GetActivityNewLabelMap 获取活动【新】标签Map
  806. func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) {
  807. labelMap = make(map[int]bool, 0)
  808. industryNewMap = make(map[int]bool, 0)
  809. if len(activityIds) == 0 {
  810. return
  811. }
  812. // 获取活动关联的产业
  813. var groupCond string
  814. var groupPars []interface{}
  815. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 `
  816. groupPars = append(groupPars, activityIds)
  817. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  818. if e != nil {
  819. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  820. return
  821. }
  822. activityIndustryMap := make(map[int][]int, 0)
  823. industryIds := make([]int, 0)
  824. for i := range groups {
  825. industryIds = append(industryIds, groups[i].IndustrialManagementId)
  826. activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId)
  827. }
  828. // 获取新产业Map
  829. industryLabelMap, e := GetIndustryNewLabelMap(industryIds)
  830. if e != nil {
  831. err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  832. return
  833. }
  834. // 判断活动是否为新
  835. for k := range industryLabelMap {
  836. for k2, v2 := range activityIndustryMap {
  837. if labelMap[k2] {
  838. continue
  839. }
  840. // 活动的产业ID中存在一个新产业即为新活动
  841. if utils.InArrayByInt(v2, k) {
  842. labelMap[k2] = true
  843. }
  844. }
  845. }
  846. //
  847. //////产业关联的弘则报告发布日期在三个月以内的活动、产业显示 NEW标签
  848. //articNewLabel, e := GetArticNewLabelWhithActivity3Month()
  849. //if e != nil {
  850. // err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  851. // return
  852. //}
  853. //for k := range articNewLabel {
  854. // labelMap[k] = true
  855. //}
  856. return
  857. }
  858. // GetIndustryNewLabelMap 获取产业【新】标签Map
  859. func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
  860. labelMap = make(map[int]bool, 0)
  861. industryIdLen := len(industryIds)
  862. if industryIdLen == 0 {
  863. return
  864. }
  865. // 获取产业关联的报告最早发布时间及最近的发布时间
  866. var timeCond string
  867. var timePars []interface{}
  868. timeCond += ` AND b.publish_status = 1`
  869. if industryIdLen > 0 {
  870. timeCond += ` AND a.industrial_management_id IN (` + utils.GetOrmInReplace(industryIdLen) + `)`
  871. timePars = append(timePars, industryIds)
  872. }
  873. //只要弘则报告,不要研选报告
  874. timeCond += ` AND b.article_id < ? `
  875. timePars = append(timePars, utils.SummaryArticleId)
  876. industryTimeList, e := models.GetIndustryArticleMinMaxPublishTime(timeCond, timePars)
  877. if e != nil {
  878. err = errors.New("获取产业文章最大最小发布时间失败, Err: " + e.Error())
  879. return
  880. }
  881. // 判断产业是否为新
  882. nowTime := time.Now().Local()
  883. threeMonthBefore := nowTime.AddDate(0, -3, 0)
  884. nullTime, _ := time.ParseInLocation(utils.FormatDateTime, "0001-01-01 00:00:00", time.Local)
  885. industryMap := make(map[int]*models.IndustryArticleMinMaxPublishTime, 0)
  886. for i := range industryTimeList {
  887. industryMap[industryTimeList[i].IndustrialManagementId] = industryTimeList[i]
  888. }
  889. for i := range industryIds {
  890. iid := industryIds[i]
  891. item := industryMap[iid]
  892. if item != nil {
  893. // 最早发布时间为空 / 最早发布时间在三个月前之后
  894. if item.MinPublishTime.Equal(nullTime) || (item.MinPublishTime.After(threeMonthBefore)) {
  895. labelMap[iid] = true
  896. }
  897. } else {
  898. // 产业无报告, 则为新产业
  899. labelMap[iid] = true
  900. }
  901. }
  902. return
  903. }
  904. // GetSpecialDetailUserPower 处理用户查看详情的权限
  905. func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.ActivityDetail) (havePower, isResearchSpecial bool, err error) {
  906. var companyDetailStatus string
  907. var userTypeStr string
  908. //如果是弘则的用户或者宏观的权限不做校验
  909. if (GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID) || activityInfo.ChartPermissionName == utils.HONG_GUAN_NAME {
  910. havePower = true
  911. return
  912. }
  913. userType, permissionStr, permissionStrZhengShi, e := GetUserTypeZhengShi(user.CompanyId)
  914. if e != nil {
  915. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  916. return
  917. }
  918. //如果是 公司调研电话会:3,或 专家线下沙龙:5 而且 除易董同步过来的以外的研选类型活动,必须要有研选的正式权限
  919. if (activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5) && activityInfo.YidongActivityId == "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  920. isResearchSpecial = true
  921. }
  922. //如果是 对用户的研选扣点的必须要有研选的正式权限
  923. if activityInfo.IsResearchPoints {
  924. //获取活动对用户要扣的点
  925. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  926. if e != nil {
  927. err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error())
  928. return
  929. }
  930. if userPointsNum > 0 {
  931. if !strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_YANXUAN) {
  932. //如果连试用权限都没有,那么久按照普通的研选样式展示
  933. isResearchSpecial = false
  934. }
  935. if !strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  936. havePower = false
  937. return
  938. }
  939. }
  940. }
  941. //处理决策人可见权限
  942. if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 {
  943. havePower = false
  944. return
  945. }
  946. // 处理本组可见权限
  947. if activityInfo.VisibleRange == 1 {
  948. adminIds, e := models.GetSelleridWhichGroup(user.CompanyId, 2)
  949. if e != nil {
  950. err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
  951. return
  952. }
  953. haveVisibleRange := false
  954. adminIdSlice := strings.Split(adminIds, ",")
  955. for _, v := range adminIdSlice {
  956. if v == strconv.Itoa(activityInfo.AdminId) {
  957. haveVisibleRange = true
  958. }
  959. }
  960. if !haveVisibleRange {
  961. havePower = false
  962. return
  963. }
  964. }
  965. if permissionStr == "" {
  966. return
  967. }
  968. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  969. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  970. havePower = true
  971. return
  972. }
  973. //医药消费,科技,智造四大行业,验证主客观。如果主客观校验不通过,那么直接返回
  974. if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) {
  975. if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  976. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  977. havePower = true
  978. } else {
  979. havePower = false
  980. }
  981. } else {
  982. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  983. havePower = true
  984. } else {
  985. havePower = false
  986. }
  987. }
  988. //如果主客观校验不通过,那么直接返回
  989. if !havePower {
  990. return
  991. }
  992. }
  993. if activityInfo.LimitPeopleNum > 0 {
  994. mapUserType, e := GetActivityCcustomerTypeList()
  995. if e != nil {
  996. err = e
  997. return
  998. }
  999. userTypeStr = mapUserType[userType]
  1000. // 永续客户、大套餐客户、30W套餐客户可以查看行业升级套餐客户 权限
  1001. if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" {
  1002. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  1003. havePower = true
  1004. //return
  1005. }
  1006. }
  1007. } else {
  1008. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1009. havePower = true
  1010. return
  1011. }
  1012. }
  1013. //判断管理规模是否满足
  1014. companyProduct, e := models.GetCompanyProductDetail(user.CompanyId, 2)
  1015. if e != nil {
  1016. err = e
  1017. return
  1018. }
  1019. if companyProduct != nil && activityInfo.Scale != "" {
  1020. if strings.Contains(activityInfo.Scale, companyProduct.Scale) {
  1021. havePower = true
  1022. }
  1023. }
  1024. if user.CompanyId <= 1 {
  1025. return
  1026. } else {
  1027. if permissionStr == "" {
  1028. return
  1029. } else {
  1030. companyDetail, e := models.GetCompanyDetailById(user.CompanyId)
  1031. if e != nil {
  1032. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1033. return
  1034. }
  1035. if companyDetail == nil {
  1036. err = errors.New("客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId))
  1037. return
  1038. }
  1039. companyDetailStatus = companyDetail.Status
  1040. }
  1041. }
  1042. if activityInfo.ChartPermissionId == 1 {
  1043. havePower = true
  1044. return
  1045. }
  1046. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == 0 {
  1047. havePower = true
  1048. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  1049. havePower = true
  1050. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  1051. havePower = true
  1052. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  1053. havePower = true
  1054. }
  1055. fmt.Println(permissionStrZhengShi)
  1056. //if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1057. // havePower = true
  1058. // return
  1059. //}
  1060. if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" {
  1061. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  1062. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1063. havePower = true
  1064. return
  1065. }
  1066. } else {
  1067. if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  1068. havePower = true
  1069. return
  1070. }
  1071. }
  1072. }
  1073. permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId)
  1074. if errs != nil {
  1075. err = errs
  1076. return
  1077. }
  1078. //fmt.Println("主客观2", havePower)
  1079. //if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  1080. // havePower = true
  1081. //}
  1082. //fmt.Println("主客观3", havePower)
  1083. //处理升级权限以及用户身份的 双重判断
  1084. if activityInfo.CustomerTypeIds != "" {
  1085. if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" {
  1086. havePower = false
  1087. if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  1088. havePower = true
  1089. }
  1090. }
  1091. }
  1092. if havePower && activityInfo.LimitPeopleNum > 0 {
  1093. //对于一些特殊的活动,即使权限满足也不给产看
  1094. noPower, e := GetShareNoPowe(activityInfo, permissionStr, userType, user)
  1095. if e != nil {
  1096. err = errors.New("GetShareNoPowe, Err: " + e.Error())
  1097. return
  1098. }
  1099. if noPower {
  1100. havePower = false
  1101. }
  1102. }
  1103. return
  1104. }
  1105. // 校验被分享的用户是否有查看详情的权限
  1106. func GetShareNoPowe(activityInfo *models.ActivityDetail, permissionStr string, userType int, user *models.WxUserItem) (noPower bool, err error) {
  1107. //如果是弘则的就不进行可见权限校验
  1108. if user.CompanyId == utils.HZ_COMPANY_ID {
  1109. return
  1110. }
  1111. //var noPower bool
  1112. //if !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
  1113. // noPower = true
  1114. //}
  1115. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  1116. //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)) {
  1117. // noPower = true
  1118. //}
  1119. //if userType == 2 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  1120. // noPower = true
  1121. //}
  1122. //if userType == 3 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  1123. // noPower = true
  1124. //}
  1125. //if userType == 3 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  1126. // noPower = true
  1127. //}
  1128. if userType == 8 {
  1129. permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  1130. if errs != nil {
  1131. err = errs
  1132. return
  1133. }
  1134. if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) {
  1135. noPower = true
  1136. return
  1137. }
  1138. }
  1139. if !noPower {
  1140. noPower, err = CheckUserPowerByActivityChoose(user, activityInfo)
  1141. }
  1142. return
  1143. }
  1144. // 处理活动本组们是否决策人权限
  1145. func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *models.ActivityDetail) (noPower bool, err error) {
  1146. //处理 见范围 1,仅本组可见 、2,全部客户可见
  1147. if activityInfo.VisibleRange == 1 {
  1148. adminIds, errAdmin := models.GetSelleridWhichGroup(user.CompanyId, 2)
  1149. if errAdmin != nil {
  1150. err = errAdmin
  1151. return
  1152. }
  1153. sliceAdminIds := strings.Split(adminIds, ",")
  1154. var haveAdminId bool
  1155. for _, v := range sliceAdminIds {
  1156. if v == strconv.Itoa(activityInfo.AdminId) {
  1157. haveAdminId = true
  1158. }
  1159. }
  1160. if !haveAdminId {
  1161. noPower = true
  1162. }
  1163. }
  1164. //处理 是否仅决策人可见 0,否 、1,是
  1165. if activityInfo.IsMakerShow == 1 {
  1166. if user.IsMaker == 0 {
  1167. noPower = true
  1168. }
  1169. }
  1170. return
  1171. }
  1172. // 判断预约纪要按钮是否显示
  1173. func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
  1174. if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
  1175. isShowAppointment = true
  1176. }
  1177. if activityTypeId == 5 && chartPermissionName == "医药" {
  1178. isShowAppointment = true
  1179. }
  1180. return
  1181. }
  1182. // GetindustryVideoDetailById 通过视频ID获取视频详情
  1183. func GetActivityVideoDetailById(user *models.WxUserItem, videoId int) (industryVideo *models.CygxActivityVideoDetailResp, AuthInfo *models.UserPermissionAuthInfo, err error) {
  1184. total, e := models.GetActivityVideoByVideoIdCount(videoId)
  1185. if e != nil {
  1186. err = errors.New("获取活动的视频失败,GetActivityVideoByVideoIdCount " + e.Error())
  1187. return
  1188. }
  1189. if total == 0 {
  1190. err = errors.New("视频不存在,或已取消发布")
  1191. return
  1192. }
  1193. // 用户权限
  1194. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1195. if e != nil {
  1196. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  1197. return
  1198. }
  1199. videoSimple := new(models.CygxActivityVideoDetailResp)
  1200. // 权限
  1201. var au *models.UserPermissionAuthInfo
  1202. videoSimple, e = models.GetCygxActivityVideoById(videoId)
  1203. if e != nil {
  1204. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  1205. return
  1206. } else {
  1207. //videoSimple.Id = video.Id
  1208. //videoSimple.Title = video.Title
  1209. //videoSimple.ResourceUrl = video.ResourceUrl
  1210. //videoSimple.PlaySeconds = video.PlaySeconds
  1211. //videoSimple.ActivityId = video.ActivityId
  1212. //videoSimple.ChartPermissionId = video.ChartPermissionId
  1213. if videoSimple.BackgroundImg == "" {
  1214. // 获取默认图配置
  1215. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  1216. if e != nil {
  1217. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  1218. return
  1219. }
  1220. videoSimple.BackgroundImg = videoMap[videoSimple.ChartPermissionId]
  1221. }
  1222. au = new(models.UserPermissionAuthInfo)
  1223. au.SellerName = authInfo.SellerName
  1224. au.SellerMobile = authInfo.SellerMobile
  1225. au.HasPermission = authInfo.HasPermission
  1226. au.OperationMode = authInfo.OperationMode
  1227. if au.HasPermission == 1 {
  1228. // 非宏观权限进一步判断是否有权限
  1229. if videoSimple.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, videoSimple.ChartPermissionName) {
  1230. au.HasPermission = 2
  1231. }
  1232. }
  1233. // 无权限的弹框提示
  1234. if au.HasPermission != 1 {
  1235. if au.OperationMode == UserPermissionOperationModeCall {
  1236. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  1237. } else {
  1238. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  1239. }
  1240. videoSimple.ResourceUrl = ""
  1241. }
  1242. }
  1243. industryVideo = videoSimple
  1244. AuthInfo = au
  1245. return
  1246. }
  1247. // 用户活动操作行为,模板消息推送
  1248. func ActivityUserRemind(user *models.WxUserItem, activityDetail *models.ActivityDetail, source int) (err error) {
  1249. defer func() {
  1250. if err != nil {
  1251. go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  1252. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1253. }
  1254. }()
  1255. countUser, err := models.GetUserRemind(user.UserId)
  1256. if err != nil {
  1257. return err
  1258. }
  1259. if countUser == 0 {
  1260. return err
  1261. }
  1262. var sourceMsg string
  1263. if source == 1 {
  1264. sourceMsg = "预约外呼"
  1265. } else if source == 2 {
  1266. sourceMsg = "设置会议提醒"
  1267. } else if source == 3 {
  1268. sourceMsg = "预约纪要"
  1269. } else if source == 4 {
  1270. sourceMsg = "活动报名"
  1271. }
  1272. //获取销售手机号
  1273. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1274. if err != nil && err.Error() != utils.ErrNoRow() {
  1275. return err
  1276. }
  1277. if sellerItemQy != nil {
  1278. openIdList, err := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
  1279. if err != nil {
  1280. fmt.Println(err)
  1281. return err
  1282. }
  1283. var keyword1 string
  1284. var keyword2 string
  1285. keyword1 = activityDetail.ActivityName
  1286. keyword2 = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:", sourceMsg)
  1287. SendWxMsgWithActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
  1288. }
  1289. return
  1290. }