OrderController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\OrderValidator;
  5. use App\Services\Api\MemberService;
  6. use App\Services\Api\OrderService;
  7. use App\Services\Kd100Service;
  8. /**
  9. * 订单
  10. * @package App\Http\Controllers\Api
  11. */
  12. class OrderController extends webApp
  13. {
  14. /**
  15. * 列表
  16. * @return array
  17. */
  18. public function index()
  19. {
  20. $params = request()->post();
  21. $pageSize = request()->post('pageSize', 15);
  22. $params['user_id'] = $this->userId;
  23. $datas = OrderService::make()->getDataList($params, $pageSize);
  24. return message(1010, true, $datas);
  25. }
  26. /**
  27. * 验证订单状态
  28. * @return array
  29. */
  30. public function check()
  31. {
  32. if ($data = OrderService::make()->checkOrderStatus($this->userId)) {
  33. return showJson(1010, true, $data);
  34. } else {
  35. return showJson(1009, false);
  36. }
  37. }
  38. /**
  39. * 数量
  40. * @return array
  41. */
  42. public function count()
  43. {
  44. $status = request()->post('status', 1);
  45. $data = OrderService::make()->getCountByStatus($this->userId, $status);
  46. return showJson(1010, true, $data);
  47. }
  48. /**
  49. * 详情
  50. * @return array|mixed
  51. */
  52. public function info()
  53. {
  54. $params = request()->all();
  55. $id = isset($params['id']) ? intval($params['id']) : 0;
  56. $no = isset($params['order_no']) ? trim($params['order_no']) : '';
  57. if ($id <= 0 && empty($no)) {
  58. return showJson(1036, false);
  59. }
  60. $data = OrderService::make()->getOrderInfo($id, $no);
  61. if (empty($data)) {
  62. return showJson(1009, false);
  63. }
  64. return showJson(1010, true, $data);
  65. }
  66. /**
  67. * 下单
  68. * @param OrderValidator $validator
  69. * @return array
  70. */
  71. public function submit(OrderValidator $validator)
  72. {
  73. $params = request()->all();
  74. $params = $validator->check($params, 'submit');
  75. if (!is_array($params)) {
  76. return showJson($params, false);
  77. }
  78. try {
  79. if (!$result = OrderService::make()->createOrder($this->userId, $params)) {
  80. $error = OrderService::make()->getError();
  81. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  82. } else {
  83. return showJson(OrderService::make()->getError(), true, $result);
  84. }
  85. } catch (\Exception $exception) {
  86. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  87. return showJson(1046, false, $error);
  88. }
  89. }
  90. /**
  91. * 支付
  92. * @return array
  93. */
  94. public function pay()
  95. {
  96. $params = request()->all();
  97. $id = isset($params['id'])? $params['id'] : 0;
  98. try {
  99. if (!$result = OrderService::make()->pay($this->userId, $id)) {
  100. $error = OrderService::make()->getError();
  101. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  102. } else {
  103. return showJson(OrderService::make()->getError(), true, $result);
  104. }
  105. } catch (\Exception $exception) {
  106. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  107. return showJson(1046, false, $error);
  108. }
  109. }
  110. /**
  111. * 取消
  112. * @return array
  113. */
  114. public function cancel()
  115. {
  116. $params = request()->all();
  117. $id = isset($params['id'])? $params['id'] : 0;
  118. try {
  119. if (!$result = OrderService::make()->cancel($this->userId, $id)) {
  120. $error = OrderService::make()->getError();
  121. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  122. } else {
  123. return showJson(1002, true, $result);
  124. }
  125. } catch (\Exception $exception) {
  126. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  127. return showJson(1046, false, $error);
  128. }
  129. }
  130. /**
  131. * 收货
  132. * @return array
  133. */
  134. public function complete()
  135. {
  136. $params = request()->all();
  137. $id = isset($params['id'])? $params['id'] : 0;
  138. try {
  139. if (!$result = OrderService::make()->complete($this->userId, $id)) {
  140. $error = OrderService::make()->getError();
  141. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  142. } else {
  143. return showJson(OrderService::make()->getError(), true, $result);
  144. }
  145. } catch (\Exception $exception) {
  146. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  147. return showJson(1046, false, $error);
  148. }
  149. }
  150. /**
  151. * 售后/退款
  152. * @return array
  153. */
  154. public function after()
  155. {
  156. $params = request()->all();
  157. try {
  158. if (!$result = OrderService::make()->after($this->userId, $params)) {
  159. $error = OrderService::make()->getError();
  160. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  161. } else {
  162. return showJson(OrderService::make()->getError(), true, $result);
  163. }
  164. } catch (\Exception $exception) {
  165. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  166. return showJson(1046, false, $error);
  167. }
  168. }
  169. public function logistics()
  170. {
  171. $params = request()->all();
  172. $id = isset($params['id'])? $params['id'] : 0;
  173. try {
  174. if (!$result = OrderService::make()->getDelivery($id)) {
  175. $error = OrderService::make()->getError();
  176. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  177. } else {
  178. return showJson(1010, true, $result);
  179. }
  180. } catch (\Exception $exception) {
  181. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  182. return showJson(1046, false, $error);
  183. }
  184. }
  185. }