| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace common\components\delivery\platform\shansong;
- /**
- * Class SystemStatusUtil
- * 闪送配送平台状态转换工具类 (转换为主订单 status)
- * @package common\components\delivery\platform\shansong
- */
- class OrderStatusUtil
- {
- /**
- * 闪送平台订单状态到系统 status 的转换映射
- *
- * 闪送平台状态码说明:
- * 20 - 派单中(转单改派中)
- * 30 - 待取货(已就位)
- * 40 - 闪送中(申请取消中、物品送回中、取消单客服介入中)
- * 50 - 已完成(已退款)
- * 60 - 已取消
- *
- * 系统内 status 状态码说明:
- * 1 - 待付款
- * 2 - 待配送
- * 3 - 配送中
- * 4 - 已完成
- * 5 - 已取消
- */
- const STATUS_MAPPING = [
- 20 => 3, // 派单中 -> 配送中
- 30 => 3, // 待取货 -> 配送中
- 40 => 3, // 闪送中 -> 配送中
- 50 => 4, // 已完成 -> 已完成
- 60 => 2, // 已取消 -> 待配送(配送的取消不等于订单的取消,由于 status 带有配送状态,所以改为:待配送)
- ];
- /**
- * 将闪送平台的订单状态转换为系统内的 status
- *
- * @param int $shansongStatus 闪送平台的订单状态码
- * @param int|null $subStatus 闪送平台的订单子状态码(可选)
- * @return int 转换后的系统 status 状态码
- * @throws \Exception 当状态码无法转换时抛出异常
- */
- public static function convertStatus($shansongStatus, $subStatus = null)
- {
- $shansongStatus = (int)$shansongStatus;
-
- // 此处不需要子状态映射,因为系统 status 状态较粗粒度
- // 20(派单中), 30(待取货) 都对应 3(配送中)
- // 40(闪送中) 对应 3(配送中)
-
- 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;
- }
- /**
- * 获取系统 status 的状态描述
- *
- * @param int $status 系统的 status 状态码
- * @return string 状态描述
- */
- public static function getSystemStatusDesc($status)
- {
- $statusDescMap = [
- 1 => '待付款',
- 2 => '待配送',
- 3 => '配送中',
- 4 => '已完成',
- 5 => '已取消',
- ];
-
- return $statusDescMap[$status] ?? '未知状态';
- }
- }
|