GetOrderDetail.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const API = require("../../../lib/API")
  2. const db = require("../../../plugin/DataBase/db")
  3. const AccessControl = require("../../../lib/AccessControl")
  4. const { BaseStdResponse } = require("../../../BaseStdResponse")
  5. class GetOrderDetail extends API {
  6. constructor() {
  7. super()
  8. this.setPath('/Admin/Order/Detail')
  9. this.setMethod('get')
  10. }
  11. async onRequest(req, res) {
  12. const { uuid, session, orderId } = req.query
  13. if (!uuid || !session || !orderId) {
  14. return res.json({
  15. ...BaseStdResponse.MISSING_PARAMETER
  16. })
  17. }
  18. if (!await AccessControl.checkSession(uuid, session)) {
  19. return res.status(401).json({
  20. ...BaseStdResponse.ACCESS_DENIED
  21. })
  22. }
  23. let permission = await AccessControl.getPermission(uuid)
  24. if (!permission.includes("admin") && !permission.includes("product")) {
  25. return res.json({
  26. ...BaseStdResponse.PERMISSION_DENIED
  27. })
  28. }
  29. const sql = `
  30. SELECT
  31. o.orderId,
  32. o.create_time,
  33. o.pay_time,
  34. o.price,
  35. o.state,
  36. o.pay_id,
  37. o.pay_type,
  38. o.goods_id,
  39. o.create_user,
  40. g.name,
  41. g.content,
  42. g.icon,
  43. g.isHot,
  44. g.description,
  45. g.category,
  46. g.features,
  47. g.lepao_count,
  48. g.ic_count,
  49. g.vip,
  50. u.username,
  51. u.avatar,
  52. u.email AS user_email
  53. FROM
  54. orders o
  55. LEFT JOIN
  56. goods g ON o.goods_id = g.id
  57. LEFT JOIN
  58. users u ON o.create_user = u.uuid
  59. WHERE
  60. o.orderId = ?
  61. `
  62. const rows = await db.query(sql, [orderId])
  63. if (!rows || rows.length !== 1) {
  64. return res.json({
  65. ...BaseStdResponse.ERR,
  66. msg: '订单不存在'
  67. })
  68. }
  69. res.json({
  70. ...BaseStdResponse.OK,
  71. data: rows[0]
  72. })
  73. }
  74. }
  75. module.exports.GetOrderDetail = GetOrderDetail