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
75818ace
Commit
75818ace
authored
Jan 19, 2022
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6256c4df
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
10 deletions
+128
-10
models/models.py
+29
-6
models_tmp.py
+0
-0
myapps/automat/api/rent_portal.py
+6
-3
myapps/pc_management/api/rent_portal.py
+93
-1
utils/error_code.py
+0
-0
No files found.
models/models.py
View file @
75818ace
...
...
@@ -349,27 +349,50 @@ class RentDetail(Base):
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
,
unique
=
True
)
rent_no
=
Column
(
String
(
40
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'订单编号'
)
user_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
index
=
True
,
comment
=
'用户id'
)
user_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'用户id'
)
machine_no
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'机柜id'
)
hatch_no
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
comment
=
'机柜仓口号'
)
production_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'商品id'
)
total
=
Column
(
INTEGER
(
10
),
server_default
=
text
(
"'0'"
),
comment
=
'实收金额'
)
rent_count
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'0'"
))
refund_total
=
Column
(
INTEGER
(
10
),
server_default
=
text
(
"'0'"
))
refund_count
=
Column
(
INTEGER
(
10
),
server_default
=
text
(
"'0'"
))
is_take
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'0'"
),
comment
=
'是否取货'
)
name
=
Column
(
String
(
100
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'商品名称'
)
business_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
,
server_default
=
text
(
"'0'"
))
status
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'1'"
),
comment
=
'1正常 2删除'
)
production_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'商品id'
)
production_name
=
Column
(
String
(
100
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'商品名称'
)
title
=
Column
(
String
(
200
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'商品标题'
)
brand_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'品牌ID'
)
brand_name
=
Column
(
String
(
100
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'商品名称'
)
production_type_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'分类ID'
)
production_type_name
=
Column
(
String
(
200
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
comment
=
'商品标题'
)
price
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'价格'
)
rent_count
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'数量
'
)
original_price
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
comment
=
'商品原价
'
)
img
=
Column
(
String
(
200
,
'utf8mb4_unicode_ci'
))
tags
=
Column
(
String
(
255
,
'utf8mb4_unicode_ci'
),
comment
=
'商品标签'
)
content
=
Column
(
Text
(
collation
=
'utf8mb4_unicode_ci'
),
comment
=
'商品内容'
)
summary
=
Column
(
Text
(
collation
=
'utf8mb4_unicode_ci'
),
comment
=
'商品描述'
)
status
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'1'"
),
comment
=
'1正常 -1删除'
)
business_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
,
server_default
=
text
(
"'0'"
),
comment
=
"商户号"
)
created_at
=
Column
(
TIMESTAMP
,
server_default
=
text
(
"CURRENT_TIMESTAMP"
))
updated_at
=
Column
(
TIMESTAMP
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
weight
=
Column
(
INTEGER
(
10
),
server_default
=
text
(
"'0'"
),
comment
=
'重量'
)
weight_unit
=
Column
(
String
(
10
,
'utf8mb4_unicode_ci'
),
server_default
=
text
(
"'g'"
),
comment
=
'重量单位'
)
expiration_date
=
Column
(
INTEGER
(
10
),
server_default
=
text
(
"'0'"
),
comment
=
'保质期'
)
expiration_date_unit
=
Column
(
String
(
10
,
'utf8mb4_unicode_ci'
),
server_default
=
text
(
"'月'"
),
comment
=
'保质期单位'
)
is_expiration_date
=
Column
(
TINYINT
(
1
),
server_default
=
text
(
"'0'"
),
comment
=
'是否有保质期'
)
weight_error
=
Column
(
INTEGER
(
10
),
server_default
=
text
(
"'0'"
),
comment
=
'重量误差'
)
class
RentRefund
(
Base
):
__tablename__
=
'rent_refund'
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
user_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
,
index
=
True
,
comment
=
'用户id'
)
refund_no
=
Column
(
String
(
191
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
rent_no
=
Column
(
String
(
191
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
rent_detail_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
)
total
=
Column
(
INTEGER
(
10
),
nullable
=
False
)
comment
=
Column
(
Text
(
collation
=
'utf8mb4_unicode_ci'
))
cause
=
Column
(
String
(
191
,
'utf8mb4_unicode_ci'
))
class
SalePlan
(
Base
):
...
...
models_tmp.py
View file @
75818ace
This diff is collapsed.
Click to expand it.
myapps/automat/api/rent_portal.py
View file @
75818ace
...
...
@@ -93,6 +93,7 @@ def create_rent():
rent
.
user_id
=
g
.
user
.
id
rent
.
place_id
=
machine
.
place_id
rent
.
total
=
total_fee
rent
.
real_total
=
total_fee
rent
.
add_time
=
datetime
.
datetime
.
now
()
rent
.
is_pay
=
1
rent
.
pay_time
=
datetime
.
datetime
.
now
()
...
...
@@ -105,13 +106,14 @@ def create_rent():
rent_detail
.
machine_no
=
rent
.
machine_no
rent_detail
.
hatch_no
=
open_hatch
.
hatch_no
rent_detail
.
production_id
=
open_hatch
.
production_id
rent_detail
.
name
=
open_hatch
.
production_name
rent_detail
.
production_
name
=
open_hatch
.
production_name
rent_detail
.
title
=
open_hatch
.
title
rent_detail
.
brand_id
=
open_hatch
.
brand_id
rent_detail
.
brand_name
=
open_hatch
.
brand_name
rent_detail
.
production_type_id
=
open_hatch
.
production_type_id
rent_detail
.
production_type_name
=
open_hatch
.
production_type_name
rent_detail
.
price
=
0
rent_detail
.
total
=
0
rent_detail
.
rent_count
=
1
rent_detail
.
img
=
open_hatch
.
img
rent_detail
.
tags
=
open_hatch
.
tags
...
...
@@ -260,13 +262,14 @@ def wx_pay_callback():
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
.
production_name
rent_detail
.
production_
name
=
i
.
production_name
rent_detail
.
title
=
i
.
title
rent_detail
.
brand_id
=
i
.
brand_id
rent_detail
.
brand_name
=
i
.
brand_name
rent_detail
.
production_type_id
=
i
.
production_type_id
rent_detail
.
production_type_name
=
i
.
production_type_name
rent_detail
.
price
=
i
.
price
*
open_hatchs
[
str
(
i
.
hatch_no
)]
rent_detail
.
price
=
i
.
price
rent_detail
.
total
=
i
.
price
*
open_hatchs
[
str
(
i
.
hatch_no
)]
rent_detail
.
rent_count
=
open_hatchs
[
str
(
i
.
hatch_no
)]
rent_detail
.
img
=
i
.
img
rent_detail
.
tags
=
i
.
tags
...
...
myapps/pc_management/api/rent_portal.py
View file @
75818ace
...
...
@@ -11,8 +11,15 @@ author:Aeolus
import
logging
from
flask
import
Blueprint
,
g
,
request
,
jsonify
from
sqlalchemy.exc
import
SQLAlchemyError
from
config.wechat_config
import
platform_appid_config_list
,
pay_config_list
from
models.base_model
import
db
from
utils.error_code
import
OPERATE_LEVEL_ERROR
from
models.models
import
Rent
,
RentDetail
,
WxUser
,
Machine
,
RentRefund
from
service.rent_service
import
RentService
from
service.wechat_service
import
WeChatPayService
from
utils.error_code
import
OPERATE_LEVEL_ERROR
,
ACTION_CODE_ERROR
,
REFUND_NOT_PRODUCTION_INFO
,
Param_Invalid_Error
,
\
REFUND_MONEY_IS_ZERO
,
REFUND_MONEY_ERROR
from
utils.my_response
import
BaseResponse
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -181,3 +188,88 @@ def get_rent_detail():
else
:
return
BaseResponse
()
@rent_route.route
(
'/rent_money_refund'
,
methods
=
[
'GET'
,
'POST'
])
def
rent_money_refund_new
():
if
g
.
user
.
level
not
in
(
1
,
2
,
4
):
return
jsonify
(
OPERATE_LEVEL_ERROR
)
json_data
=
request
.
get_json
()
action_pwd
=
json_data
[
'action_pwd'
]
if
'action_pwd'
in
json_data
else
''
rent_no
=
json_data
[
'rent_no'
]
rent_detail_id
=
json_data
[
'rent_detail_id'
]
if
action_pwd
!=
"xxzn666"
:
return
BaseResponse
(
**
ACTION_CODE_ERROR
)
cause
=
json_data
[
'cause'
]
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
rent_info
=
db
.
session
.
query
(
RentDetail
,
Rent
,
WxUser
,
Machine
)
.
join
(
Rent
,
Rent
.
rent_no
==
RentDetail
.
rent_no
)
.
join
(
WxUser
,
WxUser
.
id
==
Rent
.
user_id
)
.
filter
(
RentDetail
.
id
==
rent_detail_id
,
Rent
.
rent_no
==
rent_no
)
.
first
()
if
not
rent_info
:
return
jsonify
(
REFUND_NOT_PRODUCTION_INFO
)
rent
=
rent_info
.
Rent
rent_detail
=
rent_info
.
RentDetail
wx_user
=
rent_info
.
WxUser
refund_count
=
int
(
json_data
[
"refund_count"
])
refund_money
=
refund_count
*
rent_detail
.
price
if
refund_money
<=
0
:
return
jsonify
(
REFUND_MONEY_IS_ZERO
)
if
refund_money
>
rent_detail
.
total
:
# 不能超出金额退款
return
jsonify
(
REFUND_MONEY_ERROR
)
new_total
=
rent_detail
.
total
-
refund_money
# 重新计算订单对应所有讲解器总收入,退款金额
rent_total
=
0
rent_details
=
RentDetail
.
query
.
filter_by
(
rent_no
=
rent
.
rent_no
)
.
all
()
for
tmp
in
rent_details
:
if
tmp
.
id
==
rent_detail
.
id
:
rent_total
+=
new_total
else
:
rent_total
+=
tmp
.
total
# 退款操作
data
=
{
"out_refund_no"
:
RentService
.
create_refund_no
(),
"out_trade_no"
:
rent_info
.
Rent
.
rent_no
,
"total_fee"
:
rent
.
total
,
"refund_fee"
:
refund_money
}
result
=
WeChatPayService
(
app_id
=
platform_appid_config_list
[
wx_user
.
platform
],
config_name
=
pay_config_list
[
rent
.
mch_platform
])
.
do_refund
(
data
)
if
result
:
try
:
rent_refund
=
RentRefund
()
rent_refund
.
user_id
=
g
.
user
.
id
rent_refund
.
refund_no
=
data
[
"out_refund_no"
]
rent_refund
.
rent_no
=
rent
.
rent_no
rent_refund
.
rent_detail_id
=
rent_detail
.
id
rent_refund
.
total
=
refund_money
rent_refund
.
comment
=
comment
rent_refund
.
cause
=
cause
rent
.
real_total
=
rent_total
rent
.
back_money
+=
refund_money
rent_detail
.
total
=
new_total
rent_detail
.
refund_count
+=
refund_count
rent_detail
.
refund_total
+=
refund_money
db
.
session
.
add
(
rent_refund
)
db
.
session
.
add
(
rent
)
db
.
session
.
add
(
rent_detail
)
db
.
session
.
commit
()
except
SQLAlchemyError
as
e
:
db
.
session
.
rollback
()
raise
e
return
BaseResponse
()
else
:
return
BaseResponse
(
error_code
=-
1
,
error_message
=
'refund failed'
)
utils/error_code.py
View file @
75818ace
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