def card_pay(self, cost, paytype, sereialno): """ 信用卡支付,从信用卡可透支余额中扣费 :param sereialno: 流水号 :param cost: 消费金额 float类型 :param paytype: 消费类型 int类型 ( 1:消费、2:转账、3:提现、4:手续费 ) 对于2,3类型的支付要扣手续费,单记录一条流水单 :return: """ if paytype == 1: payfor = "消费" elif paytype == 2: payfor = "转账" elif paytype == 3: payfor = "提现" elif paytype == 4: payfor = "手续费" else: payfor = "未知" # 支付扣款 self.credit_balance -= cost # 记录消费流水对账单,将发生了费用还没有还款的账单信息写入文件 report_bill 中 _tmp_bill_record = dict(cardno="{0}".format(self.cardno), starttime=datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M"), payfor=payfor, cost=cost, serialno=sereialno) dbapi.append_db_json(_tmp_bill_record, os.path.join(Settings.REPORT_PATH, "report_bill")) # 更新信用卡可透支余额信息到数据库 creditcard.db self.credit_card[self.cardno]["credit_balance"] = self.credit_balance dbapi.write_db_json(self.credit_card, self.__database)
def update_card(self): password = common.encrypt(self.password) self.credit_card[self.cardno]["password"] = password self.credit_card[self.cardno]["owner"] = self.owner self.credit_card[self.cardno]["credit_total"] = self.credit_total self.credit_card[self.cardno]["credit_balance"] = self.credit_balance self.credit_card[self.cardno]["frozenstatus"] = self.frozenstatus # 写入数据库 dbapi.write_db_json(self.credit_card, self.__database)
def create_card(self): """ 新发行一张行用卡 :return: """ password = common.encrypt(self.password) self.credit_card[self.cardno] = dict(password=password, credit_total=self.credit_total, credit_balance=self.credit_balance, owner=self.owner, frozenstatus=self.frozenstatus) # 保存到数据库 dbapi.write_db_json(self.credit_card, self.__database)
def create_user(self): """ 新创建一个用户,将用户数据同步写入到数据库文件 :return: """ self.dict_user[self.username] = dict( password=common.encrypt(self.password), name=self.name, mobile=self.mobile, bindcard=self.bindcard, role=self.role, islocked=0, isdel=0, ) dbapi.write_db_json(self.dict_user, self.__database)
def update_user(self): """ 用户数据更新方法,用户修改信息、用户账户锁定、解锁等操作之后更新数据库文件 :return: """ try: ''' _password = common.encrypt(self.password) self.dict_user[self.username]["password"] = _password self.dict_user[self.username]["islocked"] = self.islocked self.dict_user[self.username]["name"] = self.name self.dict_user[self.username]["mobile"] = self.mobile self.dict_user[self.username]["bindcard"] = self.bindcard self.dict_user[self.username]["isdel"] = self.isdel self.dict_user[self.username]["role"] = self.role ''' # 写入数据库文件 dbapi.write_db_json(self.dict_user, self.__database) return True except Exception as e: common.write_log(e) return False