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