activity_special.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/services"
  7. "hongze/hongze_clpt/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // 专项调研活动
  12. type ActivitySpecialController struct {
  13. BaseAuthController
  14. }
  15. // @Title 专项产业调研列表
  16. // @Description 获取专项产业调研列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  20. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  21. // @Param WhichDay query string false "哪一天 今天:1、明天:2, 本周:3 上周:4,本月:5上月:6多个用 , 隔开"
  22. // @Success 200 {object} models.GetCygxActivitySpecialDetailListResp
  23. // @router /list [get]
  24. func (this *ActivitySpecialController) SpecialList() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. user := this.User
  31. if user == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. return
  35. }
  36. pageSize, _ := this.GetInt("PageSize")
  37. currentIndex, _ := this.GetInt("CurrentIndex")
  38. chartPermissionIds := this.GetString("ChartPermissionIds")
  39. whichDay := this.GetString("WhichDay")
  40. activeState := this.GetString("ActiveState")
  41. if pageSize <= 0 {
  42. pageSize = utils.PageSize20
  43. }
  44. if currentIndex <= 0 {
  45. currentIndex = 1
  46. }
  47. if activeState == "1" {
  48. activeState = ""
  49. }
  50. conditionActivity := services.ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState)
  51. list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "", conditionActivity, activeState)
  52. if errList != nil {
  53. br.Msg = "获取失败"
  54. br.ErrMsg = "获取失败,Err:" + errList.Error()
  55. return
  56. }
  57. page := paging.GetPaging(currentIndex, pageSize, total)
  58. resp := new(models.GetCygxActivitySpecialDetailListResp)
  59. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  60. if err != nil {
  61. br.Msg = "获取数据失败!"
  62. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  63. return
  64. }
  65. if count == 1 && user.UserId > 0 {
  66. resp.IsFollow = true
  67. }
  68. if user.Mobile != "" {
  69. resp.IsBindingMobile = true
  70. }
  71. if len(list) == 0 {
  72. list = make([]*models.CygxActivitySpecialDetail, 0)
  73. }
  74. resp.List = list
  75. resp.Paging = page
  76. br.Ret = 200
  77. br.Success = true
  78. br.Msg = "获取成功"
  79. br.Data = resp
  80. }
  81. // @Title 专项产业调研详情
  82. // @Description 获取专项产业调研详情接口
  83. // @Param ActivityId query int true "活动ID"
  84. // @Success Ret=200 {object} models.CygxActivitySpecialResp
  85. // @router /detail [get]
  86. func (this *ActivitySpecialController) SpecialDetail() {
  87. br := new(models.BaseResponse).Init()
  88. defer func() {
  89. this.Data["json"] = br
  90. this.ServeJSON()
  91. }()
  92. user := this.User
  93. if user == nil {
  94. br.Msg = "请登录"
  95. br.ErrMsg = "请登录,用户信息为空"
  96. br.Ret = 408
  97. return
  98. }
  99. uid := user.UserId
  100. activityId, _ := this.GetInt("ActivityId")
  101. if activityId < 1 {
  102. br.Msg = "请输入活动ID"
  103. return
  104. }
  105. resp := new(models.CygxActivitySpecialResp)
  106. activityInfo, err := models.GetCygxActivitySpecialDetailById(uid, activityId)
  107. if err != nil && err.Error() != utils.ErrNoRow() {
  108. br.Msg = "获取信息失败"
  109. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  110. return
  111. }
  112. if activityInfo == nil {
  113. br.Msg = "活动不存在"
  114. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  115. return
  116. }
  117. //havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  118. //if err != nil {
  119. // br.Msg = "获取信息失败"
  120. // br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  121. // return
  122. //}
  123. var havePower bool
  124. havePower = true
  125. //判断有没有对应的权限,如果没有则给出对应的状态码
  126. if havePower {
  127. resp.HasPermission = 1
  128. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  129. if err != nil {
  130. br.Msg = "获取数据失败!"
  131. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  132. return
  133. }
  134. if count == 1 {
  135. resp.IsFollow = true
  136. }
  137. activityInfo, err := services.HandleActivitySpecialShow(activityInfo, user)
  138. if err != nil {
  139. br.Msg = "获取数据失败!"
  140. br.ErrMsg = "HandleActivitySpecialShow,Err:" + err.Error()
  141. return
  142. }
  143. var condition string
  144. var pars []interface{}
  145. condition += ` AND t.activity_id = ? AND t.is_cancel = 0 `
  146. pars = append(pars, activityInfo.ActivityId)
  147. tripTota, err := models.GetActivitySpecialTripCountByActivityId(condition, pars)
  148. if err != nil {
  149. br.Msg = "获取数据失败!"
  150. br.ErrMsg = "GetActivitySpecialTripCountByActivityId,Err:" + err.Error()
  151. return
  152. }
  153. activityInfo.TripNum = tripTota
  154. activityInfo.ActivityTypeName = "专项调研"
  155. activityInfo.ShareImg = services.GetActivitySpecialShareImg(activityInfo)
  156. resp.Detail = activityInfo
  157. resp.Detail = activityInfo
  158. } else {
  159. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  160. if err != nil {
  161. br.Msg = "获取信息失败"
  162. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  163. return
  164. }
  165. resp.PopupMsg = popupMsg
  166. resp.HasPermission = hasPermission
  167. resp.SellerName = sellerName
  168. resp.SellerMobile = sellerMobile
  169. }
  170. br.Ret = 200
  171. br.Success = true
  172. br.Msg = "获取成功"
  173. br.Data = resp
  174. }
  175. // @Title报名
  176. // @Description 报名
  177. // @Param request body models.ActivityIdRep true "type json string"
  178. // @Success Ret=200 {object} models.SignupSpecialStatus
  179. // @router /trip/add [post]
  180. func (this *ActivitySpecialController) SpecialTripAdd() {
  181. br := new(models.BaseResponse).Init()
  182. defer func() {
  183. this.Data["json"] = br
  184. this.ServeJSON()
  185. }()
  186. user := this.User
  187. if user == nil {
  188. br.Msg = "请登录"
  189. br.ErrMsg = "请登录,用户信息为空"
  190. br.Ret = 408
  191. return
  192. }
  193. uid := user.UserId
  194. var req models.ActivityIdRep
  195. resp := new(models.SignupSpecialStatus)
  196. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  197. if err != nil {
  198. br.Msg = "参数解析异常!"
  199. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  200. return
  201. }
  202. activityId := req.ActivityId
  203. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  204. if activityInfo == nil {
  205. br.Msg = "操作失败"
  206. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  207. return
  208. }
  209. if errInfo != nil {
  210. br.Msg = "操作失败"
  211. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  212. return
  213. }
  214. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  215. if err != nil {
  216. br.Msg = "获取信息失败"
  217. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  218. return
  219. }
  220. //判断有没有对应的权限,如果没有则给出对应的状态码
  221. if havePower {
  222. resp.HasPermission = 1
  223. signupStatus, popupMsg, popupMsg2, err := services.SpecialTripPopupMsg(activityInfo, user)
  224. if err != nil {
  225. br.Msg = "获取信息失败"
  226. br.ErrMsg = "SpecialTripPopupMsg,Err:" + err.Error()
  227. return
  228. }
  229. resp.PopupMsg = popupMsg
  230. resp.PopupMsg2 = popupMsg2
  231. resp.SignupStatus = signupStatus
  232. if signupStatus == 1 {
  233. total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
  234. if err != nil {
  235. br.Msg = "获取信息失败"
  236. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  237. return
  238. }
  239. //流水记录表
  240. itemBill := new(models.CygxActivitySpecialTripBill)
  241. itemBill.UserId = user.UserId
  242. itemBill.ActivityId = activityInfo.ActivityId
  243. itemBill.CreateTime = time.Now()
  244. itemBill.Mobile = user.Mobile
  245. itemBill.Email = user.Email
  246. itemBill.CompanyId = user.CompanyId
  247. itemBill.CompanyName = user.CompanyName
  248. itemBill.RealName = user.RealName
  249. itemBill.Source = 1
  250. itemBill.DoType = 1
  251. itemBill.BillDetailed = -1 // 流水减一
  252. itemBill.RegisterPlatform = utils.REGISTER_PLATFORM
  253. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  254. itemBill.ChartPermissionName = activityInfo.ChartPermissionName
  255. if utils.InArrayByStr(utils.ACTIVITY_SPECIAL_TRIP_PERMISSION_NAME_OTHER, activityInfo.ChartPermissionName) {
  256. //如果是策略、固收、周期行业,把代扣行业信息放入流水表,取消报名的时候,返点使用
  257. maxChartPermissionId, maxChartPermissionName, err := services.GetSpecialBillMaxChartPermissionId(user)
  258. if err != nil {
  259. br.Msg = "操作失败"
  260. br.ErrMsg = "获取销售信息失败,GetSpecialBillMaxChartPermissionId Err:" + err.Error()
  261. return
  262. }
  263. itemBill.ChartPermissionId = maxChartPermissionId
  264. itemBill.ChartPermissionName = maxChartPermissionName
  265. }
  266. var itemMeeting = new(models.CygxActivitySpecialMeetingDetail)
  267. itemMeeting.UserId = user.UserId
  268. itemMeeting.ActivityId = activityId
  269. itemMeeting.CreateTime = time.Now()
  270. itemMeeting.Mobile = user.Mobile
  271. itemMeeting.Email = user.Email
  272. itemMeeting.CompanyId = user.CompanyId
  273. itemMeeting.CompanyName = user.CompanyName
  274. itemMeeting.RealName = user.RealName
  275. go services.ActivitySpecialUserRmind(user, activityId, 2)
  276. go services.ActivitySpecialUserAddTrip(user, activityId)
  277. //判断是删除还是添加
  278. if total == 0 {
  279. //获取销售信息
  280. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  281. if err != nil {
  282. br.Msg = "操作失败"
  283. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  284. return
  285. }
  286. item := new(models.CygxActivitySpecialTrip)
  287. item.UserId = uid
  288. item.RealName = user.RealName
  289. item.ActivityId = activityId
  290. item.CreateTime = time.Now()
  291. item.Mobile = user.Mobile
  292. item.Email = user.Email
  293. item.CompanyId = user.CompanyId
  294. item.CompanyName = user.CompanyName
  295. item.IsValid = 1
  296. if sellerItem != nil {
  297. item.SellerName = sellerItem.RealName
  298. }
  299. if user.OutboundMobile != "" {
  300. item.OutboundMobile = user.OutboundMobile
  301. if user.OutboundCountryCode == "" {
  302. item.CountryCode = "86"
  303. } else {
  304. item.CountryCode = user.OutboundCountryCode
  305. }
  306. } else {
  307. item.OutboundMobile = user.Mobile
  308. if user.CountryCode == "" {
  309. item.CountryCode = "86"
  310. } else {
  311. item.CountryCode = user.CountryCode
  312. }
  313. }
  314. err = services.DeductTripRemainingtimesByUser(user, activityInfo) //扣除用户专项调研剩余次数
  315. if err != nil {
  316. br.Msg = "操作失败"
  317. br.ErrMsg = "操作失败,Err:" + err.Error()
  318. return
  319. }
  320. err = models.AddCygxActivitySpecialTrip(item)
  321. if err != nil {
  322. br.Msg = "操作失败"
  323. br.ErrMsg = "操作失败,Err:" + err.Error()
  324. return
  325. }
  326. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  327. } else {
  328. updateParams := make(map[string]interface{})
  329. updateParams["IsValid"] = 1
  330. updateParams["CreateTime"] = time.Now()
  331. updateParams["IsCancel"] = 0
  332. whereParam := map[string]interface{}{"user_id": user.UserId, "activity_id": activityId}
  333. err = models.UpdateByExpr(models.CygxActivitySpecialTrip{}, whereParam, updateParams)
  334. if err != nil {
  335. br.Msg = "报名失败,"
  336. br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
  337. return
  338. }
  339. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  340. //48小时之内的取消也扣除一次参会记录
  341. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  342. itemBill.BillDetailed = 0 //48小时之内,取消报名之后二次报名,不扣除流水记录
  343. } else {
  344. err = services.DeductTripRemainingtimesByUser(user, activityInfo) //扣除用户专项调研剩余次数
  345. if err != nil {
  346. br.Msg = "操作失败"
  347. br.ErrMsg = "操作失败,Err:" + err.Error()
  348. return
  349. }
  350. }
  351. }
  352. //userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
  353. //if err != nil {
  354. // br.Msg = "获取专项调研剩余次数失败"
  355. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  356. // return
  357. //}
  358. //if userType == 2 {
  359. // tripRemaining = tripRemaining + itemBill.BillDetailed
  360. // itemBill.Total = strconv.Itoa(tripRemaining) + "次"
  361. //} else {
  362. // for k, num := range mapChartName {
  363. // if activityInfo.ChartPermissionName == k {
  364. // num = num + itemBill.BillDetailed
  365. // }
  366. // itemBill.Total += k + strconv.Itoa(num) + "次+"
  367. // }
  368. // itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  369. //}
  370. totalText, err := services.HandleActivitySpecialTripBillTotalText(user.CompanyId)
  371. if err != nil {
  372. br.Msg = "报名失败,"
  373. br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
  374. return
  375. }
  376. itemBill.Total = totalText
  377. //添加流水记录
  378. err = models.AddCygxActivitySpecialTripBill(itemBill)
  379. if err != nil {
  380. br.Msg = "报名失败,"
  381. br.ErrMsg = "AddCygxActivitySpecialTripBill,Err:" + err.Error()
  382. return
  383. }
  384. //添加数据到会信息
  385. err = models.AddCygxActivitySpecialMeetingDetail(itemMeeting)
  386. if err != nil {
  387. br.Msg = "报名失败,"
  388. br.ErrMsg = "AddCygxActivitySpecialMeetingDetail,Err:" + err.Error()
  389. return
  390. }
  391. }
  392. } else {
  393. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  394. if err != nil {
  395. br.Msg = "获取信息失败"
  396. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  397. return
  398. }
  399. resp.PopupMsg = popupMsg
  400. resp.HasPermission = hasPermission
  401. resp.SellerName = sellerName
  402. resp.SellerMobile = sellerMobile
  403. }
  404. resp.ActivityId = activityId
  405. br.Ret = 200
  406. br.Success = true
  407. br.Msg = "操作成功"
  408. br.Data = resp
  409. }
  410. // @Title 取消报名
  411. // @Description 取消报名
  412. // @Param request body models.ActivityIdRep true "type json string"
  413. // @Success Ret=200 {object} models.SignupStatus
  414. // @router /trip/cancel [post]
  415. func (this *ActivitySpecialController) Tripcancel() {
  416. br := new(models.BaseResponse).Init()
  417. defer func() {
  418. this.Data["json"] = br
  419. this.ServeJSON()
  420. }()
  421. user := this.User
  422. if user == nil {
  423. br.Msg = "请登录"
  424. br.ErrMsg = "请登录,用户信息为空"
  425. br.Ret = 408
  426. return
  427. }
  428. uid := user.UserId
  429. var req models.ActivityIdRep
  430. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  431. if err != nil {
  432. br.Msg = "参数解析异常!"
  433. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  434. return
  435. }
  436. activityId := req.ActivityId
  437. total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
  438. if err != nil {
  439. br.Msg = "获取信息失败"
  440. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  441. return
  442. }
  443. if total == 0 {
  444. br.Msg = "报名已取消!"
  445. return
  446. }
  447. activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, activityId)
  448. if activityInfo == nil {
  449. br.Msg = "操作失败"
  450. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  451. return
  452. }
  453. if errInfo != nil {
  454. br.Msg = "操作失败"
  455. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  456. return
  457. }
  458. //流水记录表
  459. itemBill := new(models.CygxActivitySpecialTripBill)
  460. itemBill.UserId = user.UserId
  461. itemBill.ActivityId = activityInfo.ActivityId
  462. itemBill.CreateTime = time.Now()
  463. itemBill.Mobile = user.Mobile
  464. itemBill.Email = user.Email
  465. itemBill.CompanyId = user.CompanyId
  466. itemBill.CompanyName = user.CompanyName
  467. itemBill.RealName = user.RealName
  468. itemBill.Source = 1
  469. itemBill.DoType = 2
  470. itemBill.BillDetailed = 1 // 流水加一
  471. itemBill.RegisterPlatform = utils.REGISTER_PLATFORM
  472. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  473. itemBill.ChartPermissionName = activityInfo.ChartPermissionName
  474. if utils.InArrayByStr(utils.ACTIVITY_SPECIAL_TRIP_PERMISSION_NAME_OTHER, activityInfo.ChartPermissionName) {
  475. //如果是策略、固收、周期行业,把代扣行业信息放入流水表,取消报名的时候,返点使用
  476. lastTripBill, err := models.GetCygxActivitySpecialTripBillLastDetialByActivityId(activityInfo.ActivityId, user.UserId)
  477. if err != nil {
  478. br.Msg = "操作失败"
  479. br.ErrMsg = "获取销售信息失败,GetSpecialBillMaxChartPermissionId Err:" + err.Error()
  480. return
  481. }
  482. itemBill.ChartPermissionId = lastTripBill.ChartPermissionId
  483. itemBill.ChartPermissionName = lastTripBill.ChartPermissionName
  484. }
  485. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  486. //48小时之内的取消也扣除一次参会记录
  487. var isValid int
  488. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  489. isValid = 1
  490. itemBill.BillDetailed = 0 //48小时之内取消的活动扣点不返回
  491. } else {
  492. err = services.RebateTripRemainingtimesByUser(user, activityInfo) // 返点
  493. if err != nil {
  494. br.Msg = "操作失败"
  495. br.ErrMsg = "操作失败,RebateTripRemainingtimesByUserErr:" + err.Error()
  496. return
  497. }
  498. }
  499. //userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
  500. //if err != nil {
  501. // br.Msg = "获取专项调研剩余次数失败"
  502. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  503. // return
  504. //}
  505. //if userType == 2 {
  506. // tripRemaining += itemBill.BillDetailed
  507. // itemBill.Total = strconv.Itoa(tripRemaining) + "次"
  508. //} else {
  509. // for k, num := range mapChartName {
  510. // if activityInfo.ChartPermissionName == k {
  511. // num += itemBill.BillDetailed
  512. // }
  513. // itemBill.Total += k + strconv.Itoa(num) + "次+"
  514. // }
  515. // itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  516. //}
  517. totalText, err := services.HandleActivitySpecialTripBillTotalText(user.CompanyId)
  518. if err != nil {
  519. br.Msg = "报名失败,"
  520. br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
  521. return
  522. }
  523. itemBill.Total = totalText
  524. err = models.CancelActivitySpecialTripIsValid(isValid, activityInfo.ActivityId, uid)
  525. if err != nil {
  526. br.Msg = "操作失败"
  527. br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
  528. return
  529. }
  530. err = models.CancelCygxActivitySpecialMeetingDetail(uid, activityId)
  531. if err != nil {
  532. br.Msg = "操作失败"
  533. br.ErrMsg = "CancelCygxActivitySpecialMeetingDetail,Err:" + err.Error()
  534. return
  535. }
  536. go models.AddCygxActivitySpecialTripBill(itemBill)
  537. br.Ret = 200
  538. br.Success = true
  539. br.Msg = "已取消"
  540. }
  541. // @Title 感兴趣、不感兴趣
  542. // @Description 感兴趣、不感兴趣接口
  543. // @Param request body models.ActivityIdRep true "type json string"
  544. // @Success Ret=200 {object} models.SignupSpecialStatus
  545. // @router /signup/add [post]
  546. func (this *ActivitySpecialController) SpecialSignupAdd() {
  547. br := new(models.BaseResponse).Init()
  548. defer func() {
  549. this.Data["json"] = br
  550. this.ServeJSON()
  551. }()
  552. user := this.User
  553. if user == nil {
  554. br.Msg = "请登录"
  555. br.ErrMsg = "请登录,用户信息为空"
  556. br.Ret = 408
  557. return
  558. }
  559. uid := user.UserId
  560. var req models.ActivityIdRep
  561. resp := new(models.SignupSpecialStatus)
  562. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  563. if err != nil {
  564. br.Msg = "参数解析异常!"
  565. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  566. return
  567. }
  568. activityId := req.ActivityId
  569. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  570. if activityInfo == nil {
  571. br.Msg = "操作失败"
  572. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  573. return
  574. }
  575. if errInfo != nil {
  576. br.Msg = "操作失败"
  577. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  578. return
  579. }
  580. //havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  581. //if err != nil {
  582. // br.Msg = "获取信息失败"
  583. // br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  584. // return
  585. //}
  586. var havePower bool
  587. havePower = true
  588. //判断有没有对应的权限,如果没有则给出对应的状态码
  589. if havePower {
  590. resp.HasPermission = 1
  591. total, err := models.GetUserCygxActivitySpecialSignup(user.UserId, activityId)
  592. if err != nil {
  593. br.Msg = "获取信息失败"
  594. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  595. return
  596. }
  597. resp.SignupStatus = 1
  598. //判断是删除还是添加
  599. if total == 0 {
  600. //获取销售信息
  601. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  602. if err != nil {
  603. br.Msg = "操作失败"
  604. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  605. return
  606. }
  607. item := new(models.CygxActivitySpecialSignup)
  608. item.RegisterPlatform = utils.REGISTER_PLATFORM
  609. item.UserId = uid
  610. item.RealName = user.RealName
  611. item.ActivityId = activityId
  612. item.CreateTime = time.Now()
  613. item.Mobile = user.Mobile
  614. item.Email = user.Email
  615. item.CompanyId = user.CompanyId
  616. item.CompanyName = user.CompanyName
  617. if sellerItem != nil {
  618. item.SellerName = sellerItem.RealName
  619. }
  620. err = models.AddCygxActivitySpecialSignup(item)
  621. if err != nil {
  622. br.Msg = "操作失败"
  623. br.ErrMsg = "操作失败,Err:" + err.Error()
  624. return
  625. }
  626. resp.Status = 1
  627. resp.PopupMsg = "感谢反馈"
  628. resp.PopupMsg2 = "此调研具体行程尚未确认,待预报名人数满10人后弘则会确定行程并推送给您活动日期,只有在确认行程中再次报名才完成占位。"
  629. //给所属销售发送消息
  630. //if sellerItem.Mobile != "" {
  631. // openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  632. // if openIpItem != nil && openIpItem.OpenId != "" {
  633. // if sellerItem != nil {
  634. // //go services.SendSpecialTemplateMsg(user.RealName+"【"+user.CompanyName+"】", time.Now().Format(utils.FormatDateTime), user.Mobile, activityInfo.ResearchTheme, "sale", openIpItem)
  635. // }
  636. // }
  637. //}
  638. // 给芳姐发消息
  639. actList, _ := models.GetActivityListSpecialByActivityId(activityId)
  640. if len(actList) == 10 {
  641. go services.SendWxMsgActivitySpecial10(activityInfo)
  642. }
  643. //用户专项调研操作行为,模板消息推送
  644. //go services.SpecialActivityUserRemind(user, activityInfo, 1)
  645. } else {
  646. err = models.DeleteCygxActivitySpecialSignup(user.UserId, activityId)
  647. if err != nil {
  648. br.Msg = "操作失败"
  649. br.ErrMsg = "操作失败,Err:" + err.Error()
  650. return
  651. }
  652. resp.Status = 2
  653. }
  654. } else {
  655. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  656. if err != nil {
  657. br.Msg = "获取信息失败"
  658. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  659. return
  660. }
  661. resp.PopupMsg = popupMsg
  662. resp.HasPermission = hasPermission
  663. resp.SellerName = sellerName
  664. resp.SellerMobile = sellerMobile
  665. }
  666. br.Ret = 200
  667. br.Success = true
  668. br.Msg = "操作成功"
  669. br.Data = resp
  670. }
  671. // @Title 新调研通知取消跟添加
  672. // @Description 新调研通知取消跟添加接口
  673. // @Param request body models.ArticleCollectResp true "type json string"
  674. // @Success 200
  675. // @router /follow [post]
  676. func (this *ActivitySpecialController) SpecialMsg() {
  677. br := new(models.BaseResponse).Init()
  678. defer func() {
  679. this.Data["json"] = br
  680. this.ServeJSON()
  681. }()
  682. user := this.User
  683. if user == nil {
  684. br.Msg = "请重新登录"
  685. br.Ret = 408
  686. return
  687. }
  688. resp := new(models.ArticleCollectResp)
  689. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  690. if err != nil {
  691. br.Msg = "获取数据失败!"
  692. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  693. return
  694. }
  695. if count == 0 {
  696. item := new(models.CygxUserFollowSpecial)
  697. item.UserId = user.UserId
  698. item.RealName = user.RealName
  699. item.CreateTime = time.Now()
  700. item.Mobile = user.Mobile
  701. item.Email = user.Email
  702. item.CompanyId = user.CompanyId
  703. item.CompanyName = user.CompanyName
  704. item.CreateTime = time.Now()
  705. err := models.AddUserFollowSpecial(item)
  706. if err != nil {
  707. br.Msg = "操作失败!"
  708. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  709. return
  710. }
  711. resp.Status = 1
  712. } else {
  713. err := models.DeleteCygxUserFollowSpecial(user.UserId)
  714. if err != nil {
  715. br.Msg = "操作失败!"
  716. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  717. return
  718. }
  719. resp.Status = 2
  720. }
  721. br.Ret = 200
  722. br.Data = resp
  723. br.Success = true
  724. br.Msg = "操作成功!"
  725. }