activity.go 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "unicode/utf8"
  11. )
  12. // 获取活动列表查询权限的SQL
  13. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  14. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  15. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  16. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  17. // @Param WhichTime query string false "已结束的时间筛选项 本周:1、上周:2 、本月:3、上月:4"
  18. // @Param Label query string false "搜索主题 多个用 , 隔开"
  19. // @Param PlayBack query int false "是否仅展示回放 1:是、0:否 默认0"
  20. // @Param KeyWord query string false "搜索关键词"
  21. // @Param ikType query int false "联想词类型 , 1不做联想,2,做除初始词的联想,3所有联想"
  22. func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermissionIds, whichDay, activeState, label string, isPower, source int, keyWord string, playBack, ikType int) (conditionActivity string, err error) {
  23. keyWordNoIk := keyWord
  24. adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
  25. if err != nil {
  26. return
  27. }
  28. userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
  29. if err != nil {
  30. return
  31. }
  32. //判断客户规模是否属于可见范围的活动
  33. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  34. if err != nil && err.Error() != utils.ErrNoRow() {
  35. return
  36. }
  37. isMaker := user.IsMaker
  38. slicePer := strings.Split(permissionStr, ",")
  39. var permissionSqlStr string
  40. var permissionNameStr string
  41. for _, v := range slicePer {
  42. if userType == 1 {
  43. //研选权限处理
  44. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  45. permissionNameStr += "'" + v + "',"
  46. }
  47. } else {
  48. permissionNameStr += "'" + v + "',"
  49. }
  50. }
  51. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  52. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  53. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  54. slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
  55. var permissionNameStrZhengShi string
  56. for _, v := range slicePerZhengShi {
  57. if userType == 1 {
  58. //研选权限处理
  59. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  60. permissionNameStrZhengShi += "'" + v + "',"
  61. }
  62. } else {
  63. permissionNameStrZhengShi += "'" + v + "',"
  64. }
  65. }
  66. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
  67. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
  68. permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
  69. mapUserType, e := GetActivityCcustomerTypeList()
  70. if e != nil {
  71. err = e
  72. return
  73. }
  74. var userTypeStr string
  75. userTypeStr = mapUserType[userType]
  76. // 查研观向7.4-始终查询宏观的权限(无论是否有权限)
  77. if permissionNameStr == `` {
  78. permissionNameStr = `'宏观'`
  79. } else {
  80. permissionNameStr += `, '宏观'`
  81. }
  82. var condition string
  83. var conditionAdmin string
  84. var conditionHz string // 弘则权限处理
  85. var sqlExport string // 专家权限处理
  86. //permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  87. sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  88. //if userType == 2 {
  89. // sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  90. //}
  91. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  92. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  93. }
  94. sqlExport += `) `
  95. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  96. if activityTypeId != "" {
  97. if activityTypeId == strconv.Itoa(utils.ANALYST_TELL_ACTIVITY_TYPE_ID) {
  98. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id IN (` + activityTypeId + "," + strconv.Itoa(utils.C_CLASS_ACTIVITY_TYPE_ID) + `)`
  99. } else {
  100. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id IN (` + activityTypeId + `)`
  101. }
  102. }
  103. //主题
  104. if label != "" {
  105. condition = ` AND art.label LIKE "%` + label + `%" `
  106. }
  107. if isPower == 1 {
  108. condition += permissionSqlStr
  109. }
  110. //行业名称
  111. if len(chartPermissionIds) > 0 {
  112. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  113. }
  114. //如果是PC的,则不看易董的
  115. if source == 1 {
  116. condition += ` AND art.yidong_activity_id = '' `
  117. }
  118. var conditionOr string
  119. if whichDay != "" {
  120. var startDate string
  121. var endDate string
  122. if whichDay == "1" {
  123. startDate = time.Now().Format(utils.FormatDate)
  124. endDate = startDate
  125. } else if whichDay == "2" {
  126. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  127. endDate = startDate
  128. } else if whichDay == "3" {
  129. startDate = utils.GetNowWeekMonday().Format(utils.FormatDate)
  130. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  131. } else if whichDay == "4" {
  132. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  133. endDate = utils.GetLastWeekSunday().Format(utils.FormatDate)
  134. } else if whichDay == "5" {
  135. startDate = utils.GetNowMonthFirstDay().Format(utils.FormatDate)
  136. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  137. } else if whichDay == "6" {
  138. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  139. endDate = utils.GetLastMonthLastDay().Format(utils.FormatDate)
  140. } else if whichDay == "1,2" {
  141. startDate = time.Now().Format(utils.FormatDate)
  142. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  143. } else if whichDay == "3,4" {
  144. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  145. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  146. } else if whichDay == "5,6" {
  147. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  148. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  149. } else {
  150. startDate = time.Now().Format(utils.FormatDate)
  151. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  152. }
  153. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  154. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  155. }
  156. //有搜索条件传过来时,不判进行状态条件
  157. if keyWord != "" {
  158. if ikType == 2 || ikType == 3 {
  159. keyWordArr, e := GetIndustryMapNameSliceV3(keyWord)
  160. if e != nil {
  161. err = errors.New("获取分词失败,GetIndustryMapNameSliceV3, Err: " + keyWord + e.Error())
  162. return
  163. }
  164. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  165. //var keywords string
  166. if len(keyWordArr) > 1 {
  167. if ikType == 2 {
  168. keyWord = KeyWordArrSqlRegexp(keyWordArr)
  169. condition += ` AND (art.label NOT LIKE '%` + keyWordNoIk + `%' AND art.activity_name NOT LIKE '%` + keyWordNoIk + `%' ) `
  170. } else if ikType == 3 {
  171. keyWord = KeyWordArrSqlRegexpAll(keyWordArr)
  172. }
  173. }
  174. }
  175. condition += ` AND (art.label REGEXP '` + keyWord + `' OR art.activity_name REGEXP '` + keyWord + `' ) `
  176. } else {
  177. if activeState != "" {
  178. // 默认查看未开始跟进行中
  179. if activeState == "1" {
  180. condition += ` AND art.active_state IN (1,2)`
  181. } else {
  182. condition += ` AND art.active_state IN (` + activeState + `)`
  183. }
  184. } else {
  185. condition += ` AND art.active_state IN (1,2)`
  186. }
  187. }
  188. if playBack == 1 {
  189. var pars []interface{}
  190. ativityVIdArry := make([]string, 0)
  191. voiceList, e := models.GetActivityVoiceListAll("", pars, 0, 1000)
  192. if e != nil && e.Error() != utils.ErrNoRow() {
  193. err = e
  194. return
  195. }
  196. for _, v := range voiceList {
  197. ativityVIdArry = append(ativityVIdArry, strconv.Itoa(v.ActivityId))
  198. }
  199. videoList, e := models.GetActivityVideoListAll("", pars, 0, 1000)
  200. if e != nil && e.Error() != utils.ErrNoRow() {
  201. err = e
  202. return
  203. }
  204. for _, v := range videoList {
  205. ativityVIdArry = append(ativityVIdArry, strconv.Itoa(v.ActivityId))
  206. }
  207. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  208. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  209. //condition += ` AND art.activity_time > '` + endTime + `' `
  210. if len(ativityVIdArry) > 0 {
  211. ativityVIdstr := strings.Join(ativityVIdArry, ",")
  212. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  213. } else {
  214. condition += ` AND art.activity_id = 0 `
  215. }
  216. }
  217. //查询全部可见的数据(是否全部客户可见)
  218. //condition += ` AND art.visible_range != 1 AND art.publish_status = 1 `
  219. condition += ` AND art.publish_status = 1 `
  220. //if adminIds == "" {
  221. // //condition += ` AND art.visible_range != 1 `
  222. //} else {
  223. // condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  224. //}
  225. if adminIds != "" {
  226. condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  227. }
  228. conditionHz = condition
  229. //活动仅决策人可见
  230. if isMaker == 0 {
  231. condition += ` AND art.is_maker_show = 0 `
  232. }
  233. conditionAdmin = condition + ` AND art.visible_range = 1 `
  234. //condition += ` AND art.visible_range != 1 `
  235. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  236. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  237. }
  238. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  239. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  240. }
  241. if userType == 1 {
  242. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  243. } else {
  244. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  245. }
  246. if userType == 6 || userType == 7 {
  247. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
  248. }
  249. if companyProduct != nil {
  250. if companyProduct.Scale != "" {
  251. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  252. }
  253. }
  254. if adminIds != "" {
  255. if userType == 3 {
  256. conditionAdmin += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  257. }
  258. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + userTypeStr + `%' ` + ` AND art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) `
  259. if companyProduct != nil {
  260. if companyProduct.Scale != "" {
  261. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%'` + ` AND art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) `
  262. }
  263. }
  264. }
  265. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  266. if e != nil {
  267. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  268. return
  269. }
  270. if conditionShengji != "" {
  271. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) `
  272. }
  273. if conditionZhengshi != "" {
  274. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) `
  275. }
  276. if conditionHangYe != "" {
  277. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) `
  278. }
  279. //弘则研究下的客户不做权限,限制,C类电话会,仅本组销售、部门管理员、admin、权益研究员账号能看到
  280. if user.CompanyId == utils.HZ_COMPANY_ID {
  281. mapMobile, e := GetAdminMobileMap()
  282. if e != nil {
  283. err = e
  284. return
  285. }
  286. if _, ok := mapMobile[user.Mobile]; ok {
  287. conditionOr += ` OR ( art.publish_status = 1 ` + conditionHz + `) `
  288. }
  289. }
  290. if userType == 3 {
  291. condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  292. }
  293. conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
  294. return
  295. }
  296. // 根据用户身份处理活动可见
  297. func ActivityConditioninitSql(user *models.WxUserItem, condition string, isPower int) (conditionActivity string, err error) {
  298. condition += ` AND art.publish_status = 1 `
  299. conditionActivity = condition
  300. //弘则可以查看所有活动
  301. if GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID {
  302. return
  303. }
  304. adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2)
  305. if err != nil {
  306. return
  307. }
  308. userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId)
  309. if err != nil {
  310. return
  311. }
  312. //判断客户规模是否属于可见范围的活动
  313. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  314. if err != nil && err.Error() != utils.ErrNoRow() {
  315. return
  316. }
  317. isMaker := user.IsMaker
  318. slicePer := strings.Split(permissionStr, ",")
  319. var permissionSqlStr string
  320. var permissionNameStr string
  321. for _, v := range slicePer {
  322. if userType == 1 {
  323. //研选权限处理
  324. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  325. permissionNameStr += "'" + v + "',"
  326. }
  327. } else {
  328. permissionNameStr += "'" + v + "',"
  329. }
  330. }
  331. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  332. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  333. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  334. slicePerZhengShi := strings.Split(permissionStrZhengShi, ",")
  335. var permissionNameStrZhengShi string
  336. for _, v := range slicePerZhengShi {
  337. if userType == 1 {
  338. //研选权限处理
  339. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  340. permissionNameStrZhengShi += "'" + v + "',"
  341. }
  342. } else {
  343. permissionNameStrZhengShi += "'" + v + "',"
  344. }
  345. }
  346. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1)
  347. permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1)
  348. permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",")
  349. mapUserType, e := GetActivityCcustomerTypeList()
  350. if e != nil {
  351. err = e
  352. return
  353. }
  354. var userTypeStr string
  355. userTypeStr = mapUserType[userType]
  356. // 查研观向7.4-始终查询宏观的权限(无论是否有权限)
  357. if permissionNameStr == `` {
  358. permissionNameStr = `'宏观'`
  359. } else {
  360. permissionNameStr += `, '宏观'`
  361. }
  362. var sqlExport string // 专家权限处理
  363. sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  364. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  365. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  366. }
  367. sqlExport += `) `
  368. if isPower == 1 {
  369. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  370. condition += permissionSqlStr
  371. }
  372. var conditionOr string
  373. //查询全部可见的数据(是否全部客户可见)
  374. if adminIds != "" {
  375. condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) `
  376. }
  377. //活动仅决策人可见
  378. if isMaker == 0 {
  379. condition += ` AND art.is_maker_show = 0 `
  380. }
  381. //condition += ` AND art.visible_range != 1 `
  382. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  383. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  384. }
  385. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  386. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  387. }
  388. if userType == 1 {
  389. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  390. } else {
  391. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  392. }
  393. if userType == 6 || userType == 7 {
  394. conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) `
  395. }
  396. if companyProduct != nil {
  397. if companyProduct.Scale != "" {
  398. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  399. }
  400. }
  401. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  402. if e != nil {
  403. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  404. return
  405. }
  406. // 升级客户可查看范围
  407. if conditionShengji != "" {
  408. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) `
  409. }
  410. // 正式客户可查看范围
  411. if conditionZhengshi != "" {
  412. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) `
  413. }
  414. // 行业客户可查看范围
  415. if conditionHangYe != "" {
  416. conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) `
  417. }
  418. if userType == 3 {
  419. condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) `
  420. }
  421. condition += ` AND art.is_limit_people = 0 `
  422. conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
  423. return
  424. }
  425. // 获取可见的活动
  426. func HandleActivityPowerList(listActivity []*models.CygxActivity, user *models.WxUserItem) (items []*models.CygxActivity, err error) {
  427. return
  428. }
  429. // 5.3版本活动标签字符串处理
  430. func LabelStr(label string, isShowSubjectName int, temporaryLabel string) (labelNew string) {
  431. slicebr := strings.Split(label, "-")
  432. if len(slicebr) > 1 {
  433. if isShowSubjectName == 1 {
  434. labelNew = slicebr[1]
  435. } else {
  436. labelNew = slicebr[0]
  437. }
  438. } else {
  439. labelNew = label
  440. }
  441. if temporaryLabel != "" {
  442. labelNew = temporaryLabel
  443. }
  444. return labelNew
  445. }
  446. // 列表
  447. func HandleActivityTypeHomeList(listType []*models.ActivityTypeHome, listActivity []*models.CygxActivity, user *models.WxUserItem) (items []*models.ActivityTypeHome, err error) {
  448. mapActivity := make(map[int][]*models.CygxActivityLabelList)
  449. activityIds := make([]int, 0) // 用于查询活动【新】标签Map
  450. for _, v := range listActivity {
  451. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  452. if v.ActivityTypeId == 7 {
  453. v.ActivityTypeId = 2
  454. }
  455. if v.ActivityTypeId == 1 {
  456. activityIds = append(activityIds, v.ActivityId)
  457. }
  458. }
  459. // 活动【新】标签Map
  460. newLabelMap, _, e := GetActivityNewLabelMap(activityIds)
  461. if e != nil {
  462. err = errors.New("获取产业新标签Map失败,GetActivityNewLabelMap Err: " + e.Error())
  463. return
  464. }
  465. mapkeyWord := make(map[string]string)
  466. for _, v := range listActivity {
  467. if v.Label == "" {
  468. continue
  469. }
  470. // 如果是C类电话会就不展示内容,且合并到分析师电话会
  471. if v.ActivityTypeId == 7 {
  472. v.ActivityTypeId = 2
  473. }
  474. item := new(models.CygxActivityLabelList)
  475. item.KeyWord = LabelStr(v.Label, v.IsShowSubjectName, v.TemporaryLabel)
  476. if _, ok := mapkeyWord[fmt.Sprint(v.ActivityTypeId, "-", item.KeyWord)]; ok {
  477. continue
  478. }
  479. item.Resource = 1
  480. item.ActivityId = v.ActivityId
  481. if v.IsExternalLabel > 0 {
  482. item.IsExternalLabel = true
  483. }
  484. if v.IsResearchPoints > 0 {
  485. item.IsResearchPoints = true
  486. }
  487. item.City = v.City
  488. if utf8.RuneCountInString(v.City) != 2 {
  489. item.City = ""
  490. }
  491. item.IsNew = newLabelMap[v.ActivityId]
  492. mapActivity[v.ActivityTypeId] = append(mapActivity[v.ActivityTypeId], item)
  493. mapkeyWord[fmt.Sprint(v.ActivityTypeId, "-", item.KeyWord)] = item.KeyWord
  494. }
  495. for _, v := range listType {
  496. v.Resource = 1
  497. if len(mapActivity[v.ActivityTypeId]) > 0 {
  498. v.List = mapActivity[v.ActivityTypeId]
  499. } else {
  500. v.List = make([]*models.CygxActivityLabelList, 0)
  501. }
  502. }
  503. items = listType
  504. return
  505. }
  506. // GetActivityVoiceResp 处理活动音频回放
  507. func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) {
  508. activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId)
  509. if err != nil && err.Error() != utils.ErrNoRow() {
  510. return
  511. }
  512. mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq)
  513. if len(activityVoiceList) > 0 {
  514. for _, v := range activityVoiceList {
  515. mapActivityVoice[v.ActivityId] = v
  516. }
  517. }
  518. mapItem = mapActivityVoice
  519. return
  520. }
  521. // GetActivityVideoResp 处理活动视频频回放
  522. func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) {
  523. var condition string
  524. var ativityVIdstr string
  525. for _, v := range mapActivityId {
  526. ativityVIdstr += strconv.Itoa(v) + ","
  527. }
  528. if ativityVIdstr == "" {
  529. return
  530. }
  531. ativityVIdstr = strings.TrimRight(ativityVIdstr, ",")
  532. condition += ` AND art.activity_id IN (` + ativityVIdstr + `) `
  533. var pars []interface{}
  534. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  535. //condition += ` AND art.activity_time > ? `
  536. //pars = append(pars, endTime)
  537. videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000)
  538. if e != nil && e.Error() != utils.ErrNoRow() {
  539. err = e
  540. return
  541. }
  542. mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp)
  543. if len(videoList) > 0 {
  544. for _, v := range videoList {
  545. mapActivityVideo[v.ActivityId] = v
  546. }
  547. }
  548. mapItem = mapActivityVideo
  549. return
  550. }
  551. func ActivityButtonShow(item *models.ActivityDetail, user *models.WxUserItem, permissionArr []string) (itemActivity *models.ActivityListResp) {
  552. articleDetail := item
  553. //IsShowAppointment bool `description:"是否展示预约纪要"`
  554. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  555. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  556. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  557. //IsShowSignup bool `description:"是否展示我要报名"`
  558. if strings.Contains(articleDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  559. articleDetail.IsResearch = true
  560. }
  561. //如果是 公司调研电话会:3,或 专家线下沙龙:5 而且 除易董同步过来的以外的研选类型活动,必须要有研选的正式权限
  562. if (articleDetail.ActivityTypeId == 3 || articleDetail.ActivityTypeId == 5) && articleDetail.YidongActivityId == "" && strings.Contains(articleDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && utils.InArrayByStr(permissionArr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  563. articleDetail.IsResearchSpecial = true
  564. }
  565. activityTimeText := articleDetail.ActivityTimeText
  566. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  567. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  568. articleDetail.ActivityTimeText = activityTimeText
  569. var yidongActivityUrl string
  570. articleDetail.IsShowAppointment = false
  571. //易董的操作按钮都隐藏
  572. if articleDetail.YidongActivityId != "" {
  573. articleDetail.IsShowSignup = false
  574. articleDetail.IsShowDetails = true
  575. if articleDetail.YidongActivityId != "" {
  576. ydTgc, _ := GetYiDongCreateUserInfo(user)
  577. yidongLongLink, _ := GetYiDongOriginalLink(articleDetail)
  578. if yidongLongLink != "" {
  579. yidongActivityUrl = yidongLongLink + "%26source=11%26fromHz=true%26tgc=" + ydTgc
  580. }
  581. }
  582. } else {
  583. //专家电话会 1
  584. if articleDetail.ActivityTypeId == 1 && articleDetail.IsLimitPeople == 0 && (articleDetail.ActiveState == "1" || articleDetail.ActiveState == "2") {
  585. articleDetail.IsShowHelpSsk = true
  586. }
  587. if articleDetail.ActiveState == "1" {
  588. //新的是否展示规则
  589. if articleDetail.IsCanAppointmentMinutes == 1 {
  590. articleDetail.IsShowAppointment = true
  591. }
  592. //专家电话会 1
  593. if articleDetail.ActivityTypeId == 1 {
  594. if articleDetail.LimitPeopleNum == 0 {
  595. articleDetail.IsShowOutboundCall = true
  596. } else {
  597. articleDetail.IsShowSignup = true
  598. }
  599. articleDetail.IsShowMeetingReminder = true
  600. articleDetail.IsShowHelpSsk = true
  601. }
  602. //分析师电话会 2
  603. if articleDetail.ActivityTypeId == 2 {
  604. if articleDetail.LimitPeopleNum == 0 {
  605. articleDetail.IsShowOutboundCall = true
  606. } else {
  607. articleDetail.IsShowSignup = true
  608. }
  609. articleDetail.IsShowMeetingReminder = true
  610. }
  611. //公司调研电话会 3
  612. if articleDetail.ActivityTypeId == 3 {
  613. if articleDetail.LimitPeopleNum == 0 {
  614. articleDetail.IsShowMeetingReminder = true
  615. articleDetail.IsShowOutboundCall = true
  616. } else {
  617. articleDetail.IsShowSignup = true
  618. }
  619. }
  620. //公司线下调研 4
  621. if articleDetail.ActivityTypeId == 4 {
  622. articleDetail.IsShowSignup = true
  623. }
  624. //专家线下沙龙 5
  625. if articleDetail.ActivityTypeId == 5 {
  626. articleDetail.IsShowSignup = true
  627. }
  628. //分析师线下沙龙 6
  629. if articleDetail.ActivityTypeId == 6 {
  630. articleDetail.IsShowSignup = true
  631. }
  632. //分析师电话会(C类) 7
  633. if articleDetail.ActivityTypeId == 7 {
  634. articleDetail.IsShowSignup = true
  635. articleDetail.IsShowMeetingReminder = true
  636. }
  637. //如果是易董创建的活动,展示我要报名,不展示预约外呼
  638. if articleDetail.IsYidongConduct {
  639. articleDetail.IsShowSignup = true
  640. articleDetail.IsShowOutboundCall = false
  641. }
  642. }
  643. }
  644. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  645. if e != nil {
  646. e = errors.New("获取用户权限失败, Err: " + e.Error())
  647. return
  648. }
  649. v := articleDetail
  650. itemActivity = &models.ActivityListResp{
  651. ActivityId: v.ActivityId,
  652. ActivityTypeId: v.ActivityTypeId,
  653. ActivityTypeName: v.ActivityTypeName,
  654. ChartPermissionId: v.ChartPermissionId,
  655. ChartPermissionName: v.ChartPermissionName,
  656. IsLimitPeople: v.IsLimitPeople,
  657. LimitPeopleNum: v.LimitPeopleNum,
  658. LastUpdatedTime: v.LastUpdatedTime,
  659. ActivityTime: v.ActivityTime,
  660. ActivityTimeText: v.ActivityTimeText,
  661. DistinguishedGuest: v.DistinguishedGuest,
  662. Host: v.Host,
  663. Speaker: v.Speaker,
  664. MainlandTell: v.MainlandTell,
  665. HongKongTell: v.HongKongTell,
  666. TaiwanTell: v.TaiwanTell,
  667. AmericaTell: v.AmericaTell,
  668. ParticipationCode: v.ParticipationCode,
  669. Theme: v.Theme,
  670. Expert: v.Expert,
  671. ActivityName: v.ActivityName,
  672. OnlineParticipation: v.OnlineParticipation,
  673. ReportLink: v.ReportLink,
  674. City: v.City,
  675. Address: v.Address,
  676. Highlights: v.Highlights,
  677. Remarks: v.Remarks,
  678. IsSignup: v.IsSignup,
  679. IsCancelMeetingReminder: v.IsCancelMeetingReminder,
  680. IsAppointment: v.IsAppointment,
  681. ActiveState: v.ActiveState,
  682. IsShowSustainable: v.IsShowSustainable,
  683. Description: v.Description,
  684. IsResearch: v.IsResearch,
  685. IsHideAppointment: v.IsHideAppointment,
  686. IsCClassMeeting: v.IsCClassMeeting,
  687. Label: v.Label,
  688. ImgUrl: v.ImgUrl,
  689. ImgUrlText: v.ImgUrlText,
  690. ActivityType: v.ActivityType,
  691. IsShowOutboundCall: v.IsShowOutboundCall,
  692. IsShowMeetingReminder: v.IsShowMeetingReminder,
  693. IsShowHelpSsk: v.IsShowHelpSsk,
  694. IsShowSignup: v.IsShowSignup,
  695. IsShowAppointment: v.IsShowAppointment,
  696. IsShowDetails: v.IsShowDetails,
  697. AudioLink: v.AudioLink,
  698. VoiceDetail: v.VoiceList,
  699. VideoDetail: v.VideoDetail,
  700. FileType: v.FileType,
  701. SourceType: v.SourceType,
  702. SignupNum: v.SignupNum,
  703. YidongActivityUrl: yidongActivityUrl,
  704. Explain: utils.ACtIVITY_SPECIAL_EXPLAIN,
  705. TripImgLink: v.TripImgLink,
  706. Days: v.Days,
  707. SignupType: v.SignupType,
  708. IsYidongConduct: v.IsYidongConduct,
  709. IsCanOutboundCall: v.IsCanOutboundCall,
  710. TencentConferenceNumber: v.TencentConferenceNumber,
  711. IsResearchSpecial: v.IsResearchSpecial,
  712. }
  713. au := new(models.UserPermissionAuthInfo)
  714. au.SellerName = authInfo.SellerName
  715. au.SellerMobile = authInfo.SellerMobile
  716. au.HasPermission = authInfo.HasPermission
  717. au.OperationMode = authInfo.OperationMode
  718. if au.HasPermission == 1 {
  719. // 非宏观权限进一步判断是否有权限
  720. if v.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, v.ChartPermissionName) {
  721. au.HasPermission = 2
  722. }
  723. }
  724. // 无权限的弹框提示
  725. if au.HasPermission != 1 {
  726. if au.OperationMode == UserPermissionOperationModeCall {
  727. if v.FileType == 1 {
  728. au.PopupMsg = UserPermissionPopupMsgCallMicroVoice
  729. } else {
  730. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  731. }
  732. } else {
  733. if v.FileType == 1 {
  734. au.PopupMsg = UserPermissionPopupMsgApplyMicroVoice
  735. } else {
  736. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  737. }
  738. }
  739. }
  740. itemActivity.AuthInfo = au
  741. //处理用户已经报名了的行程
  742. var activityIds []int
  743. activityIds = append(activityIds, v.ActivityId)
  744. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  745. if e != nil {
  746. e = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  747. return
  748. }
  749. if _, ok := UserMap[v.ActivityId]; ok {
  750. itemActivity.IsTrip = 1
  751. }
  752. if itemActivity.Days == 0 {
  753. itemActivity.TripStatus = 1
  754. //activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  755. } else {
  756. itemActivity.TripStatus = 2
  757. //itemActivity.TripImgLink = itemActivity.TripImgLinkFix
  758. //activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  759. }
  760. return
  761. }
  762. func ActivityDetaailShow(activityInfo *models.ActivityListResp) (itemActivity *models.ActivityListResp, err error) {
  763. itemActivity = activityInfo
  764. if GetShowSustainable() && strings.Contains(itemActivity.ChartPermissionName, "研选") {
  765. itemActivity.IsShowSustainable = true
  766. }
  767. if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
  768. activityInfo.SignupNum = activityInfo.LimitPeopleNum
  769. }
  770. //if activityInfo.ReportLink != "" {
  771. // artList := strings.Split(activityInfo.ReportLink, "{|}")
  772. // if len(artList) > 0 {
  773. // for _, v := range artList {
  774. // artitem := new(models.ActivityArticleResp)
  775. // artitem.ReportLink = v
  776. // artIdSlice := strings.Split(v, "/")
  777. // if len(artIdSlice) > 0 {
  778. // articleId, _ := strconv.Atoi(artIdSlice[len(artIdSlice)-1])
  779. // artitem.ArticleId = articleId
  780. // }
  781. // activityInfo.ArticleList = append(activityInfo.ArticleList, artitem)
  782. // }
  783. // }
  784. //} else {
  785. // activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
  786. //}
  787. if activityInfo.ReportLink != "" {
  788. artList, e := GetActivityReportLinkToArticleList(activityInfo)
  789. if e != nil && e.Error() != utils.ErrNoRow() {
  790. err = e
  791. return
  792. }
  793. if len(artList) == 0 {
  794. activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
  795. } else {
  796. activityInfo.ArticleList = artList
  797. }
  798. } else {
  799. activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0)
  800. }
  801. activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
  802. return
  803. }
  804. // GetActivityNewLabelMap 获取活动【新】标签Map
  805. func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) {
  806. labelMap = make(map[int]bool, 0)
  807. industryNewMap = make(map[int]bool, 0)
  808. if len(activityIds) == 0 {
  809. return
  810. }
  811. // 获取活动关联的产业
  812. var groupCond string
  813. var groupPars []interface{}
  814. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 AND a.active_state != 3 `
  815. groupPars = append(groupPars, activityIds)
  816. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  817. if e != nil {
  818. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  819. return
  820. }
  821. activityIndustryMap := make(map[int][]int, 0)
  822. industryIds := make([]int, 0)
  823. for i := range groups {
  824. industryIds = append(industryIds, groups[i].IndustrialManagementId)
  825. activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId)
  826. }
  827. // 获取新产业Map
  828. industryLabelMap, e := GetIndustryNewLabelMap(industryIds)
  829. if e != nil {
  830. err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  831. return
  832. }
  833. // 判断活动是否为新
  834. for k := range industryLabelMap {
  835. for k2, v2 := range activityIndustryMap {
  836. if labelMap[k2] {
  837. continue
  838. }
  839. // 活动的产业ID中存在一个新产业即为新活动
  840. if utils.InArrayByInt(v2, k) {
  841. labelMap[k2] = true
  842. }
  843. }
  844. }
  845. //for _, v := range activityIds {
  846. // labelMap[v] = true
  847. //}
  848. //fmt.Println(labelMap)
  849. ////产业关联的弘则报告发布日期在三个月以内的活动、产业显示 NEW标签
  850. articNewLabel, e := GetArticNewLabelWhithActivity3Month()
  851. if e != nil {
  852. err = errors.New("获取产业新标签Map失败, Err: " + e.Error())
  853. return
  854. }
  855. for k := range articNewLabel {
  856. labelMap[k] = false
  857. }
  858. return
  859. }
  860. // GetIndustryNewLabelMap 获取产业【新】标签Map
  861. func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
  862. labelMap = make(map[int]bool, 0)
  863. industryIdLen := len(industryIds)
  864. if industryIdLen == 0 {
  865. return
  866. }
  867. // 获取产业关联的报告最早发布时间及最近的发布时间
  868. var timeCond string
  869. var timePars []interface{}
  870. timeCond += ` AND b.publish_status = 1`
  871. if industryIdLen > 0 {
  872. timeCond += ` AND a.industrial_management_id IN (` + utils.GetOrmInReplace(industryIdLen) + `)`
  873. timePars = append(timePars, industryIds)
  874. }
  875. industryTimeList, e := models.GetIndustryArticleMinMaxPublishTime(timeCond, timePars)
  876. if e != nil {
  877. err = errors.New("获取产业文章最大最小发布时间失败, Err: " + e.Error())
  878. return
  879. }
  880. // 判断产业是否为新
  881. nowTime := time.Now().Local()
  882. threeMonthBefore := nowTime.AddDate(0, -3, 0)
  883. nullTime, _ := time.ParseInLocation(utils.FormatDateTime, "0001-01-01 00:00:00", time.Local)
  884. industryMap := make(map[int]*models.IndustryArticleMinMaxPublishTime, 0)
  885. for i := range industryTimeList {
  886. industryMap[industryTimeList[i].IndustrialManagementId] = industryTimeList[i]
  887. }
  888. for i := range industryIds {
  889. iid := industryIds[i]
  890. item := industryMap[iid]
  891. if item != nil {
  892. // 最早发布时间为空 / 最早发布时间在三个月前之后
  893. if item.MinPublishTime.Equal(nullTime) || (item.MinPublishTime.After(threeMonthBefore)) {
  894. labelMap[iid] = true
  895. }
  896. } else {
  897. // 产业无报告, 则为新产业
  898. labelMap[iid] = true
  899. }
  900. }
  901. return
  902. }
  903. // GetSpecialDetailUserPower 处理用户查看详情的权限
  904. func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.ActivityDetail) (havePower, isResearchSpecial bool, err error) {
  905. var companyDetailStatus string
  906. var userTypeStr string
  907. if GetBelongingRai(user.Mobile) || activityInfo.ChartPermissionName == utils.HONG_GUAN_NAME {
  908. havePower = true
  909. return
  910. }
  911. userType, permissionStr, permissionStrZhengShi, e := GetUserTypeZhengShi(user.CompanyId)
  912. if e != nil {
  913. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  914. return
  915. }
  916. //如果是 公司调研电话会:3,或 专家线下沙龙:5 而且 除易董同步过来的以外的研选类型活动,必须要有研选的正式权限
  917. if (activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5) && activityInfo.YidongActivityId == "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  918. isResearchSpecial = true
  919. }
  920. //如果是 公司调研电话会:3,或 专家线下沙龙:5 而且 除易董同步过来的以外的研选类型活动,必须要有研选的正式权限
  921. if isResearchSpecial {
  922. if !strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_YANXUAN) {
  923. //如果连试用权限都没有,那么久按照普通的研选样式展示
  924. isResearchSpecial = false
  925. }
  926. if !strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  927. havePower = false
  928. return
  929. }
  930. }
  931. //处理决策人可见权限
  932. if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 {
  933. havePower = false
  934. return
  935. }
  936. // 处理本组可见权限
  937. if activityInfo.VisibleRange == 1 {
  938. adminIds, e := models.GetSelleridWhichGroup(user.CompanyId, 2)
  939. if e != nil {
  940. err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
  941. return
  942. }
  943. haveVisibleRange := false
  944. adminIdSlice := strings.Split(adminIds, ",")
  945. for _, v := range adminIdSlice {
  946. if v == strconv.Itoa(activityInfo.AdminId) {
  947. haveVisibleRange = true
  948. }
  949. }
  950. if !haveVisibleRange {
  951. havePower = false
  952. return
  953. }
  954. }
  955. if permissionStr == "" {
  956. return
  957. }
  958. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  959. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  960. havePower = true
  961. return
  962. }
  963. //医药消费,科技,智造四大行业,验证主客观。如果主客观校验不通过,那么直接返回
  964. if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) {
  965. if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  966. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  967. havePower = true
  968. } else {
  969. havePower = false
  970. }
  971. } else {
  972. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  973. havePower = true
  974. } else {
  975. havePower = false
  976. }
  977. }
  978. }
  979. //如果主客观校验不通过,那么直接返回
  980. if !havePower {
  981. return
  982. }
  983. if activityInfo.LimitPeopleNum > 0 {
  984. mapUserType, e := GetActivityCcustomerTypeList()
  985. if e != nil {
  986. err = e
  987. return
  988. }
  989. userTypeStr = mapUserType[userType]
  990. // 永续客户、大套餐客户、30W套餐客户可以查看行业升级套餐客户 权限
  991. if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" {
  992. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  993. havePower = true
  994. //return
  995. }
  996. }
  997. } else {
  998. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  999. havePower = true
  1000. return
  1001. }
  1002. }
  1003. //判断管理规模是否满足
  1004. companyProduct, e := models.GetCompanyProductDetail(user.CompanyId, 2)
  1005. if e != nil {
  1006. err = e
  1007. return
  1008. }
  1009. if companyProduct != nil && activityInfo.Scale != "" {
  1010. if strings.Contains(activityInfo.Scale, companyProduct.Scale) {
  1011. havePower = true
  1012. }
  1013. }
  1014. if user.CompanyId <= 1 {
  1015. return
  1016. } else {
  1017. if permissionStr == "" {
  1018. return
  1019. } else {
  1020. companyDetail, e := models.GetCompanyDetailById(user.CompanyId)
  1021. if e != nil {
  1022. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1023. return
  1024. }
  1025. if companyDetail == nil {
  1026. err = errors.New("客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId))
  1027. return
  1028. }
  1029. companyDetailStatus = companyDetail.Status
  1030. }
  1031. }
  1032. if activityInfo.ChartPermissionId == 1 {
  1033. havePower = true
  1034. return
  1035. }
  1036. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == 0 {
  1037. havePower = true
  1038. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  1039. havePower = true
  1040. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  1041. havePower = true
  1042. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  1043. havePower = true
  1044. }
  1045. //if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1046. // havePower = true
  1047. // return
  1048. //}
  1049. if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" {
  1050. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  1051. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  1052. havePower = true
  1053. return
  1054. }
  1055. } else {
  1056. if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  1057. havePower = true
  1058. return
  1059. }
  1060. }
  1061. }
  1062. permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId)
  1063. if errs != nil {
  1064. err = errs
  1065. return
  1066. }
  1067. //if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  1068. // havePower = true
  1069. //}
  1070. //fmt.Println("主客观2", havePower)
  1071. //if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  1072. // havePower = true
  1073. //}
  1074. //fmt.Println("主客观3", havePower)
  1075. //处理升级权限以及用户身份的 双重判断
  1076. if activityInfo.CustomerTypeIds != "" {
  1077. if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" {
  1078. havePower = false
  1079. if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  1080. havePower = true
  1081. }
  1082. }
  1083. }
  1084. if havePower && activityInfo.LimitPeopleNum > 0 {
  1085. //对于一些特殊的活动,即使权限满足也不给产看
  1086. noPower, e := GetShareNoPowe(activityInfo, permissionStr, userType, user)
  1087. if e != nil {
  1088. err = errors.New("GetShareNoPowe, Err: " + e.Error())
  1089. return
  1090. }
  1091. if noPower {
  1092. havePower = false
  1093. }
  1094. }
  1095. return
  1096. }
  1097. // 校验被分享的用户是否有查看详情的权限
  1098. func GetShareNoPowe(activityInfo *models.ActivityDetail, permissionStr string, userType int, user *models.WxUserItem) (noPower bool, err error) {
  1099. //如果是弘则的就不进行可见权限校验
  1100. if user.CompanyId == utils.HZ_COMPANY_ID {
  1101. return
  1102. }
  1103. //var noPower bool
  1104. //if !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
  1105. // noPower = true
  1106. //}
  1107. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  1108. //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)) {
  1109. // noPower = true
  1110. //}
  1111. //if userType == 2 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  1112. // noPower = true
  1113. //}
  1114. //if userType == 3 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  1115. // noPower = true
  1116. //}
  1117. //if userType == 3 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  1118. // noPower = true
  1119. //}
  1120. if userType == 8 {
  1121. permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  1122. if errs != nil {
  1123. err = errs
  1124. return
  1125. }
  1126. if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) {
  1127. noPower = true
  1128. return
  1129. }
  1130. }
  1131. if !noPower {
  1132. noPower, err = CheckUserPowerByActivityChoose(user, activityInfo)
  1133. }
  1134. return
  1135. }
  1136. // 处理活动本组们是否决策人权限
  1137. func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *models.ActivityDetail) (noPower bool, err error) {
  1138. //处理 见范围 1,仅本组可见 、2,全部客户可见
  1139. if activityInfo.VisibleRange == 1 {
  1140. adminIds, errAdmin := models.GetSelleridWhichGroup(user.CompanyId, 2)
  1141. if errAdmin != nil {
  1142. err = errAdmin
  1143. return
  1144. }
  1145. sliceAdminIds := strings.Split(adminIds, ",")
  1146. var haveAdminId bool
  1147. for _, v := range sliceAdminIds {
  1148. if v == strconv.Itoa(activityInfo.AdminId) {
  1149. haveAdminId = true
  1150. }
  1151. }
  1152. if !haveAdminId {
  1153. noPower = true
  1154. }
  1155. }
  1156. //处理 是否仅决策人可见 0,否 、1,是
  1157. if activityInfo.IsMakerShow == 1 {
  1158. if user.IsMaker == 0 {
  1159. noPower = true
  1160. }
  1161. }
  1162. return
  1163. }
  1164. // 判断预约纪要按钮是否显示
  1165. func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
  1166. if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
  1167. isShowAppointment = true
  1168. }
  1169. if activityTypeId == 5 && chartPermissionName == "医药" {
  1170. isShowAppointment = true
  1171. }
  1172. return
  1173. }
  1174. // GetindustryVideoDetailById 通过视频ID获取视频详情
  1175. func GetActivityVideoDetailById(user *models.WxUserItem, videoId int) (industryVideo *models.CygxActivityVideoDetailResp, AuthInfo *models.UserPermissionAuthInfo, err error) {
  1176. total, e := models.GetActivityVideoByVideoIdCount(videoId)
  1177. if e != nil {
  1178. err = errors.New("获取活动的视频失败,GetActivityVideoByVideoIdCount " + e.Error())
  1179. return
  1180. }
  1181. if total == 0 {
  1182. err = errors.New("视频不存在,或已取消发布")
  1183. return
  1184. }
  1185. // 用户权限
  1186. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1187. if e != nil {
  1188. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  1189. return
  1190. }
  1191. videoSimple := new(models.CygxActivityVideoDetailResp)
  1192. // 权限
  1193. var au *models.UserPermissionAuthInfo
  1194. videoSimple, e = models.GetCygxActivityVideoById(videoId)
  1195. if e != nil {
  1196. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  1197. return
  1198. } else {
  1199. //videoSimple.Id = video.Id
  1200. //videoSimple.Title = video.Title
  1201. //videoSimple.ResourceUrl = video.ResourceUrl
  1202. //videoSimple.PlaySeconds = video.PlaySeconds
  1203. //videoSimple.ActivityId = video.ActivityId
  1204. //videoSimple.ChartPermissionId = video.ChartPermissionId
  1205. if videoSimple.BackgroundImg == "" {
  1206. // 获取默认图配置
  1207. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  1208. if e != nil {
  1209. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  1210. return
  1211. }
  1212. videoSimple.BackgroundImg = videoMap[videoSimple.ChartPermissionId]
  1213. }
  1214. au = new(models.UserPermissionAuthInfo)
  1215. au.SellerName = authInfo.SellerName
  1216. au.SellerMobile = authInfo.SellerMobile
  1217. au.HasPermission = authInfo.HasPermission
  1218. au.OperationMode = authInfo.OperationMode
  1219. if au.HasPermission == 1 {
  1220. // 非宏观权限进一步判断是否有权限
  1221. if videoSimple.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, videoSimple.ChartPermissionName) {
  1222. au.HasPermission = 2
  1223. }
  1224. }
  1225. // 无权限的弹框提示
  1226. if au.HasPermission != 1 {
  1227. if au.OperationMode == UserPermissionOperationModeCall {
  1228. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  1229. } else {
  1230. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  1231. }
  1232. videoSimple.ResourceUrl = ""
  1233. }
  1234. }
  1235. industryVideo = videoSimple
  1236. AuthInfo = au
  1237. return
  1238. }
  1239. // 用户活动操作行为,模板消息推送
  1240. func ActivityUserRemind(user *models.WxUserItem, activityDetail *models.ActivityDetail, source int) (err error) {
  1241. defer func() {
  1242. if err != nil {
  1243. go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  1244. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1245. }
  1246. }()
  1247. countUser, err := models.GetUserRemind(user.UserId)
  1248. if err != nil {
  1249. return err
  1250. }
  1251. if countUser == 0 {
  1252. return err
  1253. }
  1254. var sourceMsg string
  1255. if source == 1 {
  1256. sourceMsg = "预约外呼"
  1257. } else if source == 2 {
  1258. sourceMsg = "设置会议提醒"
  1259. } else if source == 3 {
  1260. sourceMsg = "预约纪要"
  1261. } else if source == 4 {
  1262. sourceMsg = "活动报名"
  1263. }
  1264. //获取销售手机号
  1265. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1266. if err != nil && err.Error() != utils.ErrNoRow() {
  1267. return err
  1268. }
  1269. if sellerItemQy != nil {
  1270. openIdList, err := models.GetUserRecordListByMobile(4, sellerItemQy.Mobile)
  1271. if err != nil {
  1272. fmt.Println(err)
  1273. return err
  1274. }
  1275. var keyword1 string
  1276. var keyword2 string
  1277. keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:", sourceMsg)
  1278. keyword2 = activityDetail.ActivityName
  1279. SendWxMsgWithActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId)
  1280. }
  1281. return
  1282. }