activity.go 49 KB

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