acitvity.go 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  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. })
  667. strnum := strings.Index(body, "活动亮点:")
  668. if strnum > 0 {
  669. bodyHighlights := body[strnum:]
  670. bodyHighlightsNew, _ := ActivityHtmlAnalysis(bodyHighlights, "活动亮点:")
  671. if len(bodyHighlightsNew) > 0 {
  672. item.Highlights = strings.Replace(bodyHighlightsNew, "活动亮点:", "", -1)
  673. } else {
  674. item.Highlights = strings.Replace(bodyHighlights, "活动亮点:", "", -1)
  675. }
  676. }
  677. strnum2 := strings.Index(body, "备注:")
  678. if strnum2 > 0 {
  679. bodyRemarks := body[strnum2:]
  680. bodyRemarksNew, _ := ActivityHtmlAnalysis(bodyRemarks, "备注:")
  681. if len(bodyRemarksNew) > 0 {
  682. item.Remarks = strings.Replace(bodyRemarksNew, "备注:", "", -1)
  683. } else {
  684. item.Remarks = strings.Replace(bodyRemarks, "备注:", "", -1)
  685. }
  686. }
  687. strnum3 := strings.Index(body, "主题:")
  688. if strnum3 > 0 {
  689. bodyTheme := body[strnum3:]
  690. bodyThemeNew, _ := ActivityHtmlAnalysis(bodyTheme, "主题:")
  691. if len(bodyThemeNew) > 0 {
  692. item.Theme = strings.Replace(bodyThemeNew, "主题:", "", -1)
  693. } else {
  694. item.Theme = strings.Replace(bodyTheme, "主题:", "", -1)
  695. }
  696. }
  697. strnum4 := strings.Index(body, "专家:")
  698. if strnum4 > 0 {
  699. bodyExpert := body[strnum4:]
  700. //bodyExpert = strings.Replace(bodyExpert, "专家:", "", -1)
  701. bodyExpertNew, _ := ActivityHtmlAnalysis(bodyExpert, "专家:")
  702. //fmt.Println(bodyExpertNew)
  703. if len(bodyExpertNew) > 0 {
  704. item.Expert = strings.Replace(bodyExpertNew, "专家:", "", -1)
  705. } else {
  706. item.Expert = strings.Replace(bodyExpert, "专家:", "", -1)
  707. }
  708. }
  709. itemr = item
  710. return
  711. }
  712. // 解析查研观向的模板内容
  713. func ActivityHtmlAnalysis(body, srt string) (bodyNew, srts string) {
  714. var strarr = [...]string{"主讲人:", "嘉宾:", "主持人:", "大陆拨入号:", "香港拨入号:", "台湾拨入号:", "美国拨入号:", "拨入密码:", "参会人密码:", "参会密码:", "主题:", "专家:", "网络参会:", "参会链接:", "报告链接:", "城市:", "活动地址:", "活动亮点:", "备注:", "标签:", "链接参会:", "App参会:", "会议密码:", "腾讯会议号:"}
  715. var bodys string
  716. for _, v := range strarr {
  717. if v != srt {
  718. strnum := strings.Index(body, v)
  719. if strnum > 0 {
  720. strnum := strings.Index(body, v)
  721. bodys = body[0:strnum]
  722. bodys = strings.Replace(bodys, srt, "", -1)
  723. var isGoback bool //判断是否递归回调
  724. for _, v2 := range strarr {
  725. if strings.Index(bodys, v2) > 0 {
  726. isGoback = true
  727. }
  728. }
  729. if isGoback {
  730. ActivityHtmlAnalysis(bodys, srt)
  731. } else {
  732. bodyNew = bodys
  733. return
  734. }
  735. }
  736. }
  737. }
  738. bodyNew = bodys
  739. return
  740. }
  741. func ActivityReportLink(item *cygx.CygxActivity, industrialSubjectIdS string) (newReportLink string, err error) {
  742. var categoryIds string
  743. var reportLink string
  744. if item.ReportLink == "" {
  745. //ActivityTypeId = 2是分析师电话会
  746. if item.ActivityTypeId == 2 {
  747. //类型ID 医药(医享会:28 、药调研:301)、消费【渠道新声:32】、科技【科技前言:79】、智造【匠心智造:84】
  748. if item.ChartPermissionName == "医药" {
  749. categoryIds = "28,301"
  750. } else if item.ChartPermissionName == "消费" {
  751. categoryIds = "32"
  752. } else if item.ChartPermissionName == "科技" {
  753. categoryIds = "79"
  754. } else if item.ChartPermissionName == "智造" {
  755. categoryIds = "84"
  756. }
  757. if categoryIds != "" {
  758. articleList, errArt := cygx.GetArticleListByCategoryId(categoryIds, industrialSubjectIdS)
  759. if errArt != nil {
  760. err = errArt
  761. return
  762. }
  763. if len(articleList) > 0 {
  764. for _, v := range articleList {
  765. reportLink += utils.Hz_CeLue_Article_Url + strconv.Itoa(v.ArticleId) + "{|}"
  766. }
  767. }
  768. }
  769. }
  770. }
  771. reportLink = strings.TrimRight(reportLink, "{|}")
  772. fmt.Println(reportLink)
  773. newReportLink = reportLink
  774. return
  775. }
  776. // 判断预约纪要按钮是否显示
  777. func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) {
  778. if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 {
  779. isShowAppointment = true
  780. }
  781. if activityTypeId == 5 && chartPermissionName == "医药" {
  782. isShowAppointment = true
  783. }
  784. return
  785. }
  786. // 判断预约纪要按钮是否显示 管理员设置
  787. func IsShowAppointmentByadminSet(IsCanAppointmentMinutes int) (isShowAppointment bool) {
  788. if IsCanAppointmentMinutes == 1 {
  789. isShowAppointment = true
  790. }
  791. return
  792. }
  793. //func init() {
  794. // DoActivityOnenIdWxTemplateMsg(2703)
  795. //}
  796. // 处理活动是否进行模板消息推送
  797. func DoActivityOnenIdWxTemplateMsg(activityId int) (err error) {
  798. var weekday string
  799. weekday = time.Now().Weekday().String()
  800. if weekday == "Sunday" {
  801. //fmt.Println("今天是周日,不推送")
  802. return err
  803. }
  804. var msg string
  805. defer func() {
  806. //fmt.Println()
  807. if err != nil {
  808. fmt.Println("err:", err)
  809. go alarm_msg.SendAlarmMsg("查研观向处理活动是否进行模板消息推送,发送模版消息失败,Err:"+err.Error()+";msg:"+msg+"活动ID"+strconv.Itoa(activityId), 3)
  810. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  811. }
  812. if msg != "" {
  813. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  814. }
  815. }()
  816. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  817. if err != nil {
  818. return
  819. }
  820. industrialList, err := cygx.GetIndustrialActivityGroupManagementList(activityId, 1)
  821. if err != nil && err.Error() != utils.ErrNoRow() {
  822. return
  823. }
  824. if activityInfo.VisibleRange == 1 {
  825. return //只要是仅对本组可见的活动,发布时,模板消息统一不发送, p2_876
  826. }
  827. //10分钟之内的活动二次编辑不重复推送
  828. cacheKey := fmt.Sprint("Source:ADMIN", "_ActivityId:", activityId)
  829. isExist := utils.Rc.IsExist(cacheKey)
  830. if isExist {
  831. return err
  832. }
  833. setNX := utils.Rc.SetNX(cacheKey, activityId, time.Minute*10)
  834. if !setNX {
  835. go alarm_msg.SendAlarmMsg("发送模版消息失败,10分钟之内的活动二次编辑不重复推送,设置Redis Key 过期时间失败:key"+cacheKey, 3)
  836. return err
  837. }
  838. var chartPermissionIds string
  839. var chartPermissionName string
  840. //专家权限可以查看以参加以下活动的类型 1:专家电话会 、3:公司调研电话会、4:公司线下调研、5:专家线下沙龙
  841. chartPermissionName = `'` + activityInfo.ChartPermissionName + `'`
  842. if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5 {
  843. chartPermissionName += `'专家'` + `'` + activityInfo.ChartPermissionName + `'`
  844. }
  845. var activityChartPermissionName string
  846. activityChartPermissionName = activityInfo.ChartPermissionName
  847. //如果是四大行业的则做主客观区分处理
  848. if activityChartPermissionName == utils.YI_YAO_NAME || activityChartPermissionName == utils.XIAO_FEI_NAME || activityChartPermissionName == utils.KE_JI_NAME || activityChartPermissionName == utils.ZHI_ZAO_NAME {
  849. if activityInfo.PermissionType == 1 {
  850. activityChartPermissionName = activityInfo.ChartPermissionName + "(主观)"
  851. } else {
  852. activityChartPermissionName = activityInfo.ChartPermissionName + "(客观)"
  853. }
  854. }
  855. listPermissionByname, err := company.GetPermissionLookItemsSandOByName(`'` + activityChartPermissionName + `'`)
  856. if err != nil {
  857. return
  858. }
  859. var chartPermissionIdArr []int
  860. var chartPermissionStarus []string
  861. for _, v := range listPermissionByname {
  862. chartPermissionIds += strconv.Itoa(v.ChartPermissionId) + ","
  863. chartPermissionIdArr = append(chartPermissionIdArr, v.ChartPermissionId)
  864. }
  865. if strings.Contains(activityInfo.CustomerTypeIds, "1") {
  866. chartPermissionStarus = append(chartPermissionStarus, "永续")
  867. }
  868. if strings.Contains(activityInfo.CustomerTypeIds, "2") || strings.Contains(activityInfo.CustomerTypeIds, "3") || strings.Contains(activityInfo.CustomerTypeIds, "4") || strings.Contains(activityInfo.CustomerTypeIds, "9") {
  869. chartPermissionStarus = append(chartPermissionStarus, "正式")
  870. }
  871. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  872. chartPermissionStarus = append(chartPermissionStarus, "试用")
  873. }
  874. chartPermissionIds = strings.TrimRight(chartPermissionIds, ",")
  875. //var conditionPer string
  876. var parsPer []interface{}
  877. //conditionPer = ` AND p.chart_permission_id IN (` + utils.GetOrmInReplace(len(chartPermissionIdArr)) + `) `
  878. parsPer = append(parsPer, chartPermissionIdArr)
  879. //if len(chartPermissionStarus) > 0 {
  880. // conditionPer += ` AND p.STATUS IN (` + utils.GetOrmInReplace(len(chartPermissionStarus)) + `) `
  881. // parsPer = append(parsPer, chartPermissionStarus)
  882. //}
  883. //先获取有对应权限的所有用户
  884. //openidPowerList, e := cygx.GetCygxUserRecordPowerOpenid(conditionPer, parsPer)
  885. //if e != nil && e.Error() != utils.ErrNoRow() {
  886. // err = errors.New("GetCygxUserRecordPowerOpenid, Err: " + e.Error())
  887. // return
  888. //}
  889. //fmt.Println(len(openidPowerList))
  890. // 获取所有有权的用户的 openid
  891. //openidPowerList, err := cygx.GetCygxUserRecordPower(chartPermissionIds)
  892. //if err != nil {
  893. // return
  894. //}
  895. var havePowerCompanyid string
  896. //如果活动限制人数就做可见区分判断
  897. if activityInfo.IsLimitPeople > 0 {
  898. var companyIdsRecord []int
  899. var companyIdsYongxu []int
  900. companyIdsYongxuMap := make(map[int]int)
  901. var companyIdsDaTaoCan []int
  902. companyIdsDaTaoCanMap := make(map[int]int)
  903. //var companyIdsHangYe []int // 行业套餐客户
  904. companyIdsHangYeMap := make(map[int]int) // 行业套餐客户
  905. companyIds30WMap := make(map[int]int) // 30W套餐客户
  906. var companyIdsShiYong []int
  907. companyIdsShiYongMap := make(map[int]int) // 试用客户
  908. companyIdsShengJiMap := make(map[int]int) // 升级客户
  909. companyIdsZhuKeGuanMap := make(map[int]int) // 行业套餐客户区分主客观
  910. //获取关注了查研观向小助手的客户ID
  911. cygxUserRecordCompanyList, e := cygx.GetCygxUserRecordCompany()
  912. if e != nil && e.Error() != utils.ErrNoRow() {
  913. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  914. return
  915. }
  916. for _, v := range cygxUserRecordCompanyList {
  917. companyIdsRecord = append(companyIdsRecord, v.CompanyId)
  918. }
  919. listYongXu, e := company.GetCompanyProductListByStatus("永续", 2)
  920. if e != nil && e.Error() != utils.ErrNoRow() {
  921. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  922. return
  923. }
  924. //永续客户
  925. for _, v := range listYongXu {
  926. companyIdsYongxu = append(companyIdsYongxu, v.CompanyId)
  927. companyIdsYongxuMap[v.CompanyId] = v.CompanyId
  928. }
  929. listShiYong, e := company.GetCompanyProductListByStatus("试用", 2)
  930. if e != nil && e.Error() != utils.ErrNoRow() {
  931. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  932. return
  933. }
  934. //试用客户
  935. for _, v := range listShiYong {
  936. companyIdsShiYong = append(companyIdsShiYong, v.CompanyId)
  937. companyIdsShiYongMap[v.CompanyId] = v.CompanyId
  938. }
  939. //自定义的大套餐客户
  940. listDaTaoCan, e := cygx.GetCygxCompanyUserTypeList()
  941. if e != nil && e.Error() != utils.ErrNoRow() {
  942. err = errors.New("GetCygxCompanyUserTypeList, Err: " + e.Error())
  943. return
  944. }
  945. for _, v := range listDaTaoCan {
  946. companyIdsDaTaoCan = append(companyIdsDaTaoCan, v.CompanyId)
  947. companyIdsDaTaoCanMap[v.CompanyId] = v.CompanyId
  948. }
  949. var conditionPer string
  950. var parsPer []interface{}
  951. companyIdsRecord = append(companyIdsRecord, 0)
  952. conditionPer = ` AND r.company_id IN ( ` + utils.GetOrmInReplace(len(companyIdsRecord)) + `) `
  953. parsPer = append(parsPer, companyIdsRecord)
  954. companyReportPermissionItemList, e := cygx.GetCompanyReportPermissionItem(conditionPer, parsPer)
  955. if e != nil && e.Error() != utils.ErrNoRow() {
  956. err = errors.New("GetCompanyReportPermissionItem, Err: " + e.Error())
  957. return
  958. }
  959. permissionNameNumMap := make(map[string]int)
  960. permissionComapnyNumMap := make(map[int]int)
  961. //过滤这些客户中的30w套餐客户(四大行业+策略,有任意4个以上是正式状态的客户)
  962. for _, v := range companyReportPermissionItemList {
  963. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 {
  964. permissionNameNumMap[fmt.Sprint(v.CompanyId, "_", v.PermissionName)]++
  965. 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 {
  966. if permissionNameNumMap[fmt.Sprint(v.CompanyId, "_", v.PermissionName)] == 2 {
  967. permissionComapnyNumMap[v.CompanyId]++
  968. }
  969. }
  970. if v.PermissionName == utils.CE_LUE_NAME {
  971. permissionComapnyNumMap[v.CompanyId]++
  972. }
  973. }
  974. if v.IsUpgrade == 1 && v.PermissionName == activityInfo.ChartPermissionName {
  975. companyIdsShengJiMap[v.CompanyId] = v.CompanyId
  976. }
  977. if activityInfo.PermissionType == 1 {
  978. activityChartPermissionName = activityInfo.ChartPermissionName + "(主观)"
  979. } else {
  980. activityChartPermissionName = activityInfo.ChartPermissionName + "(客观)"
  981. }
  982. }
  983. for k, v := range permissionComapnyNumMap {
  984. if v >= 4 {
  985. companyIds30WMap[k] = v
  986. }
  987. }
  988. //如果一个客户不满足,永续客户,大套餐客户,30W套餐客户 就把他归为其他行业正式客户
  989. for _, v := range companyReportPermissionItemList {
  990. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 && companyIds30WMap[v.CompanyId] == 0 {
  991. if v.Remark == activityChartPermissionName {
  992. companyIdsZhuKeGuanMap[v.CompanyId] = v.CompanyId
  993. }
  994. }
  995. }
  996. //listHangYe, e := company.GetCompanyProductListByStatus("正式", 2)
  997. //if e != nil && e.Error() != utils.ErrNoRow() {
  998. // err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  999. // return
  1000. //}
  1001. for _, v := range companyReportPermissionItemList {
  1002. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 && companyIds30WMap[v.CompanyId] == 0 {
  1003. companyIdsHangYeMap[v.CompanyId] = v.CompanyId
  1004. //var companyIdsHangYe []int // 行业套餐客户
  1005. //companyIdsHangYeMap := make(map[int]int) // 行业套餐客户
  1006. }
  1007. }
  1008. //处理活动针对可见的用户
  1009. var companyIdsPower []int // 获取可见活动的公司ID
  1010. //var companyIds []int
  1011. //mapComapnyId := make(map[int]int)
  1012. //mapCompanyProduct := make(map[int]int)
  1013. //mapComapnyPower := make(map[int]*cygx.CompanyPermissionPower)
  1014. if activityInfo.CustomerTypeIds != "" {
  1015. customerTypeIdMap, err := GetCustomerTypeIds(activityInfo.CustomerTypeIds)
  1016. if err != nil {
  1017. return err
  1018. }
  1019. if _, ok := customerTypeIdMap[1]; ok {
  1020. //永续客户
  1021. for _, v := range listYongXu {
  1022. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1023. }
  1024. }
  1025. if _, ok := customerTypeIdMap[2]; ok {
  1026. //大套餐客户
  1027. for _, v := range listDaTaoCan {
  1028. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1029. }
  1030. }
  1031. if _, ok := customerTypeIdMap[3]; ok {
  1032. //行业套餐客户
  1033. for _, v := range companyIdsHangYeMap {
  1034. companyIdsPower = append(companyIdsPower, v)
  1035. }
  1036. }
  1037. if _, ok := customerTypeIdMap[10]; ok {
  1038. //30万套餐客户
  1039. for k := range companyIds30WMap {
  1040. companyIdsPower = append(companyIdsPower, k)
  1041. }
  1042. }
  1043. if _, ok := customerTypeIdMap[5]; ok {
  1044. //试用客户
  1045. for _, v := range listShiYong {
  1046. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1047. }
  1048. }
  1049. if _, ok := customerTypeIdMap[8]; ok {
  1050. //升级权限的客户
  1051. for k := range companyIdsShengJiMap {
  1052. companyIdsPower = append(companyIdsPower, k)
  1053. }
  1054. for _, v := range listYongXu {
  1055. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1056. }
  1057. }
  1058. if _, ok := customerTypeIdMap[9]; ok {
  1059. //其他行业正式客户
  1060. for k := range companyIdsZhuKeGuanMap {
  1061. companyIdsPower = append(companyIdsPower, k)
  1062. }
  1063. }
  1064. }
  1065. //如果勾选了管理规模可见,则做以下处理
  1066. if activityInfo.Scale != "" {
  1067. listCompmayScale, e := company.GetCompanyProductListByScale(activityInfo.Scale, 2)
  1068. if e != nil && e.Error() != utils.ErrNoRow() {
  1069. err = errors.New("GetCompanyProductListByScale, Err: " + e.Error())
  1070. return
  1071. }
  1072. for _, v := range listCompmayScale {
  1073. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1074. }
  1075. }
  1076. companyIdsPowerMap := make(map[int]int)
  1077. for _, v := range companyIdsPower {
  1078. companyIdsPowerMap[v] = v
  1079. }
  1080. //如果活动设置仅本组可见,那么则对公司ID做限制
  1081. if activityInfo.VisibleRange == 1 {
  1082. adminInfo, err := system.GetSysUserById(activityInfo.AdminId)
  1083. if err != nil {
  1084. return err
  1085. }
  1086. adminList, err := system.GetAdminListByGroupId(adminInfo.GroupId)
  1087. if err != nil {
  1088. return err
  1089. }
  1090. var adminIdGroup string
  1091. for _, v := range adminList {
  1092. adminIdGroup += strconv.Itoa(v.AdminId) + ","
  1093. }
  1094. adminIdGroup = strings.TrimRight(adminIdGroup, ",")
  1095. companyProductList, err := company.GetCompanyProductsBySellerId(adminIdGroup)
  1096. if err != nil && err.Error() != utils.ErrNoRow() {
  1097. return err
  1098. }
  1099. if len(companyProductList) == 0 {
  1100. return err
  1101. }
  1102. for _, v := range companyProductList {
  1103. if companyIdsPowerMap[v.CompanyId] > 0 {
  1104. havePowerCompanyid += strconv.Itoa(v.CompanyId) + ","
  1105. }
  1106. }
  1107. } else {
  1108. for _, v := range companyIdsPowerMap {
  1109. havePowerCompanyid += strconv.Itoa(v) + ","
  1110. }
  1111. }
  1112. havePowerCompanyid = strings.TrimRight(havePowerCompanyid, ",")
  1113. if havePowerCompanyid == "" {
  1114. return err
  1115. }
  1116. }
  1117. //获取拒绝接收推送的的用户的 openid
  1118. mapOpenidRefuset := make(map[int]string)
  1119. openidRefusetList, err := cygx.GetCygxUserRefusetOpenid()
  1120. if err != nil && err.Error() != utils.ErrNoRow() {
  1121. return err
  1122. }
  1123. for _, v := range openidRefusetList {
  1124. mapOpenidRefuset[v.UserId] = v.OpenId
  1125. }
  1126. var condition string
  1127. //如果活动选择了仅有决策人可见则做以下处理
  1128. if activityInfo.IsMakerShow == 1 {
  1129. condition += ` AND u.is_maker = 1 `
  1130. }
  1131. //fmt.Println(havePowerCompanyid)
  1132. if activityInfo.IsLimitPeople > 0 && havePowerCompanyid != "" {
  1133. condition += ` AND u.company_id IN (` + havePowerCompanyid + `) `
  1134. }
  1135. //根据活动的主客观,获取选择主客观规则的用户的 openid
  1136. mapUserIdChooseTypeSend := make(map[int]int)
  1137. //获取提交过推送规则的用户的 openid
  1138. mapUserIdChooseSend := make(map[int]int)
  1139. var conditionChoose string
  1140. if activityInfo.ChartPermissionName == utils.YI_YAO_NAME {
  1141. conditionChoose = ` AND all_in_yi_yao = 0 `
  1142. } else if activityInfo.ChartPermissionName == utils.XIAO_FEI_NAME {
  1143. conditionChoose = ` AND all_in_xiao_fei = 0 `
  1144. } else if activityInfo.ChartPermissionName == utils.KE_JI_NAME {
  1145. conditionChoose = ` AND all_in_ke_ji = 0 `
  1146. } else if activityInfo.ChartPermissionName == utils.ZHI_ZAO_NAME {
  1147. conditionChoose = ` AND all_in_zhi_zao = 0 `
  1148. } else if activityInfo.ChartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN || activityInfo.ChartPermissionName == utils.CHART_PERMISSION_NAME_YANXUAN {
  1149. conditionChoose = ` AND all_in_yan_xuan = 0 `
  1150. }
  1151. chooseSendtList, err := cygx.GetCygxXzsChooseSend(conditionChoose)
  1152. if err != nil && err.Error() != utils.ErrNoRow() {
  1153. return err
  1154. }
  1155. for _, v := range chooseSendtList {
  1156. mapUserIdChooseSend[v.UserId] = v.UserId
  1157. //选择主观的客户
  1158. if activityInfo.PermissionType == 1 && v.IsSubjective == 1 {
  1159. mapUserIdChooseTypeSend[v.UserId] = v.UserId
  1160. }
  1161. //选择客观的客户
  1162. if activityInfo.PermissionType == 2 && v.IsObjective == 1 {
  1163. mapUserIdChooseTypeSend[v.UserId] = v.UserId
  1164. }
  1165. }
  1166. //fmt.Println(chooseSendtList)
  1167. //获取关注这个活动对应产业的用户的 openid
  1168. mapOpenidFllow := make(map[int]string)
  1169. openidFllowList, err := cygx.GetCygxActiviyUserFllowOpenid(activityId)
  1170. if err != nil && err.Error() != utils.ErrNoRow() {
  1171. return err
  1172. }
  1173. for _, v := range openidFllowList {
  1174. mapOpenidFllow[v.UserId] = v.OpenId
  1175. }
  1176. //fmt.Println(mapOpenidFllow)
  1177. openidPowerByActivitySetList, openidPowerByActivitySetListYx, err := cygx.GetCygxUserRecordPowerByActivitySet(chartPermissionIds, condition)
  1178. if err != nil && err.Error() != utils.ErrNoRow() {
  1179. return err
  1180. }
  1181. //已经推送过的不做二次推送
  1182. listSendOpendId, err := cygx.GeCygxActivityUserTemplateRecordListByActivityId(activityId, utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD)
  1183. if err != nil && err.Error() != utils.ErrNoRow() {
  1184. return err
  1185. }
  1186. mapSendOpenid := make(map[string]int)
  1187. for _, v := range listSendOpendId {
  1188. mapSendOpenid[v.OpenId] = v.UserId
  1189. }
  1190. var OpenIdList []*models.OpenIdList
  1191. for _, v := range openidPowerByActivitySetList {
  1192. if mapSendOpenid[v.OpenId] > 0 {
  1193. //fmt.Println("已经推过了")
  1194. continue
  1195. }
  1196. item := new(models.OpenIdList)
  1197. item.UserId = v.UserId
  1198. item.OpenId = v.OpenId
  1199. if mapUserIdChooseSend[v.UserId] == 0 {
  1200. //如果小助手没有选择过权限信息,那么做消息推送
  1201. OpenIdList = append(OpenIdList, item)
  1202. } else {
  1203. //如果勾选了权限信息,则要满足 1选择产业,2没有选择不接受任何消息推送,3活动对应的主客观跟自己选择的一致。
  1204. if mapOpenidFllow[v.UserId] != "" && mapOpenidRefuset[v.UserId] == "" && mapUserIdChooseTypeSend[v.UserId] != 0 {
  1205. OpenIdList = append(OpenIdList, item)
  1206. }
  1207. }
  1208. }
  1209. var openiditems []*cygx.CygxActivityUserTemplateRecord
  1210. var openIdArr []string
  1211. for _, v := range OpenIdList {
  1212. //openIdArr[i] = v.OpenId
  1213. openIdArr = append(openIdArr, v.OpenId)
  1214. openiditem := new(cygx.CygxActivityUserTemplateRecord)
  1215. openiditem.ActivityId = activityId
  1216. openiditem.UserId = v.UserId
  1217. openiditem.OpenId = v.OpenId
  1218. openiditem.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1219. openiditem.CreateTime = time.Now()
  1220. openiditems = append(openiditems, openiditem)
  1221. }
  1222. var OpenIdListYx []*models.OpenIdList
  1223. for _, v := range openidPowerByActivitySetListYx {
  1224. if mapSendOpenid[v.OpenId] > 0 {
  1225. //fmt.Println("已经推过了")
  1226. continue
  1227. }
  1228. item := new(models.OpenIdList)
  1229. item.UserId = v.UserId
  1230. item.OpenId = v.OpenId
  1231. if mapUserIdChooseSend[v.UserId] == 0 {
  1232. //如果小助手没有选择过权限信息,那么做消息推送
  1233. OpenIdListYx = append(OpenIdListYx, item)
  1234. } else {
  1235. //如果勾选了权限信息,则要满足 1选择产业,2没有选择不接受任何消息推送,3活动对应的主客观跟自己选择的一致。
  1236. if mapOpenidFllow[v.UserId] != "" && mapOpenidRefuset[v.UserId] == "" && mapUserIdChooseTypeSend[v.UserId] != 0 {
  1237. OpenIdListYx = append(OpenIdListYx, item)
  1238. }
  1239. }
  1240. }
  1241. var openIdArrYx []string
  1242. for _, v := range OpenIdListYx {
  1243. //openIdArr[i] = v.OpenId
  1244. openIdArrYx = append(openIdArrYx, v.OpenId)
  1245. openiditem := new(cygx.CygxActivityUserTemplateRecord)
  1246. openiditem.ActivityId = activityId
  1247. openiditem.UserId = v.UserId
  1248. openiditem.OpenId = v.OpenId
  1249. openiditem.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1250. openiditem.CreateTime = time.Now()
  1251. openiditems = append(openiditems, openiditem)
  1252. }
  1253. if len(OpenIdList)+len(OpenIdListYx) == 0 {
  1254. return err
  1255. }
  1256. activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
  1257. if len(openIdArr) > 0 {
  1258. first := "您关注的赛道,有【" + activityInfo.ActivityTypeName + "】活动发布,欢迎参与"
  1259. keyword1 := "新活动:" + activityInfo.ActivityName
  1260. keyword2 := activityInfo.ActivityTimeText + ",【" + activityInfo.Label + "】"
  1261. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  1262. sendInfo := new(services.SendWxTemplate)
  1263. sendInfo.First = first
  1264. sendInfo.Keyword1 = keyword1
  1265. sendInfo.Keyword2 = keyword2
  1266. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  1267. sendInfo.RedirectUrl = redirectUrl
  1268. sendInfo.RedirectTarget = 3
  1269. sendInfo.Resource = strconv.Itoa(activityId)
  1270. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1271. sendInfo.OpenIdArr = openIdArr
  1272. e := services.SendTemplateMsg(sendInfo)
  1273. if e != nil {
  1274. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  1275. return
  1276. }
  1277. }
  1278. if len(OpenIdListYx) > 0 {
  1279. industrialName := ""
  1280. for _, v := range industrialList {
  1281. industrialName += v.IndustryName + ","
  1282. }
  1283. industrialName = strings.TrimRight(industrialName, ",")
  1284. // 发类目模版消息
  1285. if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  1286. actTime, _ := time.Parse(utils.FormatDateTime, activityInfo.ActivityTime)
  1287. first := industrialName
  1288. keyword1 := "发布了新活动"
  1289. keyword2 := utils.TruncateActivityNameString(activityInfo.ActivityName)
  1290. keyword3 := actTime.Format(utils.FormatDateTimeMinute2)
  1291. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  1292. sendInfo := new(services.SendWxCategoryTemplate)
  1293. sendInfo.Keywords = []string{first, keyword1, keyword2, keyword3}
  1294. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  1295. sendInfo.RedirectUrl = redirectUrl
  1296. sendInfo.RedirectTarget = 3
  1297. sendInfo.Resource = strconv.Itoa(activityId)
  1298. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1299. sendInfo.OpenIdArr = openIdArrYx
  1300. e := services.SendCategoryTemplateMsg(sendInfo)
  1301. if e != nil {
  1302. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  1303. return
  1304. }
  1305. }
  1306. }
  1307. //活动发布推送的Openid记录
  1308. if len(openiditems) > 0 {
  1309. e := cygx.AddCygxActivityUserTemplateRecordMulti(openiditems)
  1310. if e != nil {
  1311. err = errors.New("AddCygxActivityUserTemplateRecordMulti, Err: " + e.Error())
  1312. return
  1313. }
  1314. }
  1315. return
  1316. }
  1317. // 获取 用户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  1318. func GetUserTypeByPermission(item *cygx.CompanyPermissionPower) (itemPower *cygx.CompanyPermissionPower) {
  1319. itemPower = item
  1320. var userType int
  1321. var permissionStr string
  1322. var permissionZhengShiStr string
  1323. permissionStr = item.PermissionName
  1324. permissionZhengShiStr = item.PermissionNameZhengShi
  1325. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户 6、冻结客户;7、流失客户
  1326. if item.Status == "永续" {
  1327. userType = 1
  1328. } else if item.Status == "试用" {
  1329. userType = 5
  1330. } else if item.Status == "正式" {
  1331. if permissionStr == "专家" {
  1332. userType = 4
  1333. } else if strings.Contains(permissionZhengShiStr, "医药") && strings.Contains(permissionZhengShiStr, "消费") && strings.Contains(permissionZhengShiStr, "科技") && strings.Contains(permissionZhengShiStr, "智造") {
  1334. userType = 2
  1335. } else {
  1336. userType = 3
  1337. }
  1338. if userType == 3 {
  1339. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  1340. userType = 4
  1341. }
  1342. }
  1343. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  1344. if userType == 3 {
  1345. var permissionZhegnshiNum int
  1346. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  1347. permissionZhegnshiNum++
  1348. }
  1349. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  1350. permissionZhegnshiNum++
  1351. }
  1352. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  1353. permissionZhegnshiNum++
  1354. }
  1355. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  1356. permissionZhegnshiNum++
  1357. }
  1358. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  1359. permissionZhegnshiNum++
  1360. }
  1361. if permissionZhegnshiNum >= 4 {
  1362. userType = 2
  1363. }
  1364. }
  1365. } else if item.Status == "冻结" {
  1366. userType = 6
  1367. } else if item.Status == "流失" {
  1368. userType = 7
  1369. }
  1370. itemPower.UserType = userType
  1371. return
  1372. }
  1373. // GetActChartPermissionList 获取活动行业分类列表
  1374. func GetActChartPermissionList() []*cygx.ChartPermissionRepMore {
  1375. list := []*cygx.ChartPermissionRepMore{
  1376. {PermissionName: "医药"},
  1377. {PermissionName: "消费"},
  1378. {PermissionName: "科技"},
  1379. {PermissionName: "智造"},
  1380. {PermissionName: "策略"},
  1381. {PermissionName: "固收"},
  1382. {PermissionName: "周期"},
  1383. {PermissionName: "宏观"},
  1384. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN},
  1385. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(医药)"},
  1386. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(消费)"},
  1387. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(科技)"},
  1388. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(智造)"},
  1389. }
  1390. return list
  1391. }
  1392. // 同步活动到最新数据表
  1393. func UpdateResourceData(sourceId int, source, doType, publishDate string) (err error) {
  1394. defer func() {
  1395. if err != nil {
  1396. fmt.Println("err:", err)
  1397. go alarm_msg.SendAlarmMsg("同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型"+source+"操作方式"+doType, 3)
  1398. }
  1399. }()
  1400. if doType == "add" {
  1401. item := new(cygx.CygxResourceData)
  1402. item.SourceId = sourceId
  1403. item.Source = source
  1404. item.PublishDate = publishDate
  1405. item.CreateTime = time.Now()
  1406. _, err = cygx.AddCygxResourceData(item)
  1407. } else if doType == "delete" {
  1408. err = cygx.DeleteResourceData(sourceId, source)
  1409. } else if doType == "update" {
  1410. err = cygx.UpdateResourceData(sourceId, source, publishDate)
  1411. }
  1412. return
  1413. }
  1414. // CheckActivityUpdatePower 校验活动后台管理员、销售是否有修改权限
  1415. func CheckActivityUpdatePower(adminId int, activityInfo *cygx.ActivityDetail) (havePower bool, popupMsg string, err error) {
  1416. defer func() {
  1417. if err != nil {
  1418. fmt.Println("err:", err)
  1419. go alarm_msg.SendAlarmMsg("校验活动后台管理员、销售是否有修改权限失败,Err:"+err.Error(), 3)
  1420. }
  1421. }()
  1422. adminInfo, e := system.GetSysUserById(adminId)
  1423. if e != nil {
  1424. err = errors.New("获取管理员身份失败,GetSysUserById" + e.Error())
  1425. return
  1426. }
  1427. //如果这个活动不是自己建的会议,那么就对权益销售跟权益组长做身份限制判断
  1428. if activityInfo.AdminId > 0 && activityInfo.AdminId != adminId && (adminInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || adminInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP) {
  1429. popupMsg = "只有建会销售可修改。"
  1430. return
  1431. }
  1432. havePower = true
  1433. return
  1434. }
  1435. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  1436. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  1437. defer func() {
  1438. if err != nil {
  1439. fmt.Println("err:", err)
  1440. go alarm_msg.SendAlarmMsg("GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置失败,Err:"+err.Error(), 3)
  1441. }
  1442. }()
  1443. audioMap = make(map[int]string, 0)
  1444. videoMap = make(map[int]string, 0)
  1445. audioShareMap = make(map[int]string, 0)
  1446. videoShareMap = make(map[int]string, 0)
  1447. key := utils.MicroRoadshowDefaultImgKey
  1448. conf, e := cygx.GetCygxConfigDetailByCode(key)
  1449. if e != nil {
  1450. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  1451. return
  1452. }
  1453. if conf.ConfigValue == "" {
  1454. err = errors.New("获取微路演默认图配置有误")
  1455. return
  1456. }
  1457. list := new(cygx.MicroRoadShowDefaultImgList)
  1458. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  1459. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  1460. return
  1461. }
  1462. audioList := list.Audio
  1463. for i := range audioList {
  1464. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  1465. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  1466. }
  1467. videoList := list.Video
  1468. for i := range videoList {
  1469. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  1470. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  1471. }
  1472. return
  1473. }
  1474. // 根据活动ID获取活动关联的产业名称
  1475. func GetActivityIndustrialLabelByActivityIds(activityids []int, source int) (respMap map[int][]string) {
  1476. if len(activityids) == 0 {
  1477. return
  1478. }
  1479. var err error
  1480. defer func() {
  1481. if err != nil {
  1482. go alarm_msg.SendAlarmMsg(fmt.Sprint("根据活动ID获取活动关联的产业名称 失败 GetActivityIndustrialLabelByActivityIds activityids: ", activityids, err.Error()), 2)
  1483. }
  1484. }()
  1485. list, e := cygx.GetIndustrialActivityGroupListByactivityIdsArr(activityids, source)
  1486. if e != nil && e.Error() != utils.ErrNoRow() {
  1487. err = errors.New("GetIndustrialActivityGroupListByactivityIdsArr, Err: " + e.Error())
  1488. return
  1489. }
  1490. respMap = make(map[int][]string, 0)
  1491. for _, v := range list {
  1492. respMap[v.ActivityId] = append(respMap[v.ActivityId], v.IndustryName)
  1493. }
  1494. return
  1495. }
  1496. // 根据活动ID获取活动关联的标的名称
  1497. func GetActivitySubjectLabelByActivityIds(activityids []int, source int) (respMap map[int][]string) {
  1498. if len(activityids) == 0 {
  1499. return
  1500. }
  1501. var err error
  1502. defer func() {
  1503. if err != nil {
  1504. fmt.Println(err)
  1505. go alarm_msg.SendAlarmMsg(fmt.Sprint("根据活动ID获取活动关联的标的名称 失败 GetActivitySubjectLabelByActivityIds activityids: ", activityids, err.Error()), 2)
  1506. }
  1507. }()
  1508. list, e := cygx.GetSubjectActivityGroupManagementListByActivityIdsArr(activityids, source)
  1509. if e != nil && e.Error() != utils.ErrNoRow() {
  1510. err = errors.New("GetSubjectActivityGroupManagementListByActivityIdsArr, Err: " + e.Error())
  1511. return
  1512. }
  1513. respMap = make(map[int][]string, 0)
  1514. for _, v := range list {
  1515. respMap[v.ActivityId] = append(respMap[v.ActivityId], v.SubjectName)
  1516. }
  1517. return
  1518. }