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
69cbb907
Commit
69cbb907
authored
Nov 28, 2020
by
pengxiong@wealthgrow.cn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
session异常处理
parent
0965e2ba
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
594 additions
and
134 deletions
+594
-134
engine.py
app/api/engine.py
+27
-34
errors.py
app/config/errors.py
+3
-1
order.py
app/controller/order.py
+8
-8
order_service.py
app/service/order_service.py
+90
-91
tamp_course_order.log
logs/tamp_course_order.log
+466
-0
No files found.
app/api/engine.py
View file @
69cbb907
...
@@ -23,38 +23,6 @@ CFG_FILEPATH = work_dir + '/app/config/config.yaml'
...
@@ -23,38 +23,6 @@ CFG_FILEPATH = work_dir + '/app/config/config.yaml'
config
=
yaml
.
load
(
open
(
CFG_FILEPATH
,
'r'
),
Loader
=
yaml
.
FullLoader
)
config
=
yaml
.
load
(
open
(
CFG_FILEPATH
,
'r'
),
Loader
=
yaml
.
FullLoader
)
class
TAMP_SQL
(
object
):
"""[sqlalchemy 封装]
Args:
object ([type]): [description]
Returns:
[type]: [description]
"""
def
__init__
(
self
,
db_engine
):
# db = "mysql+mysqlconnector://root:password@localhost:3306/test"
# engine = create_engine(db)
# 创建DBSession类型:
self
.
DBSession
=
scoped_session
(
sessionmaker
(
bind
=
db_engine
))
def
__enter__
(
self
):
self
.
session
=
self
.
DBSession
()
return
self
.
session
def
__exit__
(
self
,
ext_type
,
exc_val
,
exc_tb
):
print
(
ext_type
)
self
.
session
.
commit
()
self
.
session
.
close
()
def
add
(
self
,
model
):
# model = User(id='5', name='Bob')
# 添加到session:
self
.
session
.
add
(
model
)
# 提交即保存到数据库:
self
.
session
.
commit
()
tamp_user_engine
=
create_engine
(
tamp_user_engine
=
create_engine
(
'mysql+pymysql://{user}:{password}@{host}:{port}/{db}?charset={charset}'
.
format
(
'mysql+pymysql://{user}:{password}@{host}:{port}/{db}?charset={charset}'
.
format
(
db
=
config
[
env
][
'MySQL'
][
'tamp_user_db'
],
db
=
config
[
env
][
'MySQL'
][
'tamp_user_db'
],
...
@@ -76,8 +44,6 @@ tamp_pay_engine = create_engine(
...
@@ -76,8 +44,6 @@ tamp_pay_engine = create_engine(
charset
=
"utf8"
),
charset
=
"utf8"
),
echo
=
True
echo
=
True
)
)
tamp_user_session
=
scoped_session
(
sessionmaker
(
bind
=
tamp_user_engine
))()
tamp_pay_session
=
scoped_session
(
sessionmaker
(
bind
=
tamp_pay_engine
))()
# redis = redis.StrictRedis(
# redis = redis.StrictRedis(
# host=config[env]['redis']['host'],
# host=config[env]['redis']['host'],
...
@@ -92,3 +58,30 @@ logging.basicConfig(level=logging.INFO,
...
@@ -92,3 +58,30 @@ logging.basicConfig(level=logging.INFO,
datefmt
=
config
[
env
][
'log'
][
'datefmt'
]
datefmt
=
config
[
env
][
'log'
][
'datefmt'
]
)
)
class
TAMP_SQL
(
object
):
"""[sqlalchemy 封装]
Args:
object ([type]): [description]
Returns:
[type]: [description]
"""
def
__init__
(
self
,
db_engine
):
# 创建DBSession类型:
self
.
DBSession
=
scoped_session
(
sessionmaker
(
bind
=
db_engine
))
self
.
session
=
self
.
DBSession
()
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
try
:
self
.
session
.
commit
()
except
:
self
.
session
.
rollback
()
finally
:
self
.
session
.
close
()
app/config/errors.py
View file @
69cbb907
...
@@ -18,6 +18,7 @@ class Errors:
...
@@ -18,6 +18,7 @@ class Errors:
INPUT_PARAMS_ERROR
=
'9006'
INPUT_PARAMS_ERROR
=
'9006'
REPEAT_BUY
=
'9007'
REPEAT_BUY
=
'9007'
PROD_NOPRICE
=
'9008'
PROD_NOPRICE
=
'9008'
NO_ORDERS
=
'9009'
MSG
=
{
MSG
=
{
TOKEN_INVALID
:
'TOKEN失效'
,
TOKEN_INVALID
:
'TOKEN失效'
,
...
@@ -27,5 +28,6 @@ class Errors:
...
@@ -27,5 +28,6 @@ class Errors:
APPLE_VOCHER_USED
:
'该支付凭证已使用'
,
APPLE_VOCHER_USED
:
'该支付凭证已使用'
,
INPUT_PARAMS_ERROR
:
'入参错误'
,
INPUT_PARAMS_ERROR
:
'入参错误'
,
REPEAT_BUY
:
'请勿重复购买商品'
,
REPEAT_BUY
:
'请勿重复购买商品'
,
PROD_NOPRICE
:
'商品未定价'
PROD_NOPRICE
:
'商品未定价'
,
NO_ORDERS
:
'未找到订单'
}
}
app/controller/order.py
View file @
69cbb907
...
@@ -15,7 +15,7 @@ from app.api import app
...
@@ -15,7 +15,7 @@ from app.api import app
from
app.controller.errorhandler
import
CustomFlaskErr
from
app.controller.errorhandler
import
CustomFlaskErr
from
app.config.errors
import
Errors
from
app.config.errors
import
Errors
from
app.service
import
order_service
from
app.service
import
order_service
from
app.api.engine
import
logging
,
tamp_user_session
from
app.api.engine
import
logging
class
TopUpOrder
(
Resource
):
class
TopUpOrder
(
Resource
):
...
@@ -27,12 +27,13 @@ class TopUpOrder(Resource):
...
@@ -27,12 +27,13 @@ class TopUpOrder(Resource):
def
get
(
self
):
def
get
(
self
):
"""."""
"""."""
# raise CustomFlaskErr(Errors.USER_ALREADY_EXISTS)
self
.
parser
.
add_argument
(
'pageNumber'
,
type
=
int
,
required
=
True
)
self
.
parser
.
add_argument
(
'pageNumber'
,
type
=
int
,
required
=
True
)
self
.
parser
.
add_argument
(
'pageSize'
,
type
=
int
,
required
=
True
)
self
.
parser
.
add_argument
(
'pageSize'
,
type
=
int
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
args
=
self
.
parser
.
parse_args
()
args
[
'user_id'
]
=
request
.
user_id
args
[
'user_id'
]
=
request
.
user_id
data
=
order_service
.
TopUpOrderService
()
.
get_order
(
args
)
data
=
order_service
.
TopUpOrderService
()
.
get_order
(
args
)
if
not
data
.
get
(
'content'
,
None
):
raise
CustomFlaskErr
(
Errors
.
NO_ORDERS
)
resp
=
request
.
return_success
resp
=
request
.
return_success
resp
[
'attributes'
]
=
data
resp
[
'attributes'
]
=
data
return
resp
return
resp
...
@@ -75,10 +76,10 @@ class ConsumeOrder(Resource):
...
@@ -75,10 +76,10 @@ class ConsumeOrder(Resource):
user_id
=
request
.
user_id
user_id
=
request
.
user_id
args
[
'user_id'
]
=
request
.
user_id
args
[
'user_id'
]
=
request
.
user_id
data
=
order_service
.
CurriculumOrderService
()
.
get_order
(
args
)
data
=
order_service
.
CurriculumOrderService
()
.
get_order
(
args
)
if
not
data
.
get
(
'content'
,
None
):
raise
CustomFlaskErr
(
Errors
.
NO_ORDERS
)
resp
=
request
.
return_success
resp
=
request
.
return_success
resp
[
'attributes'
]
=
data
resp
[
'attributes'
]
=
data
resp
=
make_response
(
resp
)
resp
.
hearders
=
{
'Content-Type'
:
'application/json;charset=UTF-8'
}
return
resp
return
resp
def
post
(
self
):
def
post
(
self
):
...
@@ -206,10 +207,9 @@ class AllOrders(Resource):
...
@@ -206,10 +207,9 @@ class AllOrders(Resource):
self
.
parser
.
add_argument
(
'pageSize'
,
type
=
int
,
required
=
True
)
self
.
parser
.
add_argument
(
'pageSize'
,
type
=
int
,
required
=
True
)
args
=
self
.
parser
.
parse_args
()
args
=
self
.
parser
.
parse_args
()
args
[
'user_id'
]
=
request
.
user_id
args
[
'user_id'
]
=
request
.
user_id
try
:
data
=
order_service
.
getAllOrders
(
args
)
data
=
order_service
.
getAllOrders
(
args
)
if
not
data
.
get
(
'content'
,
None
):
except
InvalidRequestError
:
raise
CustomFlaskErr
(
Errors
.
NO_ORDERS
)
tamp_user_session
.
rollback
()
resp
=
request
.
return_success
resp
=
request
.
return_success
resp
[
'attributes'
]
=
data
resp
[
'attributes'
]
=
data
return
resp
return
resp
...
...
app/service/order_service.py
View file @
69cbb907
This diff is collapsed.
Click to expand it.
logs/tamp_course_order.log
View file @
69cbb907
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