activity.go 51 KB

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