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
86145334
Commit
86145334
authored
Nov 05, 2021
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
0772014e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
12 deletions
+102
-12
models/models.py
+14
-3
myapps/sukang24h/api/__init__.py
+2
-0
myapps/sukang24h/api/nfc_card_portal.py
+76
-9
service/rent_service.py
+10
-0
No files found.
models/models.py
View file @
86145334
...
...
@@ -91,10 +91,9 @@ class NfcCard(Base):
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
card_no
=
Column
(
String
(
40
,
'utf8mb4_unicode_ci'
),
comment
=
'卡片编号'
)
user_name
=
Column
(
String
(
40
,
'utf8mb4_unicode_ci'
),
comment
=
'学生名称'
)
user_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
index
=
True
,
comment
=
'用户id'
)
nick_name
=
Column
(
String
(
40
,
'utf8mb4_unicode_ci'
),
comment
=
'学生名称'
)
phone
=
Column
(
String
(
40
,
'utf8mb4_unicode_ci'
),
index
=
True
,
comment
=
'手机号'
)
language
=
Column
(
String
(
40
,
'utf8mb4_unicode_ci'
),
comment
=
'语种'
)
nick_name
=
Column
(
String
(
40
,
'utf8mb4_unicode_ci'
),
comment
=
'昵称'
)
money
=
Column
(
INTEGER
(
10
),
nullable
=
False
)
mch_platform
=
Column
(
INTEGER
(
11
),
nullable
=
False
,
server_default
=
text
(
"'1'"
),
comment
=
'1咻咻'
)
status
=
Column
(
TINYINT
(
4
),
nullable
=
False
,
comment
=
'状态0停用1正常'
)
...
...
@@ -112,6 +111,7 @@ class NfcCardPayRecord(Base):
user_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
index
=
True
,
comment
=
'用户id'
)
is_pay
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'0'"
),
comment
=
'是否支付'
)
pay_money
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'充值金额'
)
mch_platform
=
Column
(
INTEGER
(
11
),
nullable
=
False
,
server_default
=
text
(
"'1'"
),
comment
=
'1咻咻'
)
prepay_id
=
Column
(
VARCHAR
(
191
),
comment
=
'微信支付prepay_id'
)
refund_no
=
Column
(
VARCHAR
(
191
),
comment
=
'退款单号'
)
status
=
Column
(
TINYINT
(
4
),
nullable
=
False
,
comment
=
'状态-1停用1正常'
)
...
...
@@ -119,6 +119,17 @@ class NfcCardPayRecord(Base):
updated_at
=
Column
(
TIMESTAMP
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
class
NfcCardPayRefund
(
Base
):
__tablename__
=
'nfc_card_pay_refund'
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
refund_no
=
Column
(
String
(
191
,
'utf8mb4_bin'
),
nullable
=
False
)
rent_no
=
Column
(
String
(
191
,
'utf8mb4_bin'
),
nullable
=
False
)
fee
=
Column
(
INTEGER
(
10
),
server_default
=
FetchedValue
(),
nullable
=
False
)
comment
=
Column
(
Text
(
collation
=
'utf8mb4_bin'
))
cause
=
Column
(
String
(
191
,
'utf8mb4_bin'
))
class
Place
(
Base
):
__tablename__
=
'place'
...
...
myapps/sukang24h/api/__init__.py
View file @
86145334
...
...
@@ -12,6 +12,7 @@ from myapps.sukang24h.api.hatch_portal import hatch_route
from
myapps.sukang24h.api.rent_portal
import
rent_route
from
myapps.sukang24h.api.tallyman_portal
import
tallyman_route
from
myapps.sukang24h.api.machine_portal
import
machine_route
from
myapps.sukang24h.api.nfc_card_portal
import
nfc_card_route
def
register_sukang_blueprint
(
app
:
Flask
):
...
...
@@ -21,3 +22,4 @@ def register_sukang_blueprint(app: Flask):
app
.
register_blueprint
(
rent_route
,
url_prefix
=
prefix
+
"/rent"
)
app
.
register_blueprint
(
tallyman_route
,
url_prefix
=
prefix
+
"/tallyman"
)
app
.
register_blueprint
(
machine_route
,
url_prefix
=
prefix
+
"/machine"
)
app
.
register_blueprint
(
nfc_card_route
,
url_prefix
=
prefix
+
"/nfc_card"
)
myapps/sukang24h/api/nfc_card_portal.py
View file @
86145334
...
...
@@ -16,10 +16,10 @@ 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
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
from
utils.error_code
import
NFC_CARD_NOT_EXIST
,
NFC_CARD_ACTIVATED_ERROR
,
WE_MINIAPP_PAY_FAIL
,
NO_RENT_RECORD
from
utils.my_redis_cache
import
redis_client
from
utils.my_response
import
BaseResponse
...
...
@@ -28,7 +28,7 @@ logger = logging.getLogger(__name__)
nfc_card_route
=
Blueprint
(
'nfc_card'
,
__name__
)
@nfc_card_route.route
(
"activate"
)
@nfc_card_route.route
(
"activate"
,
methods
=
[
"POST"
]
)
def
run_nfc_card_activate
():
json_data
=
request
.
get_json
()
card_no
=
json_data
[
"card_no"
]
...
...
@@ -42,14 +42,19 @@ def run_nfc_card_activate():
return
jsonify
(
NFC_CARD_ACTIVATED_ERROR
)
card
.
status
=
1
card
.
user_id
=
g
.
user
.
id
if
user_name
:
card
.
nick_name
=
user_name
if
phone
:
card
.
phone
=
phone
db
.
session
.
add
(
card
)
db
.
session
.
commit
()
return
BaseResponse
()
@nfc_card_route.route
(
"pay"
)
def
run_nfc_card_
activate
():
@nfc_card_route.route
(
"pay"
,
methods
=
[
"POST"
]
)
def
run_nfc_card_
pay
():
json_data
=
request
.
get_json
()
card_no
=
json_data
[
"card_no"
]
money
=
json_data
[
"money"
]
...
...
@@ -135,6 +140,7 @@ def run_nfc_card_wx_pay_callback():
rent
.
user_id
=
user_id
rent
.
pay_money
=
int
(
callback_data
[
"total_fee"
])
rent
.
is_pay
=
1
rent
.
status
=
1
rent
.
mch_platform
=
platform
prepay_id
=
redis_client
.
get
(
USER_RENT_PREPAY_ID
+
str
(
user_id
)
+
rent_no
)
if
prepay_id
:
...
...
@@ -149,6 +155,25 @@ def run_nfc_card_wx_pay_callback():
return
xmltodict
.
unparse
({
'xml'
:
response_data
},
pretty
=
True
),
header
@nfc_card_route.route
(
'/pay_result'
,
methods
=
[
'POST'
])
def
run_nfc_card_pay_result
():
json_data
=
request
.
get_json
()
rent_no
=
json_data
[
"rent_no"
]
rent
=
NfcCardPayRecord
.
query
.
filter_by
(
rent_no
=
rent_no
)
.
first
()
if
not
rent
:
return
jsonify
(
NO_RENT_RECORD
)
tmp_data
=
{}
tmp_data
[
"rent_no"
]
=
rent
.
rent_no
tmp_data
[
"card_no"
]
=
rent
.
card_no
tmp_data
[
"user_id"
]
=
rent
.
user_id
tmp_data
[
"status"
]
=
rent
.
status
tmp_data
[
"pay_money"
]
=
rent
.
pay_money
tmp_data
[
"pay_date"
]
=
rent
.
created_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
return
BaseResponse
(
data
=
tmp_data
)
@nfc_card_route.route
(
'/pay_record'
,
methods
=
[
'POST'
])
def
run_nfc_card_pay_record
():
json_data
=
request
.
get_json
()
...
...
@@ -161,11 +186,16 @@ def run_nfc_card_pay_record():
NfcCardPayRecord
.
user_id
==
g
.
user
.
id
]
if
pay_year
and
pay_month
:
filter_list
.
append
(
extract
(
'year'
,
NfcCardPayRecord
.
create_date
)
==
pay_year
)
filter_list
.
append
(
extract
(
'month'
,
NfcCardPayRecord
.
create_date
)
==
pay_month
)
if
pay_year
:
filter_list
.
append
(
extract
(
'year'
,
NfcCardPayRecord
.
created_at
)
==
pay_year
)
if
pay_month
:
filter_list
.
append
(
extract
(
'month'
,
NfcCardPayRecord
.
created_at
)
==
pay_month
)
order_list
=
[
NfcCardPayRecord
.
created_at
.
desc
()]
total_count
=
NfcCardPayRecord
.
query
.
filter
(
*
filter_list
)
.
count
()
if
not
total_count
:
return
BaseResponse
(
data
=
[],
total
=
total_count
,
page
=
page
,
pageSize
=
page_size
)
rent_list
=
NfcCardPayRecord
.
query
.
filter
(
*
filter_list
)
.
order_by
(
*
order_list
)
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
.
all
()
...
...
@@ -175,8 +205,45 @@ def run_nfc_card_pay_record():
tmp_data
[
"rent_no"
]
=
rent
.
rent_no
tmp_data
[
"card_no"
]
=
rent
.
card_no
tmp_data
[
"user_id"
]
=
rent
.
user_id
tmp_data
[
"status"
]
=
rent
.
status
tmp_data
[
"pay_money"
]
=
rent
.
pay_money
tmp_data
[
"pay_date"
]
=
rent
.
created_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
return_data
.
append
(
tmp_data
)
return
BaseResponse
(
data
=
return_data
)
return
BaseResponse
(
data
=
return_data
,
total
=
total_count
,
page
=
page
,
pageSize
=
page_size
)
@nfc_card_route.route
(
'/pay_refund'
,
methods
=
[
'POST'
])
def
run_nfc_card_pay_refund
():
json_data
=
request
.
get_json
()
rent_no
=
json_data
[
"rent_no"
]
comment
=
json_data
.
get
(
"comment"
,
None
)
cause
=
json_data
.
get
(
"cause"
,
None
)
rent
=
NfcCardPayRecord
.
query
.
filter_by
(
rent_no
=
rent_no
,
status
=
1
)
.
first
()
if
not
rent
:
return
jsonify
(
NO_RENT_RECORD
)
# 退款操作
data
=
{
"out_refund_no"
:
RentService
.
create_refund_no
(),
"out_trade_no"
:
rent
.
rent_no
,
"total_fee"
:
rent
.
pay_money
,
"refund_fee"
:
rent
.
pay_money
}
result
=
WeChatPayService
(
app_id
=
platform_appid_config_list
[
g
.
user
.
platform
],
config_name
=
pay_config_list
[
rent
.
mch_platform
])
.
do_refund
(
data
)
if
result
:
rent_refund
=
NfcCardPayRefund
()
rent_refund
.
refund_no
=
data
[
"out_refund_no"
]
rent_refund
.
rent_no
=
rent_no
rent_refund
.
fee
=
data
[
"refund_fee"
]
rent_refund
.
comment
=
comment
rent_refund
.
cause
=
cause
rent
.
status
=
3
db
.
session
.
add
(
rent_refund
)
db
.
session
.
commit
()
return
BaseResponse
()
service/rent_service.py
View file @
86145334
...
...
@@ -26,6 +26,16 @@ class RentService(object):
return
prefix
+
data_str
+
int_str
@staticmethod
def
create_refund_no
():
'''
生成退款单号
:return:
'''
data_str
=
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y
%
m
%
d
%
H
%
M
%
S'
)
int_str
=
str
(
random
.
randint
(
1
,
999
))
.
zfill
(
6
)
return
'RF'
+
data_str
+
int_str
@staticmethod
def
create_order
(
rent_no
,
data
,
machine
,
platform
,
type
=
1
):
"""
生成订单数据
...
...
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