activity.go 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. "strconv"
  8. "strings"
  9. )
  10. // 获取 用户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户
  11. func GetUserType(companyId int) (userType int, permissionStrnew string, err error) {
  12. var permissionStr, permissionZhengShiStr string
  13. if companyId <= 1 {
  14. userType = 0
  15. } else {
  16. total, errs := models.GetCountCompanyDetailByIdGroup(companyId)
  17. if errs != nil {
  18. err = errs
  19. return
  20. }
  21. if total == 0 {
  22. userType = 0
  23. } else {
  24. companyDetail, errs := models.GetCompanyDetailByIdGroup(companyId)
  25. if errs != nil {
  26. err = errs
  27. return
  28. }
  29. permissionStr, errs = models.GetCompanyPermission(companyId)
  30. if errs != nil {
  31. err = errs
  32. return
  33. }
  34. permissionStrnew = permissionStr
  35. //大套餐客户,数据库添加标识,
  36. companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
  37. if errs != nil && errs.Error() != utils.ErrNoRow() {
  38. err = errs
  39. return
  40. }
  41. if companyUserTypeDetail != nil {
  42. if companyUserTypeDetail.CustomerTypeId != 0 {
  43. userType = companyUserTypeDetail.CustomerTypeId
  44. return
  45. }
  46. }
  47. permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
  48. if errs != nil {
  49. err = errs
  50. return
  51. }
  52. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
  53. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  54. if companyDetail.Status == "永续" {
  55. userType = 1
  56. } else if companyDetail.Status == "试用" {
  57. userType = 5
  58. } else if companyDetail.Status == "冻结" {
  59. userType = 6
  60. } else if companyDetail.Status == "流失" {
  61. userType = 7
  62. }
  63. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  64. if userType == 0 && companyDetail.Status == "正式" {
  65. var permissionZhegnshiNum int
  66. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  67. permissionZhegnshiNum++
  68. }
  69. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  70. permissionZhegnshiNum++
  71. }
  72. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  73. permissionZhegnshiNum++
  74. }
  75. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  76. permissionZhegnshiNum++
  77. }
  78. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  79. permissionZhegnshiNum++
  80. }
  81. if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
  82. permissionZhegnshiNum++
  83. }
  84. //if permissionZhegnshiNum == 6 {
  85. // userType = 2
  86. //} else
  87. //大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
  88. if permissionZhegnshiNum >= 4 {
  89. userType = 10
  90. } else {
  91. userType = 3
  92. }
  93. }
  94. }
  95. }
  96. permissionStrnew = permissionStr
  97. return
  98. }
  99. func GetUserTypeZhengShi(companyId int) (userType int, permissionStrnew, permissionStrZhengShinew string, err error) {
  100. var permissionStr, permissionZhengShiStr string
  101. if companyId <= 1 {
  102. userType = 0
  103. } else {
  104. total, errs := models.GetCountCompanyDetailByIdGroup(companyId)
  105. if errs != nil {
  106. err = errs
  107. return
  108. }
  109. if total == 0 {
  110. userType = 0
  111. } else {
  112. companyDetail, errs := models.GetCompanyDetailByIdGroup(companyId)
  113. if errs != nil {
  114. err = errs
  115. return
  116. }
  117. permissionStr, errs = models.GetCompanyPermission(companyId)
  118. if errs != nil {
  119. err = errs
  120. return
  121. }
  122. permissionStrnew = permissionStr
  123. permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
  124. if errs != nil {
  125. err = errs
  126. return
  127. }
  128. permissionStrZhengShinew = permissionZhengShiStr
  129. //大套餐客户,数据库添加标识,
  130. companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
  131. if errs != nil && errs.Error() != utils.ErrNoRow() {
  132. err = errs
  133. return
  134. }
  135. if companyUserTypeDetail != nil {
  136. if companyUserTypeDetail.CustomerTypeId != 0 {
  137. userType = companyUserTypeDetail.CustomerTypeId
  138. return
  139. }
  140. }
  141. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
  142. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  143. if companyDetail.Status == "永续" {
  144. userType = 1
  145. } else if companyDetail.Status == "试用" {
  146. userType = 5
  147. } else if companyDetail.Status == "冻结" {
  148. userType = 6
  149. } else if companyDetail.Status == "流失" {
  150. userType = 7
  151. }
  152. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  153. if userType == 0 && companyDetail.Status == "正式" {
  154. var permissionZhegnshiNum int
  155. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  156. permissionZhegnshiNum++
  157. }
  158. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  159. permissionZhegnshiNum++
  160. }
  161. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  162. permissionZhegnshiNum++
  163. }
  164. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  165. permissionZhegnshiNum++
  166. }
  167. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  168. permissionZhegnshiNum++
  169. }
  170. if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
  171. permissionZhegnshiNum++
  172. }
  173. //if permissionZhegnshiNum == 6 {
  174. // userType = 2
  175. //} else
  176. //大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
  177. if permissionZhegnshiNum >= 4 {
  178. userType = 10
  179. } else {
  180. userType = 3
  181. }
  182. }
  183. }
  184. }
  185. permissionStrnew = permissionStr
  186. permissionStrZhengShinew = permissionZhengShiStr
  187. return
  188. }
  189. // GetSpecialDetailUserPower 处理用户查看详情的权限
  190. func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.ActivityDetail) (havePower, isResearchSpecial bool, err error) {
  191. var companyDetailStatus string
  192. var userTypeStr string
  193. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  194. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  195. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityInfo.ActivityId] {
  196. isResearchSpecial = true
  197. }
  198. //如果是弘则的用户或者宏观的权限不做校验
  199. //if (GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID) || activityInfo.ChartPermissionName == utils.HONG_GUAN_NAME {
  200. if GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID {
  201. havePower = true
  202. return
  203. }
  204. userType, permissionStr, permissionStrZhengShi, e := GetUserTypeZhengShi(user.CompanyId)
  205. if e != nil {
  206. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  207. return
  208. }
  209. //如果一个权限都没有就返回无权限
  210. if permissionStr == "" {
  211. return
  212. }
  213. permissionStr += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限
  214. if permissionStrZhengShi == "" {
  215. permissionStrZhengShi = utils.HONG_GUAN_NAME // 添加一个宏观权限
  216. } else {
  217. permissionStrZhengShi += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限
  218. }
  219. //如果是易董的活动,主、副权限有一个满足即可
  220. if activityInfo.YidongActivityId != "" {
  221. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) || strings.Contains(permissionStr, activityInfo.ChartPermissionNameDeputy) {
  222. havePower = true
  223. return
  224. }
  225. }
  226. //如果权限不包含那么直接返回
  227. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  228. return
  229. }
  230. //如果是 对用户的研选扣点的必须要有研选的正式权限
  231. if activityInfo.IsResearchPoints {
  232. //获取活动对用户要扣的点
  233. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  234. if e != nil {
  235. err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error())
  236. return
  237. }
  238. if userPointsNum > 0 {
  239. //if !strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_YANXUAN) {
  240. // //如果连试用权限都没有,那么久按照普通的研选样式展示
  241. // isResearchSpecial = false
  242. //}
  243. if !strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  244. havePower = false
  245. return
  246. }
  247. }
  248. }
  249. //处理决策人可见权限
  250. if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 {
  251. havePower = false
  252. return
  253. }
  254. // 处理本组可见权限
  255. if activityInfo.VisibleRange == 1 {
  256. adminIds, e := models.GetSelleridWhichGroup(user.CompanyId, 2)
  257. if e != nil {
  258. err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
  259. return
  260. }
  261. haveVisibleRange := false
  262. adminIdSlice := strings.Split(adminIds, ",")
  263. for _, v := range adminIdSlice {
  264. if v == strconv.Itoa(activityInfo.AdminId) {
  265. haveVisibleRange = true
  266. }
  267. }
  268. if !haveVisibleRange {
  269. havePower = false
  270. return
  271. }
  272. }
  273. if permissionStr == "" {
  274. return
  275. }
  276. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  277. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  278. havePower = true
  279. return
  280. }
  281. //医药消费,科技,智造四大行业,验证主客观。如果主客观校验不通过,那么直接返回
  282. if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) {
  283. if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  284. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  285. havePower = true
  286. } else {
  287. havePower = false
  288. }
  289. } else {
  290. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  291. havePower = true
  292. } else {
  293. havePower = false
  294. }
  295. }
  296. if !havePower {
  297. return
  298. }
  299. }
  300. if activityInfo.LimitPeopleNum > 0 {
  301. mapUserType, e := GetActivityCcustomerTypeList()
  302. if e != nil {
  303. err = e
  304. return
  305. }
  306. userTypeStr = mapUserType[userType]
  307. // 永续客户、大套餐客户、30W套餐客户可以查看行业升级套餐客户 权限
  308. if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" {
  309. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  310. havePower = true
  311. //return
  312. }
  313. }
  314. } else {
  315. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  316. havePower = true
  317. return
  318. }
  319. }
  320. //判断管理规模是否满足
  321. companyProduct, e := models.GetCompanyProductDetail(user.CompanyId, 2)
  322. if e != nil {
  323. err = e
  324. return
  325. }
  326. if companyProduct != nil && activityInfo.Scale != "" {
  327. if strings.Contains(activityInfo.Scale, companyProduct.Scale) {
  328. havePower = true
  329. }
  330. }
  331. if user.CompanyId <= 1 {
  332. return
  333. } else {
  334. if permissionStr == "" {
  335. return
  336. } else {
  337. companyDetail, e := models.GetCompanyDetailById(user.CompanyId)
  338. if e != nil {
  339. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  340. return
  341. }
  342. if companyDetail == nil {
  343. err = errors.New("客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId))
  344. return
  345. }
  346. companyDetailStatus = companyDetail.Status
  347. }
  348. }
  349. //宏观满足用户可见身份验证权限既满足 2023-9-18
  350. if activityInfo.ChartPermissionId == 1 {
  351. if activityInfo.LimitPeopleNum > 0 {
  352. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  353. havePower = true
  354. return
  355. }
  356. } else {
  357. havePower = true
  358. return
  359. }
  360. }
  361. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == 0 {
  362. havePower = true
  363. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  364. havePower = true
  365. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  366. havePower = true
  367. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  368. havePower = true
  369. }
  370. fmt.Println(permissionStrZhengShi)
  371. //if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  372. // havePower = true
  373. // return
  374. //}
  375. if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" {
  376. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  377. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  378. havePower = true
  379. return
  380. }
  381. } else {
  382. if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  383. havePower = true
  384. return
  385. }
  386. }
  387. }
  388. permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId)
  389. if errs != nil {
  390. err = errs
  391. return
  392. }
  393. //fmt.Println("主客观2", havePower)
  394. //if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  395. // havePower = true
  396. //}
  397. //fmt.Println("主客观3", havePower)
  398. //处理升级权限以及用户身份的 双重判断
  399. if activityInfo.CustomerTypeIds != "" {
  400. if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" {
  401. havePower = false
  402. if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  403. havePower = true
  404. }
  405. }
  406. }
  407. if havePower && activityInfo.LimitPeopleNum > 0 {
  408. //对于一些特殊的活动,即使权限满足也不给产看
  409. noPower, e := GetShareNoPowe(activityInfo, permissionStr, userType, user)
  410. if e != nil {
  411. err = errors.New("GetShareNoPowe, Err: " + e.Error())
  412. return
  413. }
  414. if noPower {
  415. havePower = false
  416. }
  417. }
  418. return
  419. }
  420. // 校验被分享的用户是否有查看详情的权限
  421. func GetShareNoPowe(activityInfo *models.ActivityDetail, permissionStr string, userType int, user *models.WxUserItem) (noPower bool, err error) {
  422. //如果是弘则的就不进行可见权限校验
  423. if user.CompanyId == utils.HZ_COMPANY_ID {
  424. return
  425. }
  426. //var noPower bool
  427. //if !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
  428. // noPower = true
  429. //}
  430. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  431. //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)) {
  432. // noPower = true
  433. //}
  434. //if userType == 2 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  435. // noPower = true
  436. //}
  437. //if userType == 3 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  438. // noPower = true
  439. //}
  440. //if userType == 3 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  441. // noPower = true
  442. //}
  443. fmt.Println(userType)
  444. if userType == 8 {
  445. permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  446. if errs != nil {
  447. err = errs
  448. return
  449. }
  450. if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) {
  451. noPower = true
  452. return
  453. }
  454. }
  455. if !noPower {
  456. noPower, err = CheckUserPowerByActivityChoose(user, activityInfo)
  457. }
  458. return
  459. }
  460. // 处理活动本组们是否决策人权限
  461. func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *models.ActivityDetail) (noPower bool, err error) {
  462. //处理 见范围 1,仅本组可见 、2,全部客户可见
  463. if activityInfo.VisibleRange == 1 {
  464. adminIds, errAdmin := models.GetSelleridWhichGroup(user.CompanyId, 2)
  465. if errAdmin != nil {
  466. err = errAdmin
  467. return
  468. }
  469. sliceAdminIds := strings.Split(adminIds, ",")
  470. var haveAdminId bool
  471. for _, v := range sliceAdminIds {
  472. if v == strconv.Itoa(activityInfo.AdminId) {
  473. haveAdminId = true
  474. }
  475. }
  476. if !haveAdminId {
  477. noPower = true
  478. }
  479. }
  480. //处理 是否仅决策人可见 0,否 、1,是
  481. if activityInfo.IsMakerShow == 1 {
  482. if user.IsMaker == 0 {
  483. noPower = true
  484. }
  485. }
  486. return
  487. }
  488. // 根据用户身份处理活动可见
  489. func ActivityConditioninitSql(user *models.WxUserItem, condition string, isPower int) (conditionActivity string, err error) {
  490. //未登录的用户也可以查看所有活动v12.2.1
  491. if user.UserId == 0 {
  492. conditionActivity = ` AND art.publish_status = 1 AND art.yidong_activity_id = '' ` + condition
  493. return
  494. }
  495. // cygx_10.9 未绑定联系方式的客户可以看到部分活动
  496. if user.UserId == 0 || user.CompanyId == 1 {
  497. 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
  498. return
  499. }
  500. condition += ` AND art.publish_status = 1 `
  501. conditionActivity = condition
  502. //弘则可以查看所有活动
  503. if (GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID) || user.UserId == 0 {
  504. return
  505. }
  506. adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
  507. if err != nil {
  508. return
  509. }
  510. userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
  511. if err != nil {
  512. return
  513. }
  514. //判断客户规模是否属于可见范围的活动
  515. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  516. if err != nil && err.Error() != utils.ErrNoRow() {
  517. return
  518. }
  519. isMaker := user.IsMaker
  520. slicePer := strings.Split(permissionStr, ",")
  521. var permissionSqlStr string
  522. var permissionNameStr string
  523. for _, v := range slicePer {
  524. if userType == 1 {
  525. //研选权限处理
  526. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  527. permissionNameStr += "'" + v + "',"
  528. }
  529. } else {
  530. permissionNameStr += "'" + v + "',"
  531. }
  532. }
  533. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  534. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  535. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  536. slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
  537. var permissionNameStrZhengShi string
  538. for _, v := range slicePerZhengShi {
  539. if userType == 1 {
  540. //研选权限处理
  541. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  542. permissionNameStrZhengShi += "'" + v + "',"
  543. }
  544. } else {
  545. permissionNameStrZhengShi += "'" + v + "',"
  546. }
  547. }
  548. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
  549. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
  550. permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
  551. mapUserType, e := GetActivityCcustomerTypeList()
  552. if e != nil {
  553. err = e
  554. return
  555. }
  556. var userTypeStr string
  557. userTypeStr = mapUserType[userType]
  558. // 查研观向7.4-始终查询宏观的权限(无论是否有权限)
  559. if permissionNameStr == `` {
  560. permissionNameStr = `'宏观'`
  561. } else {
  562. permissionNameStr += `, '宏观'`
  563. }
  564. var sqlExport string // 专家权限处理
  565. sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  566. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  567. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  568. }
  569. sqlExport += `) `
  570. if isPower == 1 {
  571. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  572. condition += permissionSqlStr
  573. }
  574. var conditionOr string
  575. //查询全部可见的数据(是否全部客户可见)
  576. if adminIds != "" {
  577. condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  578. }
  579. //活动仅决策人可见
  580. if isMaker == 0 {
  581. condition += ` AND art.is_maker_show = 0 `
  582. }
  583. //condition += ` AND art.visible_range != 1 `
  584. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  585. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  586. }
  587. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  588. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  589. }
  590. if userType == 1 {
  591. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  592. } else {
  593. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  594. }
  595. if userType == 6 || userType == 7 {
  596. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
  597. }
  598. if companyProduct != nil {
  599. if companyProduct.Scale != "" {
  600. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  601. }
  602. }
  603. if userType == 3 {
  604. condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  605. }
  606. condition += ` AND art.is_limit_people = 1 `
  607. conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
  608. return
  609. }
  610. // 活动标签字符串处理
  611. func LabelStr(label string) (labelNew string) {
  612. slicebr := strings.Split(label, "-")
  613. if len(slicebr) < 2 {
  614. labelNew = label
  615. } else {
  616. labelNew = slicebr[1]
  617. }
  618. return labelNew
  619. }
  620. // 判断预约纪要按钮是否显示
  621. func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
  622. if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
  623. isShowAppointment = true
  624. }
  625. if activityTypeId == 5 && chartPermissionName == "医药" {
  626. isShowAppointment = true
  627. }
  628. return
  629. }
  630. // 用户报告操作行为,模板消息推送 (先放在活动模块下,避免代码冲突)
  631. func ArticleUserRemind(user *models.WxUserItem, articleDetail *models.ArticleDetail, source int) (err error) {
  632. defer func() {
  633. if err != nil {
  634. go utils.SendAlarmMsg(" 用户报告操作行为,模板消息推送失败"+fmt.Sprint("UserId:", user.UserId, "ArticleId:", articleDetail.ArticleId), 2)
  635. }
  636. }()
  637. countUser, err := models.GetUserRemind(user.UserId)
  638. if err != nil {
  639. return err
  640. }
  641. if countUser == 0 {
  642. return err
  643. }
  644. var sourceMsg string
  645. if source == 1 {
  646. sourceMsg = "阅读报告"
  647. } else {
  648. sourceMsg = "收藏报告"
  649. }
  650. //获取销售手机号
  651. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  652. if err != nil && err.Error() != utils.ErrNoRow() {
  653. return err
  654. }
  655. if sellerItemQy != nil {
  656. openIdList, err := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
  657. if err != nil {
  658. fmt.Println(err)
  659. return err
  660. }
  661. var keyword1 string
  662. var keyword2 string
  663. keyword1 = articleDetail.Title
  664. keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
  665. SendWxMsgWithArticleUserRemind(keyword1, keyword2, openIdList, articleDetail.ArticleId)
  666. }
  667. return
  668. }
  669. // 用户活动操作行为,模板消息推送
  670. func ActivityUserRemind(user *models.WxUserItem, activityDetail *models.ActivityDetail, source int) (err error) {
  671. defer func() {
  672. if err != nil {
  673. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ActivityUserRemind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  674. }
  675. }()
  676. //获取销售手机号
  677. countUser, e := models.GetUserRemind(user.UserId)
  678. if e != nil {
  679. err = errors.New("GetUserRemind, Err: " + e.Error())
  680. return
  681. }
  682. // 如果是买方研选下的专家沙龙,同时推给内容组四人
  683. if activityDetail.ActivityTypeId == 5 {
  684. go SendNeiRongZuActivitieSignTemplateMsg(user, activityDetail)
  685. }
  686. //获取销售手机号
  687. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  688. if e != nil && e.Error() != utils.ErrNoRow() {
  689. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  690. return
  691. }
  692. if sellerItemQy == nil {
  693. err = nil
  694. return
  695. }
  696. //某销售下的所有客户活动报名/预约外呼时,模板消息提醒该销售(可设置销售范围,随时增减销售)
  697. conf, e := models.GetConfigByCode("tpl_msg_seller_mobile")
  698. if e != nil {
  699. err = errors.New("GetConfigByCode, Err: " + e.Error())
  700. return
  701. }
  702. //如果用户没有设置消息提醒,而且销售的手机号也没有添加到配置中,那么就不推送模版消息
  703. if countUser == 0 && !strings.Contains(conf.ConfigValue, sellerItemQy.Mobile) {
  704. err = nil
  705. return
  706. }
  707. var sourceMsg string
  708. if source == 1 {
  709. sourceMsg = "预约外呼"
  710. } else if source == 2 {
  711. sourceMsg = "设置会议提醒"
  712. } else if source == 3 {
  713. sourceMsg = "预约纪要"
  714. } else if source == 4 {
  715. sourceMsg = "活动报名"
  716. }
  717. openIdList, e := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
  718. if e != nil {
  719. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error())
  720. return err
  721. }
  722. var keyword1 string
  723. var keyword2 string
  724. keyword1 = activityDetail.ActivityName
  725. keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
  726. SendWxMsgWithActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
  727. return
  728. }
  729. func ActivityButtonShow(item *models.ActivityDetail) (activityDetail *models.ActivityDetail) {
  730. if item.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  731. item.IsResearch = true
  732. }
  733. activityDetail = item
  734. //IsShowAppointment bool `description:"是否展示预约纪要"`
  735. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  736. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  737. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  738. //IsShowSignup bool `description:"是否展示我要报名"`
  739. activityTypeIdMap := GetActivityTypeIdMap()
  740. activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId] // 线上还是线下
  741. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  742. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  743. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  744. activityDetail.SiginupDeadline = ""
  745. }
  746. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  747. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  748. activityDetail.CancelDeadline = ""
  749. }
  750. activityTimeText := activityDetail.ActivityTimeText
  751. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  752. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  753. activityDetail.ActivityTimeText = activityTimeText
  754. if activityDetail.SourceType != 2 {
  755. activityDetail.SourceType = 1
  756. }
  757. activityDetail.IsShowAppointment = false
  758. //易董的操作按钮都隐藏
  759. if activityDetail.YidongActivityId != "" {
  760. activityDetail.SourceType = 1
  761. activityDetail.IsShowSignup = false
  762. activityDetail.IsShowDetails = true
  763. activityDetail.IsExternalLabel = true
  764. activityDetail.IsResearch = false
  765. activityDetail.IsResearchSpecial = false
  766. return
  767. }
  768. //专家电话会 1
  769. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  770. activityDetail.IsShowHelpSsk = true
  771. }
  772. //新的是否展示规则
  773. if activityDetail.IsCanAppointmentMinutes == 1 {
  774. activityDetail.IsShowAppointment = true
  775. } else {
  776. activityDetail.IsShowAppointment = false
  777. }
  778. if activityDetail.ActiveState == "1" {
  779. //专家电话会 1
  780. //专家电话会限制人数的展示我要报名,不限制的展示预约外外呼
  781. if activityDetail.ActivityTypeId == 1 {
  782. //articleDetail.IsShowOutboundCall = true
  783. if activityDetail.LimitPeopleNum == 0 {
  784. activityDetail.IsShowOutboundCall = true
  785. //articleDetail.IsShowHelpSsk = true
  786. } else {
  787. activityDetail.IsShowSignup = true
  788. }
  789. activityDetail.IsShowMeetingReminder = true
  790. activityDetail.IsShowHelpSsk = true
  791. }
  792. //分析师电话会 2
  793. if activityDetail.ActivityTypeId == 2 {
  794. if activityDetail.LimitPeopleNum == 0 {
  795. activityDetail.IsShowOutboundCall = true
  796. //articleDetail.IsShowHelpSsk = true
  797. } else {
  798. activityDetail.IsShowSignup = true
  799. }
  800. activityDetail.IsShowMeetingReminder = true
  801. }
  802. //公司调研电话会 3
  803. if activityDetail.ActivityTypeId == 3 {
  804. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  805. activityDetail.IsShowSignup = true
  806. } else {
  807. activityDetail.IsShowMeetingReminder = true
  808. activityDetail.IsShowOutboundCall = true
  809. }
  810. }
  811. //公司线下调研 4
  812. if activityDetail.ActivityTypeId == 4 {
  813. activityDetail.IsShowSignup = true
  814. }
  815. //专家线下沙龙 5
  816. if activityDetail.ActivityTypeId == 5 {
  817. activityDetail.IsShowSignup = true
  818. }
  819. //分析师线下沙龙 6
  820. if activityDetail.ActivityTypeId == 6 {
  821. activityDetail.IsShowSignup = true
  822. }
  823. //分析师电话会(C类) 7
  824. if activityDetail.ActivityTypeId == 7 {
  825. activityDetail.IsShowSignup = true
  826. activityDetail.IsShowMeetingReminder = true
  827. activityDetail.ActivityTypeName = "分析师电话会"
  828. }
  829. //买方线下交流 8 // 查研观向 11.0
  830. if activityDetail.ActivityTypeId == 8 {
  831. activityDetail.IsShowSignup = true
  832. }
  833. }
  834. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  835. if activityDetail.IsYidongConduct {
  836. activityDetail.IsShowSignup = true
  837. activityDetail.IsShowOutboundCall = false
  838. }
  839. return
  840. }
  841. func ActivityArrButtonShow(items []*models.ActivityDetail) (activityDetails []*models.ActivityDetail) {
  842. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  843. activityTypeIdMap := GetActivityTypeIdMap()
  844. for _, activityDetail := range items {
  845. activityDetail.ActivityType = activityTypeIdMap[activityDetail.ActivityTypeId] // 线上还是线下
  846. if activityDetail.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  847. activityDetail.IsResearch = true
  848. }
  849. //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
  850. if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] {
  851. activityDetail.IsResearchSpecial = true
  852. }
  853. //IsShowAppointment bool `description:"是否展示预约纪要"`
  854. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  855. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  856. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  857. //IsShowSignup bool `description:"是否展示我要报名"`
  858. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  859. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  860. activityDetail.SiginupDeadline = ""
  861. }
  862. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  863. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  864. activityDetail.CancelDeadline = ""
  865. }
  866. activityTimeText := activityDetail.ActivityTimeText
  867. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  868. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  869. activityDetail.ActivityTimeText = activityTimeText
  870. if activityDetail.SourceType != 2 {
  871. activityDetail.SourceType = 1
  872. }
  873. activityDetail.IsShowAppointment = false
  874. //易董的操作按钮都隐藏
  875. if activityDetail.YidongActivityId != "" {
  876. activityDetail.SourceType = 1
  877. activityDetail.IsShowSignup = false
  878. activityDetail.IsShowDetails = true
  879. } else {
  880. //专家电话会 1
  881. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  882. activityDetail.IsShowHelpSsk = true
  883. }
  884. //新的是否展示规则
  885. if activityDetail.IsCanAppointmentMinutes == 1 {
  886. activityDetail.IsShowAppointment = true
  887. } else {
  888. activityDetail.IsShowAppointment = false
  889. }
  890. if activityDetail.ActiveState == "1" {
  891. //专家电话会 1
  892. //专家电话会限制人数的展示我要报名,不限制的展示预约外外呼
  893. if activityDetail.ActivityTypeId == 1 {
  894. //articleDetail.IsShowOutboundCall = true
  895. if activityDetail.LimitPeopleNum == 0 {
  896. activityDetail.IsShowOutboundCall = true
  897. //articleDetail.IsShowHelpSsk = true
  898. } else {
  899. activityDetail.IsShowSignup = true
  900. }
  901. activityDetail.IsShowMeetingReminder = true
  902. activityDetail.IsShowHelpSsk = true
  903. }
  904. //分析师电话会 2
  905. if activityDetail.ActivityTypeId == 2 {
  906. if activityDetail.LimitPeopleNum == 0 {
  907. activityDetail.IsShowOutboundCall = true
  908. //articleDetail.IsShowHelpSsk = true
  909. } else {
  910. activityDetail.IsShowSignup = true
  911. }
  912. activityDetail.IsShowMeetingReminder = true
  913. }
  914. //公司调研电话会 3
  915. if activityDetail.ActivityTypeId == 3 {
  916. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  917. activityDetail.IsShowSignup = true
  918. } else {
  919. activityDetail.IsShowMeetingReminder = true
  920. activityDetail.IsShowOutboundCall = true
  921. }
  922. }
  923. //公司线下调研 4
  924. if activityDetail.ActivityTypeId == 4 {
  925. activityDetail.IsShowSignup = true
  926. }
  927. //专家线下沙龙 5
  928. if activityDetail.ActivityTypeId == 5 {
  929. activityDetail.IsShowSignup = true
  930. }
  931. //分析师线下沙龙 6
  932. if activityDetail.ActivityTypeId == 6 {
  933. activityDetail.IsShowSignup = true
  934. }
  935. //分析师电话会(C类) 7
  936. if activityDetail.ActivityTypeId == 7 {
  937. activityDetail.IsShowSignup = true
  938. activityDetail.IsShowMeetingReminder = true
  939. activityDetail.ActivityTypeName = "分析师电话会"
  940. }
  941. //买方线下交流 8 // 查研观向 11.0
  942. if activityDetail.ActivityTypeId == 8 {
  943. activityDetail.IsShowSignup = true
  944. }
  945. }
  946. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  947. if activityDetail.IsYidongConduct {
  948. activityDetail.IsShowSignup = true
  949. activityDetail.IsShowOutboundCall = false
  950. }
  951. }
  952. //如果是易董同步过来的,只展示外部资源标签
  953. if activityDetail.YidongActivityId != "" {
  954. activityDetail.IsExternalLabel = true
  955. activityDetail.IsResearch = false
  956. activityDetail.IsResearchSpecial = false
  957. }
  958. if activityDetail.ActivityTypeName == "买方线下交流" {
  959. activityDetail.LabelKeyword = utils.LABEL_L1_2
  960. }
  961. if activityDetail.ActivityTypeName == "专家电话会" || activityDetail.ActivityTypeName == "专家线下沙龙" {
  962. activityDetail.LabelKeyword = utils.LABEL_L1_3
  963. }
  964. if activityDetail.ActivityTypeName == "公司调研电话会" {
  965. activityDetail.LabelKeyword = utils.LABEL_L1_4
  966. }
  967. activityDetails = append(activityDetails, activityDetail)
  968. }
  969. return
  970. }
  971. // GetActivityNewLabelMap 获取活动【新】标签Map
  972. func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) {
  973. labelMap = make(map[int]bool, 0)
  974. industryNewMap = make(map[int]bool, 0)
  975. if len(activityIds) == 0 {
  976. return
  977. }
  978. // 获取活动关联的产业
  979. var groupCond string
  980. var groupPars []interface{}
  981. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 `
  982. groupPars = append(groupPars, activityIds)
  983. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  984. if e != nil {
  985. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  986. return
  987. }
  988. activityIndustryMap := make(map[int][]int, 0)
  989. industryIds := make([]int, 0)
  990. for i := range groups {
  991. industryIds = append(industryIds, groups[i].IndustrialManagementId)
  992. activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId)
  993. }
  994. // 获取新产业Map
  995. industryLabelMap, e := GetIndustryNewLabelMap(industryIds)
  996. if e != nil {
  997. err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  998. return
  999. }
  1000. // 判断活动是否为新
  1001. for k := range industryLabelMap {
  1002. for k2, v2 := range activityIndustryMap {
  1003. if labelMap[k2] {
  1004. continue
  1005. }
  1006. // 活动的产业ID中存在一个新产业即为新活动
  1007. if utils.InArrayByInt(v2, k) {
  1008. labelMap[k2] = true
  1009. }
  1010. }
  1011. }
  1012. ////产业关联的弘则报告发布日期在三个月以内的活动、产业显示 NEW标签
  1013. //articNewLabel, e := GetArticNewLabelWhithActivity3Month()
  1014. //if e != nil {
  1015. // err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  1016. // return
  1017. //}
  1018. //for k := range articNewLabel {
  1019. // labelMap[k] = true
  1020. //}
  1021. return
  1022. }
  1023. // GetActivityVoiceResp 处理活动音频回放
  1024. func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) {
  1025. activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId)
  1026. if err != nil && err.Error() != utils.ErrNoRow() {
  1027. return
  1028. }
  1029. mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq)
  1030. if len(activityVoiceList) > 0 {
  1031. for _, v := range activityVoiceList {
  1032. mapActivityVoice[v.ActivityId] = v
  1033. }
  1034. }
  1035. mapItem = mapActivityVoice
  1036. return
  1037. }
  1038. // GetActivityVideoResp 处理活动视频频回放
  1039. func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) {
  1040. var condition string
  1041. var ativityVIdstr string
  1042. for _, v := range mapActivityId {
  1043. ativityVIdstr += strconv.Itoa(v) + ","
  1044. }
  1045. if ativityVIdstr == "" {
  1046. return
  1047. }
  1048. ativityVIdstr = strings.TrimRight(ativityVIdstr, ",")
  1049. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  1050. var pars []interface{}
  1051. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  1052. //condition += ` AND art.activity_time > ? `
  1053. //pars = append(pars, endTime)
  1054. videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000)
  1055. if e != nil && e.Error() != utils.ErrNoRow() {
  1056. err = e
  1057. return
  1058. }
  1059. mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp)
  1060. if len(videoList) > 0 {
  1061. for _, v := range videoList {
  1062. mapActivityVideo[v.ActivityId] = v
  1063. }
  1064. }
  1065. mapItem = mapActivityVideo
  1066. return
  1067. }
  1068. // 用户音视频回放操作操作行为,模板消息推送
  1069. func ActivityVideoUserRmind(user *models.WxUserItem, activityId, fileType int) (err error) {
  1070. defer func() {
  1071. if err != nil {
  1072. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  1073. }
  1074. }()
  1075. countUser, err := models.GetUserRemind(user.UserId)
  1076. if err != nil {
  1077. return err
  1078. }
  1079. if countUser == 0 {
  1080. return err
  1081. }
  1082. var first string
  1083. var keyword1 string
  1084. var keyword2 string
  1085. var keyword3 string
  1086. var keyword4 string
  1087. var remark string
  1088. //获取销售手机号
  1089. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1090. if err != nil && err.Error() != utils.ErrNoRow() {
  1091. return err
  1092. }
  1093. if sellerItemQy != nil {
  1094. openIdList, e := models.GetWxOpenIdByMobileList(sellerItemQy.Mobile)
  1095. if e != nil {
  1096. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1097. return
  1098. }
  1099. //TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
  1100. if fileType == 1 {
  1101. activityInfo, e := models.GetCygxActivityVideoByActivityId(activityId)
  1102. if e != nil {
  1103. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  1104. return
  1105. }
  1106. if activityInfo == nil {
  1107. return
  1108. }
  1109. keyword1 = activityInfo.VideoName
  1110. keyword2 = fmt.Sprint("互动:播放视频,", user.RealName, "--", user.CompanyName)
  1111. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放视频")
  1112. } else {
  1113. activityInfo, e := models.GetCygxActivityVoiceByActivityId(activityId)
  1114. if e != nil {
  1115. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  1116. return
  1117. }
  1118. if activityInfo == nil {
  1119. return
  1120. }
  1121. keyword1 = activityInfo.VoiceName
  1122. keyword2 = fmt.Sprint("互动:播放音频,", user.RealName, "--", user.CompanyName)
  1123. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放音频")
  1124. }
  1125. //keyword2 = "__"
  1126. //remark = "点击查看活动详情"
  1127. openIdArr := make([]string, 0)
  1128. for _, v := range openIdList {
  1129. openIdArr = append(openIdArr, v.OpenId)
  1130. }
  1131. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  1132. sendInfo := new(SendWxTemplate)
  1133. sendInfo.First = first
  1134. sendInfo.Keyword1 = keyword1
  1135. sendInfo.Keyword2 = keyword2
  1136. sendInfo.Keyword3 = keyword3
  1137. sendInfo.Keyword4 = keyword4
  1138. sendInfo.Remark = remark
  1139. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  1140. sendInfo.RedirectUrl = redirectUrl
  1141. sendInfo.RedirectTarget = 3
  1142. sendInfo.Resource = strconv.Itoa(activityId)
  1143. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1144. sendInfo.OpenIdArr = openIdArr
  1145. err = PublicSendTemplateMsg(sendInfo)
  1146. if err != nil {
  1147. return
  1148. }
  1149. }
  1150. return
  1151. }
  1152. // 解析活动填写的报告链接
  1153. func GetActivityReportLinkToArticleList(item *models.ActivityDetail) (items []*models.ActivityArticleResp, err error) {
  1154. reportLink := item.ReportLink
  1155. //处理活动的
  1156. var articleIds []int
  1157. var articleList []string
  1158. if strings.Contains(reportLink, ";") {
  1159. articleList = strings.Split(reportLink, ";")
  1160. } else {
  1161. articleList = strings.Split(reportLink, ";")
  1162. }
  1163. for _, v := range articleList {
  1164. linkList := strings.Split(v, "/")
  1165. if linkList[len(linkList)-1] != "" {
  1166. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  1167. articleIds = append(articleIds, linkArticleId)
  1168. }
  1169. }
  1170. lenarticleIds := len(articleIds)
  1171. if lenarticleIds == 0 {
  1172. return
  1173. }
  1174. var condition string
  1175. var pars []interface{}
  1176. pars = make([]interface{}, 0)
  1177. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
  1178. pars = append(pars, articleIds)
  1179. listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  1180. if e != nil {
  1181. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1182. return
  1183. }
  1184. if len(listArticle) > 0 {
  1185. for _, v := range listArticle {
  1186. artItem := new(models.ActivityArticleResp)
  1187. artItem.ArticleId = v.ArticleId
  1188. artItem.Title = v.Title
  1189. items = append(items, artItem)
  1190. }
  1191. }
  1192. return
  1193. }
  1194. // 获取活动线上还是线下的类型
  1195. func GetActivityTypeIdMap() (mapResp map[int]int) {
  1196. var err error
  1197. defer func() {
  1198. if err != nil {
  1199. fmt.Println(err)
  1200. go utils.SendAlarmMsg("获取活动线上还是线下的类型,失败,GetActivityTypeIdMap:Err "+err.Error(), 2)
  1201. }
  1202. }()
  1203. list, e := models.GetActivityTypeList("")
  1204. if e != nil {
  1205. err = errors.New("GetActivityTypeList, Err: " + e.Error())
  1206. return
  1207. }
  1208. mapResp = make(map[int]int, 0)
  1209. for _, v := range list {
  1210. mapResp[v.ActivityTypeId] = v.ActivityType
  1211. }
  1212. return
  1213. }
  1214. // GetYanxuanActivityIds 获取研选活动ID
  1215. func GetYanxuanActivityIds() (activityIds []int) {
  1216. var err error
  1217. defer func() {
  1218. if err != nil {
  1219. fmt.Println(err)
  1220. go utils.SendAlarmMsg("获取研选活动ID GetYanxuanActivityIds,失败:"+err.Error(), 2)
  1221. }
  1222. }()
  1223. var condition string
  1224. var pars []interface{}
  1225. condition = ` AND chart_permission_id = ? AND yidong_activity_id = '' `
  1226. pars = append(pars, utils.CHART_PERMISSION_ID_YANXUAN)
  1227. list, e := models.GetCygxActivityIdList(condition, pars)
  1228. if e != nil {
  1229. err = errors.New("GetCygxActivityIdList, Err: " + e.Error())
  1230. return
  1231. }
  1232. for _, v := range list {
  1233. activityIds = append(activityIds, v.ActivityId)
  1234. }
  1235. return
  1236. }