|
|
@@ -3,7 +3,6 @@ namespace common\components\delivery\services\adapter;
|
|
|
|
|
|
|
|
|
use bizGhs\order\classes\OrderItemClass;
|
|
|
-use common\components\delivery\helpers\HttpClient;
|
|
|
use common\components\delivery\platform\shunfeng\Shunfeng;
|
|
|
use Yii;
|
|
|
|
|
|
@@ -165,6 +164,153 @@ class ShunfengAdapter extends Shunfeng implements Adapter
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 取消订单
|
|
|
+ *
|
|
|
+ * 当商家处发生异常需要取消配送时,调用此接口对订单进行取消操作。
|
|
|
+ * @param array $data 预取消查询参数,结构参考:
|
|
|
+ * [
|
|
|
+ * // ========== 必填参数(二选一)==========
|
|
|
+ * 'order_id' => '订单ID',
|
|
|
+ * 'partner_order_code' => '外部订单号',
|
|
|
+ * // 注意:order_id 和 partner_order_code 必填一个
|
|
|
+ *
|
|
|
+ * // ========== 必填参数 ==========
|
|
|
+ * 'order_cancel_code' => '取消原因code(从可用取消原因列表接口返回结果选择)',
|
|
|
+ * ]
|
|
|
+ * @param string $orderId 顺丰订单号(SF订单号或商家订单号)
|
|
|
+ * @param array $reason 取消原因信息
|
|
|
+ * [
|
|
|
+ * 'cancel_code' => int, // 可选:取消原因代码(默认313=其他)
|
|
|
+ * 'cancel_reason' => string, // 可选:其他取消原因说明
|
|
|
+ * 'order_type' => int // 可选:1-顺丰订单号,2-商家订单号(默认1)
|
|
|
+ * ]
|
|
|
+ * @return array 取消结果
|
|
|
+ */
|
|
|
+ public function cancelOrder($orderId, $data)
|
|
|
+ {
|
|
|
+ // 构建请求参数
|
|
|
+ $payload = [
|
|
|
+ 'order_id' => $orderId,
|
|
|
+ 'push_time' => time(), // 取消时间戳(秒级)
|
|
|
+ ];
|
|
|
+
|
|
|
+ $payload['cancel_code'] = $data['order_cancel_code'];
|
|
|
+ if(isset($data['order_cancel_reason'])){
|
|
|
+ $payload['cancel_reason'] = $data['order_cancel_reason'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['order_type'])) {
|
|
|
+ $payload['order_type'] = $data['order_type'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用API
|
|
|
+ $resp = $this->httpRequest('cancelorder', $payload);
|
|
|
+
|
|
|
+ // 处理响应
|
|
|
+ if (isset($resp['error_code']) && $resp['error_code'] == 0 && isset($resp['result'])) {
|
|
|
+ $result = $resp['result'];
|
|
|
+ return [
|
|
|
+ 'code' => 0,
|
|
|
+ 'platform' => 'shunfeng',
|
|
|
+ 'data' => [
|
|
|
+ 'deductionFee' => $result['deduction_detail']['deduction_fee'], //取消收费金额(单位:分)
|
|
|
+ 'sf_order_id' => $result['sf_order_id'],
|
|
|
+ 'shop_order_id' => $result['shop_order_id'],
|
|
|
+ 'shop_cancel_times' => $result['deduction_detail']['shop_cancel_times'],
|
|
|
+ 'free_cancel_times' => $result['deduction_detail']['free_cancel_times'],
|
|
|
+ 'push_time' => $result['push_time'],
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'code' => (int)($resp['error_code'] ?? -1),
|
|
|
+ 'platform' => 'shunfeng',
|
|
|
+ 'msg' => $resp['error_msg'] ?? 'Cancel order failed',
|
|
|
+ 'data' => null
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预取消订单
|
|
|
+ *
|
|
|
+ * 并非真正取消订单,用来验证是否可以取消订单并返回计价等信息。
|
|
|
+ *
|
|
|
+ * @param array $data 预取消订单参数
|
|
|
+ * [
|
|
|
+ * 'order_id' => string, // 必须:订单ID(顺丰订单号或商家订单号)
|
|
|
+ * 'cancel_reason' => string, // 可选:取消原因
|
|
|
+ * 'shop_id' => string, // 可选:店铺ID
|
|
|
+ * 'shop_type' => int // 可选:店铺类型(1-顺丰,2-接入方)
|
|
|
+ * ]
|
|
|
+ * @return array 预取消结果(包含是否可以取消、计费信息等)
|
|
|
+ */
|
|
|
+ public function preCancelOrder($data)
|
|
|
+ {
|
|
|
+ // 验证必填参数
|
|
|
+ if (empty($data['order_id'])) {
|
|
|
+ return [
|
|
|
+ 'code' => -1,
|
|
|
+ 'msg' => 'order_id is required',
|
|
|
+ 'data' => null
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建请求参数
|
|
|
+ $payload = [
|
|
|
+ 'order_id' => $data['order_id'],
|
|
|
+ 'push_time' => time(), // 取消时间戳(秒级)
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 添加可选参数
|
|
|
+ if (isset($data['cancel_reason']) && !empty($data['cancel_reason'])) {
|
|
|
+ $payload['cancel_reason'] = $data['cancel_reason'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['shop_id']) && !empty($data['shop_id'])) {
|
|
|
+ $payload['shop_id'] = $data['shop_id'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['shop_type'])) {
|
|
|
+ $payload['shop_type'] = $data['shop_type'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用API
|
|
|
+ $resp = $this->httpRequest('precancelorder', $payload);
|
|
|
+
|
|
|
+ // 处理响应
|
|
|
+ if (isset($resp['error_code']) && $resp['error_code'] == 0 && isset($resp['result'])) {
|
|
|
+ $result = $resp['result'];
|
|
|
+ return [
|
|
|
+ 'code' => 0,
|
|
|
+ 'platform' => 'shunfeng',
|
|
|
+ 'data' => [
|
|
|
+ 'order_type' => $result['order_type'],
|
|
|
+ 'could_cancel' => $result['could_cancel'],
|
|
|
+ 'promise_delivery_time' => $result['promise_delivery_time'], // 承诺配送时长(分)
|
|
|
+ 'delivery_type' => $result['delivery_type'], // 订单类型(0-预约送达,1-立即单,2-预约上门)
|
|
|
+ 'is_cancel_charge_price_rule' => $result['is_cancel_charge_price_rule'],
|
|
|
+ 'is_over_free_cancel_times' => $result['is_over_free_cancel_times'], // 是否超出免费取消次数
|
|
|
+ 'is_deduction_fee' => $result['is_deduction_fee'], // 是否有取消收费
|
|
|
+ 'deduction_fee' => $result['deduction_fee'], // 取消收费(单位:分)
|
|
|
+ 'cancel_charge_price_rule' => $result['cancel_charge_price_rule'],
|
|
|
+ 'shop_cancel_times' => $result['shop_cancel_times'],
|
|
|
+ 'free_cancel_times' => $result['free_cancel_times'],
|
|
|
+ 'sf_order_id' => $result['sf_order_id'],
|
|
|
+ 'shop_order_id' => $result['shop_order_id'],
|
|
|
+ 'push_time' => $result['push_time'],
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'code' => (int)($resp['error_code'] ?? -1),
|
|
|
+ 'msg' => $resp['error_msg'] ?? 'Pre-cancel order failed',
|
|
|
+ 'data' => null
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
public function getPrice($data)
|
|
|
{
|
|
|
// $requestData = [
|