移除地区的校验,不需要填地区
This commit is contained in:
@@ -18,7 +18,7 @@ class Address extends Backend
|
|||||||
|
|
||||||
* 收获地址管理
|
* 收获地址管理
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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', '')));
|
$phone = trim(strval($request->post('phone', '')));
|
||||||
$receiverName = trim(strval($request->post('receiver_name', '')));
|
$receiverName = trim(strval($request->post('receiver_name', '')));
|
||||||
$region = MallAddress::normalizeRegion($request->post('region', ''));
|
|
||||||
$detailAddress = trim(strval($request->post('detail_address', '')));
|
$detailAddress = trim(strval($request->post('detail_address', '')));
|
||||||
$defaultSetting = strval($request->post('default_setting', '0')) === '1' ? 1 : 0;
|
$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'));
|
return $this->error(__('Missing required fields'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1239,7 +1238,6 @@ SQL;
|
|||||||
'playx_user_asset_id' => $assetId,
|
'playx_user_asset_id' => $assetId,
|
||||||
'receiver_name' => $receiverName,
|
'receiver_name' => $receiverName,
|
||||||
'phone' => $phone,
|
'phone' => $phone,
|
||||||
'region' => $region,
|
|
||||||
'detail_address' => $detailAddress,
|
'detail_address' => $detailAddress,
|
||||||
'default_setting' => $defaultSetting,
|
'default_setting' => $defaultSetting,
|
||||||
'create_time' => time(),
|
'create_time' => time(),
|
||||||
@@ -1290,9 +1288,6 @@ SQL;
|
|||||||
if ($request->post('receiver_name', null) !== null) {
|
if ($request->post('receiver_name', null) !== null) {
|
||||||
$updates['receiver_name'] = trim(strval($request->post('receiver_name', '')));
|
$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) {
|
if ($request->post('detail_address', null) !== null) {
|
||||||
$updates['detail_address'] = trim(strval($request->post('detail_address', '')));
|
$updates['detail_address'] = trim(strval($request->post('detail_address', '')));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
use app\common\model\traits\TimestampInteger;
|
use app\common\model\traits\TimestampInteger;
|
||||||
use support\think\Db;
|
|
||||||
use support\think\Model;
|
use support\think\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,122 +18,27 @@ class MallAddress extends Model
|
|||||||
// 自动写入时间戳字段
|
// 自动写入时间戳字段
|
||||||
protected $autoWriteTimestamp = true;
|
protected $autoWriteTimestamp = true;
|
||||||
|
|
||||||
// 追加属性
|
/** 地区字段已废弃,接口与后台不再使用 */
|
||||||
protected $append = [
|
protected array $hidden = ['region'];
|
||||||
'region_text',
|
|
||||||
];
|
protected static function onBeforeInsert($model): void
|
||||||
|
{
|
||||||
|
$model->set('region', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function onBeforeUpdate($model): void
|
||||||
|
{
|
||||||
|
$model->set('region', '');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 表单展示:文本地区返回规范化字符串;历史地区 ID 转为名称(英文逗号拼接)
|
|
||||||
*/
|
|
||||||
public function getregionAttr($value): string
|
public function getregionAttr($value): string
|
||||||
{
|
{
|
||||||
if ($value === '' || $value === null) {
|
return trim(strval($value ?? ''));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 入库:统一为英文逗号分隔(与 API / 原 city 组件存储格式一致)
|
|
||||||
*/
|
|
||||||
public function setregionAttr($value): string
|
public function setregionAttr($value): string
|
||||||
{
|
{
|
||||||
return self::normalizeRegion($value);
|
return '';
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function playxUserAsset(): \think\model\relation\BelongsTo
|
public function playxUserAsset(): \think\model\relation\BelongsTo
|
||||||
@@ -149,19 +53,10 @@ class MallAddress extends Model
|
|||||||
*/
|
*/
|
||||||
public static function snapshotForPhysicalOrder(self $addr): array
|
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 [
|
return [
|
||||||
'receiver_name' => trim($addr->receiver_name ?? ''),
|
'receiver_name' => trim($addr->receiver_name ?? ''),
|
||||||
'receiver_phone' => trim($addr->phone ?? ''),
|
'receiver_phone' => trim($addr->phone ?? ''),
|
||||||
'receiver_address' => $receiverAddress,
|
'receiver_address' => trim($addr->detail_address ?? ''),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ curl -G "https://{域名}/api/v1/mall/pointsLogs" \
|
|||||||
### 4.2 新增地址
|
### 4.2 新增地址
|
||||||
**POST** ` /api/v1/mall/addressAdd `
|
**POST** ` /api/v1/mall/addressAdd `
|
||||||
|
|
||||||
Body 含 `receiver_name`(收货人,建议填写;实物兑换下单快照需要非空的收货人、电话与拼接后的完整地址)。
|
Body 含 `receiver_name`、`phone`、`detail_address`(完整收货地址,必填);实物兑换下单快照使用上述字段。
|
||||||
|
|
||||||
### 4.3 编辑地址
|
### 4.3 编辑地址
|
||||||
**POST** ` /api/v1/mall/addressEdit `
|
**POST** ` /api/v1/mall/addressEdit `
|
||||||
|
|||||||
@@ -326,8 +326,7 @@ Body:
|
|||||||
|------|------|------|
|
|------|------|------|
|
||||||
| `receiver_name` | 是 | 收货人 |
|
| `receiver_name` | 是 | 收货人 |
|
||||||
| `phone` | 是 | 电话 |
|
| `phone` | 是 | 电话 |
|
||||||
| `region` | 是 | 地区(数组或逗号分隔字符串) |
|
| `detail_address` | 是 | 完整收货地址 |
|
||||||
| `detail_address` | 是 | 详细地址 |
|
|
||||||
| `default_setting` | 否 | `1` 设为默认地址 |
|
| `default_setting` | 否 | `1` 设为默认地址 |
|
||||||
|
|
||||||
#### 3.x.3 修改地址(含设为默认)
|
#### 3.x.3 修改地址(含设为默认)
|
||||||
|
|||||||
@@ -577,8 +577,7 @@ GET /api/v1/mall/addressList?session_id=fc7f3e3f0d0f4cb29f66e4c8fbab4f66
|
|||||||
"session_id": "fc7f3e3f0d0f4cb29f66e4c8fbab4f66",
|
"session_id": "fc7f3e3f0d0f4cb29f66e4c8fbab4f66",
|
||||||
"receiver_name": "Tom",
|
"receiver_name": "Tom",
|
||||||
"phone": "0123456789",
|
"phone": "0123456789",
|
||||||
"region": "Kuala Lumpur,KLCC",
|
"detail_address": "Tower A, 8F, Kuala Lumpur",
|
||||||
"detail_address": "Tower A, 8F",
|
|
||||||
"default_setting": 1
|
"default_setting": 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ export default {
|
|||||||
playxuserasset__username: 'username',
|
playxuserasset__username: 'username',
|
||||||
receiver_name: 'receiver name',
|
receiver_name: 'receiver name',
|
||||||
phone: 'phone',
|
phone: 'phone',
|
||||||
region: 'region',
|
|
||||||
region_tip: 'Separate levels with commas, e.g. Kuala Lumpur,KLCC',
|
|
||||||
detail_address: 'detail_address',
|
detail_address: 'detail_address',
|
||||||
default_setting: 'Default address',
|
default_setting: 'Default address',
|
||||||
'default_setting 0': '--',
|
'default_setting 0': '--',
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ export default {
|
|||||||
playxuserasset__username: '用户名',
|
playxuserasset__username: '用户名',
|
||||||
receiver_name: '收货人',
|
receiver_name: '收货人',
|
||||||
phone: '电话',
|
phone: '电话',
|
||||||
region: '地区',
|
|
||||||
region_tip: '多个层级请用英文逗号分隔,如:广东省,广州市,天河区',
|
|
||||||
detail_address: '详细地址',
|
detail_address: '详细地址',
|
||||||
default_setting: '默认地址',
|
default_setting: '默认地址',
|
||||||
'default_setting 0': '--',
|
'default_setting 0': '--',
|
||||||
|
|||||||
@@ -39,28 +39,6 @@ const { t } = useI18n()
|
|||||||
const tableRef = useTemplateRef('tableRef')
|
const tableRef = useTemplateRef('tableRef')
|
||||||
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])
|
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])
|
||||||
|
|
||||||
const hasChinese = (s: string) => /[\u4e00-\u9fa5]/.test(s)
|
|
||||||
|
|
||||||
const formatRegion = (raw: string) => {
|
|
||||||
const s = raw.toString().trim()
|
|
||||||
if (!s) return ''
|
|
||||||
if (hasChinese(s)) {
|
|
||||||
return s.replace(/[,,\s]+/g, ',')
|
|
||||||
}
|
|
||||||
return s.replace(/[,,\s]+/g, ',')
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizeRegionInput = (raw: unknown) => {
|
|
||||||
const s = String(raw ?? '').trim()
|
|
||||||
if (!s) return ''
|
|
||||||
return s
|
|
||||||
.replace(/,/g, ',')
|
|
||||||
.split(',')
|
|
||||||
.map((part) => part.trim())
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(',')
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* baTable 内包含了表格的所有数据且数据具备响应性,然后通过 provide 注入给了后代组件
|
* baTable 内包含了表格的所有数据且数据具备响应性,然后通过 provide 注入给了后代组件
|
||||||
*/
|
*/
|
||||||
@@ -98,24 +76,15 @@ const baTable = new baTableClass(
|
|||||||
sortable: false,
|
sortable: false,
|
||||||
operator: 'LIKE',
|
operator: 'LIKE',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: t('mall.address.region'),
|
|
||||||
prop: 'region_text',
|
|
||||||
align: 'center',
|
|
||||||
operator: false,
|
|
||||||
showOverflowTooltip: true,
|
|
||||||
formatter: (row: TableRow, _column: TableColumn, cellValue: string) => {
|
|
||||||
const raw = (cellValue || row.region || '').toString()
|
|
||||||
return formatRegion(raw)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: t('mall.address.detail_address'),
|
label: t('mall.address.detail_address'),
|
||||||
prop: 'detail_address',
|
prop: 'detail_address',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
|
minWidth: 200,
|
||||||
operatorPlaceholder: t('Fuzzy query'),
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
sortable: false,
|
sortable: false,
|
||||||
operator: 'LIKE',
|
operator: 'LIKE',
|
||||||
|
showOverflowTooltip: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('mall.address.default_setting'),
|
label: t('mall.address.default_setting'),
|
||||||
@@ -156,15 +125,6 @@ const baTable = new baTableClass(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultItems: {},
|
defaultItems: {},
|
||||||
},
|
|
||||||
{
|
|
||||||
onSubmit: () => {
|
|
||||||
const items = baTable.form.items
|
|
||||||
if (items && items.region !== undefined && items.region !== null) {
|
|
||||||
items.region = normalizeRegionInput(items.region)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -51,16 +51,9 @@
|
|||||||
prop="phone"
|
prop="phone"
|
||||||
:placeholder="t('Please input field', { field: t('mall.address.phone') })"
|
:placeholder="t('Please input field', { field: t('mall.address.phone') })"
|
||||||
/>
|
/>
|
||||||
<FormItem
|
|
||||||
:label="t('mall.address.region')"
|
|
||||||
type="string"
|
|
||||||
v-model="baTable.form.items!.region"
|
|
||||||
prop="region"
|
|
||||||
:placeholder="t('mall.address.region_tip')"
|
|
||||||
/>
|
|
||||||
<FormItem
|
<FormItem
|
||||||
:label="t('mall.address.detail_address')"
|
:label="t('mall.address.detail_address')"
|
||||||
type="string"
|
type="textarea"
|
||||||
v-model="baTable.form.items!.detail_address"
|
v-model="baTable.form.items!.detail_address"
|
||||||
prop="detail_address"
|
prop="detail_address"
|
||||||
:placeholder="t('Please input field', { field: t('mall.address.detail_address') })"
|
:placeholder="t('Please input field', { field: t('mall.address.detail_address') })"
|
||||||
@@ -103,6 +96,8 @@ const { t } = useI18n()
|
|||||||
|
|
||||||
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||||
phone: [buildValidatorData({ name: 'required', title: t('mall.address.phone') })],
|
phone: [buildValidatorData({ name: 'required', title: t('mall.address.phone') })],
|
||||||
|
receiver_name: [buildValidatorData({ name: 'required', title: t('mall.address.receiver_name') })],
|
||||||
|
detail_address: [buildValidatorData({ name: 'required', title: t('mall.address.detail_address') })],
|
||||||
create_time: [buildValidatorData({ name: 'date', title: t('mall.address.create_time') })],
|
create_time: [buildValidatorData({ name: 'date', title: t('mall.address.create_time') })],
|
||||||
update_time: [buildValidatorData({ name: 'date', title: t('mall.address.update_time') })],
|
update_time: [buildValidatorData({ name: 'date', title: t('mall.address.update_time') })],
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user