| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Http\Validator\OrderValidator;
- use App\Services\Api\AccountService;
- use App\Services\Api\GoodsService;
- use App\Services\Api\MemberService;
- use App\Services\Api\OrderService;
- use App\Services\ConfigService;
- use App\Services\Kd100Service;
- /**
- * 订单
- * @package App\Http\Controllers\Api
- */
- class OrderController extends webApp
- {
- /**
- * 列表
- * @return array
- */
- public function index()
- {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 15);
- $uid = isset($params['uid'])?$params['uid']:0;
- $params['user_id'] = $uid?$uid:$this->userId;
- $datas = OrderService::make()->getDataList($params, $pageSize);
- return message(1010, true, $datas);
- }
- /**
- * 详情
- */
- public function info()
- {
- $params = request()->all();
- $id = isset($params['id'])? intval($params['id']) : 0;
- $no = isset($params['order_no'])? trim($params['order_no']) : '';
- if(empty($id) && empty($no)){
- return message(1036, false);
- }
- if($info = OrderService::make()->getOrderInfo($id,$no)){
- return message(1010, true, $info);
- }else{
- return message(1009, false);
- }
- }
- /**
- * 数量
- * @return array
- */
- public function count()
- {
- $status = request()->post('status', 1);
- $data = OrderService::make()->getCountByStatus($this->userId, $status);
- return showJson(1010, true, $data);
- }
- /**
- * 下单
- * @param OrderValidator $validator
- * @return array
- */
- public function submit(OrderValidator $validator)
- {
- $params = request()->all();
- $params = $validator->check($params, 'submit');
- if (!is_array($params)) {
- return showJson($params, false);
- }
- try {
- if (!$result = OrderService::make()->createOrder($this->userId, $params)) {
- $error = OrderService::make()->getError();
- return showJson($error, false, '', $error == 1042||$error == 1045 ? '403' : -1);
- } else {
- return showJson(OrderService::make()->getError(), true, $result);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage(),'trace'=>$exception->getTrace()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 支付
- * @return array
- */
- public function pay()
- {
- $params = request()->all();
- $id = isset($params['id'])? $params['id'] : 0;
- try {
- if (!$result = OrderService::make()->pay($this->userId, $id)) {
- $error = OrderService::make()->getError();
- return showJson($error, false, '', $error == 2206 ? '405' : -1);
- } else {
- return showJson(OrderService::make()->getError(), true, $result);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 取消
- * @return array
- */
- public function cancel()
- {
- $params = request()->all();
- $id = isset($params['id'])? $params['id'] : 0;
- try {
- if (!$result = OrderService::make()->cancel($this->userId, $id)) {
- $error = OrderService::make()->getError();
- return showJson($error, false, '', $error == 2206 ? '405' : -1);
- } else {
- return showJson(1002, true, $result);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 删除隐藏
- * @return array
- */
- public function hide()
- {
- $params = request()->all();
- $id = isset($params['id'])? $params['id'] : 0;
- try {
- if (!$result = OrderService::make()->hide($this->userId, $id)) {
- $error = OrderService::make()->getError();
- return showJson($error, false, '', $error == 2206 ? '405' : -1);
- } else {
- return showJson(1002, true, $result);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 收货
- * @return array
- */
- public function complete()
- {
- $params = request()->all();
- $id = isset($params['id'])? $params['id'] : 0;
- try {
- if (!$result = OrderService::make()->complete($this->userId, $id)) {
- $error = OrderService::make()->getError();
- return showJson($error, false, '', $error == 2206 ? '405' : -1);
- } else {
- return showJson(OrderService::make()->getError(), true, $result);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 售后/退款
- * @return array
- */
- public function after()
- {
- $params = request()->all();
- try {
- if (!$result = OrderService::make()->after($this->userId, $params)) {
- $error = OrderService::make()->getError();
- return showJson($error, false, '', $error == 2206 ? '405' : -1);
- } else {
- return showJson(OrderService::make()->getError(), true, $result);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- public function logistics()
- {
- $params = request()->all();
- $id = isset($params['id'])? $params['id'] : 0;
- try {
- if (!$result = OrderService::make()->getDelivery($id)) {
- $error = OrderService::make()->getError();
- return showJson($error, false, '', $error == 2206 ? '405' : -1);
- } else {
- return showJson(1010, true, $result);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- }
|