acitvity.go 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  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(2703)
  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. //if len(chartPermissionStarus) > 0 {
  883. // conditionPer += ` AND p.STATUS IN (` + utils.GetOrmInReplace(len(chartPermissionStarus)) + `) `
  884. // parsPer = append(parsPer, chartPermissionStarus)
  885. //}
  886. //先获取有对应权限的所有用户
  887. //openidPowerList, e := cygx.GetCygxUserRecordPowerOpenid(conditionPer, parsPer)
  888. //if e != nil && e.Error() != utils.ErrNoRow() {
  889. // err = errors.New("GetCygxUserRecordPowerOpenid, Err: " + e.Error())
  890. // return
  891. //}
  892. //fmt.Println(len(openidPowerList))
  893. // 获取所有有权的用户的 openid
  894. //openidPowerList, err := cygx.GetCygxUserRecordPower(chartPermissionIds)
  895. //if err != nil {
  896. // return
  897. //}
  898. var havePowerCompanyid string
  899. //如果活动限制人数就做可见区分判断
  900. if activityInfo.IsLimitPeople > 0 {
  901. var companyIdsRecord []int
  902. var companyIdsYongxu []int
  903. companyIdsYongxuMap := make(map[int]int)
  904. var companyIdsDaTaoCan []int
  905. companyIdsDaTaoCanMap := make(map[int]int)
  906. //var companyIdsHangYe []int // 行业套餐客户
  907. companyIdsHangYeMap := make(map[int]int) // 行业套餐客户
  908. companyIds30WMap := make(map[int]int) // 30W套餐客户
  909. var companyIdsShiYong []int
  910. companyIdsShiYongMap := make(map[int]int) // 试用客户
  911. companyIdsShengJiMap := make(map[int]int) // 升级客户
  912. companyIdsZhuKeGuanMap := make(map[int]int) // 行业套餐客户区分主客观
  913. //获取关注了查研观向小助手的客户ID
  914. cygxUserRecordCompanyList, e := cygx.GetCygxUserRecordCompany()
  915. if e != nil && e.Error() != utils.ErrNoRow() {
  916. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  917. return
  918. }
  919. for _, v := range cygxUserRecordCompanyList {
  920. companyIdsRecord = append(companyIdsRecord, v.CompanyId)
  921. }
  922. listYongXu, e := company.GetCompanyProductListByStatus("永续", 2)
  923. if e != nil && e.Error() != utils.ErrNoRow() {
  924. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  925. return
  926. }
  927. //永续客户
  928. for _, v := range listYongXu {
  929. companyIdsYongxu = append(companyIdsYongxu, v.CompanyId)
  930. companyIdsYongxuMap[v.CompanyId] = v.CompanyId
  931. }
  932. listShiYong, e := company.GetCompanyProductListByStatus("试用", 2)
  933. if e != nil && e.Error() != utils.ErrNoRow() {
  934. err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  935. return
  936. }
  937. //试用客户
  938. for _, v := range listShiYong {
  939. companyIdsShiYong = append(companyIdsShiYong, v.CompanyId)
  940. companyIdsShiYongMap[v.CompanyId] = v.CompanyId
  941. }
  942. //自定义的大套餐客户
  943. listDaTaoCan, e := cygx.GetCygxCompanyUserTypeList()
  944. if e != nil && e.Error() != utils.ErrNoRow() {
  945. err = errors.New("GetCygxCompanyUserTypeList, Err: " + e.Error())
  946. return
  947. }
  948. for _, v := range listDaTaoCan {
  949. companyIdsDaTaoCan = append(companyIdsDaTaoCan, v.CompanyId)
  950. companyIdsDaTaoCanMap[v.CompanyId] = v.CompanyId
  951. }
  952. var conditionPer string
  953. var parsPer []interface{}
  954. companyIdsRecord = append(companyIdsRecord, 0)
  955. conditionPer = ` AND r.company_id IN ( ` + utils.GetOrmInReplace(len(companyIdsRecord)) + `) `
  956. parsPer = append(parsPer, companyIdsRecord)
  957. companyReportPermissionItemList, e := cygx.GetCompanyReportPermissionItem(conditionPer, parsPer)
  958. if e != nil && e.Error() != utils.ErrNoRow() {
  959. err = errors.New("GetCompanyReportPermissionItem, Err: " + e.Error())
  960. return
  961. }
  962. permissionNameNumMap := make(map[string]int)
  963. permissionComapnyNumMap := make(map[int]int)
  964. //过滤这些客户中的30w套餐客户(四大行业+策略,有任意4个以上是正式状态的客户)
  965. for _, v := range companyReportPermissionItemList {
  966. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 {
  967. permissionNameNumMap[fmt.Sprint(v.CompanyId, "_", v.PermissionName)]++
  968. 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 {
  969. if permissionNameNumMap[fmt.Sprint(v.CompanyId, "_", v.PermissionName)] == 2 {
  970. permissionComapnyNumMap[v.CompanyId]++
  971. }
  972. }
  973. if v.PermissionName == utils.CE_LUE_NAME {
  974. permissionComapnyNumMap[v.CompanyId]++
  975. }
  976. }
  977. if v.IsUpgrade == 1 && v.PermissionName == activityInfo.ChartPermissionName {
  978. companyIdsShengJiMap[v.CompanyId] = v.CompanyId
  979. }
  980. if activityInfo.PermissionType == 1 {
  981. activityChartPermissionName = activityInfo.ChartPermissionName + "(主观)"
  982. } else {
  983. activityChartPermissionName = activityInfo.ChartPermissionName + "(客观)"
  984. }
  985. }
  986. for k, v := range permissionComapnyNumMap {
  987. if v >= 4 {
  988. companyIds30WMap[k] = v
  989. }
  990. }
  991. //如果一个客户不满足,永续客户,大套餐客户,30W套餐客户 就把他归为其他行业正式客户
  992. for _, v := range companyReportPermissionItemList {
  993. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 && companyIds30WMap[v.CompanyId] == 0 {
  994. if v.Remark == activityChartPermissionName {
  995. companyIdsZhuKeGuanMap[v.CompanyId] = v.CompanyId
  996. }
  997. }
  998. }
  999. //listHangYe, e := company.GetCompanyProductListByStatus("正式", 2)
  1000. //if e != nil && e.Error() != utils.ErrNoRow() {
  1001. // err = errors.New("GetCygxUserRecordCompany, Err: " + e.Error())
  1002. // return
  1003. //}
  1004. for _, v := range companyReportPermissionItemList {
  1005. if companyIdsYongxuMap[v.CompanyId] == 0 && companyIdsDaTaoCanMap[v.CompanyId] == 0 && companyIds30WMap[v.CompanyId] == 0 {
  1006. companyIdsHangYeMap[v.CompanyId] = v.CompanyId
  1007. //var companyIdsHangYe []int // 行业套餐客户
  1008. //companyIdsHangYeMap := make(map[int]int) // 行业套餐客户
  1009. }
  1010. }
  1011. //处理活动针对可见的用户
  1012. var companyIdsPower []int // 获取可见活动的公司ID
  1013. //var companyIds []int
  1014. //mapComapnyId := make(map[int]int)
  1015. //mapCompanyProduct := make(map[int]int)
  1016. //mapComapnyPower := make(map[int]*cygx.CompanyPermissionPower)
  1017. if activityInfo.CustomerTypeIds != "" {
  1018. customerTypeIdMap, err := GetCustomerTypeIds(activityInfo.CustomerTypeIds)
  1019. if err != nil {
  1020. return err
  1021. }
  1022. if _, ok := customerTypeIdMap[1]; ok {
  1023. //永续客户
  1024. for _, v := range listYongXu {
  1025. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1026. }
  1027. }
  1028. if _, ok := customerTypeIdMap[2]; ok {
  1029. //大套餐客户
  1030. for _, v := range listDaTaoCan {
  1031. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1032. }
  1033. }
  1034. if _, ok := customerTypeIdMap[3]; ok {
  1035. //行业套餐客户
  1036. for _, v := range companyIdsHangYeMap {
  1037. companyIdsPower = append(companyIdsPower, v)
  1038. }
  1039. }
  1040. if _, ok := customerTypeIdMap[10]; ok {
  1041. //30万套餐客户
  1042. for k := range companyIds30WMap {
  1043. companyIdsPower = append(companyIdsPower, k)
  1044. }
  1045. }
  1046. if _, ok := customerTypeIdMap[5]; ok {
  1047. //试用客户
  1048. for _, v := range listShiYong {
  1049. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1050. }
  1051. }
  1052. if _, ok := customerTypeIdMap[8]; ok {
  1053. //升级权限的客户
  1054. for k := range companyIdsShengJiMap {
  1055. companyIdsPower = append(companyIdsPower, k)
  1056. }
  1057. for _, v := range listYongXu {
  1058. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1059. }
  1060. }
  1061. if _, ok := customerTypeIdMap[9]; ok {
  1062. //其他行业正式客户
  1063. for k := range companyIdsZhuKeGuanMap {
  1064. companyIdsPower = append(companyIdsPower, k)
  1065. }
  1066. }
  1067. }
  1068. //如果勾选了管理规模可见,则做以下处理
  1069. if activityInfo.Scale != "" {
  1070. listCompmayScale, e := company.GetCompanyProductListByScale(activityInfo.Scale, 2)
  1071. if e != nil && e.Error() != utils.ErrNoRow() {
  1072. err = errors.New("GetCompanyProductListByScale, Err: " + e.Error())
  1073. return
  1074. }
  1075. for _, v := range listCompmayScale {
  1076. companyIdsPower = append(companyIdsPower, v.CompanyId)
  1077. }
  1078. }
  1079. companyIdsPowerMap := make(map[int]int)
  1080. for _, v := range companyIdsPower {
  1081. companyIdsPowerMap[v] = v
  1082. }
  1083. //如果活动设置仅本组可见,那么则对公司ID做限制
  1084. if activityInfo.VisibleRange == 1 {
  1085. adminInfo, err := system.GetSysUserById(activityInfo.AdminId)
  1086. if err != nil {
  1087. return err
  1088. }
  1089. adminList, err := system.GetAdminListByGroupId(adminInfo.GroupId)
  1090. if err != nil {
  1091. return err
  1092. }
  1093. var adminIdGroup string
  1094. for _, v := range adminList {
  1095. adminIdGroup += strconv.Itoa(v.AdminId) + ","
  1096. }
  1097. adminIdGroup = strings.TrimRight(adminIdGroup, ",")
  1098. companyProductList, err := company.GetCompanyProductsBySellerId(adminIdGroup)
  1099. if err != nil && err.Error() != utils.ErrNoRow() {
  1100. return err
  1101. }
  1102. if len(companyProductList) == 0 {
  1103. return err
  1104. }
  1105. for _, v := range companyProductList {
  1106. if companyIdsPowerMap[v.CompanyId] > 0 {
  1107. havePowerCompanyid += strconv.Itoa(v.CompanyId) + ","
  1108. }
  1109. }
  1110. } else {
  1111. for _, v := range companyIdsPowerMap {
  1112. havePowerCompanyid += strconv.Itoa(v) + ","
  1113. }
  1114. }
  1115. havePowerCompanyid = strings.TrimRight(havePowerCompanyid, ",")
  1116. if havePowerCompanyid == "" {
  1117. return err
  1118. }
  1119. }
  1120. //获取拒绝接收推送的的用户的 openid
  1121. mapOpenidRefuset := make(map[int]string)
  1122. openidRefusetList, err := cygx.GetCygxUserRefusetOpenid()
  1123. if err != nil && err.Error() != utils.ErrNoRow() {
  1124. return err
  1125. }
  1126. for _, v := range openidRefusetList {
  1127. mapOpenidRefuset[v.UserId] = v.OpenId
  1128. }
  1129. var condition string
  1130. //如果活动选择了仅有决策人可见则做以下处理
  1131. if activityInfo.IsMakerShow == 1 {
  1132. condition += ` AND u.is_maker = 1 `
  1133. }
  1134. //fmt.Println(havePowerCompanyid)
  1135. if activityInfo.IsLimitPeople > 0 && havePowerCompanyid != "" {
  1136. condition += ` AND u.company_id IN (` + havePowerCompanyid + `) `
  1137. }
  1138. //根据活动的主客观,获取选择主客观规则的用户的 openid
  1139. mapUserIdChooseTypeSend := make(map[int]int)
  1140. //获取提交过推送规则的用户的 openid
  1141. mapUserIdChooseSend := make(map[int]int)
  1142. var conditionChoose string
  1143. if activityInfo.ChartPermissionName == utils.YI_YAO_NAME {
  1144. conditionChoose = ` AND all_in_yi_yao = 0 `
  1145. } else if activityInfo.ChartPermissionName == utils.XIAO_FEI_NAME {
  1146. conditionChoose = ` AND all_in_xiao_fei = 0 `
  1147. } else if activityInfo.ChartPermissionName == utils.KE_JI_NAME {
  1148. conditionChoose = ` AND all_in_ke_ji = 0 `
  1149. } else if activityInfo.ChartPermissionName == utils.ZHI_ZAO_NAME {
  1150. conditionChoose = ` AND all_in_zhi_zao = 0 `
  1151. } else if activityInfo.ChartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN || activityInfo.ChartPermissionName == utils.CHART_PERMISSION_NAME_YANXUAN {
  1152. conditionChoose = ` AND all_in_yan_xuan = 0 `
  1153. }
  1154. chooseSendtList, err := cygx.GetCygxXzsChooseSend(conditionChoose)
  1155. if err != nil && err.Error() != utils.ErrNoRow() {
  1156. return err
  1157. }
  1158. for _, v := range chooseSendtList {
  1159. mapUserIdChooseSend[v.UserId] = v.UserId
  1160. //选择主观的客户
  1161. if activityInfo.PermissionType == 1 && v.IsSubjective == 1 {
  1162. mapUserIdChooseTypeSend[v.UserId] = v.UserId
  1163. }
  1164. //选择客观的客户
  1165. if activityInfo.PermissionType == 2 && v.IsObjective == 1 {
  1166. mapUserIdChooseTypeSend[v.UserId] = v.UserId
  1167. }
  1168. }
  1169. //fmt.Println(chooseSendtList)
  1170. //获取关注这个活动对应产业的用户的 openid
  1171. mapOpenidFllow := make(map[int]string)
  1172. openidFllowList, err := cygx.GetCygxActiviyUserFllowOpenid(activityId)
  1173. if err != nil && err.Error() != utils.ErrNoRow() {
  1174. return err
  1175. }
  1176. for _, v := range openidFllowList {
  1177. mapOpenidFllow[v.UserId] = v.OpenId
  1178. }
  1179. //fmt.Println(mapOpenidFllow)
  1180. openidPowerByActivitySetList, openidPowerByActivitySetListYx, err := cygx.GetCygxUserRecordPowerByActivitySet(chartPermissionIds, condition)
  1181. if err != nil && err.Error() != utils.ErrNoRow() {
  1182. return err
  1183. }
  1184. //已经推送过的不做二次推送
  1185. listSendOpendId, err := cygx.GeCygxActivityUserTemplateRecordListByActivityId(activityId, utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD)
  1186. if err != nil && err.Error() != utils.ErrNoRow() {
  1187. return err
  1188. }
  1189. mapSendOpenid := make(map[string]int)
  1190. for _, v := range listSendOpendId {
  1191. mapSendOpenid[v.OpenId] = v.UserId
  1192. }
  1193. var OpenIdList []*models.OpenIdList
  1194. for _, v := range openidPowerByActivitySetList {
  1195. if mapSendOpenid[v.OpenId] > 0 {
  1196. //fmt.Println("已经推过了")
  1197. continue
  1198. }
  1199. item := new(models.OpenIdList)
  1200. item.UserId = v.UserId
  1201. item.OpenId = v.OpenId
  1202. if mapUserIdChooseSend[v.UserId] == 0 {
  1203. //如果小助手没有选择过权限信息,那么做消息推送
  1204. OpenIdList = append(OpenIdList, item)
  1205. } else {
  1206. //如果勾选了权限信息,则要满足 1选择产业,2没有选择不接受任何消息推送,3活动对应的主客观跟自己选择的一致。
  1207. if mapOpenidFllow[v.UserId] != "" && mapOpenidRefuset[v.UserId] == "" && mapUserIdChooseTypeSend[v.UserId] != 0 {
  1208. OpenIdList = append(OpenIdList, item)
  1209. }
  1210. }
  1211. }
  1212. var openiditems []*cygx.CygxActivityUserTemplateRecord
  1213. var openIdArr []string
  1214. for _, v := range OpenIdList {
  1215. //openIdArr[i] = v.OpenId
  1216. openIdArr = append(openIdArr, v.OpenId)
  1217. openiditem := new(cygx.CygxActivityUserTemplateRecord)
  1218. openiditem.ActivityId = activityId
  1219. openiditem.UserId = v.UserId
  1220. openiditem.OpenId = v.OpenId
  1221. openiditem.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1222. openiditem.CreateTime = time.Now()
  1223. openiditems = append(openiditems, openiditem)
  1224. }
  1225. var OpenIdListYx []*models.OpenIdList
  1226. for _, v := range openidPowerByActivitySetListYx {
  1227. if mapSendOpenid[v.OpenId] > 0 {
  1228. //fmt.Println("已经推过了")
  1229. continue
  1230. }
  1231. item := new(models.OpenIdList)
  1232. item.UserId = v.UserId
  1233. item.OpenId = v.OpenId
  1234. if mapUserIdChooseSend[v.UserId] == 0 {
  1235. //如果小助手没有选择过权限信息,那么做消息推送
  1236. OpenIdListYx = append(OpenIdListYx, item)
  1237. } else {
  1238. //如果勾选了权限信息,则要满足 1选择产业,2没有选择不接受任何消息推送,3活动对应的主客观跟自己选择的一致。
  1239. if mapOpenidFllow[v.UserId] != "" && mapOpenidRefuset[v.UserId] == "" && mapUserIdChooseTypeSend[v.UserId] != 0 {
  1240. OpenIdListYx = append(OpenIdListYx, item)
  1241. }
  1242. }
  1243. }
  1244. var openIdArrYx []string
  1245. for _, v := range OpenIdListYx {
  1246. //openIdArr[i] = v.OpenId
  1247. openIdArrYx = append(openIdArrYx, v.OpenId)
  1248. openiditem := new(cygx.CygxActivityUserTemplateRecord)
  1249. openiditem.ActivityId = activityId
  1250. openiditem.UserId = v.UserId
  1251. openiditem.OpenId = v.OpenId
  1252. openiditem.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1253. openiditem.CreateTime = time.Now()
  1254. openiditems = append(openiditems, openiditem)
  1255. }
  1256. if len(OpenIdList)+len(OpenIdListYx) == 0 {
  1257. return err
  1258. }
  1259. activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
  1260. if len(openIdArr) > 0 {
  1261. first := "您关注的赛道,有【" + activityInfo.ActivityTypeName + "】活动发布,欢迎参与"
  1262. keyword1 := "新活动:" + activityInfo.ActivityName
  1263. keyword2 := activityInfo.ActivityTimeText + ",【" + activityInfo.Label + "】"
  1264. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  1265. sendInfo := new(services.SendWxTemplate)
  1266. sendInfo.First = first
  1267. sendInfo.Keyword1 = keyword1
  1268. sendInfo.Keyword2 = keyword2
  1269. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  1270. sendInfo.RedirectUrl = redirectUrl
  1271. sendInfo.RedirectTarget = 3
  1272. sendInfo.Resource = strconv.Itoa(activityId)
  1273. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1274. sendInfo.OpenIdArr = openIdArr
  1275. e := services.SendTemplateMsg(sendInfo)
  1276. if e != nil {
  1277. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  1278. return
  1279. }
  1280. }
  1281. if len(OpenIdListYx) > 0 {
  1282. industrialName := ""
  1283. for _, v := range industrialList {
  1284. industrialName += v.IndustryName + ","
  1285. }
  1286. industrialName = strings.TrimRight(industrialName, ",")
  1287. // 发类目模版消息
  1288. if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  1289. actTime, _ := time.Parse(utils.FormatDateTime, activityInfo.ActivityTime)
  1290. first := industrialName
  1291. keyword1 := "发布了新活动"
  1292. keyword2 := utils.TruncateActivityNameString(activityInfo.ActivityName)
  1293. keyword3 := actTime.Format(utils.FormatDateTimeMinute2)
  1294. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  1295. sendInfo := new(services.SendWxCategoryTemplate)
  1296. sendInfo.Keywords = []string{first, keyword1, keyword2, keyword3}
  1297. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  1298. sendInfo.RedirectUrl = redirectUrl
  1299. sendInfo.RedirectTarget = 3
  1300. sendInfo.Resource = strconv.Itoa(activityId)
  1301. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  1302. sendInfo.OpenIdArr = openIdArrYx
  1303. e := services.SendCategoryTemplateMsg(sendInfo)
  1304. if e != nil {
  1305. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  1306. return
  1307. }
  1308. }
  1309. }
  1310. //活动发布推送的Openid记录
  1311. if len(openiditems) > 0 {
  1312. e := cygx.AddCygxActivityUserTemplateRecordMulti(openiditems)
  1313. if e != nil {
  1314. err = errors.New("AddCygxActivityUserTemplateRecordMulti, Err: " + e.Error())
  1315. return
  1316. }
  1317. }
  1318. return
  1319. }
  1320. // 获取 用户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  1321. func GetUserTypeByPermission(item *cygx.CompanyPermissionPower) (itemPower *cygx.CompanyPermissionPower) {
  1322. itemPower = item
  1323. var userType int
  1324. var permissionStr string
  1325. var permissionZhengShiStr string
  1326. permissionStr = item.PermissionName
  1327. permissionZhengShiStr = item.PermissionNameZhengShi
  1328. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户 6、冻结客户;7、流失客户
  1329. if item.Status == "永续" {
  1330. userType = 1
  1331. } else if item.Status == "试用" {
  1332. userType = 5
  1333. } else if item.Status == "正式" {
  1334. if permissionStr == "专家" {
  1335. userType = 4
  1336. } else if strings.Contains(permissionZhengShiStr, "医药") && strings.Contains(permissionZhengShiStr, "消费") && strings.Contains(permissionZhengShiStr, "科技") && strings.Contains(permissionZhengShiStr, "智造") {
  1337. userType = 2
  1338. } else {
  1339. userType = 3
  1340. }
  1341. if userType == 3 {
  1342. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  1343. userType = 4
  1344. }
  1345. }
  1346. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  1347. if userType == 3 {
  1348. var permissionZhegnshiNum int
  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, "智造") == 2 {
  1359. permissionZhegnshiNum++
  1360. }
  1361. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  1362. permissionZhegnshiNum++
  1363. }
  1364. if permissionZhegnshiNum >= 4 {
  1365. userType = 2
  1366. }
  1367. }
  1368. } else if item.Status == "冻结" {
  1369. userType = 6
  1370. } else if item.Status == "流失" {
  1371. userType = 7
  1372. }
  1373. itemPower.UserType = userType
  1374. return
  1375. }
  1376. // GetActChartPermissionList 获取活动行业分类列表
  1377. func GetActChartPermissionList() []*cygx.ChartPermissionRepMore {
  1378. list := []*cygx.ChartPermissionRepMore{
  1379. {PermissionName: "医药"},
  1380. {PermissionName: "消费"},
  1381. {PermissionName: "科技"},
  1382. {PermissionName: "智造"},
  1383. {PermissionName: "策略"},
  1384. {PermissionName: "固收"},
  1385. {PermissionName: "周期"},
  1386. {PermissionName: "宏观"},
  1387. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN},
  1388. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(医药)"},
  1389. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(消费)"},
  1390. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(科技)"},
  1391. //{PermissionName: utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(智造)"},
  1392. }
  1393. return list
  1394. }
  1395. // 同步活动到最新数据表
  1396. func UpdateResourceData(sourceId int, source, doType, publishDate string) (err error) {
  1397. defer func() {
  1398. if err != nil {
  1399. fmt.Println("err:", err)
  1400. go alarm_msg.SendAlarmMsg("同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型"+source+"操作方式"+doType, 3)
  1401. }
  1402. }()
  1403. if doType == "add" {
  1404. item := new(cygx.CygxResourceData)
  1405. item.SourceId = sourceId
  1406. item.Source = source
  1407. item.PublishDate = publishDate
  1408. item.CreateTime = time.Now()
  1409. _, err = cygx.AddCygxResourceData(item)
  1410. } else if doType == "delete" {
  1411. err = cygx.DeleteResourceData(sourceId, source)
  1412. } else if doType == "update" {
  1413. err = cygx.UpdateResourceData(sourceId, source, publishDate)
  1414. }
  1415. return
  1416. }
  1417. // CheckActivityUpdatePower 校验活动后台管理员、销售是否有修改权限
  1418. func CheckActivityUpdatePower(adminId int, activityInfo *cygx.ActivityDetail) (havePower bool, popupMsg string, err error) {
  1419. defer func() {
  1420. if err != nil {
  1421. fmt.Println("err:", err)
  1422. go alarm_msg.SendAlarmMsg("校验活动后台管理员、销售是否有修改权限失败,Err:"+err.Error(), 3)
  1423. }
  1424. }()
  1425. adminInfo, e := system.GetSysUserById(adminId)
  1426. if e != nil {
  1427. err = errors.New("获取管理员身份失败,GetSysUserById" + e.Error())
  1428. return
  1429. }
  1430. //如果这个活动不是自己建的会议,那么就对权益销售跟权益组长做身份限制判断
  1431. if activityInfo.AdminId > 0 && activityInfo.AdminId != adminId && (adminInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || adminInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP) {
  1432. popupMsg = "只有建会销售可修改。"
  1433. return
  1434. }
  1435. havePower = true
  1436. return
  1437. }
  1438. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  1439. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  1440. defer func() {
  1441. if err != nil {
  1442. fmt.Println("err:", err)
  1443. go alarm_msg.SendAlarmMsg("GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置失败,Err:"+err.Error(), 3)
  1444. }
  1445. }()
  1446. audioMap = make(map[int]string, 0)
  1447. videoMap = make(map[int]string, 0)
  1448. audioShareMap = make(map[int]string, 0)
  1449. videoShareMap = make(map[int]string, 0)
  1450. key := utils.MicroRoadshowDefaultImgKey
  1451. conf, e := cygx.GetCygxConfigDetailByCode(key)
  1452. if e != nil {
  1453. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  1454. return
  1455. }
  1456. if conf.ConfigValue == "" {
  1457. err = errors.New("获取微路演默认图配置有误")
  1458. return
  1459. }
  1460. list := new(cygx.MicroRoadShowDefaultImgList)
  1461. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  1462. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  1463. return
  1464. }
  1465. audioList := list.Audio
  1466. for i := range audioList {
  1467. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  1468. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  1469. }
  1470. videoList := list.Video
  1471. for i := range videoList {
  1472. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  1473. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  1474. }
  1475. return
  1476. }
  1477. // 根据活动ID获取活动关联的产业名称
  1478. func GetActivityIndustrialLabelByActivityIds(activityids []int, source int) (respMap map[int][]string) {
  1479. if len(activityids) == 0 {
  1480. return
  1481. }
  1482. var err error
  1483. defer func() {
  1484. if err != nil {
  1485. go alarm_msg.SendAlarmMsg(fmt.Sprint("根据活动ID获取活动关联的产业名称 失败 GetActivityIndustrialLabelByActivityIds activityids: ", activityids, err.Error()), 2)
  1486. }
  1487. }()
  1488. list, e := cygx.GetIndustrialActivityGroupListByactivityIdsArr(activityids, source)
  1489. if e != nil && e.Error() != utils.ErrNoRow() {
  1490. err = errors.New("GetIndustrialActivityGroupListByactivityIdsArr, Err: " + e.Error())
  1491. return
  1492. }
  1493. respMap = make(map[int][]string, 0)
  1494. for _, v := range list {
  1495. respMap[v.ActivityId] = append(respMap[v.ActivityId], v.IndustryName)
  1496. }
  1497. return
  1498. }
  1499. // 根据活动ID获取活动关联的标的名称
  1500. func GetActivitySubjectLabelByActivityIds(activityids []int, source int) (respMap map[int][]string) {
  1501. if len(activityids) == 0 {
  1502. return
  1503. }
  1504. var err error
  1505. defer func() {
  1506. if err != nil {
  1507. fmt.Println(err)
  1508. go alarm_msg.SendAlarmMsg(fmt.Sprint("根据活动ID获取活动关联的标的名称 失败 GetActivitySubjectLabelByActivityIds activityids: ", activityids, err.Error()), 2)
  1509. }
  1510. }()
  1511. list, e := cygx.GetSubjectActivityGroupManagementListByActivityIdsArr(activityids, source)
  1512. if e != nil && e.Error() != utils.ErrNoRow() {
  1513. err = errors.New("GetSubjectActivityGroupManagementListByActivityIdsArr, Err: " + e.Error())
  1514. return
  1515. }
  1516. respMap = make(map[int][]string, 0)
  1517. for _, v := range list {
  1518. respMap[v.ActivityId] = append(respMap[v.ActivityId], v.SubjectName)
  1519. }
  1520. return
  1521. }