activity.go 48 KB

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