OrderController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. $validator = new OrderValidator();
  56. $params = $validator->check($params, 'info');
  57. if (!is_array($params)) {
  58. return showJson($params, false);
  59. }
  60. $id = isset($params['id']) ? intval($params['id']) : 0;
  61. $no = isset($params['order_no']) ? trim($params['order_no']) : '';
  62. if ($id <= 0 && empty($no)) {
  63. return showJson(1036, false);
  64. }
  65. $data = OrderService::make()->getOrderInfo($id, $no);
  66. if (empty($data)) {
  67. return showJson(1009, false);
  68. }
  69. return showJson(1010, true, $data);
  70. }
  71. /**
  72. * 下单
  73. * @param OrderValidator $validator
  74. * @return array
  75. */
  76. public function submit(OrderValidator $validator)
  77. {
  78. $params = request()->all();
  79. $params = $validator->check($params, 'submit');
  80. if (!is_array($params)) {
  81. return showJson($params, false);
  82. }
  83. try {
  84. if (!$result = OrderService::make()->createOrder($this->userId, $params)) {
  85. $error = OrderService::make()->getError();
  86. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  87. } else {
  88. return showJson(OrderService::make()->getError(), true, $result);
  89. }
  90. } catch (\Exception $exception) {
  91. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  92. return showJson(1046, false, $error);
  93. }
  94. }
  95. /**
  96. * 支付
  97. * @return array
  98. */
  99. public function pay()
  100. {
  101. $params = request()->all();
  102. $id = isset($params['id'])? $params['id'] : 0;
  103. try {
  104. if (!$result = OrderService::make()->pay($this->userId, $id)) {
  105. $error = OrderService::make()->getError();
  106. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  107. } else {
  108. return showJson(OrderService::make()->getError(), true, $result);
  109. }
  110. } catch (\Exception $exception) {
  111. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  112. return showJson(1046, false, $error);
  113. }
  114. }
  115. /**
  116. * 取消
  117. * @return array
  118. */
  119. public function cancel()
  120. {
  121. $params = request()->all();
  122. $id = isset($params['id'])? $params['id'] : 0;
  123. try {
  124. if (!$result = OrderService::make()->cancel($this->userId, $id)) {
  125. $error = OrderService::make()->getError();
  126. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  127. } else {
  128. return showJson(1002, true, $result);
  129. }
  130. } catch (\Exception $exception) {
  131. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  132. return showJson(1046, false, $error);
  133. }
  134. }
  135. /**
  136. * 收货
  137. * @return array
  138. */
  139. public function complete()
  140. {
  141. $params = request()->all();
  142. $id = isset($params['id'])? $params['id'] : 0;
  143. try {
  144. if (!$result = OrderService::make()->complete($this->userId, $id)) {
  145. $error = OrderService::make()->getError();
  146. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  147. } else {
  148. return showJson(OrderService::make()->getError(), true, $result);
  149. }
  150. } catch (\Exception $exception) {
  151. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  152. return showJson(1046, false, $error);
  153. }
  154. }
  155. /**
  156. * 售后/退款
  157. * @return array
  158. */
  159. public function after()
  160. {
  161. $params = request()->all();
  162. try {
  163. if (!$result = OrderService::make()->after($this->userId, $params)) {
  164. $error = OrderService::make()->getError();
  165. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  166. } else {
  167. return showJson(OrderService::make()->getError(), true, $result);
  168. }
  169. } catch (\Exception $exception) {
  170. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  171. return showJson(1046, false, $error);
  172. }
  173. }
  174. public function logistics()
  175. {
  176. $params = request()->all();
  177. $id = isset($params['id'])? $params['id'] : 0;
  178. try {
  179. if (!$result = OrderService::make()->getDelivery($id)) {
  180. $error = OrderService::make()->getError();
  181. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  182. } else {
  183. return showJson(1010, true, $result);
  184. }
  185. } catch (\Exception $exception) {
  186. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  187. return showJson(1046, false, $error);
  188. }
  189. }
  190. }