activity.go 48 KB

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