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 Favorite(db.Model): """ 찜 테이블 """ __tablename__ = 'favorite' fv_idx = db.Column(db.Integer, nullable=False, primary_key=True) #일렬번호 mb_id = db.Column(db.Integer, db.ForeignKey('member.id'), nullable=False) #회원아이디 cp_idx = db.Column(db.Integer, db.ForeignKey('company.cp_idx'), nullable=False) #업체번호 fv_regdate = db.Column( db.String(20), nullable=False, ) #등록일자 fv_ip = db.Column(db.String(20)) #아이피
class Review(db.Model): """ 리뷰 테이블 """ __tablename__ = 'review' rv_idx = db.Column(db.Integer, nullable=False, primary_key=True) #일렬번호 rv_pidx = db.Column(db.Integer) #부모일렬번호 - 답변일 때 부모일렬번호가 들어감 mb_id = db.Column(db.Integer, db.ForeignKey('member.id'), nullable=False) #회원아이디 cp_idx = db.Column(db.Integer, db.ForeignKey('company.cp_idx'), nullable=False) #업체번호 rv_star = db.Column(db.Integer) #별점 rv_content = db.Column(db.Text, nullable=False) #글내용 rv_regdate = db.Column(db.String(20), nullable=False) #등록일자 rv_edtdate = db.Column(db.String(20)) #수정일자 rv_ip = db.Column(db.String(20)) #아이피
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 Faq(db.Model): """ 자주 묻는 질문 테이블 """ __tablename__ = 'faq' bo_idx = db.Column(db.Integer, nullable=False, primary_key=True) vl_num = db.Column(db.Integer) #역인덱스용 최초 -1부터 추가시 감산한다. bo_title = db.Column(db.String(255), nullable=False) #제목 bo_content = db.Column(db.Text, nullable=False) #내용 bo_step = db.Column(db.Integer) #노출순서 등록시 max+1이 되고 수정이 가능해야함 bo_regdate = db.Column(db.String(20), nullable=False) #등록일자 bo_edtdate = db.Column(db.String(20)) #수정일자 bo_ip = db.Column(db.String(20)) #아이피
class Notice(db.Model): """ 공지사항 테이블 """ __tablename__ = 'notice' bo_idx = db.Column(db.Integer, nullable=False, primary_key=True) vl_num = db.Column(db.Integer) #역인덱스용 최초 -1부터 추가시 감산한다. bo_title = db.Column(db.String(255), nullable=False) #제목 bo_content = db.Column(db.Text, nullable=False) #내용 bo_notice = db.Column(db.String(1), nullable=False, default='0') #상단공지여부 기본값0, 0:일반, 1:상단 bo_regdate = db.Column(db.String(20), nullable=False) #등록일자 bo_edtdate = db.Column(db.String(20)) #수정일자 bo_ip = db.Column(db.String(20))
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 Coupon(db.Model): """ 쿠폰 테이블 """ __tablename__ = 'coupon' cu_idx = db.Column(db.Integer, nullable=False, primary_key=True) mb_id = db.Column(db.Integer, db.ForeignKey('member.id'), nullable=False) cu_num = db.Column(db.String(20)) #쿠폰번호 cu_used = db.Column(db.String(1), nullable=False, default='0') #사용여부 0:미사용, 1:사용 cu_edate = db.Column(db.String(20), nullable=False) #사용만기날짜 cu_usedate = db.Column(db.String(20)) #사용날짜
class AdPeriod(db.Model): """ 광고기한 테이블 """ __tablename__ = 'ad_period' ap_idx = db.Column(db.Integer, nullable=False, primary_key=True) cp_idx = db.Column(db.Integer, db.ForeignKey('company.cp_idx'), nullable=False) mb_id = db.Column(db.Integer, db.ForeignKey('member.id'), nullable=False) ap_type = db.Column(db.String(1), nullable=False, default='N') #광고타입 M:메인, N:일반 ap_showdate = db.Column(db.String(20), nullable=False) #노출기한 ap_regdate = db.Column(db.String(20), nullable=False) #등록일자 ap_edtdate = db.Column(db.String(20)) #수정일자
class Viewlog(db.Model): """ 업체열람로그 테이블 """ __tablename__ = 'viewlog' vl_idx = db.Column(db.Integer, nullable=False, primary_key=True) vl_num = db.Column(db.Integer) #역인덱스용 최초 -1부터 추가시 감산한다. cp_idx = db.Column(db.Integer, db.ForeignKey('company.cp_idx'), nullable=False) #업체번호 mb_id = db.Column(db.String(40), nullable=False) #회원아이디 vl_regdate = db.Column(db.String(20), nullable=False) #등록일자 vl_ip = db.Column(db.String(20)) #아이피
class Files(db.Model): """ 파일 테이블 """ __tablename__ = 'files' fi_idx = db.Column(db.Integer, nullable=False, primary_key=True) mb_id = db.Column(db.Integer, db.ForeignKey('member.id')) #회원아이디 fi_gubun1 = db.Column(db.String(20)) #구분1 fi_gubun2 = db.Column(db.String(20)) #구분2 fi_gubun3 = db.Column(db.String(20)) #구분3 fi_rname = db.Column(db.String(255), nullable=False) #실제파일이름 fi_vname = db.Column(db.String(255), nullable=False) #가상파일이름 fi_is_img = db.Column(db.String(1), nullable=False) #이미지인지 아닌지 fi_mime_type = db.Column(db.String(20), nullable=False) #마임타입(파일종류) fi_size = db.Column(db.String(20)) #파일사이즈 fi_width = db.Column(db.String(6)) #이미지가로사이즈 fi_height = db.Column(db.String(6)) #이미지세로사이즈 fi_regdate = db.Column(db.String(20)) #아이피
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)
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')