order.go 18 KB

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