|
|
@@ -3,11 +3,14 @@ namespace ghs\controllers;
|
|
|
|
|
|
use biz\shop\classes\ShopClass;
|
|
|
use bizGhs\express\classes\GhsDeliveryOrderClass;
|
|
|
-use bizGhs\express\classes\ShansAuthTokenClass;
|
|
|
+use bizGhs\express\classes\DeliveryAuthTokenClass;
|
|
|
use bizGhs\order\classes\OrderClass;
|
|
|
use common\components\delivery\services\adapter\HuolalaAdapter;
|
|
|
use common\components\util;
|
|
|
use common\components\delivery\services\DispatchService;
|
|
|
+use ghs\models\delivery\CancelOrderForm;
|
|
|
+use ghs\models\delivery\CreateOrderForm;
|
|
|
+use ghs\models\delivery\OrderDetailForm;
|
|
|
use Yii;
|
|
|
|
|
|
/**
|
|
|
@@ -19,9 +22,45 @@ class DeliveryController extends BaseController
|
|
|
{
|
|
|
public $guestAccess = ['callback', 'shansong-auth-callback', 'huolala-auth-callback', 'fengniao-callback'];
|
|
|
|
|
|
+ public function actionList()
|
|
|
+ {
|
|
|
+ $mainId = $this->mainId;
|
|
|
+ DeliveryAuthTokenClass::getAllByCondition(['mainId'=>$mainId]);
|
|
|
+// [
|
|
|
+// { id: 'dada', name: '达达', logo: '📦', is_authorized: true, balance: 178.0, access_type: 'oauth' },
|
|
|
+// { id: 'sf-tongcheng', name: '顺丰同城', logo: '🚚', is_authorized: true, balance: 174.0, access_type: 'oauth' },
|
|
|
+// ];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function actionGetAuthUrl()
|
|
|
+ {
|
|
|
+ $platform = Yii::$app->request->get('platformId');
|
|
|
+ switch($platform){
|
|
|
+ case 'shansong':
|
|
|
+ return $this->actionShansongAuth();
|
|
|
+ break;
|
|
|
+ case 'huolala':
|
|
|
+ return $this->actionHuolalaAuth();
|
|
|
+ break;
|
|
|
+ case 'fengniao':
|
|
|
+ return $this->actionFengniaoAuth();
|
|
|
+ break;
|
|
|
+ case 'dada':
|
|
|
+ return $this->actionDadaAuth();
|
|
|
+ break;
|
|
|
+ case 'shunfeng':
|
|
|
+ break;
|
|
|
+ case '':
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ util::error(-1, $platform . '不存在');
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// ------------------ 授权(账号绑定) ---------------------
|
|
|
//授权
|
|
|
- public function actionMerchantAuth()
|
|
|
+ public function actionShansongAuth()
|
|
|
{
|
|
|
//闪送授权(商户授权:授权后能为商户下所有门店发单)
|
|
|
$auth = new \common\components\delivery\platform\shansong\Auth();
|
|
|
@@ -29,7 +68,8 @@ class DeliveryController extends BaseController
|
|
|
$authUrl = $auth->generateMerchantAuthUrl($this->mainId, $redirectUrl);
|
|
|
|
|
|
// 重定向用户
|
|
|
- header('Location: ' . $authUrl);
|
|
|
+ //header('Location: ' . $authUrl);
|
|
|
+ util::success(['url'=>$authUrl]);
|
|
|
}
|
|
|
|
|
|
public function actionHuolalaAuth()
|
|
|
@@ -39,7 +79,8 @@ class DeliveryController extends BaseController
|
|
|
$redirectUrl = 'https://api.shop.hzghd.com/delivery/huolala-auth-callback' . '?mainId=' . $mainId;
|
|
|
$authUrl = $huoLalaAuth->generateAuthUrl($redirectUrl);
|
|
|
|
|
|
- header('Location: ' . $authUrl);
|
|
|
+ //header('Location: ' . $authUrl);
|
|
|
+ util::success(['url'=>$authUrl]);
|
|
|
}
|
|
|
|
|
|
public function actionFengniaoAuth()
|
|
|
@@ -49,7 +90,8 @@ class DeliveryController extends BaseController
|
|
|
$redirectUrl = 'https://api.shop.hzghd.com/delivery/fengniao-auth-callback' . '?mainId=' . $mainId;
|
|
|
$authUrl = $fengnaioAuth->generateAuthUrl($redirectUrl);
|
|
|
|
|
|
- header('Location: ' . $authUrl);
|
|
|
+ //header('Location: ' . $authUrl);
|
|
|
+ util::success(['url'=>$authUrl]);
|
|
|
}
|
|
|
|
|
|
public function actionDadaAuth()
|
|
|
@@ -62,13 +104,26 @@ class DeliveryController extends BaseController
|
|
|
$shopNumber = '40d8391f9b05477b';
|
|
|
$state = 'huidiao_biaoshi';
|
|
|
$authUrl = $dadaAuth->generateAuthUrl($ticket, $state, $shopNumber);
|
|
|
- header('Location: ' . $authUrl);
|
|
|
+ //header('Location: ' . $authUrl);
|
|
|
+ util::success(['url'=>$authUrl]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function actionShunfengAuth()
|
|
|
+ {
|
|
|
+ $shunfengAuth = new \common\components\delivery\platform\shunfeng\Auth();
|
|
|
+
|
|
|
+ $mainId = $this->mainId;
|
|
|
+ $redirectUrl = 'https://api.shop.hzghd.com/delivery/dada-auth-callback' . '?mainId=' . $mainId;
|
|
|
+ $shopNumber = '40d8391f9b05477b';
|
|
|
+ $state = 'huidiao_biaoshi';
|
|
|
+ $authUrl = $shunfengAuth->generateAuthUrl($state, $shopNumber);
|
|
|
+ util::success(['url'=>$authUrl]);
|
|
|
}
|
|
|
|
|
|
public function actionHuolalaVehicle()
|
|
|
{
|
|
|
$mainId = $this->mainId;
|
|
|
- $authPlatforms = ShansAuthTokenClass::getByCondition(['user_id'=>$mainId, 'platform'=>'huolala']);
|
|
|
+ $authPlatforms = DeliveryAuthTokenClass::getByCondition(['mainId'=>$mainId, 'platform'=>'huolala']);
|
|
|
$huolalaAdapter = new HuolalaAdapter($authPlatforms['access_token']);
|
|
|
$cities = $huolalaAdapter->getCityVehicleList(1006);
|
|
|
return $this->asJson($cities);
|
|
|
@@ -229,7 +284,10 @@ class DeliveryController extends BaseController
|
|
|
// 创建订单(真实下单)
|
|
|
public function actionCreateOrder()
|
|
|
{
|
|
|
- $post = Yii::$app->request->post();
|
|
|
+ $form = new CreateOrderForm();
|
|
|
+ $form->loadAndValidate();
|
|
|
+
|
|
|
+ $post = $form->getAttributes();
|
|
|
$orderId = $post['orderId']; // xhGhsOrder.id
|
|
|
$params = $post['allParams'];
|
|
|
$platform = $params['en_name'];// $post['platform'] 是中文
|
|
|
@@ -245,11 +303,11 @@ class DeliveryController extends BaseController
|
|
|
$ghsOrder = OrderClass::getById($orderId, true);
|
|
|
// if ($ghsOrder['status'] != 2) {
|
|
|
// util::fail('订单状态不是待配送');
|
|
|
+ // // }
|
|
|
+ // if(!in_array($ghsOrder['sendStatus'], [-4, -1])) {
|
|
|
+ // Yii::error('订单已经发过跑腿');
|
|
|
+ // util::fail('订单已经发过跑腿');
|
|
|
// }
|
|
|
- if(!in_array($ghsOrder['sendStatus'], [-4, -1])) {
|
|
|
- Yii::error('订单已经发过跑腿');
|
|
|
- util::fail('订单已经发过跑腿');
|
|
|
- }
|
|
|
|
|
|
$ds = new DispatchService($this->mainId, $platform);
|
|
|
$ret = $ds->createOrder($ghsOrder, $shopId, $params);
|
|
|
@@ -285,13 +343,15 @@ class DeliveryController extends BaseController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查询订单
|
|
|
+ * 查询订单详情
|
|
|
*
|
|
|
* 1. 蜂鸟平台 orderId 可以使用 "XSD_CS26322799" (即:表 xhGhsOrder.orderSn)
|
|
|
*/
|
|
|
- public function actionSelectOrder()
|
|
|
+ public function actionOrderDetail()
|
|
|
{
|
|
|
- $post = Yii::$app->request->post();
|
|
|
+ $form = new OrderDetailForm();
|
|
|
+ $form->loadAndValidate();
|
|
|
+ $post = $form->getAttributes();
|
|
|
$platform = $post['platform'];
|
|
|
$orderId = $post['orderId'];
|
|
|
$orderSn = isset($post['orderSn']) ? $post['orderSn'] : '';
|
|
|
@@ -309,12 +369,14 @@ class DeliveryController extends BaseController
|
|
|
// 取消订单
|
|
|
public function actionCancelOrder()
|
|
|
{
|
|
|
- $post = Yii::$app->request->post();
|
|
|
+ $form = new CancelOrderForm();
|
|
|
+ $form->loadAndValidate();
|
|
|
+ $post = $form->getAttributes();
|
|
|
$orderId = $post['orderId'] ?? 0; // 平台的orderId,
|
|
|
$platform = $post['platform'] ?? '';
|
|
|
- $ghsOrderId = $post['ghsOrderId'] ?? 0;
|
|
|
+ $ghsOrderId = $post['ghsOrderId'];
|
|
|
|
|
|
- if($platform == '') {
|
|
|
+ if($platform == '' || $orderId == 0) {
|
|
|
$gdo = GhsDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'ghsOrderId'=>$ghsOrderId, 'orderStatus!='=>-1], true);
|
|
|
if(!empty($gdo)) {
|
|
|
$orderId = $gdo->orderId;
|
|
|
@@ -325,10 +387,24 @@ class DeliveryController extends BaseController
|
|
|
}
|
|
|
|
|
|
$ds = new DispatchService($this->mainId, $platform);
|
|
|
- $ret = $ds->cancelOrder($orderId, '');
|
|
|
+
|
|
|
+ $cancelCostCent = 0;
|
|
|
+ if($platform == 'fengniao') {
|
|
|
+ //请求订单预取消接口,获取是否可取消。如果运单状态不允许取消,则直接返回
|
|
|
+ $cancelParams = ['order_id'=>$orderId, 'order_cancel_code'=>$post['order_cancel_code']];
|
|
|
+ $res = $ds->getAdapter()->preCancelOrder($cancelParams);
|
|
|
+ if($res['code'] != 0){
|
|
|
+ util::fail('运单状态不允许取消');
|
|
|
+ }
|
|
|
+ $cancelCostCent = $res['data']['actual_cancel_cost_cent']; //取消实际需金额(单位:分)
|
|
|
+ }
|
|
|
+
|
|
|
+ $post['order_cancel_role'] = 1; //1:商户取消, 2:用户取消
|
|
|
+ $ret = $ds->cancelOrder($orderId, $post);
|
|
|
if($ret['code'] == 0) {
|
|
|
// 更新跑腿订单与批发订单状态
|
|
|
$gdo->orderStatus = -1;
|
|
|
+ $gdo->cancelCost = $cancelCostCent;
|
|
|
$gdo->save();
|
|
|
|
|
|
$ghsOrder = OrderClass::getById($ghsOrderId, true, 'id, sendDistance, sendStatus, deliveryId');
|
|
|
@@ -343,6 +419,29 @@ class DeliveryController extends BaseController
|
|
|
util::fail('取消失败');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取订单取消原因
|
|
|
+ */
|
|
|
+ public function actionCancelReason()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $ghsOrderId = $post['ghsOrderId'];
|
|
|
+ $platform = $post['platform'];
|
|
|
+
|
|
|
+ $gdo = GhsDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'ghsOrderId'=>$ghsOrderId, 'orderStatus!='=>-1], true);
|
|
|
+ if(!empty($gdo)) {
|
|
|
+ $orderId = $gdo->orderId;
|
|
|
+ //$platform = $gdo->deliveryId;
|
|
|
+ } else {
|
|
|
+ util::fail('未找到对应订单: ' . $ghsOrderId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $ds = new DispatchService($this->mainId, $platform);
|
|
|
+ $ret = $ds->getCancelReasonList($orderId);
|
|
|
+
|
|
|
+ util::success($ret);
|
|
|
+ }
|
|
|
+
|
|
|
// 第三方回调入口
|
|
|
/**
|
|
|
* 回调接口
|
|
|
@@ -426,13 +525,13 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
// 保存授权信息到数据库
|
|
|
$data = [
|
|
|
- 'user_id' => $state,
|
|
|
- 'shop_id' => $shopId,
|
|
|
- 'access_token' => $result['access_token'],
|
|
|
- 'refresh_token' => $result['refresh_token'],
|
|
|
- 'expires_at' => time() + $result['expires_in'],
|
|
|
- 'auth_type' => $isAllStoreAuth ? 'all_store' : 'single_store',
|
|
|
- 'platform_type' => 'shansong'
|
|
|
+ 'mainId' => $state,
|
|
|
+ 'shopId' => $shopId, //闪送商户ID
|
|
|
+ 'accessToken' => $result['access_token'],
|
|
|
+ 'refreshToken' => $result['refresh_token'],
|
|
|
+ 'expiresAt' => time() + $result['expires_in'],
|
|
|
+ 'authType' => $isAllStoreAuth ? 'all_store' : 'single_store',
|
|
|
+ 'platform' => 'shansong'
|
|
|
];
|
|
|
|
|
|
if (!$isAllStoreAuth) {
|
|
|
@@ -440,7 +539,7 @@ class DeliveryController extends BaseController
|
|
|
$data['shans_store_id'] = $storeId;
|
|
|
}
|
|
|
|
|
|
- ShansAuthTokenClass::add($data);
|
|
|
+ DeliveryAuthTokenClass::add($data);
|
|
|
if (false) {
|
|
|
throw new \yii\web\HttpException(500, '保存授权信息失败');
|
|
|
}
|
|
|
@@ -480,16 +579,16 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
// 保存授权信息到数据库
|
|
|
$data = [
|
|
|
- 'user_id' => $mainId,
|
|
|
- 'shop_id' => $result['auth_mobile'],
|
|
|
- 'access_token' => $result['access_token'],
|
|
|
- 'refresh_token' => $result['refresh_token'],
|
|
|
- 'expires_at' => strtotime($result['auth_end_time']),
|
|
|
- 'auth_type' => 'all_store',
|
|
|
+ 'shopId' => $mainId,
|
|
|
+ 'shopId' => '',
|
|
|
+ 'accessToken' => $result['access_token'],
|
|
|
+ 'refreshToken' => $result['refresh_token'],
|
|
|
+ 'expiresAt' => strtotime($result['auth_end_time']),
|
|
|
+ 'authType' => 'all_store',
|
|
|
'platform' => 'huolala'
|
|
|
];
|
|
|
|
|
|
- ShansAuthTokenClass::add($data);
|
|
|
+ DeliveryAuthTokenClass::add($data);
|
|
|
|
|
|
return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']);
|
|
|
}
|
|
|
@@ -530,16 +629,16 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
// 保存授权信息到数据库
|
|
|
$data = [
|
|
|
- 'user_id' => $mainId,
|
|
|
- 'shop_id' => '',
|
|
|
- 'access_token' => $result['access_token'],
|
|
|
- 'refresh_token' => $result['refresh_token'],
|
|
|
- 'expires_at' => $result['expire_in'],
|
|
|
- 'auth_type' => 'all_store',
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'shopId' => '',
|
|
|
+ 'accessToken' => $result['access_token'],
|
|
|
+ 'refreshToken' => $result['refresh_token'],
|
|
|
+ 'expiresAt' => $result['expire_in'],
|
|
|
+ 'authType' => 'all_store',
|
|
|
'platform' => 'fengniao'
|
|
|
];
|
|
|
|
|
|
- ShansAuthTokenClass::add($data);
|
|
|
+ DeliveryAuthTokenClass::add($data);
|
|
|
|
|
|
return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']);
|
|
|
}
|