activity.go 69 KB

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