activity.go 48 KB

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