order.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/ep/melloi/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/binding"
  8. )
  9. func queryOrder(c *bm.Context) {
  10. qor := model.QueryOrderRequest{}
  11. if err := c.BindWith(&qor, binding.Form); err != nil {
  12. c.JSON(nil, err)
  13. return
  14. }
  15. if err := qor.Verify(); err != nil {
  16. c.JSON(nil, err)
  17. return
  18. }
  19. c.JSON(srv.QueryOrder(&qor))
  20. }
  21. func addOrder(c *bm.Context) {
  22. order := model.Order{}
  23. if err := c.BindWith(&order, binding.JSON); err != nil {
  24. c.JSON(nil, err)
  25. return
  26. }
  27. c.JSON(nil, srv.AddOrder(&order))
  28. }
  29. func updateOrder(c *bm.Context) {
  30. order := model.Order{}
  31. if err := c.BindWith(&order, binding.JSON); err != nil {
  32. c.JSON(nil, err)
  33. return
  34. }
  35. c.JSON(nil, srv.UpdateOrder(&order))
  36. }
  37. func delOrder(c *bm.Context) {
  38. v := new(struct {
  39. ID int64 `form:"id"`
  40. })
  41. if err := c.Bind(v); err != nil {
  42. c.JSON(nil, ecode.RequestErr)
  43. return
  44. }
  45. c.JSON(nil, srv.DelOrder(v.ID))
  46. }
  47. func addOrderReport(c *bm.Context) {
  48. report := new(model.OrderReport)
  49. if err := c.BindWith(&report, binding.JSON); err != nil {
  50. c.JSON(nil, err)
  51. return
  52. }
  53. nameStr := ""
  54. if username, err := c.Request.Cookie("username"); err == nil || username != nil {
  55. nameStr = username.Value
  56. }
  57. c.JSON(nil, srv.AddReport(nameStr, report))
  58. }
  59. func queryOrderReport(c *bm.Context) {
  60. params := c.Request.Form
  61. orderID := params.Get("order_id")
  62. oid, err := strconv.ParseInt(orderID, 10, 64)
  63. if err != nil || oid <= 0 {
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. c.JSON(srv.QueryReportByOrderID(oid))
  68. }