activity.go 46 KB

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