acitvity.go 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/PuerkitoBio/goquery"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/company"
  9. "hongze/hz_crm_api/models/cygx"
  10. "hongze/hz_crm_api/models/system"
  11. "hongze/hz_crm_api/services"
  12. "hongze/hz_crm_api/services/alarm_msg"
  13. "hongze/hz_crm_api/utils"
  14. "html"
  15. "regexp"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // 线下活动处理用户爽约限制人数
  21. func AddCygxActivityRestrictSignupByAdmin(activityId int) (err error) {
  22. defer func() {
  23. if err != nil {
  24. fmt.Println("err:", err)
  25. go alarm_msg.SendAlarmMsg("查研观向处理活动用户限制报名失败,Err:"+err.Error(), 3)
  26. }
  27. }()
  28. activityInfo, e := cygx.GetAddActivityInfoById(activityId)
  29. if e != nil {
  30. err = errors.New("GetAddActivityInfoById" + e.Error())
  31. return
  32. }
  33. if activityInfo == nil {
  34. return
  35. }
  36. //不限制报名的不做爽约限制处理
  37. //if activityInfo.IsLimitPeople > 0 {
  38. //total, err := cygx.GetActivitySignupNomeetingCount(activityId)
  39. if err != nil {
  40. return
  41. }
  42. mobileList, _ := cygx.GetUserMeetingMobile(activityId)
  43. var userIdArr []int
  44. if len(mobileList) >= 0 {
  45. for _, v := range mobileList {
  46. userIdArr = append(userIdArr, v.UserId)
  47. }
  48. lenuserIdArr := len(userIdArr)
  49. var condition string
  50. var pars []interface{}
  51. condition = ` AND user_id IN (` + utils.GetOrmInReplace(lenuserIdArr) + `)`
  52. pars = append(pars, userIdArr)
  53. restrictSignupList, e := cygx.GetCygxActivityRestrictSignupList(condition, pars, 0, 9999)
  54. if e != nil {
  55. err = errors.New("GetCygxActivityRestrictSignupList" + e.Error())
  56. return
  57. }
  58. //获取这些用户是否被加入到限制报名了
  59. maptotalRestrict := make(map[int]bool)
  60. for _, v := range restrictSignupList {
  61. maptotalRestrict[v.UserId] = true
  62. }
  63. pars = make([]interface{}, 0)
  64. condition = ` AND a.is_limit_people = 1 AND v.is_meeting = 0 AND v.do_fail_type = 0 AND v.user_id IN (` + utils.GetOrmInReplace(lenuserIdArr) + `)`
  65. pars = append(pars, userIdArr)
  66. listSignup, e := cygx.GetActivitySignupInnerActivityList(condition, pars)
  67. if e != nil && e.Error() != utils.ErrNoRow() {
  68. err = errors.New("GetActivitySignupList" + e.Error())
  69. return
  70. }
  71. mapNomeet := make(map[int]int)
  72. if len(listSignup) > 0 {
  73. for _, v := range listSignup {
  74. mapNomeet[v.UserId]++
  75. }
  76. }
  77. var userIdDelArr []int
  78. for _, v := range mobileList {
  79. //如果加入了爽约限制但是爽约次数少于3条就删除爽约记录
  80. if maptotalRestrict[v.UserId] && mapNomeet[v.UserId] < 3 {
  81. userIdDelArr = append(userIdDelArr, v.UserId)
  82. }
  83. }
  84. if len(userIdDelArr) > 0 {
  85. e = cygx.DeleteCygxActivityRestrictSignupByUserIds(userIdDelArr)
  86. if e != nil {
  87. err = errors.New("DeleteCygxActivityRestrictSignupByUserIds" + e.Error())
  88. return
  89. }
  90. }
  91. }
  92. //if total == 0 {
  93. // return
  94. //}
  95. //}
  96. list, e := cygx.GetActivitySignupNomeetingCountList(activityId)
  97. if e != nil {
  98. err = errors.New("GetActivitySignupNomeetingCountList" + e.Error())
  99. return
  100. }
  101. var userIdSiginArr []int
  102. var items []*cygx.CygxActivitySignupBreak
  103. for _, v := range list {
  104. userIdSiginArr = append(userIdSiginArr, v.UserId)
  105. //添加爽约记录
  106. item := new(cygx.CygxActivitySignupBreak)
  107. item.UserId = v.UserId
  108. item.ActivityId = v.ActivityId
  109. item.CreateTime = time.Now()
  110. item.Mobile = v.Mobile
  111. item.Email = v.Email
  112. item.CompanyId = v.CompanyId
  113. item.CompanyName = v.CompanyName
  114. item.RealName = v.RealName
  115. item.SellerName = v.SellerName
  116. items = append(items, item)
  117. }
  118. if len(list) == 0 {
  119. return
  120. }
  121. var itemsRestrict []*cygx.CygxActivityRestrictSignup
  122. maptotalRestrict := make(map[int]bool)
  123. lenuserIdSiginArr := len(userIdSiginArr)
  124. var condition string
  125. var pars []interface{}
  126. condition = ` AND user_id IN (` + utils.GetOrmInReplace(lenuserIdSiginArr) + `)`
  127. pars = append(pars, userIdSiginArr)
  128. restrictSignupList, e := cygx.GetCygxActivityRestrictSignupList(condition, pars, 0, 9999)
  129. if e != nil {
  130. err = errors.New("GetCygxActivityRestrictSignupList" + e.Error())
  131. return
  132. }
  133. //获取这些用户是否被加入到限制报名了
  134. for _, v := range restrictSignupList {
  135. maptotalRestrict[v.UserId] = true
  136. }
  137. pars = make([]interface{}, 0)
  138. condition = ` AND a.is_limit_people = 1 AND v.is_meeting = 0 AND v.do_fail_type = 0 AND user_id IN (` + utils.GetOrmInReplace(lenuserIdSiginArr) + `)`
  139. pars = append(pars, userIdSiginArr)
  140. listSignup, e := cygx.GetActivitySignupInnerActivityList(condition, pars)
  141. if e != nil && e.Error() != utils.ErrNoRow() {
  142. err = errors.New("GetActivitySignupList" + e.Error())
  143. return
  144. }
  145. mapNomeet := make(map[int]int)
  146. if len(listSignup) > 0 {
  147. for _, v := range listSignup {
  148. mapNomeet[v.UserId]++
  149. }
  150. }
  151. for _, v := range mobileList {
  152. //如果加入了爽约限制但是爽约次数少于3条就删除爽约记录
  153. if !maptotalRestrict[v.UserId] && mapNomeet[v.UserId] >= 3 {
  154. itemRestrict := new(cygx.CygxActivityRestrictSignup)
  155. itemRestrict.UserId = v.UserId
  156. itemRestrict.CreateTime = time.Now()
  157. itemRestrict.Mobile = v.Mobile
  158. itemRestrict.Email = v.Email
  159. itemRestrict.CompanyId = v.CompanyId
  160. itemRestrict.CompanyName = v.CompanyName
  161. itemRestrict.IsRestrict = 1
  162. itemsRestrict = append(itemsRestrict, itemRestrict)
  163. }
  164. }
  165. err = cygx.DeleteCygxActivitySignupBreakById(activityId)
  166. if err != nil {
  167. err = errors.New("DeleteCygxActivitySignupBreakById" + err.Error())
  168. return
  169. }
  170. //添加爽约记录
  171. if len(items) > 0 {
  172. _, e = cygx.AddCygxActivitySignupBreakList(items)
  173. if e != nil {
  174. err = errors.New("AddCygxActivitySignupBreakList, Err: " + e.Error())
  175. return
  176. }
  177. }
  178. //添加报名限制
  179. if len(itemsRestrict) > 0 {
  180. _, e = cygx.AddCygxActivityRestrictSignupList(itemsRestrict)
  181. if e != nil {
  182. err = errors.New("AddCygxActivityRestrictSignupList, Err: " + e.Error())
  183. return
  184. }
  185. }
  186. return
  187. }
  188. func GetReportContentTextSub(content string) (contentSub string, err error) {
  189. content = html.UnescapeString(content)
  190. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  191. docText := doc.Text()
  192. bodyRune := []rune(docText)
  193. bodyRuneLen := len(bodyRune)
  194. if bodyRuneLen > 200 {
  195. bodyRuneLen = 200
  196. }
  197. body := string(bodyRune[:bodyRuneLen])
  198. contentSub = body
  199. return
  200. }
  201. // 富文本字段过滤处理
  202. func GetRichtext(content string) (contentSub string) {
  203. contentSub = strings.Replace(content, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  204. return
  205. }
  206. // 校验该用户是否有报名权限
  207. func CheckaddSignuUserPower(companyId, activityId int, activityInfo *cygx.ActivityDetail) (havePower bool) {
  208. havePower = true
  209. companyPermission, _ := cygx.GetCompanyPermission(companyId)
  210. if companyPermission == "" {
  211. havePower = false
  212. return
  213. }
  214. userType, _, permissionStr, companyStatus, _ := GetUserType(companyId)
  215. permissionStr += ",宏观"
  216. if activityInfo.IsLimitPeople > 0 {
  217. noPower, _ := GetShareNoPowe(activityInfo, permissionStr, userType)
  218. if noPower {
  219. havePower = false
  220. //获取用户的产业规模,判断是否允许可见
  221. companyProduct, _ := company.GetCompanyProductByCompanyIdAndProductId(companyId, 2)
  222. if companyProduct.Scale != "" {
  223. if strings.Count(activityInfo.Scale, companyProduct.Scale) > 0 {
  224. havePower = true
  225. }
  226. }
  227. return
  228. }
  229. }
  230. if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  231. havePower = false
  232. return
  233. }
  234. havePower = GetHavePower(activityInfo, permissionStr, companyStatus)
  235. return
  236. }
  237. // 校验用户报名的权限
  238. func GetHavePower(activityInfo *cygx.ActivityDetail, permissionStr, companyDetailStatus string) (havePower bool) {
  239. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == "0" {
  240. havePower = true
  241. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  242. havePower = true
  243. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  244. havePower = true
  245. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  246. havePower = true
  247. }
  248. if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  249. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  250. havePower = true
  251. }
  252. } else {
  253. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  254. havePower = true
  255. }
  256. }
  257. if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  258. havePower = true
  259. }
  260. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  261. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  262. havePower = true
  263. }
  264. if activityInfo.ChartPermissionName == "宏观" {
  265. havePower = true
  266. }
  267. return
  268. }
  269. // 获取 用户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  270. func GetUserType(companyId int) (userType, packageType int, permissionStrnew, companyStatus string, err error) {
  271. var permissionStr, permissionZhengShiStr string
  272. if companyId <= 1 {
  273. userType = 0
  274. } else {
  275. total, errs := cygx.GetCountCompanyDetailByIdGroup(companyId)
  276. if errs != nil {
  277. err = errs
  278. return
  279. }
  280. if total == 0 {
  281. userType = 0
  282. } else {
  283. companyDetail, errs := cygx.GetCompanyDetailByIdGroup(companyId)
  284. if errs != nil {
  285. err = errs
  286. return
  287. }
  288. companyStatus = companyDetail.Status
  289. permissionStr, errs = cygx.GetCompanyPermission(companyId)
  290. if errs != nil {
  291. err = errs
  292. return
  293. }
  294. permissionStrnew = permissionStr
  295. //大套餐客户,数据库添加标识,
  296. companyUserTypeDetail, errs := cygx.GetCygxCompanyUserType(companyId)
  297. if errs != nil && errs.Error() != utils.ErrNoRow() {
  298. err = errs
  299. return
  300. }
  301. if companyUserTypeDetail != nil {
  302. packageType = companyUserTypeDetail.PackageType
  303. if companyUserTypeDetail.CustomerTypeId != 0 {
  304. userType = companyUserTypeDetail.CustomerTypeId
  305. return
  306. }
  307. }
  308. permissionZhengShiStr, errs = cygx.GetCompanyPermissionByUserZhengShi(companyId)
  309. if errs != nil {
  310. err = errs
  311. return
  312. }
  313. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
  314. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  315. if companyDetail.Status == "永续" {
  316. userType = 1
  317. } else if companyDetail.Status == "试用" {
  318. userType = 5
  319. } else if companyDetail.Status == "冻结" {
  320. userType = 6
  321. } else if companyDetail.Status == "流失" {
  322. userType = 7
  323. }
  324. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  325. if userType == 0 && companyDetail.Status == "正式" {
  326. var permissionZhegnshiNum int
  327. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  328. permissionZhegnshiNum++
  329. }
  330. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  331. permissionZhegnshiNum++
  332. }
  333. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  334. permissionZhegnshiNum++
  335. }
  336. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  337. permissionZhegnshiNum++
  338. }
  339. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  340. permissionZhegnshiNum++
  341. }
  342. if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
  343. permissionZhegnshiNum++
  344. }
  345. //if permissionZhegnshiNum == 6 {
  346. // userType = 2
  347. //} else
  348. //大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
  349. if permissionZhegnshiNum >= 4 {
  350. userType = 10
  351. } else {
  352. userType = 3
  353. }
  354. }
  355. }
  356. }
  357. permissionStrnew = permissionStr
  358. return
  359. }
  360. func GetUserTypeZhengShi(companyId int) (userType int, permissionStrnew, permissionStrZhengShinew, companyStatus string, err error) {
  361. var permissionStr, permissionZhengShiStr string
  362. if companyId <= 1 {
  363. userType = 0
  364. } else {
  365. total, errs := cygx.GetCountCompanyDetailByIdGroup(companyId)
  366. if errs != nil {
  367. err = errs
  368. return
  369. }
  370. if total == 0 {
  371. userType = 0
  372. } else {
  373. companyDetail, errs := cygx.GetCompanyDetailByIdGroup(companyId)
  374. if errs != nil {
  375. err = errs
  376. return
  377. }
  378. companyStatus = companyDetail.Status
  379. permissionStr, errs = cygx.GetCompanyPermission(companyId)
  380. if errs != nil {
  381. err = errs
  382. return
  383. }
  384. permissionStrnew = permissionStr
  385. permissionZhengShiStr, errs = cygx.GetCompanyPermissionByUserZhengShi(companyId)
  386. if errs != nil {
  387. err = errs
  388. return
  389. }
  390. permissionStrZhengShinew = permissionZhengShiStr
  391. //大套餐客户,数据库添加标识,
  392. companyUserTypeDetail, errs := cygx.GetCygxCompanyUserType(companyId)
  393. if errs != nil && errs.Error() != utils.ErrNoRow() {
  394. err = errs
  395. return
  396. }
  397. if companyUserTypeDetail != nil {
  398. if companyUserTypeDetail.CustomerTypeId != 0 {
  399. userType = companyUserTypeDetail.CustomerTypeId
  400. return
  401. }
  402. }
  403. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
  404. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  405. if companyDetail.Status == "永续" {
  406. userType = 1
  407. } else if companyDetail.Status == "试用" {
  408. userType = 5
  409. } else if companyDetail.Status == "冻结" {
  410. userType = 6
  411. } else if companyDetail.Status == "流失" {
  412. userType = 7
  413. }
  414. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  415. if userType == 0 && companyDetail.Status == "正式" {
  416. var permissionZhegnshiNum int
  417. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  418. permissionZhegnshiNum++
  419. }
  420. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  421. permissionZhegnshiNum++
  422. }
  423. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  424. permissionZhegnshiNum++
  425. }
  426. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  427. permissionZhegnshiNum++
  428. }
  429. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  430. permissionZhegnshiNum++
  431. }
  432. if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
  433. permissionZhegnshiNum++
  434. }
  435. //if permissionZhegnshiNum == 6 {
  436. // userType = 2
  437. //} else
  438. //大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
  439. if permissionZhegnshiNum >= 4 {
  440. userType = 10
  441. } else {
  442. userType = 3
  443. }
  444. }
  445. }
  446. }
  447. permissionStrnew = permissionStr
  448. permissionStrZhengShinew = permissionZhengShiStr
  449. return
  450. }
  451. // 校验被分享的用户是否有查看详情的权限
  452. func GetShareNoPowe(activityInfo *cygx.ActivityDetail, permissionStr string, userType int) (noPower bool, err error) {
  453. //var noPower bool
  454. if (userType == 1 || userType == 4 || userType == 5) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
  455. noPower = true
  456. }
  457. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  458. 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)) {
  459. noPower = true
  460. }
  461. if userType == 2 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  462. noPower = true
  463. }
  464. if userType == 3 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  465. noPower = true
  466. }
  467. if userType == 3 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  468. noPower = true
  469. }
  470. return
  471. }
  472. // 校验活动是否可以新增纪要预约
  473. func CheckActivityAddAppointment(activityInfo *cygx.ActivityDetail) (isProhibit bool) {
  474. if (activityInfo.ActivityTypeId == 5 && activityInfo.ChartPermissionName != "医药") || activityInfo.ActivityTypeId == 6 {
  475. isProhibit = true
  476. }
  477. return
  478. }
  479. //// 处理活动取消报名截止时间类型展示
  480. //func ActivityCancelDeadlineType(activityInfo *cygx.ActivityDetail) (cancelDeadlineType int) {
  481. // //CancelDeadlineType int `description:"取消报名截止时间类型,0:不设置,1:24小时之前、2:48小时之前"`
  482. // //如果时间是初始值或者为空,就是默认为0 状态
  483. // if activityInfo.CancelDeadline == "" || activityInfo.CancelDeadline == utils.EmptyDateTimeStr {
  484. // cancelDeadlineType = 0
  485. // return
  486. // }
  487. // activityTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  488. // cancelDeadline := utils.StrTimeToTime(activityInfo.CancelDeadline) //时间字符串格式转时间格式
  489. // hourNum := activityTime.Sub(cancelDeadline).Hours()
  490. // if hourNum == 24 {
  491. // cancelDeadlineType = 1
  492. // }
  493. // if hourNum == 48 {
  494. // cancelDeadlineType = 2
  495. // }
  496. // return
  497. //}
  498. // 解析查研观向的模板内容
  499. func ActivityBodyAnalysis(body string, activeState int, req cygx.ActivityRep) (itemr *cygx.CygxActivity, errstr string) {
  500. item := new(cygx.CygxActivity)
  501. body = strings.Replace(body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  502. //活动地址,活动地点,地点,地址,办会地点,办会地址。对地址字眼进行替换,对上述字段兼容做内容解析
  503. body = strings.Replace(body, "活动地点:", "活动地址:", -1)
  504. if !strings.Contains(body, "活动地点:") && !strings.Contains(body, "办会地点:") {
  505. body = strings.Replace(body, "地点:", "活动地址:", -1)
  506. }
  507. if !strings.Contains(body, "办会地址:") && !strings.Contains(body, "活动地址:") {
  508. body = strings.Replace(body, "地址:", "活动地址:", -1)
  509. }
  510. body = strings.Replace(body, "办会地点:", "活动地址:", -1)
  511. body = strings.Replace(body, "办会地址:", "活动地址:", -1)
  512. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(body))
  513. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  514. contentTxt := s.Text()
  515. contentTxt = strings.Replace(contentTxt, "\n", "", -1)
  516. //contentTxt = strings.Replace(contentTxt, " ", "", -1)
  517. if strings.Contains(contentTxt, "活动名称:") {
  518. item.ActivityName = strings.Replace(contentTxt, "活动名称:", "", -1)
  519. }
  520. if i == 0 {
  521. item.ActivityName = contentTxt
  522. }
  523. if strings.Contains(contentTxt, "时间:") || strings.Contains(contentTxt, "时间:") {
  524. strText := strings.Replace(contentTxt, "时间:", "", -1)
  525. strText = strings.Replace(strText, "时间:", "", -1)
  526. strText = strings.Replace(strText, "p", "", -1)
  527. strText = strings.Replace(strText, "P", "", -1)
  528. strText = strings.Replace(strText, "m", "", -1)
  529. strText = strings.Replace(strText, "M", "", -1)
  530. strText = strings.Replace(strText, "a", "", -1)
  531. strText = strings.Replace(strText, "A", "", -1)
  532. strText = strings.Replace(strText, " ", "", -1)
  533. item.ActivityTimeText = strText
  534. //var hrefRegexp = regexp.MustCompile("[^\\\\x00-\\\\xff]+")
  535. var hrefRegexp = regexp.MustCompile("[/\\d+/]+")
  536. match := hrefRegexp.FindAllString(strText, -1)
  537. if match != nil {
  538. activityTimeText := item.ActivityTimeText
  539. //timeStr := strings.Replace(strText, match[len(match)-1], " ", -1)
  540. //resultTime := utils.StrTimeToTime(timeStr + ":00") //时间字符串格式转时间格式
  541. if len(match) < 5 {
  542. errstr = "活动时间格式错误"
  543. }
  544. var timeStr string
  545. for k, v := range match {
  546. if k < 2 {
  547. timeStr += v + "-"
  548. } else if k == 2 {
  549. timeStr += v + " "
  550. } else if k <= 4 {
  551. timeStr += v + ":"
  552. }
  553. }
  554. timeStr += "00"
  555. resultTime := utils.StrTimeToTime(timeStr) //时间字符串格式转时间格式
  556. timeStrYmd := resultTime.Format(utils.FormatDate)
  557. timeYmd := utils.StrTimeToTime(timeStrYmd + " 11:59:59") //拼接当天中午12点的时间 处理AM、PM标签
  558. var amOrPm string
  559. if resultTime.After(timeYmd) {
  560. amOrPm = " PM"
  561. } else {
  562. amOrPm = " AM"
  563. }
  564. item.ActivityTimeText = activityTimeText + amOrPm
  565. item.ActivityTime = timeStr
  566. res := time.Now().After(resultTime)
  567. if res && activeState == 0 {
  568. errstr = "时间格式错误,请按照模板时间格式填写!"
  569. return
  570. }
  571. //如果报名时间不为空,而且是买方研选活动那么就做校验、
  572. if req.SiginupDeadline != "" && strings.Contains(req.PermissionName, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  573. siginupDeadline := utils.StrTimeToTime(req.SiginupDeadline)
  574. if siginupDeadline.After(resultTime) && activeState == 0 {
  575. errstr = "截止时间需早于活动开始时间!"
  576. return
  577. }
  578. }
  579. //设置取消报名截止时间为会前一小时
  580. item.CancelDeadline = resultTime.Add(-time.Hour * 1).Format(utils.FormatDateTime)
  581. if req.IsResearchPoints == 1 {
  582. if req.PointsSet.CancelDeadlineType == "1" && req.SiginupDeadline != "" {
  583. item.CancelDeadline = req.SiginupDeadline
  584. }
  585. if req.PointsSet.CancelDeadlineType == "2" {
  586. item.CancelDeadline = resultTime.Add(-time.Hour * 24).Format(utils.FormatDateTime)
  587. }
  588. if req.PointsSet.CancelDeadlineType == "3" {
  589. item.CancelDeadline = resultTime.Add(-time.Hour * 48).Format(utils.FormatDateTime)
  590. }
  591. }
  592. }
  593. }
  594. if strings.Contains(contentTxt, "主讲人:") {
  595. item.Speaker = strings.Replace(contentTxt, "主讲人:", "", -1)
  596. }
  597. if strings.Contains(contentTxt, "嘉宾:") {
  598. item.DistinguishedGuest = strings.Replace(contentTxt, "嘉宾:", "", -1)
  599. }
  600. if strings.Contains(contentTxt, "主持人:") {
  601. item.Host = strings.Replace(contentTxt, "主持人:", "", -1)
  602. }
  603. if strings.Contains(contentTxt, "大陆拨入号:") {
  604. item.MainlandTell = strings.Replace(contentTxt, "大陆拨入号:", "", -1)
  605. }
  606. if strings.Contains(contentTxt, "香港拨入号:") {
  607. item.HongKongTell = strings.Replace(contentTxt, "香港拨入号:", "", -1)
  608. }
  609. if strings.Contains(contentTxt, "台湾拨入号:") {
  610. item.TaiwanTell = strings.Replace(contentTxt, "台湾拨入号:", "", -1)
  611. }
  612. if strings.Contains(contentTxt, "美国拨入号:") {
  613. item.AmericaTell = strings.Replace(contentTxt, "美国拨入号:", "", -1)
  614. }
  615. if strings.Contains(contentTxt, "拨入密码:") {
  616. item.ParticipationCode = strings.Replace(contentTxt, "拨入密码:", "", -1)
  617. }
  618. if strings.Contains(contentTxt, "参会人密码:") {
  619. item.ParticipationCode = strings.Replace(contentTxt, "参会人密码:", "", -1)
  620. }
  621. if strings.Contains(contentTxt, "参会密码:") {
  622. item.ParticipationCode = strings.Replace(contentTxt, "参会密码:", "", -1)
  623. }
  624. if strings.Contains(contentTxt, "主题:") {
  625. item.Theme = strings.Replace(contentTxt, "主题:", "", -1)
  626. }
  627. if strings.Contains(contentTxt, "专家:") {
  628. item.Expert = strings.Replace(contentTxt, "专家:", "", -1)
  629. }
  630. if strings.Contains(contentTxt, "网络参会:") {
  631. item.OnlineParticipation = strings.Replace(contentTxt, "网络参会:", "", -1)
  632. }
  633. if strings.Contains(contentTxt, "参会链接:") {
  634. item.OnlineParticipation = strings.Replace(contentTxt, "参会链接:", "", -1)
  635. }
  636. if strings.Contains(contentTxt, "报告链接:") {
  637. item.ReportLink = strings.Replace(contentTxt, "报告链接:", "", -1)
  638. }
  639. if strings.Contains(contentTxt, "城市:") {
  640. item.City = strings.Replace(contentTxt, "城市:", "", -1)
  641. }
  642. if strings.Contains(contentTxt, "活动地址:") {
  643. item.Address = strings.Replace(contentTxt, "活动地址:", "", -1)
  644. }
  645. if strings.Contains(contentTxt, "活动亮点:") {
  646. item.Highlights = strings.Replace(contentTxt, "活动亮点:", "", -1)
  647. }
  648. if strings.Contains(contentTxt, "备注:") {
  649. item.Remarks = strings.Replace(contentTxt, "备注:", "", -1)
  650. }
  651. if strings.Contains(contentTxt, "标签:") {
  652. item.Label = strings.Replace(contentTxt, "标签:", "", -1)
  653. }
  654. if strings.Contains(contentTxt, "链接参会:") {
  655. item.LinkParticipants = strings.Replace(contentTxt, "链接参会:", "", -1)
  656. }
  657. if strings.Contains(contentTxt, "App参会:") {
  658. item.AppAttendance = strings.Replace(contentTxt, "App参会:", "", -1)
  659. }
  660. if strings.Contains(contentTxt, "会议密码:") {
  661. item.ConferencePassword = strings.Replace(contentTxt, "会议密码:", "", -1)
  662. }
  663. if strings.Contains(contentTxt, "腾讯会议号:") {
  664. item.TencentConferenceNumber = strings.Replace(contentTxt, "腾讯会议号:", "", -1)
  665. }
  666. if strings.Contains(contentTxt, "会议ID:") {
  667. item.MeetingId = strings.Replace(contentTxt, "会议ID:", "", -1)
  668. }
  669. })
  670. strnum := strings.Index(body, "活动亮点:")
  671. if strnum > 0 {
  672. bodyHighlights := body[strnum:]
  673. bodyHighlightsNew, _ := ActivityHtmlAnalysis(bodyHighlights, "活动亮点:")
  674. if len(bodyHighlightsNew) > 0 {
  675. item.Highlights = strings.Replace(bodyHighlightsNew, "活动亮点:", "", -1)
  676. } else {
  677. item.Highlights = strings.Replace(bodyHighlights, "活动亮点:", "", -1)
  678. }
  679. }
  680. strnum2 := strings.Index(body, "备注:")
  681. if strnum2 > 0 {
  682. bodyRemarks := body[strnum2:]
  683. bodyRemarksNew, _ := ActivityHtmlAnalysis(bodyRemarks, "备注:")
  684. if len(bodyRemarksNew) > 0 {
  685. item.Remarks = strings.Replace(bodyRemarksNew, "备注:", "", -1)
  686. } else {
  687. item.Remarks = strings.Replace(bodyRemarks, "备注:", "", -1)
  688. }
  689. }
  690. strnum3 := strings.Index(body, "主题:")
  691. if strnum3 > 0 {
  692. bodyTheme := body[strnum3:]
  693. bodyThemeNew, _ := ActivityHtmlAnalysis(bodyTheme, "主题:")
  694. if len(bodyThemeNew) > 0 {
  695. item.Theme = strings.Replace(bodyThemeNew, "主题:", "", -1)
  696. } else {
  697. item.Theme = strings.Replace(bodyTheme, "主题:", "", -1)
  698. }
  699. }
  700. strnum4 := strings.Index(body, "专家:")
  701. if strnum4 > 0 {
  702. bodyExpert := body[strnum4:]
  703. //bodyExpert = strings.Replace(bodyExpert, "专家:", "", -1)
  704. bodyExpertNew, _ := ActivityHtmlAnalysis(bodyExpert, "专家:")
  705. //fmt.Println(bodyExpertNew)
  706. if len(bodyExpertNew) > 0 {
  707. item.Expert = strings.Replace(bodyExpertNew, "专家:", "", -1)
  708. } else {
  709. item.Expert = strings.Replace(bodyExpert, "专家:", "", -1)
  710. }
  711. }
  712. itemr = item
  713. return
  714. }
  715. // 解析查研观向的模板内容
  716. func ActivityHtmlAnalysis(body, srt string) (bodyNew, srts string) {
  717. var strarr = [...]string{"主讲人:", "嘉宾:", "主持人:", "大陆拨入号:", "香港拨入号:", "台湾拨入号:", "美国拨入号:", "拨入密码:", "参会人密码:", "参会密码:", "主题:", "专家:", "网络参会:", "参会链接:", "报告链接:", "城市:", "活动地址:", "活动亮点:", "备注:", "标签:", "链接参会:", "App参会:", "会议密码:", "腾讯会议号:"}
  718. var bodys string
  719. for _, v := range strarr {
  720. if v != srt {
  721. strnum := strings.Index(body, v)
  722. if strnum > 0 {
  723. strnum := strings.Index(body, v)
  724. bodys = body[0:strnum]
  725. bodys = strings.Replace(bodys, srt, "", -1)
  726. var isGoback bool //判断是否递归回调
  727. for _, v2 := range strarr {
  728. if strings.Index(bodys, v2) > 0 {
  729. isGoback = true
  730. }
  731. }
  732. if isGoback {
  733. ActivityHtmlAnalysis(bodys, srt)
  734. } else {
  735. bodyNew = bodys
  736. return
  737. }
  738. }
  739. }
  740. }
  741. bodyNew = bodys
  742. return
  743. }
  744. func ActivityReportLink(item *cygx.CygxActivity, industrialSubjectIdS string) (newReportLink string, err error) {
  745. var categoryIds string
  746. var reportLink string
  747. if item.ReportLink == "" {
  748. //ActivityTypeId = 2是分析师电话会
  749. if item.ActivityTypeId == 2 {
  750. //类型ID 医药(医享会:28 、药调研:301)、消费【渠道新声:32】、科技【科技前言:79】、智造【匠心智造:84】
  751. if item.ChartPermissionName == "医药" {
  752. categoryIds = "28,301"
  753. } else if item.ChartPermissionName == "消费" {
  754. categoryIds = "32"
  755. } else if item.ChartPermissionName == "科技" {
  756. categoryIds = "79"
  757. } else if item.ChartPermissionName == "智造" {
  758. categoryIds = "84"
  759. }
  760. if categoryIds != "" {
  761. articleList, errArt := cygx.GetArticleListByCategoryId(categoryIds, industrialSubjectIdS)
  762. if errArt != nil {
  763. err = errArt
  764. return
  765. }
  766. if len(articleList) > 0 {
  767. for _, v := range articleList {
  768. reportLink += utils.Hz_CeLue_Article_Url + strconv.Itoa(v.ArticleId) + "{|}"
  769. }
  770. }
  771. }
  772. }
  773. }
  774. reportLink = strings.TrimRight(reportLink, "{|}")
  775. fmt.Println(reportLink)
  776. newReportLink = reportLink
  777. return
  778. }
  779. // 判断预约纪要按钮是否显示
  780. func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
  781. if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
  782. isShowAppointment = true
  783. }
  784. if activityTypeId == 5 && chartPermissionName == "医药" {
  785. isShowAppointment = true
  786. }
  787. return
  788. }
  789. // 判断预约纪要按钮是否显示 管理员设置
  790. func IsShowAppointmentByadminSet(IsCanAppointmentMinutes int) (isShowAppointment bool) {
  791. if IsCanAppointmentMinutes == 1 {
  792. isShowAppointment = true
  793. }
  794. return
  795. }
  796. //func init() {
  797. // DoActivityOnenIdWxTemplateMsg(2986)
  798. //}
  799. // 处理活动是否进行模板消息推送
  800. func DoActivityOnenIdWxTemplateMsg(activityId int) (err error) {
  801. var weekday string
  802. weekday = time.Now().Weekday().String()
  803. if weekday == "Sunday" {
  804. //fmt.Println("今天是周日,不推送")
  805. return err
  806. }
  807. var msg string
  808. defer func() {
  809. //fmt.Println()
  810. if err != nil {
  811. fmt.Println("err:", err)
  812. go alarm_msg.SendAlarmMsg("查研观向处理活动是否进行模板消息推送,发送模版消息失败,Err:"+err.Error()+";msg:"+msg+"活动ID"+strconv.Itoa(activityId), 3)
  813. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  814. }
  815. if msg != "" {
  816. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  817. }
  818. }()
  819. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  820. if err != nil {
  821. return
  822. }
  823. industrialList, err := cygx.GetIndustrialActivityGroupManagementList(activityId, 1)
  824. if err != nil && err.Error() != utils.ErrNoRow() {
  825. return
  826. }
  827. if activityInfo.VisibleRange == 1 {
  828. return //只要是仅对本组可见的活动,发布时,模板消息统一不发送, p2_876
  829. }
  830. //10分钟之内的活动二次编辑不重复推送
  831. cacheKey := fmt.Sprint("Source:ADMIN", "_ActivityId:", activityId)
  832. isExist := utils.Rc.IsExist(cacheKey)
  833. if isExist {
  834. return err
  835. }
  836. setNX := utils.Rc.SetNX(cacheKey, activityId, time.Minute*10)
  837. if !setNX {
  838. go alarm_msg.SendAlarmMsg("发送模版消息失败,10分钟之内的活动二次编辑不重复推送,设置Redis Key 过期时间失败:key"+cacheKey, 3)
  839. return err
  840. }
  841. var chartPermissionIds string
  842. var chartPermissionName string
  843. //专家权限可以查看以参加以下活动的类型 1:专家电话会 、3:公司调研电话会、4:公司线下调研、5:专家线下沙龙
  844. chartPermissionName = `'` + activityInfo.ChartPermissionName + `'`
  845. if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5 {
  846. chartPermissionName += `'专家'` + `'` + activityInfo.ChartPermissionName + `'`
  847. }
  848. var activityChartPermissionName string
  849. activityChartPermissionName = activityInfo.ChartPermissionName
  850. //如果是四大行业的则做主客观区分处理
  851. if activityChartPermissionName == utils.YI_YAO_NAME || activityChartPermissionName == utils.XIAO_FEI_NAME || activityChartPermissionName == utils.KE_JI_NAME || activityChartPermissionName == utils.ZHI_ZAO_NAME {
  852. if activityInfo.PermissionType == 1 {
  853. activityChartPermissionName = activityInfo.ChartPermissionName + "(主观)"
  854. } else {
  855. activityChartPermissionName = activityInfo.ChartPermissionName + "(客观)"
  856. }
  857. }
  858. listPermissionByname, err := company.GetPermissionLookItemsSandOByName(`'` + activityChartPermissionName + `'`)
  859. if err != nil {
  860. return
  861. }
  862. var chartPermissionIdArr []int
  863. var chartPermissionStarus []string
  864. for _, v := range listPermissionByname {
  865. chartPermissionIds += strconv.Itoa(v.ChartPermissionId) + ","
  866. chartPermissionIdArr = append(chartPermissionIdArr, v.ChartPermissionId)
  867. }
  868. if strings.Contains(activityInfo.CustomerTypeIds, "1") {
  869. chartPermissionStarus = append(chartPermissionStarus, "永续")
  870. }
  871. if strings.Contains(activityInfo.CustomerTypeIds, "2") || strings.Contains(activityInfo.CustomerTypeIds, "3") || strings.Contains(activityInfo.CustomerTypeIds, "4") || strings.Contains(activityInfo.CustomerTypeIds, "9") {
  872. chartPermissionStarus = append(chartPermissionStarus, "正式")
  873. }
  874. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  875. chartPermissionStarus = append(chartPermissionStarus, "试用")
  876. }
  877. chartPermissionIds = strings.TrimRight(chartPermissionIds, ",")
  878. //var conditionPer string
  879. var parsPer []interface{}
  880. //conditionPer = ` AND p.chart_permission_id IN (` + utils.GetOrmInReplace(len(chartPermissionIdArr)) + `) `
  881. parsPer = append(parsPer, chartPermissionIdArr)
  882. var havePowerCompanyid string
  883. //如果活动限制人数就做可见区分判断
  884. if activityInfo.IsLimitPeople > 0 {
  885. var companyIdsRecord []int
  886. var companyIdsYongxu []int
  887. companyIdsYongxuMap := make(map[int]int)
  888. var companyIdsDaTaoCan []int
  889. companyIdsDaTaoCanMap := make(map[int]int)
  890. //var companyIdsHangYe []int // 行业套餐客户
  891. companyIdsHangYeMap := make(map[int]int) // 行业套餐客户
  892. companyIds30WMap := make(map[int]int) // 30W套餐客户
  893. var companyIdsShiYong []int
  894. companyIdsShiYongMap := make(map[int]int) // 试用客户
  895. companyIdsShengJiMap := make(map[int]int) // 升级客户
  896. companyIdsZhuKeGuanMap := make(map[int]int) // 行业套餐客户区分主客观
  897. //获取关注了查研观向小助手的客户ID
  898. cygxUserRecordCompanyList, e := cygx.GetCygxUserRecordCompany()
  899. if e != nil && e.Error() != utils.ErrNoRow() {
  900. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  901. return
  902. }
  903. for _, v := range cygxUserRecordCompanyList {
  904. companyIdsRecord = append(companyIdsRecord, v.CompanyId)
  905. }
  906. listYongXu, e := company.GetCompanyProductListByStatus("永续", 2)
  907. if e != nil && e.Error() != utils.ErrNoRow() {
  908. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  909. return
  910. }
  911. //永续客户
  912. for _, v := range listYongXu {
  913. companyIdsYongxu = append(companyIdsYongxu, v.CompanyId)
  914. companyIdsYongxuMap[v.CompanyId] = v.CompanyId
  915. }
  916. listShiYong, e := company.GetCompanyProductListByStatus("试用", 2)
  917. if e != nil && e.Error() != utils.ErrNoRow() {
  918. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  919. return
  920. }
  921. //试用客户
  922. for _, v := range listShiYong {
  923. companyIdsShiYong = append(companyIdsShiYong, v.CompanyId)
  924. companyIdsShiYongMap[v.CompanyId] = v.CompanyId
  925. }
  926. //自定义的大套餐客户
  927. listDaTaoCan, e := cygx.GetCygxCompanyUserTypeList()
  928. if e != nil && e.Error() != utils.ErrNoRow() {
  929. err = errors.New("GetCygxCompanyUserTypeList, Err: " + e.Error())
  930. return
  931. }
  932. for _, v := range listDaTaoCan {
  933. companyIdsDaTaoCan = append(companyIdsDaTaoCan, v.CompanyId)
  934. companyIdsDaTaoCanMap[v.CompanyId] = v.CompanyId
  935. }
  936. var conditionPer string
  937. var parsPer []interface{}
  938. companyIdsRecord = append(companyIdsRecord, 0)
  939. conditionPer = ` AND r.company_id IN ( ` + utils.GetOrmInReplace(len(companyIdsRecord)) + `) `
  940. parsPer = append(parsPer, companyIdsRecord)
  941. companyReportPermissionItemList, e := cygx.GetCompanyReportPermissionItem(conditionPer, parsPer)
  942. if e != nil && e.Error() != utils.ErrNoRow() {
  943. err = errors.New("GetCompanyReportPermissionItem, Err: " + e.Error())
  944. return
  945. }
  946. permissionNameNumMap := make(map[string]int)
  947. permissionComapnyNumMap := make(map[int]int)
  948. //过滤这些客户中的30w套餐客户(四大行业+策略,有任意4个以上是正式状态的客户)
  949. for _, v := range companyReportPermissionItemList {
  950. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 {
  951. permissionNameNumMap[fmt.Sprint(v.CompanyId, "_", v.PermissionName)]++
  952. if v.PermissionName == utils.YI_YAO_NAME || v.PermissionName == utils.XIAO_FEI_NAME || v.PermissionName == utils.KE_JI_NAME || v.PermissionName == utils.ZHI_ZAO_NAME || v.PermissionName == utils.CE_LUE_NAME {
  953. if permissionNameNumMap[fmt.Sprint(v.CompanyId, "_", v.PermissionName)] == 2 {
  954. permissionComapnyNumMap[v.CompanyId]++
  955. }
  956. }
  957. if v.PermissionName == utils.CE_LUE_NAME {
  958. permissionComapnyNumMap[v.CompanyId]++
  959. }
  960. }
  961. if v.IsUpgrade == 1 && v.PermissionName == activityInfo.ChartPermissionName {
  962. companyIdsShengJiMap[v.CompanyId] = v.CompanyId
  963. }
  964. if activityInfo.PermissionType == 1 {
  965. activityChartPermissionName = activityInfo.ChartPermissionName + "(主观)"
  966. } else {
  967. activityChartPermissionName = activityInfo.ChartPermissionName + "(客观)"
  968. }
  969. }
  970. for k, v := range permissionComapnyNumMap {
  971. if v >= 4 {
  972. companyIds30WMap[k] = v
  973. }
  974. }
  975. //如果一个客户不满足,永续客户,大套餐客户,30W套餐客户 就把他归为其他行业正式客户
  976. for _, v := range companyReportPermissionItemList {
  977. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 && companyIds30WMap[v.CompanyId] == 0 {
  978. if v.Remark == activityChartPermissionName {
  979. companyIdsZhuKeGuanMap[v.CompanyId] = v.CompanyId
  980. }
  981. }
  982. }
  983. //listHangYe, e := company.GetCompanyProductListByStatus("正式", 2)
  984. //if e != nil && e.Error() != utils.ErrNoRow() {
  985. // err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  986. // return
  987. //}
  988. for _, v := range companyReportPermissionItemList {
  989. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 && companyIds30WMap[v.CompanyId] == 0 {
  990. companyIdsHangYeMap[v.CompanyId] = v.CompanyId
  991. //var companyIdsHangYe []int // 行业套餐客户
  992. //companyIdsHangYeMap := make(map[int]int) // 行业套餐客户
  993. }
  994. }
  995. //处理活动针对可见的用户
  996. var companyIdsPower []int // 获取可见活动的公司ID
  997. //var companyIds []int
  998. //mapComapnyId := make(map[int]int)
  999. //mapCompanyProduct := make(map[int]int)
  1000. //mapComapnyPower := make(map[int]*cygx.CompanyPermissionPower)
  1001. if activityInfo.CustomerTypeIds != "" {
  1002. customerTypeIdMap, err := GetCustomerTypeIds(activityInfo.CustomerTypeIds)
  1003. if err != nil {
  1004. return err
  1005. }
  1006. if _, ok := customerTypeIdMap[1]; ok {
  1007. //永续客户
  1008. for _, v := range listYongXu {
  1009. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1010. }
  1011. }
  1012. if _, ok := customerTypeIdMap[2]; ok {
  1013. //大套餐客户
  1014. for _, v := range listDaTaoCan {
  1015. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1016. }
  1017. }
  1018. if _, ok := customerTypeIdMap[3]; ok {
  1019. //行业套餐客户
  1020. for _, v := range companyIdsHangYeMap {
  1021. companyIdsPower = append(companyIdsPower, v)
  1022. }
  1023. }
  1024. if _, ok := customerTypeIdMap[10]; ok {
  1025. //30万套餐客户
  1026. for k := range companyIds30WMap {
  1027. companyIdsPower = append(companyIdsPower, k)
  1028. }
  1029. }
  1030. if _, ok := customerTypeIdMap[5]; ok {
  1031. //试用客户
  1032. for _, v := range listShiYong {
  1033. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1034. }
  1035. }
  1036. if _, ok := customerTypeIdMap[8]; ok {
  1037. //升级权限的客户
  1038. for k := range companyIdsShengJiMap {
  1039. companyIdsPower = append(companyIdsPower, k)
  1040. }
  1041. for _, v := range listYongXu {
  1042. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1043. }
  1044. }
  1045. if _, ok := customerTypeIdMap[9]; ok {
  1046. //其他行业正式客户
  1047. for k := range companyIdsZhuKeGuanMap {
  1048. companyIdsPower = append(companyIdsPower, k)
  1049. }
  1050. }
  1051. }
  1052. //如果勾选了管理规模可见,则做以下处理
  1053. if activityInfo.Scale != "" {
  1054. listCompmayScale, e := company.GetCompanyProductListByScale(activityInfo.Scale, 2)
  1055. if e != nil && e.Error() != utils.ErrNoRow() {
  1056. err = errors.New("GetCompanyProductListByScale, Err: " + e.Error())
  1057. return
  1058. }
  1059. for _, v := range listCompmayScale {
  1060. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1061. }
  1062. }
  1063. companyIdsPowerMap := make(map[int]int)
  1064. for _, v := range companyIdsPower {
  1065. companyIdsPowerMap[v] = v
  1066. }
  1067. //如果活动设置仅本组可见,那么则对公司ID做限制
  1068. if activityInfo.VisibleRange == 1 {
  1069. adminInfo, err := system.GetSysUserById(activityInfo.AdminId)
  1070. if err != nil {
  1071. return err
  1072. }
  1073. adminList, err := system.GetAdminListByGroupId(adminInfo.GroupId)
  1074. if err != nil {
  1075. return err
  1076. }
  1077. var adminIdGroup string
  1078. for _, v := range adminList {
  1079. adminIdGroup += strconv.Itoa(v.AdminId) + ","
  1080. }
  1081. adminIdGroup = strings.TrimRight(adminIdGroup, ",")
  1082. companyProductList, err := company.GetCompanyProductsBySellerId(adminIdGroup)
  1083. if err != nil && err.Error() != utils.ErrNoRow() {
  1084. return err
  1085. }
  1086. if len(companyProductList) == 0 {
  1087. return err
  1088. }
  1089. for _, v := range companyProductList {
  1090. if companyIdsPowerMap[v.CompanyId] > 0 {
  1091. havePowerCompanyid += strconv.Itoa(v.CompanyId) + ","
  1092. }
  1093. }
  1094. } else {
  1095. for _, v := range companyIdsPowerMap {
  1096. havePowerCompanyid += strconv.Itoa(v) + ","
  1097. }
  1098. }
  1099. havePowerCompanyid = strings.TrimRight(havePowerCompanyid, ",")
  1100. if havePowerCompanyid == "" {
  1101. return err
  1102. }
  1103. }
  1104. //获取拒绝接收推送的的用户的 openid
  1105. mapOpenidRefuset := make(map[int]string)
  1106. openidRefusetList, err := cygx.GetCygxUserRefusetOpenid()
  1107. if err != nil && err.Error() != utils.ErrNoRow() {
  1108. return err
  1109. }
  1110. for _, v := range openidRefusetList {
  1111. mapOpenidRefuset[v.UserId] = v.OpenId
  1112. }
  1113. if len(industrialList) > 0 {
  1114. var industrialIds []int
  1115. for _, v := range industrialList {
  1116. industrialIds = append(industrialIds, v.IndustrialManagementId)
  1117. }
  1118. var conditionFollow string
  1119. var parsFollow []interface{}
  1120. //根据产业关注ID,获取用户不感兴趣的产业信息
  1121. conditionFollow = " AND industrial_management_id IN (" + utils.GetOrmInReplace(len(industrialIds)) + ") AND follow_type = 3 "
  1122. parsFollow = append(parsFollow, industrialIds)
  1123. userFllowListUninterested, e := cygx.GetCygxIndustryFllowList(conditionFollow, parsFollow, 0, 0)
  1124. if e != nil {
  1125. err = errors.New("GetCygxIndustryFllowList, Err: " + e.Error())
  1126. return
  1127. }
  1128. var userFllowNum = make(map[int]int)
  1129. for _, v := range userFllowListUninterested {
  1130. userFllowNum[v.UserId]++
  1131. //如果活动对应的产业数量,跟用户不感兴趣的产业数量一致,就不做推送
  1132. if userFllowNum[v.UserId] == len(industrialList) {
  1133. mapOpenidRefuset[v.UserId] = "_"
  1134. }
  1135. }
  1136. }
  1137. var condition string
  1138. //如果活动选择了仅有决策人可见则做以下处理
  1139. if activityInfo.IsMakerShow == 1 {
  1140. condition += ` AND u.is_maker = 1 `
  1141. }
  1142. //fmt.Println(havePowerCompanyid)
  1143. if activityInfo.IsLimitPeople > 0 && havePowerCompanyid != "" {
  1144. condition += ` AND u.company_id IN (` + havePowerCompanyid + `) `
  1145. }
  1146. //根据活动的主客观,获取选择主客观规则的用户的 openid
  1147. mapUserIdChooseTypeSend := make(map[int]int)
  1148. //获取提交过推送规则的用户的 openid
  1149. mapUserIdChooseSend := make(map[int]int)
  1150. var conditionChoose string
  1151. if activityInfo.ChartPermissionName == utils.YI_YAO_NAME {
  1152. conditionChoose = ` AND all_in_yi_yao = 0 `
  1153. } else if activityInfo.ChartPermissionName == utils.XIAO_FEI_NAME {
  1154. conditionChoose = ` AND all_in_xiao_fei = 0 `
  1155. } else if activityInfo.ChartPermissionName == utils.KE_JI_NAME {
  1156. conditionChoose = ` AND all_in_ke_ji = 0 `
  1157. } else if activityInfo.ChartPermissionName == utils.ZHI_ZAO_NAME {
  1158. conditionChoose = ` AND all_in_zhi_zao = 0 `
  1159. } else if activityInfo.ChartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN || activityInfo.ChartPermissionName == utils.CHART_PERMISSION_NAME_YANXUAN {
  1160. conditionChoose = ` AND all_in_yan_xuan = 0 `
  1161. }
  1162. chooseSendtList, err := cygx.GetCygxXzsChooseSend(conditionChoose)
  1163. if err != nil && err.Error() != utils.ErrNoRow() {
  1164. return err
  1165. }
  1166. for _, v := range chooseSendtList {
  1167. mapUserIdChooseSend[v.UserId] = v.UserId
  1168. //选择主观的客户
  1169. if activityInfo.PermissionType == 1 && v.IsSubjective == 1 {
  1170. mapUserIdChooseTypeSend[v.UserId] = v.UserId
  1171. }
  1172. //选择客观的客户
  1173. if activityInfo.PermissionType == 2 && v.IsObjective == 1 {
  1174. mapUserIdChooseTypeSend[v.UserId] = v.UserId
  1175. }
  1176. }
  1177. //fmt.Println(chooseSendtList)
  1178. //获取关注这个活动对应产业的用户的 openid
  1179. mapOpenidFllow := make(map[int]string)
  1180. openidFllowList, err := cygx.GetCygxActiviyUserFllowOpenid(activityId)
  1181. if err != nil && err.Error() != utils.ErrNoRow() {
  1182. return err
  1183. }
  1184. for _, v := range openidFllowList {
  1185. mapOpenidFllow[v.UserId] = v.OpenId
  1186. }
  1187. //fmt.Println(mapOpenidFllow)
  1188. openidPowerByActivitySetList, openidPowerByActivitySetListYx, err := cygx.GetCygxUserRecordPowerByActivitySet(chartPermissionIds, condition)
  1189. if err != nil && err.Error() != utils.ErrNoRow() {
  1190. return err
  1191. }
  1192. //已经推送过的不做二次推送
  1193. listSendOpendId, err := cygx.GeCygxActivityUserTemplateRecordListByActivityId(activityId, utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD)
  1194. if err != nil && err.Error() != utils.ErrNoRow() {
  1195. return err
  1196. }
  1197. mapSendOpenid := make(map[string]int)
  1198. for _, v := range listSendOpendId {
  1199. mapSendOpenid[v.OpenId] = v.UserId
  1200. }
  1201. var OpenIdList []*models.OpenIdList
  1202. for _, v := range openidPowerByActivitySetList {
  1203. if mapSendOpenid[v.OpenId] > 0 {
  1204. //fmt.Println("已经推过了")
  1205. continue
  1206. }
  1207. item := new(models.OpenIdList)
  1208. item.UserId = v.UserId
  1209. item.OpenId = v.OpenId
  1210. if mapUserIdChooseSend[v.UserId] == 0 {
  1211. //如果小助手没有选择过权限信息,那么做消息推送
  1212. OpenIdList = append(OpenIdList, item)
  1213. } else {
  1214. //如果勾选了权限信息,则要满足 1选择产业,2没有选择不接受任何消息推送,3活动对应的主客观跟自己选择的一致。
  1215. if mapOpenidRefuset[v.UserId] == "" && mapUserIdChooseTypeSend[v.UserId] != 0 {
  1216. OpenIdList = append(OpenIdList, item)
  1217. }
  1218. }
  1219. }
  1220. var openiditems []*cygx.CygxActivityUserTemplateRecord
  1221. var openIdArr []string
  1222. for _, v := range OpenIdList {
  1223. //openIdArr[i] = v.OpenId
  1224. openIdArr = append(openIdArr, v.OpenId)
  1225. openiditem := new(cygx.CygxActivityUserTemplateRecord)
  1226. openiditem.ActivityId = activityId
  1227. openiditem.UserId = v.UserId
  1228. openiditem.OpenId = v.OpenId
  1229. openiditem.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1230. openiditem.CreateTime = time.Now()
  1231. openiditems = append(openiditems, openiditem)
  1232. }
  1233. var OpenIdListYx []*models.OpenIdList
  1234. for _, v := range openidPowerByActivitySetListYx {
  1235. if mapSendOpenid[v.OpenId] > 0 {
  1236. //fmt.Println("已经推过了")
  1237. continue
  1238. }
  1239. item := new(models.OpenIdList)
  1240. item.UserId = v.UserId
  1241. item.OpenId = v.OpenId
  1242. if mapUserIdChooseSend[v.UserId] == 0 {
  1243. //如果小助手没有选择过权限信息,那么做消息推送
  1244. OpenIdListYx = append(OpenIdListYx, item)
  1245. } else {
  1246. //如果勾选了权限信息,则要满足 1选择产业,2没有选择不接受任何消息推送,3活动对应的主客观跟自己选择的一致。
  1247. if mapOpenidRefuset[v.UserId] == "" && mapUserIdChooseTypeSend[v.UserId] != 0 {
  1248. OpenIdListYx = append(OpenIdListYx, item)
  1249. }
  1250. }
  1251. }
  1252. var openIdArrYx []string
  1253. for _, v := range OpenIdListYx {
  1254. //openIdArr[i] = v.OpenId
  1255. openIdArrYx = append(openIdArrYx, v.OpenId)
  1256. openiditem := new(cygx.CygxActivityUserTemplateRecord)
  1257. openiditem.ActivityId = activityId
  1258. openiditem.UserId = v.UserId
  1259. openiditem.OpenId = v.OpenId
  1260. openiditem.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1261. openiditem.CreateTime = time.Now()
  1262. openiditems = append(openiditems, openiditem)
  1263. }
  1264. if len(OpenIdList)+len(OpenIdListYx) == 0 {
  1265. return err
  1266. }
  1267. activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
  1268. if len(openIdArr) > 0 {
  1269. first := "您关注的赛道,有【" + activityInfo.ActivityTypeName + "】活动发布,欢迎参与"
  1270. keyword1 := "新活动:" + activityInfo.ActivityName
  1271. keyword2 := activityInfo.ActivityTimeText + ",【" + activityInfo.Label + "】"
  1272. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  1273. sendInfo := new(services.SendWxTemplate)
  1274. sendInfo.First = first
  1275. sendInfo.Keyword1 = keyword1
  1276. sendInfo.Keyword2 = keyword2
  1277. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  1278. sendInfo.RedirectUrl = redirectUrl
  1279. sendInfo.RedirectTarget = 3
  1280. sendInfo.Resource = strconv.Itoa(activityId)
  1281. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1282. sendInfo.OpenIdArr = openIdArr
  1283. e := services.SendTemplateMsg(sendInfo)
  1284. if e != nil {
  1285. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  1286. return
  1287. }
  1288. }
  1289. if len(OpenIdListYx) > 0 {
  1290. industrialName := ""
  1291. for _, v := range industrialList {
  1292. industrialName += v.IndustryName + ","
  1293. }
  1294. industrialName = strings.TrimRight(industrialName, ",")
  1295. // 发类目模版消息
  1296. if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  1297. actTime, _ := time.Parse(utils.FormatDateTime, activityInfo.ActivityTime)
  1298. first := industrialName
  1299. keyword1 := "发布了新活动"
  1300. keyword2 := utils.TruncateActivityNameString(activityInfo.ActivityName)
  1301. keyword3 := actTime.Format(utils.FormatDateTimeMinute2)
  1302. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  1303. sendInfo := new(services.SendWxCategoryTemplate)
  1304. sendInfo.Keywords = []string{first, keyword1, keyword2, keyword3}
  1305. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  1306. sendInfo.RedirectUrl = redirectUrl
  1307. sendInfo.RedirectTarget = 3
  1308. sendInfo.Resource = strconv.Itoa(activityId)
  1309. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1310. sendInfo.OpenIdArr = openIdArrYx
  1311. e := services.SendCategoryTemplateMsg(sendInfo)
  1312. if e != nil {
  1313. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  1314. return
  1315. }
  1316. }
  1317. }
  1318. //活动发布推送的Openid记录
  1319. if len(openiditems) > 0 {
  1320. e := cygx.AddCygxActivityUserTemplateRecordMulti(openiditems)
  1321. if e != nil {
  1322. err = errors.New("AddCygxActivityUserTemplateRecordMulti, Err: " + e.Error())
  1323. return
  1324. }
  1325. }
  1326. return
  1327. }
  1328. // 获取 用户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  1329. func GetUserTypeByPermission(item *cygx.CompanyPermissionPower) (itemPower *cygx.CompanyPermissionPower) {
  1330. itemPower = item
  1331. var userType int
  1332. var permissionStr string
  1333. var permissionZhengShiStr string
  1334. permissionStr = item.PermissionName
  1335. permissionZhengShiStr = item.PermissionNameZhengShi
  1336. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户 6、冻结客户;7、流失客户
  1337. if item.Status == "永续" {
  1338. userType = 1
  1339. } else if item.Status == "试用" {
  1340. userType = 5
  1341. } else if item.Status == "正式" {
  1342. if permissionStr == "专家" {
  1343. userType = 4
  1344. } else if strings.Contains(permissionZhengShiStr, "医药") && strings.Contains(permissionZhengShiStr, "消费") && strings.Contains(permissionZhengShiStr, "科技") && strings.Contains(permissionZhengShiStr, "智造") {
  1345. userType = 2
  1346. } else {
  1347. userType = 3
  1348. }
  1349. if userType == 3 {
  1350. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  1351. userType = 4
  1352. }
  1353. }
  1354. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  1355. if userType == 3 {
  1356. var permissionZhegnshiNum int
  1357. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  1358. permissionZhegnshiNum++
  1359. }
  1360. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  1361. permissionZhegnshiNum++
  1362. }
  1363. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  1364. permissionZhegnshiNum++
  1365. }
  1366. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  1367. permissionZhegnshiNum++
  1368. }
  1369. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  1370. permissionZhegnshiNum++
  1371. }
  1372. if permissionZhegnshiNum >= 4 {
  1373. userType = 2
  1374. }
  1375. }
  1376. } else if item.Status == "冻结" {
  1377. userType = 6
  1378. } else if item.Status == "流失" {
  1379. userType = 7
  1380. }
  1381. itemPower.UserType = userType
  1382. return
  1383. }
  1384. // GetActChartPermissionList 获取活动行业分类列表
  1385. func GetActChartPermissionList() []*cygx.ChartPermissionRepMore {
  1386. list := []*cygx.ChartPermissionRepMore{
  1387. {PermissionName: "医药"},
  1388. {PermissionName: "消费"},
  1389. {PermissionName: "科技"},
  1390. {PermissionName: "智造"},
  1391. {PermissionName: "策略"},
  1392. {PermissionName: "固收"},
  1393. {PermissionName: "周期"},
  1394. {PermissionName: "宏观"},
  1395. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN},
  1396. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(医药)"},
  1397. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(消费)"},
  1398. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(科技)"},
  1399. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(智造)"},
  1400. }
  1401. return list
  1402. }
  1403. // 同步活动到最新数据表
  1404. func UpdateResourceData(sourceId int, source, doType, publishDate string) (err error) {
  1405. defer func() {
  1406. if err != nil {
  1407. fmt.Println("err:", err)
  1408. go alarm_msg.SendAlarmMsg("同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型"+source+"操作方式"+doType, 3)
  1409. }
  1410. }()
  1411. if doType == "add" {
  1412. item := new(cygx.CygxResourceData)
  1413. item.SourceId = sourceId
  1414. item.Source = source
  1415. item.PublishDate = publishDate
  1416. item.CreateTime = time.Now()
  1417. _, err = cygx.AddCygxResourceData(item)
  1418. } else if doType == "delete" {
  1419. err = cygx.DeleteResourceData(sourceId, source)
  1420. } else if doType == "update" {
  1421. err = cygx.UpdateResourceData(sourceId, source, publishDate)
  1422. }
  1423. return
  1424. }
  1425. // CheckActivityUpdatePower 校验活动后台管理员、销售是否有修改权限
  1426. func CheckActivityUpdatePower(adminId int, activityInfo *cygx.ActivityDetail) (havePower bool, popupMsg string, err error) {
  1427. defer func() {
  1428. if err != nil {
  1429. fmt.Println("err:", err)
  1430. go alarm_msg.SendAlarmMsg("校验活动后台管理员、销售是否有修改权限失败,Err:"+err.Error(), 3)
  1431. }
  1432. }()
  1433. adminInfo, e := system.GetSysUserById(adminId)
  1434. if e != nil {
  1435. err = errors.New("获取管理员身份失败,GetSysUserById" + e.Error())
  1436. return
  1437. }
  1438. //如果这个活动不是自己建的会议,那么就对权益销售跟权益组长做身份限制判断
  1439. if activityInfo.AdminId > 0 && activityInfo.AdminId != adminId && (adminInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || adminInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP) {
  1440. popupMsg = "只有建会销售可修改。"
  1441. return
  1442. }
  1443. havePower = true
  1444. return
  1445. }
  1446. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  1447. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  1448. defer func() {
  1449. if err != nil {
  1450. fmt.Println("err:", err)
  1451. go alarm_msg.SendAlarmMsg("GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置失败,Err:"+err.Error(), 3)
  1452. }
  1453. }()
  1454. audioMap = make(map[int]string, 0)
  1455. videoMap = make(map[int]string, 0)
  1456. audioShareMap = make(map[int]string, 0)
  1457. videoShareMap = make(map[int]string, 0)
  1458. key := utils.MicroRoadshowDefaultImgKey
  1459. conf, e := cygx.GetCygxConfigDetailByCode(key)
  1460. if e != nil {
  1461. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  1462. return
  1463. }
  1464. if conf.ConfigValue == "" {
  1465. err = errors.New("获取微路演默认图配置有误")
  1466. return
  1467. }
  1468. list := new(cygx.MicroRoadShowDefaultImgList)
  1469. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  1470. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  1471. return
  1472. }
  1473. audioList := list.Audio
  1474. for i := range audioList {
  1475. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  1476. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  1477. }
  1478. videoList := list.Video
  1479. for i := range videoList {
  1480. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  1481. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  1482. }
  1483. return
  1484. }
  1485. // 根据活动ID获取活动关联的产业名称
  1486. func GetActivityIndustrialLabelByActivityIds(activityids []int, source int) (respMap map[int][]string) {
  1487. if len(activityids) == 0 {
  1488. return
  1489. }
  1490. var err error
  1491. defer func() {
  1492. if err != nil {
  1493. go alarm_msg.SendAlarmMsg(fmt.Sprint("根据活动ID获取活动关联的产业名称 失败 GetActivityIndustrialLabelByActivityIds activityids: ", activityids, err.Error()), 2)
  1494. }
  1495. }()
  1496. list, e := cygx.GetIndustrialActivityGroupListByactivityIdsArr(activityids, source)
  1497. if e != nil && e.Error() != utils.ErrNoRow() {
  1498. err = errors.New("GetIndustrialActivityGroupListByactivityIdsArr, Err: " + e.Error())
  1499. return
  1500. }
  1501. respMap = make(map[int][]string, 0)
  1502. for _, v := range list {
  1503. respMap[v.ActivityId] = append(respMap[v.ActivityId], v.IndustryName)
  1504. }
  1505. return
  1506. }
  1507. // 根据活动ID获取活动关联的标的名称
  1508. func GetActivitySubjectLabelByActivityIds(activityids []int, source int) (respMap map[int][]string) {
  1509. if len(activityids) == 0 {
  1510. return
  1511. }
  1512. var err error
  1513. defer func() {
  1514. if err != nil {
  1515. fmt.Println(err)
  1516. go alarm_msg.SendAlarmMsg(fmt.Sprint("根据活动ID获取活动关联的标的名称 失败 GetActivitySubjectLabelByActivityIds activityids: ", activityids, err.Error()), 2)
  1517. }
  1518. }()
  1519. list, e := cygx.GetSubjectActivityGroupManagementListByActivityIdsArr(activityids, source)
  1520. if e != nil && e.Error() != utils.ErrNoRow() {
  1521. err = errors.New("GetSubjectActivityGroupManagementListByActivityIdsArr, Err: " + e.Error())
  1522. return
  1523. }
  1524. respMap = make(map[int][]string, 0)
  1525. for _, v := range list {
  1526. respMap[v.ActivityId] = append(respMap[v.ActivityId], v.SubjectName)
  1527. }
  1528. return
  1529. }