Order.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\presale\api\controller;
  13. use addon\presale\model\PresaleOrder;
  14. use addon\presale\model\PresaleOrderCommon;
  15. use app\api\controller\BaseApi;
  16. /**
  17. * 预售订单
  18. */
  19. class Order extends BaseApi
  20. {
  21. /**
  22. * 订单列表
  23. * @return false|string
  24. */
  25. public function page()
  26. {
  27. $token = $this->checkToken();
  28. if ($token[ 'code' ] < 0) return $this->response($token);
  29. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  30. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  31. $condition = [
  32. [ 'ppo.site_id', '=', $this->site_id ],
  33. [ 'ppo.member_id', '=', $this->member_id ]
  34. ];
  35. $order_status = isset($this->params[ 'order_status' ]) ? $this->params[ 'order_status' ] : '';
  36. if ($order_status !== '') {
  37. $condition[] = [ 'ppo.order_status', '=', $order_status ];
  38. }
  39. $presale_order_model = new PresaleOrder();
  40. $list = $presale_order_model->getPresaleOrderPageList($condition, $page, $page_size);
  41. if (!empty($list[ 'data' ][ 'list' ])) {
  42. foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
  43. $action = empty($v[ "order_status_action" ]) ? [] : json_decode($v[ "order_status_action" ], true);
  44. $member_action = $action[ "member_action" ] ?? [];
  45. $list[ 'data' ][ 'list' ][ $k ][ 'action' ] = $member_action;
  46. unset($list[ 'data' ][ 'list' ][ $k ][ 'order_status_action' ]);
  47. }
  48. }
  49. return $this->response($list);
  50. }
  51. /**
  52. * 订单详情
  53. */
  54. public function detail()
  55. {
  56. $token = $this->checkToken();
  57. if ($token[ 'code' ] < 0) return $this->response($token);
  58. $id = isset($this->params[ 'order_id' ]) ? $this->params[ 'order_id' ] : 0;
  59. if (empty($id)) {
  60. return $this->response($this->error('', '缺少必须参数order_id'));
  61. }
  62. $presale_order_model = new PresaleOrder();
  63. $condition = [
  64. [ 'id', '=', $id ],
  65. [ 'member_id', '=', $this->member_id ],
  66. ];
  67. $order_info = $presale_order_model->getPresaleOrderInfo($condition);
  68. if (!empty($order_info[ 'data' ])) {
  69. $action = empty($order_info[ 'data' ][ "order_status_action" ]) ? [] : json_decode($order_info[ 'data' ][ "order_status_action" ], true);
  70. $member_action = $action[ "member_action" ] ?? [];
  71. $order_info[ 'data' ][ 'action' ] = $member_action;
  72. unset($order_info[ 'data' ][ 'order_status_action' ]);
  73. }
  74. return $this->response($order_info);
  75. }
  76. /**
  77. * 关闭订单
  78. */
  79. public function close()
  80. {
  81. $token = $this->checkToken();
  82. if ($token[ 'code' ] < 0) return $this->response($token);
  83. $id = isset($this->params[ 'order_id' ]) ? $this->params[ 'order_id' ] : 0;
  84. if (empty($id)) {
  85. return $this->response($this->error('', '缺少必须参数order_id'));
  86. }
  87. $order_common_model = new PresaleOrderCommon();
  88. $condition = [
  89. [ 'id', '=', $id ],
  90. [ 'member_id', '=', $this->member_id ],
  91. ];
  92. $res = $order_common_model->depositOrderClose($condition);
  93. return $this->response($res);
  94. }
  95. /**
  96. * 删除订单
  97. */
  98. public function delete()
  99. {
  100. $token = $this->checkToken();
  101. if ($token[ 'code' ] < 0) return $this->response($token);
  102. $id = isset($this->params[ 'order_id' ]) ? $this->params[ 'order_id' ] : 0;
  103. if (empty($id)) {
  104. return $this->response($this->error('', '缺少必须参数order_id'));
  105. }
  106. $order_common_model = new PresaleOrderCommon();
  107. $condition = [
  108. [ 'id', '=', $id ],
  109. [ 'member_id', '=', $this->member_id ],
  110. ];
  111. $res = $order_common_model->deleteOrder($condition);
  112. return $this->response($res);
  113. }
  114. /**
  115. * 获取定金或尾款交易流水号
  116. */
  117. public function pay()
  118. {
  119. $token = $this->checkToken();
  120. if ($token[ 'code' ] < 0) return $this->response($token);
  121. $id = isset($this->params[ 'id' ]) ? $this->params[ 'id' ] : ''; //预售订单id
  122. $order_common_model = new PresaleOrderCommon();
  123. $res = $order_common_model->getPresaleOrderOutTradeNo($id, $this->member_id, $this->site_id);
  124. return $this->response($res);
  125. }
  126. }