activity.go 51 KB

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