| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\controller\api\store\order;
- use app\common\repositories\store\order\StoreCartRepository;
- use app\services\ThirdParty\AlibabaAgent\OrderService;
- use think\facade\Db;
- class AlibabaOrder
- {
- public function checkOrder(StoreCartRepository $cartRepository)
- {
- $cartId = request()->param('cart_id', []);
- $addressId = request()->param('address_id');
- if (empty($addressId)) {
- return app('json')->fail('请选择收货地址');
- }
- $postagePrice = 0;
- // 判断是否是阿里巴巴商品
- $cartInfo = Db::name('store_cart')->whereIn('cart_id', $cartId)->select()->toArray();
- $productInfo = Db::name('store_product')->whereIn('product_id', array_column($cartInfo, 'product_id'))->find();
- if (!$productInfo['is_alibaba']) {
- return app('json')->success(['postagePrice' => $postagePrice]);
- }
- // 获取地址
- $addressInfo = Db::name('user_address')->where('address_id', $addressId)->find();
- $addressParam = [
- 'fullName' => $addressInfo['real_name'],
- 'mobile' => $addressInfo['phone'],
- 'provinceText' => $addressInfo['province'],
- 'cityText' => $addressInfo['city'],
- 'areaText' => $addressInfo['district'],
- 'address' => $addressInfo['detail'],
- ];
- // 获取商品规格
- $quantity = array_column($cartInfo, 'cart_num')[0];
- $offerId = $productInfo['spu_id'];
- $specId = Db::name('store_product_attr_value')->where('product_id', $productInfo['product_id'])->whereIn('unique', array_column($cartInfo, 'product_attr_unique'))->value('spec_id');
- $cargoParamList = [
- 'offerId' => $offerId,
- 'specId' => $specId,
- 'quantity' => $quantity
- ];
- $orderService = new OrderService();
- $res = $orderService->previewOrder(['cargoParamList' => $cargoParamList, 'addressParam' => $addressParam]);
- if (!$res) {
- return app('json')->fail('预下单失败');
- }
- return app('json')->success(['postagePrice' => $res['preview']['sumCarriage'] / 100, 'flow' => $res['preview']['flowFlag']]);
- }
- /**
- * 查询退款退货原因列表
- *
- * 客户端只需传入 order_id,服务端自动调用 alibaba.trade.get.buyerView
- * 获取订单详情,提取子订单号和货物状态后,再调用 alibaba.trade.getRefundReasonList
- *
- * API: alibaba.trade.getRefundReasonList-1
- *
- * @return \think\Response
- */
- public function refundReasonList()
- {
- $orderId = request()->param('order_id');
- if (empty($orderId)) {
- return app('json')->fail('订单号不能为空');
- }
- $orderService = new OrderService();
- $result = $orderService->getRefundReasonList(['orderId' => $orderId]);
- if ($result === false) {
- return app('json')->fail('获取退款原因失败');
- }
- return app('json')->success($result);
- }
- }
|