Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
Automat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冯佳佳
Automat
Commits
33c765f0
Commit
33c765f0
authored
Oct 15, 2021
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
d8c89673
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
158 additions
and
343 deletions
+158
-343
config/commen_config.py
+7
-0
models/models.py
+29
-4
myapps/sukang24h/api/__init__.py
+2
-0
myapps/sukang24h/api/rent_portal.py
+2
-2
myapps/sukang24h/api/tally_portal.py
+0
-22
myapps/sukang24h/api/tallyman_portal.py
+85
-309
service/tallyman_service.py
+26
-0
utils/error_code.py
+2
-2
utils/jwt_util.py
+2
-2
utils/middlewares.py
+2
-2
utils/mytools.py
+1
-0
No files found.
config/commen_config.py
View file @
33c765f0
...
@@ -33,3 +33,10 @@ WX_SESSION_KEY = "W_S_K_"
...
@@ -33,3 +33,10 @@ WX_SESSION_KEY = "W_S_K_"
WX_ACCESS_TOKEN
=
"W_A_T_"
WX_ACCESS_TOKEN
=
"W_A_T_"
# 微信公众号access_token过期时间
# 微信公众号access_token过期时间
WX_ACCESS_TOKEN_EXPIRE
=
"W_A_T_E_"
WX_ACCESS_TOKEN_EXPIRE
=
"W_A_T_E_"
LOGIN_TYPE
=
{
'code_login'
:
1
,
'token_login'
:
2
,
'send_code'
:
3
,
'password'
:
4
}
models/models.py
View file @
33c765f0
# coding: utf-8
# coding: utf-8
from
sqlalchemy
import
Column
,
DateTime
,
Index
,
String
,
TIMESTAMP
,
Text
,
text
from
sqlalchemy
import
Column
,
DateTime
,
Index
,
String
,
TIMESTAMP
,
Text
,
text
,
FetchedValue
from
sqlalchemy.dialects.mysql
import
INTEGER
,
TINYINT
,
VARCHAR
from
sqlalchemy.dialects.mysql
import
INTEGER
,
TINYINT
,
VARCHAR
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
from
models.base_model
import
Base
from
models.base_model
import
Base
...
@@ -213,28 +214,52 @@ class TallymanAccount(Base):
...
@@ -213,28 +214,52 @@ class TallymanAccount(Base):
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:补货员'
)
status
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
comment
=
'1:正常 2:删除'
)
status
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
comment
=
'1:正常 2:删除'
)
password
=
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
)
expire_time
=
Column
(
DateTime
)
expire_time
=
Column
(
DateTime
)
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"
))
@property
def
password
(
self
):
raise
Exception
(
'密码不能被读取'
)
# 为了保持使用习惯,还是设置一个password字段用来设置密码,当然也不能被读取。
# 赋值password,则自动加密存储。
@password.setter
def
password
(
self
,
value
):
self
.
_password_hash_
=
generate_password_hash
(
value
)
# 使用check_password,进行密码校验,返回True False。
def
check_password
(
self
,
pasword
):
return
check_password_hash
(
self
.
_password_hash_
,
pasword
)
class
TallymanMachine
(
Base
):
class
TallymanMachine
(
Base
):
__tablename__
=
'tallyman_machine'
__tablename__
=
'tallyman_machine'
__table_args__
=
(
__table_args__
=
(
Index
(
'index4tallymachine_user_machine_unique'
,
'user_id'
,
'machine_
id
'
,
unique
=
True
),
Index
(
'index4tallymachine_user_machine_unique'
,
'user_id'
,
'machine_
no
'
,
unique
=
True
),
)
)
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
user_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
index
=
True
)
user_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
index
=
True
)
machine_
id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
index
=
True
)
machine_
no
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'机柜id'
)
status
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
index
=
True
,
comment
=
'1:正常 -1:删除'
)
status
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
index
=
True
,
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"
))
class
TallymanLoginRecord
(
Base
):
__tablename__
=
'tallyman_login_record'
id
=
Column
(
INTEGER
,
primary_key
=
True
)
phone
=
Column
(
String
(
255
,
'utf8mb4_bin'
),
nullable
=
False
,
server_default
=
FetchedValue
())
ip
=
Column
(
String
(
255
,
'utf8mb4_bin'
),
nullable
=
False
,
server_default
=
FetchedValue
())
platform
=
Column
(
INTEGER
,
nullable
=
False
,
server_default
=
FetchedValue
(),
comment
=
'平台 2小导游 8商户PC'
)
last_login
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
FetchedValue
())
login_type
=
Column
(
INTEGER
,
nullable
=
False
,
server_default
=
FetchedValue
(),
comment
=
'1:验证码登录 2:token 3:发送验证码 4:密码'
)
class
WxUser
(
Base
):
class
WxUser
(
Base
):
__tablename__
=
'wx_user'
__tablename__
=
'wx_user'
__table_args__
=
{
'comment'
:
'微信用户表'
}
__table_args__
=
{
'comment'
:
'微信用户表'
}
...
...
myapps/sukang24h/api/__init__.py
View file @
33c765f0
...
@@ -10,6 +10,7 @@ from flask import Flask
...
@@ -10,6 +10,7 @@ from flask import Flask
from
myapps.sukang24h.api.wx_auth_portal
import
wx_auth_route
from
myapps.sukang24h.api.wx_auth_portal
import
wx_auth_route
from
myapps.sukang24h.api.hatch_portal
import
hatch_route
from
myapps.sukang24h.api.hatch_portal
import
hatch_route
from
myapps.sukang24h.api.rent_portal
import
rent_route
from
myapps.sukang24h.api.rent_portal
import
rent_route
from
myapps.sukang24h.api.tallyman_portal
import
tallyman_route
def
register_sukang_blueprint
(
app
:
Flask
):
def
register_sukang_blueprint
(
app
:
Flask
):
...
@@ -17,3 +18,4 @@ def register_sukang_blueprint(app: Flask):
...
@@ -17,3 +18,4 @@ def register_sukang_blueprint(app: Flask):
app
.
register_blueprint
(
wx_auth_route
,
url_prefix
=
prefix
+
"/wx_auth"
)
app
.
register_blueprint
(
wx_auth_route
,
url_prefix
=
prefix
+
"/wx_auth"
)
app
.
register_blueprint
(
hatch_route
,
url_prefix
=
prefix
+
"/hatch"
)
app
.
register_blueprint
(
hatch_route
,
url_prefix
=
prefix
+
"/hatch"
)
app
.
register_blueprint
(
rent_route
,
url_prefix
=
prefix
+
"/rent"
)
app
.
register_blueprint
(
rent_route
,
url_prefix
=
prefix
+
"/rent"
)
app
.
register_blueprint
(
tallyman_route
,
url_prefix
=
prefix
+
"/tallyman"
)
myapps/sukang24h/api/rent_portal.py
View file @
33c765f0
...
@@ -22,7 +22,7 @@ from models.models import Machine, Hatch, Rent, WxUser, RentDetail
...
@@ -22,7 +22,7 @@ from models.models import Machine, Hatch, Rent, WxUser, RentDetail
from
service.rent_service
import
RentService
from
service.rent_service
import
RentService
from
service.wechat_service
import
WeChatPayService
from
service.wechat_service
import
WeChatPayService
from
utils.error_code
import
Param_Invalid_Error
,
MACHINE_NOT_EXIST_ERROR
,
HATCH_NOT_EXIST_ERROR
,
\
from
utils.error_code
import
Param_Invalid_Error
,
MACHINE_NOT_EXIST_ERROR
,
HATCH_NOT_EXIST_ERROR
,
\
HATCH_NOT_ALL_EXIST_ERROR
,
WE_MINIAPP_PAY_FAIL
,
NO_RENT_RECORD
HATCH_NOT_ALL_EXIST_ERROR
,
WE_MINIAPP_PAY_FAIL
,
NO_RENT_RECORD
,
HATCH_COUNT_ERROR
from
utils.my_redis_cache
import
redis_client
from
utils.my_redis_cache
import
redis_client
from
utils.my_response
import
BaseResponse
from
utils.my_response
import
BaseResponse
...
@@ -53,7 +53,7 @@ def create_rent():
...
@@ -53,7 +53,7 @@ def create_rent():
return
jsonify
(
HATCH_NOT_EXIST_ERROR
)
return
jsonify
(
HATCH_NOT_EXIST_ERROR
)
if
len
(
hatch_list
)
<
int
(
count
):
if
len
(
hatch_list
)
<
int
(
count
):
return
jsonify
(
HATCH_
NOT_ALL_EXIS
T_ERROR
)
return
jsonify
(
HATCH_
COUN
T_ERROR
)
total_fee
+=
hatch_list
[
0
]
.
price
*
int
(
count
)
total_fee
+=
hatch_list
[
0
]
.
price
*
int
(
count
)
...
...
myapps/sukang24h/api/tally_portal.py
deleted
100644 → 0
View file @
d8c89673
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@file: tally_portal.py
"""
import
logging
from
flask
import
Blueprint
,
request
logger
=
logging
.
getLogger
(
__name__
)
tally_route
=
Blueprint
(
'tally'
,
__name__
)
@tally_route.route
(
"/login"
,
methods
=
[
"POST"
])
def
run_tally_login
():
json_data
=
request
.
get_json
()
user_name
=
json_data
[
"user_name"
]
password
=
json_data
[
"password"
]
myapps/sukang24h/api/tallyman_portal.py
View file @
33c765f0
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
datetime
import
datetime
import
logging
import
logging
import
time
from
flask
import
Blueprint
,
jsonify
,
request
,
g
from
flask
import
Blueprint
,
jsonify
,
request
,
g
from
pymongo
import
MongoClient
from
utils.Helper
import
Helper
from
config.base_config
import
MONGO_DATABASE_URI
from
config.base_config
import
MONGO_DATABASE_URI
from
config.commen_config
import
ACCOUNT_STATUS
,
LOGIN_TYPE
from
config.commen_config
import
LOGIN_TYPE
from
utils.error_code.account_error
import
ACCOUNT_AGENT_SPOT_NULL_ERROR
,
ACCOUNT_NOT_EXISTS_ERROR
,
\
ACCOUNT_ALREADY_EXISTS_ERROR
,
ACCOUNT_ALREADY_DELETE_ERROR
,
AGNET_MODULES_ERROR
from
utils.error_code.auth_error
import
PHONE_NOT_NULL_ERROR
,
PHONE_NOT_VALID_ERROR
,
TOKEN_NOT_VALID_ERROR
,
\
TOKEN_EXPIRE_ERROR
,
VERIFICATION_CODE_INVALID_ERROR
,
VERIFICATION_CODE_ERROR
from
models.base_model
import
db
from
models.base_model
import
db
from
models.models
import
TallymanAccount
from
models.models
import
TallymanAccount
,
TallymanMachine
,
TallymanLoginRecord
from
service.tallyman_service
import
TallymanService
from
utils.error_code
import
TALLYMAN_ACCOUNT_EXIST
,
PHONE_NOT_VALID_ERROR
,
TOKEN_NOT_VALID_ERROR
,
PASSWORD_ERROR
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
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -27,63 +25,22 @@ def test():
...
@@ -27,63 +25,22 @@ def test():
return
BaseResponse
(
**
{
'code'
:
200
,
'msg'
:
'success!'
,
'data'
:
ip
})
return
BaseResponse
(
**
{
'code'
:
200
,
'msg'
:
'success!'
,
'data'
:
ip
})
@tallyman_route.route
(
'/edit_
account
'
,
methods
=
[
'GET'
,
'POST'
])
@tallyman_route.route
(
'/edit_
password
'
,
methods
=
[
'GET'
,
'POST'
])
def
edit_user
():
def
run_tallyman_edit_password
():
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
old_phone
=
json_data
[
'old_phone'
]
if
'old_phone'
in
json_data
else
''
user_name
=
json_data
.
get
(
'name'
,
None
)
new_phone
=
json_data
[
'new_phone'
]
if
'new_phone'
in
json_data
else
''
password
=
json_data
.
get
(
'password'
,
None
)
user_name
=
json_data
[
'name'
]
if
'name'
in
json_data
else
'SSW'
password
=
json_data
[
'password'
]
if
'password'
in
json_data
else
''
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
level
=
json_data
[
'level'
]
if
'level'
in
json_data
else
''
if
not
old_phone
:
return
BaseResponse
(
error_code
=-
1
,
error_message
=
'old phone is null'
)
if
not
new_phone
:
tallyman_info
=
g
.
user
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
result
=
Helper
.
check_phone
(
new_phone
)
if
not
result
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
tallyman_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
old_phone
)
.
first
()
if
not
tallyman_info
:
if
not
tallyman_info
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
tallyman_info
.
user_name
=
user_name
if
user_name
:
tallyman_info
.
phone
=
new_phone
tallyman_info
.
user_name
=
user_name
tallyman_info
.
comment
=
comment
if
level
:
tallyman_info
.
level
=
int
(
level
)
if
password
:
if
password
:
salt
=
AgentService
.
gene_salt
()
tallyman_info
.
password
=
password
agent_info
.
salt_pwd
=
salt
db
.
session
.
add
(
tallyman_info
)
agent_info
.
password
=
AgentService
.
gene_pwd
(
password
,
salt
)
db
.
session
.
add
(
agent_info
)
agent_spot_info
=
AgentSpot
.
query
.
filter_by
(
agent_no
=
agent_info
.
id
)
.
all
()
for
info
in
agent_spot_info
:
info
.
status
=
ACCOUNT_STATUS
[
'delete'
]
db
.
session
.
add
(
info
)
for
i
in
spot_list
:
cur_spot_info
=
AgentSpot
.
query
.
filter_by
(
agent_no
=
agent_info
.
id
,
spot_no
=
i
)
.
first
()
if
not
cur_spot_info
:
cur_agent_spot
=
AgentSpot
()
cur_agent_spot
.
agent_no
=
agent_info
.
id
cur_agent_spot
.
spot_no
=
i
cur_agent_spot
.
status
=
ACCOUNT_STATUS
[
'on_use'
]
cur_agent_spot
.
created_at
=
datetime
.
datetime
.
now
()
cur_agent_spot
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
cur_agent_spot
)
else
:
cur_spot_info
.
status
=
ACCOUNT_STATUS
[
'on_use'
]
db
.
session
.
add
(
cur_spot_info
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
()
...
@@ -97,50 +54,40 @@ def add_user():
...
@@ -97,50 +54,40 @@ def add_user():
password
=
json_data
[
'password'
]
if
'password'
in
json_data
else
None
password
=
json_data
[
'password'
]
if
'password'
in
json_data
else
None
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
agent_no
=
AgentService
.
create_agent_no
()
tallyman
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
if
not
phone
:
if
tallyman
:
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
if
tallyman
.
status
!=
-
1
:
return
jsonify
(
TALLYMAN_ACCOUNT_EXIST
)
result
=
Helper
.
check_phone
(
phone
)
else
:
if
not
result
:
tallyman
=
TallymanAccount
()
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
tallyman
.
user_no
=
"todo"
agent_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
ACCOUNT_STATUS
[
'on_use'
])
.
first
()
tallyman
.
user_name
=
user_name
if
agent_info
:
tallyman
.
phone
=
phone
return
BaseResponse
(
**
ACCOUNT_ALREADY_EXISTS_ERROR
)
tallyman
.
level
=
level
tallyman
.
status
=
1
user_info
=
TallymanAccount
()
tallyman
.
comment
=
comment
user_info
.
agent_no
=
agent_no
tallyman
.
created_at
=
datetime
.
datetime
.
now
()
user_info
.
user_name
=
user_name
tallyman
.
updated_at
=
datetime
.
datetime
.
now
()
user_info
.
phone
=
phone
user_info
.
level
=
level
user_info
.
status
=
ACCOUNT_STATUS
[
'on_use'
]
user_info
.
comment
=
comment
user_info
.
created_at
=
datetime
.
datetime
.
now
()
user_info
.
updated_at
=
datetime
.
datetime
.
now
()
if
password
:
if
password
:
salt
=
AgentService
.
gene_salt
()
tallyman
.
password
=
password
user_info
.
salt_pwd
=
salt
db
.
session
.
add
(
tallyman
)
user_info
.
password
=
AgentService
.
gene_pwd
(
password
,
salt
)
db
.
session
.
commit
()
db
.
session
.
add
(
user_info
)
tallyman
.
user_no
=
"SK"
+
str
(
tallyman
.
id
)
.
zfill
(
6
)
db
.
session
.
add
(
tallyman
)
db
.
session
.
commit
()
db
.
session
.
commit
()
spot_list
=
json_data
[
'spot_list'
]
if
'spot_list'
in
json_data
else
[]
machine_list
=
json_data
.
get
(
"machine_list"
,
[])
if
not
spot_list
:
if
not
machine_list
:
return
BaseResponse
(
**
ACCOUNT_AGENT_SPOT_NULL_ERROR
)
return
BaseResponse
()
cur_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
ACCOUNT_STATUS
[
'on_use'
])
.
first
()
if
not
cur_info
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
for
i
in
spot_list
:
for
i
in
machine_list
:
user_spot
=
AgentSpot
()
model
=
TallymanMachine
()
user_spot
.
agent_no
=
cur_info
.
id
model
.
user_id
=
tallyman
.
id
user_spot
.
spot_no
=
i
model
.
machine_no
=
i
user_spot
.
status
=
ACCOUNT_STATUS
[
'on_use'
]
model
.
status
=
1
user_spot
.
created_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
model
)
user_spot
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
user_spot
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
()
...
@@ -149,237 +96,66 @@ def add_user():
...
@@ -149,237 +96,66 @@ def add_user():
@tallyman_route.route
(
'/delete_account'
,
methods
=
[
'GET'
,
'POST'
])
@tallyman_route.route
(
'/delete_account'
,
methods
=
[
'GET'
,
'POST'
])
def
delete_user
():
def
delete_user
():
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
''
phone
=
json_data
[
'phone'
]
if
not
phone
:
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
agent_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
tallyman
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
if
not
agent_info
:
if
not
tallyman
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
return
BaseResponse
()
agent_spot_info
=
AgentSpot
.
query
.
filter_by
(
agent_no
=
agent_info
.
id
)
.
all
()
agent_spot_info
=
TallymanMachine
.
query
.
filter_by
(
user_id
=
tallyman
.
id
)
.
all
()
for
info
in
agent_spot_info
:
for
info
in
agent_spot_info
:
info
.
status
=
ACCOUNT_STATUS
[
'delete'
]
info
.
status
=
-
1
db
.
session
.
add
(
info
)
db
.
session
.
add
(
info
)
agent_info
.
status
=
ACCOUNT_STATUS
[
'delete'
]
tallyman
.
status
=
-
1
db
.
session
.
add
(
agent_info
)
db
.
session
.
add
(
tallyman
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
()
@tallyman_route.route
(
'/sendCode'
,
methods
=
[
'GET'
,
'POST'
])
@tallyman_route.route
(
'/login'
,
methods
=
[
'GET'
,
'POST'
])
def
send_code
():
def
run_tallyman_login
():
json_data
=
request
.
get_json
()
cur_ip
=
request
.
remote_addr
cur_ip
=
request
.
remote_addr
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
None
json_data
=
request
.
get_json
()
if
not
phone
:
data
=
{}
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
phone
=
json_data
[
'phone'
]
password
=
json_data
[
'password'
]
logger
.
info
(
phone
)
# 密码登录
# 判断该手机号是否再数据库中,不在返回无权限登录
# 判断密码是否正确
agent
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
tallyman
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
1
)
.
first
()
logger
.
info
(
'agent:'
)
if
not
tallyman
:
logger
.
info
(
agent
)
if
not
agent
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
# 判断该账号是否已被删除
if
tallyman
.
check_password
(
password
)
!=
True
:
if
agent
.
status
==
ACCOUNT_STATUS
[
'delete'
]:
return
BaseResponse
(
**
PASSWORD_ERROR
)
return
BaseResponse
(
**
ACCOUNT_ALREADY_DELETE_ERROR
)
result
=
Helper
.
check_phone
(
phone
)
tallyman
.
last_login
=
datetime
.
datetime
.
now
()
if
not
result
:
db
.
session
.
add
(
tallyman
)
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
sms
=
SMSService
()
login_log
=
TallymanLoginRecord
()
result
=
sms
.
phoneSendCode
(
phone
,
520391
,
'灰兔智能'
)
login_log
.
phone
=
tallyman
.
phone
logger
.
info
(
result
)
login_log
.
ip
=
cur_ip
login_log
.
last_login
=
tallyman
.
last_login
agent_log
=
AgentLogRecord
()
login_log
.
login_type
=
LOGIN_TYPE
[
'password'
]
agent_log
.
phone
=
phone
login_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
ip
=
cur_ip
login_log
.
updated_at
=
datetime
.
datetime
.
now
()
agent_log
.
last_login
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
login_log
)
agent_log
.
login_type
=
LOGIN_TYPE
[
'send_code'
]
agent_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_log
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
BaseResponse
()
new_token
=
generate_jwt
(
payload
=
{
"user_no"
:
tallyman
.
user_no
},
expiry
=
time
.
time
()
+
24
*
60
*
60
)
data
[
'token'
]
=
new_token
data
[
'user_name'
]
=
tallyman
.
user_name
data
[
'phone'
]
=
tallyman
.
phone
data
[
'level'
]
=
tallyman
.
level
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
@tallyman_route.route
(
'/login'
,
methods
=
[
'GET'
,
'POST'
])
def
login
():
token
=
request
.
headers
.
get
(
'token'
)
cur_ip
=
request
.
remote_addr
json_data
=
request
.
get_json
()
data
=
{}
@tallyman_route.route
(
'/machine_list'
,
methods
=
[
'GET'
,
'POST'
])
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
None
code
=
json_data
[
'code'
]
if
'code'
in
json_data
else
None
login_type
=
json_data
[
'type'
]
if
'type'
in
json_data
else
1
# 1.验证码登录,2.密码登录
# test
if
phone
==
'18068402080'
and
code
==
'1234'
:
test_agent_info
=
TallymanAccount
.
query
.
filter_by
(
id
=
4
)
.
first
()
g
.
user
=
test_agent_info
data
[
'token'
]
=
test_agent_info
.
access_token
data
[
'user_name'
]
=
test_agent_info
.
user_name
data
[
'phone'
]
=
test_agent_info
.
phone
data
[
'level'
]
=
test_agent_info
.
level
data
[
'spot_info'
]
=
AgentService
.
get_spot_info
(
test_agent_info
)
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
if
token
:
# token登录
user_info
=
AgentService
.
check_agent_token
(
token
)
if
user_info
==
1
:
return
BaseResponse
(
**
TOKEN_NOT_VALID_ERROR
)
if
user_info
==
2
:
return
BaseResponse
(
**
TOKEN_EXPIRE_ERROR
)
# 判断该账号是否已被删除
if
user_info
.
status
==
ACCOUNT_STATUS
[
'delete'
]:
return
BaseResponse
(
**
ACCOUNT_ALREADY_DELETE_ERROR
)
if
user_info
.
phone
in
(
'13913505018'
,
'15952417966'
,
'13912636952'
,
'18051909777'
):
sms
=
SMSService
()
result
=
sms
.
phoneSendCodeWithContent
([
'18913573855'
,
'13912720828'
],
934619
,
[
user_info
.
phone
],
'灰兔智能'
)
logger
.
info
(
result
)
salt
=
AgentService
.
gene_salt
()
new_token
=
"
%
s#
%
s"
%
(
AgentService
.
gene_agent_code
(
user_info
,
salt
),
user_info
.
id
)
user_info
.
access_token
=
new_token
user_info
.
salt
=
salt
user_info
.
last_login
=
datetime
.
datetime
.
now
()
user_info
.
expire_time
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=
1
)
user_info
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
user_info
)
agent_log
=
AgentLogRecord
()
agent_log
.
phone
=
user_info
.
phone
agent_log
.
ip
=
cur_ip
agent_log
.
last_login
=
user_info
.
last_login
agent_log
.
login_type
=
LOGIN_TYPE
[
'token_login'
]
agent_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_log
)
db
.
session
.
commit
()
data
[
'token'
]
=
new_token
data
[
'user_name'
]
=
user_info
.
user_name
data
[
'phone'
]
=
user_info
.
phone
data
[
'level'
]
=
user_info
.
level
data
[
'spot_info'
]
=
AgentService
.
get_spot_info
(
user_info
)
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
else
:
if
login_type
==
1
:
# 验证码登录
# 判断验证码是否正确
sms
=
SMSService
()
res
=
sms
.
verificate
(
phone
,
code
)
if
res
==
-
1
:
return
BaseResponse
(
**
VERIFICATION_CODE_INVALID_ERROR
)
elif
res
==
-
2
:
return
BaseResponse
(
**
VERIFICATION_CODE_ERROR
)
agent_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
ACCOUNT_STATUS
[
'on_use'
])
.
first
()
if
not
agent_info
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
if
agent_info
.
phone
in
(
'13913505018'
,
'15952417966'
,
'13912636952'
,
'18051909777'
):
sms
=
SMSService
()
result
=
sms
.
phoneSendCodeWithContent
([
'18913573855'
,
'13912720828'
],
934619
,
[
agent_info
.
phone
],
'灰兔智能'
)
logger
.
info
(
result
)
salt
=
AgentService
.
gene_salt
()
new_token
=
"
%
s#
%
s"
%
(
AgentService
.
gene_agent_code
(
agent_info
,
salt
),
agent_info
.
id
)
agent_token
=
new_token
agent_info
.
access_token
=
agent_token
agent_info
.
salt
=
salt
agent_info
.
last_login
=
datetime
.
datetime
.
now
()
agent_info
.
expire_time
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=
1
)
agent_info
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_info
)
agent_log
=
AgentLogRecord
()
agent_log
.
phone
=
agent_info
.
phone
agent_log
.
ip
=
cur_ip
agent_log
.
last_login
=
agent_info
.
last_login
agent_log
.
login_type
=
LOGIN_TYPE
[
'code_login'
]
agent_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_log
)
db
.
session
.
commit
()
data
[
'token'
]
=
new_token
data
[
'user_name'
]
=
agent_info
.
user_name
data
[
'phone'
]
=
agent_info
.
phone
data
[
'level'
]
=
agent_info
.
level
data
[
'spot_info'
]
=
AgentService
.
get_spot_info
(
agent_info
)
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
else
:
# 密码登录
# 判断密码是否正确
agent_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
ACCOUNT_STATUS
[
'on_use'
])
.
first
()
if
not
agent_info
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
if
not
agent_info
.
password
:
return
BaseResponse
(
error_code
=-
1
,
error_message
=
'login error'
)
if
agent_info
.
password
!=
AgentService
.
gene_pwd
(
code
,
agent_info
.
salt_pwd
):
return
BaseResponse
(
error_code
=-
1
,
error_message
=
'手机号或密码错误'
)
if
agent_info
.
phone
in
(
'13913505018'
,
'15952417966'
,
'13912636952'
,
'18051909777'
):
sms
=
SMSService
()
result
=
sms
.
phoneSendCodeWithContent
([
'18913573855'
,
'13912720828'
],
934619
,
[
agent_info
.
phone
],
'灰兔智能'
)
logger
.
info
(
result
)
salt
=
AgentService
.
gene_salt
()
new_token
=
"
%
s#
%
s"
%
(
AgentService
.
gene_agent_code
(
agent_info
,
salt
),
agent_info
.
id
)
agent_token
=
new_token
agent_info
.
access_token
=
agent_token
agent_info
.
salt
=
salt
agent_info
.
last_login
=
datetime
.
datetime
.
now
()
agent_info
.
expire_time
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=
1
)
agent_info
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_info
)
agent_log
=
AgentLogRecord
()
agent_log
.
phone
=
agent_info
.
phone
agent_log
.
ip
=
cur_ip
agent_log
.
last_login
=
agent_info
.
last_login
agent_log
.
login_type
=
LOGIN_TYPE
[
'password'
]
agent_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_log
)
db
.
session
.
commit
()
data
[
'token'
]
=
new_token
data
[
'user_name'
]
=
agent_info
.
user_name
data
[
'phone'
]
=
agent_info
.
phone
data
[
'level'
]
=
agent_info
.
level
data
[
'spot_info'
]
=
AgentService
.
get_spot_info
(
agent_info
)
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
@tallyman_route.route
(
'/agent_module_list'
,
methods
=
[
'GET'
,
'POST'
])
def
get_agent_module_list
():
def
get_agent_module_list
():
agent_id
=
g
.
user
.
id
machine_info
=
TallymanService
.
get_machine_info
(
g
.
user
)
platform
=
g
.
platform
mongodatabase
=
MongoClient
(
MONGO_DATABASE_URI
)
.
get_database
(
"suishenwan"
)
return
BaseResponse
(
data
=
machine_info
)
agent_modules
=
mongodatabase
.
get_collection
(
"agent_modules"
)
result
=
agent_modules
.
find_one
({
"agent_id"
:
agent_id
,
"platform"
:
platform
})
if
result
:
return_data
=
{
"agent_id"
:
agent_id
,
"module_list"
:
result
[
"module_list"
]}
return
BaseResponse
(
data
=
return_data
)
else
:
return
BaseResponse
(
**
AGNET_MODULES_ERROR
)
service/tallyman_service.py
0 → 100644
View file @
33c765f0
# -*- coding: utf-8 -*-
import
logging
from
models.models
import
TallymanMachine
,
Machine
,
Hatch
logger
=
logging
.
getLogger
(
__name__
)
class
TallymanService
(
object
):
@classmethod
def
get_machine_info
(
cls
,
tallyman
):
machine_infos
=
Machine
.
query
(
Machine
)
.
join
(
TallymanMachine
,
TallymanMachine
.
machine_no
==
Machine
.
machine_no
)
.
filter
(
user_id
=
tallyman
.
id
,
status
=
1
)
.
all
()
return_data
=
[]
for
tmp_machine
in
machine_infos
:
cur_machine
=
{}
cur_machine
[
'machine_no'
]
=
tmp_machine
.
machine_no
cur_machine
[
'short_address'
]
=
tmp_machine
.
short_address
cur_machine
[
'address'
]
=
tmp_machine
.
address
cur_machine
[
'place_id'
]
=
tmp_machine
.
place_id
cur_machine
[
'empty_number'
]
=
Hatch
.
query
.
filter
(
Hatch
.
machine_no
==
tmp_machine
.
machine_no
,
Hatch
.
status
==
2
)
.
count
()
return_data
.
append
(
cur_machine
)
return
return_data
utils/error_code.py
View file @
33c765f0
#!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": "账号或密码错误" } ## 微信登陆相关 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, 存在已售出商品" } ### 订单相关 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": "退款单号重复" }
#!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": "账号或密码错误" } ## 微信登陆相关 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, 商品数量错误,检查数量" } ### 订单相关 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, 补货员账号已存在" }
\ No newline at end of file
\ No newline at end of file
...
...
utils/jwt_util.py
View file @
33c765f0
#!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": 1}, 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": 1}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'SK000001'}, 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
...
...
utils/middlewares.py
View file @
33c765f0
#!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 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对象保存 """ if current_app.name == "sukang24h": 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'), ] else: NO_AUTH_CHECK_URL = [] 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') if not user_id: return BaseResponse(**TOKEN_NOT_VALID_ERROR) try: g.user = WxUser.query.filter_by(id=user_id).first() return except Exception as e: print(e) else: return BaseResponse(**TOKEN_NOT_VALID_ERROR) 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 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对象保存 """ print(request.path) path_list = request.path.split("/") if current_app.name == "sukang24h": 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'), ] 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) 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) else: return BaseResponse(**TOKEN_NOT_VALID_ERROR) else: NO_AUTH_CHECK_URL = [] 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') if not user_id: return BaseResponse(**TOKEN_NOT_VALID_ERROR) try: g.user = WxUser.query.filter_by(id=user_id).first() return except Exception as e: print(e) else: return BaseResponse(**TOKEN_NOT_VALID_ERROR) 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
...
...
utils/mytools.py
0 → 100644
View file @
33c765f0
# -*- coding: utf-8 -*-
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment