activity.go 52 KB

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