| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Http\Validator\OrderValidator;
- use App\Services\Api\OrderService;
- use App\Services\MapService;
- /**
- * 订单
- * @package App\Http\Controllers\Api
- */
- class OrderController extends webApp
- {
- /**
- * 列表
- * @return array
- */
- public function index()
- {
- $params =request()->post();
- $pageSize = request()->post('pageSize', 15);
- $params['user_id'] = isset($params['user_id']) && $params['user_id']? $params['user_id'] : $this->userId;
- $datas = OrderService::make()->getDataList($params, $pageSize);
- return message(1010, true, $datas);
- }
- /**
- * 列表
- * @return array
- */
- public function list()
- {
- $params =request()->post();
- $pageSize = request()->post('pageSize', 15);
- $params['user_id'] = isset($params['user_id']) && $params['user_id']? $params['user_id'] : $this->userId;
- $datas = OrderService::make()->getDataList($params, $pageSize);
- return message(1010, true, $datas);
- }
- /**
- * 详情
- * @return array|mixed
- */
- public function info()
- {
- $params = request()->all();
- $validator = new OrderValidator();
- $params = $validator->check($params, 'info');
- if (!is_array($params)) {
- return showJson($params, false);
- }
- $id = isset($params['id'])? intval($params['id']) : 0;
- if($id<=0){
- return showJson(1036,false);
- }
- $data = OrderService::make()->getOrderInfo($id, $this->userId);
- if(empty($data)){
- return showJson(1009, false);
- }
- 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);
- }
- $params['stock_id'] = isset($params['stock_id']) && $params['stock_id']>0? intval($params['stock_id']) : $this->stockId;
- if (!$result = OrderService::make()->createOrder($this->userId, $params)) {
- return showJson(OrderService::make()->getError(), false);
- } else {
- return showJson(OrderService::make()->getError(), true, $result);
- }
- }
- /**
- * 订单统计数据
- * @return array
- */
- public function count()
- {
- if (!$result = OrderService::make()->getCounts($this->userId)) {
- return showJson(1009, false);
- } else {
- return showJson(1010, true, $result);
- }
- }
- /**
- * 完成订单
- * @param OrderValidator $validator
- * @return array
- * @throws \Yansongda\Pay\Exception\ContainerException
- * @throws \Yansongda\Pay\Exception\InvalidParamsException
- * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
- */
- public function complete(OrderValidator $validator)
- {
- $params = request()->all();
- $params = $validator->check($params, 'info');
- if (!is_array($params)) {
- return showJson($params, false);
- }
- if (!$result = OrderService::make()->complete($this->userId, $params,1)) {
- return showJson(OrderService::make()->getError(), false);
- } else {
- return showJson(OrderService::make()->getError(), true, $result);
- }
- }
- /**
- * 取消订单
- * @param OrderValidator $validator
- * @return array
- * @throws \Yansongda\Pay\Exception\ContainerException
- * @throws \Yansongda\Pay\Exception\InvalidParamsException
- * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
- */
- public function cancel(OrderValidator $validator)
- {
- $params = request()->all();
- $params = $validator->check($params, 'cancel');
- if (!is_array($params)) {
- return showJson($params, false);
- }
- if (!$result = OrderService::make()->cancel($this->userId, $params)) {
- return showJson(OrderService::make()->getError(), false);
- } else {
- return showJson(OrderService::make()->getError(), true, $result);
- }
- }
- }
|