Пример #1
0
 def delete_unactivated_user(email):
     user = UserBiz.get_user_by_email(email)
     if not user:
         raise DaixieError(USER_NOT_EXIST)
     db_session.delete(user)
     db_session.commit()
     return DELETE_USER_OK
Пример #2
0
    def pay(id):
        order = OrderBiz.get_order_by_id(id)
        if not order:
            return u"订单不存在"
        elif order.status != Order.STATUS.CREATED:
            return u"该订单已付款"

        cuser = UserBiz.get_user_by_id(order.user_id)
        if order.expect_order_price is None:
            return "DatabaseError:Price Format Error"

        if order.expect_order_price > cuser.account:
            return u"账户余额不足"
        else:
            try:
                # 从账户扣钱
                amount = order.expect_order_price
                print amount
                if UserBiz.pay(order.user_id, amount, Transaction.TYPE.PAY, u"用户对订单付款") == REFUND_SUCCESS:
                    order.status = Order.STATUS.PAID
                db_session.add(order)
                db_session.commit()
            except DaixieError as e:
                raise e.get_msg()
        return PAY_ORDER_SUCCESS
Пример #3
0
    def activate_user(user):
        user.activate = User.ACTIVATE.YES
        db_session.commit()

        login_user(user, remember=True)

        return USER_ACTIVATE_OK
Пример #4
0
 def create(user_id, amount, account, type, description):
     try:
         transaction = Transaction(user_id, amount, account, type, description)
         db_session.add(transaction)
         db_session.commit()
     except:
         raise DaixieError(u'生成交易记录失败')
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
    def register(user):
        if UserBiz.get_user_by_email(user.email):
            raise DaixieError(USER_DUPLICATE)

        db_session.add(user)
        db_session.commit()

        login_user(user, remember=True)
        
        return USER_REGISTER_OK
Пример #8
0
 def refund(id, amount, type, description):
     user = UserBiz.get_user_by_id(id)
     if not user:
         raise DaixieError(USER_NOT_EXIST)
     try:
         user.account -= int(amount)
         db_session.add(user)
         db_session.commit()
         TransactionBiz.create(id, amount, user.account, type, description)
     except:
         raise DaixieError(REFUND_FAIL)
     return REFUND_SUCCESS
Пример #9
0
 def recharge(id, amount, type, description):
     user = UserBiz.get_user_by_id(id)
     if not user:
         raise DaixieError(USER_NOT_EXIST)
     try:
         user.account += int(amount)
         db_session.add(user)
         db_session.commit()
     except:
         raise DaixieError(RECHARGE_FAIL)
     else:
         TransactionBiz.create(id, amount, user.account, type, description)
     return RECHARGE_SUCCESS
Пример #10
0
	def refund(id):
		order = OrderBiz.get_order_by_id(id)
		if not order:
			raise DaixieError(u'订单不存在')
		elif order.status != Order.STATUS.CREATED:
			raise DaixieError(u'该订单已付款')
		try:
			#订单付款失败,偿还从账户中扣除的钱
			amount = int(order.expect_order_price)
			UserBiz.recharge(order.user_id, amount, Transaction.TYPE.REFUND, u'用户付款失败,返回付款金额')
			order.status = Order.STATUS.CREATED
			db_session.add(order)
			db_session.commit()
		except DaixieError as e:
			raise e
Пример #11
0
 def pay(id, amount, type, description):
     user = UserBiz.get_user_by_id(id)
     if not user:
         raise DaixieError(USER_NOT_EXIST)
     try:
         print amount
         user.account = user.account - amount
         print user.account
         db_session.add(user)
         print "committing user"
         db_session.commit()
         TransactionBiz.create(id, amount, user.account, type, description)
     except:
         raise DaixieError(REFUND_FAIL)
     return REFUND_SUCCESS
Пример #12
0
	def pay(id):
		order = OrderBiz.get_order_by_id(id)
		if not order:
			raise DaixieError(u'订单不存在')
		elif order.status != Order.STATUS.CREATED:
			raise DaixieError(u'该订单已付款')
		elif order.expect_order_price > current_user.account:
			raise DaixieError(u'账户余额不足')

		try:
			#从账户扣钱
			amount = int(order.expect_order_price)
			UserBiz.refund(order.user_id, amount, Transaction.TYPE.PAY, u'用户对订单进行付款')
			order.status = Order.STATUS.PAID
			db_session.add(order)
			db_session.commit()
		except DaixieError as e:
			OrderBiz.refund(id)
			raise e
		return PAY_ORDER_SUCCESS
Пример #13
0
 def delete_CS(cs):
     db_session.delete(cs)
     db_session.commit()
     return CS_DELETE_OK
Пример #14
0
 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