bug修复

parent 231172c7
......@@ -22,6 +22,39 @@ CFG_FILEPATH = work_dir + '/app/config/config.yaml'
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(
'mysql+pymysql://{user}:{password}@{host}:{port}/{db}?charset={charset}'.format(
db=config[env]['MySQL']['tamp_user_db'],
......
......@@ -17,6 +17,7 @@ class Errors:
APPLE_VOCHER_USED = '9005'
INPUT_PARAMS_ERROR = '9006'
REPEAT_BUY = '9007'
PROD_NOPRICE = '9008'
MSG = {
TOKEN_INVALID: 'TOKEN失效',
......@@ -25,5 +26,6 @@ class Errors:
TANGPU_BALANCE_NOT_ENOUGH: '探普币余额不足',
APPLE_VOCHER_USED: '该支付凭证已使用',
INPUT_PARAMS_ERROR: '入参错误',
REPEAT_BUY: '请勿重复购买商品'
REPEAT_BUY: '请勿重复购买商品',
PROD_NOPRICE: '商品未定价'
}
......@@ -9,12 +9,13 @@
import json
from flask_restful import Resource, reqparse
from flask import request, make_response
from sqlalchemy.exc import InvalidRequestError
from app.api import app
from app.controller.errorhandler import CustomFlaskErr
from app.config.errors import Errors
from app.service import order_service
from app.api.engine import logging
from app.api.engine import logging, tamp_user_session
class TopUpOrder(Resource):
......@@ -207,8 +208,8 @@ class AllOrders(Resource):
args['user_id'] = request.user_id
try:
data = order_service.getAllOrders(args)
except Exception as e:
logging.error(e)
except InvalidRequestError:
tamp_user_session.rollback()
resp = request.return_success
resp['attributes'] = data
return resp
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment