上传附件优化
This commit is contained in:
@@ -38,21 +38,24 @@ class OrderShipService
|
||||
|
||||
/**
|
||||
* 需求交付发货单(开发者发货:凭证截图+交付附件+备注)
|
||||
* 多图/多文件统一存英文逗号分隔的 URL 字符串:
|
||||
* http://xxx/a.jpg,http://xxx/b.pdf
|
||||
* @param $order_no
|
||||
* @param $order_goods_spu_id
|
||||
* @param $demand_id
|
||||
* @param array $images
|
||||
* @param array $files
|
||||
* @param array $images URL 数组
|
||||
* @param array $files URL 数组
|
||||
* @param string $remark
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createDemandDelivery($order_no, $order_goods_spu_id, $demand_id, array $images, array $files, $remark = '')
|
||||
{
|
||||
$imagesStr = json_encode($images, JSON_UNESCAPED_UNICODE);
|
||||
$filesStr = json_encode($files, JSON_UNESCAPED_UNICODE);
|
||||
// 复用模型的规范化方法,统一为英文逗号分隔字符串
|
||||
$imagesStr = OrderShips::toUrlString($images);
|
||||
$filesStr = OrderShips::toUrlString($files);
|
||||
if (mb_strlen($imagesStr) > 1000 || mb_strlen($filesStr) > 1000) {
|
||||
exception('附件内容过多,请精简后重新发货');
|
||||
exception('附件数量过多或链接过长,请精简后重新发货');
|
||||
}
|
||||
$data = [
|
||||
'order_no' => $order_no,
|
||||
@@ -69,4 +72,60 @@ class OrderShipService
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需求最新的发货单(未发货返回 null)
|
||||
* @param int $demandId
|
||||
* @return OrderShips|null
|
||||
*/
|
||||
public static function getDemandLastShip($demandId)
|
||||
{
|
||||
return self::where(['demand_id' => $demandId])->order('id', 'desc')->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需求的交付内容(未发货返回 null)
|
||||
* 结构:['images' => [{url,name}], 'files' => [{url,name}], 'remark' => '', 'delivery_time' => 时间戳]
|
||||
* @param int $demandId
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getDemandDelivery($demandId)
|
||||
{
|
||||
$ship = self::getDemandLastShip($demandId);
|
||||
if (!$ship) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'images' => $ship->images_list,
|
||||
'files' => $ship->files_list,
|
||||
'remark' => $ship->remark,
|
||||
'delivery_time' => $ship->createtime,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断需求是否已发货
|
||||
* @param int $demandId
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasDemandDelivery($demandId)
|
||||
{
|
||||
return !empty(self::getDemandLastShip($demandId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取已发货的需求ID(用于列表按钮展示,避免 N+1 查询)
|
||||
* @param array $demandIds
|
||||
* @return array
|
||||
*/
|
||||
public static function getDeliveredDemandIds(array $demandIds)
|
||||
{
|
||||
$demandIds = array_filter(array_unique(array_map('intval', $demandIds)));
|
||||
if (!$demandIds) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::where(['demand_id' => ['in', $demandIds]])->column('demand_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user