def edit_order(order): o = OrderBiz.get_order_by_id(order.id).first() user = UserBiz.get_user_by_id(order.user_id) if o is None: raise DaixieError(ORDER_NOT_EXIST) if o.status >= '1' and order.actual_order_price != 0: try: amount = float(o.expect_order_price)-float(order.actual_order_price) if amount>0: UserBiz.refund(o.user_id, abs(amount), type=Transaction.TYPE.REFUND, description=u'订单最终价格调整') else: if user.account < abs(amount): raise DaixieError(u'用户的余额不足,无法填写订单实际价格,修改失败') UserBiz.recharge(o.user_id, abs(amount), type=Transaction.TYPE.PAY, description=u'订单最终价格调整') except DaixieError as e: raise e try: db_session.add(order) db_session.commit() except: raise DaixieError(EDIT_ORDER_FAIL) return EDIT_ORDER_OK
def recharge(id, amount, type, description): user = UserBiz.get_user_by_id(id) if not user: raise DaixieError(USER_NOT_EXIST) try: user.account -= float(amount) db_session.add(user) db_session.commit() TransactionBiz.create(id, amount, user.account, type, description) except: raise DaixieError(REFUND_FAIL) return RECHARGE_SUCCESS
def register(user): if UserBiz.get_user_by_email(user.email): raise DaixieError(USER_DUPLICATE) db_session.add(user) db_session.commit() return USER_REGISTER_OK
def add_solver(solver): if AdminBiz.get_admin_by_email(solver.email): raise DaixieError(USER_DUPLICATE) solver.type = Admin.ADMIN_TYPE.SOLVER db_session.add(solver) db_session.commit() return CS_ADD_OK
def edit_user_profile(user): try: db_session.add(user) db_session.commit() login_user(user, remember=True) except: raise DaixieError(EDIT_USER_PROFILE_FAIL) return EDIT_USER_PROFILE_OK
def user_login(user, remember): u = db_session.query(User).filter_by(email=user.email, passwd=user.passwd).first() if not u: raise DaixieError(USER_NOT_EXIST) user.id = u.id login_user(u, remember=remember) return USER_LOGIN_OK
def admin_login(admin, remember): u = db_session.query(Admin).filter_by(email=admin.email, passwd=admin.passwd).first() if not u: raise DaixieError(USER_NOT_EXIST) admin.id = u.id login_user(u, remember=remember) return USER_LOGIN_OK
def create_order(order): try: db_session.add(order) db_session.commit() order.id += 17394000 db_session.add(order) db_session.commit() except: raise DaixieError(CREATE_ORDER_FAIL) return CREATE_ORDER_OK
def send_activate_email(id, email): try: to = email title = USER_ACTIVATE_TITLE msg = Message(title, recipients=[to]) msg.html = render_template('mail/register_active.html', id=str(id)) mail.send(msg) return SEND_EMAIL_SUCCESS except: raise DaixieError(SEND_EMAIL_FAIL)
def create(user_id, amount, account, type, description): try: transaction = Transaction(user_id, amount, account, type, description) db_session.add(transaction) db_session.commit() transaction.id += 23714000 db_session.add(transaction) db_session.commit() except: raise DaixieError(u'生成交易记录失败')
def user_logout(): try: logout_user() except: raise DaixieError(USER_LOGOUT_FAIL) return USER_LOGOUT_OK
def add_solver(user): if UserBiz.get_user_by_email(user.email): raise DaixieError(USER_DUPLICATE) db_session.add(user) db_session.commit() return SOLVER_ADD_OK
def add_CS(cs): if AdminBiz.get_admin_by_email(cs.email): raise DaixieError(USER_DUPLICATE) db_session.add(cs) db_session.commit() return CS_ADD_OK