activity_special.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. "hongze/hz_crm_api/models/system"
  10. "hongze/hz_crm_api/services"
  11. cygxService "hongze/hz_crm_api/services/cygx"
  12. "hongze/hz_crm_api/services/elastic"
  13. "hongze/hz_crm_api/utils"
  14. "os"
  15. "path/filepath"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // 专项调研
  21. type ActivitySpecialCoAntroller struct {
  22. controllers.BaseAuthController
  23. }
  24. // @Title 专项调研内容的保存与发布
  25. // @Description 专项调研内容的保存与发布接口
  26. // @Param request body cygx.ActivitySpecialRep true "type json string"
  27. // @Success 200 操作成功
  28. // @router /special/PreserveAndPublish [post]
  29. func (this *ActivitySpecialCoAntroller) PreserveAndPublish() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. AdminUser := this.SysUser
  36. if AdminUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,用户信息为空"
  39. br.Ret = 408
  40. return
  41. }
  42. var req cygx.ActivitySpecialRep
  43. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  44. if err != nil {
  45. br.Msg = "参数解析异常!"
  46. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  47. return
  48. }
  49. activityId := req.ActivityId
  50. industrialManagementIdS := req.IndustrialManagementIdS
  51. industrialSubjectIdS := req.IndustrialSubjectIdS
  52. temporaryLabel := req.TemporaryLabel
  53. temporarySubject := req.TemporarySubject
  54. permissionName := req.PermissionName
  55. specialType := req.SpecialType
  56. city := req.City
  57. isShowSubjectName := req.IsShowSubjectName
  58. customerTypeIds := req.CustomerTypeIds
  59. if customerTypeIds != "" {
  60. condition := ` AND customer_type_id IN (` + customerTypeIds + `)`
  61. listValue, err := cygx.GetActivityCcustomerTypeList(condition)
  62. if err != nil {
  63. br.Msg = "活动可见套餐类型错误,请核实"
  64. return
  65. }
  66. req.CustomerTypeIds = ""
  67. for _, v := range listValue {
  68. req.CustomerTypeIds += v.PermissionValue + ","
  69. }
  70. req.CustomerTypeIds = strings.TrimRight(req.CustomerTypeIds, ",")
  71. }
  72. item := new(cygx.CygxActivitySpecial)
  73. var industrialActivityItems []*cygx.CygxIndustrialActivityGroupManagement
  74. var subjectActivityItems []*cygx.CygxIndustrialActivityGroupSubject
  75. var industrialNames string
  76. var industrialSubjectNames string
  77. if specialType != 1 && specialType != 2 {
  78. br.Msg = "请选择调研形式!"
  79. return
  80. }
  81. if specialType == 2 && city == "" {
  82. br.Msg = "请输入调研城市!"
  83. return
  84. }
  85. //如果临时标签是空的话,就去关联产业跟标的
  86. if temporaryLabel == "" {
  87. if industrialManagementIdS == "" {
  88. br.Msg = "请选择产业"
  89. return
  90. }
  91. industrialManagementList := strings.Split(industrialManagementIdS, ",")
  92. for _, v := range industrialManagementList {
  93. industrialActivityItem := new(cygx.CygxIndustrialActivityGroupManagement)
  94. industrialManagementId, err := strconv.Atoi(v)
  95. if err != nil {
  96. br.Msg = "参数解析异常!"
  97. br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIdS
  98. return
  99. }
  100. industrialActivityItem.CreateTime = time.Now()
  101. industrialActivityItem.IndustrialManagementId = industrialManagementId
  102. industrialActivityItem.ActivityId = activityId
  103. industrialActivityItem.Source = 2
  104. industrialActivityItems = append(industrialActivityItems, industrialActivityItem)
  105. }
  106. if industrialSubjectIdS != "" {
  107. industrialSubjectIdList := strings.Split(industrialSubjectIdS, ",")
  108. for _, v := range industrialSubjectIdList {
  109. subjectActivityItem := new(cygx.CygxIndustrialActivityGroupSubject)
  110. industrialSubjectId, err := strconv.Atoi(v)
  111. if err != nil {
  112. br.Msg = "参数解析异常!"
  113. br.ErrMsg = "标的ID不规范,Err:" + err.Error() + industrialManagementIdS
  114. return
  115. }
  116. subjectActivityItem.CreateTime = time.Now()
  117. subjectActivityItem.IndustrialSubjectId = industrialSubjectId
  118. subjectActivityItem.ActivityId = activityId
  119. subjectActivityItem.Source = 2
  120. subjectActivityItems = append(subjectActivityItems, subjectActivityItem)
  121. }
  122. }
  123. //产业名称
  124. if industrialManagementIdS != "" {
  125. industrialNames, err = cygx.GetindustrialManagementNames(industrialManagementIdS)
  126. if err != nil {
  127. br.Msg = "参数解析异常!"
  128. br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIdS
  129. return
  130. }
  131. }
  132. //标的名称
  133. if industrialSubjectIdS != "" {
  134. industrialSubjectNames, err = cygx.GetindustrialSubjectNames(industrialSubjectIdS)
  135. if err != nil {
  136. br.Msg = "参数解析异常!"
  137. br.ErrMsg = "标的ID不规范,Err:" + err.Error() + industrialSubjectIdS
  138. return
  139. }
  140. if temporarySubject != "" {
  141. industrialSubjectNames += "/" + strings.Replace(temporarySubject, ",", "/", -1)
  142. }
  143. } else {
  144. industrialSubjectNames = ""
  145. if temporarySubject != "" {
  146. industrialSubjectNames = strings.Replace(temporarySubject, ",", "/", -1)
  147. }
  148. }
  149. } else {
  150. industrialActivityItems = make([]*cygx.CygxIndustrialActivityGroupManagement, 0)
  151. subjectActivityItems = make([]*cygx.CygxIndustrialActivityGroupSubject, 0)
  152. }
  153. //List := []*cygx.ChartPermissionRepMore{{PermissionName: "医药"}, {PermissionName: "消费"}, {PermissionName: "科技"}, {PermissionName: "智造"}, {PermissionName: "研选"}}
  154. //var haveCheck bool
  155. //for _, v := range List {
  156. // if permissionName == v.PermissionName {
  157. // haveCheck = true
  158. // }
  159. //}
  160. //if !haveCheck {
  161. // br.Msg = "行业名称:" + permissionName + "不存在"
  162. // return
  163. //}
  164. //if strings.Contains(permissionName, "研选") {
  165. // permissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  166. //}
  167. charInfo, errCategory := cygx.GetCategoryInfoByName(permissionName)
  168. if errCategory != nil {
  169. br.Msg = "请选择所属行业"
  170. br.ErrMsg = "获取所属行业信息失败,Err:" + errCategory.Error()
  171. return
  172. }
  173. item.ChartPermissionId = charInfo.ChartPermissionId
  174. item.ChartPermissionName = req.PermissionName
  175. item.CustomerTypeIds = req.CustomerTypeIds
  176. item.PublishStatus = req.DoType
  177. item.ResearchTheme = req.ResearchTheme
  178. item.ActivityTimeText = req.ActivityTimeText
  179. item.TemporaryLabel = req.TemporaryLabel
  180. item.TemporarySubject = req.TemporarySubject
  181. //item.Scale = req.Scale
  182. item.TripImgLink = req.TripImgLink
  183. item.IndustrialName = industrialNames
  184. item.IndustrialSubjectName = industrialSubjectNames
  185. item.SpecialType = specialType
  186. item.AdminId = AdminUser.AdminId
  187. item.AdminName = AdminUser.RealName
  188. if specialType == 1 {
  189. item.City = ""
  190. } else {
  191. item.City = city
  192. }
  193. item.IsShowSubjectName = isShowSubjectName
  194. item.PublishDate = time.Now().Format(utils.FormatDateTime)
  195. if req.TemporaryLabel != "" {
  196. item.Label = req.TemporaryLabel
  197. } else {
  198. if isShowSubjectName == 1 {
  199. item.Label = industrialSubjectNames
  200. if industrialSubjectNames == "" {
  201. br.Msg = "请选择关联标的"
  202. }
  203. } else {
  204. item.Label = industrialNames
  205. }
  206. }
  207. item.LastUpdatedTime = time.Now()
  208. item.CreateTime = time.Now()
  209. if req.ActivityId > 0 {
  210. activityInfo, errInfo := cygx.GetAddActivityInfoSpecialById(req.ActivityId)
  211. if errInfo != nil {
  212. br.Msg = "活动不存在"
  213. br.ErrMsg = "活动ID错误,ActivityId:" + strconv.Itoa(req.ActivityId)
  214. return
  215. }
  216. //校验活动后台管理员、销售是否有修改权限
  217. havePower, popupMsg, err := cygxService.CheckActivitySpecialUpdatePower(AdminUser.AdminId, activityInfo)
  218. if err != nil {
  219. br.Msg = "获取管理员身份信息失败"
  220. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  221. return
  222. }
  223. if !havePower {
  224. br.Msg = popupMsg
  225. return
  226. }
  227. item.ActivityId = req.ActivityId
  228. //如果点发布PublishStatus = 1 如果点保存,PublishStatus则为之前的状态 发布人还是之前的发布人
  229. if item.PublishStatus == 0 {
  230. item.PublishStatus = activityInfo.PublishStatus
  231. }
  232. updateParams := make(map[string]interface{})
  233. updateParams["ChartPermissionId"] = item.ChartPermissionId
  234. updateParams["ChartPermissionName"] = item.ChartPermissionName
  235. updateParams["CustomerTypeIds"] = item.CustomerTypeIds
  236. updateParams["PublishStatus"] = item.PublishStatus
  237. updateParams["ResearchTheme"] = item.ResearchTheme
  238. updateParams["ActivityTimeText"] = item.ActivityTimeText
  239. updateParams["Label"] = item.Label
  240. updateParams["TemporaryLabel"] = item.TemporaryLabel
  241. updateParams["TemporarySubject"] = item.TemporarySubject
  242. //updateParams["Scale"] = item.Scale
  243. updateParams["TripImgLink"] = item.TripImgLink
  244. updateParams["IndustrialName"] = item.IndustrialName
  245. updateParams["IndustrialSubjectName"] = item.IndustrialSubjectName
  246. updateParams["LastUpdatedTime"] = time.Now()
  247. updateParams["SpecialType"] = item.SpecialType
  248. updateParams["City"] = item.City
  249. updateParams["IsShowSubjectName"] = item.IsShowSubjectName
  250. if req.DoType == 1 {
  251. updateParams["IsOffline"] = 0
  252. updateParams["PublishDate"] = time.Now()
  253. }
  254. err = cygx.EditActivitySpecial(updateParams, item, industrialActivityItems, subjectActivityItems)
  255. if err != nil {
  256. br.Msg = "发布失败"
  257. br.ErrMsg = "发布失败,Err:" + err.Error()
  258. return
  259. }
  260. } else {
  261. newId, err := cygx.AddActivitySpecial(item, industrialActivityItems, subjectActivityItems)
  262. if err != nil {
  263. br.Msg = "发布失败"
  264. br.ErrMsg = "发布失败,Err:" + err.Error()
  265. return
  266. }
  267. activityId = int(newId)
  268. }
  269. //模板消息推送
  270. if req.DoType == 1 {
  271. go services.SendWxMsgWithCygxActivitySpecial(activityId)
  272. //go cygxService.UpdateResourceData(activityId, "activityspecial", "add", time.Now().Format(utils.FormatDateTime))
  273. }
  274. go cygxService.UpdateActivitySpecialResourceData(activityId) //写入首页最新 cygx_resource_data 表
  275. go elastic.AddComprehensiveActivitySpecial(activityId) // Es添加活动
  276. br.Ret = 200
  277. br.Success = true
  278. br.Msg = "操作成功"
  279. br.IsAddLog = true
  280. }
  281. // @Title 活动列表
  282. // @Description 获取活动列表接口
  283. // @Param PageSize query int true "每页数据条数"
  284. // @Param CurrentIndex query int true "当前页页码,从1开始"
  285. // @Param PublishStatus query int false "发布状态 ,0未发布,1已发布,传2查询所有,3已下线,4:已确定行程"
  286. // @Param ChartPermissionId query string false "行业id"
  287. // @Param KeyWord query string false "搜索关键词"
  288. // @Param IsTrip query bool false "是否是确定行程"
  289. // @Success 200 {object} cygx.GetCygxActivityListSpecialRep
  290. // @router /special/list [get]
  291. func (this *ActivitySpecialCoAntroller) ActivityList() {
  292. br := new(models.BaseResponse).Init()
  293. defer func() {
  294. this.Data["json"] = br
  295. this.ServeJSON()
  296. }()
  297. sysUser := this.SysUser
  298. if sysUser == nil {
  299. br.Msg = "请登录"
  300. br.ErrMsg = "请登录,SysUser Is Empty"
  301. return
  302. }
  303. pageSize, _ := this.GetInt("PageSize")
  304. currentIndex, _ := this.GetInt("CurrentIndex")
  305. publishStatus, _ := this.GetInt("PublishStatus")
  306. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  307. keyWord := this.GetString("KeyWord")
  308. isTrip, _ := this.GetBool("IsTrip", false)
  309. var startSize int
  310. if pageSize <= 0 {
  311. pageSize = utils.PageSize20
  312. }
  313. if currentIndex <= 0 {
  314. currentIndex = 1
  315. }
  316. startSize = utils.StartIndex(currentIndex, pageSize)
  317. var condition string
  318. var pars []interface{}
  319. if keyWord != "" {
  320. condition += ` AND (art.research_theme LIKE '%` + keyWord + `%' ) `
  321. }
  322. //行业名称
  323. if chartPermissionId > 0 {
  324. condition += ` AND art.chart_permission_id = '` + strconv.Itoa(chartPermissionId) + `'`
  325. }
  326. if isTrip {
  327. if publishStatus == 0 || publishStatus == 1 {
  328. condition += ` AND art.publish_status = ` + strconv.Itoa(publishStatus)
  329. }
  330. } else {
  331. if publishStatus == 0 {
  332. condition += ` AND art.days = 0 AND art.publish_status = 0 AND art.is_offline =0 `
  333. }
  334. if publishStatus == 1 {
  335. condition += ` AND art.days = 0 AND art.publish_status = 1 `
  336. }
  337. }
  338. if publishStatus == 3 {
  339. condition += ` AND art.is_offline =1 `
  340. }
  341. if publishStatus == 4 || isTrip {
  342. condition += ` AND art.days > 0 `
  343. }
  344. total, err := cygx.GetActivitySpecialCount(condition, pars)
  345. if err != nil {
  346. br.Msg = "获取失败"
  347. br.ErrMsg = "获取失败,Err:" + err.Error()
  348. return
  349. }
  350. if isTrip {
  351. condition += ` ORDER BY art.activity_time DESC `
  352. } else {
  353. condition += ` ORDER BY art.last_updated_time DESC `
  354. }
  355. list, errList := cygx.GetActivityListSpecialAll(condition, pars, startSize, pageSize)
  356. if errList != nil {
  357. br.Msg = "获取失败"
  358. br.ErrMsg = "获取失败,Err:" + errList.Error()
  359. return
  360. }
  361. list = cygxService.HandleActivityListSpecial(list, isTrip)
  362. page := paging.GetPaging(currentIndex, pageSize, total)
  363. resp := new(cygx.GetCygxActivityListSpecialRep)
  364. resp.List = list
  365. resp.Paging = page
  366. br.Ret = 200
  367. br.Success = true
  368. br.Msg = "获取成功"
  369. br.Data = resp
  370. }
  371. // @Title 活动详情
  372. // @Description 获取活动详情接口
  373. // @Param ActivityId query int true "活动ID"
  374. // @Success Ret=200 {object} cygx.ActivitySpecialDetail
  375. // @router /special/detail [get]
  376. func (this *ActivitySpecialCoAntroller) Detail() {
  377. br := new(models.BaseResponse).Init()
  378. defer func() {
  379. this.Data["json"] = br
  380. this.ServeJSON()
  381. }()
  382. AdminUser := this.SysUser
  383. if AdminUser == nil {
  384. br.Msg = "请登录"
  385. br.ErrMsg = "请登录,用户信息为空"
  386. br.Ret = 408
  387. return
  388. }
  389. activityId, _ := this.GetInt("ActivityId")
  390. if activityId < 1 {
  391. br.Msg = "请输入活动ID"
  392. return
  393. }
  394. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  395. if err != nil {
  396. br.Msg = "活动不存在"
  397. br.ErrMsg = "活动ID错误,ActivityId:" + strconv.Itoa(activityId)
  398. return
  399. }
  400. industrialList, err := cygx.GetIndustrialActivityGroupManagementList(activityId, 2)
  401. if err != nil && err.Error() != utils.ErrNoRow() {
  402. br.Msg = "获取信息失败"
  403. br.ErrMsg = "获取活动关联的产业列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  404. return
  405. }
  406. var subjectList []*cygx.SubjectActivityGroupManagementRep
  407. if len(industrialList) > 0 {
  408. subjectList, err = cygx.GetSubjectActivityGroupManagementList(activityId, 2)
  409. if err != nil && err.Error() != utils.ErrNoRow() {
  410. br.Msg = "获取信息失败"
  411. br.ErrMsg = "获取活动关联的标的列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  412. return
  413. }
  414. }
  415. if activityInfo.CustomerTypeIds != "" {
  416. customerTypeIdslist := strings.Split(activityInfo.CustomerTypeIds, ",")
  417. var permissionValueStr string
  418. for _, v := range customerTypeIdslist {
  419. permissionValueStr += "'" + v + "',"
  420. }
  421. permissionValueStr = strings.TrimRight(permissionValueStr, ",")
  422. condition := ` AND permission_value IN (` + permissionValueStr + `)`
  423. listValue, err := cygx.GetActivityCcustomerTypeList(condition)
  424. if err != nil {
  425. br.Msg = "活动可见套餐类型错误,请核实"
  426. br.ErrMsg = "GetActivityCcustomerTypeList,Err:" + err.Error()
  427. return
  428. }
  429. activityInfo.CustomerTypeIds = ""
  430. for _, v := range listValue {
  431. activityInfo.CustomerTypeIds += strconv.Itoa(v.CustomerTypeId) + ","
  432. }
  433. activityInfo.CustomerTypeIds = strings.TrimRight(activityInfo.CustomerTypeIds, ",")
  434. nameStr, err := cygx.GetCustomerName(activityInfo.CustomerTypeIds)
  435. if err != nil {
  436. br.Msg = "获取信息失败"
  437. br.ErrMsg = "获取用户可见范围失败,Err:" + err.Error()
  438. return
  439. }
  440. activityInfo.CustomerName = nameStr
  441. }
  442. dateYmdList, err := cygxService.GetCygxActivitySpecialDay(activityId)
  443. if err != nil {
  444. br.Msg = "获取信息失败"
  445. br.ErrMsg = " 处理时间格式失败,GetCygxActivitySpecialDay,Err:" + err.Error()
  446. return
  447. }
  448. activityInfo.ListIndustrial = industrialList
  449. activityInfo.ListSubject = subjectList
  450. activityInfo.DateYmdList = dateYmdList
  451. br.Ret = 200
  452. br.Success = true
  453. br.Msg = "获取成功"
  454. br.Data = activityInfo
  455. }
  456. // @Title 活动的发布与取消发布
  457. // @Description 活动的发布与取消发布接口
  458. // @Param request body cygx.ActivityIdRep true "type json string"
  459. // @Success 200 操作成功
  460. // @router /special/PublishAndCancel [post]
  461. func (this *ActivitySpecialCoAntroller) PublishAndCancel() {
  462. br := new(models.BaseResponse).Init()
  463. defer func() {
  464. this.Data["json"] = br
  465. this.ServeJSON()
  466. }()
  467. AdminUser := this.SysUser
  468. if AdminUser == nil {
  469. br.Msg = "请登录"
  470. br.ErrMsg = "请登录,用户信息为空"
  471. br.Ret = 408
  472. return
  473. }
  474. var req cygx.ActivityIdRep
  475. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  476. if err != nil {
  477. br.Msg = "参数解析异常!"
  478. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  479. return
  480. }
  481. activityId := req.ActivityId
  482. item := new(cygx.CygxActivitySpecial)
  483. activityInfo, errInfo := cygx.GetAddActivityInfoSpecialById(activityId)
  484. if activityInfo == nil {
  485. br.Msg = "操作失败"
  486. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  487. return
  488. }
  489. if errInfo != nil {
  490. br.Msg = "操作失败"
  491. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  492. return
  493. }
  494. //校验活动后台管理员、销售是否有修改权限
  495. havePower, popupMsg, err := cygxService.CheckActivitySpecialUpdatePower(AdminUser.AdminId, activityInfo)
  496. if err != nil {
  497. br.Msg = "获取管理员身份信息失败"
  498. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  499. return
  500. }
  501. if !havePower {
  502. br.Msg = popupMsg
  503. return
  504. }
  505. updateParams := make(map[string]interface{})
  506. if activityInfo.PublishStatus == 0 {
  507. item.PublishStatus = 1
  508. updateParams["PublishDate"] = time.Now()
  509. } else {
  510. item.PublishStatus = 0
  511. // 取消专项调研返点
  512. //go cygxService.ActivitySpecialPublishAndCancel(activityInfo)
  513. }
  514. updateParams["PublishStatus"] = item.PublishStatus
  515. item.ActivityId = req.ActivityId
  516. err = cygx.UpdateActivitySpecial(updateParams, item)
  517. if err != nil {
  518. br.Msg = "操作失败"
  519. br.ErrMsg = "操作失败,Err:" + err.Error()
  520. return
  521. }
  522. //模板消息推送
  523. if item.PublishStatus == 1 {
  524. go services.SendWxMsgWithCygxActivitySpecial(activityId)
  525. //go cygxService.UpdateResourceData(activityId, "activityspecial", "add", time.Now().Format(utils.FormatDateTime))
  526. } else {
  527. go cygxService.DetermineTripCancel(activityId)
  528. //go cygxService.UpdateResourceData(activityId, "activityspecial", "delete", time.Now().Format(utils.FormatDateTime))
  529. }
  530. go cygxService.UpdateActivitySpecialResourceData(activityId) //写入首页最新 cygx_resource_data 表
  531. go elastic.AddComprehensiveActivitySpecial(activityId) // Es添加活动
  532. br.Ret = 200
  533. br.Success = true
  534. br.Msg = "操作成功"
  535. br.IsAddLog = true
  536. }
  537. // @Title 删除活动
  538. // @Description 删除活动接口
  539. // @Param request body cygx.ActivityIdRep true "type json string"
  540. // @Success Ret=200
  541. // @router /special/delete [post]
  542. func (this *ActivitySpecialCoAntroller) Delete() {
  543. br := new(models.BaseResponse).Init()
  544. defer func() {
  545. this.Data["json"] = br
  546. this.ServeJSON()
  547. }()
  548. AdminUser := this.SysUser
  549. if AdminUser == nil {
  550. br.Msg = "请登录"
  551. br.ErrMsg = "请登录,SysUser Is Empty"
  552. br.Ret = 408
  553. return
  554. }
  555. var req cygx.ActivityIdRep
  556. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  557. if err != nil {
  558. br.Msg = "参数解析异常!"
  559. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  560. return
  561. }
  562. activityId := req.ActivityId
  563. if activityId < 1 {
  564. br.Msg = "请输入活动ID"
  565. return
  566. }
  567. activityInfo, errInfo := cygx.GetAddActivityInfoSpecialById(activityId)
  568. if activityInfo == nil {
  569. br.Msg = "操作失败"
  570. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  571. return
  572. }
  573. if errInfo != nil {
  574. br.Msg = "操作失败"
  575. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  576. return
  577. }
  578. //校验活动后台管理员、销售是否有修改权限
  579. havePower, popupMsg, err := cygxService.CheckActivitySpecialUpdatePower(AdminUser.AdminId, activityInfo)
  580. if err != nil {
  581. br.Msg = "获取管理员身份信息失败"
  582. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  583. return
  584. }
  585. if !havePower {
  586. br.Msg = popupMsg
  587. return
  588. }
  589. err = cygx.DeleteActivitySpecial(activityId)
  590. if err != nil {
  591. br.Msg = "删除信息失败"
  592. br.ErrMsg = "删除信息失败,Err:" + err.Error()
  593. return
  594. }
  595. br.Ret = 200
  596. br.Success = true
  597. br.Msg = "已删除"
  598. br.IsAddLog = true
  599. }
  600. // @Title 获取活动感兴趣人员列表
  601. // @Description 获取活动感兴趣人员列表情接口
  602. // @Param ActivityId query int true "活动ID"
  603. // @Success Ret=200 {object} cygx.CygxActivitySpecialSignupListResp
  604. // @router /special/interested/list [get]
  605. func (this *ActivitySpecialCoAntroller) InterestedList() {
  606. br := new(models.BaseResponse).Init()
  607. defer func() {
  608. this.Data["json"] = br
  609. this.ServeJSON()
  610. }()
  611. AdminUser := this.SysUser
  612. if AdminUser == nil {
  613. br.Msg = "请登录"
  614. br.ErrMsg = "请登录,用户信息为空"
  615. br.Ret = 408
  616. return
  617. }
  618. activityId, _ := this.GetInt("ActivityId")
  619. if activityId < 1 {
  620. br.Msg = "请输入活动ID"
  621. return
  622. }
  623. _, err := cygx.GetAddActivityInfoSpecialById(activityId)
  624. if err != nil {
  625. br.Msg = "活动不存在"
  626. br.ErrMsg = "活动ID错误,ActivityId:" + strconv.Itoa(activityId)
  627. return
  628. }
  629. list, errList := cygx.GetCygxActivitySpecialSignupList(activityId)
  630. if errList != nil {
  631. br.Msg = "获取失败"
  632. br.ErrMsg = "获取失败,Err:" + errList.Error()
  633. return
  634. }
  635. resp := new(cygx.CygxActivitySpecialSignupListResp)
  636. resp.List = list
  637. br.Ret = 200
  638. br.Success = true
  639. br.Msg = "获取成功"
  640. br.Data = resp
  641. }
  642. // @Title 动感兴趣人员列表表格下载
  643. // @Description 动感兴趣人员列表表格下载接口
  644. // @Param ActivityId query int true "活动ID"
  645. // @Success 200 导出成功
  646. // @router /special/export [get]
  647. func (this *ActivitySignupCoAntroller) SpecialExport() {
  648. br := new(models.BaseResponse).Init()
  649. defer func() {
  650. this.Data["json"] = br
  651. this.ServeJSON()
  652. }()
  653. AdminUser := this.SysUser
  654. if AdminUser == nil {
  655. br.Msg = "请登录"
  656. br.ErrMsg = "请登录,SysUser Is Empty"
  657. return
  658. }
  659. activityId, _ := this.GetInt("ActivityId")
  660. //signupType := this.GetString("SignupType")
  661. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  662. if err != nil {
  663. br.Msg = "活动不存在"
  664. br.ErrMsg = "活动ID错误,ActivityId:" + strconv.Itoa(activityId)
  665. return
  666. }
  667. list, errList := cygx.GetCygxActivitySpecialSignupList(activityId)
  668. if errList != nil {
  669. br.Msg = "获取失败"
  670. br.ErrMsg = "获取失败,Err:" + errList.Error()
  671. return
  672. }
  673. //创建excel
  674. dir, err := os.Executable()
  675. exPath := filepath.Dir(dir)
  676. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  677. xlsxFile := xlsx.NewFile()
  678. if err != nil {
  679. br.Msg = "生成文件失败"
  680. br.ErrMsg = "生成文件失败"
  681. return
  682. }
  683. style := xlsx.NewStyle()
  684. alignment := xlsx.Alignment{
  685. Horizontal: "center",
  686. Vertical: "center",
  687. WrapText: true,
  688. }
  689. style.Alignment = alignment
  690. style.ApplyAlignment = true
  691. sheet, err := xlsxFile.AddSheet("名单")
  692. if err != nil {
  693. br.Msg = "新增Sheet失败"
  694. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  695. return
  696. }
  697. var isAdmin bool
  698. adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId)
  699. if errAdmin != nil {
  700. br.Msg = "获取失败"
  701. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  702. return
  703. }
  704. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  705. isAdmin = true
  706. }
  707. //标头
  708. rowTitle := sheet.AddRow()
  709. if isAdmin {
  710. cellA := rowTitle.AddCell()
  711. cellA.Value = "姓名"
  712. cellB := rowTitle.AddCell()
  713. cellB.Value = "手机号"
  714. cellC := rowTitle.AddCell()
  715. cellC.Value = "公司名称"
  716. cellD := rowTitle.AddCell()
  717. cellD.Value = "所属销售"
  718. for _, item := range list {
  719. row := sheet.AddRow()
  720. cellA := row.AddCell()
  721. cellA.Value = item.RealName
  722. cellB := row.AddCell()
  723. cellB.Value = item.Mobile
  724. cellC := row.AddCell()
  725. cellC.Value = item.CompanyName
  726. cellD := row.AddCell()
  727. cellD.Value = item.SellerName
  728. }
  729. } else {
  730. cellA := rowTitle.AddCell()
  731. cellA.Value = "姓名"
  732. cellB := rowTitle.AddCell()
  733. cellB.Value = "公司名称"
  734. cellC := rowTitle.AddCell()
  735. cellC.Value = "所属销售"
  736. for _, item := range list {
  737. row := sheet.AddRow()
  738. cellA := row.AddCell()
  739. cellA.Value = item.RealName
  740. cellB := row.AddCell()
  741. cellB.Value = item.CompanyName
  742. cellC := row.AddCell()
  743. cellC.Value = item.SellerName
  744. }
  745. }
  746. err = xlsxFile.Save(downLoadnFilePath)
  747. if err != nil {
  748. br.Msg = "保存文件失败"
  749. br.ErrMsg = "保存文件失败"
  750. return
  751. }
  752. downloadFileName := activityInfo.ResearchTheme + ".xlsx"
  753. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  754. defer func() {
  755. os.Remove(downLoadnFilePath)
  756. }()
  757. //添加操作日志记录
  758. br.Success = true
  759. br.Ret = 200
  760. br.Msg = "导出成功"
  761. br.IsAddLog = true
  762. }
  763. // @Title 专项调研客户感兴趣总览
  764. // @Description 专项调研客户感兴趣总览接口
  765. // @Param PageSize query int true "每页数据条数"
  766. // @Param CurrentIndex query int true "当前页页码,从1开始"
  767. // @Success 200 {object} cygx.CygxActivitySpecialSignupRespList
  768. // @router /special/signup/list [get]
  769. func (this *ActivitySpecialCoAntroller) ActivitySignupList() {
  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. var startSize int
  784. if pageSize <= 0 {
  785. pageSize = utils.PageSize20
  786. }
  787. if currentIndex <= 0 {
  788. currentIndex = 1
  789. }
  790. startSize = utils.StartIndex(currentIndex, pageSize)
  791. var condition string
  792. var isCanDownload bool
  793. var pars []interface{}
  794. if sysUser.Role == "admin" || sysUser.Role == "researcher" {
  795. isCanDownload = true
  796. }
  797. if isCanDownload == false {
  798. if sysUser.RoleTypeCode == "rai_group" {
  799. //组长查看本组所有组员
  800. condition += ` AND s.company_id IN (SELECT company_id FROM user_seller_relation WHERE seller_id IN (SELECT admin_id FROM admin WHERE group_id = (SELECT group_id FROM admin WHERE admin_id = ` + strconv.Itoa(sysUser.AdminId) + ` ) )) `
  801. } else {
  802. //组员查看自己
  803. condition += ` AND s.company_id IN (SELECT company_id FROM user_seller_relation WHERE seller_id = ` + strconv.Itoa(sysUser.AdminId) + `) `
  804. }
  805. }
  806. //condition += ` AND s.create_time < ? `
  807. //pars = append(pars, time.Now().Format(utils.FormatDate))
  808. total, err := cygx.GetCygxActivitySpecialSignupCount(condition, pars)
  809. if err != nil {
  810. br.Msg = "获取失败"
  811. br.ErrMsg = "获取失败,Err:" + err.Error()
  812. return
  813. }
  814. condition += ` GROUP BY s.id ORDER BY s.create_time DESC `
  815. list, errList := cygx.GetCygxActivitySpecialSignupListAll(condition, pars, startSize, pageSize)
  816. if errList != nil {
  817. br.Msg = "获取失败"
  818. br.ErrMsg = "获取失败,Err:" + errList.Error()
  819. return
  820. }
  821. if len(list) == 0 {
  822. list = make([]*cygx.CygxActivitySpecialSignupResp, 0)
  823. }
  824. page := paging.GetPaging(currentIndex, pageSize, total)
  825. resp := new(cygx.CygxActivitySpecialSignupRespList)
  826. resp.List = list
  827. resp.Paging = page
  828. br.Ret = 200
  829. br.Success = true
  830. br.Msg = "获取成功"
  831. br.Data = resp
  832. }
  833. // @Title 确定行程编辑
  834. // @Description 确定行程编辑接口
  835. // @Param request body cygx.ActivitySpecialRep true "type json string"
  836. // @Success 200 操作成功
  837. // @router /special/trip/PreserveAndPublish [post]
  838. func (this *ActivitySpecialCoAntroller) TripPreserveAndPublish() {
  839. br := new(models.BaseResponse).Init()
  840. defer func() {
  841. this.Data["json"] = br
  842. this.ServeJSON()
  843. }()
  844. AdminUser := this.SysUser
  845. if AdminUser == nil {
  846. br.Msg = "请登录"
  847. br.ErrMsg = "请登录,用户信息为空"
  848. br.Ret = 408
  849. return
  850. }
  851. var req cygx.ActivitySpecialDateRep
  852. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  853. if err != nil {
  854. br.Msg = "参数解析异常!"
  855. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  856. return
  857. }
  858. activityId := req.ActivityId
  859. industrialManagementIdS := req.IndustrialManagementIdS
  860. industrialSubjectIdS := req.IndustrialSubjectIdS
  861. temporaryLabel := req.TemporaryLabel
  862. permissionName := req.PermissionName
  863. specialType := req.SpecialType
  864. city := req.City
  865. isShowSubjectName := req.IsShowSubjectName
  866. temporarySubject := req.TemporarySubject
  867. dateYmdList := req.DateYmdList
  868. item := new(cygx.CygxActivitySpecial)
  869. customerTypeIds := req.CustomerTypeIds
  870. if customerTypeIds != "" {
  871. condition := ` AND customer_type_id IN (` + customerTypeIds + `)`
  872. listValue, err := cygx.GetActivityCcustomerTypeList(condition)
  873. if err != nil {
  874. br.Msg = "活动可见套餐类型错误,请核实"
  875. return
  876. }
  877. req.CustomerTypeIds = ""
  878. for _, v := range listValue {
  879. req.CustomerTypeIds += v.PermissionValue + ","
  880. }
  881. req.CustomerTypeIds = strings.TrimRight(req.CustomerTypeIds, ",")
  882. }
  883. if specialType != 1 && specialType != 2 {
  884. br.Msg = "请选择调研形式!"
  885. return
  886. }
  887. if specialType == 2 && city == "" {
  888. br.Msg = "请输入调研城市!"
  889. return
  890. }
  891. if req.Days < 1 {
  892. br.Msg = "请选择调研天数!"
  893. return
  894. }
  895. if req.Host == "" {
  896. br.Msg = "请输入主持人!"
  897. return
  898. }
  899. if req.PersonInCharge == "" {
  900. br.Msg = "请输入纪要负责人!"
  901. return
  902. }
  903. if len(dateYmdList) < 1 {
  904. br.Msg = "请选择调研日期!"
  905. return
  906. }
  907. req.Days = len(dateYmdList)
  908. industrialActivityItems, subjectActivityItems, err, industrialNames, industrialSubjectNames := cygxService.HandleIndustrialLabel(temporaryLabel, industrialManagementIdS, industrialSubjectIdS, activityId)
  909. if err != nil {
  910. br.Msg = "参数解析异常!"
  911. br.ErrMsg = "cygxService.HandleIndustrialLabel,Err:" + err.Error()
  912. return
  913. }
  914. //var items []*cygx.CygxActivity
  915. var dateYmdListOld []*cygx.CygxActivitySpecialDayResp
  916. dateYmdListOld, err = cygx.GetCygxActivitySpecialDayByActivityId(activityId)
  917. if err != nil {
  918. br.Msg = "获取信息失败"
  919. br.ErrMsg = " 处理时间格式失败,GetCygxActivitySpecialDay,Err:" + err.Error()
  920. return
  921. }
  922. activityTimeTextByDay, activityTime, activityTimeEnd, dateList, e := cygxService.HandleDateYmdList(dateYmdList)
  923. if e != nil {
  924. br.Msg = "时间格式有误!"
  925. br.ErrMsg = "cygxService.HandleIndustrialLabel,Err:" + e.Error()
  926. return
  927. }
  928. if strings.Contains(permissionName, "研选") {
  929. permissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  930. }
  931. charInfo, errCategory := cygx.GetCategoryInfoByName(permissionName)
  932. if errCategory != nil {
  933. br.Msg = "请选择所属行业"
  934. br.ErrMsg = "获取所属行业信息失败,Err:" + errCategory.Error()
  935. return
  936. }
  937. item.ChartPermissionId = charInfo.ChartPermissionId
  938. item.ChartPermissionName = req.PermissionName
  939. item.CustomerTypeIds = req.CustomerTypeIds
  940. item.ResearchTheme = req.ResearchTheme
  941. item.TemporaryLabel = req.TemporaryLabel
  942. item.TemporarySubject = req.TemporarySubject
  943. item.Scale = req.Scale
  944. item.TripImgLink = req.TripImgLink
  945. item.IndustrialName = industrialNames
  946. item.IndustrialSubjectName = industrialSubjectNames
  947. item.SpecialType = specialType
  948. if specialType == 1 {
  949. item.City = ""
  950. } else {
  951. item.City = city
  952. }
  953. item.IsShowSubjectName = isShowSubjectName
  954. if req.TemporaryLabel != "" {
  955. item.Label = req.TemporaryLabel
  956. } else {
  957. if isShowSubjectName == 1 {
  958. if temporarySubject != "" {
  959. item.Label = strings.Replace(temporarySubject, ",", "/", -1)
  960. } else {
  961. if industrialSubjectNames == "" {
  962. br.Msg = "请选择关联标的"
  963. return
  964. }
  965. item.Label = industrialSubjectNames
  966. }
  967. } else {
  968. item.Label = industrialNames
  969. }
  970. }
  971. activityInfo, errInfo := cygx.GetAddActivityInfoSpecialById(req.ActivityId)
  972. if errInfo != nil {
  973. br.Msg = "活动不存在"
  974. br.ErrMsg = "活动ID错误,ActivityId:" + strconv.Itoa(req.ActivityId)
  975. return
  976. }
  977. //校验活动后台管理员、销售是否有修改权限
  978. havePower, popupMsg, err := cygxService.CheckActivitySpecialUpdatePower(AdminUser.AdminId, activityInfo)
  979. if err != nil {
  980. br.Msg = "获取管理员身份信息失败"
  981. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  982. return
  983. }
  984. if !havePower {
  985. br.Msg = popupMsg
  986. return
  987. }
  988. item.ActivityId = activityInfo.ActivityId
  989. updateParams := make(map[string]interface{})
  990. updateParams["ChartPermissionId"] = item.ChartPermissionId
  991. updateParams["ChartPermissionName"] = item.ChartPermissionName
  992. updateParams["CustomerTypeIds"] = item.CustomerTypeIds
  993. updateParams["ResearchTheme"] = item.ResearchTheme
  994. updateParams["Label"] = item.Label
  995. updateParams["TemporaryLabel"] = item.TemporaryLabel
  996. updateParams["TemporarySubject"] = item.TemporarySubject
  997. updateParams["Scale"] = item.Scale
  998. updateParams["IndustrialName"] = item.IndustrialName
  999. updateParams["IndustrialSubjectName"] = item.IndustrialSubjectName
  1000. updateParams["LastUpdatedTime"] = time.Now()
  1001. updateParams["SpecialType"] = item.SpecialType
  1002. updateParams["City"] = item.City
  1003. updateParams["IsShowSubjectName"] = item.IsShowSubjectName
  1004. updateParams["Days"] = req.Days
  1005. updateParams["Host"] = req.Host
  1006. updateParams["LimitPeopleNum"] = req.LimitPeopleNum
  1007. updateParams["PersonInCharge"] = req.PersonInCharge
  1008. updateParams["TripImgLinkFix"] = req.TripImgLinkFix
  1009. updateParams["ActivityTimeTextByDay"] = activityTimeTextByDay
  1010. updateParams["ActivityTime"] = activityTime
  1011. updateParams["ActivityTimeEnd"] = activityTimeEnd
  1012. err = cygx.EditActivitySpecial(updateParams, item, industrialActivityItems, subjectActivityItems)
  1013. if err != nil {
  1014. br.Msg = "发布失败"
  1015. br.ErrMsg = "发布失败,Err:" + err.Error()
  1016. return
  1017. }
  1018. // 批量插入日程时间
  1019. err = cygxService.AddActivitySpecial(dateList, activityId)
  1020. if err != nil {
  1021. br.Msg = "发布失败"
  1022. br.ErrMsg = "发布失败,时间格式有误Err:" + err.Error()
  1023. return
  1024. }
  1025. if activityInfo.Days == 0 {
  1026. cygxService.DetermineTripBeInterested(activityId)
  1027. cygxService.SendWxMsgWithCygxActivitySpecialSubscribeNoInterested(activityId)
  1028. } else {
  1029. var changeMsg string
  1030. if activityInfo.SpecialType != req.SpecialType {
  1031. if req.SpecialType == 1 {
  1032. changeMsg = "调研形式由【线下】变为【线上】"
  1033. } else {
  1034. changeMsg = "调研形式由【线上】变为【线下】"
  1035. }
  1036. cygxService.DetermineTripChange(activityId, "SpecialType", changeMsg)
  1037. }
  1038. if activityInfo.City != req.City && req.City != "" && activityInfo.SpecialType == req.SpecialType {
  1039. changeMsg = "调研形式由【" + activityInfo.City + "】变为【" + req.City + "】"
  1040. cygxService.DetermineTripChange(activityId, "City", changeMsg)
  1041. }
  1042. //判断时间是否有改动,处理字符串
  1043. mapdateYmd := make(map[string]string)
  1044. mapdateYmdTxt := make(map[string]string)
  1045. for k, v := range dateList {
  1046. resultTime := utils.StrTimeToTime(v) //时间字符串格式转时间格式
  1047. timeStrYmd := resultTime.Format(utils.FormatDateTime)
  1048. timeStrYmdTxt := resultTime.Format(utils.FormatDate)
  1049. timeStrHm := resultTime.Format(utils.FormatTimeHm)
  1050. mapdateYmd[timeStrYmd] += timeStrYmd
  1051. if k%2 == 0 {
  1052. mapdateYmdTxt[timeStrYmdTxt] += timeStrHm
  1053. } else {
  1054. mapdateYmdTxt[timeStrYmdTxt] += "~" + timeStrHm + ", "
  1055. }
  1056. }
  1057. for k, v := range mapdateYmdTxt {
  1058. v = strings.TrimRight(v, ", ")
  1059. changeMsg += k + " " + v + ";"
  1060. }
  1061. changeMsg = strings.TrimRight(changeMsg, ";")
  1062. var changedate bool
  1063. for _, v := range dateYmdListOld {
  1064. if _, ok := mapdateYmd[v.DayTime.Format(utils.FormatDateTime)]; !ok {
  1065. changedate = true
  1066. }
  1067. }
  1068. if len(dateList) != len(dateYmdListOld) || changedate {
  1069. changeMsg = strings.TrimRight(changeMsg, ",")
  1070. cygxService.DetermineTripChange(activityId, "dateList", changeMsg)
  1071. }
  1072. }
  1073. go elastic.AddComprehensiveActivitySpecial(activityId) // Es添加活动
  1074. br.Ret = 200
  1075. br.Success = true
  1076. br.Msg = "操作成功"
  1077. br.IsAddLog = true
  1078. }
  1079. // @Title 活动下线与重新发布
  1080. // @Description 活动的发布与取消发布接口
  1081. // @Param request body cygx.ActivityIdRep true "type json string"
  1082. // @Success 200 操作成功
  1083. // @router /special/Offline [post]
  1084. func (this *ActivitySpecialCoAntroller) Offline() {
  1085. br := new(models.BaseResponse).Init()
  1086. defer func() {
  1087. this.Data["json"] = br
  1088. this.ServeJSON()
  1089. }()
  1090. AdminUser := this.SysUser
  1091. if AdminUser == nil {
  1092. br.Msg = "请登录"
  1093. br.ErrMsg = "请登录,用户信息为空"
  1094. br.Ret = 408
  1095. return
  1096. }
  1097. var req cygx.ActivityIdRep
  1098. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1099. if err != nil {
  1100. br.Msg = "参数解析异常!"
  1101. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1102. return
  1103. }
  1104. activityId := req.ActivityId
  1105. item := new(cygx.CygxActivitySpecial)
  1106. activityInfo, errInfo := cygx.GetAddActivityInfoSpecialById(activityId)
  1107. if activityInfo == nil {
  1108. br.Msg = "操作失败"
  1109. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1110. return
  1111. }
  1112. if errInfo != nil {
  1113. br.Msg = "操作失败"
  1114. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1115. return
  1116. }
  1117. //校验活动后台管理员、销售是否有修改权限
  1118. havePower, popupMsg, err := cygxService.CheckActivitySpecialUpdatePower(AdminUser.AdminId, activityInfo)
  1119. if err != nil {
  1120. br.Msg = "获取管理员身份信息失败"
  1121. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  1122. return
  1123. }
  1124. if !havePower {
  1125. br.Msg = popupMsg
  1126. return
  1127. }
  1128. updateParams := make(map[string]interface{})
  1129. if activityInfo.IsOffline == 0 {
  1130. item.IsOffline = 1
  1131. item.PublishStatus = 0
  1132. } else {
  1133. item.IsOffline = 0
  1134. item.PublishStatus = 1
  1135. updateParams["PublishDate"] = time.Now()
  1136. }
  1137. updateParams["PublishStatus"] = item.PublishStatus
  1138. updateParams["IsOffline"] = item.IsOffline
  1139. item.ActivityId = req.ActivityId
  1140. err = cygx.UpdateActivitySpecial(updateParams, item)
  1141. if err != nil {
  1142. br.Msg = "操作失败"
  1143. br.ErrMsg = "操作失败,Err:" + err.Error()
  1144. return
  1145. }
  1146. //模板消息推送
  1147. //if item.PublishStatus == 1 {
  1148. // go cygxService.UpdateResourceData(activityId, "activityspecial", "add", time.Now().Format(utils.FormatDateTime))
  1149. // //go services.SendWxMsgWithCygxActivitySpecial(activityId)
  1150. //} else {
  1151. // go cygxService.UpdateResourceData(activityId, "activityspecial", "delete", time.Now().Format(utils.FormatDateTime))
  1152. //}
  1153. go cygxService.UpdateActivitySpecialResourceData(activityId) //写入首页最新 cygx_resource_data 表
  1154. go elastic.AddComprehensiveActivitySpecial(activityId) // Es添加活动
  1155. br.Ret = 200
  1156. br.Success = true
  1157. br.Msg = "操作成功"
  1158. br.IsAddLog = true
  1159. }