OrderController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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\ConfigService;
  8. use App\Services\Kd100Service;
  9. /**
  10. * 订单
  11. * @package App\Http\Controllers\Api
  12. */
  13. class OrderController extends webApp
  14. {
  15. /**
  16. * 列表
  17. * @return array
  18. */
  19. public function index()
  20. {
  21. $params = request()->post();
  22. $pageSize = request()->post('pageSize', 15);
  23. $params['user_id'] = $this->userId;
  24. $datas = OrderService::make()->getDataList($params, $pageSize);
  25. return message(1010, true, $datas);
  26. }
  27. /**
  28. * 验证订单状态
  29. * @return array
  30. */
  31. public function check()
  32. {
  33. if ($data = OrderService::make()->checkOrderStatus($this->userId)) {
  34. return showJson(1010, true, $data);
  35. } else {
  36. return showJson(1009, false);
  37. }
  38. }
  39. /**
  40. * 数量
  41. * @return array
  42. */
  43. public function count()
  44. {
  45. $status = request()->post('status', 1);
  46. $data = OrderService::make()->getCountByStatus($this->userId, $status);
  47. return showJson(1010, true, $data);
  48. }
  49. /**
  50. * 详情
  51. * @return array|mixed
  52. */
  53. public function info()
  54. {
  55. $params = request()->all();
  56. $id = isset($params['id']) ? intval($params['id']) : 0;
  57. $no = isset($params['order_no']) ? trim($params['order_no']) : '';
  58. if ($id <= 0 && empty($no)) {
  59. return showJson(1036, false);
  60. }
  61. if($no && preg_match("/^PR/")){
  62. $data = OrderService::make()->getPayOrderInfo($id, $no);
  63. }else{
  64. $data = OrderService::make()->getOrderInfo($id, $no);
  65. }
  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. }