OrderController.php 6.5 KB

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