|
|
@@ -1,6 +1,8 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace ghs\controllers;
|
|
|
|
|
|
+use Yii;
|
|
|
use biz\shop\classes\ShopClass;
|
|
|
use bizGhs\express\classes\GhsDeliveryOrderClass;
|
|
|
use bizGhs\express\classes\DeliveryAuthTokenClass;
|
|
|
@@ -12,7 +14,6 @@ use common\components\delivery\services\DispatchService;
|
|
|
use ghs\models\delivery\CancelOrderForm;
|
|
|
use ghs\models\delivery\CreateOrderForm;
|
|
|
use ghs\models\delivery\OrderDetailForm;
|
|
|
-use Yii;
|
|
|
use yii\web\Response;
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
|
@@ -29,36 +30,37 @@ class DeliveryController extends BaseController
|
|
|
'huolala-auth-callback', 'huolala-callback',
|
|
|
'fengniao-auth-callback', 'fengniao-callback',
|
|
|
'shunfeng-callback',
|
|
|
- 'dada-auth-callback', 'dada-callback'
|
|
|
+ 'dada-auth-callback', 'dada-callback',
|
|
|
+ 'didi-auth-callback', 'didi-callback',
|
|
|
];
|
|
|
|
|
|
public function actionList()
|
|
|
{
|
|
|
$platformList = [];
|
|
|
$platformLogos = [
|
|
|
- 'data' => ['name'=>'达达', 'logo'=>'📦'],
|
|
|
- 'shunfeng' => ['name'=>'顺丰同城', 'logo'=>'🚚'],
|
|
|
- 'meituan' => ['name'=>'美团', 'logo'=>'🍱'] ,
|
|
|
- 'fengniao' => ['name'=>'蜂鸟', 'logo'=>'🍜'],
|
|
|
- 'huolala' => ['name'=>'货拉拉跑腿', 'logo'=>'🚛'],
|
|
|
- 'shansong' => ['name'=>'闪送', 'logo'=>'⚡'],
|
|
|
- 'didi' => ['name'=>'滴滴', 'logo'=>'🚗'],
|
|
|
- 'uu' => ['name'=>'UU跑腿', 'logo'=>'🛵']
|
|
|
+ 'dada' => ['name' => '达达', 'logo' => '📦'],
|
|
|
+ 'shunfeng' => ['name' => '顺丰同城', 'logo' => '🚚'],
|
|
|
+ 'meituan' => ['name' => '美团', 'logo' => '🍱'],
|
|
|
+ 'fengniao' => ['name' => '蜂鸟', 'logo' => '🍜'],
|
|
|
+ 'huolala' => ['name' => '货拉拉跑腿', 'logo' => '🚛'],
|
|
|
+ 'shansong' => ['name' => '闪送', 'logo' => '⚡'],
|
|
|
+ 'didi' => ['name' => '滴滴', 'logo' => '🚗'],
|
|
|
+ 'uu' => ['name' => 'UU跑腿', 'logo' => '🛵']
|
|
|
];
|
|
|
$mainId = $this->mainId;
|
|
|
- $allDeliveries = DeliveryAuthTokenClass::getAllByCondition(['mainId'=>$mainId]);
|
|
|
- foreach($allDeliveries as $d){
|
|
|
+ $allDeliveries = DeliveryAuthTokenClass::getAllByCondition(['mainId' => $mainId]);
|
|
|
+ foreach ($allDeliveries as $d) {
|
|
|
$item = [
|
|
|
- 'id'=>$d['platform'],
|
|
|
- 'logo'=>$platformLogos[$d['platform']]['logo'],
|
|
|
- 'name'=>$platformLogos[$d['platform']]['name'],
|
|
|
+ 'id' => $d['platform'],
|
|
|
+ 'logo' => $platformLogos[$d['platform']]['logo'],
|
|
|
+ 'name' => $platformLogos[$d['platform']]['name'],
|
|
|
'is_authorized' => true,
|
|
|
- 'balance' => $d['balance']/100.0,
|
|
|
+ 'balance' => $d['balance'] / 100.0,
|
|
|
'access_type' => 'oauth'
|
|
|
];
|
|
|
$platformList[] = $item;
|
|
|
}
|
|
|
- util::success(['platformList'=>$platformList]);
|
|
|
+ util::success(['platformList' => $platformList]);
|
|
|
}
|
|
|
|
|
|
public function actionGetAuthUrl()
|
|
|
@@ -67,7 +69,7 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$Auth = new \common\components\delivery\services\AuthService();
|
|
|
$mainId = $this->mainId;
|
|
|
- switch($platform){
|
|
|
+ switch ($platform) {
|
|
|
case 'shansong':
|
|
|
$Auth->shansongAuth($mainId);
|
|
|
break;
|
|
|
@@ -87,7 +89,7 @@ class DeliveryController extends BaseController
|
|
|
$Auth->didiAuth($mainId, $this->shopId);
|
|
|
break;
|
|
|
case 'dada':
|
|
|
- $Auth->dadaAuth($mainId);
|
|
|
+ $Auth->dadaAuth($mainId, $this->shopId);
|
|
|
break;
|
|
|
default:
|
|
|
util::error(-1, $platform . '不存在');
|
|
|
@@ -100,28 +102,28 @@ class DeliveryController extends BaseController
|
|
|
// 有平台有对应的取消授权接口,有的没有。
|
|
|
// 有的就对接下,然后再删除数据。没有的直接删除数据就行。
|
|
|
$platform = Yii::$app->request->get('platform');
|
|
|
- $delivery = DeliveryAuthTokenClass::getByCondition(['mainId'=>$this->mainId, 'platform'=>$platform]);
|
|
|
- if($delivery) {
|
|
|
- if($platform == 'shansong') {
|
|
|
+ $delivery = DeliveryAuthTokenClass::getByCondition(['mainId' => $this->mainId, 'platform' => $platform]);
|
|
|
+ if ($delivery) {
|
|
|
+ if ($platform == 'shansong') {
|
|
|
$auth = new \common\components\delivery\platform\shansong\Auth();
|
|
|
$result = $auth->cancelAuthorization($delivery['accessToken']);
|
|
|
- if($result['success']) {
|
|
|
+ if ($result['success']) {
|
|
|
// 授权已取消
|
|
|
- }else{
|
|
|
- if($result['message'] == '商户未授权,请授权后再次尝试'){
|
|
|
+ } else {
|
|
|
+ if ($result['message'] == '商户未授权,请授权后再次尝试') {
|
|
|
Yii::info($this->mainId . '--商户未授权,请授权后再次尝试');
|
|
|
- }else{
|
|
|
- util::fail('取消授权失败:'.$result['message']);
|
|
|
+ } else {
|
|
|
+ util::fail('取消授权失败:' . $result['message']);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
util::fail('取消授权失败,数据未找到');
|
|
|
}
|
|
|
|
|
|
- $ret = DeliveryAuthTokenClass::deleteByCondition(['mainId'=>$this->mainId, 'platform'=>$platform]);
|
|
|
- if($ret > 0){
|
|
|
- util::success(['message'=>'取消授权成功']);
|
|
|
+ $ret = DeliveryAuthTokenClass::deleteByCondition(['mainId' => $this->mainId, 'platform' => $platform]);
|
|
|
+ if ($ret > 0) {
|
|
|
+ util::success(['message' => '取消授权成功']);
|
|
|
} else {
|
|
|
util::fail('取消授权失败');
|
|
|
}
|
|
|
@@ -132,7 +134,7 @@ class DeliveryController extends BaseController
|
|
|
public function actionHuolalaVehicle()
|
|
|
{
|
|
|
$mainId = $this->mainId;
|
|
|
- $authPlatforms = DeliveryAuthTokenClass::getByCondition(['mainId'=>$mainId, 'platform'=>'huolala']);
|
|
|
+ $authPlatforms = DeliveryAuthTokenClass::getByCondition(['mainId' => $mainId, 'platform' => 'huolala']);
|
|
|
$huolalaAdapter = new HuolalaAdapter($authPlatforms['access_token']);
|
|
|
$cities = $huolalaAdapter->getCityVehicleList(1006);
|
|
|
return $this->asJson($cities);
|
|
|
@@ -149,7 +151,7 @@ class DeliveryController extends BaseController
|
|
|
$newCitiesArr = [];
|
|
|
|
|
|
$citiesArr = $cities['data'];
|
|
|
- foreach($citiesArr as $block) {
|
|
|
+ foreach ($citiesArr as $block) {
|
|
|
foreach ($block['cities'] as $city) {
|
|
|
$newCitiesArr[$city['name']] = $city;
|
|
|
}
|
|
|
@@ -161,7 +163,7 @@ class DeliveryController extends BaseController
|
|
|
$newCitiesArr = [
|
|
|
'expire' => $cities['data']['expire'],
|
|
|
];
|
|
|
- foreach($citiesArr as $city) {
|
|
|
+ foreach ($citiesArr as $city) {
|
|
|
$newCitiesArr[$city['name']] = [
|
|
|
'city_id' => $city['city_id'],
|
|
|
'city_name' => $city['name'],
|
|
|
@@ -205,13 +207,26 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$orderId = intval($post['orderId']);
|
|
|
$order = OrderClass::getById($orderId);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ if ($order['mainId'] != $this->mainId) {
|
|
|
+ util::fail('不是你的订单');
|
|
|
+ }
|
|
|
+ if (empty($order['address'])) {
|
|
|
+ util::fail('客户地址缺失');
|
|
|
+ }
|
|
|
+ if (empty($order['long']) || empty($order['lat'])) {
|
|
|
+ util::fail('客户地址信息缺失');
|
|
|
+ }
|
|
|
+
|
|
|
$shop = ShopClass::getById($this->shopId);
|
|
|
$order['weight'] = $weight;
|
|
|
$order['remark'] = $remark;
|
|
|
|
|
|
$ds = new DispatchService($this->mainId);
|
|
|
$platformQuotes = $ds->getAllPlatformPrice($order, $shop, $orderTime);
|
|
|
- if(isset($platformQuotes['error'])){
|
|
|
+ if (isset($platformQuotes['error'])) {
|
|
|
util::fail($platformQuotes['error']);
|
|
|
}
|
|
|
|
|
|
@@ -231,32 +246,42 @@ class DeliveryController extends BaseController
|
|
|
$form->loadAndValidate();
|
|
|
|
|
|
$post = $form->getAttributes();
|
|
|
- $orderId = $post['orderId']; // xhGhsOrder.id
|
|
|
- $params = $post['allParams'];
|
|
|
- $platform = $params['en_name'];// $post['platform'] 是中文
|
|
|
- $pickupTime = $post['pickupTime'];
|
|
|
+ $orderId = $post['orderId'] ?? 0; // xhGhsOrder.id
|
|
|
+ $params = $post['allParams'] ?? '';
|
|
|
+ $platform = $params['en_name'] ?? '';// 平台英文名,$post['platform'] 是中文
|
|
|
+ if (empty($platform)) {
|
|
|
+ util::fail('请选择跑腿');
|
|
|
+ }
|
|
|
+ $pickupTime = $post['pickupTime'] ?? '';
|
|
|
|
|
|
$params['mainId'] = $this->mainId;
|
|
|
$params['ip'] = Yii::$app->request->userIP;
|
|
|
- $params['remark'] = $post['remark'];
|
|
|
- $params['total_price_fen'] = $post['price'];
|
|
|
- $params['pickupTime'] = $pickupTime['value'];
|
|
|
- $shopId = $this->shopId;
|
|
|
+ $params['weight'] = $post['weight'] ?? 1;
|
|
|
+ $params['remark'] = $post['remark'] ?? '';
|
|
|
+ $params['total_price_fen'] = $post['price'] ?? 1;
|
|
|
+ $params['pickupTime'] = $pickupTime['value'] ?? '';
|
|
|
|
|
|
$ghsOrder = OrderClass::getById($orderId, true);
|
|
|
- // if ($ghsOrder['status'] != 2) {
|
|
|
- // util::fail('订单状态不是待配送');
|
|
|
- // // }
|
|
|
- if(!in_array($ghsOrder['sendStatus'], [-4, -1])) {
|
|
|
- Yii::error('订单已经发过跑腿');
|
|
|
- util::fail('订单已经发过跑腿');
|
|
|
- }
|
|
|
+ if (empty($ghsOrder)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ if ($ghsOrder->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的订单');
|
|
|
+ }
|
|
|
+ if (!in_array($ghsOrder['sendStatus'], [-4, -1])) {
|
|
|
+ Yii::error('订单已经发过跑腿');
|
|
|
+ util::fail('订单已经发过跑腿');
|
|
|
+ }
|
|
|
+
|
|
|
+ //避免连续点击的重复提交 ssh
|
|
|
+ $adminId = $this->adminId;
|
|
|
+ util::checkRepeatCommit($adminId, 3);
|
|
|
|
|
|
$ds = new DispatchService($this->mainId, $platform);
|
|
|
- $ret = $ds->createOrder($ghsOrder, $shopId, $params);
|
|
|
+ $ret = $ds->createOrder($ghsOrder, 'xhGhsOrder', $this->shopId, $params);
|
|
|
|
|
|
if (isset($ret['code']) && $ret['code'] == 0) {
|
|
|
- $gdo = GhsDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'orderId'=>$ret['data']['order_id']]);
|
|
|
+ $gdo = GhsDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'orderId' => $ret['data']['order_id']]);
|
|
|
if (empty($gdo)) {
|
|
|
$data = [
|
|
|
'mainId' => $this->mainId,
|
|
|
@@ -278,11 +303,15 @@ class DeliveryController extends BaseController
|
|
|
$ghsOrder->deliveryId = $ret['platform'];
|
|
|
$ghsOrder->sendType = 2;// 2指跑腿
|
|
|
$ghsOrder->save();
|
|
|
- //OrderClass::hasSend($ghsOrder);//这个错误的方法应该删除,要使用OrderClass::orderSend()
|
|
|
+ //OrderClass::hasSend($ghsOrder);// 更新 status (不正确的,暂留做为对比)
|
|
|
+
|
|
|
+ //发货
|
|
|
+ $params = ['fhType' => 0, 'fhWl' => '', 'fhWlNo' => '', 'staffId' => 0, 'staffName' => ''];
|
|
|
+ OrderClass::orderSend($ghsOrder, $params);
|
|
|
|
|
|
util::success($ret, "success");
|
|
|
} else {
|
|
|
- if(isset($ret['msg'])){
|
|
|
+ if (isset($ret['msg'])) {
|
|
|
util::fail($ret['msg']);
|
|
|
}
|
|
|
util::fail('创建跑腿失败');
|
|
|
@@ -307,8 +336,8 @@ class DeliveryController extends BaseController
|
|
|
$ret = $ds->selectOrder($orderId, $orderSn);
|
|
|
|
|
|
$return = isset($ret['ret']) ? $ret['ret'] : $ret['code']; // 各平台兼容处理
|
|
|
- if($return == 0) {
|
|
|
- util::success($ret, "success");
|
|
|
+ if ($return == 0) {
|
|
|
+ util::success($ret, "success");
|
|
|
}
|
|
|
util::fail('查询失败');
|
|
|
}
|
|
|
@@ -324,34 +353,34 @@ class DeliveryController extends BaseController
|
|
|
$ghsOrderId = $post['ghsOrderId'];
|
|
|
|
|
|
// 先获取配送订单,确保 $gdo 始终可用
|
|
|
- $gdo = GhsDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'ghsOrderId'=>$ghsOrderId, 'orderStatus!='=> -1], true);
|
|
|
- if(empty($gdo)) {
|
|
|
+ $gdo = GhsDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'ghsOrderId' => $ghsOrderId, 'orderStatus!=' => -1], true);
|
|
|
+ if (empty($gdo)) {
|
|
|
util::fail('未找到对应订单: ' . $ghsOrderId);
|
|
|
}
|
|
|
|
|
|
// 如果没有提供平台和订单ID,从配送订单中获取
|
|
|
- if($platform == '' || $orderId == 0) {
|
|
|
- $orderId = $gdo->orderId;
|
|
|
- $platform = $gdo->deliveryId;
|
|
|
+ if ($platform == '' || $orderId == 0) {
|
|
|
+ $orderId = $gdo->orderId;
|
|
|
+ $platform = $gdo->deliveryId;
|
|
|
}
|
|
|
|
|
|
$ds = new DispatchService($this->mainId, $platform);
|
|
|
|
|
|
$cancelCostCent = 0;
|
|
|
- if($platform == 'fengniao') {
|
|
|
+ if ($platform == 'fengniao') {
|
|
|
//请求订单预取消接口,获取是否可取消。如果运单状态不允许取消,则直接返回
|
|
|
- $cancelParams = ['order_id'=>$orderId, 'order_cancel_code'=>$post['order_cancel_code']];
|
|
|
+ $cancelParams = ['order_id' => $orderId, 'order_cancel_code' => $post['order_cancel_code']];
|
|
|
$res = $ds->getAdapter()->preCancelOrder($cancelParams);
|
|
|
- if($res['code'] != 0){
|
|
|
+ if ($res['code'] != 0) {
|
|
|
util::fail('运单状态不允许取消');
|
|
|
}
|
|
|
$cancelCostCent = $res['data']['actual_cancel_cost_cent']; //取消实际需金额(单位:分)
|
|
|
}
|
|
|
- if($platform == 'shunfeng') {
|
|
|
+ if ($platform == 'shunfeng') {
|
|
|
//请求订单预取消接口,获取是否可取消。如果运单状态不允许取消,则直接返回
|
|
|
- $cancelParams = ['order_id'=>$orderId, 'order_cancel_code'=>$post['order_cancel_code']];
|
|
|
+ $cancelParams = ['order_id' => $orderId, 'order_cancel_code' => $post['order_cancel_code']];
|
|
|
$res = $ds->getAdapter()->preCancelOrder($cancelParams);
|
|
|
- if($res['code'] != 0){
|
|
|
+ if ($res['code'] != 0) {
|
|
|
util::fail('运单状态不允许取消');
|
|
|
}
|
|
|
$post['order_type'] = 1; //查询订单ID类型 1、顺丰订单号 2、商家订单号
|
|
|
@@ -359,24 +388,25 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$post['order_cancel_role'] = 1; //1:商户取消, 2:用户取消
|
|
|
$ret = $ds->cancelOrder($orderId, $post);
|
|
|
- if($ret['code'] == 0) {
|
|
|
+ if ($ret['code'] == 0) {
|
|
|
// 更新跑腿订单与批发订单状态
|
|
|
$gdo->orderStatus = -1;
|
|
|
$gdo->cancelCost = $ret['platform'] !== 'fengniao' ? $ret['data']['deductionFee'] : $cancelCostCent; // 由于蜂鸟平台返回的扣费不一样造成
|
|
|
- if(!$gdo->save()) {
|
|
|
+ if (!$gdo->save()) {
|
|
|
Yii::error('保存配送订单失败: ' . json_encode($gdo->errors));
|
|
|
util::fail('保存配送订单失败');
|
|
|
}
|
|
|
|
|
|
- $ghsOrder = OrderClass::getById($ghsOrderId, true, 'id, sendDistance, sendStatus, deliveryId');
|
|
|
+ $ghsOrder = OrderClass::getById($ghsOrderId, true, 'id, sendDistance, sendStatus, deliveryId, purchaseId, status');
|
|
|
$ghsOrder->sendDistance = 0;
|
|
|
- $ghsOrder->sendStatus = -4;
|
|
|
- $ghsOrder->deliveryId = '';
|
|
|
+ $ghsOrder->sendStatus = -1;
|
|
|
+ // $ghsOrder->deliveryId = ''; // 为了获取上一次的配送记录,不要置空
|
|
|
$ghsOrder->sendTip = 0;
|
|
|
- if(!$ghsOrder->save()) {
|
|
|
+ if (!$ghsOrder->save()) {
|
|
|
Yii::error('保存批发订单失败: ' . json_encode($ghsOrder->errors));
|
|
|
util::fail('保存批发订单失败');
|
|
|
}
|
|
|
+ OrderClass::cancelOrderSend($ghsOrder, ['staffId' => 0, 'staffName' => '']);
|
|
|
|
|
|
util::success($ret['data'], "success");
|
|
|
}
|
|
|
@@ -393,8 +423,8 @@ class DeliveryController extends BaseController
|
|
|
$ghsOrderId = $post['ghsOrderId'];
|
|
|
$platform = $post['platform'];
|
|
|
|
|
|
- $gdo = GhsDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'ghsOrderId'=>$ghsOrderId, 'orderStatus!='=>-1], true);
|
|
|
- if(!empty($gdo)) {
|
|
|
+ $gdo = GhsDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'ghsOrderId' => $ghsOrderId, 'orderStatus!=' => -1], true);
|
|
|
+ if (!empty($gdo)) {
|
|
|
$orderId = $gdo->orderId;
|
|
|
//$platform = $gdo->deliveryId;
|
|
|
} else {
|
|
|
@@ -403,10 +433,10 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$ds = new DispatchService($this->mainId, $platform);
|
|
|
$ret = $ds->getCancelReasonList($orderId);
|
|
|
- if($ret['code'] == 0){
|
|
|
+ if ($ret['code'] == 0) {
|
|
|
util::success($ret['data']);
|
|
|
- }else{
|
|
|
- Yii::error('获取订单取消原因:'.json_encode($ret));
|
|
|
+ } else {
|
|
|
+ Yii::error('获取订单取消原因:' . json_encode($ret));
|
|
|
util::fail($ret['msg']);
|
|
|
}
|
|
|
}
|
|
|
@@ -421,29 +451,29 @@ class DeliveryController extends BaseController
|
|
|
$platform = $post['platform'];
|
|
|
$tips = intval($post['tips']);
|
|
|
|
|
|
- if($tips < 0) {
|
|
|
+ if ($tips < 0) {
|
|
|
util::fail('小费金额至少为1元');
|
|
|
}
|
|
|
$tips *= 100;
|
|
|
|
|
|
- $gdo = GhsDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'ghsOrderId'=>$ghsOrderId, 'orderStatus'=>['in',[0,1,2,10]]], true);
|
|
|
- if($gdo == null){
|
|
|
+ $gdo = GhsDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'ghsOrderId' => $ghsOrderId, 'orderStatus' => ['in', [0, 1, 2, 10]]], true);
|
|
|
+ if ($gdo == null) {
|
|
|
util::fail('当前配送状态无法加小费');
|
|
|
}
|
|
|
|
|
|
$ds = new DispatchService($this->mainId, $platform);
|
|
|
- $ret = $ds->addTip(['orderId'=>$gdo->orderId, 'tips'=>$tips]);
|
|
|
- if($ret['code'] == 0){
|
|
|
+ $ret = $ds->addTip(['orderId' => $gdo->orderId, 'tips' => $tips]);
|
|
|
+ if ($ret['code'] == 0) {
|
|
|
$gdo->tip = $tips + $gdo->tip;
|
|
|
$gdo->save();
|
|
|
|
|
|
$orderObj = OrderClass::getById($gdo->ghsOrderId, true, 'id,sendTip');
|
|
|
- $orderObj->sendTip = $tips/100 + $orderObj->sendTip;
|
|
|
+ $orderObj->sendTip = $tips / 100 + $orderObj->sendTip;
|
|
|
$orderObj->save();
|
|
|
|
|
|
util::success($ret['data']);
|
|
|
- }else{
|
|
|
- Yii::error('添加小费请求失败,请求数据是:'.json_encode($ret));
|
|
|
+ } else {
|
|
|
+ Yii::error('添加小费请求失败,请求数据是:' . json_encode($ret));
|
|
|
util::fail($ret['msg']);
|
|
|
}
|
|
|
}
|
|
|
@@ -488,11 +518,11 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$obj = new \common\components\delivery\platform\shansong\OrderStatusCallBack();
|
|
|
$ret = $obj->handle($callbackData);
|
|
|
- if($ret) {
|
|
|
- return $this->asJson(['status' => 200, 'msg' => 'OK', "data"=> null]);
|
|
|
+ if ($ret) {
|
|
|
+ return $this->asJson(['status' => 200, 'msg' => 'OK', "data" => null]);
|
|
|
} else {
|
|
|
Yii::error('闪送回调失败: ' . json_encode($callbackData, JSON_UNESCAPED_UNICODE));
|
|
|
- return $this->asJson(['status' => 200, 'msg' => '回调失败', "data"=> null]);
|
|
|
+ return $this->asJson(['status' => 200, 'msg' => '回调失败', "data" => null]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -511,9 +541,9 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$fa = new \common\components\delivery\services\adapter\FengniaoAdapter();
|
|
|
$paramSign = $fa->generateSignature($param);
|
|
|
- if($paramSign == $callbackData['signature']){
|
|
|
+ if ($paramSign == $callbackData['signature']) {
|
|
|
$businessData = isset($callbackData['business_data']) ? $callbackData['business_data'] : '';
|
|
|
- if(empty($businessData)){
|
|
|
+ if (empty($businessData)) {
|
|
|
$this->asJson(['return_code' => -1, 'return_msg' => 'business data is empty']);
|
|
|
}
|
|
|
$businessData = json_decode($businessData, true);
|
|
|
@@ -521,7 +551,7 @@ class DeliveryController extends BaseController
|
|
|
$ret = $cbnObj->handle($businessData['callback_business_type'], $businessData['param']);
|
|
|
|
|
|
return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
Yii::error('蜂鸟回调接口签名出错');
|
|
|
}
|
|
|
}
|
|
|
@@ -533,9 +563,9 @@ class DeliveryController extends BaseController
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
Yii::info('货拉拉回调接口post:' . json_encode($post, JSON_UNESCAPED_UNICODE), 'delivery');
|
|
|
-
|
|
|
+
|
|
|
$action = $post['action'] ?? '';
|
|
|
- if($action != 'order_update') {
|
|
|
+ if ($action != 'order_update') {
|
|
|
Yii::error('当前接口只处理货拉拉订单状态变更事件');
|
|
|
return $this->asJson(['return_code' => 0, 'msg' => '当前接口只处理货拉拉订单状态变更事件']);
|
|
|
}
|
|
|
@@ -544,16 +574,16 @@ class DeliveryController extends BaseController
|
|
|
unset($param['signature']);
|
|
|
$huolala = new \common\components\delivery\platform\huolala\Huolala();
|
|
|
$paramSign = $huolala->generateSignatureWithoutAppSecret($param); //注意:不用拼接secret,所有的参数都参与计算,包含空值。
|
|
|
- if($paramSign == $post['signature']){
|
|
|
+ if ($paramSign == $post['signature']) {
|
|
|
$cbh = new \common\components\delivery\platform\huolala\CallBackHandler();
|
|
|
$ret = $cbh->handler($post);
|
|
|
- if($ret) {
|
|
|
+ if ($ret) {
|
|
|
return $this->asJson(['serial_no' => $post['serial_no']]);
|
|
|
} else {
|
|
|
Yii::error('货拉拉回调失败: ' . json_encode($post, JSON_UNESCAPED_UNICODE));
|
|
|
return $this->asJson(['return_code' => -1, 'return_msg' => 'failed']);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
Yii::error('蜂鸟回调接口签名出错');
|
|
|
return $this->asJson(['return_code' => -1, 'return_msg' => 'signature error']);
|
|
|
}
|
|
|
@@ -567,7 +597,7 @@ class DeliveryController extends BaseController
|
|
|
$post = Yii::$app->request->post();
|
|
|
$cbh = new \common\components\delivery\platform\shunfeng\CallBackHandler();
|
|
|
$ret = $cbh->handle($post);// 各回调处理
|
|
|
- if($ret) {
|
|
|
+ if ($ret) {
|
|
|
return $this->asJson(['error_code' => 0, 'error_msg' => 'success']);
|
|
|
} else {
|
|
|
Yii::error('顺丰回调失败: ' . json_encode($post, JSON_UNESCAPED_UNICODE));
|
|
|
@@ -577,6 +607,7 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------- 授权回调接口 ----------------------------------------------------------
|
|
|
+
|
|
|
/**
|
|
|
* 闪送授权回调接口
|
|
|
*/
|
|
|
@@ -630,7 +661,7 @@ class DeliveryController extends BaseController
|
|
|
$template = file_get_contents($templatePath);
|
|
|
}
|
|
|
if ($template === false || $template === '') {
|
|
|
- throw new \yii\web\HttpException(500, '返回h5页面不存在');
|
|
|
+ throw new \yii\web\HttpException(500, '返回h5页面不存在');
|
|
|
}
|
|
|
|
|
|
$content = strtr($template, [
|
|
|
@@ -650,7 +681,7 @@ class DeliveryController extends BaseController
|
|
|
*/
|
|
|
public function actionHuolalaAuthCallback()
|
|
|
{
|
|
|
- $get = Yii::$app->request->get();
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
$getData = json_encode($get, JSON_UNESCAPED_UNICODE);
|
|
|
Yii::info($getData);
|
|
|
$code = $get['code'];
|
|
|
@@ -710,7 +741,7 @@ class DeliveryController extends BaseController
|
|
|
Yii::info('蜂鸟授权回调:' . json_encode($callbackData, JSON_UNESCAPED_UNICODE), 'fengniao');
|
|
|
|
|
|
$get = Yii::$app->request->get();
|
|
|
- if(!isset($get['main_id'])){
|
|
|
+ if (!isset($get['main_id'])) {
|
|
|
Yii::error('蜂鸟授权回调的回调地址 authCallbackUrl 中没有带 main_id');
|
|
|
noticeUtil::push('蜂鸟授权回调的回调地址 authCallbackUrl 中没有带 main_id,回调数据:' . json_encode($callbackData, JSON_UNESCAPED_UNICODE), 'fengniao');
|
|
|
return;
|
|
|
@@ -734,9 +765,9 @@ class DeliveryController extends BaseController
|
|
|
$result = $result['data'];
|
|
|
|
|
|
$exist = DeliveryAuthTokenClass::exists(['mainId' => $mainId, 'platform' => 'fengniao']);
|
|
|
- if($exist){
|
|
|
+ if ($exist) {
|
|
|
noticeUtil::push("mainId=" . $mainId . ' 已成功授权了。如果蜂鸟不能正确使用,请查询数据库进行检查。');
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
// 保存授权信息到数据库
|
|
|
$data = [
|
|
|
'mainId' => $mainId,
|
|
|
@@ -762,16 +793,34 @@ class DeliveryController extends BaseController
|
|
|
$get = Yii::$app->request->get();
|
|
|
$getData = json_encode($get, JSON_UNESCAPED_UNICODE);
|
|
|
Yii::info($getData);
|
|
|
+ // {"sourceId":"1003654","ticket":"b8b4e56a86934b73a512ea9994e7774e","state":"huidiao_biaoshi","shopNo":"1003654-88547413"}
|
|
|
+ // 用merchanId 来保存 sourceId
|
|
|
+ if ($getData['state'] != 'huidiao_biaoshi') {
|
|
|
+ Yii::error('达达授权回调 state 参数不对');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!isset($getData['mainId'])) {
|
|
|
+ Yii::error('达达授权回调缺少必要参数 mainId');
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- $callbackData = Yii::$app->request->post();
|
|
|
- if (empty($callbackData)) {
|
|
|
- $postStr = file_get_contents('php://input');
|
|
|
- $callbackData = json_decode($postStr, true);
|
|
|
- if (empty($callbackData)) {
|
|
|
- Yii::info('回调请求的数据为空');
|
|
|
- }
|
|
|
+ try {
|
|
|
+ // 保存授权信息到数据库
|
|
|
+ $data = [
|
|
|
+ 'mainId' => $getData['mainId'],
|
|
|
+ 'merchantId' => $getData['sourceId'], // 用merchanId 来保存 sourceId
|
|
|
+ 'shopId' => $getData['shopNo'],
|
|
|
+ 'accessToken' => '',
|
|
|
+ 'refreshToken' => '',
|
|
|
+ 'expiresAt' => 9997773456,
|
|
|
+ 'authType' => 'all_store', //即 scope='all'
|
|
|
+ 'platform' => 'dada'
|
|
|
+ ];
|
|
|
+ DeliveryAuthTokenClass::add($data);
|
|
|
+ Yii::info('达达授权回调保存成功', 'dada');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Yii::error('达达授权回调保存失败' . $e->getMessage(), 'dada');
|
|
|
}
|
|
|
- Yii::info('达达授权回调:' . json_encode($callbackData, JSON_UNESCAPED_UNICODE), 'dada');
|
|
|
}
|
|
|
|
|
|
/**
|