activity.go 47 KB

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