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] ?? '未知'; } }