SendStatusUtil.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace common\components\delivery\platform\shansong;
  3. /**
  4. * Class OrderStatusUtil
  5. * 闪送配送平台状态转换工具类
  6. * @package common\components\delivery\platform\shanSong
  7. */
  8. class SendStatusUtil
  9. {
  10. /**
  11. * 闪送平台订单状态到系统 orderStatus 的转换映射
  12. *
  13. * 闪送平台状态码说明:
  14. * 20 - 派单中(转单改派中)
  15. * subStatus: 1-派单中, 2-转单改派中
  16. * 30 - 待取货(已就位)
  17. * subStatus: 1-待取货, 2-已就位
  18. * 40 - 闪送中(申请取消中、物品送回中、取消单客服介入中)
  19. * subStatus: 1-闪送中, 2-申请取消中, 3-物品送回中, 4-取消单客服介入中
  20. * 50 - 已完成(已退款)
  21. * subStatus: 1-已完成, 2-已退款
  22. * 60 - 已取消
  23. *
  24. * 系统内 orderStatus 状态码说明:
  25. * 0 - 订单生成
  26. * 1 - 系统已接单
  27. * 2 - 派单中
  28. * 3 - 待取货
  29. * 4 - 配送中
  30. * 5 - 已送达
  31. * -1 - 已取消
  32. * -2 - 异常
  33. * 10 - 改派中
  34. * 20 - 已分配骑手
  35. * 30 - 骑手已到店
  36. * 40 - 申请取消中
  37. * 50 - 客服介入处理中
  38. */
  39. const STATUS_MAPPING = [
  40. 20 => 2, // 派单中 -> 派单中
  41. 30 => 3, // 待取货 -> 待取货
  42. 40 => 4, // 闪送中 -> 配送中
  43. 50 => 5, // 已完成 -> 已送达
  44. 60 => -1, // 已取消 -> 已取消
  45. ];
  46. /**
  47. * 子状态到系统状态的特殊映射
  48. * 格式:[主状态 => [子状态 => 系统状态]]
  49. */
  50. const SUB_STATUS_MAPPING = [
  51. 20 => [
  52. 1 => 2, // 派单中 -> 派单中
  53. 2 => 10, // 转单改派中 -> 改派中
  54. ],
  55. 30 => [
  56. 1 => 3, // 待取货 -> 待取货
  57. 2 => 30, // 已就位 -> 骑手已到店
  58. ],
  59. 40 => [
  60. 1 => 4, // 闪送中 -> 配送中
  61. 2 => 40, // 申请取消中 -> 申请取消中
  62. 3 => 4, // 物品送回中 -> 配送中
  63. 4 => 50, // 取消单客服介入中 -> 客服介入处理中
  64. ],
  65. 50 => [
  66. 1 => 5, // 已完成 -> 已送达
  67. 2 => 5, // 已退款 -> 已送达
  68. ],
  69. ];
  70. /**
  71. * 将闪送平台的订单状态转换为系统内的 orderStatus
  72. *
  73. * @param int $shansongStatus 闪送平台的订单状态码
  74. * @param int|null $subStatus 闪送平台的订单子状态码(可选)
  75. * @return int 转换后的系统 orderStatus 状态码
  76. * @throws \Exception 当状态码无法转换时抛出异常
  77. */
  78. public static function convertOrderStatus($shansongStatus, $subStatus = null)
  79. {
  80. $shansongStatus = (int)$shansongStatus;
  81. // 如果提供了子状态,优先使用子状态映射
  82. if ($subStatus !== null) {
  83. $subStatus = (int)$subStatus;
  84. if (isset(self::SUB_STATUS_MAPPING[$shansongStatus][$subStatus])) {
  85. return self::SUB_STATUS_MAPPING[$shansongStatus][$subStatus];
  86. }
  87. }
  88. // 使用主状态映射
  89. if (!isset(self::STATUS_MAPPING[$shansongStatus])) {
  90. throw new \Exception("无效的闪送订单状态码:{$shansongStatus}");
  91. }
  92. return self::STATUS_MAPPING[$shansongStatus];
  93. }
  94. /**
  95. * 获取闪送平台的状态描述
  96. *
  97. * @param int $shansongStatus 闪送平台的订单状态码
  98. * @param int|null $subStatus 闪送平台的订单子状态码(可选)
  99. * @return string 状态描述
  100. */
  101. public static function getStatusDesc($shansongStatus, $subStatus = null)
  102. {
  103. $mainStatusDescMap = [
  104. 20 => '派单中',
  105. 30 => '待取货',
  106. 40 => '闪送中',
  107. 50 => '已完成',
  108. 60 => '已取消',
  109. ];
  110. $subStatusDescMap = [
  111. 20 => [1 => '派单中', 2 => '转单改派中'],
  112. 30 => [1 => '待取货', 2 => '已就位'],
  113. 40 => [1 => '闪送中', 2 => '申请取消中', 3 => '物品送回中', 4 => '取消单客服介入中'],
  114. 50 => [1 => '已完成', 2 => '已退款'],
  115. ];
  116. $mainDesc = $mainStatusDescMap[$shansongStatus] ?? '未知状态';
  117. if ($subStatus !== null && isset($subStatusDescMap[$shansongStatus][$subStatus])) {
  118. return $subStatusDescMap[$shansongStatus][$subStatus];
  119. }
  120. return $mainDesc;
  121. }
  122. /**
  123. * 获取系统 orderStatus 的状态描述
  124. *
  125. * @param int $orderStatus 系统的 orderStatus 状态码
  126. * @return string 状态描述
  127. */
  128. public static function getOrderStatusDesc($orderStatus)
  129. {
  130. $statusDescMap = [
  131. 0 => '订单生成',
  132. 1 => '系统已接单',
  133. 2 => '派单中',
  134. 3 => '待取货',
  135. 4 => '配送中',
  136. 5 => '已送达',
  137. -1 => '已取消',
  138. -2 => '异常',
  139. 10 => '改派中',
  140. 20 => '已分配骑手',
  141. 30 => '骑手已到店',
  142. 40 => '申请取消中',
  143. 50 => '客服介入处理中',
  144. ];
  145. return $statusDescMap[$orderStatus] ?? '未知状态';
  146. }
  147. /**
  148. * 获取取消发起人描述
  149. *
  150. * @param int $abortType 取消发起人类型
  151. * @return string 描述
  152. */
  153. public static function getAbortTypeDesc($abortType)
  154. {
  155. $descMap = [
  156. 1 => '客户发起取消',
  157. 3 => '闪送员发起取消',
  158. 10 => '系统自动发起取消',
  159. ];
  160. return $descMap[$abortType] ?? '未知';
  161. }
  162. /**
  163. * 获取取消责任人描述
  164. *
  165. * @param int $punishType 取消责任人类型
  166. * @return string 描述
  167. */
  168. public static function getPunishTypeDesc($punishType)
  169. {
  170. $descMap = [
  171. 1 => '因客户',
  172. 2 => '因服务',
  173. 3 => '因闪送员',
  174. 10 => '因系统自动取消',
  175. 99 => '因其它',
  176. ];
  177. return $descMap[$punishType] ?? '未知';
  178. }
  179. }