order.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_web_mfyx/models"
  6. "hongze/hongze_web_mfyx/models/order"
  7. "hongze/hongze_web_mfyx/services"
  8. "hongze/hongze_web_mfyx/utils"
  9. "strings"
  10. "time"
  11. )
  12. // 订单
  13. type OrderController struct {
  14. BaseAuthController
  15. }
  16. // @Title 通过文章创建订单
  17. // @Description 通过文章创建订单接口
  18. // @Param request body models.ActivitySingnupRep true "type json string"
  19. // @Success Ret=200 {object} models.SignupStatus
  20. // @router /addByArticle [post]
  21. func (this *OrderController) AddByArticle() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. user := this.User
  28. if user == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,用户信息为空"
  31. br.Ret = 408
  32. return
  33. }
  34. var req order.CygxOrderAddReq
  35. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  36. if err != nil {
  37. br.Msg = "参数解析异常!"
  38. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  39. return
  40. }
  41. uid := user.UserId
  42. goodsId := req.GoodsId
  43. sourceId := req.SourceId
  44. if goodsId == 0 {
  45. br.Msg = "支付失败"
  46. br.ErrMsg = "支付失败,goodsId 信息错误Err:" + err.Error()
  47. return
  48. }
  49. goodsDetail, err := order.GetCygxGoodsDetailByGoodsId(goodsId)
  50. if err != nil {
  51. br.Msg = "获取信息失败"
  52. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  53. return
  54. }
  55. var title string
  56. oldOrderCode := services.GetHaverEquallyOrderByUser10Min(uid, goodsId) //获取用户十分钟之内是否有相同的订单信息
  57. articleDetail, err := models.GetArticleDetailById(sourceId)
  58. if err != nil {
  59. br.Msg = "获取信息失败"
  60. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  61. return
  62. }
  63. title = articleDetail.Title
  64. item := new(order.CygxOrder)
  65. item.OrderCode = utils.GetOrdernum()
  66. item.OutTradeNo = "TRADE" + item.OrderCode
  67. item.GoodsName = goodsDetail.GoodsName
  68. item.GoodsId = goodsId
  69. item.GoodsMoney = goodsDetail.Price
  70. item.OrderMoney = goodsDetail.CurrentPrice
  71. item.SourceId = sourceId
  72. item.Source = utils.CYGX_OBJ_ARTICLE
  73. item.SourceTitle = title
  74. item.UserId = user.UserId
  75. item.Mobile = user.Mobile
  76. item.Email = user.Email
  77. item.CompanyId = user.CompanyId
  78. item.CompanyName = user.CompanyName
  79. item.RealName = user.RealName
  80. item.SellerName, item.SellerId = services.GetSellerName(user) // 销售姓名
  81. item.ShareName, item.ShareId = services.GetAdminByInviteShareCode(req.InviteShareCode) // 分享人信息
  82. item.CreateTime = time.Now()
  83. item.ModifyTime = time.Now()
  84. item.RegisterPlatform = utils.REGISTER_PLATFORM
  85. item.OrderType = 1
  86. //如果十分钟之内有相同的订单就修改,没有就新增
  87. if oldOrderCode == "" {
  88. err = order.AddCygxOrder(item)
  89. } else {
  90. item.OrderCode = oldOrderCode
  91. err = order.UpdateCygxOrder(item, oldOrderCode)
  92. }
  93. if err != nil {
  94. br.Msg = "创建订单信息失败"
  95. br.ErrMsg = "创建订单信息失败,Err:" + err.Error()
  96. return
  97. }
  98. codeUrl, err := services.ExampleNativeApiServicePrepay(item)
  99. if err != nil {
  100. br.Msg = "创建订单信息失败"
  101. br.ErrMsg = "创建订单信息失败,ExampleNativeApiServicePrepay:" + err.Error()
  102. return
  103. }
  104. resp := new(order.WxNativeApiResp)
  105. _, resp.PayTimeCountdown = services.GetHaverEquallyOrderByUser10MinByArticle(uid, sourceId, goodsId) //截止支付时间倒计时
  106. resp.CodeUrl = codeUrl
  107. resp.OrderCode = item.OrderCode
  108. br.Data = resp
  109. br.Ret = 200
  110. br.Success = true
  111. br.Msg = "操作成功"
  112. }
  113. // @Title 通过活动创建订单
  114. // @Description 通过活动创建订单接口
  115. // @Param request body models.ActivitySingnupRep true "type json string"
  116. // @Success Ret=200 {object} models.SignupStatus
  117. // @router /addByActivity [post]
  118. func (this *OrderController) AddByActivity() {
  119. br := new(models.BaseResponse).Init()
  120. defer func() {
  121. this.Data["json"] = br
  122. this.ServeJSON()
  123. }()
  124. user := this.User
  125. if user == nil {
  126. br.Msg = "请登录"
  127. br.ErrMsg = "请登录,用户信息为空"
  128. br.Ret = 408
  129. return
  130. }
  131. var req order.CygxOrderAddReq
  132. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  133. if err != nil {
  134. br.Msg = "参数解析异常!"
  135. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  136. return
  137. }
  138. uid := user.UserId
  139. goodsId := req.GoodsId
  140. sourceId := req.SourceId
  141. source := req.Source
  142. if goodsId == 0 {
  143. br.Msg = "支付失败"
  144. br.ErrMsg = "支付失败,goodsId 信息错误Err:" + err.Error()
  145. return
  146. }
  147. goodsDetail, err := order.GetCygxGoodsDetailByGoodsId(goodsId)
  148. if err != nil {
  149. br.Msg = "获取信息失败"
  150. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  151. return
  152. }
  153. activityDetail, err := models.GetAddActivityInfoById(sourceId)
  154. if err != nil {
  155. br.Msg = "获取信息失败"
  156. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  157. return
  158. }
  159. var title string
  160. var oldOrderCode string
  161. var payTimeCountdown int
  162. //var _ int
  163. item := new(order.CygxOrder)
  164. if source == "ActivityVivo" {
  165. oldOrderCode, payTimeCountdown = services.GetHaverEquallyOrderByUser10MinByActivtyVivo(uid, sourceId)
  166. item.OrderType = 3
  167. } else {
  168. if (!activityDetail.IsResearchPoints && activityDetail.IsLimitPeople == 0) || activityDetail.YidongActivityId != "" { //易董的活动 或者(不扣点且不限制人数)走月卡日卡逻辑
  169. oldOrderCode = services.GetHaverEquallyOrderByUser10Min(uid, goodsId) //获取用户十分钟之内是否有相同的订单信息
  170. item.OrderType = 1
  171. } else {
  172. oldOrderCode, payTimeCountdown = services.GetHaverEquallyOrderByUser10MinByActivty(uid, sourceId)
  173. item.OrderType = 2
  174. }
  175. }
  176. title = activityDetail.ActivityName
  177. item.OrderCode = utils.GetOrdernum()
  178. item.OutTradeNo = "TRADE" + item.OrderCode
  179. if activityDetail.ActivityTypeName == "买方线下交流" {
  180. item.GoodsName = "买方交流"
  181. }
  182. if activityDetail.ActivityTypeName == "专家电话会" || activityDetail.ActivityTypeName == "专家线下沙龙" {
  183. item.GoodsName = "专家调研"
  184. }
  185. if activityDetail.ActivityTypeName == "公司调研电话会" {
  186. item.GoodsName = "上市公司小范围"
  187. }
  188. switch goodsId {
  189. case 1:
  190. item.GoodsName = "日卡"
  191. case 2:
  192. item.GoodsName = "月卡"
  193. case 9:
  194. item.GoodsName = "活动回放"
  195. }
  196. //如果活动有自定义的价格就优先按照自定义的价格来
  197. if activityDetail.ActivityPrice > 0 {
  198. goodsDetail.CurrentPrice = activityDetail.ActivityPrice
  199. }
  200. //fmt.Println("item.GoodsName", item.GoodsName)
  201. //return
  202. item.GoodsId = goodsId
  203. item.GoodsMoney = goodsDetail.Price
  204. item.OrderMoney = goodsDetail.CurrentPrice
  205. item.SourceId = sourceId
  206. item.Source = utils.CYGX_OBJ_ACTIVITY
  207. item.SourceTitle = title
  208. item.UserId = user.UserId
  209. item.Mobile = user.Mobile
  210. item.Email = user.Email
  211. item.CompanyId = user.CompanyId
  212. item.CompanyName = user.CompanyName
  213. item.RealName = user.RealName
  214. item.SellerName, item.SellerId = services.GetSellerName(user) // 销售姓名
  215. item.ShareName, item.ShareId = services.GetAdminByInviteShareCode(req.InviteShareCode) // 分享人信息
  216. item.CreateTime = time.Now()
  217. item.ModifyTime = time.Now()
  218. item.RegisterPlatform = utils.REGISTER_PLATFORM
  219. //如果是音视频的订单,数据做二次处理
  220. if source == "ActivityVivo" {
  221. vivoPointsSetDetail, err := models.GetCygxActivityVivoPointsSetByActivityId(sourceId)
  222. if err != nil {
  223. br.Msg = "获取信息失败"
  224. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  225. return
  226. }
  227. item.GoodsMoney = vivoPointsSetDetail.GoodsMoney
  228. item.OrderMoney = vivoPointsSetDetail.GoodsMoney
  229. item.Source = vivoPointsSetDetail.Source
  230. if vivoPointsSetDetail.Source == utils.CYGX_OBJ_ACTIVITYVIDEO {
  231. activityVideoInfo, err := models.GetCygxActivityVideoByActivityId(sourceId)
  232. if err != nil {
  233. br.Msg = "获取信息失败"
  234. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  235. return
  236. }
  237. title = activityVideoInfo.VideoName
  238. } else if vivoPointsSetDetail.Source == utils.CYGX_OBJ_ACTIVITYVOICE {
  239. activityVoiceInfo, err := models.GetCygxActivityVoiceByActivityId(sourceId)
  240. if err != nil {
  241. br.Msg = "获取信息失败"
  242. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  243. return
  244. }
  245. title = activityVoiceInfo.VoiceName
  246. } else {
  247. br.Msg = "获取信息失败"
  248. br.ErrMsg = "获取信息失败,音视频数据类型错误"
  249. return
  250. }
  251. item.SourceTitle = title
  252. }
  253. //如果十分钟之内有相同的订单就修改,没有就新增
  254. if oldOrderCode == "" {
  255. err = order.AddCygxOrder(item)
  256. } else {
  257. item.OrderCode = oldOrderCode
  258. err = order.UpdateCygxOrder(item, oldOrderCode)
  259. }
  260. codeUrl, err := services.ExampleNativeApiServicePrepay(item)
  261. if err != nil {
  262. br.Msg = "创建订单信息失败"
  263. br.ErrMsg = "创建订单信息失败,ExampleNativeApiServicePrepay:" + err.Error()
  264. return
  265. }
  266. resp := new(order.WxNativeApiResp)
  267. resp.PayTimeCountdown = payTimeCountdown //截止支付时间倒计时
  268. resp.CodeUrl = codeUrl
  269. resp.OrderCode = item.OrderCode
  270. br.Data = resp
  271. br.Ret = 200
  272. br.Success = true
  273. br.Msg = "操作成功"
  274. }
  275. // @Title 通过研选专栏创建订单
  276. // @Description 通过文章创建订单接口
  277. // @Param request body models.ActivitySingnupRep true "type json string"
  278. // @Success Ret=200 {object} models.SignupStatus
  279. // @router /addByYanxuanspecial [post]
  280. func (this *OrderController) AddByYanxuanspecial() {
  281. br := new(models.BaseResponse).Init()
  282. defer func() {
  283. this.Data["json"] = br
  284. this.ServeJSON()
  285. }()
  286. user := this.User
  287. if user == nil {
  288. br.Msg = "请登录"
  289. br.ErrMsg = "请登录,用户信息为空"
  290. br.Ret = 408
  291. return
  292. }
  293. var req order.CygxOrderAddReq
  294. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  295. if err != nil {
  296. br.Msg = "参数解析异常!"
  297. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  298. return
  299. }
  300. uid := user.UserId
  301. goodsId := req.GoodsId
  302. sourceId := req.SourceId
  303. if goodsId == 0 {
  304. br.Msg = "支付失败"
  305. br.ErrMsg = "支付失败,goodsId 信息错误Err:" + err.Error()
  306. return
  307. }
  308. goodsDetail, err := order.GetCygxGoodsDetailByGoodsId(goodsId)
  309. if err != nil {
  310. br.Msg = "获取信息失败"
  311. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  312. return
  313. }
  314. var title string
  315. oldOrderCode := services.GetHaverEquallyOrderByUser10Min(uid, goodsId) //获取用户十分钟之内是否有相同的订单信息
  316. // 研选专栏
  317. yanxuanSpecialBySpeciaDetail, err := models.GetYanxuanSpecialBySpecialId(sourceId)
  318. if err != nil {
  319. br.Msg = "获取信息失败"
  320. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  321. return
  322. }
  323. title = yanxuanSpecialBySpeciaDetail.Title
  324. item := new(order.CygxOrder)
  325. item.OrderCode = utils.GetOrdernum()
  326. item.OutTradeNo = "TRADE" + item.OrderCode
  327. item.GoodsName = goodsDetail.GoodsName
  328. item.GoodsId = goodsId
  329. item.GoodsMoney = goodsDetail.Price
  330. item.OrderMoney = goodsDetail.CurrentPrice
  331. item.SourceId = sourceId
  332. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  333. item.SourceTitle = title
  334. item.UserId = user.UserId
  335. item.Mobile = user.Mobile
  336. item.Email = user.Email
  337. item.CompanyId = user.CompanyId
  338. item.CompanyName = user.CompanyName
  339. item.RealName = user.RealName
  340. item.SellerName, item.SellerId = services.GetSellerName(user) // 销售姓名
  341. item.ShareName, item.ShareId = services.GetAdminByInviteShareCode(req.InviteShareCode) // 分享人信息
  342. item.CreateTime = time.Now()
  343. item.ModifyTime = time.Now()
  344. item.RegisterPlatform = utils.REGISTER_PLATFORM
  345. item.OrderType = 1
  346. //如果十分钟之内有相同的订单就修改,没有就新增
  347. if oldOrderCode == "" {
  348. err = order.AddCygxOrder(item)
  349. } else {
  350. item.OrderCode = oldOrderCode
  351. err = order.UpdateCygxOrder(item, oldOrderCode)
  352. }
  353. if err != nil {
  354. br.Msg = "创建订单信息失败"
  355. br.ErrMsg = "创建订单信息失败,Err:" + err.Error()
  356. return
  357. }
  358. codeUrl, err := services.ExampleNativeApiServicePrepay(item)
  359. if err != nil {
  360. br.Msg = "创建订单信息失败"
  361. br.ErrMsg = "创建订单信息失败,ExampleNativeApiServicePrepay:" + err.Error()
  362. return
  363. }
  364. resp := new(order.WxNativeApiResp)
  365. _, resp.PayTimeCountdown = services.GetHaverEquallyOrderByUser10MinByArticle(uid, sourceId, goodsId) //截止支付时间倒计时
  366. resp.CodeUrl = codeUrl
  367. resp.OrderCode = item.OrderCode
  368. br.Data = resp
  369. br.Ret = 200
  370. br.Success = true
  371. br.Msg = "操作成功"
  372. }
  373. // @Title 用户订单列表
  374. // @Description 用户订单列表接口
  375. // @Param PageSize query int true "每页数据条数"
  376. // @Param CurrentIndex query int true "当前页页码,从1开始"
  377. // @Param OrderType query int false "订单类型 1:畅读卡订单,2:单场付费订单"
  378. // @Success 200 {object} models.SpecialListResp
  379. // @router /user/orderList [get]
  380. func (this *OrderController) UserOrderList() {
  381. br := new(models.BaseResponse).Init()
  382. defer func() {
  383. this.Data["json"] = br
  384. this.ServeJSON()
  385. }()
  386. user := this.User
  387. if user == nil {
  388. br.Msg = "请登录"
  389. br.ErrMsg = "请登录,用户信息为空"
  390. br.Ret = 408
  391. return
  392. }
  393. pageSize, _ := this.GetInt("PageSize")
  394. currentIndex, _ := this.GetInt("CurrentIndex")
  395. orderType, _ := this.GetInt("OrderType", 1)
  396. var startSize int
  397. if pageSize <= 0 {
  398. pageSize = utils.PageSize20
  399. }
  400. if currentIndex <= 0 {
  401. currentIndex = 1
  402. }
  403. startSize = utils.StartIndex(currentIndex, pageSize)
  404. resp := new(order.UserOrderListResp)
  405. var condition string
  406. var pars []interface{}
  407. userId := user.UserId
  408. if orderType > 0 {
  409. condition += ` AND order_type = ? `
  410. pars = append(pars, orderType)
  411. }
  412. condition += ` AND user_id = ? `
  413. pars = append(pars, userId)
  414. total, err := order.GetCygxOrderCount(condition, pars)
  415. if err != nil {
  416. br.Msg = "获取失败"
  417. br.ErrMsg = "获取失败, Err:" + err.Error()
  418. return
  419. }
  420. condition += ` ORDER BY order_id DESC `
  421. list, err := order.GetCygxOrderList(condition, pars, startSize, pageSize)
  422. if err != nil {
  423. br.Msg = "获取失败"
  424. br.ErrMsg = "获取失败, Err:" + err.Error()
  425. return
  426. }
  427. var activityIds []int
  428. //音视频时长
  429. var activityVivoIds []int
  430. for _, v := range list {
  431. if v.Source == utils.CYGX_OBJ_ACTIVITY {
  432. activityIds = append(activityIds, v.SourceId)
  433. }
  434. if v.OrderType == 3 {
  435. activityVivoIds = append(activityVivoIds, v.SourceId)
  436. }
  437. }
  438. mapActivityVivo := services.GetActivityVivoByActivityIds(activityVivoIds)
  439. activityLabelKeyword := services.GetActivityOrderListLabelKeywordByActivityIds(activityIds)
  440. for _, v := range list {
  441. item := new(order.OrderListResp)
  442. item.OrderCode = v.OrderCode
  443. item.OrderMoney = v.OrderMoney
  444. item.SourceId = v.SourceId
  445. item.Source = v.Source
  446. item.SourceTitle = v.SourceTitle
  447. item.OrderStatus = v.OrderStatus
  448. switch item.OrderStatus {
  449. case 0:
  450. item.OrderStatusText = "已取消"
  451. case 1:
  452. item.OrderStatusText = "待支付"
  453. case 2:
  454. item.OrderStatusText = "支付成功"
  455. case 3:
  456. item.OrderStatusText = "转入退款"
  457. case 4:
  458. item.OrderStatusText = "退款处理中"
  459. case 5:
  460. item.OrderStatusText = "退款异常"
  461. case 6:
  462. item.OrderStatusText = "退款关闭"
  463. }
  464. if orderType == 1 {
  465. if v.GoodsId == 1 {
  466. item.LabelKeywordImgLink = utils.LABEL_ICO_7 //日卡图标
  467. item.LabelKeyword = "畅读日卡" //日卡图标
  468. item.StartDate = v.StartDate.Format(utils.FormatDateTime)
  469. item.EndDate = v.EndDate.Format(utils.FormatDateTime)
  470. } else if v.GoodsId == 2 {
  471. item.LabelKeywordImgLink = utils.LABEL_ICO_8 // 月卡图标
  472. item.LabelKeyword = "畅读月卡" //日卡图标
  473. item.StartDate = v.StartDate.Format(utils.FormatDate)
  474. item.EndDate = v.EndDate.Format(utils.FormatDate)
  475. }
  476. } else if orderType == 2 {
  477. item.LabelKeywordImgLink = utils.LABEL_ICO_3
  478. item.LabelKeyword = activityLabelKeyword[v.SourceId]
  479. } else if orderType == 3 {
  480. item.LabelKeyword = "活动回放" //日卡图标
  481. }
  482. if v.OrderType == 3 {
  483. item.PlaySeconds = mapActivityVivo[v.SourceId]
  484. }
  485. item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  486. resp.List = append(resp.List, item)
  487. }
  488. page := paging.GetPaging(currentIndex, pageSize, total)
  489. resp.Paging = page
  490. br.Data = resp
  491. br.Ret = 200
  492. br.Success = true
  493. br.Msg = "获取成功"
  494. }
  495. // @Title 订单支付详情
  496. // @Description 订单支付详情接口
  497. // @Param OrderCode query string false "订单号"
  498. // @Success 200 {object} models.SpecialListResp
  499. // @router /orderPay/detail [get]
  500. func (this *OrderController) OrderDetail() {
  501. br := new(models.BaseResponse).Init()
  502. defer func() {
  503. this.Data["json"] = br
  504. this.ServeJSON()
  505. }()
  506. user := this.User
  507. if user == nil {
  508. br.Msg = "请登录"
  509. br.ErrMsg = "请登录,用户信息为空"
  510. br.Ret = 408
  511. return
  512. }
  513. resp := new(order.PayEdOrderDetailResp)
  514. orderCode := this.GetString("OrderCode")
  515. orderDetail, err := order.GetCygxOrderDetailByOrderCode(orderCode)
  516. if err != nil {
  517. br.Msg = "获取失败"
  518. br.ErrMsg = "获取失败, Err:" + err.Error()
  519. return
  520. }
  521. if orderDetail.OrderType == 1 && orderDetail.OrderStatus == 2 {
  522. cardDetail, err := order.GetCygxOrderUserCardDetailByOrderCode(orderCode)
  523. if err != nil {
  524. br.Msg = "获取失败"
  525. br.ErrMsg = "获取失败, Err:" + err.Error()
  526. return
  527. }
  528. resp.EndDate = strings.Replace(cardDetail.EndDate.Format(utils.FormatDateTime), "00:00:00", "", -1)
  529. }
  530. resp.OrderCode = orderDetail.OrderCode
  531. resp.OrderType = orderDetail.OrderType
  532. resp.OrderStatus = orderDetail.OrderStatus
  533. resp.Source = orderDetail.Source
  534. resp.SourceId = orderDetail.SourceId
  535. if orderDetail.Source == utils.CYGX_OBJ_ACTIVITY {
  536. resp.IsPublicActivitie, resp.IsSignUp = services.GetActivityWechatPayMsg(orderDetail.SourceId) //如果是活动就要判断是否是公开活动,是否需要自动报名
  537. }
  538. br.Data = resp
  539. br.Ret = 200
  540. br.Success = true
  541. br.Msg = "获取成功"
  542. }
  543. // @Title 取消订单
  544. // @Description 取消订单接口
  545. // @Param request body models.ActivitySingnupRep true "type json string"
  546. // @Success Ret=200 {object} models.SignupStatus
  547. // @router /cancel [post]
  548. func (this *OrderController) Cancel() {
  549. br := new(models.BaseResponse).Init()
  550. defer func() {
  551. this.Data["json"] = br
  552. this.ServeJSON()
  553. }()
  554. user := this.User
  555. if user == nil {
  556. br.Msg = "请登录"
  557. br.ErrMsg = "请登录,用户信息为空"
  558. br.Ret = 408
  559. return
  560. }
  561. var req order.CygxOrderCancelReq
  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. orderCode := req.OrderCode
  569. orderDetail, err := order.GetCygxOrderDetailByOrderCode(orderCode)
  570. if err != nil {
  571. br.Msg = "获取失败"
  572. br.ErrMsg = "获取失败, Err:" + err.Error()
  573. return
  574. }
  575. err = order.CancelCygxOrder(orderDetail)
  576. if err != nil {
  577. br.Msg = "取消订单失败"
  578. br.ErrMsg = "获取失败, Err:" + err.Error()
  579. return
  580. }
  581. go services.ExampleJsapiApiService_CloseOrder(orderDetail.OutTradeNo)
  582. br.Ret = 200
  583. br.Success = true
  584. br.Msg = "操作成功"
  585. }