activity.go 48 KB

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