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
1b0fb537
Commit
1b0fb537
authored
Nov 29, 2021
by
yanglei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into yanglei
parents
3db5cabd
1332af34
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
149 additions
and
98 deletions
+149
-98
config/base_config.py
+2
-0
models/models.py
+3
-0
myapps/sukang24h/api/machine_portal.py
+2
-1
myapps/sukang24h/api/nfc_card_portal.py
+92
-29
myapps/sukang24h/api/rent_portal.py
+40
-59
myapps/sukang24h/api/tallyman_portal.py
+5
-4
sukang_app.py
+1
-1
utils/error_code.py
+2
-2
utils/middlewares.py
+2
-2
No files found.
config/base_config.py
View file @
1b0fb537
...
...
@@ -11,3 +11,5 @@ SECRET_KEY = os.getenv('SECRET_KEY')
SQLALCHEMY_DATABASE_URI
=
os
.
getenv
(
"SQLALCHEMY_DATABASE_URI"
)
MONGO_DATABASE_URI
=
os
.
getenv
(
"MONGO_DATABASE_URI"
)
TENCENT_REDIS_URL
=
os
.
getenv
(
"TENCENT_REDIS_URL"
)
NFC_PAY_LOAD_SECRET
=
os
.
getenv
(
"NFC_PAY_LOAD_SECRET"
)
models/models.py
View file @
1b0fb537
...
...
@@ -37,6 +37,8 @@ class Hatch(Base):
production_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'商品id'
)
name
=
Column
(
String
(
100
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'商品名称'
)
title
=
Column
(
String
(
200
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'商品标题'
)
left_count
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
comment
=
'剩余数量'
)
total_count
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
comment
=
'总数'
)
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
=
'总数'
)
...
...
@@ -73,6 +75,7 @@ class Machine(Base):
status
=
Column
(
TINYINT
(
1
),
server_default
=
text
(
"'1'"
),
comment
=
'状态: 1正常-1删除'
)
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"
))
command_time
=
Column
(
INTEGER
(
1
),
nullable
=
False
)
class
MachineProduction
(
Base
):
...
...
myapps/sukang24h/api/machine_portal.py
View file @
1b0fb537
...
...
@@ -88,6 +88,7 @@ def run_get_machine_no():
machine
=
Machine
.
query
.
filter_by
(
qrcode_no
=
qrcode_no
)
.
first
()
if
machine
:
return
BaseResponse
(
data
=
{
"machine_no"
:
machine
.
machine_no
,
"status"
:
machine
.
status
})
return
BaseResponse
(
data
=
{
"machine_no"
:
machine
.
machine_no
,
"status"
:
machine
.
status
,
"mac_no"
:
machine
.
mac
,
"command_time"
:
machine
.
command_time
})
else
:
return
jsonify
(
MACHINE_NOT_EXIST_ERROR
)
myapps/sukang24h/api/nfc_card_portal.py
View file @
1b0fb537
...
...
@@ -12,7 +12,9 @@ import time
from
flask
import
Blueprint
,
request
,
jsonify
,
g
from
sqlalchemy
import
extract
from
sqlalchemy.exc
import
SQLAlchemyError
from
config.base_config
import
NFC_PAY_LOAD_SECRET
from
config.commen_config
import
USER_RENT_PREPAY_ID
from
config.wechat_config
import
platform_appid_config_list
,
pay_config_list
,
NFC_PAY_CALLBCK_URL
from
models.base_model
import
db
...
...
@@ -20,7 +22,7 @@ from models.models import NfcCard, NfcCardPayRecord, NfcCardPayRefund
from
service.rent_service
import
RentService
from
service.wechat_service
import
WeChatPayService
from
utils.error_code
import
NFC_CARD_NOT_EXIST
,
NFC_CARD_ACTIVATED_ERROR
,
WE_MINIAPP_PAY_FAIL
,
NO_RENT_RECORD
,
\
NO_NFC_CARD_ERROR
NO_NFC_CARD_ERROR
,
NFC_PAY_LOAD_SECRET_ERROR
from
utils.my_redis_cache
import
redis_client
from
utils.my_response
import
BaseResponse
...
...
@@ -327,43 +329,104 @@ def run_nfc_card_pay_refund():
return
BaseResponse
()
#查询充值记录
# 查询充值记录
@nfc_card_route.route
(
'/user_pay_record'
,
methods
=
[
'POST'
])
def
run_nfc_card_user_pay_record
():
json_data
=
request
.
get_json
()
secret
=
json_data
[
"secret"
]
card_no
=
json_data
[
"card_no"
]
page
=
json_data
.
get
(
"page"
,
1
)
page_size
=
json_data
.
get
(
"page_size"
,
5
)
if
secret
!=
NFC_PAY_LOAD_SECRET
:
return
jsonify
(
NFC_PAY_LOAD_SECRET_ERROR
)
card_result
=
NfcCard
.
query
.
filter_by
(
card_no
=
card_no
,
status
=
1
)
.
first
()
if
not
card_result
:
return
jsonify
(
NFC_CARD_NOT_EXIST
)
card_result
=
NfcCardPayRecord
.
query
.
filter_by
(
card_no
=
card_no
,
is_pay
=
1
)
.
all
()
result_data
=
[]
for
card
in
card_result
:
record
=
{
"card_no"
:
card
.
card_no
,
"id"
:
card
.
id
,
"pay_money"
:
card
.
pay_money
,
"created_at"
:
card
.
created_at
,
"updated_at"
:
card
.
updated_at
total_count
=
NfcCardPayRecord
.
query
.
filter_by
(
card_no
=
card_no
,
status
=
1
)
.
count
()
if
not
total_count
:
return
BaseResponse
(
data
=
[],
total_count
=
0
,
page
=
page
,
page_size
=
page_size
)
pay_records
=
NfcCardPayRecord
.
query
.
filter_by
(
card_no
=
card_no
,
status
=
1
)
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
.
all
()
result_data
=
[]
for
record
in
pay_records
:
tmp_data
=
{
"card_no"
:
record
.
card_no
,
"record_no"
:
record
.
rent_no
,
"pay_money"
:
record
.
pay_money
,
"pay_time"
:
record
.
created_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
}
result_data
.
append
(
record
)
return
BaseResponse
(
data
=
result_data
)
#充值成功后改变数据库
@nfc_card_route.route
(
'/user_pay_succeed'
,
methods
=
[
'POST'
])
def
run_nfc_card_pay_succeed
():
json_data
=
request
.
get_json
()
for
key
,
val
in
json_data
.
items
():
id
=
json_data
[
key
][
"id"
]
card_no
=
json_data
[
key
][
"card_no"
]
pay_money
=
json_data
[
key
][
"pay_money"
]
card_result
=
NfcCard
.
query
.
filter_by
(
card_no
=
card_no
)
.
first
()
# 查询到卡号
card_record
=
NfcCardPayRecord
.
query
.
filter_by
(
id
=
id
)
.
first
()
#查询到充值记录
card_result
.
money
+=
pay_money
card_record
.
is_pay
=
2
db
.
session
.
add
(
card_record
,
card_record
)
result_data
.
append
(
tmp_data
)
return
BaseResponse
(
data
=
result_data
,
total
=
total_count
,
page
=
page
,
page_size
=
page_size
)
# 充值成功后改变数据库
@nfc_card_route.route
(
'/load_succeed'
,
methods
=
[
'POST'
])
def
run_nfc_card_load_succeed
():
json_data
=
request
.
get_json
()
secret
=
json_data
[
"secret"
]
record_nos
=
json_data
[
"record_nos"
]
card_no
=
json_data
[
"card_no"
]
if
secret
!=
NFC_PAY_LOAD_SECRET
:
return
jsonify
(
NFC_PAY_LOAD_SECRET_ERROR
)
card_result
=
NfcCard
.
query
.
filter_by
(
card_no
=
card_no
)
.
first
()
# 查询到卡号
if
not
card_result
:
return
jsonify
(
NFC_CARD_NOT_EXIST
)
for
record_no
in
record_nos
:
card_record
=
NfcCardPayRecord
.
query
.
filter_by
(
rent_no
=
record_no
,
status
=
1
)
.
first
()
# 查询到充值记录
if
card_record
:
card_result
.
money
+=
card_record
.
pay_money
card_record
.
status
=
2
db
.
session
.
add
(
card_record
)
try
:
db
.
session
.
add
(
card_result
)
db
.
session
.
commit
()
except
SQLAlchemyError
as
e
:
db
.
session
.
rollback
()
return_data
=
{
"card_no"
:
card_result
.
card_no
,
"money"
:
card_result
.
money
}
return
BaseResponse
(
data
=
return_data
)
return
BaseResponse
()
# 查询充值记录
@nfc_card_route.route
(
'/user_load_record'
,
methods
=
[
'POST'
])
def
run_nfc_card_user_load_record
():
json_data
=
request
.
get_json
()
secret
=
json_data
[
"secret"
]
card_no
=
json_data
[
"card_no"
]
page
=
json_data
.
get
(
"page"
,
1
)
page_size
=
json_data
.
get
(
"page_size"
,
5
)
if
secret
!=
NFC_PAY_LOAD_SECRET
:
return
jsonify
(
NFC_PAY_LOAD_SECRET_ERROR
)
card_result
=
NfcCard
.
query
.
filter_by
(
card_no
=
card_no
,
status
=
1
)
.
first
()
if
not
card_result
:
return
jsonify
(
NFC_CARD_NOT_EXIST
)
total_count
=
NfcCardPayRecord
.
query
.
filter_by
(
card_no
=
card_no
,
status
=
2
)
.
count
()
if
not
total_count
:
return
BaseResponse
(
data
=
[],
total_count
=
0
,
page
=
page
,
page_size
=
page_size
)
pay_records
=
NfcCardPayRecord
.
query
.
filter_by
(
card_no
=
card_no
,
status
=
2
)
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
.
all
()
result_data
=
[]
for
record
in
pay_records
:
tmp_data
=
{
"card_no"
:
record
.
card_no
,
"record_no"
:
record
.
rent_no
,
"load_money"
:
record
.
pay_money
,
"load_time"
:
record
.
updated_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
}
result_data
.
append
(
tmp_data
)
return
BaseResponse
(
data
=
result_data
,
total
=
total_count
,
page
=
page
,
page_size
=
page_size
)
myapps/sukang24h/api/rent_portal.py
View file @
1b0fb537
...
...
@@ -44,41 +44,38 @@ def create_rent():
return
jsonify
(
MACHINE_NOT_EXIST_ERROR
)
total_fee
=
0
open_hatchs
=
{}
for
id
,
count
in
productions
.
items
():
count
=
int
(
count
)
id
=
int
(
id
)
# 根据给的仓号去获取商品信息
hatch_list
=
Hatch
.
query
.
filter
(
Hatch
.
machine_no
==
machine_no
,
Hatch
.
production_id
==
id
,
Hatch
.
status
=
=
1
)
.
order_by
(
func
.
random
())
.
all
()
Hatch
.
left_count
>
=
1
)
.
order_by
(
func
.
random
())
.
all
()
if
not
hatch_list
:
return
jsonify
(
HATCH_NOT_EXIST_ERROR
)
if
len
(
hatch_list
)
<
int
(
count
):
left_count
=
count
for
i
in
hatch_list
:
if
i
.
left_count
<=
left_count
:
open_hatchs
[
str
(
i
.
hatch_no
)]
=
i
.
left_count
left_count
=
left_count
-
i
.
left_count
else
:
open_hatchs
[
str
(
i
.
hatch_no
)]
=
left_count
left_count
=
0
if
left_count
<=
0
:
break
if
left_count
>
0
:
return
jsonify
(
HATCH_COUNT_ERROR
)
total_fee
+=
hatch_list
[
0
]
.
price
*
int
(
count
)
# 生成订单编号
rent_no
=
RentService
.
create_order_no
()
open_hatchs
=
[]
for
id
,
count
in
productions
.
items
():
count
=
int
(
count
)
id
=
int
(
id
)
# 根据给的仓号去获取商品信息
hatch_list
=
Hatch
.
query
.
filter
(
Hatch
.
machine_no
==
machine_no
,
Hatch
.
production_id
==
id
,
Hatch
.
status
==
1
)
.
order_by
(
func
.
random
())
.
all
()
if
not
hatch_list
:
return
jsonify
(
HATCH_NOT_EXIST_ERROR
)
if
len
(
hatch_list
)
<
count
:
return
jsonify
(
HATCH_NOT_ALL_EXIST_ERROR
)
hatch_no_list
=
[
x
.
hatch_no
for
x
in
hatch_list
[:
count
]]
open_hatchs
+=
hatch_no_list
# 配置微信订单数据
wechat_service
=
WeChatPayService
(
app_id
=
platform_appid_config_list
[
user
.
platform
],
config_name
=
pay_config_list
[
machine
.
mch_platform
])
# 生成订单编号
rent_no
=
RentService
.
create_order_no
()
pay_data
=
{
'body'
:
'灰兔智能租借押金'
,
# 商品描述
'out_trade_no'
:
rent_no
,
# 商户订单号
...
...
@@ -153,17 +150,6 @@ def wx_pay_callback():
machine
=
Machine
.
query
.
filter_by
(
machine_no
=
machine_no
)
.
first
()
try
:
lock_time
=
0
while
lock_time
<
3
:
# redis 加锁
lock_res
=
redis_client
.
set
(
RENT_SALE_LOCK
+
str
(
machine
.
id
),
datetime
.
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
ex
=
60
,
nx
=
True
)
if
lock_res
:
break
lock_time
+=
1
time
.
sleep
(
1
)
rent
=
Rent
()
rent
.
rent_no
=
rent_no
rent
.
machine_no
=
machine
.
machine_no
...
...
@@ -181,33 +167,30 @@ def wx_pay_callback():
total_fee
=
0
hatchs
=
Hatch
.
query
.
filter
(
Hatch
.
machine_no
==
machine_no
,
Hatch
.
hatch_no
.
in_
(
open_hatchs
),
Hatch
.
status
==
1
)
.
order_by
(
func
.
random
())
.
all
()
hatchs
=
Hatch
.
query
.
filter
(
Hatch
.
machine_no
==
machine_no
,
Hatch
.
hatch_no
.
in_
(
open_hatchs
.
keys
()))
.
order_by
(
func
.
random
())
.
all
()
for
i
in
hatchs
:
if
i
.
status
==
1
:
rent_detail
=
RentDetail
()
rent_detail
.
rent_no
=
rent_no
rent_detail
.
user_id
=
rent
.
user_id
rent_detail
.
machine_no
=
rent
.
machine_no
rent_detail
.
hatch_no
=
i
.
hatch_no
rent_detail
.
production_id
=
i
.
production_id
rent_detail
.
name
=
i
.
name
rent_detail
.
title
=
i
.
title
rent_detail
.
brand_id
=
i
.
brand_id
rent_detail
.
brand_name
=
i
.
brand_name
rent_detail
.
cate_id
=
i
.
cate_id
rent_detail
.
cate_name
=
i
.
cate_name
rent_detail
.
price
=
i
.
price
rent_detail
.
img
=
i
.
img
rent_detail
.
tags
=
i
.
tags
rent_detail
.
content
=
i
.
content
rent_detail
.
summary
=
i
.
summary
i
.
status
=
2
db
.
session
.
add
(
rent_detail
)
db
.
session
.
add
(
i
)
total_fee
+=
i
.
price
rent_detail
=
RentDetail
()
rent_detail
.
rent_no
=
rent_no
rent_detail
.
user_id
=
rent
.
user_id
rent_detail
.
machine_no
=
rent
.
machine_no
rent_detail
.
hatch_no
=
i
.
hatch_no
rent_detail
.
production_id
=
i
.
production_id
rent_detail
.
name
=
i
.
name
rent_detail
.
title
=
i
.
title
rent_detail
.
brand_id
=
i
.
brand_id
rent_detail
.
brand_name
=
i
.
brand_name
rent_detail
.
cate_id
=
i
.
cate_id
rent_detail
.
cate_name
=
i
.
cate_name
rent_detail
.
price
=
i
.
price
*
open_hatchs
[
str
(
i
.
hatch_no
)]
rent_detail
.
img
=
i
.
img
rent_detail
.
tags
=
i
.
tags
rent_detail
.
content
=
i
.
content
rent_detail
.
summary
=
i
.
summary
db
.
session
.
add
(
rent_detail
)
db
.
session
.
add
(
i
)
total_fee
+=
rent_detail
.
price
if
total_fee
!=
int
(
callback_data
[
'total_fee'
]):
return
xmltodict
.
unparse
({
'xml'
:
error_data
},
pretty
=
True
),
header
...
...
@@ -216,10 +199,8 @@ def wx_pay_callback():
db
.
session
.
commit
()
except
Exception
as
e
:
redis_client
.
delete
(
RENT_SALE_LOCK
+
str
(
machine
.
id
))
return
xmltodict
.
unparse
({
'xml'
:
error_data
},
pretty
=
True
),
header
redis_client
.
delete
(
RENT_SALE_LOCK
+
str
(
machine
.
machine_id
))
return
xmltodict
.
unparse
({
'xml'
:
response_data
},
pretty
=
True
),
header
...
...
myapps/sukang24h/api/tallyman_portal.py
View file @
1b0fb537
...
...
@@ -347,15 +347,16 @@ def get_tally_report():
def
run_machine_activate
():
json_data
=
request
.
get_json
()
qrcode_no
=
json_data
[
"qrcode_no"
]
machine_no
=
json_data
[
"machine_no"
]
mac
=
json_data
[
"mac"
]
#
machine_no = json_data["machine_no"]
mac
=
json_data
.
get
(
"mac"
,
None
)
machine
=
Machine
.
query
.
filter_by
(
qrcode_no
=
qrcode_no
)
.
first
()
if
machine
and
machine
.
machine_no
==
qrcode_no
:
if
machine
:
if
machine
.
status
==
1
:
return
jsonify
(
MACHINE_ACTIVATED_ERROR
)
machine
.
status
=
1
machine
.
mac
=
mac
if
mac
:
machine
.
mac
=
mac
db
.
session
.
add
(
machine
)
db
.
session
.
commit
()
return
BaseResponse
()
...
...
sukang_app.py
View file @
1b0fb537
...
...
@@ -13,4 +13,4 @@ app = create_app(os.getenv('RUN_ENV', 'prod'))
logger
.
info
(
"run server"
)
if
__name__
==
'__main__'
:
app
.
run
(
'127.0.0.1'
,
8893
,
debug
=
Tru
e
)
app
.
run
(
'127.0.0.1'
,
8893
,
debug
=
Fals
e
)
utils/error_code.py
View file @
1b0fb537
#!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, 商品数量错误,检查数量" } MACHINE_ACTIVATED_ERROR = { "error_code": '5010', "error_message": "machine activated, 机柜已激活" } ### 订单相关 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 , 卡片已存在" }
\ No newline at end of file
#!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, 商品数量错误,检查数量" } MACHINE_ACTIVATED_ERROR = { "error_code": '5010', "error_message": "machine activated, 机柜已激活" } ### 订单相关 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 , 身份验证失败" }
\ No newline at end of file
...
...
utils/middlewares.py
View file @
1b0fb537
#!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对象保存 """ 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'), url_for('machine.run_get_machine_no'), url_for('nfc_card.run_nfc_card_wx_pay_callback') ] 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) 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
#!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对象保存 """ 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'), url_for('machine.run_get_machine_no'), 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) 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
...
...
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