from django.contrib.postgres.fields import ArrayField from django.db import models from core.enums import ( ClientBuildingAgeRange, ClientContactGender, ClientDecoration, ClientFloorPreference, ClientOrientation, ClientRequirementType, ) from core.models.base import UUIDPrimaryKeyModel class ClientContact(UUIDPrimaryKeyModel): client = models.ForeignKey( "fonrey_client.Client", on_delete=models.CASCADE, related_name="contacts" ) sort_order = models.SmallIntegerField(default=0) name = models.CharField(max_length=50) gender = models.CharField( max_length=10, choices=ClientContactGender.choices, default=ClientContactGender.MALE ) phone_enc = models.BinaryField() phone_hash = models.CharField(max_length=64) phone_country_code = models.CharField(max_length=10, default="+86") phone_is_invalid = models.BooleanField(default=False) phone2_enc = models.BinaryField(null=True, blank=True) phone2_hash = models.CharField(max_length=64, blank=True, default="") wechat = models.CharField(max_length=100, blank=True, default="") qq = models.CharField(max_length=20, blank=True, default="") remarks = models.CharField(max_length=200, blank=True, default="") created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) deleted_at = models.DateTimeField(null=True, blank=True) created_by = models.ForeignKey( "org.Staff", null=True, blank=True, on_delete=models.SET_NULL, related_name="created_client_contacts", ) class Meta: db_table = "client_contacts" verbose_name = "客源联系人" verbose_name_plural = "客源联系人" indexes = [ models.Index(fields=["phone_hash"], name="idx_cc_phone_hash"), models.Index(fields=["phone2_hash"], name="idx_cc_phone2_hash"), models.Index(fields=["client"], name="idx_cc_client"), ] class ClientRequirement(UUIDPrimaryKeyModel): client = models.ForeignKey( "fonrey_client.Client", on_delete=models.CASCADE, related_name="requirements" ) requirement_type = models.CharField( max_length=20, choices=ClientRequirementType.choices ) is_primary = models.BooleanField(default=True) budget_min = models.DecimalField( max_digits=12, decimal_places=2, null=True, blank=True ) budget_max = models.DecimalField( max_digits=12, decimal_places=2, null=True, blank=True ) area_min = models.DecimalField( max_digits=8, decimal_places=2, null=True, blank=True ) area_max = models.DecimalField( max_digits=8, decimal_places=2, null=True, blank=True ) bedroom_counts = ArrayField( models.SmallIntegerField(), blank=True, default=list ) floor_preferences = ArrayField( models.CharField(max_length=20, choices=ClientFloorPreference.choices), blank=True, default=list, ) orientations = ArrayField( models.CharField(max_length=10, choices=ClientOrientation.choices), blank=True, default=list, ) decorations = ArrayField( models.CharField(max_length=10, choices=ClientDecoration.choices), blank=True, default=list, ) building_age_ranges = ArrayField( models.CharField(max_length=20, choices=ClientBuildingAgeRange.choices), blank=True, default=list, ) intent_district_ids = ArrayField( models.UUIDField(), blank=True, default=list ) intent_business_area_ids = ArrayField( models.UUIDField(), blank=True, default=list ) intent_complex_names = models.TextField(blank=True, default="") transportation = models.CharField(max_length=50, blank=True, default="") intent_school_names = models.TextField(blank=True, default="") school_enrollment_date = models.DateField(null=True, blank=True) traffic_preference = models.TextField(blank=True, default="") requirement_notes = models.CharField(max_length=200, blank=True, default="") created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: db_table = "client_requirements" verbose_name = "客源需求" verbose_name_plural = "客源需求" indexes = [ models.Index(fields=["client"], name="idx_creq_client"), models.Index(fields=["requirement_type", "client"], name="idx_creq_type"), models.Index(fields=["budget_min", "budget_max"], name="idx_creq_budget"), models.Index(fields=["area_min", "area_max"], name="idx_creq_area"), ] class ClientSchoolPreference(UUIDPrimaryKeyModel): requirement = models.ForeignKey( ClientRequirement, on_delete=models.CASCADE, related_name="school_preferences", ) school_id = models.UUIDField(null=True, blank=True) school_name = models.CharField(max_length=100) created_at = models.DateTimeField(auto_now_add=True) class Meta: db_table = "client_school_preferences" verbose_name = "意向学校" verbose_name_plural = "意向学校" indexes = [ models.Index(fields=["requirement"], name="idx_csp_requirement"), ]