OrderController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 count()
  33. {
  34. $status = request()->post('status', 1);
  35. $data = OrderService::make()->getCountByStatus($this->userId, $status);
  36. return showJson(1010, true, $data);
  37. }
  38. /**
  39. * 下单
  40. * @param OrderValidator $validator
  41. * @return array
  42. */
  43. public function submit(OrderValidator $validator)
  44. {
  45. $params = request()->all();
  46. $params = $validator->check($params, 'submit');
  47. if (!is_array($params)) {
  48. return showJson($params, false);
  49. }
  50. try {
  51. if (!$result = OrderService::make()->createOrder($this->userId, $params)) {
  52. $error = OrderService::make()->getError();
  53. return showJson($error, false, '', $error == 1042||$error == 1045 ? '403' : -1);
  54. } else {
  55. return showJson(OrderService::make()->getError(), true, $result);
  56. }
  57. } catch (\Exception $exception) {
  58. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage(),'trace'=>$exception->getTrace()];
  59. return showJson(1046, false, $error);
  60. }
  61. }
  62. /**
  63. * 支付
  64. * @return array
  65. */
  66. public function pay()
  67. {
  68. $params = request()->all();
  69. $id = isset($params['id'])? $params['id'] : 0;
  70. try {
  71. if (!$result = OrderService::make()->pay($this->userId, $id)) {
  72. $error = OrderService::make()->getError();
  73. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  74. } else {
  75. return showJson(OrderService::make()->getError(), true, $result);
  76. }
  77. } catch (\Exception $exception) {
  78. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  79. return showJson(1046, false, $error);
  80. }
  81. }
  82. /**
  83. * 取消
  84. * @return array
  85. */
  86. public function cancel()
  87. {
  88. $params = request()->all();
  89. $id = isset($params['id'])? $params['id'] : 0;
  90. try {
  91. if (!$result = OrderService::make()->cancel($this->userId, $id)) {
  92. $error = OrderService::make()->getError();
  93. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  94. } else {
  95. return showJson(1002, true, $result);
  96. }
  97. } catch (\Exception $exception) {
  98. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  99. return showJson(1046, false, $error);
  100. }
  101. }
  102. /**
  103. * 删除隐藏
  104. * @return array
  105. */
  106. public function hide()
  107. {
  108. $params = request()->all();
  109. $id = isset($params['id'])? $params['id'] : 0;
  110. try {
  111. if (!$result = OrderService::make()->hide($this->userId, $id)) {
  112. $error = OrderService::make()->getError();
  113. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  114. } else {
  115. return showJson(1002, true, $result);
  116. }
  117. } catch (\Exception $exception) {
  118. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  119. return showJson(1046, false, $error);
  120. }
  121. }
  122. /**
  123. * 收货
  124. * @return array
  125. */
  126. public function complete()
  127. {
  128. $params = request()->all();
  129. $id = isset($params['id'])? $params['id'] : 0;
  130. try {
  131. if (!$result = OrderService::make()->complete($this->userId, $id)) {
  132. $error = OrderService::make()->getError();
  133. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  134. } else {
  135. return showJson(OrderService::make()->getError(), true, $result);
  136. }
  137. } catch (\Exception $exception) {
  138. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  139. return showJson(1046, false, $error);
  140. }
  141. }
  142. /**
  143. * 售后/退款
  144. * @return array
  145. */
  146. public function after()
  147. {
  148. $params = request()->all();
  149. try {
  150. if (!$result = OrderService::make()->after($this->userId, $params)) {
  151. $error = OrderService::make()->getError();
  152. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  153. } else {
  154. return showJson(OrderService::make()->getError(), true, $result);
  155. }
  156. } catch (\Exception $exception) {
  157. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  158. return showJson(1046, false, $error);
  159. }
  160. }
  161. public function logistics()
  162. {
  163. $params = request()->all();
  164. $id = isset($params['id'])? $params['id'] : 0;
  165. try {
  166. if (!$result = OrderService::make()->getDelivery($id)) {
  167. $error = OrderService::make()->getError();
  168. return showJson($error, false, '', $error == 2206 ? '405' : -1);
  169. } else {
  170. return showJson(1010, true, $result);
  171. }
  172. } catch (\Exception $exception) {
  173. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  174. return showJson(1046, false, $error);
  175. }
  176. }
  177. }