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
af2cd9f4
Commit
af2cd9f4
authored
Nov 18, 2021
by
Aeolus
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/yanglei'
parents
8dd0677d
5002fb13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
168 additions
and
5 deletions
+168
-5
myapps/sukang24h/api/__init__.py
+2
-0
myapps/sukang24h/api/card_edit_portal.py
+114
-0
myapps/sukang24h/api/nfc_card_portal.py
+41
-0
myapps/sukang24h/api/wx_auth_portal.py
+11
-5
utils/error_code.py
+0
-0
No files found.
myapps/sukang24h/api/__init__.py
View file @
af2cd9f4
...
@@ -13,6 +13,7 @@ from myapps.sukang24h.api.rent_portal import rent_route
...
@@ -13,6 +13,7 @@ from myapps.sukang24h.api.rent_portal import rent_route
from
myapps.sukang24h.api.tallyman_portal
import
tallyman_route
from
myapps.sukang24h.api.tallyman_portal
import
tallyman_route
from
myapps.sukang24h.api.machine_portal
import
machine_route
from
myapps.sukang24h.api.machine_portal
import
machine_route
from
myapps.sukang24h.api.nfc_card_portal
import
nfc_card_route
from
myapps.sukang24h.api.nfc_card_portal
import
nfc_card_route
from
myapps.sukang24h.api.card_edit_portal
import
card_edit_route
def
register_sukang_blueprint
(
app
:
Flask
):
def
register_sukang_blueprint
(
app
:
Flask
):
...
@@ -23,3 +24,4 @@ def register_sukang_blueprint(app: Flask):
...
@@ -23,3 +24,4 @@ def register_sukang_blueprint(app: Flask):
app
.
register_blueprint
(
tallyman_route
,
url_prefix
=
prefix
+
"/tallyman"
)
app
.
register_blueprint
(
tallyman_route
,
url_prefix
=
prefix
+
"/tallyman"
)
app
.
register_blueprint
(
machine_route
,
url_prefix
=
prefix
+
"/machine"
)
app
.
register_blueprint
(
machine_route
,
url_prefix
=
prefix
+
"/machine"
)
app
.
register_blueprint
(
nfc_card_route
,
url_prefix
=
prefix
+
"/nfc_card"
)
app
.
register_blueprint
(
nfc_card_route
,
url_prefix
=
prefix
+
"/nfc_card"
)
app
.
register_blueprint
(
card_edit_route
,
url_prefix
=
prefix
+
"/card_edit"
)
myapps/sukang24h/api/card_edit_portal.py
0 → 100644
View file @
af2cd9f4
import
json
import
logging
import
re
import
time
from
flask
import
Blueprint
,
request
,
jsonify
,
g
from
sqlalchemy
import
extract
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
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
from
utils.my_redis_cache
import
redis_client
from
utils.my_response
import
BaseResponse
logger
=
logging
.
getLogger
(
__name__
)
card_edit_route
=
Blueprint
(
'card_edit'
,
__name__
)
#创建蓝图
#增
@card_edit_route.route
(
"add"
,
methods
=
[
"post"
])
def
card_add
():
json_data
=
request
.
get_json
()
card_no
=
json_data
[
"card_no"
]
#如果有重复的卡,则报错
card
=
NfcCard
.
query
.
filter_by
(
card_no
=
card_no
,
status
=
1
)
.
first
()
if
card
:
return
jsonify
(
RE_NFC_CARD_ERROR
)
#账号重复
#先添加 添加一条行的记录
newCard
=
NfcCard
(
card_no
=
card_no
,
status
=
0
,
money
=
0
,
limit_count
=-
1
)
db
.
session
.
add
(
newCard
)
db
.
session
.
commit
()
return
BaseResponse
()
#删
@card_edit_route.route
(
"delete"
,
methods
=
[
"post"
])
def
card_delete
():
json_data
=
request
.
get_json
()
card_no
=
json_data
[
"card_no"
]
card
=
NfcCard
.
query
.
filter_by
(
card_no
=
card_no
,
status
=
1
)
.
first
()
if
not
card
:
return
jsonify
(
NFC_CARD_NOT_EXIST
)
card
.
status
=
-
1
db
.
session
.
add
(
card
)
db
.
session
.
commit
()
return
BaseResponse
()
#查 列出所有用户 根据分页来展示
@card_edit_route.route
(
"users_card"
,
methods
=
[
"post"
])
def
card_users_card
():
json_data
=
request
.
get_json
()
page
=
json_data
[
"page"
]
page_size
=
json_data
[
"pageSize"
]
filter_list
=
[
NfcCard
.
status
.
in_
([
1
])
]
total_count
=
NfcCard
.
query
.
filter
(
*
filter_list
)
.
count
()
if
not
total_count
:
return
BaseResponse
(
data
=
[],
total
=
0
,
page
=
page
,
pageSize
=
page_size
)
cards
=
NfcCard
.
query
.
filter
(
*
filter_list
)
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
.
all
()
#查询
return_data
=
[]
#返回的结果
for
card
in
cards
:
tmp_data
=
{
"card_no"
:
card
.
card_no
,
"nick_name"
:
card
.
nick_name
,
"phone"
:
card
.
phone
,
"money"
:
card
.
money
,
"status"
:
card
.
status
,
}
return_data
.
append
(
tmp_data
)
return
BaseResponse
(
data
=
return_data
,
total
=
total_count
,
page
=
page
,
pageSize
=
page_size
)
#根据卡号查询
@card_edit_route.route
(
"found_user_card"
,
methods
=
[
"post"
])
def
found_users_card
():
json_data
=
request
.
get_json
()
card_no
=
json_data
[
"card_no"
]
filter_list
=
[
NfcCard
.
card_no
==
card_no
,
NfcCard
.
status
.
in_
([
1
])
]
cards
=
NfcCard
.
query
.
filter
(
*
filter_list
)
.
all
()
if
not
cards
:
return
jsonify
(
NO_NFC_CARD_ERROR
)
return_data
=
[]
for
card
in
cards
:
tmp_data
=
{
"card_no"
:
card
.
card_no
,
"nick_name"
:
card
.
nick_name
,
"phone"
:
card
.
phone
,
"money"
:
card
.
money
,
"status"
:
card
.
status
,
}
return_data
.
append
(
tmp_data
)
return
BaseResponse
(
data
=
return_data
)
myapps/sukang24h/api/nfc_card_portal.py
View file @
af2cd9f4
...
@@ -326,3 +326,44 @@ def run_nfc_card_pay_refund():
...
@@ -326,3 +326,44 @@ def run_nfc_card_pay_refund():
db
.
session
.
commit
()
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
()
#查询充值记录
@nfc_card_route.route
(
'/user_pay_record'
,
methods
=
[
'POST'
])
def
run_nfc_card_user_pay_record
():
json_data
=
request
.
get_json
()
card_no
=
json_data
[
"card_no"
]
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
}
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
)
db
.
session
.
commit
()
return
BaseResponse
()
myapps/sukang24h/api/wx_auth_portal.py
View file @
af2cd9f4
...
@@ -31,6 +31,7 @@ wx_auth_route = Blueprint('wx_auth', __name__)
...
@@ -31,6 +31,7 @@ wx_auth_route = Blueprint('wx_auth', __name__)
@wx_auth_route.route
(
'/test'
,
methods
=
[
'POST'
])
@wx_auth_route.route
(
'/test'
,
methods
=
[
'POST'
])
def
my_test
():
def
my_test
():
a
=
{
'error_code'
:
'0'
,
'error_message'
:
'Success'
}
a
=
{
'error_code'
:
'0'
,
'error_message'
:
'Success'
}
return
jsonify
(
a
)
return
jsonify
(
a
)
...
@@ -59,16 +60,20 @@ def mini_login():
...
@@ -59,16 +60,20 @@ def mini_login():
return
jsonify
(
WX_LOGIN_CODE_ERROR
)
return
jsonify
(
WX_LOGIN_CODE_ERROR
)
try
:
try
:
user_info
=
WeChatWxaCrypto
(
user_session
[
"session_key"
],
iv
,
app_id
)
.
decrypt_message
(
encrypted_data
)
user_info
=
WeChatWxaCrypto
(
user_session
[
"session_key"
],
iv
,
app_id
)
.
decrypt_message
(
encrypted_data
)
except
:
except
:
try
:
try
:
session_key
=
redis_client
.
get
(
WX_SESSION_KEY
+
user_session
[
"openid"
])
session_key
=
redis_client
.
get
(
user_info
=
WeChatWxaCrypto
(
session_key
,
iv
,
app_id
)
.
decrypt_message
(
encrypted_data
)
WX_SESSION_KEY
+
user_session
[
"openid"
])
user_info
=
WeChatWxaCrypto
(
session_key
,
iv
,
app_id
)
.
decrypt_message
(
encrypted_data
)
except
:
except
:
return
BaseResponse
(
error_code
=
500
,
error_message
=
'user info decrypt error'
)
return
BaseResponse
(
error_code
=
500
,
error_message
=
'user info decrypt error'
)
is_new_user
=
0
is_new_user
=
0
wx_user_model
=
WxUser
.
query
.
filter_by
(
openid
=
user_session
[
"openid"
])
.
first
()
wx_user_model
=
WxUser
.
query
.
filter_by
(
openid
=
user_session
[
"openid"
])
.
first
()
if
not
wx_user_model
:
if
not
wx_user_model
:
wx_user_model
=
WxUser
()
wx_user_model
=
WxUser
()
wx_user_model
.
status
=
1
wx_user_model
.
status
=
1
...
@@ -88,7 +93,8 @@ def mini_login():
...
@@ -88,7 +93,8 @@ def mini_login():
wx_user_model
.
platform
=
platform_appid_config_list
.
index
(
app_id
)
wx_user_model
.
platform
=
platform_appid_config_list
.
index
(
app_id
)
db
.
session
.
add
(
wx_user_model
)
db
.
session
.
add
(
wx_user_model
)
db
.
session
.
commit
()
db
.
session
.
commit
()
token
=
generate_jwt
(
payload
=
{
"user_id"
:
wx_user_model
.
id
},
expiry
=
time
.
time
()
+
24
*
60
*
60
)
token
=
generate_jwt
(
payload
=
{
"user_id"
:
wx_user_model
.
id
},
expiry
=
time
.
time
()
+
24
*
60
*
60
)
return
jsonify
({
return
jsonify
({
'customer_id'
:
wx_user_model
.
id
,
'customer_id'
:
wx_user_model
.
id
,
'token'
:
token
,
'token'
:
token
,
...
...
utils/error_code.py
View file @
af2cd9f4
This diff is collapsed.
Click to expand it.
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