def activate_user(user): user.activate = User.ACTIVATE.YES db_session.commit() login_user(user, remember=True) return USER_ACTIVATE_OK
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_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 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 solver_commit_update(solver): try: solver.passwd = md5(solver.passwd).hexdigest() db_session.merge(solver) db_session.commit() except: db_session.rollback() raise return SOLVER_UPDATE_OK
def cs_commit_update(cs): try: cs.passwd = md5(cs.passwd).hexdigest() db_session.merge(cs) db_session.commit() except: db_session.rollback() raise return CS_UPDATE_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 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 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 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
def delete_CS(cs): db_session.delete(cs) db_session.commit() return CS_DELETE_OK
def delete_solver(user): db_session.delete(user) db_session.commit() return SOLVER_DELETE_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