优化接口以及后台页面样式

This commit is contained in:
2026-03-31 15:37:32 +08:00
parent 2868899253
commit 520e950dc5
28 changed files with 1241 additions and 311 deletions

View File

@@ -41,7 +41,18 @@ class MallAddress extends Model
public function getregionTextAttr($value, $row): string
{
if ($row['region'] === '' || $row['region'] === null) return '';
$cityNames = \support\think\Db::name('area')->whereIn('id', $row['region'])->column('name');
$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)) {
return '';
}
$cityNames = \support\think\Db::name('area')->whereIn('id', $ids)->column('name');
return $cityNames ? implode(',', $cityNames) : '';
}
@@ -49,4 +60,27 @@ class MallAddress extends Model
{
return $this->belongsTo(\app\common\model\MallUserAsset::class, 'playx_user_asset_id', 'id');
}
/**
* 实物订单收货快照(写入 mall_order.receiver_*,与 mall_address 当前内容一致)
*
* @return array{receiver_name: string, receiver_phone: string, receiver_address: string}
*/
public static function snapshotForPhysicalOrder(self $addr): array
{
$regionText = $addr->region_text ?? '';
$parts = array_filter([
trim($regionText),
trim($addr->detail_address ?? ''),
], static function ($s) {
return $s !== '';
});
$receiverAddress = implode(' ', $parts);
return [
'receiver_name' => trim($addr->receiver_name ?? ''),
'receiver_phone' => trim($addr->phone ?? ''),
'receiver_address' => $receiverAddress,
];
}
}

View File

@@ -28,6 +28,7 @@ use support\think\Model;
* @property string $receiver_name
* @property string $receiver_phone
* @property string|null $receiver_address
* @property int|null $mall_address_id
*/
class MallOrder extends Model
{
@@ -56,12 +57,18 @@ class MallOrder extends Model
'points_cost' => 'integer',
'amount' => 'float',
'multiplier' => 'integer',
'retry_count' => 'integer',
'retry_count' => 'integer',
'mall_address_id' => 'integer',
];
public function mallItem(): \think\model\relation\BelongsTo
{
return $this->belongsTo(MallItem::class, 'mall_item_id', 'id');
}
public function mallAddress(): \think\model\relation\BelongsTo
{
return $this->belongsTo(MallAddress::class, 'mall_address_id', 'id');
}
}

View File

@@ -31,18 +31,21 @@ class MallUserAsset extends Model
*/
public static function ensureForUsername(string $username): self
{
// $username = trim($username);
$username = trim($username);
$existing = self::where('username', $username)->find();
if ($existing) {
return $existing;
}
//手机号直接=用户名,暂时不做验证
// $phone = self::allocateUniquePhone();
// 创建用户时phone 与 username 同值H5 临时账号)
$phone = $username;
if ($phone === null) {
throw new \RuntimeException('Failed to allocate unique phone');
$phoneExisting = self::where('phone', $phone)->find();
if ($phoneExisting) {
// 若历史数据存在“手机号=用户名”的行,直接复用;若不一致则拒绝创建,避免污染
if (trim((string) ($phoneExisting->username ?? '')) === $username) {
return $phoneExisting;
}
throw new \RuntimeException('Username is already used by another account');
}
$pwd = hash_password(Random::build('alnum', 16));
@@ -77,16 +80,6 @@ class MallUserAsset extends Model
return $created;
}
private static function allocateUniquePhone(): ?string
{
for ($i = 0; $i < 8; $i++) {
$candidate = '13' . sprintf('%09d', mt_rand(0, 999999999));
if (!self::where('phone', $candidate)->find()) {
return $candidate;
}
}
return null;
}
// allocateUniquePhone 已废弃:临时登录场景下 phone=用户名
}