activity.go 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. "hongze/hz_crm_api/services"
  10. cygxService "hongze/hz_crm_api/services/cygx"
  11. "hongze/hz_crm_api/services/elastic"
  12. "hongze/hz_crm_api/utils"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // 活动
  18. type ActivityCoAntroller struct {
  19. controllers.BaseAuthController
  20. }
  21. // @Title 活动客户列表
  22. // @Description 活动客户列表接口
  23. // @Param IsZxdy query bool false "是否展示专项调研类型"
  24. // @Success 200 {object} cygx.ActivityCcustomerTypeList
  25. // @router /activity/customerTypelist [get]
  26. func (this *ActivityCoAntroller) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. isZxdy, _ := this.GetBool("IsZxdy", false)
  33. sysUser := this.SysUser
  34. if sysUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. br.Ret = 408
  38. return
  39. }
  40. resp := new(cygx.ActivityCcustomerTypeList)
  41. var condition string
  42. if !isZxdy {
  43. condition += ` AND is_activity = 1 `
  44. } else {
  45. condition += ` AND is_apecial = 1 `
  46. }
  47. list, err := cygx.GetActivityCcustomerTypeList(condition)
  48. if err != nil {
  49. br.Msg = "获取失败"
  50. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  51. return
  52. }
  53. resp.List = list
  54. br.Ret = 200
  55. br.Success = true
  56. br.Msg = "获取成功"
  57. br.Data = resp
  58. }
  59. // @Title 活动内容的保存与发布
  60. // @Description 活动内容的保存与发布接口
  61. // @Param request body cygx.ActivityRep true "type json string"
  62. // @Success 200 操作成功
  63. // @router /activity/PreserveAndPublish [post]
  64. func (this *ActivityCoAntroller) PreserveAndPublish() {
  65. br := new(models.BaseResponse).Init()
  66. defer func() {
  67. this.Data["json"] = br
  68. this.ServeJSON()
  69. }()
  70. AdminUser := this.SysUser
  71. if AdminUser == nil {
  72. br.Msg = "请登录"
  73. br.ErrMsg = "请登录,用户信息为空"
  74. br.Ret = 408
  75. return
  76. }
  77. var req cygx.ActivityRep
  78. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  79. if err != nil {
  80. br.Msg = "参数解析异常!"
  81. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  82. return
  83. }
  84. if req.Body == "" {
  85. br.Msg = "内容不可为空"
  86. return
  87. }
  88. //不限制人数的,强制改为全部客户可见
  89. if req.LimitPeopleNum == 0 {
  90. req.VisibleRange = 2
  91. req.IsMakerShow = 0
  92. req.Scale = ""
  93. req.CustomerTypeIds = ""
  94. }
  95. if req.IsResearchPoints == 0 {
  96. req.SiginupDeadline = ""
  97. }
  98. activityId := req.ActivityId
  99. labelType := req.LabelType
  100. labelList := req.List
  101. activityTypeId := req.ActivityTypeId
  102. scale := req.Scale
  103. voiceList := req.VoiceList
  104. videoDetail := req.VideoDetail
  105. isBClass := req.IsBClass
  106. isResearchPoints := req.IsResearchPoints
  107. var items []*cygx.CygxActivity
  108. //temporaryLabel := req.TemporaryLabel
  109. industrialManagementIdS := req.IndustrialManagementIdS
  110. industrialSubjectIdS := req.IndustrialSubjectIdS
  111. body := req.Body
  112. customerTypeIds := req.CustomerTypeIds
  113. if req.VisibleRange != 1 {
  114. req.VisibleRange = 2
  115. }
  116. //公司调研电话会,增加【外部资源】勾选项,其他的强制过滤
  117. if req.ActivityTypeId != 3 {
  118. req.IsExternalLabel = 0
  119. }
  120. isExternalLabel := req.IsExternalLabel
  121. pointsSet := req.PointsSet
  122. isNeedEmail := req.IsNeedEmail
  123. siginupDeadline := req.SiginupDeadline
  124. if customerTypeIds != "" {
  125. condition := ` AND customer_type_id IN (` + customerTypeIds + `)`
  126. listValue, err := cygx.GetActivityCcustomerTypeList(condition)
  127. if err != nil {
  128. br.Msg = "活动可见套餐类型错误,请核实"
  129. return
  130. }
  131. req.CustomerTypeIds = ""
  132. for _, v := range listValue {
  133. req.CustomerTypeIds += v.PermissionValue + ","
  134. }
  135. req.CustomerTypeIds = strings.TrimRight(req.CustomerTypeIds, ",")
  136. }
  137. if len(voiceList) > 0 && videoDetail != nil {
  138. br.Msg = "音频与视频只能上传一个"
  139. return
  140. }
  141. body = strings.Replace(body, "  ", "", -1)
  142. body = strings.Replace(body, " ", "", -1)
  143. slice := strings.Split(body, "<hr>")
  144. if activityId == 0 {
  145. if activityTypeId == 1 {
  146. if labelType != 1 && labelType != 2 {
  147. br.Msg = "请选择主题标签"
  148. return
  149. }
  150. }
  151. }
  152. var industrialActivityItemsList [][]*cygx.CygxIndustrialActivityGroupManagement
  153. var subjectActivityItemsList [][]*cygx.CygxIndustrialActivityGroupSubject
  154. var industryAndSubjectNameItems []*cygx.IndustryAndSubjectName
  155. var industrialNames string
  156. var industrialSubjectNames string
  157. industryIds := make([]int, 0)
  158. for _, vLabel := range labelList {
  159. var industrialActivityItems []*cygx.CygxIndustrialActivityGroupManagement
  160. var subjectActivityItems []*cygx.CygxIndustrialActivityGroupSubject
  161. if vLabel.IndustrialManagementIdS != "" {
  162. industrialManagementIdS = vLabel.IndustrialManagementIdS
  163. industrialSubjectIdS = vLabel.IndustrialSubjectIdS
  164. if industrialManagementIdS == "" {
  165. br.Msg = "请选择产业"
  166. return
  167. }
  168. industrialManagementIdS = strings.Replace(industrialManagementIdS, " ", "", -1)
  169. industrialManagementList := strings.Split(industrialManagementIdS, ",")
  170. for _, v := range industrialManagementList {
  171. industrialActivityItem := new(cygx.CygxIndustrialActivityGroupManagement)
  172. industrialManagementId, err := strconv.Atoi(v)
  173. if err != nil {
  174. br.Msg = "参数解析异常!"
  175. br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIdS
  176. return
  177. }
  178. industryIds = append(industryIds, industrialManagementId)
  179. industrialActivityItem.CreateTime = time.Now()
  180. industrialActivityItem.IndustrialManagementId = industrialManagementId
  181. industrialActivityItem.ActivityId = activityId
  182. industrialActivityItem.Source = 1
  183. industrialActivityItems = append(industrialActivityItems, industrialActivityItem)
  184. }
  185. if industrialSubjectIdS != "" {
  186. industrialSubjectIdList := strings.Split(industrialSubjectIdS, ",")
  187. for _, v := range industrialSubjectIdList {
  188. subjectActivityItem := new(cygx.CygxIndustrialActivityGroupSubject)
  189. industrialSubjectId, err := strconv.Atoi(v)
  190. if err != nil {
  191. br.Msg = "参数解析异常!"
  192. br.ErrMsg = "标的ID不规范,Err:" + err.Error() + industrialManagementIdS
  193. return
  194. }
  195. subjectActivityItem.CreateTime = time.Now()
  196. subjectActivityItem.IndustrialSubjectId = industrialSubjectId
  197. subjectActivityItem.ActivityId = activityId
  198. subjectActivityItem.Source = 1
  199. subjectActivityItems = append(subjectActivityItems, subjectActivityItem)
  200. }
  201. }
  202. //产业名称
  203. if industrialManagementIdS != "" {
  204. industrialNames, err = cygx.GetindustrialManagementNames(industrialManagementIdS)
  205. if err != nil {
  206. br.Msg = "参数解析异常!"
  207. br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIdS
  208. return
  209. }
  210. }
  211. //标的名称
  212. if industrialSubjectIdS != "" {
  213. industrialSubjectNames, err = cygx.GetindustrialSubjectNames(industrialSubjectIdS)
  214. if err != nil {
  215. br.Msg = "参数解析异常!"
  216. br.ErrMsg = "标的ID不规范,Err:" + err.Error() + industrialSubjectIdS
  217. return
  218. }
  219. } else {
  220. industrialSubjectNames = ""
  221. }
  222. }
  223. if len(industrialActivityItems) == 0 {
  224. industrialActivityItems = make([]*cygx.CygxIndustrialActivityGroupManagement, 0)
  225. }
  226. if len(subjectActivityItems) == 0 {
  227. subjectActivityItems = make([]*cygx.CygxIndustrialActivityGroupSubject, 0)
  228. }
  229. industrialActivityItemsList = append(industrialActivityItemsList, industrialActivityItems)
  230. subjectActivityItemsList = append(subjectActivityItemsList, subjectActivityItems)
  231. //合并产业以及标的的名称
  232. industryAndSubjectNameItem := new(cygx.IndustryAndSubjectName)
  233. industryAndSubjectNameItem.IndustryNames = industrialNames
  234. industryAndSubjectNameItem.SubjectNames = industrialSubjectNames
  235. industryAndSubjectNameItem.TemporaryLabel = vLabel.TemporaryLabel
  236. industrialNames = ""
  237. industrialSubjectNames = ""
  238. industryAndSubjectNameItems = append(industryAndSubjectNameItems, industryAndSubjectNameItem)
  239. }
  240. if labelType == 1 || labelType == 0 {
  241. if len(slice) > len(industrialActivityItemsList) {
  242. for k := range slice {
  243. if k > 0 {
  244. if len(industrialActivityItemsList) > 0 {
  245. industrialActivityItemsList = append(industrialActivityItemsList, industrialActivityItemsList[0])
  246. }
  247. if len(subjectActivityItemsList) > 0 {
  248. subjectActivityItemsList = append(subjectActivityItemsList, subjectActivityItemsList[0])
  249. }
  250. if len(industryAndSubjectNameItems) > 0 {
  251. industryAndSubjectNameItems = append(industryAndSubjectNameItems, industryAndSubjectNameItems[0])
  252. }
  253. }
  254. }
  255. }
  256. }
  257. if labelType == 2 {
  258. if len(slice) != len(labelList) {
  259. br.Msg = "活动和主题个数不符,请核实"
  260. return
  261. }
  262. }
  263. permissionName := req.PermissionName
  264. List := cygxService.GetActChartPermissionList()
  265. var haveCheck bool
  266. for _, v := range List {
  267. if permissionName == v.PermissionName {
  268. haveCheck = true
  269. }
  270. }
  271. if !haveCheck {
  272. br.Msg = "行业名称:" + permissionName + "不存在"
  273. return
  274. }
  275. if strings.Contains(permissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  276. permissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  277. }
  278. //charInfo, errCategory := cygx.GetCategoryInfoById(req.ChartPermissionId)
  279. charInfo, errCategory := cygx.GetCategoryInfoByName(permissionName)
  280. if errCategory != nil {
  281. br.Msg = "请选择所属行业"
  282. br.ErrMsg = "获取所属行业信息失败,Err:" + errCategory.Error()
  283. return
  284. }
  285. if charInfo.PermissionName == "宏观经济" {
  286. charInfo.PermissionName = "宏观"
  287. }
  288. activityTypeInfo, errType := cygx.GetActivityTypeDetailById(activityTypeId)
  289. if errType != nil {
  290. br.Msg = "请选择活动类型"
  291. br.ErrMsg = "获取活动类型信息失败,Err:" + errType.Error()
  292. return
  293. }
  294. var activeState int
  295. var checkYidong bool
  296. if req.ActivityId > 0 {
  297. activityInfo, errInfo := cygx.GetAddActivityInfoById(req.ActivityId)
  298. if errInfo != nil {
  299. br.Msg = "活动不存在"
  300. br.ErrMsg = "活动ID错误,ActivityId:" + strconv.Itoa(req.ActivityId)
  301. return
  302. }
  303. if activityInfo.ActiveState > 1 {
  304. activeState = activityInfo.ActiveState
  305. }
  306. if activityInfo.YidongActivityId != "" {
  307. checkYidong = true
  308. }
  309. //校验活动后台管理员、销售是否有修改权限
  310. havePower, popupMsg, err := cygxService.CheckActivityUpdatePower(AdminUser.AdminId, activityInfo)
  311. if err != nil {
  312. br.Msg = "获取管理员身份信息失败"
  313. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  314. return
  315. }
  316. if !havePower {
  317. br.Msg = popupMsg
  318. return
  319. }
  320. }
  321. var itemPointsSet = new(cygx.CygxActivityPointsSet)
  322. var itemPointsSetOld = new(cygx.CygxActivityPointsSetRsq)
  323. if activityId > 0 {
  324. itemPointsSetOld, err = cygx.GetCygxActivityPointsSetDetail(activityId)
  325. if err != nil && err.Error() != utils.ErrNoRow() {
  326. br.Msg = "获取信息失败"
  327. br.ErrMsg = "GetCygxActivityPointsSetDetail,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  328. return
  329. }
  330. }
  331. //校验研选扣点内容,对于已结束的活动不做点数校验
  332. if isResearchPoints == 1 {
  333. errMsg, itemResp, err := cygxService.CheckActivityPointsSet(pointsSet, activityId)
  334. if errMsg != "" {
  335. br.Msg = errMsg
  336. return
  337. }
  338. if err != nil {
  339. br.Msg = "操作失败"
  340. br.ErrMsg = "操作失败,Err:" + err.Error()
  341. return
  342. }
  343. itemPointsSet = itemResp
  344. }
  345. for k, v := range slice {
  346. //如果内容不存在 时间:字段则不予处理
  347. if strings.Contains(v, "时间:") || strings.Contains(v, "时间:") {
  348. slicebr := strings.Split(v, "<br")
  349. //浏览器兼容处理
  350. if len(slicebr) > 5 {
  351. v = strings.Replace(v, "br", "p", -1)
  352. }
  353. v = strings.Replace(v, "<p><br></p>", "", -1) //删除空标签,兼容标题顶部空格、换行
  354. v = strings.Replace(v, "<p><p></p>", "", -1)
  355. v = strings.Replace(v, "<p></p>", "", -1)
  356. v = strings.Replace(v, "<p><p>", "", -1)
  357. v = strings.Replace(v, "<br>", "", -1)
  358. v = strings.Replace(v, "<p id=\"isPasted\"></p>", "", -1)
  359. item, errstr := cygxService.ActivityBodyAnalysis(v, activeState, req)
  360. if len(errstr) > 0 {
  361. br.Msg = errstr
  362. br.IsSendEmail = false
  363. return
  364. }
  365. var temporaryLabel string
  366. if len(labelList) == 1 {
  367. temporaryLabel = labelList[0].TemporaryLabel
  368. } else {
  369. temporaryLabel = labelList[k].TemporaryLabel
  370. }
  371. item.TemporaryLabel = temporaryLabel
  372. item.IsBClass = isBClass
  373. if item.ReportLink != "" {
  374. articleIdLink, err := cygxService.GetReportLinkToArticleid(item.ReportLink)
  375. if err != nil {
  376. br.Msg = "操作失败"
  377. br.ErrMsg = "解析报告链接ID失败,Err:" + err.Error()
  378. return
  379. }
  380. item.ArticleId = articleIdLink
  381. }
  382. //if k == 0 && item.Label == "" {
  383. // br.Msg = "请填写活动标签"
  384. // return
  385. //}
  386. item.AdminId = AdminUser.AdminId
  387. item.AdminName = AdminUser.RealName
  388. item.Body = v
  389. item.ChartPermissionName = charInfo.PermissionName
  390. item.ChartPermissionNames = req.PermissionName
  391. item.ChartPermissionId = charInfo.ChartPermissionId
  392. item.ActivityTypeName = activityTypeInfo.ActivityTypeName
  393. item.ActivityTypeId = activityTypeInfo.ActivityTypeId
  394. item.CustomerTypeIds = req.CustomerTypeIds
  395. item.LimitPeopleNum = req.LimitPeopleNum
  396. item.IsMakerShow = req.IsMakerShow
  397. item.VisibleRange = req.VisibleRange
  398. item.PublishDate = time.Now()
  399. item.IsYidongConduct = req.IsYidongConduct
  400. item.IsCanOutboundCall = req.IsCanOutboundCall
  401. item.IsNeedEmail = isNeedEmail
  402. item.SiginupDeadline = siginupDeadline
  403. if isResearchPoints == 1 {
  404. item.IsResearchPoints = 1
  405. }
  406. //当不限制人数的时候,强制改为全部客户可见
  407. //if req.LimitPeopleNum == 0 {
  408. // item.VisibleRange = 2
  409. //}
  410. ////除了C类电话会其他类型的会议,强制改为全部客户可见
  411. //if req.ActivityTypeId != 7 {
  412. // item.VisibleRange = 2
  413. //}
  414. item.CreateTime = time.Now()
  415. item.LastUpdatedTime = time.Now()
  416. item.Scale = scale
  417. item.IsExternalLabel = isExternalLabel
  418. item.IsAllCustomerType = req.IsAllCustomerType
  419. if len(labelList) == 1 {
  420. item.IsCanAppointmentMinutes = labelList[0].IsCanAppointmentMinutes
  421. } else {
  422. item.IsCanAppointmentMinutes = labelList[k].IsCanAppointmentMinutes
  423. }
  424. if item.ActivityName == "" {
  425. br.Msg = "请填写活动名称"
  426. return
  427. }
  428. if item.ActivityTime == "" {
  429. br.Msg = "请填写活动时间"
  430. return
  431. }
  432. //过滤标题中的符号,同步进门财经的时候使用
  433. newActivityName := item.ActivityName
  434. newActivityName = strings.Replace(newActivityName, "【", "", -1)
  435. newActivityName = strings.Replace(newActivityName, "】", "", -1)
  436. newActivityName = strings.Replace(newActivityName, "-", "", -1)
  437. newActivityName = strings.Replace(newActivityName, "—", "", -1)
  438. newActivityName = strings.Replace(newActivityName, " ", "", -1)
  439. newActivityName = strings.Replace(newActivityName, ":", "", -1)
  440. item.ActivityNameTask = newActivityName
  441. if !checkYidong {
  442. if activityTypeId == 1 {
  443. if item.Expert == "" {
  444. br.Msg = "请填写专家信息"
  445. return
  446. }
  447. if item.Host == "" {
  448. br.Msg = "请填写主持人信息"
  449. return
  450. }
  451. }
  452. if activityTypeId == 2 {
  453. if item.Speaker == "" {
  454. br.Msg = "请填写主讲人信息"
  455. return
  456. }
  457. }
  458. if activityTypeId == 3 {
  459. if item.DistinguishedGuest == "" {
  460. br.Msg = "请填写嘉宾信息"
  461. return
  462. }
  463. if item.Host == "" {
  464. br.Msg = "请填写主持人信息"
  465. return
  466. }
  467. }
  468. if activityTypeId == 4 {
  469. if item.DistinguishedGuest == "" {
  470. br.Msg = "请填写嘉宾信息"
  471. return
  472. }
  473. if item.Host == "" {
  474. br.Msg = "请填写主持人信息"
  475. return
  476. }
  477. if req.LimitPeopleNum == 0 {
  478. br.Msg = "请填写参会限制人数"
  479. return
  480. }
  481. }
  482. if activityTypeId == 5 {
  483. if item.Expert == "" {
  484. br.Msg = "请填写专家信息"
  485. return
  486. }
  487. if req.LimitPeopleNum == 0 {
  488. br.Msg = "请填写参会限制人数"
  489. return
  490. }
  491. }
  492. if activityTypeId == 6 {
  493. if item.Speaker == "" {
  494. br.Msg = "请填写主讲人信息"
  495. return
  496. }
  497. if req.LimitPeopleNum == 0 {
  498. br.Msg = "请填写参会限制人数"
  499. return
  500. }
  501. }
  502. }
  503. if req.LimitPeopleNum > 0 {
  504. item.IsLimitPeople = 1
  505. }
  506. if req.DoType == 1 {
  507. item.PublishStatus = 1
  508. }
  509. //当临时标的不为空的时候,标签为临时标的,否则为所选产业跟标的的组合
  510. if temporaryLabel != "" {
  511. item.Label = temporaryLabel
  512. } else {
  513. var labelNewStr string
  514. industrialNames = industryAndSubjectNameItems[k].IndustryNames
  515. industrialSubjectNames = industryAndSubjectNameItems[k].SubjectNames
  516. if industrialNames == "" && industrialSubjectNames != "" {
  517. labelNewStr = industrialSubjectNames
  518. } else if industrialNames != "" && industrialSubjectNames != "" {
  519. labelNewStr = industrialNames + "-" + industrialSubjectNames
  520. } else if industrialNames != "" && industrialSubjectNames == "" {
  521. labelNewStr = industrialNames
  522. }
  523. item.Label = labelNewStr
  524. if len(labelList) == 1 {
  525. item.IsShowSubjectName = labelList[0].IsShowSubjectName
  526. } else {
  527. item.IsShowSubjectName = labelList[k].IsShowSubjectName
  528. }
  529. }
  530. if item.ActivityTypeId == 2 {
  531. if item.ReportLink == "" {
  532. if labelList[k].IndustrialSubjectIdS != "" {
  533. item.ReportLink, err = cygxService.ActivityReportLink(item, labelList[k].IndustrialSubjectIdS)
  534. if err != nil {
  535. br.Msg = "发布失败"
  536. br.ErrMsg = "发布失败自动获取报告链接失败,Err:" + err.Error()
  537. return
  538. }
  539. }
  540. } else {
  541. sliceArt := strings.Split(item.ReportLink, "/")
  542. if len(sliceArt) > 0 {
  543. articleId, err := strconv.Atoi(sliceArt[len(sliceArt)-1])
  544. if err != nil {
  545. br.Msg = "报告链接格式错误!"
  546. return
  547. }
  548. detailArt, err := cygx.GetArticleIdInfoByArticleId(articleId)
  549. if err != nil {
  550. br.Msg = "内容不存在"
  551. br.ErrMsg = "操作失败,Err:" + err.Error()
  552. return
  553. }
  554. //类型ID 医药(医享会:28 、药调研:301)、消费【渠道新声:32】、科技【科技前言:79】、智造【匠心智造:84】
  555. if detailArt.CategoryId != 28 && detailArt.CategoryId != 301 && detailArt.CategoryId != 32 && detailArt.CategoryId != 79 && detailArt.CategoryId != 84 {
  556. item.IsHideAppointment = 1
  557. }
  558. }
  559. }
  560. }
  561. items = append(items, item)
  562. var errAct error
  563. if req.ActivityId == 0 {
  564. } else {
  565. if len(slice) > 1 {
  566. br.Msg = "文本格式错误,请删除多余活动"
  567. return
  568. }
  569. item.ActivityId = req.ActivityId
  570. activityInfo, errInfo := cygx.GetAddActivityInfoById(req.ActivityId)
  571. if activityInfo == nil {
  572. br.Msg = "活动不存在"
  573. br.ErrMsg = "活动ID错误,ActivityId:" + strconv.Itoa(req.ActivityId)
  574. return
  575. }
  576. if errInfo != nil {
  577. br.Msg = "操作失败"
  578. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  579. return
  580. }
  581. if item.PublishStatus == 0 {
  582. item.PublishStatus = activityInfo.PublishStatus
  583. }
  584. if req.DoType == 1 {
  585. item.AdminId = AdminUser.AdminId
  586. item.AdminName = AdminUser.RealName
  587. item.PublishDate = time.Now()
  588. item.IsCancel = 0
  589. } else {
  590. item.AdminId = activityInfo.AdminId
  591. item.AdminName = activityInfo.AdminName
  592. item.PublishDate = utils.StrTimeToTime(activityInfo.PublishDate)
  593. }
  594. //音频
  595. itemVoice := new(cygx.CygxActivityVoice)
  596. //var itemVoiceList []*cygx.CygxActivityVoice
  597. if len(voiceList) > 0 {
  598. for _, vo := range voiceList {
  599. itemVoice.ActivityId = activityId
  600. itemVoice.VoiceName = vo.Name
  601. itemVoice.VoiceUrl = vo.Url
  602. itemVoice.VoicePlaySeconds = vo.PlaySeconds
  603. itemVoice.CreateTime = time.Now()
  604. }
  605. }
  606. //视频
  607. itemVideo := new(cygx.CygxActivityVideo)
  608. if videoDetail != nil {
  609. itemVideo.VideoName = videoDetail.VideoName
  610. itemVideo.ActivityId = activityId
  611. itemVideo.VideoDuration = videoDetail.VideoDuration
  612. itemVideo.VideoUrl = videoDetail.VideoUrl
  613. itemVideo.ModifyDate = time.Now().Format(utils.FormatDateTime)
  614. itemVideo.CreateTime = time.Now().Format(utils.FormatDateTime)
  615. }
  616. //删除原有的视频数据
  617. //if itemVideo.VideoUrl != "" {
  618. videoDetail, err := cygx.GetCygxActivityVideoReqDetail(activityId)
  619. if err != nil && err.Error() != utils.ErrNoRow() {
  620. br.Msg = "获取信息失败"
  621. br.ErrMsg = "GetCygxActivityVideoReqDetail,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  622. return
  623. }
  624. if videoDetail != nil {
  625. go cygxService.UpdateResourceData(videoDetail.VideoId, "activityvideo", "delete", time.Now().Format(utils.FormatDateTime))
  626. }
  627. //}
  628. //if itemVoice.VoiceUrl != "" {
  629. voiceReqList, err := cygx.GetCygxActivityVoiceReqList(activityId)
  630. if err != nil && err.Error() != utils.ErrNoRow() {
  631. br.Msg = "获取信息失败"
  632. br.ErrMsg = "GetCygxActivityVoiceReqList,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  633. return
  634. }
  635. if len(voiceReqList) > 0 {
  636. for _, voice := range voiceReqList {
  637. go cygxService.UpdateResourceData(voice.ActivityVoiceId, "activityvoice", "delete", time.Now().Format(utils.FormatDateTime))
  638. }
  639. }
  640. //}
  641. //如果活动信息有如下变更则做消息推送
  642. voiceIdNew, videoIdNew, err := cygx.EditActivity(item, activityInfo.PublishStatus, industrialActivityItemsList, subjectActivityItemsList, itemVoice, itemVideo, itemPointsSet)
  643. if err != nil {
  644. br.Msg = "操作失败"
  645. br.ErrMsg = "操作失败,Err:" + err.Error()
  646. return
  647. }
  648. //更新活动音频
  649. if int(voiceIdNew) > 0 {
  650. go cygxService.UpdateResourceData(int(voiceIdNew), "activityvoice", "add", activityInfo.ActivityTime)
  651. go elastic.AddComprehensiveActivityVoice(activityId) //更新ES中的活动音频内容
  652. }
  653. //更新活动视频
  654. if int(videoIdNew) > 0 {
  655. go cygxService.UpdateResourceData(int(videoIdNew), "activityvideo", "add", activityInfo.ActivityTime)
  656. go elastic.AddComprehensiveActivityVideo(activityId) //更新ES中的活动视频内容
  657. }
  658. errAct = err
  659. if activityInfo.PublishStatus == 1 && activityInfo.ActivityTimeText != item.ActivityTimeText {
  660. go services.SendWxMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.ActivityTimeText, item.ActivityTimeText, "timeType")
  661. }
  662. oldExpert, _ := cygx.GetReportContentTextSub(activityInfo.Expert)
  663. newExpert, _ := cygx.GetReportContentTextSub(item.Expert)
  664. if activityInfo.PublishStatus == 1 && oldExpert != newExpert {
  665. go services.SendWxMsgWithCygxActivityUpdateTime(req.ActivityId, oldExpert, newExpert, "expertType")
  666. }
  667. if activityInfo.PublishStatus == 1 && activityInfo.Address != item.Address {
  668. go services.SendWxMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.Address, item.Address, "addressType")
  669. }
  670. if activityInfo.PublishStatus == 1 && activityInfo.ParticipationCode != item.ParticipationCode {
  671. go services.SendWxMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.ParticipationCode, item.ParticipationCode, "participationCode")
  672. }
  673. if activityInfo.PublishStatus == 1 && activityInfo.Theme != item.Theme {
  674. go services.SendWxMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.Theme, item.Theme, "Theme")
  675. }
  676. //对于限制人数的活动,如果修改改了可见范围,对于新增的那一部分做新的推送
  677. if req.DoType == 0 && activityInfo.PublishStatus == 1 && activityInfo.ActiveState == 1 && activityInfo.LimitPeopleNum != "0" {
  678. if activityInfo.CustomerTypeIds != req.CustomerTypeIds || activityInfo.Scale != req.Scale || activityInfo.IsMakerShow != req.IsMakerShow || activityInfo.VisibleRange != req.VisibleRange {
  679. go cygxService.DoActivityOnenIdWxTemplateMsg(activityId)
  680. }
  681. }
  682. //已结束或者进行中的活动修改时间后,修改活动状态以及重新发送邮件附件
  683. if activeState != 0 && activeState != 1 {
  684. resultTime := utils.StrTimeToTime(item.ActivityTime) //时间字符串格式转时间格式
  685. if time.Now().Before(resultTime) {
  686. err := cygx.EditActivityStatus(req.ActivityId)
  687. if err != nil {
  688. br.Msg = "发布失败"
  689. br.ErrMsg = "发布失败,Err:" + err.Error()
  690. return
  691. }
  692. }
  693. }
  694. //修改活动人数限制之后,对于因为人数已满而失败的用户,推送模板消息
  695. if activityInfo.PublishStatus == 1 && activityInfo.IsLimitPeople != 0 && activityInfo.LimitPeopleNum != strconv.Itoa(req.LimitPeopleNum) {
  696. go cygxService.SendWxMsgWithCygxActivityUpdateLimitPeople(req.ActivityId)
  697. }
  698. go cygxService.YiDongSaveRoadshowDetail(activityId)
  699. //如果活动名称有变更就生成新的签到码
  700. if activityInfo.ActivityName != item.ActivityName || activityInfo.SigninImg == "" {
  701. go cygxService.MakeActivitySigninImg(req.ActivityId)
  702. }
  703. if activityInfo.PublishStatus == 1 {
  704. go cygxService.UpdateYanXuanActivityPointsBillOldComapny(activityInfo, AdminUser.AdminId, itemPointsSet, itemPointsSetOld) //活动发布以及取消发布处理研选扣点,如果活动之前是发布的状态,那么就对公司的扣点进行更新(涉及到新老公司的扣点返点,不放在Redis统一处理了)
  705. go elastic.AddComprehensiveActivity(item.ActivityId) // Es添加活动
  706. }
  707. //如果活动之前是未发布的状态,现在又发布了那么就对公司的扣点进行更新
  708. //if req.DoType == 1 && activityInfo.PublishStatus == 0 {
  709. // go cygxService.YanXuanActivityPointsBillActivityPublishAndCancel(activityId, AdminUser.AdminId, 1) //活动发布以及取消发布处理研选扣点
  710. //}
  711. }
  712. if errAct != nil {
  713. br.Msg = "发布失败"
  714. br.ErrMsg = "发布失败,Err:" + errAct.Error()
  715. return
  716. }
  717. //go cygxService.YanXuanActivityPointsBillActivityEdit(activityId, AdminUser.AdminId) //活动编辑处理研选扣点
  718. }
  719. }
  720. if req.ActivityId == 0 {
  721. _, activityIdArr, err := cygx.AddActivity(items, industrialActivityItemsList, subjectActivityItemsList, itemPointsSet)
  722. if err != nil {
  723. br.Msg = "发布失败"
  724. br.ErrMsg = "发布失败,Err:" + err.Error()
  725. return
  726. }
  727. //如果是添加多条活动那么就推送多次
  728. for _, v := range activityIdArr {
  729. if req.DoType == 1 {
  730. go cygxService.DoActivityOnenIdWxTemplateMsg(v)
  731. go cygxService.UpdateResourceData(v, "activity", "add", time.Now().Format(utils.FormatDateTime))
  732. go cygxService.YiDongSaveRoadshowDetail(v)
  733. go cygxService.YanXuanActivityPointsBillActivityPublishAndCancel(v, AdminUser.AdminId, 1) //活动发布以及取消发布处理研选扣点
  734. go elastic.AddComprehensiveActivity(v) // Es添加活动
  735. }
  736. go cygxService.MakeActivitySigninImg(v)
  737. }
  738. } else {
  739. if req.DoType == 1 {
  740. go cygxService.DoActivityOnenIdWxTemplateMsg(req.ActivityId)
  741. go cygxService.UpdateResourceData(req.ActivityId, "activity", "add", time.Now().Format(utils.FormatDateTime))
  742. go cygxService.YanXuanActivityPointsBillActivityPublishAndCancel(activityId, AdminUser.AdminId, 1) //活动发布以及取消发布处理研选扣点
  743. }
  744. }
  745. // 查研观向7.4-更新产业布局时间
  746. if len(industryIds) > 0 {
  747. go cygxService.UpdateIndustryLayoutTime(industryIds, false)
  748. }
  749. //添加操作日志记录
  750. br.Ret = 200
  751. br.Success = true
  752. br.Msg = "操作成功"
  753. br.IsAddLog = true
  754. }
  755. // @Title 活动列表
  756. // @Description 获取活动列表接口
  757. // @Param PageSize query int true "每页数据条数"
  758. // @Param CurrentIndex query int true "当前页页码,从1开始"
  759. // @Param PublishStatus query int false "发布状态 ,0未发布,1已发布,3已取消,传2查询所有"
  760. // @Param ChartPermissionId query string false "行业id"
  761. // @Param ActivityTypeId query string false "活动类型id"
  762. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  763. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  764. // @Param PublishStartDate query string false "发布开始时间 ,列如2021-03-06 "
  765. // @Param PublishEndDate query string false "发布结束时间,列如2021-03-06 "
  766. // @Param KeyWord query string false "搜索关键词"
  767. // @Param ActiveState query string false "活动进行状态 未开始:NotStarted、进行中HaveInHand、已结束Complete"
  768. // @Success 200 {object} cygx.GetCygxActivityListRep
  769. // @router /activity/list [get]
  770. func (this *ActivityCoAntroller) ActivityList() {
  771. br := new(models.BaseResponse).Init()
  772. defer func() {
  773. this.Data["json"] = br
  774. this.ServeJSON()
  775. }()
  776. sysUser := this.SysUser
  777. if sysUser == nil {
  778. br.Msg = "请登录"
  779. br.ErrMsg = "请登录,SysUser Is Empty"
  780. return
  781. }
  782. pageSize, _ := this.GetInt("PageSize")
  783. currentIndex, _ := this.GetInt("CurrentIndex")
  784. publishStatus, _ := this.GetInt("PublishStatus")
  785. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  786. ActivityTypeId, _ := this.GetInt("ActivityTypeId")
  787. startDate := this.GetString("StartDate")
  788. endDate := this.GetString("EndDate")
  789. publishStartDate := this.GetString("PublishStartDate")
  790. publishEndDate := this.GetString("PublishEndDate")
  791. keyWord := this.GetString("KeyWord")
  792. activeState := this.GetString("ActiveState")
  793. activityLabel := this.GetString("ActivityLabel") // 查研观向7.4-活动标签
  794. if activeState != "HaveInHand" && activeState != "Complete" {
  795. activeState = "NotStarted"
  796. }
  797. var startSize int
  798. if pageSize <= 0 {
  799. pageSize = utils.PageSize20
  800. }
  801. if currentIndex <= 0 {
  802. currentIndex = 1
  803. }
  804. startSize = utils.StartIndex(currentIndex, pageSize)
  805. var condition string
  806. var pars []interface{}
  807. //condition += ` FROM cygx_activity as art WHERE 1= 1 `
  808. if keyWord != "" {
  809. condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' ) `
  810. }
  811. //行业名称
  812. if chartPermissionId > 0 {
  813. condition += ` AND art.chart_permission_id = '` + strconv.Itoa(chartPermissionId) + `'`
  814. }
  815. if startDate != "" {
  816. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  817. }
  818. if endDate != "" {
  819. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  820. }
  821. //发布时间状态的筛选
  822. if publishStartDate != "" {
  823. condition += ` AND art.publish_date >= ` + "'" + publishStartDate + " 00:00:00'"
  824. publishStatus = 1
  825. }
  826. if publishEndDate != "" {
  827. condition += ` AND art.publish_date <= ` + "'" + publishEndDate + " 23:59:59'"
  828. publishStatus = 1
  829. }
  830. if publishStatus == 0 {
  831. condition += ` AND art.publish_status = 0 AND art.is_cancel = 0 `
  832. } else if publishStatus == 1 {
  833. condition += ` AND art.publish_status = 1 `
  834. } else if publishStatus == 3 {
  835. condition += ` AND art.publish_status = 0 AND art.is_cancel = 1 `
  836. }
  837. if ActivityTypeId > 0 {
  838. condition += ` AND art.activity_type_id = '` + strconv.Itoa(ActivityTypeId) + `'`
  839. }
  840. if activeState == "NotStarted" {
  841. condition += ` AND art.active_state =1 `
  842. } else if activeState == "HaveInHand" {
  843. condition += ` AND art.active_state =2 `
  844. } else {
  845. condition += ` AND art.active_state =3 `
  846. }
  847. // 活动标签
  848. if activityLabel != "" {
  849. keywords := "%" + activityLabel + "%"
  850. condition += ` AND art.label LIKE ?`
  851. pars = append(pars, keywords)
  852. }
  853. //C类电话会,仅本组销售、部门管理员、admin、权益研究员账号能看到。
  854. if sysUser.Role != "admin" {
  855. conditionPermission, err := cygxService.GetAdminActivityPermission(sysUser, condition)
  856. if err != nil {
  857. br.Msg = "获取失败"
  858. br.ErrMsg = "获取失败,GetAdminActivityPermission Err:" + err.Error()
  859. return
  860. }
  861. condition += ` AND art.visible_range != 1 `
  862. condition += conditionPermission
  863. pars = append(pars, pars)
  864. }
  865. //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
  866. total, err := cygx.GetActivityCount(condition, pars)
  867. if err != nil {
  868. br.Msg = "获取失败"
  869. br.ErrMsg = "获取失败,Err:" + err.Error()
  870. return
  871. }
  872. if activeState == "NotStarted" {
  873. condition += ` ORDER BY art.activity_time ASC `
  874. } else {
  875. condition += ` ORDER BY art.activity_time DESC `
  876. }
  877. list, errList := cygx.GetActivityListAll(condition, pars, startSize, pageSize)
  878. if errList != nil {
  879. br.Msg = "获取失败"
  880. br.ErrMsg = "获取失败,Err:" + errList.Error()
  881. return
  882. }
  883. var activityIds string
  884. for k, v := range list {
  885. if v.ChartPermissionNames != "" {
  886. list[k].ChartPermissionName = v.ChartPermissionNames
  887. }
  888. if v.IsCancel == 1 {
  889. v.PublishStatus = 3
  890. }
  891. activityIds += strconv.Itoa(v.ActivityId) + ","
  892. }
  893. activityIds = strings.TrimRight(activityIds, ",")
  894. mapIndustrial := make(map[int]string)
  895. mapSubject := make(map[string]string)
  896. mapUpload := make(map[int]bool)
  897. if activityIds != "" {
  898. industrialList, err := cygx.GetIndustrialActivityGroupListByactivityIds(activityIds)
  899. if err != nil {
  900. br.Msg = "获取失败"
  901. br.ErrMsg = "获取失败,GetIndustrialActivityGroupListByactivityIds Err:" + err.Error()
  902. return
  903. }
  904. subjectList, err := cygx.GetSubjectActivityGroupListByactivityIds(activityIds)
  905. if err != nil {
  906. br.Msg = "获取失败"
  907. br.ErrMsg = "获取失败,GetSubjectActivityGroupListByactivityIds Err:" + err.Error()
  908. return
  909. }
  910. //合并活动对应的多个标的
  911. for _, v := range subjectList {
  912. mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
  913. }
  914. //活动对应的产业
  915. for _, v := range industrialList {
  916. var labelSubject string
  917. labelSubject = mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)]
  918. if labelSubject != "" {
  919. mapIndustrial[v.ActivityId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + ","
  920. } else {
  921. mapIndustrial[v.ActivityId] += v.IndustryName + ","
  922. }
  923. }
  924. var conditionupload string
  925. var pars []interface{}
  926. conditionupload = " AND activity_id IN (" + activityIds + ") "
  927. listVideo, err := cygx.GetActivityVideoList(conditionupload, pars)
  928. if err != nil && err.Error() != utils.ErrNoRow() {
  929. br.Msg = "获取失败"
  930. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  931. return
  932. }
  933. if len(listVideo) > 0 {
  934. for _, v := range listVideo {
  935. mapUpload[v.ActivityId] = true
  936. }
  937. }
  938. listVoice, err := cygx.GetActivityVoiceList(conditionupload, pars)
  939. if err != nil && err.Error() != utils.ErrNoRow() {
  940. br.Msg = "获取失败"
  941. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  942. return
  943. }
  944. if len(listVoice) > 0 {
  945. for _, v := range listVoice {
  946. mapUpload[v.ActivityId] = true
  947. }
  948. }
  949. }
  950. for k, v := range list {
  951. if mapIndustrial[v.ActivityId] != "" && v.TemporaryLabel == "" {
  952. list[k].Label = strings.TrimRight(mapIndustrial[v.ActivityId], ",")
  953. }
  954. if v.YidongActivityId != "" {
  955. list[k].ActivityTypeName += utils.YI_DONG_NAME
  956. }
  957. if v.IsYidongConduct == 1 {
  958. list[k].ActivityTypeName += utils.YI_DONG_NAME_TWO
  959. }
  960. list[k].IsUpload = mapUpload[v.ActivityId]
  961. //是否展示签到码
  962. if (v.ActivityTypeId == 5 || v.ActivityTypeId == 6) && v.SigninImg != "" && v.ActiveState == 1 && v.PublishStatus == 1 {
  963. list[k].IsShowSigninButton = true
  964. }
  965. }
  966. if len(list) == 0 {
  967. list = make([]*cygx.CygxActivityList, 0)
  968. }
  969. page := paging.GetPaging(currentIndex, pageSize, total)
  970. resp := new(cygx.GetCygxActivityListRep)
  971. resp.List = list
  972. resp.Paging = page
  973. br.Ret = 200
  974. br.Success = true
  975. br.Msg = "获取成功"
  976. br.Data = resp
  977. }
  978. // @Title 活动详情
  979. // @Description 获取活动详情接口
  980. // @Param ActivityId query int true "活动ID"
  981. // @Success Ret=200 {object} cygx.ActivityDetail
  982. // @router /activity/detail [get]
  983. func (this *ActivityCoAntroller) Detail() {
  984. br := new(models.BaseResponse).Init()
  985. defer func() {
  986. this.Data["json"] = br
  987. this.ServeJSON()
  988. }()
  989. AdminUser := this.SysUser
  990. if AdminUser == nil {
  991. br.Msg = "请登录"
  992. br.ErrMsg = "请登录,用户信息为空"
  993. br.Ret = 408
  994. return
  995. }
  996. activityId, _ := this.GetInt("ActivityId")
  997. if activityId < 1 {
  998. br.Msg = "请输入活动ID"
  999. return
  1000. }
  1001. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  1002. if err != nil {
  1003. br.Msg = "活动不存在"
  1004. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1005. return
  1006. }
  1007. detail, errDetail := cygx.GetActivityTypeDetailById(activityInfo.ActivityTypeId)
  1008. if errDetail != nil {
  1009. br.Msg = "获取信息失败"
  1010. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  1011. return
  1012. }
  1013. industrialList, err := cygx.GetIndustrialActivityGroupManagementList(activityId, 1)
  1014. if err != nil && err.Error() != utils.ErrNoRow() {
  1015. br.Msg = "获取信息失败"
  1016. br.ErrMsg = "获取活动关联的产业列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1017. return
  1018. }
  1019. var subjectList []*cygx.SubjectActivityGroupManagementRep
  1020. if len(industrialList) > 0 {
  1021. subjectList, err = cygx.GetSubjectActivityGroupManagementList(activityId, 1)
  1022. if err != nil && err.Error() != utils.ErrNoRow() {
  1023. br.Msg = "获取信息失败"
  1024. br.ErrMsg = "获取活动关联的标的列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1025. return
  1026. }
  1027. }
  1028. VoiceReqList, err := cygx.GetCygxActivityVoiceReqList(activityId)
  1029. if err != nil && err.Error() != utils.ErrNoRow() {
  1030. br.Msg = "获取信息失败"
  1031. br.ErrMsg = "GetCygxActivityVoiceReqList,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1032. return
  1033. }
  1034. if len(VoiceReqList) == 0 {
  1035. VoiceReqList = make([]*cygx.CygxActivityVoiceReq, 0)
  1036. }
  1037. VideoDetail, err := cygx.GetCygxActivityVideoReqDetail(activityId)
  1038. if err != nil && err.Error() != utils.ErrNoRow() {
  1039. br.Msg = "获取信息失败"
  1040. br.ErrMsg = "GetCygxActivityVideoReqDetail,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1041. return
  1042. }
  1043. if activityInfo.CustomerTypeIds != "" {
  1044. customerTypeIdslist := strings.Split(activityInfo.CustomerTypeIds, ",")
  1045. var permissionValueStr string
  1046. for _, v := range customerTypeIdslist {
  1047. permissionValueStr += "'" + v + "',"
  1048. }
  1049. permissionValueStr = strings.TrimRight(permissionValueStr, ",")
  1050. condition := ` AND permission_value IN (` + permissionValueStr + `)`
  1051. listValue, err := cygx.GetActivityCcustomerTypeList(condition)
  1052. if err != nil {
  1053. br.Msg = "活动可见套餐类型错误,请核实"
  1054. br.ErrMsg = "GetActivityCcustomerTypeList,Err:" + err.Error()
  1055. return
  1056. }
  1057. activityInfo.CustomerTypeIds = ""
  1058. for _, v := range listValue {
  1059. activityInfo.CustomerTypeIds += strconv.Itoa(v.CustomerTypeId) + ","
  1060. }
  1061. activityInfo.CustomerTypeIds = strings.TrimRight(activityInfo.CustomerTypeIds, ",")
  1062. }
  1063. if activityInfo.SiginupDeadline == utils.EmptyDateTimeStr {
  1064. activityInfo.SiginupDeadline = ""
  1065. }
  1066. PointsSetDetail, err := cygx.GetCygxActivityPointsSetDetail(activityId)
  1067. if err != nil && err.Error() != utils.ErrNoRow() {
  1068. br.Msg = "获取信息失败"
  1069. br.ErrMsg = "GetCygxActivityPointsSetDetail,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1070. return
  1071. }
  1072. if PointsSetDetail != nil {
  1073. if PointsSetDetail.CancelDeadlineType == "0" {
  1074. PointsSetDetail.CancelDeadlineType = ""
  1075. }
  1076. activityInfo.PointsSet = PointsSetDetail
  1077. } else {
  1078. activityInfo.PointsSet = new(cygx.CygxActivityPointsSetRsq)
  1079. }
  1080. //可见范围 1,仅本组可见 、2,全部客户可见 没设置本组可见的,强制设置为全部客户可见
  1081. if activityInfo.VisibleRange == 0 {
  1082. activityInfo.VisibleRange = 2
  1083. }
  1084. //activityInfo.CancelDeadlineType = cygxService.ActivityCancelDeadlineType(activityInfo) //处理活动取消报名截止时间类型展示
  1085. activityInfo.VoiceList = VoiceReqList
  1086. activityInfo.VideoDetail = VideoDetail
  1087. activityInfo.ShowType = detail.ShowType
  1088. activityInfo.ListIndustrial = industrialList
  1089. activityInfo.ListSubject = subjectList
  1090. br.Ret = 200
  1091. br.Success = true
  1092. br.Msg = "获取成功"
  1093. br.Data = activityInfo
  1094. }
  1095. // @Title 活动的发布与取消发布
  1096. // @Description 活动的发布与取消发布接口
  1097. // @Param request body cygx.ActivityIdRep true "type json string"
  1098. // @Success 200 操作成功
  1099. // @router /activity/PublishAndCancel [post]
  1100. func (this *ActivityCoAntroller) PublishAndCancel() {
  1101. br := new(models.BaseResponse).Init()
  1102. defer func() {
  1103. this.Data["json"] = br
  1104. this.ServeJSON()
  1105. }()
  1106. AdminUser := this.SysUser
  1107. if AdminUser == nil {
  1108. br.Msg = "请登录"
  1109. br.ErrMsg = "请登录,用户信息为空"
  1110. br.Ret = 408
  1111. return
  1112. }
  1113. var req cygx.ActivityIdRep
  1114. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1115. if err != nil {
  1116. br.Msg = "参数解析异常!"
  1117. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1118. return
  1119. }
  1120. activityId := req.ActivityId
  1121. item := new(cygx.CygxActivity)
  1122. activityInfo, errInfo := cygx.GetAddActivityInfoById(activityId)
  1123. if activityInfo == nil {
  1124. br.Msg = "操作失败"
  1125. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1126. return
  1127. }
  1128. if errInfo != nil {
  1129. br.Msg = "操作失败"
  1130. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1131. return
  1132. }
  1133. //校验活动后台管理员、销售是否有修改权限
  1134. havePower, popupMsg, err := cygxService.CheckActivityUpdatePower(AdminUser.AdminId, activityInfo)
  1135. if err != nil {
  1136. br.Msg = "获取管理员身份信息失败"
  1137. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  1138. return
  1139. }
  1140. if !havePower {
  1141. br.Msg = popupMsg
  1142. return
  1143. }
  1144. if activityInfo.ActiveState != 1 {
  1145. br.Msg = "活动已经开始,无法修改"
  1146. return
  1147. }
  1148. if activityInfo.PublishStatus == 0 {
  1149. item.PublishStatus = 1
  1150. item.IsCancel = 0
  1151. go cygxService.DoActivityOnenIdWxTemplateMsg(activityId)
  1152. go cygxService.UpdateResourceData(activityId, "activity", "add", time.Now().Format(utils.FormatDateTime))
  1153. } else {
  1154. item.PublishStatus = 0
  1155. item.IsCancel = 1
  1156. }
  1157. if activityInfo.PublishStatus == 1 {
  1158. go services.SendWxMsgWithCygxActivity(req.ActivityId)
  1159. //同步活动到最新数据表
  1160. go cygxService.UpdateResourceData(req.ActivityId, "activity", "delete", "")
  1161. }
  1162. item.ActivityId = req.ActivityId
  1163. if item.PublishStatus == 1 {
  1164. item.AdminId = AdminUser.AdminId
  1165. item.AdminName = AdminUser.RealName
  1166. item.PublishDate = time.Now()
  1167. } else {
  1168. item.AdminId = activityInfo.AdminId
  1169. item.AdminName = activityInfo.AdminName
  1170. item.PublishDate = utils.StrTimeToTime(activityInfo.PublishDate)
  1171. }
  1172. err = cygx.ActivityPublishAndCancel(item)
  1173. if err != nil {
  1174. br.Msg = "操作失败"
  1175. br.ErrMsg = "操作失败,Err:" + err.Error()
  1176. return
  1177. }
  1178. if item.PublishStatus == 1 {
  1179. //易董那边重新发布,重新建会
  1180. go cygxService.YiDongSaveRoadshowDetail(activityId)
  1181. } else {
  1182. //易董那边取消发布并删除
  1183. go cygxService.YiDongUpdateActivityPublish(activityId)
  1184. }
  1185. go cygxService.YanXuanActivityPointsBillActivityPublishAndCancel(activityId, AdminUser.AdminId, item.PublishStatus) //活动发布以及取消发布处理研选扣点
  1186. go elastic.AddComprehensiveActivity(activityId) // Es添加活动
  1187. br.Ret = 200
  1188. br.Success = true
  1189. br.Msg = "操作成功"
  1190. br.IsAddLog = true //添加操作日志记录
  1191. }
  1192. // @Title 删除活动
  1193. // @Description 删除活动接口
  1194. // @Param request body cygx.ActivityIdRep true "type json string"
  1195. // @Success Ret=200
  1196. // @router /activity/delete [post]
  1197. func (this *ActivityCoAntroller) Delete() {
  1198. br := new(models.BaseResponse).Init()
  1199. defer func() {
  1200. this.Data["json"] = br
  1201. this.ServeJSON()
  1202. }()
  1203. AdminUser := this.SysUser
  1204. if AdminUser == nil {
  1205. br.Msg = "请登录"
  1206. br.ErrMsg = "请登录,SysUser Is Empty"
  1207. br.Ret = 408
  1208. return
  1209. }
  1210. var req cygx.ActivityIdRep
  1211. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1212. if err != nil {
  1213. br.Msg = "参数解析异常!"
  1214. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1215. return
  1216. }
  1217. activityId := req.ActivityId
  1218. if activityId < 1 {
  1219. br.Msg = "请输入活动ID"
  1220. return
  1221. }
  1222. activityInfo, errInfo := cygx.GetAddActivityInfoById(activityId)
  1223. if activityInfo == nil {
  1224. br.Msg = "操作失败"
  1225. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1226. return
  1227. }
  1228. if errInfo != nil {
  1229. br.Msg = "操作失败"
  1230. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1231. return
  1232. }
  1233. //校验活动后台管理员、销售是否有修改权限
  1234. havePower, popupMsg, err := cygxService.CheckActivityUpdatePower(AdminUser.AdminId, activityInfo)
  1235. if err != nil {
  1236. br.Msg = "获取管理员身份信息失败"
  1237. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  1238. return
  1239. }
  1240. if !havePower {
  1241. br.Msg = popupMsg
  1242. return
  1243. }
  1244. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1245. res := time.Now().Before(resultTime)
  1246. if res == false {
  1247. br.Msg = "活动已结束禁止删除!"
  1248. br.ErrMsg = "活动已结束禁止删除!"
  1249. return
  1250. }
  1251. err = cygx.DeleteActivity(activityId)
  1252. if err != nil {
  1253. br.Msg = "删除信息失败"
  1254. br.ErrMsg = "删除信息失败,Err:" + err.Error()
  1255. return
  1256. }
  1257. //添加操作日志记录
  1258. br.Ret = 200
  1259. br.Success = true
  1260. br.Msg = "已删除"
  1261. br.IsAddLog = true
  1262. }
  1263. // @Title 获取活动行业分类
  1264. // @Description 获取活动行业分类接口
  1265. // @Success 200 {object} cygx.ChartPermissionRepMoreList
  1266. // @router /activity/chartPermission/list [get]
  1267. func (this *ActivityCoAntroller) ChartPermissionListAct() {
  1268. br := new(models.BaseResponse).Init()
  1269. defer func() {
  1270. this.Data["json"] = br
  1271. this.ServeJSON()
  1272. }()
  1273. AdminUser := this.SysUser
  1274. if AdminUser == nil {
  1275. br.Msg = "请登录"
  1276. br.ErrMsg = "请登录,用户信息为空"
  1277. br.Ret = 408
  1278. return
  1279. }
  1280. //数据库新加行业分类,与之前的项目权限部分冲突太多,故采用自定义而不去数据库查找
  1281. resp := new(cygx.ChartPermissionRepMoreList)
  1282. // 查研观向7.4-策略后面新增一个宏观
  1283. resp.List = cygxService.GetActChartPermissionList()
  1284. br.Ret = 200
  1285. br.Success = true
  1286. br.Msg = "获取成功"
  1287. br.Data = resp
  1288. }
  1289. // @Title 扣点设置
  1290. // @Description 扣点设置接口
  1291. // @Success 200 {object} cygx.CygxActivityPointsSetConfigListResp
  1292. // @router /activity/pointsSet [get]
  1293. func (this *ActivityCoAntroller) PointsSet() {
  1294. br := new(models.BaseResponse).Init()
  1295. defer func() {
  1296. this.Data["json"] = br
  1297. this.ServeJSON()
  1298. }()
  1299. AdminUser := this.SysUser
  1300. if AdminUser == nil {
  1301. br.Msg = "请登录"
  1302. br.ErrMsg = "请登录,用户信息为空"
  1303. br.Ret = 408
  1304. return
  1305. }
  1306. conf, err := cygx.GetCygxConfigDetailByCode("activity_points_set")
  1307. if err != nil {
  1308. br.Msg = "获取数据失败"
  1309. br.ErrMsg = "买方研选产品介绍信息失败,Err:" + err.Error()
  1310. return
  1311. }
  1312. if conf.ConfigValue == "" {
  1313. br.Msg = "获取失败"
  1314. br.ErrMsg = "买方研选产品介绍信息失败"
  1315. return
  1316. }
  1317. list := new(*cygx.CygxActivityPointsSetConfigListResp)
  1318. if err = json.Unmarshal([]byte(conf.ConfigValue), &list); err != nil {
  1319. br.Msg = "获取失败"
  1320. br.ErrMsg = "买方研选产品介绍信配置值解析失败, Err: " + err.Error()
  1321. return
  1322. }
  1323. br.Ret = 200
  1324. br.Success = true
  1325. br.Msg = "获取成功"
  1326. br.Data = list
  1327. }
  1328. // @Title 权益办会机构搜索
  1329. // @Description 权益办会机构搜索
  1330. // @Param KeyWord query string false "搜索关键词"
  1331. // @Success 200 {object} cygx.ChartPermissionRepMoreList
  1332. // @router /activity/companySearch [get]
  1333. func (this *ActivityCoAntroller) CompanySearch() {
  1334. br := new(models.BaseResponse).Init()
  1335. defer func() {
  1336. this.Data["json"] = br
  1337. this.ServeJSON()
  1338. }()
  1339. AdminUser := this.SysUser
  1340. if AdminUser == nil {
  1341. br.Msg = "请登录"
  1342. br.ErrMsg = "请登录,用户信息为空"
  1343. br.Ret = 408
  1344. return
  1345. }
  1346. keyWord := this.GetString("KeyWord")
  1347. if keyWord == "" {
  1348. br.ErrMsg = "请输入搜索关键词"
  1349. return
  1350. }
  1351. resp := new(cygx.CygxActivitySearcCompanyListResp)
  1352. list, err := cygx.GetCygxActivitySearcCompanyList(keyWord)
  1353. if err != nil {
  1354. br.Msg = "操作失败"
  1355. br.ErrMsg = "操作失败,Err:" + err.Error()
  1356. return
  1357. }
  1358. if len(list) == 0 {
  1359. list = make([]*cygx.CygxActivitySearcCompanyResp, 0)
  1360. }
  1361. resp.List = list
  1362. br.Ret = 200
  1363. br.Success = true
  1364. br.Msg = "获取成功"
  1365. br.Data = resp
  1366. }
  1367. // @Title 报名截止时间设置
  1368. // @Description 报名截止时间设置接口
  1369. // @Success Ret=200
  1370. // @router /activity/deadlineSet [get]
  1371. func (this *ActivityCoAntroller) DeadlineSet() {
  1372. br := new(models.BaseResponse).Init()
  1373. defer func() {
  1374. this.Data["json"] = br
  1375. this.ServeJSON()
  1376. }()
  1377. AdminUser := this.SysUser
  1378. if AdminUser == nil {
  1379. br.Msg = "请登录"
  1380. br.ErrMsg = "请登录,SysUser Is Empty"
  1381. return
  1382. }
  1383. list := make([]cygx.SendGroupStr, 0)
  1384. list = append(list, cygx.SendGroupStr{
  1385. Id: "1",
  1386. Name: "同报名截止时间",
  1387. })
  1388. list = append(list, cygx.SendGroupStr{
  1389. Id: "2",
  1390. Name: "活动开始前24小时",
  1391. })
  1392. list = append(list, cygx.SendGroupStr{
  1393. Id: "3",
  1394. Name: "活动开始前48小时",
  1395. })
  1396. br.Ret = 200
  1397. br.Success = true
  1398. br.Data = list
  1399. }