activity.go 52 KB

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