Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tamp_course_order
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭熊
tamp_course_order
Commits
67c6fe5e
Commit
67c6fe5e
authored
Nov 26, 2020
by
pengxiong@wealthgrow.cn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
迁移课程订单表
parent
cfee2007
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
932 additions
and
105 deletions
+932
-105
errors.py
app/config/errors.py
+3
-1
order.py
app/controller/order.py
+15
-10
account_balance.py
app/model/account_balance.py
+1
-1
curriculum_order.py
app/model/curriculum_order.py
+49
-19
tamp_user_models.py
app/model/tamp_user_models.py
+0
-29
order_service.py
app/service/order_service.py
+90
-35
apple_pay.py
app/utils/apple_pay.py
+5
-4
wx_app_pay.py
app/utils/wxpay/wx_app_pay.py
+5
-6
tamp_course_order.log
logs/tamp_course_order.log
+764
-0
No files found.
app/config/errors.py
View file @
67c6fe5e
...
@@ -13,9 +13,11 @@ class Errors:
...
@@ -13,9 +13,11 @@ class Errors:
TOKEN_INVALID
=
'9001'
TOKEN_INVALID
=
'9001'
USER_ALREADY_EXISTS
=
'9002'
USER_ALREADY_EXISTS
=
'9002'
APPLE_VOCHER_INVALID
=
'9003'
APPLE_VOCHER_INVALID
=
'9003'
TANGPU_BALANCE_NOT_ENOUGH
=
'9004'
MSG
=
{
MSG
=
{
TOKEN_INVALID
:
'TOKEN失效'
,
TOKEN_INVALID
:
'TOKEN失效'
,
USER_ALREADY_EXISTS
:
'用户已经存在'
,
USER_ALREADY_EXISTS
:
'用户已经存在'
,
APPLE_VOCHER_INVALID
:
'苹果证书无效'
APPLE_VOCHER_INVALID
:
'苹果证书无效'
,
TANGPU_BALANCE_NOT_ENOUGH
:
'探普币余额不足'
,
}
}
app/controller/order.py
View file @
67c6fe5e
...
@@ -36,12 +36,13 @@ class TopUpOrder(Resource):
...
@@ -36,12 +36,13 @@ class TopUpOrder(Resource):
"""."""
"""."""
self
.
parser
.
add_argument
(
'amount'
,
type
=
int
,
required
=
True
,
help
=
'订单总额不能为空'
)
self
.
parser
.
add_argument
(
'amount'
,
type
=
int
,
required
=
True
,
help
=
'订单总额不能为空'
)
self
.
parser
.
add_argument
(
'pay_method'
,
type
=
int
,
required
=
True
,
help
=
'支付方式不能为空'
)
self
.
parser
.
add_argument
(
'pay_method'
,
type
=
int
,
required
=
True
,
help
=
'支付方式不能为空'
)
self
.
parser
.
add_argument
(
'receipt_data'
,
type
=
str
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
args
=
self
.
parser
.
parse_args
()
args
[
'user_id'
]
=
request
.
user_id
args
[
'user_id'
]
=
request
.
user_id
args
[
'remote_addr'
]
=
request
.
remote_addr
args
[
'remote_addr'
]
=
request
.
remote_addr
res
=
order_service
.
TopUpOrderService
()
.
create_order
(
args
)
data
=
order_service
.
TopUpOrderService
()
.
create_order
(
args
)
resp
=
make_response
(
res
[
'body'
])
resp
=
request
.
return_success
resp
.
hearders
[
'Content-Type'
]
=
res
[
'header'
][
'Content-Type'
]
resp
[
'attributes'
]
=
data
return
resp
return
resp
def
put
(
self
,
id
):
def
put
(
self
,
id
):
...
@@ -70,15 +71,18 @@ class ConsumeOrder(Resource):
...
@@ -70,15 +71,18 @@ class ConsumeOrder(Resource):
def
post
(
self
):
def
post
(
self
):
"""."""
"""."""
self
.
parser
.
add_argument
(
'
prod
_type'
,
type
=
int
,
required
=
True
,
help
=
'商品类型不能为空'
)
self
.
parser
.
add_argument
(
'
ab_si
_type'
,
type
=
int
,
required
=
True
,
help
=
'商品类型不能为空'
)
self
.
parser
.
add_argument
(
'
prod_
id'
,
type
=
str
,
required
=
True
,
help
=
'商品ID不能为空'
)
self
.
parser
.
add_argument
(
'
ab_pro
id'
,
type
=
str
,
required
=
True
,
help
=
'商品ID不能为空'
)
self
.
parser
.
add_argument
(
'prod_name'
,
type
=
str
,
required
=
True
,
help
=
'商品名称不能为空'
)
self
.
parser
.
add_argument
(
'prod_name'
,
type
=
str
,
required
=
True
,
help
=
'商品名称不能为空'
)
self
.
parser
.
add_argument
(
'prod_quantity'
,
type
=
int
,
required
=
True
,
help
=
'商品数量不能为空'
)
self
.
parser
.
add_argument
(
'ab_pay_mode'
,
type
=
int
,
required
=
True
,
help
=
'支付方式不能为空'
)
self
.
parser
.
add_argument
(
'pay_method'
,
type
=
int
,
required
=
True
,
help
=
'支付方式不能为空'
)
args
=
self
.
parser
.
parse_args
()
args
=
self
.
parser
.
parse_args
()
args
[
'user_id'
]
=
request
.
user_id
args
[
'user_id'
]
=
request
.
user_id
order_service
.
CurriculumOrderService
()
.
create_order
(
args
)
args
[
'env'
]
=
request
.
headers
[
'env'
]
return
request
.
return_success
args
[
'remote_addr'
]
=
request
.
remote_addr
data
=
order_service
.
CurriculumOrderService
()
.
create_order
(
args
)
resp
=
request
.
return_success
resp
[
'attributes'
]
=
data
return
resp
def
put
(
self
,
id
):
def
put
(
self
,
id
):
"""."""
"""."""
...
@@ -159,7 +163,8 @@ class AccountBalance(Resource):
...
@@ -159,7 +163,8 @@ class AccountBalance(Resource):
def
get
(
self
):
def
get
(
self
):
"""."""
"""."""
data
=
order_service
.
getAccountBalance
()
user_id
=
request
.
user_id
data
=
order_service
.
getAccountBalance
(
user_id
)
resp
=
request
.
return_success
resp
=
request
.
return_success
resp
[
'attributes'
]
=
data
resp
[
'attributes'
]
=
data
return
resp
return
resp
...
...
app/model/account_balance.py
View file @
67c6fe5e
...
@@ -17,7 +17,7 @@ class AccountBalance(Base, BaseModel):
...
@@ -17,7 +17,7 @@ class AccountBalance(Base, BaseModel):
"""账户余额表"""
"""账户余额表"""
__tablename__
=
'account_balance'
__tablename__
=
'account_balance'
id
=
Column
(
String
(
64
),
default
=
__tablename__
+
str
(
int
(
time
.
time
()
*
10000
)),
primary_key
=
True
)
id
=
Column
(
String
(
64
),
primary_key
=
True
)
user_id
=
Column
(
String
(
64
),
server_default
=
''
,
comment
=
'用户ID'
)
user_id
=
Column
(
String
(
64
),
server_default
=
''
,
comment
=
'用户ID'
)
android_balance
=
Column
(
Integer
,
server_default
=
text
(
'0'
),
comment
=
'安卓探普贝余额'
)
android_balance
=
Column
(
Integer
,
server_default
=
text
(
'0'
),
comment
=
'安卓探普贝余额'
)
apple_balance
=
Column
(
Integer
,
server_default
=
text
(
'0'
),
comment
=
'苹果探普贝余额'
)
apple_balance
=
Column
(
Integer
,
server_default
=
text
(
'0'
),
comment
=
'苹果探普贝余额'
)
...
...
app/model/curriculum_order.py
View file @
67c6fe5e
...
@@ -6,29 +6,59 @@
...
@@ -6,29 +6,59 @@
# @Email : acepengxiong@163.com
# @Email : acepengxiong@163.com
# @Software : PyCharm
# @Software : PyCharm
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
from
sqlalchemy
import
Column
,
BigInteger
,
Integer
,
String
,
DateTime
,
Float
,
text
from
sqlalchemy
import
Column
,
BigInteger
,
Integer
,
String
,
DateTime
,
Float
,
text
,
BIGINT
from
sqlalchemy.sql
import
func
from
sqlalchemy.sql
import
func
from
app.model.base
import
Base
from
app.model.base
import
Base
from
app.model.base
import
BaseModel
from
app.model.base
import
BaseModel
import
time
import
time
class
CurriculumOrder
(
Base
,
BaseModel
):
# class CurriculumOrder(Base, BaseModel):
"""课程订单表"""
# """课程订单表"""
__tablename__
=
'curriculum_order'
# __tablename__ = 'curriculum_order'
#
# id = Column(String(64), primary_key=True)
# order_no = Column(String(50), comment='订单号')
# transaction_serial_no = Column(String(50), server_default='', comment='交易流水号')
# prod_type = Column(String(200), comment='商品类型1:栏目 3:直播 4:视频 5 音频')
# prod_name = Column(String(200), comment='商品名称')
# prod_id = Column(String(200), comment='商品ID')
# prod_quantity = Column(Integer, server_default=text('1'), comment='数量')
# amount = Column(BigInteger, comment='订单总额')
# user_id = Column(String(100), comment='用户ID')
# order_status = Column(Integer, server_default=text('0'), comment='订单状态:0:未支付,1:已支付,2:已退款')
# pay_method = Column(Integer, server_default=text('1'), comment='支付方式:1:探普贝,2:微信支付,3:支付宝支付,4:苹果支付')
# create_time = Column(DateTime(timezone=True), server_default=func.now(), comment='创建时间')
# pay_time = Column(DateTime(timezone=True), server_default=func.now(), comment='付款时间')
# complete_time = Column(DateTime(timezone=True), server_default=func.now(), comment='完成时间')
# del_flag = Column(Integer, server_default=text('0'), comment='是否删除,0:未删除,1:已删除')
id
=
Column
(
String
(
64
),
primary_key
=
True
)
class
OrderFlow
(
Base
,
BaseModel
):
order_no
=
Column
(
String
(
50
),
comment
=
'订单号'
)
__tablename__
=
'order_flow'
transaction_serial_no
=
Column
(
String
(
50
),
server_default
=
''
,
comment
=
'交易流水号'
)
prod_type
=
Column
(
String
(
200
),
comment
=
'商品类型1:栏目 3:直播 4:视频 5 音频'
)
prod_name
=
Column
(
String
(
200
),
comment
=
'商品名称'
)
prod_id
=
Column
(
String
(
200
),
comment
=
'商品ID'
)
prod_quantity
=
Column
(
Integer
,
server_default
=
text
(
'1'
),
comment
=
'数量'
)
amount
=
Column
(
BigInteger
,
comment
=
'订单总额'
)
user_id
=
Column
(
String
(
100
),
comment
=
'用户ID'
)
order_status
=
Column
(
Integer
,
server_default
=
text
(
'0'
),
comment
=
'订单状态:0:未支付,1:已支付,2:已退款'
)
pay_method
=
Column
(
Integer
,
server_default
=
text
(
'1'
),
comment
=
'支付方式:1:探普贝,2:微信支付,3:支付宝支付,4:苹果支付'
)
create_time
=
Column
(
DateTime
(
timezone
=
True
),
server_default
=
func
.
now
(),
comment
=
'创建时间'
)
pay_time
=
Column
(
DateTime
(
timezone
=
True
),
server_default
=
func
.
now
(),
comment
=
'付款时间'
)
complete_time
=
Column
(
DateTime
(
timezone
=
True
),
server_default
=
func
.
now
(),
comment
=
'完成时间'
)
del_flag
=
Column
(
Integer
,
server_default
=
text
(
'0'
),
comment
=
'是否删除,0:未删除,1:已删除'
)
id
=
Column
(
String
(
64
),
primary_key
=
True
,
server_default
=
text
(
"''"
),
comment
=
'唯一主键'
)
ab_ordernum
=
Column
(
String
(
128
),
comment
=
'订单号'
)
ab_price
=
Column
(
BIGINT
,
comment
=
'产品价格'
)
ab_score
=
Column
(
BIGINT
,
comment
=
'积分'
)
ab_score_deduct
=
Column
(
BIGINT
,
comment
=
'积分抵扣'
)
ab_account_deduct
=
Column
(
BIGINT
,
comment
=
'账户余额抵扣'
)
ab_payment
=
Column
(
BIGINT
,
comment
=
'支付通道付款金额'
)
ab_pay_mode
=
Column
(
String
(
3
),
comment
=
'支付方式 1:H5微信支付 2:优惠购买 3:线下会员,4:探普贝,5:app微信支付,6:支付宝支付,7:苹果支付'
)
ab_total_money
=
Column
(
BIGINT
,
comment
=
'订单总额'
)
ab_type
=
Column
(
String
(
3
),
comment
=
'产品类型'
)
ab_proid
=
Column
(
String
(
64
),
comment
=
'产品ID'
)
ab_pro_siid
=
Column
(
String
(
64
),
comment
=
'产品规格ID'
)
ab_si_type
=
Column
(
String
(
3
),
comment
=
'购买类型 1:栏目 3:直播 4:视频 5 音频'
)
ab_si_name
=
Column
(
String
(
32
),
comment
=
'产品规格规格名称'
)
ab_si_code
=
Column
(
String
(
16
),
comment
=
'产品规格规格编码'
)
ab_si_pattern
=
Column
(
String
(
3
),
comment
=
'产品规格定价模式'
)
ab_status
=
Column
(
String
(
16
),
comment
=
'状态 WAIT:待支付 SUCCESS:支付成功 FAIL:支付失败 CANCEL:取消交易'
)
ab_rights_status
=
Column
(
String
(
3
),
comment
=
'权益分配状态'
)
createtime
=
Column
(
DateTime
,
default
=
func
.
now
(),
comment
=
'创建时间'
)
createby
=
Column
(
String
(
64
),
comment
=
'创建人'
)
pay_time
=
Column
(
DateTime
(
timezone
=
True
),
default
=
func
.
now
(),
comment
=
'付款时间'
)
complete_time
=
Column
(
DateTime
(
timezone
=
True
),
default
=
func
.
now
(),
comment
=
'完成时间'
)
updatetime
=
Column
(
DateTime
,
comment
=
'修改时间'
)
updateby
=
Column
(
String
(
64
),
comment
=
'修改人'
)
deletetag
=
Column
(
String
(
3
),
comment
=
'删除标识'
)
unionid
=
Column
(
String
(
64
),
comment
=
'微信unionid'
)
transaction_serial_no
=
Column
(
String
(
64
),
comment
=
'交易流水号'
)
app/model/tamp_user_models.py
View file @
67c6fe5e
...
@@ -1437,35 +1437,6 @@ class Operation(Base, BaseModel):
...
@@ -1437,35 +1437,6 @@ class Operation(Base, BaseModel):
create_time
=
Column
(
DateTime
,
comment
=
'创建时间'
)
create_time
=
Column
(
DateTime
,
comment
=
'创建时间'
)
class
OrderFlow
(
Base
,
BaseModel
):
__tablename__
=
'order_flow'
id
=
Column
(
String
(
64
),
primary_key
=
True
,
server_default
=
text
(
"''"
),
comment
=
'唯一主键'
)
ab_ordernum
=
Column
(
String
(
128
),
comment
=
'订单号'
)
ab_price
=
Column
(
BIGINT
(
12
),
comment
=
'产品价格'
)
ab_score
=
Column
(
BIGINT
(
12
),
comment
=
'积分'
)
ab_score_deduct
=
Column
(
BIGINT
(
12
),
comment
=
'积分抵扣'
)
ab_account_deduct
=
Column
(
BIGINT
(
12
),
comment
=
'账户余额抵扣'
)
ab_payment
=
Column
(
BIGINT
(
12
),
comment
=
'支付通道付款金额'
)
ab_pay_mode
=
Column
(
String
(
3
),
comment
=
'支付方式'
)
ab_total_money
=
Column
(
BIGINT
(
12
),
comment
=
'订单总额'
)
ab_type
=
Column
(
String
(
3
),
comment
=
'产品类型'
)
ab_proid
=
Column
(
String
(
64
),
comment
=
'产品ID'
)
ab_pro_siid
=
Column
(
String
(
64
),
comment
=
'产品规格ID'
)
ab_si_type
=
Column
(
String
(
3
),
comment
=
'产品规格类型'
)
ab_si_name
=
Column
(
String
(
32
),
comment
=
'产品规格规格名称'
)
ab_si_code
=
Column
(
String
(
16
),
comment
=
'产品规格规格编码'
)
ab_si_pattern
=
Column
(
String
(
3
),
comment
=
'产品规格定价模式'
)
ab_status
=
Column
(
String
(
16
),
comment
=
'状态'
)
ab_rights_status
=
Column
(
String
(
3
),
comment
=
'权益分配状态'
)
createtime
=
Column
(
DateTime
,
comment
=
'创建时间'
)
createby
=
Column
(
String
(
64
),
comment
=
'创建人'
)
updatetime
=
Column
(
DateTime
,
comment
=
'修改时间'
)
updateby
=
Column
(
String
(
64
),
comment
=
'修改人'
)
deletetag
=
Column
(
String
(
3
),
comment
=
'删除标识'
)
unionid
=
Column
(
String
(
64
),
comment
=
'微信unionid'
)
class
Org
(
Base
,
BaseModel
):
class
Org
(
Base
,
BaseModel
):
__tablename__
=
'org'
__tablename__
=
'org'
...
...
app/service/order_service.py
View file @
67c6fe5e
...
@@ -13,7 +13,7 @@ from app.config.errors import Errors
...
@@ -13,7 +13,7 @@ from app.config.errors import Errors
from
app.controller.errorhandler
import
CustomFlaskErr
from
app.controller.errorhandler
import
CustomFlaskErr
from
app.model.account_balance
import
AccountBalance
from
app.model.account_balance
import
AccountBalance
from
app.model.account_topup_order
import
AccountTopupOrder
from
app.model.account_topup_order
import
AccountTopupOrder
from
app.model.curriculum_order
import
CurriculumOrder
from
app.model.curriculum_order
import
OrderFlow
from
app.model.tamp_user_models
import
CurriculumPrice
,
CurriculumColumn
,
CurriculumRes
from
app.model.tamp_user_models
import
CurriculumPrice
,
CurriculumColumn
,
CurriculumRes
from
xml.etree
import
cElementTree
as
etree
from
xml.etree
import
cElementTree
as
etree
...
@@ -40,22 +40,37 @@ class TopUpOrderService:
...
@@ -40,22 +40,37 @@ class TopUpOrderService:
subject
=
'探普币充值'
subject
=
'探普币充值'
out_trade_no
=
args
[
'order_no'
]
out_trade_no
=
args
[
'order_no'
]
notify_path
=
'/tamp_order/micro_shop/topUpOrderNotify'
notify_path
=
'/tamp_order/micro_shop/topUpOrderNotify'
pay_params
=
None
if
args
[
'pay_method'
]
==
2
:
if
args
[
'pay_method'
]
==
2
:
# 微信支付
wx_pay
=
WXPay
(
out_trade_no
,
subject
,
args
[
'amount'
],
args
[
'remote_addr'
],
notify_path
=
notify_path
)
wx_pay
=
WXPay
(
out_trade_no
,
subject
,
args
[
'amount'
],
args
[
'remote_addr'
],
notify_path
=
notify_path
)
wx_pay
.
getReturnParams
()
params
=
wx_pay
.
getReturnParams
()
pay_params
=
params
elif
args
[
'pay_method'
]
==
3
:
elif
args
[
'pay_method'
]
==
3
:
# 支付宝支付
total_amount
=
args
[
'amount'
]
/
100
total_amount
=
args
[
'amount'
]
/
100
res
=
prePay
(
subject
,
out_trade_no
,
total_amount
,
notify_path
=
notify_path
)
res
=
prePay
(
subject
,
out_trade_no
,
total_amount
,
notify_path
=
notify_path
)
pay_params
=
res
elif
args
[
'pay_method'
]
==
4
:
elif
args
[
'pay_method'
]
==
4
:
# 苹果支付
receipt_data
=
args
.
get
(
'receipt_data'
,
''
)
receipt_data
=
args
.
get
(
'receipt_data'
,
''
)
if
not
apple_pay
(
receipt_data
):
if
not
apple_pay
(
receipt_data
):
raise
CustomFlaskErr
(
Errors
.
APPLE_VOCHER_INVALID
)
raise
CustomFlaskErr
(
Errors
.
APPLE_VOCHER_INVALID
)
args
[
'order_status'
]
=
1
args
[
'order_status'
]
=
1
if
not
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
args
[
'user_id'
])
.
all
():
tamp_pay_session
.
add
(
AccountBalance
(
id
=
AccountBalance
.
__tablename__
+
str
(
int
(
time
.
time
()
*
100000
)),
user_id
=
args
[
'user_id'
],
apple_balance
=
args
[
'amount'
]))
else
:
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
args
[
'user_id'
])
.
update
({
'apple_balance'
:
AccountBalance
.
apple_balance
+
args
[
'amount'
]
})
args
.
pop
(
'remote_addr'
,
''
)
args
.
pop
(
'receipt_data'
,
''
)
order_info
=
AccountTopupOrder
(
**
args
)
order_info
=
AccountTopupOrder
(
**
args
)
tamp_pay_session
.
add
(
order_info
)
tamp_pay_session
.
add
(
order_info
)
tamp_pay_session
.
commit
()
tamp_pay_session
.
commit
()
tamp_pay_session
.
close
()
tamp_pay_session
.
close
()
return
True
return
pay_params
class
CurriculumOrderService
:
class
CurriculumOrderService
:
...
@@ -67,27 +82,76 @@ class CurriculumOrderService:
...
@@ -67,27 +82,76 @@ class CurriculumOrderService:
"""."""
"""."""
curriculum_column
=
tamp_user_session
.
query
(
CurriculumColumn
)
.
all
()
curriculum_column
=
tamp_user_session
.
query
(
CurriculumColumn
)
.
all
()
curriculum_res
=
tamp_user_session
.
query
(
CurriculumRes
)
.
all
()
curriculum_res
=
tamp_user_session
.
query
(
CurriculumRes
)
.
all
()
res
=
tamp_
pay_session
.
query
(
CurriculumOrder
)
.
filter
(
CurriculumOrder
.
user_id
==
user_id
)
.
all
()
res
=
tamp_
user_session
.
query
(
OrderFlow
)
.
filter
(
OrderFlow
.
createby
==
user_id
)
.
all
()
curriculum_column
=
{
r
.
id
:
r
.
to_dict
()
for
r
in
curriculum_column
}
curriculum_column
=
{
r
.
id
:
r
.
to_dict
()
for
r
in
curriculum_column
}
curriculum_res
=
{
r
.
id
:
r
.
to_dict
()
for
r
in
curriculum_res
}
curriculum_res
=
{
r
.
id
:
r
.
to_dict
()
for
r
in
curriculum_res
}
orders
=
[
r
.
to_dict
()
for
r
in
res
]
orders
=
[
r
.
to_dict
()
for
r
in
res
]
for
order
in
orders
:
for
order
in
orders
:
if
order
[
'prod_type'
]
==
'1'
:
prod_type
=
order
.
get
(
'ab_si_type'
,
''
)
order
[
'prod_info'
]
=
curriculum_column
.
get
(
order
[
'prod_id'
],
None
)
prod_id
=
order
.
get
(
'ab_proid'
,
''
)
elif
order
[
'prod_type'
]
in
[
'3'
,
'4'
,
'5'
]:
if
prod_type
==
'1'
:
order
[
'prod_info'
]
=
curriculum_res
.
get
(
order
[
'prod_id'
],
None
)
order
[
'prod_info'
]
=
curriculum_column
.
get
(
prod_id
,
None
)
elif
prod_type
in
[
'3'
,
'4'
,
'5'
]:
order
[
'prod_info'
]
=
curriculum_res
.
get
(
prod_id
,
None
)
return
orders
return
orders
def
create_order
(
self
,
args
):
def
create_order
(
self
,
args
):
args
[
'order_no'
]
=
time
.
strftime
(
'
%
Y
%
m
%
d'
,
time
.
localtime
(
time
.
time
()))
+
str
(
int
(
time
.
time
()
*
100000
))
"""。"""
amount
=
tamp_user_session
.
query
(
CurriculumPrice
.
price
)
.
filter
(
CurriculumPrice
.
rel_id
==
args
[
'prod_id'
])
.
first
()[
0
]
args
[
'ab_ordernum'
]
=
time
.
strftime
(
'
%
Y
%
m
%
d'
,
time
.
localtime
(
time
.
time
()))
+
str
(
int
(
time
.
time
()
*
100000
))
args
[
'id'
]
=
CurriculumOrder
.
__tablename__
+
str
(
int
(
time
.
time
()
*
100000
))
amount
=
tamp_user_session
.
query
(
CurriculumPrice
.
price
)
.
filter
(
CurriculumPrice
.
rel_id
==
args
[
'ab_proid'
])
.
first
()[
0
]
args
[
'amount'
]
=
amount
*
args
[
'prod_quantity'
]
args
[
'id'
]
=
OrderFlow
.
__tablename__
+
str
(
int
(
time
.
time
()
*
100000
))
order_info
=
CurriculumOrder
(
**
args
)
args
[
'ab_payment'
]
=
amount
*
100
tamp_pay_session
.
add
(
order_info
)
args
[
'ab_status'
]
=
'WAIT'
subject
=
args
.
get
(
'prod_name'
,
''
)
out_trade_no
=
args
[
'ab_ordernum'
]
notify_path
=
'/tamp_order/micro_shop/topUpOrderNotify'
pay_params
=
None
if
args
[
'ab_pay_mode'
]
==
4
:
# 探普币支付
if
args
[
'env'
]
==
'ios'
:
res
=
tamp_pay_session
.
query
(
AccountBalance
.
apple_balance
)
.
filter
(
AccountBalance
.
user_id
==
args
[
'user_id'
])
.
first
()
if
not
res
:
raise
CustomFlaskErr
(
Errors
.
TANGPU_BALANCE_NOT_ENOUGH
)
elif
res
[
0
]
<
args
[
'ab_payment'
]:
raise
CustomFlaskErr
(
Errors
.
TANGPU_BALANCE_NOT_ENOUGH
)
else
:
tamp_pay_session
.
query
(
AccountBalance
.
apple_balance
)
.
filter
(
AccountBalance
.
user_id
==
args
[
'user_id'
])
.
update
({
'apple_balance'
:
AccountBalance
.
apple_balance
-
args
[
'ab_payment'
]
})
args
[
'ab_status'
]
=
'SUCCESS'
elif
args
[
'env'
]
==
'android'
:
res
=
tamp_pay_session
.
query
(
AccountBalance
.
android_balance
)
.
filter
(
AccountBalance
.
user_id
==
args
[
'user_id'
])
.
first
()
if
not
res
:
raise
CustomFlaskErr
(
Errors
.
TANGPU_BALANCE_NOT_ENOUGH
)
elif
res
[
0
]
<
args
[
'ab_payment'
]:
raise
CustomFlaskErr
(
Errors
.
TANGPU_BALANCE_NOT_ENOUGH
)
else
:
tamp_pay_session
.
query
(
AccountBalance
.
android_balance
)
.
filter
(
AccountBalance
.
user_id
==
args
[
'user_id'
])
.
update
({
'android_balance'
:
AccountBalance
.
android_balance
-
args
[
'ab_payment'
]
})
args
[
'ab_status'
]
=
'SUCCESS'
elif
args
[
'ab_pay_mode'
]
==
5
:
# 微信支付
wx_pay
=
WXPay
(
out_trade_no
,
subject
,
args
[
'ab_payment'
],
args
[
'remote_addr'
],
notify_path
=
notify_path
)
params
=
wx_pay
.
getReturnParams
()
pay_params
=
params
elif
args
[
'ab_pay_mode'
]
==
6
:
# 支付宝支付
total_amount
=
args
[
'ab_payment'
]
/
100
res
=
prePay
(
subject
,
out_trade_no
,
total_amount
,
notify_path
=
notify_path
)
pay_params
=
res
args
[
'createby'
]
=
args
.
pop
(
'user_id'
,
''
)
args
.
pop
(
'prod_name'
,
''
)
args
.
pop
(
'env'
,
''
)
args
.
pop
(
'remote_addr'
,
''
)
order_info
=
OrderFlow
(
**
args
)
tamp_user_session
.
add
(
order_info
)
tamp_user_session
.
commit
()
tamp_pay_session
.
commit
()
tamp_pay_session
.
commit
()
return
True
return
pay_params
def
topUpSuccessAction
(
order_no
):
def
topUpSuccessAction
(
order_no
):
...
@@ -100,35 +164,26 @@ def topUpSuccessAction(order_no):
...
@@ -100,35 +164,26 @@ def topUpSuccessAction(order_no):
'order_status'
:
1
'order_status'
:
1
})
})
# 账户充值
# 账户充值
account_topup_order
=
tamp_pay_session
.
query
(
AccountTopupOrder
)
.
filter
(
AccountTopupOrder
.
order_no
==
order_no
)
.
first
()
account_topup_order
=
tamp_pay_session
.
query
(
AccountTopupOrder
)
.
filter
(
AccountTopupOrder
.
order_no
==
order_no
)
.
first
()
.
to_dict
()
if
account_topup_order
.
pay_method
==
4
:
# 安卓支付宝,微信支付
# 苹果支付
if
not
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
all
():
if
not
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
all
():
tamp_pay_session
.
add
(
AccountBalance
(
id
=
AccountBalance
.
__tablename__
+
str
(
int
(
time
.
time
()
*
10000
)),
user_id
=
account_topup_order
.
user_id
,
android_balance
=
account_topup_order
.
amount
))
tamp_pay_session
.
add
(
AccountBalance
(
apple_balance
=
account_topup_order
.
amount
))
else
:
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
update
({
'apple_balance'
:
AccountBalance
.
apple_balance
+
account_topup_order
.
amount
})
else
:
else
:
# 支付宝,微信支付
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
update
({
if
not
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
all
():
'apple_balance'
:
AccountBalance
.
android_balance
+
account_topup_order
.
amount
tamp_pay_session
.
add
(
AccountBalance
(
android_balance
=
account_topup_order
.
amount
))
})
else
:
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
update
({
'apple_balance'
:
AccountBalance
.
android_balance
+
account_topup_order
.
amount
})
tamp_pay_session
.
commit
()
tamp_pay_session
.
commit
()
def
consumeSucessAction
(
order_no
):
def
consumeSucessAction
(
order_no
):
"""."""
"""."""
curriculum_order
=
tamp_pay_session
.
query
(
CurriculumOrder
.
order_no
==
order_no
)
.
all
()
curriculum_order
=
tamp_pay_session
.
query
(
OrderFlow
.
ab_ordernum
==
order_no
)
.
all
()
# 幂等校验
# 幂等校验
if
curriculum_order
.
order_status
==
1
:
if
curriculum_order
.
ab_status
==
'SUCCESS'
:
return
False
return
False
tamp_pay_session
.
query
(
CurriculumOrder
)
.
filter
(
CurriculumOrder
.
order_no
==
order_no
)
.
update
({
tamp_pay_session
.
query
(
OrderFlow
)
.
filter
(
OrderFlow
.
ab_ordernum
==
order_no
)
.
update
({
'
order_status'
:
1
'
ab_status'
:
'SUCCESS'
})
})
tamp_pay_session
.
commit
()
tamp_pay_session
.
commit
()
...
...
app/utils/apple_pay.py
View file @
67c6fe5e
...
@@ -24,9 +24,9 @@ def apple_pay(receipt_data):
...
@@ -24,9 +24,9 @@ def apple_pay(receipt_data):
"exclude-old-transactions":"true",
"exclude-old-transactions":"true",
"password":"a1cdf6f00d3244aa9aa2c1c4a65b7ccf"
"password":"a1cdf6f00d3244aa9aa2c1c4a65b7ccf"
'''
'''
if
not
receipt_data
:
return
False
receipt_data
=
urllib
.
request
.
unquote
(
receipt_data
)
receipt_data
=
urllib
.
request
.
unquote
(
receipt_data
)
print
(
receipt_data
)
formdata
=
{
formdata
=
{
"receipt-data"
:
receipt_data
,
"receipt-data"
:
receipt_data
,
"exclude-old-transactions"
:
"true"
,
"exclude-old-transactions"
:
"true"
,
...
@@ -43,8 +43,9 @@ def apple_pay(receipt_data):
...
@@ -43,8 +43,9 @@ def apple_pay(receipt_data):
if
response
.
json
()
.
get
(
"status"
)
==
21007
:
if
response
.
json
()
.
get
(
"status"
)
==
21007
:
response
=
requests
.
post
(
AppStore_URL
[
1
],
data
=
dumped_json_string
)
response
=
requests
.
post
(
AppStore_URL
[
1
],
data
=
dumped_json_string
)
if
response
.
status_code
==
200
:
if
response
.
status_code
==
200
:
return
True
if
response
.
json
()
.
get
(
"status"
)
==
0
:
return
True
return
True
return
True
return
False
return
False
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
app/utils/wxpay/wx_app_pay.py
View file @
67c6fe5e
...
@@ -91,7 +91,6 @@ class WXPay(object):
...
@@ -91,7 +91,6 @@ class WXPay(object):
'trade_type'
:
self
.
trade_type
,
'trade_type'
:
self
.
trade_type
,
'sign'
:
self
.
sign
'sign'
:
self
.
sign
}
}
print
(
self
.
data
)
def
dict2xml
(
self
,
dict_
):
def
dict2xml
(
self
,
dict_
):
"""将dict转为要发送到微信服务器的xml格式."""
"""将dict转为要发送到微信服务器的xml格式."""
...
@@ -117,18 +116,18 @@ class WXPay(object):
...
@@ -117,18 +116,18 @@ class WXPay(object):
def
getPaySign
(
self
):
def
getPaySign
(
self
):
"""."""
"""."""
sign_string
=
'app
Id={0}&nonceStr={1}&package={6}prepay_id={2}&signType={3}&timeStamp={4}&key={5
}'
.
format
(
sign_string
=
'app
id={0}&noncestr={1}&package={2}&partnerid={3}&prepayid={4}×tamp={5}&key={6
}'
.
format
(
self
.
appid
,
self
.
nonce_str
,
self
.
prepay_id
,
self
.
sign_type
,
self
.
timeStamp
,
self
.
key
,
'Sign'
)
self
.
appid
,
self
.
nonce_str
,
'Sign=WXPay'
,
self
.
mch_id
,
self
.
prepay_id
,
self
.
timeStamp
,
self
.
key
)
self
.
paySign
=
hashlib
.
md5
(
sign_string
.
encode
(
"utf-8"
))
.
hexdigest
()
.
upper
()
self
.
paySign
=
hashlib
.
md5
(
sign_string
.
encode
(
"utf-8"
))
.
hexdigest
()
.
upper
()
def
getReturnParams
(
self
):
def
getReturnParams
(
self
):
"""."""
"""."""
params
=
{
'app
_id'
:
self
.
appid
,
'noncestr'
:
self
.
nonce_str
,
'mch_id'
:
self
.
mch_id
,
'prepay_
id'
:
self
.
prepay_id
,
params
=
{
'app
id'
:
self
.
appid
,
'noncestr'
:
self
.
nonce_str
,
'package'
:
'Sign=WXPay'
,
'partnerid'
:
self
.
mch_id
,
'prepay
id'
:
self
.
prepay_id
,
'sign'
:
self
.
paySign
,
'timestamp'
:
self
.
timeStamp
}
'timestamp'
:
self
.
timeStamp
,
'sign'
:
self
.
paySign
}
return
params
return
params
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
out_trade_no
=
'2018121023243241341
39
'
out_trade_no
=
'2018121023243241341
12
'
body
=
'APP支付测试'
body
=
'APP支付测试'
total_fee
=
0.01
total_fee
=
0.01
remote_addr
=
'101.95.188.178'
remote_addr
=
'101.95.188.178'
...
...
logs/tamp_course_order.log
View file @
67c6fe5e
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