diff --git a/backend/app/crud/crm/customer.py b/backend/app/crud/crm/customer.py index 668cbadc4..3089ed933 100644 --- a/backend/app/crud/crm/customer.py +++ b/backend/app/crud/crm/customer.py @@ -129,6 +129,7 @@ def _row_to_dict(row: CrmCustomer) -> Dict[str, Any]: "city": row.city or "", "district": row.district or "", "address": row.address or "", + "sameCity": 1 if int(getattr(row, "same_city", 0) or 0) == 1 else 0, "status": row.status or "", "dealStatus": row.deal_status or "", "ownerUserId": row.owner_user_id or "", @@ -206,6 +207,7 @@ def list_customer_options( "id": r.id, "customerName": r.customer_name, "customerNo": r.customer_no, + "sameCity": 1 if int(getattr(r, "same_city", 0) or 0) == 1 else 0, "label": r.customer_name, "value": r.id, } @@ -569,6 +571,7 @@ def create_customer( city=kwargs.get("city"), district=kwargs.get("district"), address=kwargs.get("address"), + same_city=1 if int(kwargs.get("same_city") or 0) == 1 else 0, status="normal", deal_status="not_deal", owner_user_id=owner_id, @@ -626,18 +629,23 @@ def update_customer( "customer_name", "short_name", "customer_type", "mobile", "telephone", "email", "website", "level", "source", "industry", "park_area", "payment_terms", "scale", "province", "city", "district", "address", + "same_city", "business_license_img", "business_permit_images", "other_cert_images", "clue_id", "order_num", "remark", "next_time", ) _datetime_fields = {"next_time"} + _flag_fields = {"same_city"} for field in _updatable: if field not in kwargs: continue val = kwargs[field] if field in _datetime_fields: setattr(obj, field, _parse_optional_datetime(val)) + elif field in _flag_fields: + if val is not None: + setattr(obj, field, 1 if int(val or 0) == 1 else 0) elif val is not None: setattr(obj, field, val) diff --git a/backend/app/models/crm_models.py b/backend/app/models/crm_models.py index 097f60b9a..b3af4de3f 100644 --- a/backend/app/models/crm_models.py +++ b/backend/app/models/crm_models.py @@ -177,6 +177,12 @@ class CrmCustomer(Base): city = Column(String(50), nullable=True, comment="市") district = Column(String(50), nullable=True, comment="区") address = Column(String(255), nullable=True, comment="详细地址") + same_city = Column( + SmallInteger, + nullable=False, + default=0, + comment="是否同市 0-否 1-是;相对本公司业务所在市,运输计划段次默认带入", + ) # 状态与归属 status = Column( diff --git a/backend/app/schemas/crm/customer.py b/backend/app/schemas/crm/customer.py index 4056f0c25..76c3e99ec 100644 --- a/backend/app/schemas/crm/customer.py +++ b/backend/app/schemas/crm/customer.py @@ -263,6 +263,11 @@ class CustomerCreateBody(BaseModel): city: Optional[str] = Field(default=None, description="市") district: Optional[str] = Field(default=None, description="区") address: Optional[str] = Field(default=None, description="详细地址") + same_city: int = Field( + default=0, + alias="sameCity", + description="是否同市 0-否 1-是;相对本公司业务所在市,运输计划段次默认带入", + ) next_time: Optional[str] = Field(default=None, alias="nextTime", description="下次联系时间") remark: Optional[str] = Field(default=None, description="备注") owner_user_id: Optional[str] = Field(default=None, alias="ownerUserId", description="负责人ID") @@ -330,6 +335,11 @@ class CustomerUpdateBody(BaseModel): city: Optional[str] = Field(default=None, description="市") district: Optional[str] = Field(default=None, description="区") address: Optional[str] = Field(default=None, description="详细地址") + same_city: Optional[int] = Field( + default=None, + alias="sameCity", + description="是否同市 0-否 1-是;相对本公司业务所在市,运输计划段次默认带入", + ) next_time: Optional[str] = Field(default=None, alias="nextTime", description="下次联系时间") remark: Optional[str] = Field(default=None, description="备注") owner_user_id: Optional[str] = Field(default=None, alias="ownerUserId", description="负责人ID") diff --git a/docs/sql/2026-11-17-crm-customer-same-city.sql b/docs/sql/2026-11-17-crm-customer-same-city.sql new file mode 100644 index 000000000..e20387e18 --- /dev/null +++ b/docs/sql/2026-11-17-crm-customer-same-city.sql @@ -0,0 +1,18 @@ +-- 客户主数据增加「是否同市」,运输计划装/送段选客户时默认带入段次勾选。 +-- MySQL 5.7。可重复执行。存量客户默认 0。 +SET NAMES utf8mb4; + +SET @schema_name = DATABASE(); + +SET @col_exists = ( + SELECT COUNT(*) FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = @schema_name AND TABLE_NAME = 'crm_customer' AND COLUMN_NAME = 'same_city' +); +SET @alter_sql = IF( + @col_exists = 0, + 'ALTER TABLE crm_customer ADD COLUMN same_city tinyint NOT NULL DEFAULT 0 COMMENT ''是否同市 0-否 1-是;相对本公司业务所在市,运输计划段次默认带入'' AFTER address', + 'SELECT 1' +); +PREPARE alter_stmt FROM @alter_sql; +EXECUTE alter_stmt; +DEALLOCATE PREPARE alter_stmt; diff --git a/docs/sql/migrations/2026-11-17-crm-customer-same-city.sql b/docs/sql/migrations/2026-11-17-crm-customer-same-city.sql new file mode 100644 index 000000000..e20387e18 --- /dev/null +++ b/docs/sql/migrations/2026-11-17-crm-customer-same-city.sql @@ -0,0 +1,18 @@ +-- 客户主数据增加「是否同市」,运输计划装/送段选客户时默认带入段次勾选。 +-- MySQL 5.7。可重复执行。存量客户默认 0。 +SET NAMES utf8mb4; + +SET @schema_name = DATABASE(); + +SET @col_exists = ( + SELECT COUNT(*) FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = @schema_name AND TABLE_NAME = 'crm_customer' AND COLUMN_NAME = 'same_city' +); +SET @alter_sql = IF( + @col_exists = 0, + 'ALTER TABLE crm_customer ADD COLUMN same_city tinyint NOT NULL DEFAULT 0 COMMENT ''是否同市 0-否 1-是;相对本公司业务所在市,运输计划段次默认带入'' AFTER address', + 'SELECT 1' +); +PREPARE alter_stmt FROM @alter_sql; +EXECUTE alter_stmt; +DEALLOCATE PREPARE alter_stmt; diff --git a/docs/sql/shanxia2.0.sql b/docs/sql/shanxia2.0.sql index 1c0c2507b..39133f6eb 100644 --- a/docs/sql/shanxia2.0.sql +++ b/docs/sql/shanxia2.0.sql @@ -9792,6 +9792,7 @@ CREATE TABLE `crm_customer` ( `city` varchar(50) DEFAULT NULL COMMENT '市', `district` varchar(50) DEFAULT NULL COMMENT '区', `address` varchar(255) DEFAULT NULL COMMENT '详细地址', + `same_city` tinyint NOT NULL DEFAULT 0 COMMENT '是否同市 0-否 1-是;相对本公司业务所在市,运输计划段次默认带入', `status` varchar(20) DEFAULT 'normal' COMMENT '客户状态(字典 crm_customer_status: normal/pool/invalid)', `deal_status` varchar(20) DEFAULT 'not_deal' COMMENT '成交状态(字典 crm_deal_status: not_deal/dealed/lost)', `owner_user_id` varchar(64) DEFAULT NULL COMMENT '负责人ID', diff --git a/web-admin/src/api/crm/customerTypes.ts b/web-admin/src/api/crm/customerTypes.ts index 619f1702a..5f1db2db7 100644 --- a/web-admin/src/api/crm/customerTypes.ts +++ b/web-admin/src/api/crm/customerTypes.ts @@ -95,6 +95,8 @@ export interface CustomerForm { district?: string; /** 详细地址 */ address?: string; + /** 是否同市 0-否 1-是 */ + sameCity?: number; /** 负责人ID */ ownerUserId?: number; /** 下次联系时间 */ @@ -133,6 +135,8 @@ export interface CustomerVO { city?: string; district?: string; address?: string; + /** 是否同市 0-否 1-是 */ + sameCity?: number; status: string; dealStatus: string; ownerUserId?: number; diff --git a/web-admin/src/components/business/pl-plan-delivery-section/index.vue b/web-admin/src/components/business/pl-plan-delivery-section/index.vue index e78d39e60..b57baf5e4 100644 --- a/web-admin/src/components/business/pl-plan-delivery-section/index.vue +++ b/web-admin/src/components/business/pl-plan-delivery-section/index.vue @@ -245,7 +245,7 @@ import { mobileStopIdentity } from '@/views/m/pl/plan/mobileStopIdentity' import MobilePlanDeliverySection from '@/views/m/pl/plan/MobilePlanDeliverySection.vue' import { Bottom, Delete, Plus, Search, Top } from '@element-plus/icons-vue' - import { fetchCustomerOptions } from '@/api/crm/customer' + import { fetchCustomerDetail, fetchCustomerOptions } from '@/api/crm/customer' import { customerStopPrefApi, type CustomerStopPref } from '@/api/pl/index' import PlAddressWithLibrary, { type PlAddressApplyPayload @@ -256,6 +256,7 @@ import { canManualToggleStopDibang, createEmptyDeliveryForm, + resolveCustomerSameCityFlag, resolveStopDibangDefaults, sumStopProductsPlanQty, type PlanDeliveryForm, @@ -331,6 +332,7 @@ id: string customerName: string customerNo?: string + sameCity?: number } const activeIndex = ref(0) @@ -579,6 +581,7 @@ products: [], generateDibang: 0, dibangDirection: 'none', + sameCity: 0, address: '', lng: null, lat: null, @@ -604,15 +607,34 @@ products: [], generateDibang: defaults.generateDibang, dibangDirection: defaults.dibangDirection, + sameCity: resolveCustomerSameCityFlag(customer?.sameCity), address: '', lng: null, lat: null, contact: '', notes: '' }) + void applySameCityFromCustomer(index, String(customerId)) void applyDeliveryStopPref(index, String(customerId)) } + async function applySameCityFromCustomer(index: number, customerId: string) { + const identity = props.mobileSheet ? mobileStopIdentity(props.modelValue[index]) : undefined + try { + const res = await fetchCustomerDetail({ id: customerId }) + const data = pickBxData<{ sameCity?: number }>(res) + if (!data) return + if (props.mobileSheet) { + index = props.modelValue.findIndex((row) => mobileStopIdentity(row) === identity) + } + const current = props.modelValue[index] + if (!current || String(current.customerId) !== String(customerId)) return + patchDelivery(index, { sameCity: resolveCustomerSameCityFlag(data.sameCity) }) + } catch { + // 静默:不阻断选客户 + } + } + async function applyDeliveryStopPref(index: number, customerId: string) { const identity = props.mobileSheet ? mobileStopIdentity(props.modelValue[index]) : undefined try { diff --git a/web-admin/src/components/business/pl-plan-load-section/index.vue b/web-admin/src/components/business/pl-plan-load-section/index.vue index 8407b260c..3c74199ab 100644 --- a/web-admin/src/components/business/pl-plan-load-section/index.vue +++ b/web-admin/src/components/business/pl-plan-load-section/index.vue @@ -175,7 +175,7 @@