|
|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace hd\controllers;
|
|
|
|
|
|
use Yii;
|
|
|
@@ -20,29 +21,29 @@ class DeliveryController extends BaseController
|
|
|
{
|
|
|
$platformList = [];
|
|
|
$platformLogos = [
|
|
|
- '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'=>'🛵']
|
|
|
+ '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]);
|
|
|
}
|
|
|
|
|
|
// 花店发货时 -- 获取多个平台报价
|
|
|
@@ -64,7 +65,7 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$ds = new DispatchService($this->mainId);
|
|
|
$platformQuotes = $ds->getAllPlatformPrice($order, $shop, $orderTime);
|
|
|
- if(isset($platformQuotes['error'])){
|
|
|
+ if (isset($platformQuotes['error'])) {
|
|
|
util::fail($platformQuotes['error']);
|
|
|
}
|
|
|
// 格式化各平台报价为前端展示格式
|
|
|
@@ -96,8 +97,8 @@ class DeliveryController extends BaseController
|
|
|
util::fail('获取custom数据失败');
|
|
|
}
|
|
|
|
|
|
- // 生成随机订单号
|
|
|
- $prefix = 'XSD_CS-' . $ghs->mainId . '-';
|
|
|
+ // 生成随机订单号,不要跟原来的混起来,跑腿-销售单-
|
|
|
+ $prefix = 'PT-XSD-' . $ghs->mainId . '-';
|
|
|
$orderSn = $prefix . round(microtime(true) * 1000);
|
|
|
|
|
|
//构建出 Order 数据
|
|
|
@@ -112,7 +113,7 @@ class DeliveryController extends BaseController
|
|
|
'long' => $custom['long'],
|
|
|
'address' => $custom['address'], //'toAddress' => $order['address'],
|
|
|
'city' => $custom['city'],
|
|
|
- 'weight' => $post['weight'] ?? 1,
|
|
|
+ 'weight' => $post['weight'] ?? 1,
|
|
|
'remark' => $post['remark'] ?? '',
|
|
|
'prePrice' => floatval($post['totalPrice'] ?? 0),
|
|
|
'actPrice' => floatval($post['totalPrice'] ?? 0),
|
|
|
@@ -120,7 +121,7 @@ class DeliveryController extends BaseController
|
|
|
$ghsShop = ShopClass::getById($ghsShopId);
|
|
|
$ds = new DispatchService($ghs->mainId);
|
|
|
$platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime);
|
|
|
- if(isset($platformQuotes['error'])){
|
|
|
+ if (isset($platformQuotes['error'])) {
|
|
|
util::fail($platformQuotes['error']);
|
|
|
}
|
|
|
|
|
|
@@ -148,13 +149,13 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$params['mainId'] = $this->mainId;
|
|
|
$params['ip'] = Yii::$app->request->userIP;
|
|
|
- $params['weight'] = $post['weight'];
|
|
|
- $params['remark'] = $post['remark'];
|
|
|
- $params['total_price_fen'] = $post['price'];
|
|
|
+ $params['weight'] = $post['weight'] ?? 1;
|
|
|
+ $params['remark'] = $post['remark'] ?? '';
|
|
|
+ $params['total_price_fen'] = $post['price'] ?? '';
|
|
|
$params['pickupTime'] = $pickupTime['value'];
|
|
|
|
|
|
$Order = OrderClass::getById($orderId, true);
|
|
|
- if(!in_array($Order['sendStatus'], [-4, -1])) {
|
|
|
+ if (!in_array($Order['sendStatus'], [-4, -1])) {
|
|
|
Yii::error('订单已经发过跑腿');
|
|
|
util::fail('订单已经发过跑腿');
|
|
|
}
|
|
|
@@ -163,7 +164,7 @@ class DeliveryController extends BaseController
|
|
|
$ret = $ds->createOrder($Order, 'xhOrder', $this->shopId, $params);
|
|
|
|
|
|
if (isset($ret['code']) && $ret['code'] == 0) {
|
|
|
- $gdo = HdDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'orderId'=>$ret['data']['order_id']]);
|
|
|
+ $gdo = HdDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'orderId' => $ret['data']['order_id']]);
|
|
|
if (empty($gdo)) {
|
|
|
$data = [
|
|
|
'mainId' => $this->mainId,
|
|
|
@@ -186,13 +187,13 @@ class DeliveryController extends BaseController
|
|
|
$Order->sendType = 2;// 2指跑腿
|
|
|
$Order->status = 3;// 3配送中
|
|
|
$save = $Order->save();
|
|
|
- if($save){
|
|
|
+ if ($save) {
|
|
|
util::success($ret, "success");
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
util::fail('创建跑腿失败(更新订单失败)');
|
|
|
}
|
|
|
} else {
|
|
|
- if(isset($ret['msg'])){
|
|
|
+ if (isset($ret['msg'])) {
|
|
|
util::fail($ret['msg']);
|
|
|
}
|
|
|
util::fail('创建跑腿失败');
|
|
|
@@ -210,13 +211,13 @@ class DeliveryController extends BaseController
|
|
|
$hdOrderId = $post['hdOrderId'];
|
|
|
|
|
|
// 先获取配送订单,确保 $gdo 始终可用
|
|
|
- $hdo = HdDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'hdOrderId'=>$hdOrderId, 'orderStatus!='=> -1], true);
|
|
|
- if(empty($hdo)) {
|
|
|
+ $hdo = HdDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'hdOrderId' => $hdOrderId, 'orderStatus!=' => -1], true);
|
|
|
+ if (empty($hdo)) {
|
|
|
util::fail('未找到对应订单: ' . $hdOrderId);
|
|
|
}
|
|
|
|
|
|
// 如果没有提供平台和订单ID,从配送订单中获取
|
|
|
- if($platform == '' || $orderId == 0) {
|
|
|
+ if ($platform == '' || $orderId == 0) {
|
|
|
$orderId = $hdo->orderId;
|
|
|
$platform = $hdo->deliveryId;
|
|
|
}
|
|
|
@@ -224,20 +225,20 @@ class DeliveryController extends BaseController
|
|
|
$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、商家订单号
|
|
|
@@ -245,11 +246,11 @@ class DeliveryController extends BaseController
|
|
|
|
|
|
$post['order_cancel_role'] = 1; //1:商户取消, 2:用户取消
|
|
|
$ret = $ds->cancelOrder($orderId, $post);
|
|
|
- if($ret['code'] == 0) {
|
|
|
+ if ($ret['code'] == 0) {
|
|
|
// 更新跑腿订单与批发订单状态
|
|
|
$hdo->orderStatus = -1;
|
|
|
$hdo->cancelCost = $ret['platform'] !== 'fengniao' ? $ret['data']['deductionFee'] : $cancelCostCent; // 由于蜂鸟平台返回的扣费不一样造成
|
|
|
- if(!$hdo->save()) {
|
|
|
+ if (!$hdo->save()) {
|
|
|
Yii::error('保存配送订单失败: ' . json_encode($hdo->errors));
|
|
|
util::fail('保存配送订单失败');
|
|
|
}
|
|
|
@@ -259,7 +260,7 @@ class DeliveryController extends BaseController
|
|
|
$Order->sendStatus = -1;
|
|
|
$Order->status = 5;
|
|
|
$Order->deliveryId = '';
|
|
|
- if(!$Order->save()) {
|
|
|
+ if (!$Order->save()) {
|
|
|
Yii::error('保存批发订单失败: ' . json_encode($Order->errors));
|
|
|
util::fail('保存批发订单失败');
|
|
|
}
|
|
|
@@ -279,8 +280,8 @@ class DeliveryController extends BaseController
|
|
|
$hdOrderId = $post['hdOrderId'];
|
|
|
$platform = $post['platform'];
|
|
|
|
|
|
- $hdo = HdDeliveryOrderClass::getByCondition(['mainId'=>$this->mainId, 'hdOrderId'=>$hdOrderId, 'orderStatus!='=>-1], true);
|
|
|
- if(!empty($hdo)) {
|
|
|
+ $hdo = HdDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'hdOrderId' => $hdOrderId, 'orderStatus!=' => -1], true);
|
|
|
+ if (!empty($hdo)) {
|
|
|
$orderId = $hdo->orderId;
|
|
|
//$platform = $gdo->deliveryId;
|
|
|
} else {
|
|
|
@@ -289,10 +290,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']);
|
|
|
}
|
|
|
}
|
|
|
@@ -320,28 +321,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('取消授权失败');
|
|
|
}
|
|
|
@@ -353,7 +354,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;
|