class AreaMain(db.Model): """ 지역 테이블 """ __tablename__ = 'area_main' am_idx = db.Column(db.Integer, nullable=False, primary_key=True) am_area = db.Column(db.String(4), nullable=False) #지역 - 서울,경기,부산,대구 ... am_step = db.Column(db.Integer) #노출순서 am_regdate = db.Column(db.String(20), nullable=False) #등록일자 am_edtdate = db.Column(db.String(20)) #수정일자 am_ip = db.Column(db.String(20)) #아이피 company = db.relationship('Company', backref='area_main', lazy=True) area_sub = db.relationship('AreaSub', backref='area_main', lazy=True) def get_area_main_object(self, sub_object=False, company_object=False): area_main = { 'am_idx': self.am_idx, 'am_area': self.am_area, 'am_step': self.am_step, 'am_regdate': self.am_regdate, 'am_edtdate': self.am_edtdate, 'am_ip': self.am_ip } if sub_object: area_main['area_sub'] = [] for sub in self.area_sub: area_main['area_sub'].append(sub.get_area_sub_object()) if company_object: area_main['company'] = [] for companys in self.company: area_main['company'].append(companys.get_company_object()) return area_main
class EventPub(db.Model): """ 이벤트당첨자 테이블 """ __tablename__ = 'event_pub' ep_idx = db.Column(db.Integer,nullable=False, primary_key=True) #일렬번호 cp_idx = db.Column(db.Integer, db.ForeignKey('company.cp_idx'), nullable=False) #업체번호 ev_idx = db.Column(db.Integer, db.ForeignKey('event.ev_idx'), nullable=False) #이벤트번호 mb_id = db.Column(db.Integer, db.ForeignKey('member.id'), nullable=False) #회원아이디 ep_regdate = db.Column(db.String(40), nullable=False,) #날짜 company = db.relationship('Company', back_populates='event_pub') event = db.relationship('Event', back_populates='event_pub')
class AreaSub(db.Model): """ 지역 테이블 """ __tablename__ = 'area_sub' as_idx = db.Column(db.Integer, nullable=False, primary_key=True) am_idx = db.Column(db.Integer, db.ForeignKey('area_main.am_idx'), nullable=False) as_area = db.Column(db.String(20), nullable=False) # 강남/역삼/서초 as_step = db.Column(db.Integer) #노출순서 as_regdate = db.Column(db.String(20), nullable=False) #등록일자 as_edtdate = db.Column(db.String(20)) #수정일자 as_ip = db.Column(db.String(20)) #아이피 company = db.relationship('Company', backref='area_sub', lazy=True) def get_area_sub_object(self, company_object=False): area_sub = { 'as_idx': self.as_idx, 'am_idx': self.am_idx, 'as_area': self.as_area, 'as_step': self.as_step, 'as_regdate': self.as_regdate, 'as_edtdate': self.as_edtdate, 'as_ip': self.as_ip } if company_object: area_sub['company'] = [] for companys in self.company: area_sub['company'].append(companys.get_company_object()) return area_sub
class Event(db.Model): """ 이벤트 테이블 """ __tablename__ = 'event' ev_idx = db.Column(db.Integer, nullable=False, primary_key=True) #일렬번호 ev_type = db.Column(db.String(1), nullable=False) #이벤트타입 C:쿠폰, E:이벤트 cp_idx = db.Column(db.Integer, db.ForeignKey('company.cp_idx'), nullable=False) #업체번호 ev_title = db.Column(db.String(255), nullable=False) #이벤트제목 ev_sdate = db.Column( db.String(20), nullable=False, ) #시작일자 ev_edate = db.Column( db.String(20), nullable=False, ) #마감일자 ev_pubdate = db.Column( db.String(20), nullable=False, ) #당첨자발표날짜 ev_summary = db.Column( db.Text, nullable=False, ) #이벤트설명 ev_regdate = db.Column(db.String(20), nullable=False) #등록일자 ev_edtdate = db.Column(db.String(20)) #수정일자 ev_ip = db.Column(db.String(20)) #아이피 event_pub = db.relationship('EventPub', back_populates='event')
class Member(db.Model): """ 사용자 테이블 """ __tablename__ = 'member' id = db.Column(db.Integer, nullable=False, primary_key=True) mb_id = db.Column(db.String(40), nullable=False, unique=True) mb_pwd = db.Column(db.String(255), nullable=False) mb_level = db.Column(db.Integer, nullable=False, default=1) #1:일반회원, 2:업체회원, 9:슈퍼관리자 mb_regtype = db.Column(db.String(2), nullable=False, default='NM') #NM:일반, KT:카톡, NV:네이버 mb_name = db.Column(db.String(20), nullable=False) mb_email = db.Column(db.String(60), nullable=False) mb_phone = db.Column(db.String(20), nullable=False) mb_autologin = db.Column(db.String(1), nullable=False, default='0') #0사용안함 , 1사용 mb_use_push = db.Column(db.String(1), nullable=False, default='1') #0사용안함 , 1사용 mb_state = db.Column(db.String(1), nullable=False, default='N') #N일반 , B차단 , O탈퇴 mb_ip = db.Column(db.String(20)) mb_bandate = db.Column(db.String(20)) mb_regdate = db.Column(db.String(20)) mb_edtdate = db.Column(db.String(20)) mb_outdate = db.Column(db.String(20)) company = db.relationship('Company', backref='member', lazy=True) ad_period = db.relationship('AdPeriod', backref='member', lazy=True) coupon = db.relationship('Coupon', backref='member', lazy=True) event_pub = db.relationship('EventPub', backref='member', lazy=True) favorite = db.relationship('Favorite', backref='member', lazy=True) review = db.relationship('Review', backref='member', lazy=True) files = db.relationship('Files', backref='member', lazy=True) @staticmethod def generate_password_hash(password): pre_hashed = hashlib.sha512(('x3FpknhFyR' + password + 'a6E8kInyyW')\ .encode('utf8')).hexdigest() return hashlib.md5(pre_hashed.encode('utf8')).hexdigest() @staticmethod def check_password_hash(mb_pwd, password): return mb_pwd == Member.generate_password_hash(password) @property def password(self): raise AttributeError('`password` is not a readable attribute') @password.setter def password(self, password): self.mb_pwd = self.generate_password_hash(password) def verify_password(self, password): return self.check_password_hash(self.mb_pwd, password) @staticmethod def verify_phone_number(mb_phone): phone_pattern = re.compile(r'^[\d]{3}-[\d]{3,4}-[\d]{4}$') return phone_pattern.match(mb_phone) @staticmethod def verify_email(mb_email): email_pattern = re.compile( r'^[A-Z0-9a-z._%+-]{1,64}@[A-Za-z0-9.-]{2,}\.[A-Za-z0-9.-]{2,}$') return email_pattern.match(mb_email) @staticmethod def verify_name(mb_name): name_pattern = re.compile(r'^[가-힣]{2,5}$') return name_pattern.match(mb_name)