79 行
1.9 KiB
PHP
79 行
1.9 KiB
PHP
<?php
|
||
namespace Common\Business;
|
||
|
||
/**
|
||
* 骑手订单状态工具类
|
||
* 统一维护状态文本与数值/集合映射
|
||
*/
|
||
class OrderStatusUtil
|
||
{
|
||
/**
|
||
* 状态键到文本映射
|
||
*/
|
||
private static $statusTexts = array(
|
||
'pending' => '待分配',
|
||
'accepted' => '已接单',
|
||
'picking_up' => '取货中',
|
||
'delivering' => '配送中',
|
||
'completed' => '已完成',
|
||
'cancelled' => '已取消',
|
||
'exception' => '异常'
|
||
);
|
||
|
||
/**
|
||
* 状态键到数值/集合条件映射(用于 ThinkPHP where)
|
||
*/
|
||
private static $statusConditions = array(
|
||
'pending' => 0,
|
||
'accepted' => 1,
|
||
'picking_up' => array('in', array(2, 3, 4)),
|
||
'delivering' => 5,
|
||
'completed' => 6,
|
||
'cancelled' => 8,
|
||
'exception' => 7
|
||
);
|
||
|
||
/**
|
||
* 获取状态文本
|
||
*/
|
||
public static function getStatusText($key)
|
||
{
|
||
return isset(self::$statusTexts[$key]) ? self::$statusTexts[$key] : '未知';
|
||
}
|
||
|
||
/**
|
||
* 获取 where 条件值(可能为整数或 ['in', [...]])
|
||
*/
|
||
public static function getStatusCondition($key)
|
||
{
|
||
return isset(self::$statusConditions[$key]) ? self::$statusConditions[$key] : null;
|
||
}
|
||
|
||
/**
|
||
* 获取在途(包含取货中与配送中)的状态集合
|
||
*/
|
||
public static function getInTransitStatuses()
|
||
{
|
||
return array(2, 3, 4, 5);
|
||
}
|
||
|
||
/**
|
||
* 获取进行中订单的状态集合(用于当前任务统计)
|
||
*/
|
||
public static function getInProgressStatuses()
|
||
{
|
||
return array(1, 2, 3, 4, 5);
|
||
}
|
||
|
||
/**
|
||
* 获取指定键的数值状态(如 completed -> 6)
|
||
*/
|
||
public static function getNumericStatus($key)
|
||
{
|
||
$cond = self::getStatusCondition($key);
|
||
if (is_array($cond)) {
|
||
return null;
|
||
}
|
||
return $cond;
|
||
}
|
||
} |