Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tour_business
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
0
Merge Requests
0
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
魏强
tour_business
Commits
7e837907
Commit
7e837907
authored
Jun 23, 2020
by
Aeolus
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev_aeolus' into test
parents
0753af61
e44c720d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
25 deletions
+156
-25
Controller/RentController.py
+156
-25
No files found.
Controller/RentController.py
View file @
7e837907
...
@@ -9,7 +9,7 @@ from sqlalchemy.exc import SQLAlchemyError
...
@@ -9,7 +9,7 @@ from sqlalchemy.exc import SQLAlchemyError
from
Config.base_config
import
ACTION_PWD
from
Config.base_config
import
ACTION_PWD
from
Libs.ErrorTips
import
BASE_RESPONSE
,
REFUND_NOT_RENT_INFO
,
REFUND_BACK_TIME_ERROR
,
REFUND_NOT_PRODUCTION_INFO
,
\
from
Libs.ErrorTips
import
BASE_RESPONSE
,
REFUND_NOT_RENT_INFO
,
REFUND_BACK_TIME_ERROR
,
REFUND_NOT_PRODUCTION_INFO
,
\
REFUND_MONEY_IS_ZERO
,
ACTION_CODE_ERROR
,
PARAMETER_ERROR
REFUND_MONEY_IS_ZERO
,
ACTION_CODE_ERROR
,
PARAMETER_ERROR
,
MACHINE_NOT_EXIST_ERROR
from
Libs.Helper
import
Helper
from
Libs.Helper
import
Helper
from
Libs.Logger
import
logger
from
Libs.Logger
import
logger
from
Model.Base
import
db
from
Model.Base
import
db
...
@@ -17,6 +17,7 @@ from Model.Customer.CustomerModel import Customer
...
@@ -17,6 +17,7 @@ from Model.Customer.CustomerModel import Customer
from
Model.Machine.MachineModel
import
Machine
from
Model.Machine.MachineModel
import
Machine
from
Model.Power.PowerModel
import
Power
from
Model.Power.PowerModel
import
Power
from
Model.Production.ProductionModel
import
Production
from
Model.Production.ProductionModel
import
Production
from
Model.Rent.FeeMinuteModel
import
FeeMinuteModel
from
Model.Rent.RentModel
import
Rent
from
Model.Rent.RentModel
import
Rent
from
Model.Rent.RentRefundModel
import
RentRefund
from
Model.Rent.RentRefundModel
import
RentRefund
from
Service.IndexService
import
IndexService
from
Service.IndexService
import
IndexService
...
@@ -272,6 +273,71 @@ def rent_search():
...
@@ -272,6 +273,71 @@ def rent_search():
return
jsonify
(
BASE_RESPONSE
(
data
=
info
)
.
to_dict
())
return
jsonify
(
BASE_RESPONSE
(
data
=
info
)
.
to_dict
())
# @route_rent.route('/rent_money_refund', methods=['GET', 'POST'])
# def rent_money_refund():
# json_data = request.get_json()
# action_pwd = json_data['action_pwd'] if 'action_pwd' in json_data else ''
#
# if action_pwd != ACTION_PWD:
# return jsonify(ACTION_CODE_ERROR)
#
# rent_no = json_data['rent_no'] if 'rent_no' in json_data else ''
# hatch_no = json_data['hatch_no'] if 'hatch_no' in json_data else ''
# comment = json_data['comment'] if 'comment' in json_data else ''
#
# if not rent_no or not hatch_no or not comment:
# return jsonify(PARAMETER_ERROR)
#
# rent_info = db.session.query(Production, Rent).join(Rent, Rent.id == Production.rent_id).filter(
# Production.rent_hatch_no == hatch_no, Rent.rent_no == rent_no).first()
#
# if not rent_info:
# return jsonify(REFUND_NOT_PRODUCTION_INFO)
#
# real_total_consume = rent_info.Rent.deposit * rent_info.Rent.number - rent_info.Rent.back_money
# real_single_refund = real_total_consume if real_total_consume < rent_info.Production.total else rent_info.Production.total
#
# rent_refund_no = RentService.create_refund_no()
#
# rent_info.Rent.back_money = rent_info.Rent.deposit * rent_info.Rent.number \
# if rent_info.Rent.back_money + real_single_refund > rent_info.Rent.deposit * rent_info.Rent.number \
# else rent_info.Rent.back_money + real_single_refund
#
# rent_total = rent_info.Rent.total - rent_info.Production.total
# rent_real_total = rent_info.Rent.real_total - real_single_refund
# rent_info.Rent.total = rent_total if rent_total > 0 else 0
# rent_info.Rent.real_total = rent_real_total if rent_real_total > 0 else 0
#
# data = {
# "out_refund_no": rent_refund_no,
# "out_trade_no": rent_info.Rent.rent_no,
# "total_fee": rent_info.Rent.deposit * rent_info.Rent.number,
# "refund_fee": real_single_refund
# }
# result = WeChatService().refund(data)
# if result:
# try:
# rent_refund = RentRefund()
# rent_refund.refund_no = rent_refund_no
# rent_refund.production_id = rent_info.Production.id
# rent_refund.fee = real_single_refund
# rent_refund.comment = comment
# rent_refund.created_at = datetime.datetime.now()
# rent_refund.updated_at = datetime.datetime.now()
#
# rent_info.Production.total = 0
#
# db.session.add(rent_refund)
# db.session.add(rent_info.Rent)
# db.session.add(rent_info.Production)
# db.session.commit()
# except SQLAlchemyError as e:
# db.session.rollback()
# raise e
# return jsonify(BASE_RESPONSE().to_dict())
# else:
# return jsonify(BASE_RESPONSE(error_code=-1, error_message='refund failed').to_dict())
@route_rent.route
(
'/rent_money_refund'
,
methods
=
[
'GET'
,
'POST'
])
@route_rent.route
(
'/rent_money_refund'
,
methods
=
[
'GET'
,
'POST'
])
def
rent_money_refund
():
def
rent_money_refund
():
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
...
@@ -283,8 +349,9 @@ def rent_money_refund():
...
@@ -283,8 +349,9 @@ def rent_money_refund():
rent_no
=
json_data
[
'rent_no'
]
if
'rent_no'
in
json_data
else
''
rent_no
=
json_data
[
'rent_no'
]
if
'rent_no'
in
json_data
else
''
hatch_no
=
json_data
[
'hatch_no'
]
if
'hatch_no'
in
json_data
else
''
hatch_no
=
json_data
[
'hatch_no'
]
if
'hatch_no'
in
json_data
else
''
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
time_price
=
json_data
[
'time_price'
]
if
'time_price'
in
json_data
else
[]
if
not
rent_no
or
not
hatch_no
or
not
comment
:
if
not
rent_no
or
not
hatch_no
or
not
comment
or
not
time_price
:
return
jsonify
(
PARAMETER_ERROR
)
return
jsonify
(
PARAMETER_ERROR
)
rent_info
=
db
.
session
.
query
(
Production
,
Rent
)
.
join
(
Rent
,
Rent
.
id
==
Production
.
rent_id
)
.
filter
(
rent_info
=
db
.
session
.
query
(
Production
,
Rent
)
.
join
(
Rent
,
Rent
.
id
==
Production
.
rent_id
)
.
filter
(
...
@@ -292,43 +359,54 @@ def rent_money_refund():
...
@@ -292,43 +359,54 @@ def rent_money_refund():
if
not
rent_info
:
if
not
rent_info
:
return
jsonify
(
REFUND_NOT_PRODUCTION_INFO
)
return
jsonify
(
REFUND_NOT_PRODUCTION_INFO
)
rent
=
rent_info
.
Rent
production
=
rent_info
.
Production
real_total_consume
=
rent_info
.
Rent
.
deposit
*
rent_info
.
Rent
.
number
-
rent_info
.
Rent
.
back_money
new_total
=
time_price
[
-
1
]
real_single_refund
=
real_total_consume
if
real_total_consume
<
rent_info
.
Production
.
total
else
rent_info
.
Production
.
total
refund_money
=
production
.
total
-
new_total
if
refund_money
<=
0
:
rent_refund_no
=
RentService
.
create_refund_no
()
return
jsonify
(
REFUND_MONEY_IS_ZERO
)
rent_info
.
Rent
.
back_money
=
rent_info
.
Rent
.
deposit
*
rent_info
.
Rent
.
number
\
if
rent_info
.
Rent
.
back_money
+
real_single_refund
>
rent_info
.
Rent
.
deposit
*
rent_info
.
Rent
.
number
\
else
rent_info
.
Rent
.
back_money
+
real_single_refund
rent_total
=
rent_info
.
Rent
.
total
-
rent_info
.
Production
.
total
rent_real_total
=
rent_info
.
Rent
.
real_total
-
real_single_refund
rent_info
.
Rent
.
total
=
rent_total
if
rent_total
>
0
else
0
rent_info
.
Rent
.
real_total
=
rent_real_total
if
rent_real_total
>
0
else
0
# 重新计算订单对应所有讲解器总收入,退款金额
rent_total
=
0
rent_real_total
=
0
productions
=
Production
.
query
.
filter_by
(
rent_id
=
rent
.
id
)
.
all
()
for
tmp
in
productions
:
if
tmp
.
id
==
production
.
id
:
rent_total
+=
new_total
rent_real_total
+=
new_total
else
:
rent_total
+=
tmp
.
total
rent_real_total
+=
tmp
.
total
rent_back_money
=
rent
.
deposit
*
rent
.
number
-
rent_total
# 退款操作
data
=
{
data
=
{
"out_refund_no"
:
rent_refund_no
,
"out_refund_no"
:
RentService
.
create_refund_no
()
,
"out_trade_no"
:
rent_info
.
Rent
.
rent_no
,
"out_trade_no"
:
rent_info
.
Rent
.
rent_no
,
"total_fee"
:
rent_info
.
Rent
.
deposit
*
rent_info
.
Rent
.
number
,
"total_fee"
:
rent_info
.
Rent
.
deposit
*
rent_info
.
Rent
.
number
,
"refund_fee"
:
re
al_single_refund
"refund_fee"
:
re
fund_money
}
}
result
=
WeChatService
()
.
refund
(
data
)
# result = WeChatService().refund(data)
result
=
True
if
result
:
if
result
:
try
:
try
:
rent_refund
=
RentRefund
()
rent_refund
=
RentRefund
()
rent_refund
.
refund_no
=
rent_refund_no
rent_refund
.
refund_no
=
data
[
"out_refund_no"
]
rent_refund
.
production_id
=
rent_info
.
Production
.
id
rent_refund
.
production_id
=
rent_info
.
Production
.
id
rent_refund
.
fee
=
re
al_single_refund
rent_refund
.
fee
=
re
fund_money
rent_refund
.
comment
=
comment
rent_refund
.
comment
=
comment
rent_refund
.
created_at
=
datetime
.
datetime
.
now
()
rent_refund
.
updated_at
=
datetime
.
datetime
.
now
()
rent_info
.
Production
.
total
=
0
rent
.
total
=
rent_total
rent
.
real_total
=
rent_real_total
rent
.
back_money
=
rent_back_money
production
.
total
=
new_total
db
.
session
.
add
(
rent_refund
)
db
.
session
.
add
(
rent_refund
)
db
.
session
.
add
(
rent
_info
.
Rent
)
db
.
session
.
add
(
rent
)
db
.
session
.
add
(
rent_info
.
P
roduction
)
db
.
session
.
add
(
p
roduction
)
db
.
session
.
commit
()
db
.
session
.
commit
()
except
SQLAlchemyError
as
e
:
except
SQLAlchemyError
as
e
:
db
.
session
.
rollback
()
db
.
session
.
rollback
()
...
@@ -528,3 +606,56 @@ def rent_money_liuyuan():
...
@@ -528,3 +606,56 @@ def rent_money_liuyuan():
return
jsonify
(
BASE_RESPONSE
()
.
to_dict
())
return
jsonify
(
BASE_RESPONSE
()
.
to_dict
())
else
:
else
:
return
jsonify
(
BASE_RESPONSE
(
error_code
=-
1
,
error_message
=
'refund failed'
)
.
to_dict
())
return
jsonify
(
BASE_RESPONSE
(
error_code
=-
1
,
error_message
=
'refund failed'
)
.
to_dict
())
@route_rent.route
(
'/machine_price'
,
methods
=
[
'POST'
])
def
get_machine_price
():
json_data
=
request
.
get_json
()
mac_no
=
json_data
.
get
(
"mac_no"
,
None
)
if
not
mac_no
:
return
jsonify
(
PARAMETER_ERROR
)
# 验证机柜是否存在
machine
=
Machine
.
query
.
filter_by
(
mac_no
=
mac_no
)
.
first
()
if
not
machine
:
return
jsonify
(
MACHINE_NOT_EXIST_ERROR
)
data
=
{
"price_type"
:
machine
.
price_type
,
"one_day_price"
:
machine
.
one_day_price
,
"desposit"
:
machine
.
deposit
,
"time_price"
:
[]
}
if
machine
.
price_type
==
1
:
# 免费时间
data
[
"time_price"
]
.
append
([
str
(
0
)
+
'天'
,
0
])
max_days
=
machine
.
deposit
//
machine
.
one_day_price
+
1
i
=
1
while
i
<
max_days
:
data
[
"time_price"
]
.
append
([
str
(
i
)
+
'天'
,
machine
.
one_day_price
*
i
])
i
+=
1
data
[
"time_price"
]
.
append
([
str
(
max_days
)
+
'天'
,
machine
.
deposit
])
elif
machine
.
price_type
==
2
:
data
[
"price_type"
]
=
2
fee_minutes
=
FeeMinuteModel
.
query
.
filter_by
(
machine_id
=
machine
.
id
,
status
=
1
)
.
order_by
(
FeeMinuteModel
.
index
.
asc
())
.
all
()
data
[
"time_price"
]
.
append
([
'0分钟'
,
'0分钟'
,
0
])
max_hours
=
len
(
fee_minutes
)
n
=
0
while
n
<
max_hours
-
1
:
data
[
"time_price"
]
.
append
(
[
str
(
fee_minutes
[
n
]
.
minute
)
+
"分钟"
,
str
(
fee_minutes
[
n
+
1
]
.
minute
)
+
"分钟"
,
fee_minutes
[
n
]
.
price
])
n
+=
1
data
[
"time_price"
]
.
append
(
[
str
(
fee_minutes
[
n
]
.
minute
)
+
"分钟"
,
"1天"
,
fee_minutes
[
n
]
.
price
])
max_days
=
machine
.
deposit
//
machine
.
one_day_price
+
1
i
=
2
while
i
<
max_days
:
data
[
"time_price"
]
.
append
([
str
(
i
)
+
'天'
,
machine
.
one_day_price
*
i
])
i
+=
1
data
[
"time_price"
]
.
append
([
str
(
max_days
)
+
'天'
,
machine
.
deposit
])
else
:
pass
return
jsonify
(
BASE_RESPONSE
(
data
=
data
)
.
to_dict
())
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