Files
code-bang/backend/application/common/model/order/Ships.php
T

117 lines
2.6 KiB
PHP
Raw Normal View History

2026-09-17 16:25:31 +08:00
<?php
namespace app\common\model\order;
use think\Model;
class Ships extends Model
{
// 表名
protected $name = 'order_ships';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
2026-09-30 16:57:26 +08:00
'images_list',
2026-10-08 20:34:08 +08:00
'files_list',
'deliver_links_list'
2026-09-17 16:25:31 +08:00
];
2026-09-30 16:57:26 +08:00
/**
* 多图列表([{url, name}]),供接口与后台直接使用
*/
public function getImagesListAttr($value, $data)
{
return self::parseUrlList($data['images'] ?? '');
}
/**
* 多文件列表([{url, name}]),供接口与后台直接使用
*/
public function getFilesListAttr($value, $data)
{
return self::parseUrlList($data['files'] ?? '');
}
2026-10-08 20:34:08 +08:00
/**
* 交付链接列表([{url, name}]),供接口与后台直接使用
*/
public function getDeliverLinksListAttr($value, $data)
{
return self::parseUrlList($data['deliver_links'] ?? '');
}
2026-09-30 16:57:26 +08:00
/**
* 解析多图/多文件字段:英文逗号分隔的 URL 字符串 -> [{url, name}]
* 例:http://a.com/1.jpg,http://a.com/2.pdf => [['url'=>'http://a.com/1.jpg','name'=>'1.jpg'], ...]
* 文件名取 URL 末段并 urldecode(OSS 路径为中文转义)
* @param string $value
* @return array
*/
public static function parseUrlList($value)
{
$value = trim((string)$value);
if ($value === '') {
return [];
}
$list = [];
foreach (array_filter(explode(',', $value)) as $url) {
$url = trim($url);
if (!$url) {
continue;
}
$list[] = [
'url' => $url,
'name' => urldecode(basename($url))
];
}
return $list;
}
/**
* 将 URL 列表规范化为英文逗号分隔字符串(写入库时使用)
* 支持传入 URL 数组或 [{url=>''}] 数组
* @param array|string $value
* @return string
*/
public static function toUrlString($value)
{
if (is_string($value)) {
$value = array_filter(explode(',', $value));
}
$urls = [];
foreach ((array)$value as $item) {
$url = is_array($item) ? trim($item['url'] ?? '') : trim((string)$item);
if ($url) {
$urls[] = $url;
}
}
return implode(',', array_unique($urls));
}
2026-09-17 16:25:31 +08:00
}