移除地区的校验,不需要填地区
This commit is contained in:
@@ -18,7 +18,7 @@ class Address extends Backend
|
||||
|
||||
* 收获地址管理
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
class Address extends Backend
|
||||
|
||||
@@ -63,41 +63,4 @@ class Address extends Backend
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 查看
|
||||
|
||||
* @throws Throwable
|
||||
|
||||
*/
|
||||
|
||||
public function index(\Webman\Http\Request $request): \support\Response
|
||||
|
||||
{
|
||||
|
||||
$response = $this->initializeBackend($request);
|
||||
|
||||
if ($response !== null) {
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($request->get('select') || $request->post('select')) {
|
||||
|
||||
$this->_select();
|
||||
|
||||
return $this->success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
|
||||
$res = $this->model
|
||||
|
||||
->with(['playxUserAsset' => function ($query) {
|
||||
|
||||
|
||||
|
||||
@@ -1221,11 +1221,10 @@ SQL;
|
||||
|
||||
$phone = trim(strval($request->post('phone', '')));
|
||||
$receiverName = trim(strval($request->post('receiver_name', '')));
|
||||
$region = MallAddress::normalizeRegion($request->post('region', ''));
|
||||
$detailAddress = trim(strval($request->post('detail_address', '')));
|
||||
$defaultSetting = strval($request->post('default_setting', '0')) === '1' ? 1 : 0;
|
||||
|
||||
if ($phone === '' || $receiverName === '' || $detailAddress === '' || $region === '' || $region === null) {
|
||||
if ($phone === '' || $receiverName === '' || $detailAddress === '') {
|
||||
return $this->error(__('Missing required fields'));
|
||||
}
|
||||
|
||||
@@ -1239,7 +1238,6 @@ SQL;
|
||||
'playx_user_asset_id' => $assetId,
|
||||
'receiver_name' => $receiverName,
|
||||
'phone' => $phone,
|
||||
'region' => $region,
|
||||
'detail_address' => $detailAddress,
|
||||
'default_setting' => $defaultSetting,
|
||||
'create_time' => time(),
|
||||
@@ -1290,9 +1288,6 @@ SQL;
|
||||
if ($request->post('receiver_name', null) !== null) {
|
||||
$updates['receiver_name'] = trim(strval($request->post('receiver_name', '')));
|
||||
}
|
||||
if ($request->post('region', null) !== null) {
|
||||
$updates['region'] = MallAddress::normalizeRegion($request->post('region', ''));
|
||||
}
|
||||
if ($request->post('detail_address', null) !== null) {
|
||||
$updates['detail_address'] = trim(strval($request->post('detail_address', '')));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace app\common\model;
|
||||
|
||||
use app\common\model\traits\TimestampInteger;
|
||||
use support\think\Db;
|
||||
use support\think\Model;
|
||||
|
||||
/**
|
||||
@@ -19,122 +18,27 @@ class MallAddress extends Model
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'region_text',
|
||||
];
|
||||
/** 地区字段已废弃,接口与后台不再使用 */
|
||||
protected array $hidden = ['region'];
|
||||
|
||||
protected static function onBeforeInsert($model): void
|
||||
{
|
||||
$model->set('region', '');
|
||||
}
|
||||
|
||||
protected static function onBeforeUpdate($model): void
|
||||
{
|
||||
$model->set('region', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单展示:文本地区返回规范化字符串;历史地区 ID 转为名称(英文逗号拼接)
|
||||
*/
|
||||
public function getregionAttr($value): string
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return '';
|
||||
}
|
||||
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);
|
||||
return trim(strval($value ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* 入库:统一为英文逗号分隔(与 API / 原 city 组件存储格式一致)
|
||||
*/
|
||||
public function setregionAttr($value): string
|
||||
{
|
||||
return self::normalizeRegion($value);
|
||||
}
|
||||
|
||||
public function getregionTextAttr($value, $row): string
|
||||
{
|
||||
$region = $row['region'] ?? '';
|
||||
if ($region === '' || $region === null) {
|
||||
return '';
|
||||
}
|
||||
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);
|
||||
return '';
|
||||
}
|
||||
|
||||
public function playxUserAsset(): \think\model\relation\BelongsTo
|
||||
@@ -149,19 +53,10 @@ class MallAddress extends Model
|
||||
*/
|
||||
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,
|
||||
'receiver_address' => trim($addr->detail_address ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user