activity.go 51 KB

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