优化增加第三方【每日推送】原始数据记录日志.log

This commit is contained in:
2026-07-21 16:44:39 +08:00
parent 2fbc07329e
commit 4fbc4500fd
16 changed files with 371 additions and 143 deletions

View File

@@ -3,6 +3,7 @@
namespace app\common\model;
use app\common\model\traits\TimestampInteger;
use support\think\Db;
use support\think\Model;
/**
@@ -23,37 +24,117 @@ class MallAddress extends Model
'region_text',
];
public function getregionAttr($value): array
/**
* 表单展示:文本地区返回规范化字符串;历史地区 ID 转为名称(英文逗号拼接)
*/
public function getregionAttr($value): string
{
if ($value === '' || $value === null) return [];
if (!is_array($value)) {
return explode(',', $value);
if ($value === '' || $value === null) {
return '';
}
return $value;
if (is_array($value)) {
return self::normalizeRegion($value);
}
$region = trim(strval($value));
if ($region === '') {
return '';
}
if (self::isAreaIdList($region)) {
return self::resolveAreaNames($region);
}
return self::normalizeRegion($region);
}
/**
* 入库:统一为英文逗号分隔(与 API / 原 city 组件存储格式一致)
*/
public function setregionAttr($value): string
{
return is_array($value) ? implode(',', $value) : $value;
return self::normalizeRegion($value);
}
public function getregionTextAttr($value, $row): string
{
if ($row['region'] === '' || $row['region'] === null) return '';
$region = $row['region'];
$ids = $region;
if (!is_array($ids)) {
$ids = explode(',', (string) $ids);
}
$ids = array_values(array_filter(array_map('trim', $ids), static function ($s) {
return $s !== '';
}));
if (empty($ids)) {
$region = $row['region'] ?? '';
if ($region === '' || $region === null) {
return '';
}
$cityNames = \support\think\Db::name('area')->whereIn('id', $ids)->column('name');
return $cityNames ? implode(',', $cityNames) : '';
if (is_array($region)) {
return self::normalizeRegion($region);
}
$region = trim(strval($region));
if ($region === '') {
return '';
}
if (self::isAreaIdList($region)) {
return self::resolveAreaNames($region);
}
return self::normalizeRegion($region);
}
/**
* 将地区规范为英文逗号分隔字符串(数组或「省,市,区」文本)
*/
public static function normalizeRegion(mixed $value): string
{
if (is_array($value)) {
$parts = [];
foreach ($value as $item) {
$part = trim(strval($item));
if ($part !== '') {
$parts[] = $part;
}
}
return implode(',', $parts);
}
$region = trim(strval($value));
if ($region === '') {
return '';
}
$region = str_replace('', ',', $region);
$parts = explode(',', $region);
$normalized = [];
foreach ($parts as $part) {
$part = trim($part);
if ($part !== '') {
$normalized[] = $part;
}
}
return implode(',', $normalized);
}
public static function isAreaIdList(string $region): bool
{
$parts = array_values(array_filter(array_map('trim', explode(',', $region)), static function ($part) {
return $part !== '';
}));
if ($parts === []) {
return false;
}
foreach ($parts as $part) {
if (!ctype_digit($part)) {
return false;
}
}
return true;
}
public static function resolveAreaNames(string $region): string
{
$ids = array_values(array_filter(array_map('trim', explode(',', $region)), static function ($part) {
return $part !== '';
}));
if ($ids === []) {
return '';
}
$cityNames = Db::name('area')->whereIn('id', $ids)->column('name');
if (!$cityNames) {
return self::normalizeRegion($region);
}
return implode(',', $cityNames);
}
public function playxUserAsset(): \think\model\relation\BelongsTo
@@ -83,4 +164,4 @@ class MallAddress extends Model
'receiver_address' => $receiverAddress,
];
}
}
}