diff --git a/app/controller/api/store/order/StoreOrder.php b/app/controller/api/store/order/StoreOrder.php index 7152f472..1b7feb1d 100644 --- a/app/controller/api/store/order/StoreOrder.php +++ b/app/controller/api/store/order/StoreOrder.php @@ -136,41 +136,6 @@ class StoreOrder extends BaseController } } - /** - * 其他创建订单 - */ - public function otherOrder(StoreOtherOrderCreateRepository $otherOrderCreateRepository) - { - $cartId = (array)$this->request->param('cart_id', []); - $addressId = (int)$this->request->param('address_id'); - $couponIds = (array)$this->request->param('use_coupon', []); - $takes = (array)$this->request->param('takes', []); - $useIntegral = (bool)$this->request->param('use_integral', false); - $receipt_data = (array)$this->request->param('receipt_data', []); - $extend = (array)$this->request->param('extend', []); - $mark = (array)$this->request->param('mark', []); - $payType = $this->request->param('pay_type'); - $post = (array)$this->request->param('post'); - $data= $otherOrderCreateRepository->v2CreateOrder( - $payType, - $this->request->userInfo(), - $cartId, - $extend, - $mark, - $receipt_data, - $takes, - $couponIds, - $useIntegral, - $addressId, - $post - ); - if($data){ - return app('json')->success('创建成功', $data); - }else{ - return app('json')->error('创建失败', $data); - } - } - /** * @return mixed * @throws \think\db\exception\DataNotFoundException @@ -190,24 +155,6 @@ class StoreOrder extends BaseController return app('json')->success($this->repository->getList($where, $page, $limit)); } - /** - * @return mixed - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - * @author xaboy - * @day 2020/6/10 - */ - public function lst_other(StoreOtherOrderRepository $otherOrderRepository) - { - [$page, $limit] = $this->getPage(); - $where['status'] = $this->request->param('status'); - $where['product_type'] = $this->request->param('product_type', 0); - $where['search'] = $this->request->param('store_name'); - $where['uid'] = $this->request->uid(); - $where['is_user'] = 1; - return app('json')->success($otherOrderRepository->getList($where, $page, $limit)); - } /** * @param $id * @return mixed diff --git a/app/controller/api/store/order/StoreOrderOther.php b/app/controller/api/store/order/StoreOrderOther.php new file mode 100644 index 00000000..2dc3fc78 --- /dev/null +++ b/app/controller/api/store/order/StoreOrderOther.php @@ -0,0 +1,306 @@ + +// +---------------------------------------------------------------------- + + +namespace app\controller\api\store\order; + + +use app\common\model\store\order\StoreGroupOrder; +use app\common\repositories\delivery\DeliveryOrderRepository; +use app\common\repositories\store\order\StoreOrderCreateRepository; +use app\common\repositories\store\order\StoreOtherOrderCreateRepository; +use app\common\repositories\store\order\StoreOrderReceiptRepository; +use app\validate\api\UserReceiptValidate; +use crmeb\basic\BaseController; +use app\common\repositories\store\order\StoreCartRepository; +use app\common\repositories\store\order\StoreGroupOrderRepository; +use app\common\repositories\store\order\StoreOrderRepository; +use app\common\repositories\store\order\StoreOtherOrderRepository; +use app\common\repositories\user\UserAddressRepository; +use think\exception\ValidateException; +use crmeb\services\ExpressService; +use crmeb\services\LockService; +use think\facade\Db; +use think\App; +use think\facade\Log; + +/** + * Class StoreOrder + * @package app\controller\api\store\order + * @author xaboy + * @day 2020/6/10 + */ +class StoreOrderOther extends BaseController +{ + /** + * @var StoreOrderRepository + */ + protected $repository; + + /** + * StoreOrder constructor. + * @param App $app + * @param StoreOrderRepository $repository + */ + public function __construct(App $app, StoreOrderRepository $repository) + { + parent::__construct($app); + $this->repository = $repository; + } + + public function v2CheckOrder(StoreCartRepository $cartRepository, StoreOrderCreateRepository $orderCreateRepository) + { + $cartId = (array)$this->request->param('cart_id', []); + $addressId = (int)$this->request->param('address_id'); + $couponIds = (array)$this->request->param('use_coupon', []); + $takes = (array)$this->request->param('takes', []); + $useIntegral = (bool)$this->request->param('use_integral', false); + $user = $this->request->userInfo(); + $uid = $user->uid; + if (!($count = count($cartId)) || $count != count($cartRepository->validIntersection($cartId, $uid))) + return app('json')->fail('数据无效'); + $orderInfo = $orderCreateRepository->v2CartIdByOrderInfo($user, $cartId, $takes, $couponIds, $useIntegral, $addressId); + + return app('json')->success($orderInfo); + } + + + /** + * 其他创建订单 + */ + public function otherOrder(StoreOtherOrderCreateRepository $otherOrderCreateRepository) + { + $cartId = (array)$this->request->param('cart_id', []); + $addressId = (int)$this->request->param('address_id'); + $couponIds = (array)$this->request->param('use_coupon', []); + $takes = (array)$this->request->param('takes', []); + $useIntegral = (bool)$this->request->param('use_integral', false); + $receipt_data = (array)$this->request->param('receipt_data', []); + $extend = (array)$this->request->param('extend', []); + $mark = (array)$this->request->param('mark', []); + $payType = $this->request->param('pay_type'); + $post = (array)$this->request->param('post'); + $data= $otherOrderCreateRepository->v2CreateOrder( + $payType, + $this->request->userInfo(), + $cartId, + $extend, + $mark, + $receipt_data, + $takes, + $couponIds, + $useIntegral, + $addressId, + $post + ); + if($data){ + return app('json')->success('创建成功', $data); + }else{ + return app('json')->error('创建失败', $data); + } + } + /** + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author xaboy + * @day 2020/6/10 + */ + public function lst_other(StoreOtherOrderRepository $otherOrderRepository) + { + [$page, $limit] = $this->getPage(); + $where['status'] = $this->request->param('status'); + $where['product_type'] = $this->request->param('product_type', 0); + $where['search'] = $this->request->param('store_name'); + $where['uid'] = $this->request->uid(); + $where['is_user'] = 1; + return app('json')->success($otherOrderRepository->getList($where, $page, $limit)); + } + /** + * @param $id + * @return mixed + * @author xaboy + * @day 2020/6/10 + */ + public function detail($id) + { + $order = $this->repository->getDetail((int)$id, $this->request->uid()); + if (!$order) + return app('json')->fail('订单不存在'); + if ($order->order_type == 1) { + $order->append(['take', 'refund_status']); + } + return app('json')->success($order->toArray()); + } + + /** + * @return mixed + * @author xaboy + * @day 2020/6/10 + */ + public function number() + { + $productType = $this->request->param('product_type', 0); + return app('json')->success($this->repository->userOrderNumber($this->request->uid(), $productType)); + } + + /** + * @param StoreGroupOrderRepository $groupOrderRepository + * @return mixed + * @author xaboy + * @day 2020/6/10 + */ + public function groupOrderList(StoreGroupOrderRepository $groupOrderRepository) + { + [$page, $limit] = $this->getPage(); + $productType = $this->request->param('product_type', 0); + $list = $groupOrderRepository->getList(['uid' => $this->request->uid(), 'paid' => 0, 'product_type' => $productType], $page, $limit); + return app('json')->success($list); + } + + /** + * @param $id + * @param StoreGroupOrderRepository $groupOrderRepository + * @return mixed + * @author xaboy + * @day 2020/6/10 + */ + public function groupOrderDetail($id, StoreGroupOrderRepository $groupOrderRepository) + { + $groupOrderRepository->getAll = true; + $groupOrder = $groupOrderRepository->detail($this->request->uid(), (int)$id); + if (!$groupOrder) + return app('json')->fail('订单不存在'); + else + return app('json')->success($groupOrder); + } + + public function groupOrderStatus($id, StoreGroupOrderRepository $groupOrderRepository) + { + $groupOrder = $groupOrderRepository->status($this->request->uid(), intval($id)); + if (!$groupOrder) + return app('json')->fail('订单不存在'); + if ($groupOrder->paid) $groupOrder->append(['give_coupon']); + $activity_type = 0; + $activity_id = 0; + foreach ($groupOrder->orderList as $order) { + $activity_type = max($order->activity_type, $activity_type); + if ($order->activity_type == 4 && $groupOrder->paid) { + $order->append(['orderProduct']); + $activity_id = $order->orderProduct[0]['activity_id']; + } + } + $groupOrder->activity_type = $activity_type; + $groupOrder->activity_id = $activity_id; + return app('json')->success($groupOrder->toArray()); + } + + /** + * @param $id + * @param StoreGroupOrderRepository $groupOrderRepository + * @return mixed + * @author xaboy + * @day 2020/6/10 + */ + public function cancelGroupOrder($id, StoreGroupOrderRepository $groupOrderRepository) + { + $groupOrderRepository->cancel((int)$id, $this->request->uid()); + return app('json')->success('取消成功'); + } + + public function groupOrderPay($id, StoreGroupOrderRepository $groupOrderRepository) + { + //TODO 佣金结算,佣金退回,物流查询 + $type = $this->request->param('type'); + if (!in_array($type, StoreOrderRepository::PAY_TYPE)) + return app('json')->fail('请选择正确的支付方式'); + $groupOrder = $groupOrderRepository->detail($this->request->uid(), (int)$id, false); + if (!$groupOrder) + return app('json')->fail('订单不存在或已支付'); + $this->repository->changePayType($groupOrder, array_search($type, StoreOrderRepository::PAY_TYPE)); + if ($groupOrder['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && !$groupOrder->orderList[0]->allowCreditPay()) { + return app('json')->fail('请等待商家确认订单'); + } + if ($groupOrder['pay_price'] == 0) { + $this->repository->paySuccess($groupOrder); + return app('json')->status('success', '支付成功', ['order_id' => $groupOrder['group_order_id']]); + } + + try { + return $this->repository->pay($type, $this->request->userInfo(), $groupOrder, $this->request->param('return_url'), $this->request->isApp()); + } catch (\Exception $e) { + return app('json')->status('error', $e->getMessage(), ['order_id' => $groupOrder->group_order_id]); + } + } + + public function take($id) + { + $this->repository->takeOrder($id, $this->request->userInfo()); + return app('json')->success('确认收货成功'); + } + + public function express($id) + { + $order = $this->repository->getWhere(['order_id' => $id, 'is_del' => 0]); + if (!$order) + return app('json')->fail('订单不存在'); + if (!$order->delivery_type || !$order->delivery_id) + return app('json')->fail('订单未发货'); + $express = $this->repository->express($id, null); + $order->append(['orderProduct']); + return app('json')->success(compact('express', 'order')); + } + + public function verifyCode($id) + { + $order = $this->repository->getWhere(['order_id' => $id, 'uid' => $this->request->uid(), 'is_del' => 0, 'order_type' => 1]); + if (!$order) + return app('json')->fail('订单状态有误'); + return app('json')->success(['qrcode' => $this->repository->wxQrcode($id, $order->verify_code)]); + } + + /** + * 生成二维码 + */ + public function logisticsCode($id) + { + $storeInfo = Db::name('store_service')->where('uid', $this->request->uid())->find(); + if (!$storeInfo) + return app('json')->fail('商户信息有误'); + $order = $this->repository->getWhere(['order_id' => $id, 'mer_id' => $storeInfo['mer_id'], 'is_del' => 0]); + if (!$order) + return app('json')->fail('订单状态有误'); + return app('json')->success(['qrcode' => $this->repository->logisticsQrcode($id, $order->order_sn)]); + } + + public function del($id) + { + $this->repository->userDel($id, $this->request->uid()); + return app('json')->success('删除成功'); + } + + public function createReceipt($id) + { + $data = $this->request->params(['receipt_type', 'receipt_title', 'duty_paragraph', 'receipt_title_type', 'bank_name', 'bank_code', 'address', 'tel', 'email']); + $order = $this->repository->getWhere(['order_id' => $id, 'uid' => $this->request->uid(), 'is_del' => 0]); + if (!$order) return app('json')->fail('订单不属于您或不存在'); + app()->make(StoreOrderReceiptRepository::class)->add($data, $order); + return app('json')->success('操作成功'); + } + + public function getOrderDelivery($id, DeliveryOrderRepository $orderRepository) + { + $res = $orderRepository->show($id, $this->request->uid()); + return app('json')->success($res); + } +} diff --git a/route/api.php b/route/api.php index 5aeff1c3..0a0655c6 100644 --- a/route/api.php +++ b/route/api.php @@ -62,8 +62,6 @@ Route::group('api/', function () { Route::group('order', function () { Route::post('check', '/v2CheckOrder'); Route::post('create', '/v2CreateOrder'); - Route::post('other', '/otherOrder'); //创建其他订单 - })->prefix('api.store.order.StoreOrder'); //新的下单接口,支持分账 扫描枪 @@ -72,7 +70,6 @@ Route::group('api/', function () { Route::post('addCart', '/addCart'); })->prefix('api.store.order.StoreMicropayOrder'); }); - //退出登录 Route::post('logout', 'api.Auth/logout'); //用户信息 @@ -130,7 +127,11 @@ Route::group('api/', function () { //其他订单 Route::group('other_order', function () { Route::get('list', '/lst_other'); - })->prefix('api.store.order.StoreOrder'); + Route::post('create', '/otherOrder'); //创建其他订单 + Route::get('number', '/number'); + + + })->prefix('api.store.order.StoreOrderOther'); // 预售 Route::group('presell', function () { Route::post('pay/:id', '/pay');