123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package order
- import (
- "eta/eta_mini_ht_api/common/exception"
- "eta/eta_mini_ht_api/common/utils/page"
- "eta/eta_mini_ht_api/controllers"
- "eta/eta_mini_ht_api/service/order"
- "eta/eta_mini_ht_api/service/user"
- )
- type OrderController struct {
- controllers.BaseController
- }
- type PreviewOrderRequest struct {
- ProductId int `json:"productId"`
- }
- // PreviewProductOrder 预览订单
- // @Summary 预览订单
- // @Description 预览订单
- // @Success 200 {object} controllers.BaseResponse
- // @router /previewProductOrder [get]
- func (o *OrderController) PreviewProductOrder(productId int) {
- controllers.Wrap(&o.BaseController, func() (result *controllers.WrapData, err error) {
- result = o.InitWrapData("预览订单创建失败")
- var userInfo user.User
- userInfo = o.Data["user"].(user.User)
- if productId <= 0 {
- err = exception.New(exception.IllegalProductId)
- o.FailedResult("预览订单失败,产品编号非法", result)
- return
- }
- //创单
- //返回订单信息、商品信息
- orderInfo, err := order.PreViewProductOrder(userInfo, productId)
- if err != nil {
- o.FailedResult("创建预览订单失败", result)
- return
- }
- o.SuccessResult("预览订单创建成功", orderInfo, result)
- return
- })
- }
- // OrderDetail 获取订单详情
- // @Summary 获取订单详情
- // @Description 获取订单详情
- // @Success 200 {object} controllers.BaseResponse
- // @router /orderDetail [get]
- func (sc *SubscribeController) GetOrderDetail(orderNo string) {
- controllers.Wrap(&sc.BaseController, func() (result *controllers.WrapData, err error) {
- result = sc.InitWrapData("获取订单号失败")
- userInfo := sc.Data["user"].(user.User)
- if orderNo == "" {
- err = exception.New(exception.IllegalProductOrderId)
- sc.FailedResult("获取订单详情失败,产品编号非法", result)
- return
- }
- orderDetail, err := order.GetOrderDetail(orderNo, userInfo.Id)
- if err != nil {
- sc.FailedResult("获取订单详情失败", result)
- err = exception.NewWithException(exception.GetOrderListFailed, err.Error())
- return
- }
- sc.SuccessResult("获取订单详情成功", orderDetail, result)
- return
- })
- }
- // GetOrderList 获取用户订单号列表
- // @Summary 获取用户订单号列表
- // @Description 获取用户订单号列表
- // @Success 200 {object} controllers.BaseResponse
- // @router /orderList [get]
- func (sc *SubscribeController) GetOrderList(orderStatus string) {
- controllers.Wrap(&sc.BaseController, func() (result *controllers.WrapData, err error) {
- result = sc.InitWrapData("分页查询订单列表失败")
- userInfo := sc.Data["user"].(user.User)
- pageRes := page.Page{
- Current: sc.PageInfo.Current,
- PageSize: sc.PageInfo.PageSize,
- }
- pageRes.Total, pageRes.LatestId = order.GetTotalPageCountByUserId(userInfo.Id, orderStatus)
- if sc.PageInfo.LatestId == 0 {
- sc.PageInfo.LatestId = pageRes.LatestId
- } else {
- pageRes.LatestId = sc.PageInfo.LatestId
- pageRes.Total = sc.PageInfo.Total
- }
- pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
- list, err := order.GetOrderPage(sc.PageInfo, userInfo.Id, orderStatus)
- if err != nil {
- sc.FailedResult("分页查询订单列表失败", result)
- return
- }
- orders := new(page.PageResult)
- orders.Data = list
- orders.Page = pageRes
- sc.SuccessResult("查询订单列表成功", orders, result)
- return
- })
- }
- type OrderRequest struct {
- ProductOrderNo string `json:"productOrderNo"`
- }
- // CloseOrder 获取用户订单号列表
- // @Summary 获取用户订单号列表
- // @Description 获取用户订单号列表
- // @Success 200 {object} controllers.BaseResponse
- // @router /closeOrder [post]
- func (sc *SubscribeController) CloseOrder() {
- controllers.Wrap(&sc.BaseController, func() (result *controllers.WrapData, err error) {
- result = sc.InitWrapData("关闭订单失败")
- userInfo := sc.Data["user"].(user.User)
- orderReq := new(OrderRequest)
- sc.GetPostParams(orderReq)
- if orderReq.ProductOrderNo == "" {
- sc.FailedResult("关闭订单失败,非法的订单编号", result)
- err = exception.New(exception.IllegalOrderNo)
- return
- }
- err = order.CloseProductOrder(userInfo.Id, orderReq.ProductOrderNo)
- if err != nil {
- sc.FailedResult("关闭订单失败", result)
- err = exception.NewWithException(exception.CloseOrderFailed, err.Error())
- return
- }
- closeDTO := map[string]string{
- "orderNo": orderReq.ProductOrderNo,
- }
- sc.SuccessResult("关闭订单成功", closeDTO, result)
- return
- })
- }
|