activity_special.go 38 KB

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