activity.go 47 KB

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