| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace common\components\delivery\platform\shansong;
- /**
- * Class OrderStatusUtil
- * 闪送配送平台状态转换工具类
- * @package common\components\delivery\platform\shanSong
- */
- class SendStatusUtil
- {
- /**
- * 闪送平台订单状态到系统 orderStatus 的转换映射
- *
- * 闪送平台状态码说明:
- * 20 - 派单中(转单改派中)
- * subStatus: 1-派单中, 2-转单改派中
- * 30 - 待取货(已就位)
- * subStatus: 1-待取货, 2-已就位
- * 40 - 闪送中(申请取消中、物品送回中、取消单客服介入中)
- * subStatus: 1-闪送中, 2-申请取消中, 3-物品送回中, 4-取消单客服介入中
- * 50 - 已完成(已退款)
- * subStatus: 1-已完成, 2-已退款
- * 60 - 已取消
- *
- * 系统内 orderStatus 状态码说明:
- * 0 - 订单生成
- * 1 - 系统已接单
- * 2 - 派单中
- * 3 - 待取货
- * 4 - 配送中
- * 5 - 已送达
- * -1 - 已取消
- * -2 - 异常
- * 10 - 改派中
- * 20 - 已分配骑手
- * 30 - 骑手已到店
- * 40 - 申请取消中
- * 50 - 客服介入处理中
- */
- const STATUS_MAPPING = [
- 20 => 2, // 派单中 -> 派单中
- 30 => 3, // 待取货 -> 待取货
- 40 => 4, // 闪送中 -> 配送中
- 50 => 5, // 已完成 -> 已送达
- 60 => -1, // 已取消 -> 已取消
- ];
- /**
- * 子状态到系统状态的特殊映射
- * 格式:[主状态 => [子状态 => 系统状态]]
- */
- const SUB_STATUS_MAPPING = [
- 20 => [
- 1 => 2, // 派单中 -> 派单中
- 2 => 10, // 转单改派中 -> 改派中
- ],
- 30 => [
- 1 => 3, // 待取货 -> 待取货
- 2 => 30, // 已就位 -> 骑手已到店
- ],
- 40 => [
- 1 => 4, // 闪送中 -> 配送中
- 2 => 40, // 申请取消中 -> 申请取消中
- 3 => 4, // 物品送回中 -> 配送中
- 4 => 50, // 取消单客服介入中 -> 客服介入处理中
- ],
- 50 => [
- 1 => 5, // 已完成 -> 已送达
- 2 => 5, // 已退款 -> 已送达
- ],
- ];
- /**
- * 将闪送平台的订单状态转换为系统内的 orderStatus
- *
- * @param int $shansongStatus 闪送平台的订单状态码
- * @param int|null $subStatus 闪送平台的订单子状态码(可选)
- * @return int 转换后的系统 orderStatus 状态码
- * @throws \Exception 当状态码无法转换时抛出异常
- */
- public static function convertOrderStatus($shansongStatus, $subStatus = null)
- {
- $shansongStatus = (int)$shansongStatus;
-
- // 如果提供了子状态,优先使用子状态映射
- if ($subStatus !== null) {
- $subStatus = (int)$subStatus;
- if (isset(self::SUB_STATUS_MAPPING[$shansongStatus][$subStatus])) {
- return self::SUB_STATUS_MAPPING[$shansongStatus][$subStatus];
- }
- }
-
- // 使用主状态映射
- if (!isset(self::STATUS_MAPPING[$shansongStatus])) {
- throw new \Exception("无效的闪送订单状态码:{$shansongStatus}");
- }
-
- return self::STATUS_MAPPING[$shansongStatus];
- }
- /**
- * 获取闪送平台的状态描述
- *
- * @param int $shansongStatus 闪送平台的订单状态码
- * @param int|null $subStatus 闪送平台的订单子状态码(可选)
- * @return string 状态描述
- */
- public static function getStatusDesc($shansongStatus, $subStatus = null)
- {
- $mainStatusDescMap = [
- 20 => '派单中',
- 30 => '待取货',
- 40 => '闪送中',
- 50 => '已完成',
- 60 => '已取消',
- ];
-
- $subStatusDescMap = [
- 20 => [1 => '派单中', 2 => '转单改派中'],
- 30 => [1 => '待取货', 2 => '已就位'],
- 40 => [1 => '闪送中', 2 => '申请取消中', 3 => '物品送回中', 4 => '取消单客服介入中'],
- 50 => [1 => '已完成', 2 => '已退款'],
- ];
-
- $mainDesc = $mainStatusDescMap[$shansongStatus] ?? '未知状态';
-
- if ($subStatus !== null && isset($subStatusDescMap[$shansongStatus][$subStatus])) {
- return $subStatusDescMap[$shansongStatus][$subStatus];
- }
-
- return $mainDesc;
- }
- /**
- * 获取系统 orderStatus 的状态描述
- *
- * @param int $orderStatus 系统的 orderStatus 状态码
- * @return string 状态描述
- */
- public static function getOrderStatusDesc($orderStatus)
- {
- $statusDescMap = [
- 0 => '订单生成',
- 1 => '系统已接单',
- 2 => '派单中',
- 3 => '待取货',
- 4 => '配送中',
- 5 => '已送达',
- -1 => '已取消',
- -2 => '异常',
- 10 => '改派中',
- 20 => '已分配骑手',
- 30 => '骑手已到店',
- 40 => '申请取消中',
- 50 => '客服介入处理中',
- ];
-
- return $statusDescMap[$orderStatus] ?? '未知状态';
- }
- /**
- * 获取取消发起人描述
- *
- * @param int $abortType 取消发起人类型
- * @return string 描述
- */
- public static function getAbortTypeDesc($abortType)
- {
- $descMap = [
- 1 => '客户发起取消',
- 3 => '闪送员发起取消',
- 10 => '系统自动发起取消',
- ];
-
- return $descMap[$abortType] ?? '未知';
- }
- /**
- * 获取取消责任人描述
- *
- * @param int $punishType 取消责任人类型
- * @return string 描述
- */
- public static function getPunishTypeDesc($punishType)
- {
- $descMap = [
- 1 => '因客户',
- 2 => '因服务',
- 3 => '因闪送员',
- 10 => '因系统自动取消',
- 99 => '因其它',
- ];
-
- return $descMap[$punishType] ?? '未知';
- }
- }
|