activity.go 47 KB

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