package controller import ( "github.com/gin-gonic/gin" "kefu/models" "kefu/types" "strconv" ) // 查询订单 func PostQueryOrder(c *gin.Context) { orderId := c.PostForm("order_id") order := models.FindProductOrder("order_sn = ?", orderId) if order.PaymentStatus == "paid" { c.JSON(200, gin.H{ "code": types.ApiCode.SUCCESS, "msg": types.ApiCode.GetMessage(types.ApiCode.SUCCESS), "result": order.ShippingAddress, }) return } c.JSON(200, gin.H{ "code": types.ApiCode.FAILED, "msg": "unpaid", }) } // 产品订单列表 func GetUserProductOrder(c *gin.Context) { userId := c.Query("user_id") entId := c.Query("ent_id") page, _ := strconv.Atoi(c.Query("page")) if page <= 0 { page = 1 } pagesize, _ := strconv.Atoi(c.Query("pagesize")) if pagesize <= 0 || pagesize > 50 { pagesize = 10 } search := "1=1 " var args = []interface{}{} search += "and ent_id = ? " args = append(args, entId) search += "and user_id = ? " args = append(args, userId) search += "and payment_status = ? " args = append(args, "paid") count := models.CountProductOrders(search, args...) list := models.FindProductOrders(page, pagesize, search, args...) c.JSON(200, gin.H{ "code": types.ApiCode.SUCCESS, "msg": types.ApiCode.GetMessage(types.ApiCode.SUCCESS), "result": gin.H{ "list": list, "count": count, "pagesize": pagesize, "page": page, }, }) } // 产品订单列表 func GetProductOrderList(c *gin.Context) { entId, _ := c.Get("ent_id") roleId, _ := c.Get("role_id") page, _ := strconv.Atoi(c.Query("page")) if page <= 0 { page = 1 } pagesize, _ := strconv.Atoi(c.Query("pagesize")) if pagesize <= 0 || pagesize > 50 { pagesize = 10 } search := "1=1 " var args = []interface{}{} if roleId.(float64) != 1 { search += "and ent_id = ? " args = append(args, entId) } count := models.CountProductOrders(search, args...) list := models.FindProductOrders(page, pagesize, search, args...) c.JSON(200, gin.H{ "code": types.ApiCode.SUCCESS, "msg": types.ApiCode.GetMessage(types.ApiCode.SUCCESS), "result": gin.H{ "list": list, "count": count, "pagesize": pagesize, "page": page, }, }) } func GetOrders(c *gin.Context) { entId, _ := c.Get("ent_id") roleId, _ := c.Get("role_id") page, _ := strconv.Atoi(c.Query("page")) if page <= 0 { page = 1 } pagesize, _ := strconv.Atoi(c.Query("pagesize")) if pagesize <= 0 || pagesize > 50 { pagesize = 10 } search := "1=1 " var args = []interface{}{} if roleId.(float64) != 1 { search += "and ent_id = ? " args = append(args, entId) } count := models.CountUserOrder(search, args...) list := models.FindUserOrders(page, pagesize, search, args...) c.JSON(200, gin.H{ "code": types.ApiCode.SUCCESS, "msg": types.ApiCode.GetMessage(types.ApiCode.SUCCESS), "result": gin.H{ "list": list, "count": count, "pagesize": pagesize, "page": page, }, }) }