package course import ( "encoding/json" "errors" "net/http" "spaceofcheng/services/models/model" "spaceofcheng/services/utils" ) // 下单 func (c *CourseController) PostOrder() { // 订单主信息 info := c.GetString("info") if info == "" { c.ResponseError(errors.New("无有效订单信息")) } var orderInfo model.TaCourseOrders // var orderCoupon []model.TaCourseOrdersCoupon if err := json.Unmarshal([]byte(info), &orderInfo); err != nil { utils.LogError("下单转换JSON失败: " + err.Error()) c.ResponseError(errors.New("下单数据格式不正确")) } // if err := json.Unmarshal([]byte(coupons), &orderCoupon); err != nil { // utils.LogError("下单优惠转换JSON失败: " + err.Error()) // c.ResponseError(errors.New("优惠数据格式不正确")) // } cust := c.Context.Get("customer").(model.TaCustomer) if cust.Phone == "" { c.ResponseError( errors.New("用户未登录或绑定"), http.StatusNotAcceptable, ) } newOrders, err := c.serv.PreOrders(&orderInfo) if err != nil { c.ResponseError(err) } c.ResponseJSON(newOrders) } // ConfirmOrders 确认订单 func (c *CourseController) ConfirmOrders() { // 订单优惠券 customercouponid := c.GetString("customercouponid") // 订单id ordersid := c.GetString(":ordersid") err := c.serv.ConfirmOrders(ordersid, customercouponid) if err != nil { c.ResponseError(err) } c.ResponseJSON("下单成功!") }