Commit 2d1c01b2 by Aeolus

Merge branch 'aeolus'

parents deb0e035 8b3f4d93
...@@ -24,6 +24,7 @@ class Config: ...@@ -24,6 +24,7 @@ class Config:
JWT_SECRET = SECRET_KEY JWT_SECRET = SECRET_KEY
TENCENT_REDIS_URL = os.getenv("TENCENT_REDIS_URL") TENCENT_REDIS_URL = os.getenv("TENCENT_REDIS_URL")
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 MAX_CONTENT_LENGTH = 16 * 1024 * 1024
# SQLALCHEMY_ECHO = True
@staticmethod @staticmethod
def init_app(app): def init_app(app):
......
...@@ -43,15 +43,13 @@ LOGIN_TYPE = { ...@@ -43,15 +43,13 @@ LOGIN_TYPE = {
AGENT_STATUS = { AGENT_STATUS = {
'1': '超级管理员', '1': '超级管理员',
'2': '出库员', '2': '管理员',
'3': '渠道经理', '3': '业务员',
'4': '财务', '4': '商户管理员',
'5': '运维管理员', '5': '商户管理员',
'6': '推销员', '6': '财务',
'7': '介绍人', '7': '运维管理员',
'8': '合伙人', '8': '客服',
'9': '补货员',
'10': '场所',
} }
ACCOUNT_STATUS = { ACCOUNT_STATUS = {
......
...@@ -49,6 +49,18 @@ class AdminBrand(Base): ...@@ -49,6 +49,18 @@ class AdminBrand(Base):
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class AdminBusiness(Base):
__tablename__ = 'admin_business'
id = Column(INTEGER(11), primary_key=True)
user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
business_id = Column(INTEGER(11), nullable=False)
status = Column(INTEGER(1), nullable=False, server_default=text("'1'"))
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class AdminLoginRecord(Base): class AdminLoginRecord(Base):
__tablename__ = 'admin_login_record' __tablename__ = 'admin_login_record'
...@@ -68,7 +80,7 @@ class AdminMachine(Base): ...@@ -68,7 +80,7 @@ class AdminMachine(Base):
id = Column(INTEGER(11), primary_key=True) id = Column(INTEGER(11), primary_key=True)
user_id = Column(INTEGER(11), nullable=False) user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False) user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
machine_no = Column(INTEGER(11), nullable=False) machine_no = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False)
status = Column(INTEGER(1), default=1, nullable=False) status = Column(INTEGER(1), default=1, nullable=False)
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -121,6 +133,16 @@ class Brand(Base): ...@@ -121,6 +133,16 @@ class Brand(Base):
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class Business(Base):
__tablename__ = 'business'
id = Column(INTEGER(10), primary_key=True)
business_name = Column(VARCHAR(191), nullable=False, index=True, comment='品牌名')
status = Column(TINYINT(1), default=text("'1'"), comment='状态: 1正常-1删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class Hatch(Base): class Hatch(Base):
__tablename__ = 'hatch' __tablename__ = 'hatch'
__table_args__ = ( __table_args__ = (
...@@ -131,18 +153,22 @@ class Hatch(Base): ...@@ -131,18 +153,22 @@ class Hatch(Base):
machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, comment='机柜id') machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, comment='机柜id')
hatch_no = Column(TINYINT(3), nullable=False, comment='机柜仓口号') hatch_no = Column(TINYINT(3), nullable=False, comment='机柜仓口号')
production_id = Column(INTEGER(10), nullable=False, comment='商品id') production_id = Column(INTEGER(10), nullable=False, comment='商品id')
name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称') production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题') title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
left_count = Column(TINYINT(3), nullable=False, comment='剩余数量') left_count = Column(TINYINT(3), nullable=False, comment='剩余数量')
total_count = Column(TINYINT(3), nullable=False, comment='总数') total_count = Column(TINYINT(3), nullable=False, comment='总数')
brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID') brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID')
left_count = Column(INTEGER(10), nullable=False, comment='余额')
total_count = Column(INTEGER(10), nullable=False, comment='总数')
brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称') brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
cate_id = Column(INTEGER(10), nullable=False, comment='分类ID') production_type_id = Column(INTEGER(10), nullable=False, comment='分类ID')
cate_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题') production_type_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
price = Column(INTEGER(10), nullable=False, comment='价格') price = Column(INTEGER(10), nullable=False, comment='价格')
original_price = Column(INTEGER(10), nullable=False, comment='商品原价') original_price = Column(INTEGER(10), nullable=False, comment='商品原价')
weight = Column(INTEGER(10), server_default=text("'0'"))
weight_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'g'"))
weight_error = Column(INTEGER(10), server_default=text("'0'"))
expiration_date = Column(INTEGER(10), server_default=text("'0'"))
expiration_date_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'月'"))
is_expiration_date = Column(TINYINT(1), server_default=text("'0'"))
img = Column(String(200, 'utf8mb4_unicode_ci')) img = Column(String(200, 'utf8mb4_unicode_ci'))
tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签') tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签')
content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容') content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容')
...@@ -174,6 +200,7 @@ class Machine(Base): ...@@ -174,6 +200,7 @@ class Machine(Base):
updated_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
command_time = Column(INTEGER(1), nullable=False, server_default=text("'1'")) command_time = Column(INTEGER(1), nullable=False, server_default=text("'1'"))
discounts_id = Column(INTEGER(11), nullable=False, server_default=text("'0'"), comment="折扣活动") discounts_id = Column(INTEGER(11), nullable=False, server_default=text("'0'"), comment="折扣活动")
business_id = Column(INTEGER(11), nullable=False, server_default=text("'0'"), comment="商户号")
class MachineProduction(Base): class MachineProduction(Base):
...@@ -312,6 +339,7 @@ class Rent(Base): ...@@ -312,6 +339,7 @@ class Rent(Base):
expire_handle = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否做过期处理') expire_handle = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否做过期处理')
prepay_id = Column(VARCHAR(191), comment='微信支付prepay_id') prepay_id = Column(VARCHAR(191), comment='微信支付prepay_id')
over_time = Column(TIMESTAMP, comment='订单完结时间') over_time = Column(TIMESTAMP, comment='订单完结时间')
business_id = Column(INTEGER(11), nullable=False, server_default=text("'0'"), comment="商户号")
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -321,26 +349,50 @@ class RentDetail(Base): ...@@ -321,26 +349,50 @@ class RentDetail(Base):
id = Column(INTEGER(10), primary_key=True, unique=True) id = Column(INTEGER(10), primary_key=True, unique=True)
rent_no = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False, comment='订单编号') rent_no = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False, comment='订单编号')
user_id = Column(INTEGER(10), nullable=False, index=True, comment='用户id') user_id = Column(INTEGER(10), nullable=False, comment='用户id')
machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, comment='机柜id') machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, comment='机柜id')
hatch_no = Column(TINYINT(3), nullable=False, comment='机柜仓口号') hatch_no = Column(TINYINT(3), nullable=False, comment='机柜仓口号')
production_id = Column(INTEGER(10), nullable=False, comment='商品id') total = Column(INTEGER(10), server_default=text("'0'"), comment='实收金额')
rent_count = Column(TINYINT(3), nullable=False, server_default=text("'0'"))
refund_total = Column(INTEGER(10), server_default=text("'0'"))
refund_count = Column(INTEGER(10), server_default=text("'0'"))
is_take = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否取货') is_take = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否取货')
name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称') business_id = Column(INTEGER(11), nullable=False, server_default=text("'0'"))
status = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='1正常 2删除')
production_id = Column(INTEGER(10), nullable=False, comment='商品id')
production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题') title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID') brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID')
brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称') brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
cate_id = Column(INTEGER(10), nullable=False, comment='分类ID') production_type_id = Column(INTEGER(10), nullable=False, comment='分类ID')
cate_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题') production_type_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
price = Column(INTEGER(10), nullable=False, comment='价格') price = Column(INTEGER(10), nullable=False, comment='价格')
rent_count = Column(INTEGER(10), nullable=False, comment='数量') original_price = Column(INTEGER(10), nullable=False, comment='商品原价')
img = Column(String(200, 'utf8mb4_unicode_ci')) img = Column(String(200, 'utf8mb4_unicode_ci'))
tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签') tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签')
content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容') content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容')
summary = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品描述') summary = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品描述')
status = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='1正常 -1删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
weight = Column(INTEGER(10), server_default=text("'0'"), comment='重量')
weight_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'g'"), comment='重量单位')
expiration_date = Column(INTEGER(10), server_default=text("'0'"), comment='保质期')
expiration_date_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'月'"), comment='保质期单位')
is_expiration_date = Column(TINYINT(1), server_default=text("'0'"), comment='是否有保质期')
weight_error = Column(INTEGER(10), server_default=text("'0'"), comment='重量误差')
class RentRefund(Base):
__tablename__ = 'rent_refund'
id = Column(INTEGER(10), primary_key=True)
user_id = Column(INTEGER(10), nullable=False, index=True, comment='用户id')
refund_no = Column(String(191, 'utf8mb4_unicode_ci'), nullable=False)
rent_no = Column(String(191, 'utf8mb4_unicode_ci'), nullable=False)
rent_detail_id = Column(INTEGER(10), nullable=False)
total = Column(INTEGER(10), nullable=False)
comment = Column(Text(collation='utf8mb4_unicode_ci'))
cause = Column(String(191, 'utf8mb4_unicode_ci'))
class SalePlan(Base): class SalePlan(Base):
...@@ -377,6 +429,7 @@ class SalePlanProduction(Base): ...@@ -377,6 +429,7 @@ class SalePlanProduction(Base):
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class TallymanAccount(Base): class TallymanAccount(Base):
__tablename__ = 'tallyman_account' __tablename__ = 'tallyman_account'
...@@ -385,6 +438,7 @@ class TallymanAccount(Base): ...@@ -385,6 +438,7 @@ class TallymanAccount(Base):
user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False) user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False)
phone = Column(String(191, 'utf8mb4_unicode_ci'), nullable=False, unique=True) phone = Column(String(191, 'utf8mb4_unicode_ci'), nullable=False, unique=True)
level = Column(INTEGER(1), nullable=False, comment='1:补货员') level = Column(INTEGER(1), nullable=False, comment='1:补货员')
business_id = Column(INTEGER(11), server_default=text("'0'"))
status = Column(INTEGER(1), nullable=False, comment='1:正常 2:删除') status = Column(INTEGER(1), nullable=False, comment='1:正常 2:删除')
_password_hash_ = Column(String(255, 'utf8mb4_unicode_ci')) _password_hash_ = Column(String(255, 'utf8mb4_unicode_ci'))
comment = Column(String(255, 'utf8mb4_unicode_ci')) comment = Column(String(255, 'utf8mb4_unicode_ci'))
......
...@@ -14,38 +14,68 @@ class AdminAccount(Base): ...@@ -14,38 +14,68 @@ class AdminAccount(Base):
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False, unique=True) user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False, unique=True)
user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False) user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False)
phone = Column(String(191, 'utf8mb4_unicode_ci'), nullable=False, unique=True) phone = Column(String(191, 'utf8mb4_unicode_ci'), nullable=False, unique=True)
level = Column(TINYINT(2), nullable=False) level = Column(TINYINT(2), nullable=False, comment="'1': '超级管理员','2': '管理员','3': '业务员','4': '商户管理员','5': '商户管理员','6': '财务','7': '运维管理员','8': '补货员','9': '客服',")
parent_id = Column(INTEGER(10), nullable=False) parent_id = Column(INTEGER(10), nullable=False, comment='上级ID')
draw = Column(TINYINT(1), nullable=False, server_default=text("'0'")) draw = Column(TINYINT(1), nullable=False, server_default=text("'0'"), comment='提现权限0不可以1可以')
rate = Column(INTEGER(10), nullable=False) rate = Column(INTEGER(10), nullable=False, comment='分成比例')
status = Column(INTEGER(1), nullable=False) status = Column(INTEGER(1), nullable=False, comment='1:正常 2:删除')
_password_hash_ = Column(String(255, 'utf8mb4_unicode_ci')) _password_hash_ = Column(String(255, 'utf8mb4_unicode_ci'))
comment = Column(String(255, 'utf8mb4_unicode_ci')) comment = Column(String(255, 'utf8mb4_unicode_ci'))
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class AdminBrand(Base):
__tablename__ = 'admin_brand'
id = Column(INTEGER(11), primary_key=True)
user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
brand_id = Column(INTEGER(11), nullable=False)
status = Column(INTEGER(1), nullable=False, server_default=text("'1'"), comment='1:正常 2:删除')
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class AdminBusines(Base):
__tablename__ = 'admin_business'
__table_args__ = (
Index('unique4admin_business_user_business', 'user_id', 'business_id', unique=True),
)
id = Column(INTEGER(11), primary_key=True)
user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
business_id = Column(INTEGER(11), nullable=False)
status = Column(INTEGER(1), nullable=False, server_default=text("'1'"), comment='1:正常 -1:删除')
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class AdminLoginRecord(Base): class AdminLoginRecord(Base):
__tablename__ = 'admin_login_record' __tablename__ = 'admin_login_record'
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
phone = Column(VARCHAR(40), nullable=False) phone = Column(VARCHAR(40), nullable=False)
platform = Column(TINYINT(4), nullable=False, server_default=text("'1'")) platform = Column(TINYINT(4), nullable=False, server_default=text("'1'"), comment='平台 1PC平台')
ip = Column(VARCHAR(40), nullable=False) ip = Column(VARCHAR(40), nullable=False)
last_login = Column(DateTime, nullable=False) last_login = Column(DateTime, nullable=False)
login_type = Column(INTEGER(1), nullable=False) login_type = Column(INTEGER(1), nullable=False, comment='1:验证码登录 2:token 3:发送验证码 4:密码')
created_at = Column(DateTime, nullable=False) created_at = Column(DateTime, nullable=False)
updated_at = Column(DateTime, nullable=False) updated_at = Column(DateTime, nullable=False)
class AdminMachine(Base): class AdminMachine(Base):
__tablename__ = 'admin_machine' __tablename__ = 'admin_machine'
__table_args__ = (
Index('unique4admin_machine_user_id_machine_no', 'user_id', 'machine_no', unique=True),
)
id = Column(INTEGER(11), primary_key=True) id = Column(INTEGER(11), primary_key=True)
user_id = Column(INTEGER(11), nullable=False) user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False) user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
machine_no = Column(INTEGER(11), nullable=False) machine_no = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False)
status = Column(INTEGER(1), nullable=False, server_default=text("'1'")) status = Column(INTEGER(1), nullable=False, server_default=text("'1'"), comment='1:正常 -1:删除')
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -57,7 +87,7 @@ class AdminPlace(Base): ...@@ -57,7 +87,7 @@ class AdminPlace(Base):
user_id = Column(INTEGER(11), nullable=False) user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False) user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
place_id = Column(INTEGER(11), nullable=False) place_id = Column(INTEGER(11), nullable=False)
status = Column(INTEGER(1), nullable=False, server_default=text("'1'")) status = Column(INTEGER(1), nullable=False, server_default=text("'1'"), comment='1:正常 2:删除')
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -69,7 +99,19 @@ class AdminProduction(Base): ...@@ -69,7 +99,19 @@ class AdminProduction(Base):
user_id = Column(INTEGER(11), nullable=False) user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False) user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
production_id = Column(INTEGER(11), nullable=False) production_id = Column(INTEGER(11), nullable=False)
status = Column(INTEGER(1), nullable=False, server_default=text("'1'")) status = Column(INTEGER(1), nullable=False, server_default=text("'1'"), comment='1:正常 2:删除')
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class AdminProductionType(Base):
__tablename__ = 'admin_production_type'
id = Column(INTEGER(11), primary_key=True)
user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
production_type_id = Column(INTEGER(11), nullable=False)
status = Column(INTEGER(1), nullable=False, server_default=text("'1'"), comment='1:正常 2:删除')
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -78,8 +120,19 @@ class Brand(Base): ...@@ -78,8 +120,19 @@ class Brand(Base):
__tablename__ = 'brand' __tablename__ = 'brand'
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
name = Column(VARCHAR(191), nullable=False, index=True) brand_name = Column(VARCHAR(191), nullable=False, index=True, comment='品牌名')
img = Column(VARCHAR(191), nullable=False) img = Column(VARCHAR(191), nullable=False, comment='logo')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
status = Column(TINYINT(1), nullable=False, server_default=text("'1'"), comment='状态: 1正常-1删除')
class Busines(Base):
__tablename__ = 'business'
id = Column(INTEGER(10), primary_key=True)
business_name = Column(VARCHAR(191), nullable=False, comment='品牌名')
status = Column(TINYINT(1), nullable=False, server_default=text("'1'"), comment='状态: 1正常-1删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -91,24 +144,30 @@ class Hatch(Base): ...@@ -91,24 +144,30 @@ class Hatch(Base):
) )
id = Column(INTEGER(10), primary_key=True, unique=True) id = Column(INTEGER(10), primary_key=True, unique=True)
machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False) machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, comment='机柜id')
hatch_no = Column(TINYINT(3), nullable=False) hatch_no = Column(TINYINT(3), nullable=False, comment='机柜仓口号')
production_id = Column(INTEGER(10), nullable=False) production_id = Column(INTEGER(10), nullable=False, comment='商品id')
name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False) production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False) title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
left_count = Column(TINYINT(3), nullable=False, server_default=text("'1'")) left_count = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='剩余数量')
total_count = Column(TINYINT(3), nullable=False, server_default=text("'1'")) total_count = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='总数量')
brand_id = Column(INTEGER(10), nullable=False) brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID')
brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False) brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
cate_id = Column(INTEGER(10), nullable=False) production_type_id = Column(INTEGER(10), nullable=False, comment='分类ID')
cate_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False) production_type_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
price = Column(INTEGER(10), nullable=False) price = Column(INTEGER(10), nullable=False, comment='价格')
original_price = Column(INTEGER(10), nullable=False) original_price = Column(INTEGER(10), nullable=False, comment='商品原价')
weight = Column(INTEGER(10), server_default=text("'0'"), comment='重量')
weight_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'g'"), comment='重量单位')
weight_error = Column(INTEGER(10), server_default=text("'0'"), comment='重量误差')
expiration_date = Column(INTEGER(10), server_default=text("'0'"), comment='保质期')
expiration_date_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'月'"), comment='保质期单位')
is_expiration_date = Column(TINYINT(1), server_default=text("'0'"), comment='是否有保质期')
img = Column(String(200, 'utf8mb4_unicode_ci')) img = Column(String(200, 'utf8mb4_unicode_ci'))
tags = Column(String(255, 'utf8mb4_unicode_ci')) tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签')
content = Column(Text(collation='utf8mb4_unicode_ci')) content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容')
summary = Column(Text(collation='utf8mb4_unicode_ci')) summary = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品描述')
status = Column(TINYINT(3), nullable=False, server_default=text("'1'")) status = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='1可售2售空')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -117,23 +176,24 @@ class Machine(Base): ...@@ -117,23 +176,24 @@ class Machine(Base):
__tablename__ = 'machine' __tablename__ = 'machine'
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, unique=True) machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, unique=True, comment='机柜编号')
device_id = Column(String(45, 'utf8mb4_unicode_ci'), unique=True) device_id = Column(String(45, 'utf8mb4_unicode_ci'), unique=True, comment='蓝牙设备号')
qrcode_no = Column(String(20, 'utf8mb4_unicode_ci'), unique=True) qrcode_no = Column(String(20, 'utf8mb4_unicode_ci'), unique=True, comment='机柜编号')
mac = Column(String(30, 'utf8mb4_unicode_ci'), unique=True) mac = Column(String(30, 'utf8mb4_unicode_ci'), unique=True)
power = Column(TINYINT(3), nullable=False, server_default=text("'0'")) power = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='电量')
short_address = Column(VARCHAR(45)) short_address = Column(VARCHAR(45))
address = Column(String(191, 'utf8mb4_unicode_ci')) address = Column(String(191, 'utf8mb4_unicode_ci'), comment='机柜位置')
place_id = Column(INTEGER(10)) place_id = Column(INTEGER(10))
mch_platform = Column(INTEGER(11), nullable=False, server_default=text("'1'")) mch_platform = Column(INTEGER(11), nullable=False, server_default=text("'1'"), comment='1随身玩 2晓见文旅')
position = Column(String(20, 'utf8mb4_unicode_ci')) position = Column(String(20, 'utf8mb4_unicode_ci'), comment='机柜位置坐标')
hatch_number = Column(TINYINT(3), nullable=False, server_default=text("'0'")) hatch_number = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='机柜的仓口数量')
type = Column(TINYINT(3), nullable=False, server_default=text("'1'")) type = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='机柜类型1 单库存 2多库存')
status = Column(TINYINT(1), server_default=text("'0'")) status = Column(TINYINT(1), server_default=text("'0'"), comment='状态: 0未激活 1正常-1删除')
created_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
command_time = Column(INTEGER(4), nullable=False, server_default=text("'1'")) command_time = Column(INTEGER(4), nullable=False, server_default=text("'1'"))
discounts_id = Column(INTEGER(10), server_default=text("'0'")) discounts_id = Column(INTEGER(10), server_default=text("'0'"), comment='折扣活动')
business_id = Column(INTEGER(10), nullable=False, server_default=text("'0'"))
class MachineProduction(Base): class MachineProduction(Base):
...@@ -143,7 +203,7 @@ class MachineProduction(Base): ...@@ -143,7 +203,7 @@ class MachineProduction(Base):
machine_id = Column(INTEGER(10), nullable=False) machine_id = Column(INTEGER(10), nullable=False)
production_id = Column(INTEGER(10), nullable=False) production_id = Column(INTEGER(10), nullable=False)
hatch_no = Column(INTEGER(10), nullable=False) hatch_no = Column(INTEGER(10), nullable=False)
status = Column(TINYINT(1), nullable=False) status = Column(TINYINT(1), nullable=False, comment='状态: 1整除-1删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -189,33 +249,35 @@ class ManagementTallyman(Base): ...@@ -189,33 +249,35 @@ class ManagementTallyman(Base):
class NfcCard(Base): class NfcCard(Base):
__tablename__ = 'nfc_card' __tablename__ = 'nfc_card'
__table_args__ = {'comment': 'nfc卡片表'}
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
card_no = Column(String(40, 'utf8mb4_unicode_ci')) card_no = Column(String(40, 'utf8mb4_unicode_ci'), comment='卡片编号')
user_id = Column(INTEGER(10)) user_id = Column(INTEGER(10))
nick_name = Column(String(40, 'utf8mb4_unicode_ci')) nick_name = Column(String(40, 'utf8mb4_unicode_ci'), comment='学生名称')
phone = Column(String(40, 'utf8mb4_unicode_ci'), index=True) phone = Column(String(40, 'utf8mb4_unicode_ci'), index=True, comment='手机号')
money = Column(INTEGER(10), nullable=False) money = Column(INTEGER(10), nullable=False)
mch_platform = Column(INTEGER(11), nullable=False, server_default=text("'1'")) mch_platform = Column(INTEGER(11), nullable=False, server_default=text("'1'"), comment='1咻咻')
limit_count = Column(TINYINT(1), nullable=False, server_default=text("'-1'")) limit_count = Column(TINYINT(1), nullable=False, server_default=text("'-1'"))
status = Column(TINYINT(4), nullable=False) status = Column(TINYINT(4), nullable=False, comment='状态0停用1正常')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class NfcCardPayRecord(Base): class NfcCardPayRecord(Base):
__tablename__ = 'nfc_card_pay_record' __tablename__ = 'nfc_card_pay_record'
__table_args__ = {'comment': 'nfc卡片充值表'}
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
card_no = Column(String(40, 'utf8mb4_unicode_ci'), index=True) card_no = Column(String(40, 'utf8mb4_unicode_ci'), index=True, comment='卡片编号')
rent_no = Column(VARCHAR(40), nullable=False) rent_no = Column(VARCHAR(40), nullable=False, comment='租借单号')
user_id = Column(INTEGER(10), nullable=False) user_id = Column(INTEGER(10), nullable=False, comment='用户id')
is_pay = Column(TINYINT(3), nullable=False, server_default=text("'0'")) is_pay = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否支付')
pay_money = Column(INTEGER(10), nullable=False) pay_money = Column(INTEGER(10), nullable=False, comment='充值金额')
mch_platform = Column(INTEGER(11), nullable=False, server_default=text("'1'")) mch_platform = Column(INTEGER(11), nullable=False, server_default=text("'1'"), comment='1随身玩 2晓见文旅')
prepay_id = Column(VARCHAR(191)) prepay_id = Column(VARCHAR(191), comment='微信支付prepay_id')
refund_no = Column(VARCHAR(191)) refund_no = Column(VARCHAR(191), comment='退款单号')
status = Column(TINYINT(4), nullable=False) status = Column(TINYINT(4), nullable=False, comment='1已充值 2已圈存到账 3已退款 -1已删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -237,16 +299,16 @@ class Place(Base): ...@@ -237,16 +299,16 @@ class Place(Base):
__tablename__ = 'place' __tablename__ = 'place'
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
parent_id = Column(INTEGER(10)) parent_id = Column(INTEGER(10), comment='上级ID')
place_name = Column(VARCHAR(191), nullable=False, index=True) place_name = Column(VARCHAR(191), nullable=False, index=True, comment='场所名')
img = Column(VARCHAR(191)) img = Column(VARCHAR(191), comment='展示界面的图片')
logo = Column(VARCHAR(191)) logo = Column(VARCHAR(191), comment='微型头像')
address = Column(VARCHAR(255), server_default=text("''")) address = Column(VARCHAR(255), server_default=text("''"))
position = Column(String(20, 'utf8mb4_unicode_ci')) position = Column(String(20, 'utf8mb4_unicode_ci'))
open_time = Column(VARCHAR(191)) open_time = Column(VARCHAR(191), comment='开始时间')
close_time = Column(VARCHAR(191)) close_time = Column(VARCHAR(191), comment='结束时间')
open_week = Column(VARCHAR(255), server_default=text("''")) open_week = Column(VARCHAR(255), server_default=text("''"))
status = Column(INTEGER(1), nullable=False, server_default=text("'1'")) status = Column(INTEGER(1), nullable=False, server_default=text("'1'"), comment='1:正常 2:删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -267,23 +329,23 @@ class Production(Base): ...@@ -267,23 +329,23 @@ class Production(Base):
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
production_no = Column(String(45, 'utf8mb4_unicode_ci'), nullable=False) production_no = Column(String(45, 'utf8mb4_unicode_ci'), nullable=False)
production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, index=True) production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, index=True, comment='商品名称')
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False) title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
brand_id = Column(INTEGER(10), nullable=False) brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID')
production_type_id = Column(INTEGER(10), nullable=False) production_type_id = Column(INTEGER(10), nullable=False, comment='分类ID')
price = Column(INTEGER(10), nullable=False) price = Column(INTEGER(10), nullable=False, comment='价格')
original_price = Column(INTEGER(10), nullable=False) original_price = Column(INTEGER(10), nullable=False, comment='商品原价')
weight = Column(INTEGER(10), server_default=text("'0'")) weight = Column(INTEGER(10), server_default=text("'0'"), comment='重量')
weight_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'g'")) weight_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'g'"), comment='重量单位')
expiration_date = Column(INTEGER(10), server_default=text("'0'")) expiration_date = Column(INTEGER(10), server_default=text("'0'"), comment='保质期')
expiration_date_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("''")) expiration_date_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'月'"), comment='保质期单位')
is_expiration_date = Column(TINYINT(1), server_default=text("'0'")) is_expiration_date = Column(TINYINT(1), server_default=text("'0'"), comment='是否有保质期')
weight_error = Column(INTEGER(10), server_default=text("'0'")) weight_error = Column(INTEGER(10), server_default=text("'0'"), comment='重量误差')
img = Column(String(200, 'utf8mb4_unicode_ci')) img = Column(String(200, 'utf8mb4_unicode_ci'))
tags = Column(String(255, 'utf8mb4_unicode_ci')) tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签')
content = Column(Text(collation='utf8mb4_unicode_ci')) content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容')
summary = Column(Text(collation='utf8mb4_unicode_ci')) summary = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品描述')
status = Column(TINYINT(1)) status = Column(TINYINT(1), nullable=False, server_default=text("'1'"), comment='状态: 1正常-1删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -292,63 +354,90 @@ class ProductionType(Base): ...@@ -292,63 +354,90 @@ class ProductionType(Base):
__tablename__ = 'production_type' __tablename__ = 'production_type'
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
name = Column(VARCHAR(191), nullable=False, index=True) production_type_name = Column(VARCHAR(191), nullable=False, index=True, comment='分类名')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
catecol = Column(String(45, 'utf8mb4_unicode_ci')) status = Column(TINYINT(1), nullable=False, server_default=text("'1'"), comment='状态: 1正常-1删除')
class Rent(Base): class Rent(Base):
__tablename__ = 'rent' __tablename__ = 'rent'
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
rent_no = Column(VARCHAR(40), nullable=False, index=True) rent_no = Column(VARCHAR(40), nullable=False, index=True, comment='租借单号')
machine_no = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False, index=True) machine_no = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False, index=True, comment='机柜id')
user_id = Column(INTEGER(10), nullable=False, index=True) user_id = Column(INTEGER(10), nullable=False, index=True, comment='用户id')
card_no = Column(String(40, 'utf8mb4_unicode_ci'), index=True) card_no = Column(String(40, 'utf8mb4_unicode_ci'), index=True)
place_id = Column(INTEGER(10), nullable=False, index=True) place_id = Column(INTEGER(10), nullable=False, index=True, comment='场所id')
total = Column(INTEGER(10), server_default=text("'0'")) total = Column(INTEGER(10), server_default=text("'0'"), comment='应收金额')
real_total = Column(INTEGER(10), server_default=text("'0'")) real_total = Column(INTEGER(10), server_default=text("'0'"), comment='实收金额')
agent_total = Column(INTEGER(10), server_default=text("'0'")) agent_total = Column(INTEGER(10), server_default=text("'0'"), comment='给代理商看的收入')
back_money = Column(INTEGER(10), nullable=False, server_default=text("'0'")) back_money = Column(INTEGER(10), nullable=False, server_default=text("'0'"), comment='退款金额')
is_pay = Column(TINYINT(3), nullable=False, server_default=text("'0'")) is_pay = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否支付')
rent_type = Column(TINYINT(3), nullable=False, server_default=text("'1'")) rent_type = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='租借类型1现场租借2预约3nfc租借')
mch_platform = Column(INTEGER(1), nullable=False, server_default=text("'1'")) mch_platform = Column(INTEGER(1), nullable=False, server_default=text("'1'"), comment='1待定')
add_time = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) add_time = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"), comment='下单时间')
pay_time = Column(TIMESTAMP) pay_time = Column(TIMESTAMP, comment='支付时间')
is_over = Column(TINYINT(3), nullable=False, server_default=text("'0'")) is_over = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否完结')
is_cancel = Column(TINYINT(3), nullable=False, server_default=text("'0'")) is_cancel = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否取消交易')
refund_no = Column(VARCHAR(191)) refund_no = Column(VARCHAR(191), comment='退款单号')
expire_handle = Column(TINYINT(3), nullable=False, server_default=text("'0'")) expire_handle = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否做过期处理')
prepay_id = Column(VARCHAR(191)) prepay_id = Column(VARCHAR(191), comment='微信支付prepay_id')
over_time = Column(TIMESTAMP) over_time = Column(TIMESTAMP, comment='订单完结时间')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
business_id = Column(INTEGER(11), nullable=False, server_default=text("'0'"))
class RentDetail(Base): class RentDetail(Base):
__tablename__ = 'rent_detail' __tablename__ = 'rent_detail'
id = Column(INTEGER(10), primary_key=True, unique=True) id = Column(INTEGER(10), primary_key=True, unique=True)
rent_no = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False) rent_no = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False, comment='订单编号')
user_id = Column(INTEGER(10), nullable=False) user_id = Column(INTEGER(10), nullable=False, comment='用户id')
machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False) machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, comment='机柜id')
hatch_no = Column(TINYINT(3), nullable=False) hatch_no = Column(TINYINT(3), nullable=False, comment='机柜仓口号')
production_id = Column(INTEGER(10), nullable=False) total = Column(INTEGER(10), server_default=text("'0'"), comment='实收金额')
is_take = Column(TINYINT(3), nullable=False, server_default=text("'0'")) rent_count = Column(TINYINT(3), nullable=False, server_default=text("'0'"))
name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False) refund_total = Column(INTEGER(10), server_default=text("'0'"))
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False) refund_count = Column(INTEGER(10), server_default=text("'0'"))
brand_id = Column(INTEGER(10), nullable=False) is_take = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='是否取货')
brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False) business_id = Column(INTEGER(11), nullable=False, server_default=text("'0'"))
cate_id = Column(INTEGER(10), nullable=False) status = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='1正常 2删除')
cate_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False) production_id = Column(INTEGER(10), nullable=False, comment='商品id')
price = Column(INTEGER(10), nullable=False) production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
rent_count = Column(TINYINT(3), nullable=False) title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID')
brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
production_type_id = Column(INTEGER(10), nullable=False, comment='分类ID')
production_type_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
price = Column(INTEGER(10), nullable=False, comment='价格')
original_price = Column(INTEGER(10), nullable=False, comment='商品原价')
img = Column(String(200, 'utf8mb4_unicode_ci')) img = Column(String(200, 'utf8mb4_unicode_ci'))
tags = Column(String(255, 'utf8mb4_unicode_ci')) tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签')
content = Column(Text(collation='utf8mb4_unicode_ci')) content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容')
summary = Column(Text(collation='utf8mb4_unicode_ci')) summary = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品描述')
status = Column(TINYINT(3), nullable=False, server_default=text("'1'")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
weight = Column(INTEGER(10), server_default=text("'0'"), comment='重量')
weight_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'g'"), comment='重量单位')
expiration_date = Column(INTEGER(10), server_default=text("'0'"), comment='保质期')
expiration_date_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'月'"), comment='保质期单位')
is_expiration_date = Column(TINYINT(1), server_default=text("'0'"), comment='是否有保质期')
weight_error = Column(INTEGER(10), server_default=text("'0'"), comment='重量误差')
class RentRefund(Base):
__tablename__ = 'rent_refund'
id = Column(INTEGER(11), primary_key=True)
user_id = Column(INTEGER(10), nullable=False)
refund_no = Column(VARCHAR(20), nullable=False)
rent_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False)
rent_detail_id = Column(INTEGER(11), nullable=False)
total = Column(INTEGER(11), nullable=False)
cause = Column(VARCHAR(191))
comment = Column(TEXT)
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -357,9 +446,9 @@ class SalePlan(Base): ...@@ -357,9 +446,9 @@ class SalePlan(Base):
__tablename__ = 'sale_plan' __tablename__ = 'sale_plan'
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False) name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='方案名称')
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False) title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='方案标题')
status = Column(TINYINT(1), nullable=False) status = Column(TINYINT(1), nullable=False, comment='状态: 1整除-1删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -370,7 +459,7 @@ class SalePlanMachine(Base): ...@@ -370,7 +459,7 @@ class SalePlanMachine(Base):
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
plan_id = Column(INTEGER(10), nullable=False) plan_id = Column(INTEGER(10), nullable=False)
machine_id = Column(INTEGER(10), nullable=False) machine_id = Column(INTEGER(10), nullable=False)
status = Column(TINYINT(1), nullable=False) status = Column(TINYINT(1), nullable=False, comment='状态: 1正常 -1删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -382,7 +471,7 @@ class SalePlanProduction(Base): ...@@ -382,7 +471,7 @@ class SalePlanProduction(Base):
plan_id = Column(INTEGER(10), nullable=False) plan_id = Column(INTEGER(10), nullable=False)
production_id = Column(INTEGER(10), nullable=False) production_id = Column(INTEGER(10), nullable=False)
index = Column(INTEGER(10), nullable=False) index = Column(INTEGER(10), nullable=False)
status = Column(TINYINT(1), nullable=False) status = Column(TINYINT(1), nullable=False, comment='状态: 1整除-1删除')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -391,14 +480,14 @@ class TallyRecord(Base): ...@@ -391,14 +480,14 @@ class TallyRecord(Base):
__tablename__ = 'tally_record' __tablename__ = 'tally_record'
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False) user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False, comment='补货员')
user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False) user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False, comment='补货员')
machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False) machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, comment='机柜id')
hatch_no = Column(TINYINT(3), nullable=False) hatch_no = Column(TINYINT(3), nullable=False, comment='机柜仓口号')
production_id = Column(INTEGER(10), nullable=False) production_id = Column(INTEGER(10), nullable=False, comment='商品id')
production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False) production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
tally_count = Column(TINYINT(3), nullable=False, server_default=text("'1'")) tally_count = Column(TINYINT(3), nullable=False, server_default=text("'1'"))
status = Column(TINYINT(3), nullable=False, server_default=text("'1'")) status = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='1指令已下发(等待开仓) 2指令上报(补货完成)')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -410,8 +499,9 @@ class TallymanAccount(Base): ...@@ -410,8 +499,9 @@ class TallymanAccount(Base):
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False, unique=True) user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False, unique=True)
user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False) user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False)
phone = Column(String(191, 'utf8mb4_unicode_ci'), nullable=False, unique=True) phone = Column(String(191, 'utf8mb4_unicode_ci'), nullable=False, unique=True)
level = Column(INTEGER(1), nullable=False) level = Column(INTEGER(1), nullable=False, comment='1:补货员')
status = Column(INTEGER(1), nullable=False) business_id = Column(INTEGER(11), server_default=text("'0'"))
status = Column(INTEGER(1), nullable=False, comment='1:正常 2:删除')
_password_hash_ = Column(String(255, 'utf8mb4_unicode_ci')) _password_hash_ = Column(String(255, 'utf8mb4_unicode_ci'))
comment = Column(String(255, 'utf8mb4_unicode_ci')) comment = Column(String(255, 'utf8mb4_unicode_ci'))
last_login = Column(DateTime) last_login = Column(DateTime)
...@@ -425,10 +515,10 @@ class TallymanLoginRecord(Base): ...@@ -425,10 +515,10 @@ class TallymanLoginRecord(Base):
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
phone = Column(VARCHAR(255), nullable=False) phone = Column(VARCHAR(255), nullable=False)
platform = Column(TINYINT(4), nullable=False, server_default=text("'2'")) platform = Column(TINYINT(4), nullable=False, server_default=text("'2'"), comment='平台 2小导游 8商户PC')
ip = Column(VARCHAR(255), nullable=False) ip = Column(VARCHAR(255), nullable=False)
last_login = Column(DateTime, nullable=False) last_login = Column(DateTime, nullable=False)
login_type = Column(INTEGER(1), nullable=False) login_type = Column(INTEGER(1), nullable=False, comment='1:验证码登录 2:token 3:发送验证码 4:密码')
created_at = Column(DateTime, nullable=False) created_at = Column(DateTime, nullable=False)
updated_at = Column(DateTime, nullable=False) updated_at = Column(DateTime, nullable=False)
...@@ -457,20 +547,21 @@ class TallymanPlace(Base): ...@@ -457,20 +547,21 @@ class TallymanPlace(Base):
class WxUser(Base): class WxUser(Base):
__tablename__ = 'wx_user' __tablename__ = 'wx_user'
__table_args__ = {'comment': '微信用户表'}
id = Column(INTEGER(10), primary_key=True) id = Column(INTEGER(10), primary_key=True)
openid = Column(String(40, 'utf8mb4_unicode_ci'), index=True) openid = Column(String(40, 'utf8mb4_unicode_ci'), index=True, comment='微信支付宝公众平台openID')
unionid = Column(String(40, 'utf8mb4_unicode_ci')) unionid = Column(String(40, 'utf8mb4_unicode_ci'), comment='微信支付宝unionid')
platform = Column(TINYINT(4), nullable=False, server_default=text("'0'")) platform = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='平台')
phone = Column(String(40, 'utf8mb4_unicode_ci'), index=True) phone = Column(String(40, 'utf8mb4_unicode_ci'), index=True, comment='手机号')
language = Column(String(40, 'utf8mb4_unicode_ci')) language = Column(String(40, 'utf8mb4_unicode_ci'), comment='语种')
nick_name = Column(String(40, 'utf8mb4_unicode_ci')) nick_name = Column(String(40, 'utf8mb4_unicode_ci'), comment='昵称')
gender = Column(TINYINT(4), nullable=False, server_default=text("'0'")) gender = Column(TINYINT(4), nullable=False, server_default=text("'0'"), comment='性别 0:未知、1:男、2:女')
avatar_url = Column(String(191, 'utf8mb4_unicode_ci')) avatar_url = Column(String(191, 'utf8mb4_unicode_ci'), comment='头像')
city = Column(String(45, 'utf8mb4_unicode_ci')) city = Column(String(45, 'utf8mb4_unicode_ci'))
province = Column(String(45, 'utf8mb4_unicode_ci')) province = Column(String(45, 'utf8mb4_unicode_ci'))
country = Column(String(45, 'utf8mb4_unicode_ci')) country = Column(String(45, 'utf8mb4_unicode_ci'))
status = Column(TINYINT(4), nullable=False) status = Column(TINYINT(4), nullable=False, comment='状态0停用1正常')
last_login_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) last_login_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"), comment='上次登录时间')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -39,12 +39,12 @@ def get_production_list(): ...@@ -39,12 +39,12 @@ def get_production_list():
"machine_no": i.machine_no, "machine_no": i.machine_no,
"hatch_no": [i.hatch_no], "hatch_no": [i.hatch_no],
"production_id": i.production_id, "production_id": i.production_id,
"name": i.name, "name": i.production_name,
"title": i.title, "title": i.title,
"brand_id": i.brand_id, "brand_id": i.brand_id,
"brand_name": i.brand_name, "brand_name": i.brand_name,
"cate_id": i.cate_id, "production_type_id": i.production_type_id,
"cate_name": i.cate_name, "production_type_name": i.production_type_name,
"price": i.price, "price": i.price,
"original_price": i.original_price, "original_price": i.original_price,
"img": i.img, "img": i.img,
...@@ -79,12 +79,12 @@ def get_production_info(): ...@@ -79,12 +79,12 @@ def get_production_info():
"machine_no": hatch_info.machine_no, "machine_no": hatch_info.machine_no,
"hatch_no": hatch_info.hatch_no, "hatch_no": hatch_info.hatch_no,
"production_id": hatch_info.production_id, "production_id": hatch_info.production_id,
"name": hatch_info.name, "name": hatch_info.production_name,
"title": hatch_info.title, "title": hatch_info.title,
"brand_id": hatch_info.brand_id, "brand_id": hatch_info.brand_id,
"brand_name": hatch_info.brand_name, "brand_name": hatch_info.brand_name,
"cate_id": hatch_info.cate_id, "production_type_id": hatch_info.production_type_id,
"cate_name": hatch_info.cate_name, "production_type_name": hatch_info.production_type_name,
"price": hatch_info.price, "price": hatch_info.price,
"original_price": hatch_info.original_price, "original_price": hatch_info.original_price,
"img": hatch_info.img, "img": hatch_info.img,
......
...@@ -40,6 +40,7 @@ def get_discount_info(): ...@@ -40,6 +40,7 @@ def get_discount_info():
machine = Machine.query.filter_by(machine_no=machine_no).first() machine = Machine.query.filter_by(machine_no=machine_no).first()
if not machine: if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
is_used = 1
if machine.discounts_id == 1: if machine.discounts_id == 1:
rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE)).first() rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE)).first()
if rent: if rent:
...@@ -47,10 +48,10 @@ def get_discount_info(): ...@@ -47,10 +48,10 @@ def get_discount_info():
else: else:
is_used = 0 is_used = 0
return_data = {"discounts_id": machine.discounts_id, return_data = {"discounts_id": machine.discounts_id,
"discounts_name": DISCOUNTS_TYPES[int(machine.discounts_id)], "discounts_name": DISCOUNTS_TYPES[int(machine.discounts_id)],
"is_used": is_used} "is_used": is_used}
return BaseResponse(data=return_data) return BaseResponse(data=return_data)
@rent_route.route("rent", methods=["POST"]) @rent_route.route("rent", methods=["POST"])
...@@ -82,7 +83,6 @@ def create_rent(): ...@@ -82,7 +83,6 @@ def create_rent():
Hatch.left_count >= 1).order_by(func.random()).first() Hatch.left_count >= 1).order_by(func.random()).first()
if not open_hatch: if not open_hatch:
print("....")
return jsonify(HATCH_NOT_EXIST_ERROR) return jsonify(HATCH_NOT_EXIST_ERROR)
break break
...@@ -93,11 +93,13 @@ def create_rent(): ...@@ -93,11 +93,13 @@ def create_rent():
rent.user_id = g.user.id rent.user_id = g.user.id
rent.place_id = machine.place_id rent.place_id = machine.place_id
rent.total = total_fee rent.total = total_fee
rent.real_total = total_fee
rent.add_time = datetime.datetime.now() rent.add_time = datetime.datetime.now()
rent.is_pay = 1 rent.is_pay = 1
rent.pay_time = datetime.datetime.now() rent.pay_time = datetime.datetime.now()
rent.rent_type = type rent.rent_type = type
rent.mch_platform = machine.mch_platform rent.mch_platform = machine.mch_platform
rent.place_id = machine.place_id
rent_detail = RentDetail() rent_detail = RentDetail()
rent_detail.rent_no = rent_no rent_detail.rent_no = rent_no
...@@ -105,13 +107,15 @@ def create_rent(): ...@@ -105,13 +107,15 @@ def create_rent():
rent_detail.machine_no = rent.machine_no rent_detail.machine_no = rent.machine_no
rent_detail.hatch_no = open_hatch.hatch_no rent_detail.hatch_no = open_hatch.hatch_no
rent_detail.production_id = open_hatch.production_id rent_detail.production_id = open_hatch.production_id
rent_detail.name = open_hatch.name rent_detail.production_name = open_hatch.production_name
rent_detail.title = open_hatch.title rent_detail.title = open_hatch.title
rent_detail.brand_id = open_hatch.brand_id rent_detail.brand_id = open_hatch.brand_id
rent_detail.brand_name = open_hatch.brand_name rent_detail.brand_name = open_hatch.brand_name
rent_detail.cate_id = open_hatch.cate_id rent_detail.production_type_id = open_hatch.production_type_id
rent_detail.cate_name = open_hatch.cate_name rent_detail.production_type_name = open_hatch.production_type_name
rent_detail.price = 0 rent_detail.price = 0
rent_detail.original_price = open_hatch.original_price
rent_detail.total = 0
rent_detail.rent_count = 1 rent_detail.rent_count = 1
rent_detail.img = open_hatch.img rent_detail.img = open_hatch.img
rent_detail.tags = open_hatch.tags rent_detail.tags = open_hatch.tags
...@@ -211,7 +215,6 @@ def wx_pay_callback(): ...@@ -211,7 +215,6 @@ def wx_pay_callback():
logger.info(xml_data) logger.info(xml_data)
logger.info(callback_data) logger.info(callback_data)
attach = re.sub('\'', '\"', callback_data["attach"]) attach = re.sub('\'', '\"', callback_data["attach"])
print(attach)
rent_data = json.loads(attach) rent_data = json.loads(attach)
platform = rent_data["platform"] platform = rent_data["platform"]
machine_no = rent_data["machine_no"] machine_no = rent_data["machine_no"]
...@@ -261,13 +264,14 @@ def wx_pay_callback(): ...@@ -261,13 +264,14 @@ def wx_pay_callback():
rent_detail.machine_no = rent.machine_no rent_detail.machine_no = rent.machine_no
rent_detail.hatch_no = i.hatch_no rent_detail.hatch_no = i.hatch_no
rent_detail.production_id = i.production_id rent_detail.production_id = i.production_id
rent_detail.name = i.name rent_detail.production_name = i.production_name
rent_detail.title = i.title rent_detail.title = i.title
rent_detail.brand_id = i.brand_id rent_detail.brand_id = i.brand_id
rent_detail.brand_name = i.brand_name rent_detail.brand_name = i.brand_name
rent_detail.cate_id = i.cate_id rent_detail.production_type_id = i.production_type_id
rent_detail.cate_name = i.cate_name rent_detail.production_type_name = i.production_type_name
rent_detail.price = i.price * open_hatchs[str(i.hatch_no)] rent_detail.price = i.price
rent_detail.total = i.price * open_hatchs[str(i.hatch_no)]
rent_detail.rent_count = open_hatchs[str(i.hatch_no)] rent_detail.rent_count = open_hatchs[str(i.hatch_no)]
rent_detail.img = i.img rent_detail.img = i.img
rent_detail.tags = i.tags rent_detail.tags = i.tags
...@@ -317,13 +321,17 @@ def get_rent_detail(): ...@@ -317,13 +321,17 @@ def get_rent_detail():
tmp_data["hatch_no"] = i.hatch_no tmp_data["hatch_no"] = i.hatch_no
tmp_data["production_id"] = i.production_id tmp_data["production_id"] = i.production_id
tmp_data["is_take"] = i.is_take tmp_data["is_take"] = i.is_take
tmp_data["name"] = i.name tmp_data["name"] = i.production_name
tmp_data["title"] = i.title tmp_data["title"] = i.title
tmp_data["brand_id"] = i.brand_id tmp_data["brand_id"] = i.brand_id
tmp_data["brand_name"] = i.brand_name tmp_data["brand_name"] = i.brand_name
tmp_data["cate_id"] = i.cate_id tmp_data["production_type_id"] = i.production_type_id
tmp_data["cate_name"] = i.cate_name tmp_data["production_type_name"] = i.production_type_name
tmp_data["price"] = i.price tmp_data["price"] = i.price
tmp_data["total"] = i.total
tmp_data["rent_count"] = i.rent_count
tmp_data["refund_total"] = i.refund_total
tmp_data["refund_count"] = i.refund_count
tmp_data["img"] = i.img tmp_data["img"] = i.img
tmp_data["tags"] = i.tags tmp_data["tags"] = i.tags
tmp_data["content"] = i.content tmp_data["content"] = i.content
...@@ -359,9 +367,13 @@ def get_user_detail_record(): ...@@ -359,9 +367,13 @@ def get_user_detail_record():
tmp_data["title"] = i.title tmp_data["title"] = i.title
tmp_data["brand_id"] = i.brand_id tmp_data["brand_id"] = i.brand_id
tmp_data["brand_name"] = i.brand_name tmp_data["brand_name"] = i.brand_name
tmp_data["cate_id"] = i.cate_id tmp_data["production_type_id"] = i.production_type_id
tmp_data["cate_name"] = i.cate_name tmp_data["production_type_name"] = i.production_type_name
tmp_data["price"] = i.price tmp_data["price"] = i.price
tmp_data["total"] = i.total
tmp_data["rent_count"] = i.rent_count
tmp_data["refund_total"] = i.refund_total
tmp_data["refund_count"] = i.refund_count
tmp_data["img"] = i.img tmp_data["img"] = i.img
tmp_data["tags"] = i.tags tmp_data["tags"] = i.tags
tmp_data["content"] = i.content tmp_data["content"] = i.content
......
...@@ -16,6 +16,10 @@ from myapps.pc_management.api.place_portal import place_route ...@@ -16,6 +16,10 @@ from myapps.pc_management.api.place_portal import place_route
from myapps.pc_management.api.machine_portal import machine_route from myapps.pc_management.api.machine_portal import machine_route
from myapps.pc_management.api.file_protal import file_route from myapps.pc_management.api.file_protal import file_route
from myapps.pc_management.api.production_portal import production_route from myapps.pc_management.api.production_portal import production_route
from myapps.pc_management.api.hatch_portal import hatch_route
from myapps.pc_management.api.business_portal import business_route
from myapps.pc_management.api.rent_portal import rent_route
from myapps.pc_management.api.tallyman_portal import tallyman_route
def register_sukang_blueprint(app: Flask): def register_sukang_blueprint(app: Flask):
...@@ -25,3 +29,7 @@ def register_sukang_blueprint(app: Flask): ...@@ -25,3 +29,7 @@ def register_sukang_blueprint(app: Flask):
app.register_blueprint(machine_route, url_prefix=prefix + "/machine") app.register_blueprint(machine_route, url_prefix=prefix + "/machine")
app.register_blueprint(file_route, url_prefix=prefix + "/file") app.register_blueprint(file_route, url_prefix=prefix + "/file")
app.register_blueprint(production_route, url_prefix=prefix + "/production") app.register_blueprint(production_route, url_prefix=prefix + "/production")
app.register_blueprint(hatch_route, url_prefix=prefix + "/hatch")
app.register_blueprint(business_route, url_prefix=prefix + "/business")
app.register_blueprint(rent_route, url_prefix=prefix + "/rent")
app.register_blueprint(tallyman_route, url_prefix=prefix + "/tallyman")
...@@ -13,11 +13,12 @@ from utils.error_code import ACCOUNT_AGENT_SPOT_NULL_ERROR, ACCOUNT_NOT_EXISTS_E ...@@ -13,11 +13,12 @@ from utils.error_code import ACCOUNT_AGENT_SPOT_NULL_ERROR, ACCOUNT_NOT_EXISTS_E
OPERATE_LEVEL_ERROR, Param_Invalid_Error, COMMON_MONGO_ERROR OPERATE_LEVEL_ERROR, Param_Invalid_Error, COMMON_MONGO_ERROR
from utils.error_code import PHONE_NOT_NULL_ERROR, PHONE_NOT_VALID_ERROR, TOKEN_NOT_VALID_ERROR, \ from utils.error_code import PHONE_NOT_NULL_ERROR, PHONE_NOT_VALID_ERROR, TOKEN_NOT_VALID_ERROR, \
VERIFICATION_CODE_INVALID_ERROR, VERIFICATION_CODE_ERROR, PASSWORD_ERROR VERIFICATION_CODE_INVALID_ERROR, VERIFICATION_CODE_ERROR, PASSWORD_ERROR
from models.base_model import db from models.base_model import db, Base
from models.models import AdminAccount, AdminLoginRecord, AdminMachine, AdminPlace, Place from models.models import AdminAccount, AdminLoginRecord, AdminMachine, AdminPlace, Place, Business, AdminBusiness
from utils.jwt_util import verify_jwt, generate_jwt from utils.jwt_util import verify_jwt, generate_jwt
from utils.my_response import BaseResponse from utils.my_response import BaseResponse
from service.sms_service import SMSService from service.sms_service import SMSService
from utils.mytools import json2obj
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -141,6 +142,10 @@ def add_user(): ...@@ -141,6 +142,10 @@ def add_user():
db.session.add(account) db.session.add(account)
db.session.commit() db.session.commit()
business_ids = json_data.get("business_ids", [])
if business_ids:
AdminService.add_or_edit_admin_business(account, business_ids)
return BaseResponse() return BaseResponse()
...@@ -151,45 +156,9 @@ def get_account_list(): ...@@ -151,45 +156,9 @@ def get_account_list():
page_size = json_data.get("pageSize", None) page_size = json_data.get("pageSize", None)
keyword = json_data.get("keyword", None) keyword = json_data.get("keyword", None)
select_sql = """select admin_account.user_name, admin_account.phone, admin_account.level, admin_account.status, return_data = AdminService.get_admin_account_list(keyword=keyword, page=page, page_size=page_size)
admin_account.comment,admin_account.parent_id,admin_account.rate, admin_account.created_at,
admin_account.updated_at,admin_account.id, admin_account.user_no
"""
count_sql = "select count(admin_account.id) as total_count"
from_sql = " from admin_account where admin_account.id in ( select admin_account.id "
from_sql += " from admin_account "
where_sql = " where 0=0 and admin_account.level > {} and admin_account.parent_id = {}".format(g.user.level,
g.user.id)
if keyword:
where_sql += """
and CONCAT(admin_account.user_name,admin_account.phone, admin_account.user_no) LIKE '%{keyword}%'
""".format(keyword=keyword)
where_sql += " ) "
order_sql = " ORDER BY admin_account.id ASC, admin_account.status ASC"
limit_sql = " LIMIT {offset} , {page_size} ".format(offset=(page - 1) * page_size, page_size=page_size)
count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone()
if not count_result:
return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0})
else:
total_count = count_result.total_count
print(select_sql + from_sql + where_sql + order_sql + limit_sql)
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = [] return BaseResponse(return_data)
for info in result:
return_data.append(
{"user_name": info.user_name, "phone": info.phone, "level": info.level, "status": info.status,
"comment": info.comment, "user_id": info.id, "user_no": info.user_no,
"create_time": info.created_at.strftime("%Y-%m-%d %H:%M:%S"),
"update_time": info.updated_at.strftime("%Y-%m-%d %H:%M:%S"),
})
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@admin_route.route('/account_detail', methods=["POST"]) @admin_route.route('/account_detail', methods=["POST"])
...@@ -199,14 +168,13 @@ def get_account_detail(): ...@@ -199,14 +168,13 @@ def get_account_detail():
if phone == g.user.phone: if phone == g.user.phone:
admin_info = g.user admin_info = g.user
else: else:
admin_info = AdminAccount.query.filter(AdminAccount.phone == phone, result = AdminService.get_admin_account_list(phone=phone)
AdminAccount.level > g.user.level, if result["total_count"] != 1:
AdminAccount.parent_id == g.user.id).first() return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
if not admin_info: admin_info = json2obj(result["list"][0])
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
user_info = { user_info = {
"user_id": admin_info.id, "id": admin_info.id,
"user_no": admin_info.user_no, "user_no": admin_info.user_no,
"user_name": admin_info.user_name, "user_name": admin_info.user_name,
"phone": admin_info.phone, "phone": admin_info.phone,
...@@ -215,6 +183,13 @@ def get_account_detail(): ...@@ -215,6 +183,13 @@ def get_account_detail():
"comment": admin_info.comment "comment": admin_info.comment
} }
business_list = db.session.query(Business).join(AdminBusiness, Business.id == AdminBusiness.business_id,
).filter(Business.status == 1,
AdminBusiness.user_id == admin_info.id,
AdminBusiness.status == 1).all()
user_info["business_list"] = []
for i in business_list:
user_info["business_list"].append({"business_id": i.id, "business_name": i.business_name})
return BaseResponse(data=user_info) return BaseResponse(data=user_info)
...@@ -223,7 +198,7 @@ def edit_user(): ...@@ -223,7 +198,7 @@ def edit_user():
json_data = request.get_json() json_data = request.get_json()
old_phone = json_data['old_phone'] if 'old_phone' in json_data else '' old_phone = json_data['old_phone'] if 'old_phone' in json_data else ''
new_phone = json_data['new_phone'] if 'new_phone' in json_data else '' new_phone = json_data['new_phone'] if 'new_phone' in json_data else ''
user_name = json_data['user_name'] if 'user_name' in json_data else 'SSW' user_name = json_data['user_name'] if 'user_name' in json_data else 'XX'
password = json_data['password'] if 'password' in json_data else '' password = json_data['password'] if 'password' in json_data else ''
comment = json_data['comment'] if 'comment' in json_data else '' comment = json_data['comment'] if 'comment' in json_data else ''
level = json_data['level'] if 'level' in json_data else '' level = json_data['level'] if 'level' in json_data else ''
...@@ -239,26 +214,34 @@ def edit_user(): ...@@ -239,26 +214,34 @@ def edit_user():
if old_phone == g.user.phone: if old_phone == g.user.phone:
admin_info = g.user admin_info = g.user
if level:
admin_info.level = int(level)
else: else:
admin_info = AdminAccount.query.filter(AdminAccount.phone == old_phone, result = AdminService.get_admin_account_list(phone=old_phone)
AdminAccount.level > g.user.level, if result["total_count"] != 1:
AdminAccount.parent_id == g.user.id return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
).first() admin = json2obj(result["list"][0])
if not admin_info: admin_info = AdminAccount.query.filter_by(id=admin.id).first()
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR) if not admin_info:
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
admin_info.user_name = user_name if level and level > g.user.level:
admin_info.phone = new_phone admin_info.level = level
admin_info.status = status if status:
admin_info.comment = comment admin_info.status = status
if comment:
admin_info.comment = comment
if user_name:
admin_info.user_name = user_name
if new_phone:
admin_info.phone = new_phone
if password: if password:
admin_info.password = password admin_info.password = password
db.session.add(admin_info) db.session.add(admin_info)
db.session.commit() db.session.commit()
business_ids = json_data.get("business_ids", [])
if business_ids:
AdminService.add_or_edit_admin_business(admin_info, business_ids)
return BaseResponse() return BaseResponse()
...@@ -269,8 +252,11 @@ def delete_user(): ...@@ -269,8 +252,11 @@ def delete_user():
if not phone: if not phone:
return BaseResponse(**PHONE_NOT_NULL_ERROR) return BaseResponse(**PHONE_NOT_NULL_ERROR)
admin_info = AdminAccount.query.filter(AdminAccount.phone == phone, result = AdminService.get_admin_account_list(phone=phone)
AdminAccount.level > g.user.level).first() if result["total_count"] != 1:
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
admin = json2obj(result["list"][0])
admin_info = AdminAccount.query.filter_by(id=admin.id).first()
if not admin_info: if not admin_info:
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR) return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
......
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2022/01/12
@file: place_portal.py
@function:
@modify:
"""
import logging
from flask import Blueprint, g, request, jsonify
from models.base_model import db
from models.models import AdminPlace, Place, Business, AdminBusiness
from utils.error_code import NO_PLACE_ERROR, NO_BUSINESS_ERROR
from utils.my_response import BaseResponse
logger = logging.getLogger(__name__)
business_route = Blueprint('business', __name__)
@business_route.route("business_list", methods=["POST"])
def run_business_list():
"""
:return:
"""
json_data = request.get_json()
page = json_data.get("page", 1)
page_size = json_data.get("pageSize", 10)
keyword = json_data.get("keyword", None)
admin = g.user
select_sql = "select business.business_name,business.status, business.id "
count_sql = "select count(business.id) as total_count"
from_sql = """ from business """
if g.user.level == 1:
where_sql = " where 0=0 "
else:
where_sql = """ where business.id in (
select business_id from admin_business where
admin_business.user_id = {} and admin_business.status = 1
)""".format(admin.id)
if keyword:
where_sql += """ and CONCAT(business.business_name) LIKE '%{keyword}%' """.format(keyword=keyword)
order_sql = " ORDER BY business.id ASC, business.status ASC"
limit_sql = " LIMIT {offset} , {page_size} ".format(offset=(page - 1) * page_size, page_size=page_size)
count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone()
if not count_result:
return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0})
else:
total_count = count_result.total_count
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = []
for info in result:
return_data.append({"business_name": info.business_name, "business_id": info.id, "status": info.status})
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@business_route.route("add_business", methods=["POST"])
def run_add_place():
"""
:return:
"""
json_data = request.get_json()
business_name = json_data["business_name"]
business_model = Business()
business_model.business_name = business_name
db.session.add(business_model)
db.session.commit()
admin_business = AdminBusiness()
admin_business.user_id = g.user.id
admin_business.user_no = g.user.user_no
admin_business.business_id = business_model.id
db.session.add(admin_business)
db.session.commit()
return BaseResponse()
@business_route.route("edit_business", methods=["POST"])
def run_edit_business():
"""
:return:
"""
json_data = request.get_json()
business_id = json_data["business_id"]
business_name = json_data.get("business_name", "")
status = json_data.get("status", None)
business_model = Business.query.filter_by(id=business_id).first()
if business_name:
business_model.business_name = business_name
if status:
business_model.status = status
db.session.add(business_model)
db.session.commit()
return BaseResponse()
@business_route.route("business_detail", methods=["POST"])
def get_business_detail():
"""
:return:
"""
json_data = request.get_json()
business_id = json_data["business_id"]
business_model = Business.query.filter_by(id=business_id).first()
if business_model:
return BaseResponse(data={"business_name": business_model.business_name,
"status": business_model.status, "business_id": business_id})
else:
return jsonify(NO_BUSINESS_ERROR)
...@@ -33,7 +33,6 @@ def run_upload_img(): ...@@ -33,7 +33,6 @@ def run_upload_img():
if filetype and filetype in ALLOWED_EXTENSIONS: # 后缀格式必须是bmp结尾 if filetype and filetype in ALLOWED_EXTENSIONS: # 后缀格式必须是bmp结尾
uid = uuid.uuid4() # 生成随机名称 uid = uuid.uuid4() # 生成随机名称
save_file_name = str(uid) + "." + filetype # 拼接名称 save_file_name = str(uid) + "." + filetype # 拼接名称
print(os.path.join(img_file_path, filename))
file.save(os.path.join(img_file_path, save_file_name)) # 保存文件 file.save(os.path.join(img_file_path, save_file_name)) # 保存文件
return BaseResponse(data={"filename": save_file_name}) return BaseResponse(data={"filename": save_file_name})
......
...@@ -14,8 +14,9 @@ from flask import Blueprint, g, request, jsonify ...@@ -14,8 +14,9 @@ from flask import Blueprint, g, request, jsonify
from config.commen_config import DISCOUNTS_TYPES from config.commen_config import DISCOUNTS_TYPES
from models.base_model import db from models.base_model import db
from models.models import AdminMachine, Machine from models.models import AdminMachine, Machine, Hatch
from utils.error_code import MACHINE_NOT_EXIST_ERROR from utils.error_code import MACHINE_NOT_EXIST_ERROR, HATCH_COUNT_MAX_ERROR, HATCH_NO_DUPLICATE_ERROR, \
HATCH_NOT_EXIST_ERROR
from utils.my_response import BaseResponse from utils.my_response import BaseResponse
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -30,28 +31,33 @@ def run_hatch_list(): ...@@ -30,28 +31,33 @@ def run_hatch_list():
:return: :return:
""" """
json_data = request.get_json() json_data = request.get_json()
page = json_data.get("page", None) page = json_data.get("page", 1)
page_size = json_data.get("pageSize", None) page_size = json_data.get("pageSize", 10)
keyword = json_data.get("keyword", None) keyword = json_data.get("keyword", None)
admin = g.user admin = g.user
select_sql = """select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status, select_sql = """select hatch.id,hatch.machine_no, hatch.hatch_no,hatch.production_id,hatch.production_name,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id, hatch.title,hatch.left_count,hatch.total_count,hatch.brand_id,hatch.brand_name,
place.place_name, machine.discounts_id hatch.production_type_id,hatch.production_type_name,
hatch.price,hatch.original_price, hatch.weight,hatch.weight_unit,hatch.weight_error,
hatch.expiration_date,hatch.expiration_date_unit,hatch.is_expiration_date,
hatch.img, hatch.tags, hatch.content,hatch.summary,hatch.status
""" """
count_sql = "select count(machine.id) as total_count" count_sql = "select count(hatch.id) as total_count"
from_sql = """ from machine left join place on machine.place_id = place.id from_sql = """ from hatch
where machine.machine_no in ( select machine_no from admin_machine where where hatch.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = {user_id} and admin_machine.status = 1) admin_machine.user_id = {user_id} and admin_machine.status = 1)
""".format(user_id=admin.id) """.format(user_id=admin.id)
where_sql = " " where_sql = " "
if keyword: if keyword:
where_sql += """ where_sql += """
and CONCAT(machine.machine_no,ifnull(machine.qrcode_no,'')) LIKE '%{keyword}%' and CONCAT(hatch.machine_no,ifnull(hatch.brand_name,''), ifnull(hatch.production_type_name,''),
ifnull(hatch.production_name,''))
LIKE '%{keyword}%'
""".format(keyword=keyword) """.format(keyword=keyword)
order_sql = " ORDER BY machine.id ASC, machine.status ASC" order_sql = " ORDER BY hatch.id ASC, hatch.status ASC"
limit_sql = " LIMIT {offset} , {page_size} ".format(offset=(page - 1) * page_size, page_size=page_size) limit_sql = " LIMIT {offset} , {page_size} ".format(offset=(page - 1) * page_size, page_size=page_size)
count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone() count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone()
...@@ -60,23 +66,32 @@ def run_hatch_list(): ...@@ -60,23 +66,32 @@ def run_hatch_list():
return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0}) return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0})
else: else:
total_count = count_result.total_count total_count = count_result.total_count
print(select_sql + from_sql + where_sql + order_sql + limit_sql)
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall() result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = [] return_data = []
for info in result: for info in result:
return_data.append( return_data.append(
{"machine_no": info.machine_no, "device_id": info.device_id, "place_name": info.place_name, {"production_name": info.production_name, "production_id": info.production_id,
"mac": info.mac, "power": info.power, "hatch_number": info.hatch_number, "type": info.type, "machine_no": info.machine_no,
"status": info.status, "place_id": info.place_id, "hatch_no": info.hatch_no,
"discounts_id": info.discounts_id, "hatch_id": info.id,
"discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"), "left_count": info.left_count,
"total_count": info.total_count,
"title": info.title, "brand_id": info.brand_id, "brand_name": info.brand_name,
"production_type_id": info.production_type_id, "production_type_name": info.production_type_name,
"price": info.price, "original_price": info.original_price, "weight": info.weight,
"weight_unit": info.weight_unit,
"expiration_date": info.expiration_date, "expiration_date_unit": info.expiration_date_unit,
"is_expiration_date": info.is_expiration_date,
"weight_error": info.weight_error,
"img": info.img, "tags": info.tags, "content": info.content,
"summary": info.summary, "status": info.status,
}) })
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count}) return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@hatch_route.route("add_machine", methods=["POST"]) @hatch_route.route("add_hatch", methods=["POST"])
def run_add_machine(): def run_add_machine():
""" """
...@@ -84,119 +99,154 @@ def run_add_machine(): ...@@ -84,119 +99,154 @@ def run_add_machine():
""" """
json_data = request.get_json() json_data = request.get_json()
machine_no = json_data["machine_no"] machine_no = json_data["machine_no"]
address = json_data.get("address", None) admin_machine = AdminMachine.query.filter_by(machine_no=machine_no, user_id=g.user.id, status=1).first()
device_id = json_data.get("device_id", None) if not admin_machine:
qrcode_no = json_data.get("qrcode_no", None) return jsonify(MACHINE_NOT_EXIST_ERROR)
mac = json_data.get("mac", None) machine = Machine.query.filter(Machine.machine_no == machine_no, Machine.status != -1).first()
power = json_data.get("power", None) if not machine:
hatch_number = json_data.get("hatch_number", None)
place_id = json_data.get("place_id", None)
type = json_data.get("type", 1)
discounts_id = json_data.get("type", 0)
machine_model = Machine()
machine_model.machine_no = machine_no
machine_model.device_id = device_id
machine_model.qrcode_no = qrcode_no
machine_model.mac = mac
machine_model.power = power
machine_model.place_id = place_id
machine_model.address = address
machine_model.mch_platform = 1
machine_model.hatch_number = hatch_number
machine_model.type = type
machine_model.discounts_id = discounts_id
db.session.add(machine_model)
admin_machine = AdminMachine()
admin_machine.user_id = g.user.id
admin_machine.user_no = g.user.user_no
admin_machine.machine_no = machine_model.machine_no
db.session.add(admin_machine)
db.session.commit()
return BaseResponse()
@hatch_route.route("edit_machine", methods=["POST"])
def run_edit_machine():
"""
:return:
"""
json_data = request.get_json()
machine_no = json_data["machine_no"]
address = json_data.get("address", None)
device_id = json_data.get("device_id", None)
qrcode_no = json_data.get("qrcode_no", None)
mac = json_data.get("mac", None)
power = json_data.get("power", None)
hatch_number = json_data.get("hatch_number", None)
place_id = json_data.get("place_id", None)
type = json_data.get("type", None)
status = json_data.get("status", None)
discounts_id = json_data.get("discounts_id", None)
machine_model = Machine.query.filter_by(machine_no=machine_no).first()
if not machine_model:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
if device_id: hatch_num = machine.hatch_number
machine_model.device_id = device_id hatchs = Hatch.query.filter_by(machine_no=machine_no).all()
if qrcode_no: if len(hatchs) >= hatch_num:
machine_model.qrcode_no = qrcode_no return jsonify(HATCH_COUNT_MAX_ERROR)
if mac:
machine_model.mac = mac hatch_no = int(json_data["hatch_no"])
if power: for i in hatchs:
machine_model.power = power if i.hatch_no == hatch_no:
if place_id: return jsonify(HATCH_NO_DUPLICATE_ERROR)
machine_model.place_id = place_id
if address: production_id = json_data["production_id"]
machine_model.address = address production_name = json_data["production_name"]
if hatch_number: title = json_data.get("title", "")
machine_model.hatch_number = hatch_number brand_id = json_data.get("brand_id", 0)
if type: brand_name = json_data.get("brand_name", "")
machine_model.type = type production_type_id = json_data.get("production_type_id", 0)
if status: production_type_name = json_data.get("production_type_name", "")
machine_model.status = status price = json_data.get("price", 0)
if discounts_id: original_price = json_data.get("original_price", 0)
machine_model.discounts_id = discounts_id weight = json_data.get("weight", 0)
db.session.add(machine_model) weight_unit = json_data.get("weight_unit", "g")
weight_error = json_data.get("weight_error", 0)
expiration_date = json_data.get("expiration_date", 0)
expiration_date_unit = json_data.get("expiration_date_unit", "月")
is_expiration_date = json_data.get("is_expiration_date", 0)
img = json_data.get("img", None)
tags = json_data.get("tags", None)
content = json_data.get("content", None)
summary = json_data.get("summary", None)
left_count = json_data.get("left_count", 0)
total_count = json_data["total_count"]
hatch_model = Hatch()
hatch_model.machine_no = machine_no
hatch_model.hatch_no = hatch_no
hatch_model.production_id = production_id
hatch_model.production_name = production_name
hatch_model.title = title
hatch_model.left_count = left_count
hatch_model.total_count = total_count
hatch_model.brand_id = brand_id
hatch_model.brand_name = brand_name
hatch_model.production_type_id = production_type_id
hatch_model.production_type_name = production_type_name
hatch_model.price = price
hatch_model.original_price = original_price
hatch_model.weight = weight
hatch_model.weight_unit = weight_unit
hatch_model.weight_error = weight_error
hatch_model.expiration_date = expiration_date
hatch_model.expiration_date_unit = expiration_date_unit
hatch_model.is_expiration_date = is_expiration_date
hatch_model.img = img
hatch_model.tags = tags
hatch_model.content = content
hatch_model.summary = summary
db.session.add(hatch_model)
db.session.commit() db.session.commit()
return BaseResponse() return BaseResponse()
@hatch_route.route("machine_detail", methods=["POST"]) @hatch_route.route("edit_hatch", methods=["POST"])
def get_machine_detail(): def run_edit_hatch():
""" """
:return: :return:
""" """
json_data = request.get_json() json_data = request.get_json()
machine_no = json_data["machine_no"] hatch_id = json_data["hatch_id"]
hatch = Hatch.query.filter_by(id=hatch_id).first()
if not hatch:
return jsonify(HATCH_NOT_EXIST_ERROR)
admin = g.user admin_machine = AdminMachine.query.filter_by(machine_no=hatch.machine_no, user_id=g.user.id, status=1).first()
select_sql = """select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status, if not admin_machine:
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id, return jsonify(MACHINE_NOT_EXIST_ERROR)
place.place_name, machine.discounts_id machine = Machine.query.filter(Machine.machine_no == hatch.machine_no, Machine.status != -1).first()
""" if not machine:
from_sql = """ from machine left join place on machine.place_id = place.id
where machine.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = {user_id} and admin_machine.status = 1)
""".format(user_id=admin.id)
where_sql = " and machine.machine_no = {}".format(machine_no)
result = db.session.execute(select_sql + from_sql + where_sql).fetchall()
if not result or len(result) != 1:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
info = result[0] production_id = json_data.get("production_id", None)
return BaseResponse(data={"machine_no": info.machine_no, "device_id": info.device_id, "place_name": info.place_name, production_name = json_data.get("production_name", None)
"mac": info.mac, "power": info.power, "hatch_number": info.hatch_number, title = json_data.get("title", None)
"type": info.type, "status": info.status, "place_id": info.place_id, brand_id = json_data.get("brand_id", None)
"discounts_id": info.discounts_id, brand_name = json_data.get("brand_name", None)
"discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"), production_type_id = json_data.get("production_type_id", None)
production_type_name = json_data.get("production_type_name", None)
}) price = json_data.get("price", None)
original_price = json_data.get("original_price", None)
weight = json_data.get("weight", None)
weight_unit = json_data.get("weight_unit", None)
weight_error = json_data.get("weight_error", None)
expiration_date = json_data.get("expiration_date", None)
expiration_date_unit = json_data.get("expiration_date_unit", None)
is_expiration_date = json_data.get("is_expiration_date", None)
img = json_data.get("img", None)
tags = json_data.get("tags", None)
content = json_data.get("content", None)
summary = json_data.get("summary", None)
left_count = json_data.get("left_count", None)
total_count = json_data.get("total_count", None)
if production_id:
hatch.production_id = production_id
hatch.production_name = production_name
if title:
hatch.title = title
if brand_id:
hatch.brand_id = brand_id
hatch.brand_name = brand_name
if production_type_id:
hatch.production_type_id = production_type_id
hatch.production_type_name = production_type_name
if price:
hatch.price = price
if original_price:
hatch.original_price = original_price
if weight:
hatch.weight = weight
if weight_unit:
hatch.weight_unit = weight_unit
if weight_error:
hatch.weight_error = weight_error
if expiration_date:
hatch.expiration_date = expiration_date
if expiration_date_unit:
hatch.expiration_date_unit = expiration_date_unit
if is_expiration_date:
hatch.is_expiration_date = is_expiration_date
if img:
hatch.img = img
if tags:
hatch.tags = tags
if content:
hatch.content = content
if summary:
hatch.summary = summary
if left_count:
hatch.left_count = left_count
if total_count:
hatch.total_count = total_count
db.session.add(hatch)
db.session.commit()
return BaseResponse()
...@@ -14,9 +14,11 @@ from flask import Blueprint, g, request, jsonify ...@@ -14,9 +14,11 @@ from flask import Blueprint, g, request, jsonify
from config.commen_config import DISCOUNTS_TYPES from config.commen_config import DISCOUNTS_TYPES
from models.base_model import db from models.base_model import db
from models.models import AdminMachine, Machine from models.models import AdminMachine, Machine, AdminAccount, AdminBusiness, TallymanMachine
from utils.error_code import MACHINE_NOT_EXIST_ERROR from service.admin_service import AdminService
from utils.error_code import MACHINE_NOT_EXIST_ERROR, ACCOUNT_NOT_EXISTS_ERROR, ADMIN_BUSINESS_NOT_EXIST
from utils.my_response import BaseResponse from utils.my_response import BaseResponse
from utils.mytools import json2obj
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -30,17 +32,19 @@ def run_machine_list(): ...@@ -30,17 +32,19 @@ def run_machine_list():
:return: :return:
""" """
json_data = request.get_json() json_data = request.get_json()
page = json_data.get("page", None) page = json_data.get("page", 1)
page_size = json_data.get("pageSize", None) page_size = json_data.get("pageSize", 10)
keyword = json_data.get("keyword", None) keyword = json_data.get("keyword", None)
admin = g.user admin = g.user
select_sql = """select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status, select_sql = """select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id, machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
place.place_name, machine.discounts_id place.place_name, machine.discounts_id, machine.business_id,business.business_name
""" """
count_sql = "select count(machine.id) as total_count" count_sql = "select count(machine.id) as total_count"
from_sql = """ from machine left join place on machine.place_id = place.id from_sql = """ from machine
left join place on machine.place_id = place.id
left join business on machine.business_id = business.id
where machine.machine_no in ( select machine_no from admin_machine where where machine.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = {user_id} and admin_machine.status = 1) admin_machine.user_id = {user_id} and admin_machine.status = 1)
""".format(user_id=admin.id) """.format(user_id=admin.id)
...@@ -60,7 +64,6 @@ def run_machine_list(): ...@@ -60,7 +64,6 @@ def run_machine_list():
return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0}) return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0})
else: else:
total_count = count_result.total_count total_count = count_result.total_count
print(select_sql + from_sql + where_sql + order_sql + limit_sql)
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall() result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = [] return_data = []
...@@ -71,6 +74,7 @@ def run_machine_list(): ...@@ -71,6 +74,7 @@ def run_machine_list():
"status": info.status, "place_id": info.place_id, "status": info.status, "place_id": info.place_id,
"discounts_id": info.discounts_id, "discounts_id": info.discounts_id,
"discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"), "discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"),
"business_id": info.business_id, "business_name": info.business_name
}) })
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count}) return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
...@@ -179,11 +183,13 @@ def get_machine_detail(): ...@@ -179,11 +183,13 @@ def get_machine_detail():
admin = g.user admin = g.user
select_sql = """select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status, select_sql = """select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id, machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
place.place_name, machine.discounts_id place.place_name, machine.discounts_id,machine.business_id,business.business_name
""" """
from_sql = """ from machine left join place on machine.place_id = place.id from_sql = """ from machine
where machine.machine_no in ( select machine_no from admin_machine where left join place on machine.place_id = place.id
admin_machine.user_id = {user_id} and admin_machine.status = 1) left join business on machine.business_id = business.id
where machine.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = {user_id} and admin_machine.status = 1)
""".format(user_id=admin.id) """.format(user_id=admin.id)
where_sql = " and machine.machine_no = {}".format(machine_no) where_sql = " and machine.machine_no = {}".format(machine_no)
...@@ -198,5 +204,81 @@ def get_machine_detail(): ...@@ -198,5 +204,81 @@ def get_machine_detail():
"type": info.type, "status": info.status, "place_id": info.place_id, "type": info.type, "status": info.status, "place_id": info.place_id,
"discounts_id": info.discounts_id, "discounts_id": info.discounts_id,
"discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"), "discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"),
"business_id": info.business_id, "business_name": info.business_name
}) })
@machine_route.route("distribute_machine", methods=["POST"])
def run_distribute_machine():
"""
:return:
"""
json_data = request.get_json()
machine_nos = json_data["machine_nos"]
user_id = json_data["user_id"]
business_id = json_data["business_id"]
result = AdminService.get_admin_account_list(user_id=user_id)
if result["total_count"] != 1:
return jsonify(ACCOUNT_NOT_EXISTS_ERROR)
admin_info = json2obj(result["list"][0])
admin_business = AdminBusiness.query.filter_by(user_id=g.user.id, business_id=business_id, status=1).first()
if not admin_business:
return jsonify(ADMIN_BUSINESS_NOT_EXIST)
return_machine_no = []
for i in machine_nos:
admin_machines = AdminMachine.query.filter_by(user_id=g.user.id, machine_no=i, status=1).first()
if not admin_machines:
continue
machine = Machine.query.filter_by(machine_no=i).first()
if not machine:
continue
insert_sql = " insert into admin_machine (user_id, user_no, machine_no) values "
insert_sql += "('{}','{}','{}'),".format(admin_info.id, admin_info.user_no, i)
insert_sql = insert_sql[:-1]
insert_sql += " ON DUPLICATE KEY UPDATE status = 1"
db.session.execute(insert_sql)
if admin_info.level == 4:
machine.business_id = business_id
db.session.commit()
return_machine_no.append(i)
return BaseResponse(data={"add_machine_nos": return_machine_no})
@machine_route.route("distribute_tallyman_machine", methods=["POST"])
def run_distribute_tallyman_machine():
"""
:return:
"""
json_data = request.get_json()
machine_nos = json_data["machine_nos"]
user_id = json_data["user_id"]
result = AdminService.get_tallyman_account_list(user_id=user_id)
if result["total_count"] != 1:
return jsonify(ACCOUNT_NOT_EXISTS_ERROR)
admin_info = json2obj(result["list"][0])
return_machine_no = []
for i in machine_nos:
admin_machines = AdminMachine.query.filter_by(user_id=g.user.id, machine_no=i, status=1).first()
if not admin_machines:
continue
machine = Machine.query.filter_by(machine_no=i).first()
if not machine:
continue
insert_sql = " insert into tallyman_machine (user_id, machine_no) values "
insert_sql += "('{}','{}'),".format(admin_info.id, i)
insert_sql = insert_sql[:-1]
insert_sql += " ON DUPLICATE KEY UPDATE status = 1"
db.session.execute(insert_sql)
db.session.commit()
return_machine_no.append(i)
return BaseResponse(data={"add_machine_nos": return_machine_no})
...@@ -77,7 +77,7 @@ def run_production_list(): ...@@ -77,7 +77,7 @@ def run_production_list():
return_data = [] return_data = []
for info in result: for info in result:
return_data.append( return_data.append(
{"production_name": info.production_name, "prodcution_id": info.id, "production_no": info.production_no, {"production_name": info.production_name, "production_id": info.id, "production_no": info.production_no,
"title": info.title, "brand_id": info.brand_id, "brand_name": info.brand_name, "title": info.title, "brand_id": info.brand_id, "brand_name": info.brand_name,
"production_type_id": info.production_type_id, "production_type_name": info.production_type_name, "production_type_id": info.production_type_id, "production_type_name": info.production_type_name,
"price": info.price, "original_price": info.original_price, "weight": info.weight, "price": info.price, "original_price": info.original_price, "weight": info.weight,
...@@ -248,7 +248,7 @@ def get_production_detail(): ...@@ -248,7 +248,7 @@ def get_production_detail():
info = result[0] info = result[0]
return BaseResponse( return BaseResponse(
data={"production_name": info.production_name, "prodcution_id": info.id, "production_no": info.production_no, data={"production_name": info.production_name, "production_id": info.id, "production_no": info.production_no,
"title": info.title, "brand_id": info.brand_id, "brand_name": info.brand_name, "title": info.title, "brand_id": info.brand_id, "brand_name": info.brand_name,
"production_type_id": info.production_type_id, "production_type_name": info.production_type_name, "production_type_id": info.production_type_id, "production_type_name": info.production_type_name,
"price": info.price, "original_price": info.original_price, "weight": info.weight, "price": info.price, "original_price": info.original_price, "weight": info.weight,
...@@ -370,7 +370,7 @@ def get_brand_detail(): ...@@ -370,7 +370,7 @@ def get_brand_detail():
brand_id = json_data["brand_id"] brand_id = json_data["brand_id"]
admin = g.user admin = g.user
select_sql = """select b.id,b.brand_name,b.status select_sql = """select b.id,b.brand_name,b.status, b.img
""" """
from_sql = """ from brand b """ from_sql = """ from brand b """
...@@ -384,7 +384,7 @@ def get_brand_detail(): ...@@ -384,7 +384,7 @@ def get_brand_detail():
return BaseResponse( return BaseResponse(
data={"brand_id": info.id, "brand_name": info.brand_name, data={"brand_id": info.id, "brand_name": info.brand_name,
"status": info.status, "status": info.status, "img": info.img
}) })
......
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2022/01/12
@file: place_portal.py
@function:
@modify:
"""
import logging
from flask import Blueprint, g, request, jsonify
from sqlalchemy.exc import SQLAlchemyError
from config.wechat_config import platform_appid_config_list, pay_config_list
from models.base_model import db
from models.models import Rent, RentDetail, WxUser, Machine, RentRefund
from service.rent_service import RentService
from service.wechat_service import WeChatPayService
from utils.error_code import OPERATE_LEVEL_ERROR, ACTION_CODE_ERROR, REFUND_NOT_PRODUCTION_INFO, Param_Invalid_Error, \
REFUND_MONEY_IS_ZERO, REFUND_MONEY_ERROR
from utils.my_response import BaseResponse
logger = logging.getLogger(__name__)
rent_route = Blueprint('rent', __name__)
@rent_route.route("rent_list", methods=["POST"])
def run_rent_list():
"""
:return:
"""
json_data = request.get_json()
page = json_data.get("page", 1)
page_size = json_data.get("pageSize", 10)
keyword = json_data.get("keyword", None)
start_date = json_data.get("startDate", None)
end_date = json_data.get("endDate", None)
business_id = json_data.get("business_id", None)
is_pay = json_data.get("is_pay", None)
if g.user.level not in (1, 2, 4):
return jsonify(OPERATE_LEVEL_ERROR)
select_sql = """
SELECT rent.rent_no, rent.machine_no, rent.user_id,rent.place_id,rent.is_pay,
rent_detail.hatch_no, rent_detail.production_id,rent_detail.production_name,
rent_detail.status,rent_detail.brand_name,
rent_detail.production_type_name,rent_detail.total,rent_detail.rent_count,
rent_detail.refund_total,rent_detail.refund_count, wx_user.phone,place.place_name,
rent_detail.id as rent_detail_id, rent.business_id, rent.created_at,rent.pay_time
"""
count_sql = " select count(rent.id) as total_count "
from_sql = """
FROM
rent
LEFT JOIN
rent_detail ON rent.rent_no = rent_detail.rent_no
LEFT JOIN
place ON rent.place_id = place.id
LEFT JOIN
wx_user ON rent.user_id = wx_user.id
"""
where_sql = " WHERE 0=0 "
if keyword:
where_sql += """
and CONCAT(rent.rent_no,
wx_user.phone) LIKE '%{keyword}%'
""".format(keyword=keyword)
if start_date:
where_sql += " and rent.created_at > '{}'".format(start_date)
if end_date:
where_sql += " and rent.created_at <= '{}'".format(end_date)
if is_pay:
where_sql += " and rent.is_pay = '{}'".format(is_pay)
if business_id:
where_sql += " and rent.business_id = '{}'".format(business_id)
if g.user.level != 1:
where_sql += """ and rent.business_id in (
select business_id from admin_business where user_id = '{}' and status = 1)
""".format(g.user.id)
order_sql = " ORDER BY rent.created_at DESC, rent_detail.created_at desc"
limit_sql = " LIMIT {offset} , {page_size}".format(offset=(page - 1) * page_size, page_size=page_size)
count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone()
if not count_result:
return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0})
else:
total_count = count_result.total_count
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = []
if result:
for info in result:
tmp = {
"rent_no": info.rent_no, "machine_no": info.machine_no, "user_id": info.user_id,
"phone": info.phone, "rent_detail_id": info.rent_detail_id, "place_name": info.place_name,
"place_id": info.place_id, "is_pay": info.is_pay, "total": info.total, "rent_count": info.rent_count,
"refund_total": info.refund_total, "refund_count": info.refund_count, "business_id": info.business_id,
"production_name": info.production_name, "production_id": info.production_id,
"status": info.status, "create_time": info.created_at.strftime("%Y-%m-%d %H:%M:%S"),
"pay_time": info.pay_time.strftime("%Y-%m-%d %H:%M:%S"),
}
return_data.append(tmp)
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@rent_route.route("rent_detail", methods=["POST"])
def get_rent_detail():
"""
:return:
"""
json_data = request.get_json()
rent_no = json_data.get("rent_no", None)
rent_detail_id = json_data.get("rent_detail_id", None)
if g.user.level not in (1, 2, 4):
return jsonify(OPERATE_LEVEL_ERROR)
select_sql = """
SELECT rent.id, rent.rent_no, rent.machine_no, rent.user_id,rent.place_id,rent.is_pay,
rent_detail.hatch_no, rent_detail.production_name,rent_detail.title, rent_detail.brand_id,
rent_detail.production_type_id, rent_detail.price,rent_detail.original_price,
rent_detail.weight, rent_detail.weight_unit, rent_detail.expiration_date,
rent_detail.expiration_date_unit, rent_detail.is_expiration_date,rent_detail.business_id,
rent_detail.weight_error, rent_detail.img, rent_detail.tags, rent_detail.content,
rent_detail.summary, rent_detail.status,rent_detail.brand_name,
rent_detail.production_type_name,rent_detail.total,rent_detail.rent_count,
rent_detail.refund_total,rent_detail.refund_count, wx_user.phone,place.place_name,
rent_detail.production_id,rent.business_id, rent.created_at,rent.pay_time,
rent_detail.id as rent_detail_id
"""
from_sql = """
FROM
rent
LEFT JOIN
rent_detail ON rent.rent_no = rent_detail.rent_no
LEFT JOIN
place ON rent.place_id = place.id
LEFT JOIN
wx_user ON rent.user_id = wx_user.id
"""
where_sql = " where rent.rent_no = '{}'".format(rent_no)
if rent_detail_id:
where_sql += " and rent_detail.id = '{}'".format(rent_detail_id)
if g.user.level != 1:
where_sql += """ and rent.business_id in (
select business_id from admin_business where user_id = '{}' and status = 1)
""".format(g.user.id)
result = db.session.execute(select_sql + from_sql + where_sql).fetchone()
if result:
return_data = {
"rent_detail_id": result.rent_detail_id, "rent_no": result.rent_no, "machine_no": result.machine_no,
"user_id": result.user_id,
"phone": result.phone, "place_name": result.place_name,
"place_id": result.id, "is_pay": result.is_pay, "total": result.total, "rent_count": result.rent_count,
"refund_total": result.refund_total, "refund_count": result.refund_count, "business_id": result.business_id,
"production_name": result.production_name, "production_id": result.production_id,
"title": result.title, "brand_id": result.brand_id, "brand_name": result.brand_name,
"production_type_id": result.production_type_id, "production_type_name": result.production_type_name,
"price": result.price, "original_price": result.original_price, "weight": result.weight,
"weight_unit": result.weight_unit,
"expiration_date": result.expiration_date, "expiration_date_unit": result.expiration_date_unit,
"is_expiration_date": result.is_expiration_date,
"weight_error": result.weight_error,
"img": result.img, "tags": result.tags, "content": result.content,
"summary": result.summary, "status": result.status,
"create_time": result.created_at.strftime("%Y-%m-%d %H:%M:%S"),
"pay_time": result.pay_time.strftime("%Y-%m-%d %H:%M:%S"),
}
return BaseResponse({"data": return_data})
else:
return BaseResponse()
@rent_route.route('/rent_money_refund', methods=['GET', 'POST'])
def rent_money_refund_new():
if g.user.level not in (1, 2, 4):
return jsonify(OPERATE_LEVEL_ERROR)
json_data = request.get_json()
action_pwd = json_data['action_pwd'] if 'action_pwd' in json_data else ''
rent_no = json_data['rent_no']
rent_detail_id = json_data['rent_detail_id']
if action_pwd != "xxzn666":
return BaseResponse(**ACTION_CODE_ERROR)
cause = json_data['cause']
comment = json_data['comment'] if 'comment' in json_data else ''
rent_info = db.session.query(RentDetail, Rent, WxUser, Machine
).join(Rent,
Rent.rent_no == RentDetail.rent_no
).join(WxUser, WxUser.id == Rent.user_id
).filter(RentDetail.id == rent_detail_id,
Rent.rent_no == rent_no).first()
if not rent_info:
return jsonify(REFUND_NOT_PRODUCTION_INFO)
rent = rent_info.Rent
rent_detail = rent_info.RentDetail
wx_user = rent_info.WxUser
refund_count = int(json_data["refund_count"])
refund_money = refund_count * rent_detail.price
if refund_money <= 0:
return jsonify(REFUND_MONEY_IS_ZERO)
if refund_money > rent_detail.total: # 不能超出金额退款
return jsonify(REFUND_MONEY_ERROR)
new_total = rent_detail.total - refund_money
# 重新计算订单对应所有讲解器总收入,退款金额
rent_total = 0
rent_details = RentDetail.query.filter_by(rent_no=rent.rent_no).all()
for tmp in rent_details:
if tmp.id == rent_detail.id:
rent_total += new_total
else:
rent_total += tmp.total
# 退款操作
data = {
"out_refund_no": RentService.create_refund_no(),
"out_trade_no": rent_info.Rent.rent_no,
"total_fee": rent.total,
"refund_fee": refund_money
}
result = WeChatPayService(app_id=platform_appid_config_list[wx_user.platform],
config_name=pay_config_list[rent.mch_platform]).do_refund(data)
if result:
try:
rent_refund = RentRefund()
rent_refund.user_id = g.user.id
rent_refund.refund_no = data["out_refund_no"]
rent_refund.rent_no = rent.rent_no
rent_refund.rent_detail_id = rent_detail.id
rent_refund.total = refund_money
rent_refund.comment = comment
rent_refund.cause = cause
rent.real_total = rent_total
rent.back_money += refund_money
rent_detail.total = new_total
rent_detail.refund_count += refund_count
rent_detail.refund_total += refund_money
db.session.add(rent_refund)
db.session.add(rent)
db.session.add(rent_detail)
db.session.commit()
except SQLAlchemyError as e:
db.session.rollback()
raise e
return BaseResponse()
else:
return BaseResponse(error_code=-1, error_message='refund failed')
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2022/01/12
@file: place_portal.py
@function:
@modify:
"""
import datetime
import logging
from flask import Blueprint, g, request, jsonify
from models.base_model import db
from models.models import AdminPlace, Place, TallymanMachine, Machine, TallymanAccount
from service.admin_service import AdminService
from utils.error_code import NO_PLACE_ERROR, TALLYMAN_ACCOUNT_NOT_EXIST, TALLYMAN_ACCOUNT_EXIST, OPERATE_LEVEL_ERROR, \
ACCOUNT_NOT_EXISTS_ERROR
from utils.my_response import BaseResponse
from utils.mytools import json2obj
logger = logging.getLogger(__name__)
tallyman_route = Blueprint('tallyman', __name__)
@tallyman_route.route('/tallyman_list', methods=["POST"])
def get_account_list():
json_data = request.get_json()
page = json_data.get("page", 1)
page_size = json_data.get("pageSize", 10)
keyword = json_data.get("keyword", None)
return_data = AdminService.get_tallyman_account_list(keyword=keyword, page=page, page_size=page_size)
return BaseResponse(return_data)
@tallyman_route.route('/edit_tallyman_account', methods=['GET', 'POST'])
def run_tallyman_edit_account():
admin = g.user
if g.user.level not in (1, 2, 4):
return jsonify(OPERATE_LEVEL_ERROR)
json_data = request.get_json()
old_phone = json_data['old_phone']
new_phone = json_data.get('new_phone', None)
user_name = json_data.get('user_name', None)
password = json_data.get('password', None)
business_id = json_data.get('business_id', None)
status = json_data.get('status', None)
tallyman_info = TallymanAccount.query.filter_by(phone=old_phone).first()
if not tallyman_info:
return jsonify(TALLYMAN_ACCOUNT_NOT_EXIST)
if new_phone:
tallyman_info.phone = new_phone
if user_name:
tallyman_info.user_name = user_name
if password:
tallyman_info.password = password
if status:
tallyman_info.status = status
if business_id:
tallyman_info.business_id = business_id
db.session.add(tallyman_info)
db.session.commit()
return BaseResponse()
@tallyman_route.route('/add_tallyman_account', methods=['GET', 'POST'])
def run_add_tallyman_account():
admin = g.user
if g.user.level not in (1, 2, 4):
return jsonify(OPERATE_LEVEL_ERROR)
json_data = request.get_json()
user_name = json_data['user_name'] if 'user_name' in json_data else 'SSW'
phone = json_data['phone'] if 'phone' in json_data else None
level = int(json_data['level']) if 'level' in json_data else 2
password = json_data['password'] if 'password' in json_data else None
comment = json_data['comment'] if 'comment' in json_data else ''
business_id = json_data["business_id"]
tallyman = TallymanAccount.query.filter_by(phone=phone).first()
if tallyman:
if tallyman.status != -1:
return jsonify(TALLYMAN_ACCOUNT_EXIST)
else:
tallyman = TallymanAccount()
tallyman.user_no = "todo"
tallyman.user_name = user_name
tallyman.phone = phone
tallyman.level = level
tallyman.business_id = business_id
tallyman.status = 1
tallyman.comment = comment
tallyman.created_at = datetime.datetime.now()
tallyman.updated_at = datetime.datetime.now()
if password:
tallyman.password = password
db.session.add(tallyman)
db.session.commit()
tallyman.user_no = "XXTM" + str(tallyman.id).zfill(6)
db.session.add(tallyman)
db.session.commit()
return BaseResponse()
@tallyman_route.route('/delete_tallyman_account', methods=['GET', 'POST'])
def run_delete_tallyman_account():
json_data = request.get_json()
if g.user.level not in (1, 2, 4):
return jsonify(OPERATE_LEVEL_ERROR)
phone = json_data['phone']
tallyman = TallymanAccount.query.filter_by(phone=phone).first()
if not tallyman:
return BaseResponse()
tallyman.status = -1
db.session.add(tallyman)
tallyman_machine_info = TallymanMachine.query.filter_by(user_id=tallyman.id).all()
for info in tallyman_machine_info:
info.status = -1
db.session.add(info)
db.session.commit()
return BaseResponse()
@tallyman_route.route('/tallyman_account_detail', methods=["POST"])
def get_tallyman_account_detail():
json_data = request.get_json()
if g.user.level not in (1, 2, 4):
return jsonify(OPERATE_LEVEL_ERROR)
phone = json_data["phone"]
if phone == g.user.phone:
admin_info = g.user
else:
result = AdminService.get_tallyman_account_list(phone=phone)
if result["total_count"] != 1:
return BaseResponse(ACCOUNT_NOT_EXISTS_ERROR)
admin_info = json2obj(result["list"][0])
user_info = {
"id": admin_info.id,
"user_no": admin_info.user_no,
"user_name": admin_info.user_name,
"phone": admin_info.phone,
"level": admin_info.level,
"business_id": admin_info.business_id,
"status": admin_info.status,
"comment": admin_info.comment
}
return BaseResponse(data=user_info)
...@@ -5,98 +5,174 @@ import hashlib ...@@ -5,98 +5,174 @@ import hashlib
import random import random
import string import string
from flask import g
from config.commen_config import ACCOUNT_STATUS from config.commen_config import ACCOUNT_STATUS
from models.models import AdminAccount from models.models import AdminAccount, Business, AdminBusiness
from models.base_model import db from models.base_model import db
from models.models import Place
# from models.user_models import AgentAccount
# from service.spot_service import SpotService
class AdminService(): class AdminService(object):
@staticmethod
def gene_salt(length=16):
key_list = [random.choice((string.ascii_letters + string.digits)) for i in range(length)]
return ("".join(key_list))
@staticmethod @staticmethod
def gene_agent_code(agent_info, salt): def get_business_id_list():
""" """
:param agent_info: :param business_ids:
:param salt:
:return: :return:
""" """
m = hashlib.md5()
str = "%s-%s-%s-%s" % (agent_info.id, agent_info.user_name, agent_info.phone, salt)
m.update(str.encode("utf-8"))
return m.hexdigest()
@staticmethod if g.user.level == 1:
def gene_pwd(pwd, salt): business_list = Business.query.filter().all()
""" if business_list:
business_id_list = [i.id for i in business_list]
else:
business_id_list = []
:param pwd: else:
:param salt: admin_business_list = AdminBusiness.query.filter_by(user_id=g.user.id, status=1).all()
:return: if admin_business_list:
""" business_id_list = [i.business_id for i in admin_business_list]
m = hashlib.md5() else:
str = "%s-%s" % (base64.encodebytes(pwd.encode("utf-8")), salt) business_id_list = []
m.update(str.encode("utf-8"))
return m.hexdigest() return business_id_list
@staticmethod @staticmethod
def check_agent_token(token): def add_or_edit_admin_business(admin_account, business_ids):
""" """
:param token: :param business_ids:
:return: :return:
""" """
token = base64.b64decode(token).decode("utf-8") my_business_id_list = AdminService.get_business_id_list()
try: right_busines_ids = list(set(business_ids).intersection(set(my_business_id_list)))
agent_info = AgentAccount.query.filter_by(access_token=token).first()
except Exception as e:
return 1
if not agent_info: insert_sql = " insert into admin_business (user_id, user_no, business_id) values "
return 1 for i in right_busines_ids:
insert_sql += "('{}','{}','{}'),".format(admin_account.id, admin_account.user_no, i)
s = token.split("#") insert_sql = insert_sql[:-1]
if len(s) != 2: insert_sql += " ON DUPLICATE KEY UPDATE status = 1"
return 1 db.session.execute(insert_sql)
db.session.commit()
if AgentService.gene_agent_code(agent_info, agent_info.salt) != s[0]:
return 1
if agent_info.expire_time < datetime.datetime.now():
return 2
return agent_info
@staticmethod @staticmethod
def create_agent_no(): def get_admin_account_list(user_id=None, phone=None, keyword=None, page=None, page_size=None):
''' """
生成用户编号
:return: :return:
''' """
ran_int = str(random.randint(1, 999999)).zfill(6) select_sql = """select admin_account.user_name, admin_account.phone, admin_account.level, admin_account.status,
return 'ssw' + ran_int admin_account.comment,admin_account.parent_id,admin_account.rate, admin_account.created_at,
admin_account.updated_at,admin_account.id, admin_account.user_no
"""
count_sql = "select count(admin_account.id) as total_count"
from_sql = " from admin_account "
if g.user.level == 1:
where_sql = " where 0=0 "
else:
where_sql = """
where
admin_account.id in (
select user_id from admin_business where business_id in (
select business_id from admin_business where user_id = {user_id} and status = 1
)
)
and admin_account.level > {level}
""".format(user_id=g.user.id, level=g.user.level)
if user_id:
where_sql += " and admin_account.id = '{id}'".format(id=user_id)
if phone:
where_sql += " and phone = '{phone}'".format(phone=phone)
if keyword:
where_sql += """
and CONCAT( admin_account.user_name,
admin_account.phone,
admin_account.user_no) LIKE '%{keyword}%'
""".format(keyword=keyword)
order_sql = " ORDER BY admin_account.id ASC, admin_account.status ASC"
if page and page_size:
limit_sql = " LIMIT {offset} , {page_size} ".format(offset=(page - 1) * page_size, page_size=page_size)
else:
limit_sql = " "
count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone()
if not count_result:
return {"list": [], "page": page, "pageSize": page_size, "total_count": 0}
else:
total_count = count_result.total_count
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = []
for info in result:
return_data.append(
{"user_name": info.user_name, "phone": info.phone, "level": info.level, "status": info.status,
"comment": info.comment, "id": info.id, "user_no": info.user_no,
"create_time": info.created_at.strftime("%Y-%m-%d %H:%M:%S"),
"update_time": info.updated_at.strftime("%Y-%m-%d %H:%M:%S"),
})
return {"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count}
@staticmethod @staticmethod
def get_spot_info(agent_info): def get_tallyman_account_list(user_id=None, phone=None, keyword=None, page=None, page_size=None):
""" """
:param agent_info:
:return: :return:
""" """
spot_info = [] select_sql = """select tallyman_account.user_name, tallyman_account.phone, tallyman_account.level,
infos = db.session.query(AgentSpot, Spot).join( tallyman_account.status,tallyman_account.created_at, tallyman_account.updated_at,
Spot, Spot.id == AgentSpot.spot_no).filter(AgentSpot.agent_no == agent_info.id, tallyman_account.id, tallyman_account.user_no, tallyman_account.comment,
AgentSpot.status == ACCOUNT_STATUS['on_use']).all() tallyman_account.business_id
for info in infos: """
cur_info = {} count_sql = "select count(tallyman_account.id) as total_count"
cur_info['id'] = info.Spot.id
cur_info['spotname'] = info.Spot.spotname from_sql = " from tallyman_account "
cur_info['letter'] = SpotService.get_pinyin(info.Spot.spotname) if g.user.level == 1:
spot_info.append(cur_info) where_sql = " where 0=0 "
return spot_info else:
where_sql = """
where
tallyman_account.business_id in (
select business_id from admin_business where user_id = {user_id} and status = 1
)
""".format(user_id=g.user.id)
if user_id:
where_sql += " and tallyman_account.id = '{id}'".format(id=user_id)
if phone:
where_sql += " and phone = '{phone}'".format(phone=phone)
if keyword:
where_sql += """
and CONCAT( tallyman_account.user_name,
tallyman_account.phone) LIKE '%{keyword}%'
""".format(keyword=keyword)
order_sql = " ORDER BY tallyman_account.id ASC, tallyman_account.status ASC"
if page and page_size:
limit_sql = " LIMIT {offset} , {page_size} ".format(offset=(page - 1) * page_size, page_size=page_size)
else:
limit_sql = " "
count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone()
if not count_result:
return {"list": [], "page": page, "pageSize": page_size, "total_count": 0}
else:
total_count = count_result.total_count
print(select_sql + from_sql + where_sql + order_sql + limit_sql)
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = []
for info in result:
return_data.append(
{"user_name": info.user_name, "phone": info.phone, "level": info.level, "status": info.status,
"comment": info.comment, "id": info.id, "user_no": info.user_no, "business_id": info.business_id,
"create_time": info.created_at.strftime("%Y-%m-%d %H:%M:%S"),
"update_time": info.updated_at.strftime("%Y-%m-%d %H:%M:%S"),
})
return {"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count}
#!usr/bin/env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @file: error_code.py """ ### 通用错误相关 Param_Invalid_Error = { "error_code": "500", "error_message": "params is invalid, 参数无效" } TOKEN_NOT_VALID_ERROR = { "error_code": "1001", "error_message": "无效的token" } TOKEN_NOT_PROVIDED_ERROR = { "error_code": "1002", "error_message": "token未提供" } TOKEN_EXPIRE_ERROR = { "error_code": "1003", "error_message": "token超时" } PHONE_NOT_BINDING_ERROR = { "error_code": "1004", "error_message": "未绑定手机号" } PHONE_NOT_NULL_ERROR = { "error_code": "1005", "error_message": "手机号为空" } PHONE_NOT_VALID_ERROR = { "error_code": "1006", "error_message": "无效的手机号" } USER_ALREADY_REGISTER_ERROR = { "error_code": "1007", "error_message": "用户已注册" } VERIFICATION_CODE_NULL_ERROR = { "error_code": "1008", "error_message": "验证码为空" } VERIFICATION_CODE_INVALID_ERROR = { "error_code": "1009", "error_message": "验证码已失效" } VERIFICATION_CODE_ERROR = { "error_code": "1010", "error_message": "验证码错误" } PASSWORD_ERROR = { "error_code": "1011", "error_message": "账号或密码错误" } # 账号相关 12开头 ACCOUNT_ALREADY_EXISTS_ERROR = { "error_code": '1012', "error_message": "该账号已存在" } ACCOUNT_NOT_EXISTS_ERROR = { "error_code": '1013', "error_message": "账号不存在" } ACCOUNT_ALREADY_DELETE_ERROR = { "error_code": '1014', "error_message": "账号已被删除" } ACCOUNT_AGENT_SPOT_NULL_ERROR = { "error_code": '1015', "error_message": "代理商景点列表为空" } AGNET_MODULES_ERROR = { "error_code": '1016', "error_message": "用户未绑定模块" } OPERATE_TYPE_ERROR = { "error_code": '1017', "error_message": "type错误" } OPERATE_LEVEL_ERROR = { "error_code": '1018', "error_message": "权限错误" } OPERATE_ERROR = { "error_code": '1019', "error_message": "操作有误" } MODULES_NOT_EXISTS_ERROR = { "error_code": '1020', "error_message": "modules not exists,模块不存在" } ACCOUNT_AGENT_SPOT_NOT_EXIST = { "error_code": '1021', "error_message": "agent spot not exists,代理景区不存在" } AGENT_MACHINE_NOT_EXIST = { "error_code": '1022', "error_message": "agent machine not exists,代理机柜不存在" } ## 微信登陆相关 WX_LOGIN_DATA_ERROR = { "error_code": "3001", "error_message": "微信登录数据错误" } WX_LOGIN_CODE_ERROR = { "error_code": "3002", "error_message": "微信登录code值错误" } WX_OPENID_NOT_GET_ERROR = { "error_code": "3003", "error_message": "微信OpenId获取失败,请刷新重试" } WX_SESSION_KEY_ERROR = { "error_code": "3004", "error_message": "session key error" } ### 微信支付相关 WE_MINIAPP_PAY_FAIL = { "error_code": "3101", "error_message": "小程序下单失败" } ### 消息推送相关 WXBizMsgCrypt_OK = { "error_code": "0", "error_message": "WXBizMsgCrypt_OK" } WXBizMsgCrypt_ValidateSignature_Error = { "error_code": "4001", "error_message": "验证签名错误" } WXBizMsgCrypt_ParseXml_Error = { "error_code": "4002", "error_message": "解析xml错误" } WXBizMsgCrypt_ComputeSignature_Error = { "error_code": "4003", "error_message": "计算签名错误" } WXBizMsgCrypt_IllegalAesKey = { "error_code": "4004", "error_message": "Aes key非法错误" } WXBizMsgCrypt_ValidateAppid_Error = { "error_code": "4005", "error_message": "appid错误" } WXBizMsgCrypt_EncryptAES_Error = { "error_code": "4006", "error_message": "aes加密错误" } WXBizMsgCrypt_DecryptAES_Error = { "error_code": "4007", "error_message": "aes解密错误" } WXBizMsgCrypt_IllegalBuffer = { "error_code": "4008", "error_message": "illegal buffer" } WXBizMsgCrypt_EncodeBase64_Error = { "error_code": "4009", "error_message": "base64加密错误" } WXBizMsgCrypt_DecodeBase64_Error = { "error_code": "4010", "error_message": "base64解密错误" } WXBizMsgCrypt_GenReturnXml_Error = { "error_code": "4011", "error_message": "gen return xml error" } MACHINE_NOT_EXIST_ERROR = { "error_code": '5001', "error_message": "机柜不存在" } MACHINE_IS_USE_ERROR = { "error_code": '5002', "error_message": "已有他人正在租借中,请稍后" } MACHINE_IS_NOT_ONLINE_ERROR = { "error_code": '5003', "error_message": "机柜不在线" } MACHINE_ADD_ERROR = { "error_code": '5004', "error_message": "机柜添加失败" } MACHINE_NO_DUPLICATE_ERROR = { "error_code": '5005', "error_message": "machine_no duplicate,机柜编号重复" } MACHINE_EDIT_ERROR = { "error_code": '5006', "error_message": "machine edit error, 机柜修改错误" } HATCH_NOT_EXIST_ERROR = { "error_code": "5007", "error_message": "no hatch, 没有商品信息" } HATCH_NOT_ALL_EXIST_ERROR = { "error_code": "5008", "error_message": "no all hatch, 存在已售出商品" } HATCH_COUNT_ERROR = { "error_code": "5009", "error_message": "hatch count error, 商品数量错误,检查数量" } MACHINE_ACTIVATED_ERROR = { "error_code": '5010', "error_message": "machine activated, 机柜已激活" } MACHINE_NO_CREATE_ERROR = { "error_code": '5011', "error_message": "machine_no create error , 机柜编号生成错误" } MACHINE_MAC_DUPLICATE_ERROR = { "error_code": '5012', "error_message": "machine_mac duplicate,机柜mac重复" } ### 订单相关 RENT_ORDER_NOT_BACK_ERROR = { "error_code": '6101', "error_message": "有未归还的订单" } RENT_ORDER_NOT_TAKE_ERROR = { "error_code": '6102', "error_message": "有未取货的订单" } RENT_ORDER_NUMBER_MAX = { "error_code": '6103', "error_message": "订单数量达到上限" } TAKE_CODE_NOT_VALID = { "error_code": '6104', "error_message": "取货码错误请确认手机号及取货码是否匹配" } CODE_CANCEL_ERROR = { "error_code": '6105', "error_message": "取货码已取消" } CODE_USED_ERROR = { "error_code": '6108', "error_message": "取货码已使用" } NO_POWER_ERROR = { "error_code": '6106', "error_message": "没有可租借设备" } NO_RENT_RECORD = { "error_code": '6107', "error_message": "订单不存在" } CODE_USED_ERROR = { "error_code": '6108', "error_message": "取货码已使用" } RENT_ORDER_NUMBER_LIMIT = { "error_code": '6109', "error_message": "机柜只允许租借一台" } REFUND_NOT_RENT_INFO = { "error_code": "6301", "error_message": "没有该订单信息" } REFUND_BACK_TIME_ERROR = { "error_code": "6302", "error_message": "归还时间异常" } REFUND_NOT_PRODUCTION_INFO = { "error_code": "6303", "error_message": "没有该讲解器信息" } REFUND_MONEY_IS_ZERO = { "error_code": "6304", "error_message": "退款金额为零" } REFUND_NO_DUPLICATE = { "error_code": "6305", "error_message": "退款单号重复" } TALLYMAN_ACCOUNT_EXIST = { "error_code": "7001", "error_message": "tallyman account exist, 补货员账号已存在" } TALLYMAN_ACCOUNT_NOT_EXIST = { "error_code": "7002", "error_message": "tallyman account not exist, 补货员账号不存在" } NFC_CARD_NOT_EXIST = { "error_code": "8001", "error_message": "nfc card not exist, 卡号错误" } NFC_CARD_ACTIVATED_ERROR = { "error_code": "8002", "error_message": "nfc card activated, 卡片已激活" } NO_NFC_CARD_ERROR = { "error_code": "8003", "error_message": "no nfc card , 不存在卡片" } RE_NFC_CARD_ERROR = { "error_code": "8004", "error_message": "re nfc card , 卡片已存在" } NFC_PAY_LOAD_SECRET_ERROR = { "error_code": "8005", "error_message": "secret error , 身份验证失败" } # 9 场所相关 NO_PLACE_ERROR = { "error_code": "9001", "error_message": "no place error,不存在场景" } # 10 商品相关 NO_PRODUCTION_ERROR = { "error_code": "10001", "error_message": "no production error,商品不存在" } NO_BRAND_ERROR = { "error_code": "10002", "error_message": "no production error,品牌不存在" } # COMMON_MONGO_ERROR = { "error_code": 5001, "error_message": "mongodb operation error, mongodb操作错误" } #!usr/bin/env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @file: error_code.py """ ### 通用错误相关 Param_Invalid_Error = { "error_code": "500", "error_message": "params is invalid, 参数无效" } TOKEN_NOT_VALID_ERROR = { "error_code": "1001", "error_message": "无效的token" } TOKEN_NOT_PROVIDED_ERROR = { "error_code": "1002", "error_message": "token未提供" } TOKEN_EXPIRE_ERROR = { "error_code": "1003", "error_message": "token超时" } PHONE_NOT_BINDING_ERROR = { "error_code": "1004", "error_message": "未绑定手机号" } PHONE_NOT_NULL_ERROR = { "error_code": "1005", "error_message": "手机号为空" } PHONE_NOT_VALID_ERROR = { "error_code": "1006", "error_message": "无效的手机号" } USER_ALREADY_REGISTER_ERROR = { "error_code": "1007", "error_message": "用户已注册" } VERIFICATION_CODE_NULL_ERROR = { "error_code": "1008", "error_message": "验证码为空" } VERIFICATION_CODE_INVALID_ERROR = { "error_code": "1009", "error_message": "验证码已失效" } VERIFICATION_CODE_ERROR = { "error_code": "1010", "error_message": "验证码错误" } PASSWORD_ERROR = { "error_code": "1011", "error_message": "账号或密码错误" } # 账号相关 12开头 ACCOUNT_ALREADY_EXISTS_ERROR = { "error_code": '1012', "error_message": "该账号已存在" } ACCOUNT_NOT_EXISTS_ERROR = { "error_code": '1013', "error_message": "账号不存在" } ACCOUNT_ALREADY_DELETE_ERROR = { "error_code": '1014', "error_message": "账号已被删除" } ACCOUNT_AGENT_SPOT_NULL_ERROR = { "error_code": '1015', "error_message": "代理商景点列表为空" } AGNET_MODULES_ERROR = { "error_code": '1016', "error_message": "用户未绑定模块" } OPERATE_TYPE_ERROR = { "error_code": '1017', "error_message": "type错误" } OPERATE_LEVEL_ERROR = { "error_code": '1018', "error_message": "权限错误" } OPERATE_ERROR = { "error_code": '1019', "error_message": "操作有误" } MODULES_NOT_EXISTS_ERROR = { "error_code": '1020', "error_message": "modules not exists,模块不存在" } ACCOUNT_AGENT_SPOT_NOT_EXIST = { "error_code": '1021', "error_message": "agent spot not exists,代理景区不存在" } AGENT_MACHINE_NOT_EXIST = { "error_code": '1022', "error_message": "agent machine not exists,代理机柜不存在" } NO_BUSINESS_ERROR = { "error_code": '1023', "error_message": "no business error,商户不存在" } ADMIN_BUSINESS_NOT_EXIST = { "error_code": '1024', "error_message": "admin business not exist,用户商户不存在" } ACTION_CODE_ERROR = { "error_code": '1025', "error_message": "退款操作码错误" } ## 微信登陆相关 WX_LOGIN_DATA_ERROR = { "error_code": "3001", "error_message": "微信登录数据错误" } WX_LOGIN_CODE_ERROR = { "error_code": "3002", "error_message": "微信登录code值错误" } WX_OPENID_NOT_GET_ERROR = { "error_code": "3003", "error_message": "微信OpenId获取失败,请刷新重试" } WX_SESSION_KEY_ERROR = { "error_code": "3004", "error_message": "session key error" } ### 微信支付相关 WE_MINIAPP_PAY_FAIL = { "error_code": "3101", "error_message": "小程序下单失败" } ### 消息推送相关 WXBizMsgCrypt_OK = { "error_code": "0", "error_message": "WXBizMsgCrypt_OK" } WXBizMsgCrypt_ValidateSignature_Error = { "error_code": "4001", "error_message": "验证签名错误" } WXBizMsgCrypt_ParseXml_Error = { "error_code": "4002", "error_message": "解析xml错误" } WXBizMsgCrypt_ComputeSignature_Error = { "error_code": "4003", "error_message": "计算签名错误" } WXBizMsgCrypt_IllegalAesKey = { "error_code": "4004", "error_message": "Aes key非法错误" } WXBizMsgCrypt_ValidateAppid_Error = { "error_code": "4005", "error_message": "appid错误" } WXBizMsgCrypt_EncryptAES_Error = { "error_code": "4006", "error_message": "aes加密错误" } WXBizMsgCrypt_DecryptAES_Error = { "error_code": "4007", "error_message": "aes解密错误" } WXBizMsgCrypt_IllegalBuffer = { "error_code": "4008", "error_message": "illegal buffer" } WXBizMsgCrypt_EncodeBase64_Error = { "error_code": "4009", "error_message": "base64加密错误" } WXBizMsgCrypt_DecodeBase64_Error = { "error_code": "4010", "error_message": "base64解密错误" } WXBizMsgCrypt_GenReturnXml_Error = { "error_code": "4011", "error_message": "gen return xml error" } MACHINE_NOT_EXIST_ERROR = { "error_code": '5001', "error_message": "机柜不存在" } MACHINE_IS_USE_ERROR = { "error_code": '5002', "error_message": "已有他人正在租借中,请稍后" } MACHINE_IS_NOT_ONLINE_ERROR = { "error_code": '5003', "error_message": "机柜不在线" } MACHINE_ADD_ERROR = { "error_code": '5004', "error_message": "机柜添加失败" } MACHINE_NO_DUPLICATE_ERROR = { "error_code": '5005', "error_message": "machine_no duplicate,机柜编号重复" } MACHINE_EDIT_ERROR = { "error_code": '5006', "error_message": "machine edit error, 机柜修改错误" } HATCH_NOT_EXIST_ERROR = { "error_code": "5007", "error_message": "no hatch, 没有仓道商品信息" } HATCH_NOT_ALL_EXIST_ERROR = { "error_code": "5008", "error_message": "no all hatch, 存在已售出商品" } HATCH_COUNT_ERROR = { "error_code": "5009", "error_message": "hatch count error, 商品数量错误,检查数量" } MACHINE_ACTIVATED_ERROR = { "error_code": '5010', "error_message": "machine activated, 机柜已激活" } MACHINE_NO_CREATE_ERROR = { "error_code": '5011', "error_message": "machine_no create error , 机柜编号生成错误" } MACHINE_MAC_DUPLICATE_ERROR = { "error_code": '5012', "error_message": "machine_mac duplicate,机柜mac重复" } HATCH_COUNT_MAX_ERROR = { "error_code": '5013', "error_message": "hatch count max,仓道数量达到上限" } HATCH_NO_DUPLICATE_ERROR = { "error_code": '5014', "error_message": "hatch_no duplicate,仓道序号重复" } HATCH_NO_DUPLICATE_ERROR = { "error_code": '5014', "error_message": "hatch_no duplicate,仓道序号重复" } ### 订单相关 RENT_ORDER_NOT_BACK_ERROR = { "error_code": '6101', "error_message": "有未归还的订单" } RENT_ORDER_NOT_TAKE_ERROR = { "error_code": '6102', "error_message": "有未取货的订单" } RENT_ORDER_NUMBER_MAX = { "error_code": '6103', "error_message": "订单数量达到上限" } TAKE_CODE_NOT_VALID = { "error_code": '6104', "error_message": "取货码错误请确认手机号及取货码是否匹配" } CODE_CANCEL_ERROR = { "error_code": '6105', "error_message": "取货码已取消" } CODE_USED_ERROR = { "error_code": '6108', "error_message": "取货码已使用" } NO_POWER_ERROR = { "error_code": '6106', "error_message": "没有可租借设备" } NO_RENT_RECORD = { "error_code": '6107', "error_message": "订单不存在" } CODE_USED_ERROR = { "error_code": '6108', "error_message": "取货码已使用" } RENT_ORDER_NUMBER_LIMIT = { "error_code": '6109', "error_message": "机柜只允许租借一台" } REFUND_NOT_RENT_INFO = { "error_code": "6301", "error_message": "没有该订单信息" } REFUND_BACK_TIME_ERROR = { "error_code": "6302", "error_message": "归还时间异常" } REFUND_NOT_PRODUCTION_INFO = { "error_code": "6303", "error_message": "没有该讲解器信息" } REFUND_MONEY_IS_ZERO = { "error_code": "6304", "error_message": "退款金额为零" } REFUND_NO_DUPLICATE = { "error_code": "6305", "error_message": "退款单号重复" } REFUND_MONEY_ERROR = { "error_code": "6306", "error_message": "refund money退款金额错误" } TALLYMAN_ACCOUNT_EXIST = { "error_code": "7001", "error_message": "tallyman account exist, 补货员账号已存在" } TALLYMAN_ACCOUNT_NOT_EXIST = { "error_code": "7002", "error_message": "tallyman account not exist, 补货员账号不存在" } NFC_CARD_NOT_EXIST = { "error_code": "8001", "error_message": "nfc card not exist, 卡号错误" } NFC_CARD_ACTIVATED_ERROR = { "error_code": "8002", "error_message": "nfc card activated, 卡片已激活" } NO_NFC_CARD_ERROR = { "error_code": "8003", "error_message": "no nfc card , 不存在卡片" } RE_NFC_CARD_ERROR = { "error_code": "8004", "error_message": "re nfc card , 卡片已存在" } NFC_PAY_LOAD_SECRET_ERROR = { "error_code": "8005", "error_message": "secret error , 身份验证失败" } # 9 场所相关 NO_PLACE_ERROR = { "error_code": "9001", "error_message": "no place error,不存在场景" } # 10 商品相关 NO_PRODUCTION_ERROR = { "error_code": "10001", "error_message": "no production error,商品不存在" } NO_BRAND_ERROR = { "error_code": "10002", "error_message": "no production error,品牌不存在" } # COMMON_MONGO_ERROR = { "error_code": 5001, "error_message": "mongodb operation error, mongodb操作错误" }
\ No newline at end of file \ No newline at end of file
......
#!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/30 @file: jwt_util.py @function: @modify: """ import jwt from flask import current_app def generate_jwt(payload, expiry, secret=None): """ 生成jwt :param payload: dict 载荷 :param expiry: datetime 有效期 :param secret: 密钥 :return: jwt """ _payload = {'exp': expiry} _payload.update(payload) if not secret: secret = current_app.config['SECRET_KEY'] token = jwt.encode(_payload, secret, algorithm='HS256') return token def verify_jwt(token, secret=None): """ 检验jwt :param token: jwt :param secret: 密钥 :return: dict: payload """ if not secret: secret = current_app.config['SECRET_KEY'] try: payload = jwt.decode(token, secret, algorithms=['HS256']) except jwt.PyJWTError: payload = None return payload if __name__ == '__main__': import time from config.env_path_config import env_path from dotenv import load_dotenv load_dotenv(dotenv_path=env_path, verbose=True, override=True) import os SECRET_KEY = os.getenv('SECRET_KEY') token = generate_jwt({"user_id": 4}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'SK000007'}, time.time() + 6000, SECRET_KEY) print(token) # for i in range(10): # result = verify_jwt(token, 'secret') # print(result) # print(time.time()) # time.sleep(1) #!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/30 @file: jwt_util.py @function: @modify: """ import jwt from flask import current_app def generate_jwt(payload, expiry, secret=None): """ 生成jwt :param payload: dict 载荷 :param expiry: datetime 有效期 :param secret: 密钥 :return: jwt """ _payload = {'exp': expiry} _payload.update(payload) if not secret: secret = current_app.config['SECRET_KEY'] token = jwt.encode(_payload, secret, algorithm='HS256') return token def verify_jwt(token, secret=None): """ 检验jwt :param token: jwt :param secret: 密钥 :return: dict: payload """ if not secret: secret = current_app.config['SECRET_KEY'] try: payload = jwt.decode(token, secret, algorithms=['HS256']) except jwt.PyJWTError: payload = None return payload if __name__ == '__main__': import time from config.env_path_config import env_path from dotenv import load_dotenv load_dotenv(dotenv_path=env_path, verbose=True, override=True) import os SECRET_KEY = os.getenv('SECRET_KEY') token = generate_jwt({"user_id": 10}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'SK000007'}, time.time() + 6000, SECRET_KEY) print(token) # for i in range(10): # result = verify_jwt(token, 'secret') # print(result) # print(time.time()) # time.sleep(1)
\ No newline at end of file \ No newline at end of file
......
#!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/26 @file: middlewares.py @function: @modify: """ import logging from flask import g, request, url_for, current_app, make_response, jsonify from config.wechat_config import platform_config_list from models.models import WxUser, TallymanAccount, AdminAccount from utils.error_code import TOKEN_NOT_VALID_ERROR from utils.my_response import BaseResponse from utils.jwt_util import verify_jwt logger = logging.getLogger(__name__) def log_enter_interface(): """ 日志打印进入接口 :return: """ logger.info("######################### 进入 {} 接口 ################################ ".format(request.path)) def log_out_interface(environ): """ 日志打印退出接口 :return: """ logger.info("######################### 退出 {} 接口 ################################\n".format(request.path)) return environ def close_db_session(environ): from models.base_model import db db.session.close() return environ """用户认证机制==>每次请求前获取并校验token""" "@myapps.before_request 不使@调用装饰器 在 init文件直接装饰" def jwt_authentication(): """ 1.获取请求头Authorization中的token 2.判断是否以 Bearer开头 3.使用jwt模块进行校验 4.判断校验结果,成功就提取token中的载荷信息,赋值给g对象保存 """ path_list = request.path.split("/") if current_app.name == "automat": NO_AUTH_CHECK_URL = [url_for('wx_auth.my_test'), url_for('wx_auth.mini_login'), url_for('rent.wx_pay_callback'), url_for('hatch.get_production_list'), url_for('tallyman.run_tallyman_login'), url_for('machine.run_get_machine_no'), url_for('machine.run_create_machine_no'), url_for('machine.run_bind_serial_num'), url_for('nfc_card.run_nfc_card_wx_pay_callback'), url_for('nfc_card.run_nfc_card_user_pay_record'), url_for('nfc_card.run_nfc_card_load_succeed'), url_for('nfc_card.run_nfc_card_user_load_record'), ] if request.path not in NO_AUTH_CHECK_URL: token = request.headers.get('Authorization') # "校验token" payload = verify_jwt(token) # "判断token的校验结果" if payload: # "获取载荷中的信息赋值给g对象" if request.path.split("/")[2] == "tallyman": user_no = payload.get('user_no') if not user_no: return BaseResponse(**TOKEN_NOT_VALID_ERROR) try: g.user = TallymanAccount.query.filter_by(user_no=user_no).first() if not g.user: return BaseResponse(**TOKEN_NOT_VALID_ERROR) return except Exception as e: print(e) if request.path.split("/")[2] == "machine": user_no = payload.get('user_no', None) user_id = payload.get('user_id', None) if user_no: try: g.user = TallymanAccount.query.filter_by(user_no=user_no).first() if not g.user: return BaseResponse(**TOKEN_NOT_VALID_ERROR) return except Exception as e: print(e) return BaseResponse(**TOKEN_NOT_VALID_ERROR) if user_id: try: g.user = WxUser.query.filter_by(id=user_id).first() if not g.user: return BaseResponse(**TOKEN_NOT_VALID_ERROR) return except Exception as e: print(e) return BaseResponse(**TOKEN_NOT_VALID_ERROR) return BaseResponse(**TOKEN_NOT_VALID_ERROR) user_id = payload.get('user_id') if not user_id: return BaseResponse(**TOKEN_NOT_VALID_ERROR) try: g.user = WxUser.query.filter_by(id=user_id).first() if not g.user: return BaseResponse(**TOKEN_NOT_VALID_ERROR) return except Exception as e: print(e) return BaseResponse(**TOKEN_NOT_VALID_ERROR) else: return BaseResponse(**TOKEN_NOT_VALID_ERROR) elif current_app.name == "pc_management": NO_AUTH_CHECK_URL = [url_for("admin.user_login") ] if request.path.split("/")[2] == "file" and request.path.split("/")[3] == "img": # 图片接口不验证token return if request.path not in NO_AUTH_CHECK_URL: token = request.headers.get('Authorization') # "校验token" payload = verify_jwt(token) # "判断token的校验结果" if payload: # "获取载荷中的信息赋值给g对象" user_id = payload.get('user_id', None) if user_id: g.user = AdminAccount.query.filter_by(id=user_id).first() if g.user: return return BaseResponse(**TOKEN_NOT_VALID_ERROR) else: NO_AUTH_CHECK_URL = [] return def get_platform(): """ :return: """ g.platform = request.headers.get('platform', "sukang24h") def all_options_pass(): """ :return: """ if request.method == "OPTIONS": headers = {'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST', 'Access-Control-Allow-Headers': 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , platform', } return make_response((jsonify({'error_code': 0}), 200, headers)) #!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/26 @file: middlewares.py @function: @modify: """ import logging from flask import g, request, url_for, current_app, make_response, jsonify from config.wechat_config import platform_config_list from models.models import WxUser, TallymanAccount, AdminAccount from utils.error_code import TOKEN_NOT_VALID_ERROR from utils.my_response import BaseResponse from utils.jwt_util import verify_jwt logger = logging.getLogger(__name__) def log_enter_interface(): """ 日志打印进入接口 :return: """ logger.info("######################### 进入 {} 接口 ################################ ".format(request.path)) def log_out_interface(environ): """ 日志打印退出接口 :return: """ logger.info("######################### 退出 {} 接口 ################################\n".format(request.path)) return environ def close_db_session(environ): from models.base_model import db db.session.close() return environ """用户认证机制==>每次请求前获取并校验token""" "@myapps.before_request 不使@调用装饰器 在 init文件直接装饰" def jwt_authentication(): """ 1.获取请求头Authorization中的token 2.判断是否以 Bearer开头 3.使用jwt模块进行校验 4.判断校验结果,成功就提取token中的载荷信息,赋值给g对象保存 """ path_list = request.path.split("/") if current_app.name == "automat": NO_AUTH_CHECK_URL = [url_for('wx_auth.my_test'), url_for('wx_auth.mini_login'), url_for('rent.wx_pay_callback'), url_for('hatch.get_production_list'), url_for('tallyman.run_tallyman_login'), url_for('machine.run_get_machine_no'), url_for('machine.run_create_machine_no'), url_for('machine.run_bind_serial_num'), url_for('nfc_card.run_nfc_card_wx_pay_callback'), url_for('nfc_card.run_nfc_card_user_pay_record'), url_for('nfc_card.run_nfc_card_load_succeed'), url_for('nfc_card.run_nfc_card_user_load_record'), ] if request.path not in NO_AUTH_CHECK_URL: token = request.headers.get('Authorization') # "校验token" payload = verify_jwt(token) # "判断token的校验结果" if payload: # "获取载荷中的信息赋值给g对象" if request.path.split("/")[2] == "tallyman": user_no = payload.get('user_no') if not user_no: return BaseResponse(**TOKEN_NOT_VALID_ERROR) try: g.user = TallymanAccount.query.filter_by(user_no=user_no).first() if not g.user: return BaseResponse(**TOKEN_NOT_VALID_ERROR) return except Exception as e: logger.info(e) if request.path.split("/")[2] == "machine": user_no = payload.get('user_no', None) user_id = payload.get('user_id', None) if user_no: try: g.user = TallymanAccount.query.filter_by(user_no=user_no).first() if not g.user: return BaseResponse(**TOKEN_NOT_VALID_ERROR) return except Exception as e: logger.info(e) return BaseResponse(**TOKEN_NOT_VALID_ERROR) if user_id: try: g.user = WxUser.query.filter_by(id=user_id).first() if not g.user: return BaseResponse(**TOKEN_NOT_VALID_ERROR) return except Exception as e: logger.info(e) return BaseResponse(**TOKEN_NOT_VALID_ERROR) return BaseResponse(**TOKEN_NOT_VALID_ERROR) user_id = payload.get('user_id') if not user_id: return BaseResponse(**TOKEN_NOT_VALID_ERROR) try: g.user = WxUser.query.filter_by(id=user_id).first() if not g.user: return BaseResponse(**TOKEN_NOT_VALID_ERROR) return except Exception as e: logger.info(e) return BaseResponse(**TOKEN_NOT_VALID_ERROR) else: return BaseResponse(**TOKEN_NOT_VALID_ERROR) elif current_app.name == "pc_management": NO_AUTH_CHECK_URL = [url_for("admin.user_login") ] if request.path.split("/")[2] == "file" and request.path.split("/")[3] == "img": # 图片接口不验证token return if request.path not in NO_AUTH_CHECK_URL: token = request.headers.get('Authorization') # "校验token" payload = verify_jwt(token) # "判断token的校验结果" if payload: # "获取载荷中的信息赋值给g对象" user_id = payload.get('user_id', None) if user_id: g.user = AdminAccount.query.filter_by(id=user_id).first() if g.user: return return BaseResponse(**TOKEN_NOT_VALID_ERROR) else: NO_AUTH_CHECK_URL = [] return def get_platform(): """ :return: """ g.platform = request.headers.get('platform', "sukang24h") def all_options_pass(): """ :return: """ if request.method == "OPTIONS": headers = {'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST', 'Access-Control-Allow-Headers': 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , platform', } return make_response((jsonify({'error_code': 0}), 200, headers))
\ No newline at end of file \ No newline at end of file
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
class UpdateParams:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __getattr__(self, item):
print(f"没有该属性:{item}")
return None
def json2obj(json_data):
d = UpdateParams.__new__(UpdateParams)
d.__dict__.update(json_data)
return d
import base64import jsonfrom Crypto.Cipher import AES class WXBizDataCrypt: def __init__(self, appId, sessionKey): self.appId = appId self.sessionKey = sessionKey def decrypt(self, encryptedData, iv): sessionKey = base64.decodebytes(bytes(self.sessionKey, encoding='utf8')) encryptedData = base64.decodebytes(bytes(encryptedData, encoding='utf8')) iv = base64.decodebytes(bytes(iv, encoding='utf8')) cipher = AES.new(sessionKey, AES.MODE_CBC, iv) des_str = cipher.decrypt(encryptedData) print("==================================") print(des_str) des_str = self._unpad(des_str) print(des_str) des_str = str(des_str,encoding='utf-8') decrypted = json.loads(des_str) if decrypted['watermark']['appid'] != self.appId: raise Exception('Invalid Buffer') return decrypted def _unpad(self, s): return s[:-ord(s[len(s) - 1:])] if __name__ == '__main__': appId = 'wx3185fb4a3633beb0' sessionKey='S7CMDfC6jXJKSaWKanG8oQ==' encryptedData='E7LZhvK7mOcaYsv9xcAfsBN9eSbzFh9FyMtFJ0zsFB0M62zRJ0cosZWksUujUR5WYUmNoIfIJnTIF8gRskxxbFU3fm5X7z4ChZecMSaFM65aEK1suRUD1U0ubB7mOwBBlY4ftdPT5kRwWgXKVkM4VAkYGN8A4fjWE93yGtjzxXs9dypQkCLSNWs6Kw5USEzjhtDZnptVy+lHF5fTXRuzoCstW2Cto4YI3G9hmnS64QuWjRteSqIgh8GN1zEPN0dROJjaWBjqraBCt/BfMsk4HBeL4PA75K8WdqVgKGfQ7/rnmPFOsNXWfajx9jl7XcrfoPaaPL1DmIJ1BlQne2GuLFtzZ3O4/8cdVQ9Lb0N/3kFAzjgzNFNLSYj2VNctmWyLdWi8hH90yslvrODIhMzIsuux2GIAfp0rQd/iVIVvtd7PXBOCe5iZ7aaqD0b0mLF4CmsuBpl8Eh20ZHkYw2SqO0x9uFrS/gy1vwtkmsTpcDw=' iv = 'DQcmcXyQkU+VKqb2mKmasQ==' pc = WXBizDataCrypt(appId, sessionKey) pc.decrypt(encryptedData, iv)# import base64import jsonfrom Crypto.Cipher import AES class WXBizDataCrypt: def __init__(self, appId, sessionKey): self.appId = appId self.sessionKey = sessionKey def decrypt(self, encryptedData, iv): sessionKey = base64.decodebytes(bytes(self.sessionKey, encoding='utf8')) encryptedData = base64.decodebytes(bytes(encryptedData, encoding='utf8')) iv = base64.decodebytes(bytes(iv, encoding='utf8')) cipher = AES.new(sessionKey, AES.MODE_CBC, iv) des_str = cipher.decrypt(encryptedData) des_str = self._unpad(des_str) des_str = str(des_str, encoding='utf-8') decrypted = json.loads(des_str) if decrypted['watermark']['appid'] != self.appId: raise Exception('Invalid Buffer') return decrypted def _unpad(self, s): return s[:-ord(s[len(s) - 1:])] if __name__ == '__main__': appId = 'wx3185fb4a3633beb0' sessionKey = 'S7CMDfC6jXJKSaWKanG8oQ==' encryptedData = 'E7LZhvK7mOcaYsv9xcAfsBN9eSbzFh9FyMtFJ0zsFB0M62zRJ0cosZWksUujUR5WYUmNoIfIJnTIF8gRskxxbFU3fm5X7z4ChZecMSaFM65aEK1suRUD1U0ubB7mOwBBlY4ftdPT5kRwWgXKVkM4VAkYGN8A4fjWE93yGtjzxXs9dypQkCLSNWs6Kw5USEzjhtDZnptVy+lHF5fTXRuzoCstW2Cto4YI3G9hmnS64QuWjRteSqIgh8GN1zEPN0dROJjaWBjqraBCt/BfMsk4HBeL4PA75K8WdqVgKGfQ7/rnmPFOsNXWfajx9jl7XcrfoPaaPL1DmIJ1BlQne2GuLFtzZ3O4/8cdVQ9Lb0N/3kFAzjgzNFNLSYj2VNctmWyLdWi8hH90yslvrODIhMzIsuux2GIAfp0rQd/iVIVvtd7PXBOCe5iZ7aaqD0b0mLF4CmsuBpl8Eh20ZHkYw2SqO0x9uFrS/gy1vwtkmsTpcDw=' iv = 'DQcmcXyQkU+VKqb2mKmasQ==' pc = WXBizDataCrypt(appId, sessionKey) pc.decrypt(encryptedData, iv)#
\ No newline at end of file \ No newline at end of file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment