def income_list(uid): ll = {} for v in IncomeDAO.find_income(uid): cl = {} cl['id'] = v[0] cl['date'] = v[1].strftime("%Y-%m-%d") cl['num'] = v[2] cl['typename'] = '到账' cl['type'] = 1 m = v[1].strftime("%m月") if ll.get(m) is None: ll[m] = {'month': m, 'records': [cl]} else: ll[m]['records'].append(cl) for v in IncomeDAO.find_incomego(uid): cl = {} cl['id'] = v[0] cl['date'] = v[2].strftime("%Y-%m-%d") cl['num'] = v[3] cl['typename'] = '支出' cl['type'] = 0 m = v[2].strftime("%m月") if ll.get(m) is None: ll[m] = {'month': m, 'records': [cl]} else: ll[m]['records'].append(cl) ll = list(ll.values()) for v in ll: v['records'] = sorted(v['records'], key=lambda x: x['date']) return {'status': 1, 'body': {'records': ll}}
def delete_one_incomego(uid, gid): if not str(gid).isdigit(): return {'msg': 'id不存在', 'status': 2} try: IncomeDAO.delete_incomego(gid) except Exception as e: return {'msg': '输入错误:' + str(e), 'status': 2} else: return {'msg': '删除成功', 'status': 1}
def add_one_income(uid, n, t): if not is_float(n): return {'msg': 'id不存在', 'status': 2} if not is_date(t): return {'msg': '输入错误', 'status': 2} try: IncomeDAO.add_income(uid, dt.datetime.strptime(t, '%Y-%m-%d'), n) except Exception as e: return {'msg': '输入错误:' + str(e), 'status': 2} else: return {'msg': '添加成功', 'status': 1}
def quick_repay_by_income(uid, in_cid, num, date, iid): if not str(in_cid).isdigit(): return {'msg': 'id不存在', 'status': 2} if not is_float(num): return {'msg': '数量错误', 'status': 2} if not is_date(date): return {'msg': '日期错误', 'status': 2} t = dt.datetime.strptime(date, '%Y-%m-%d') try: IncomeDao.add_incomego(uid, iid, t, num) RepayDao.add_repay(uid, in_cid, t, num) except Exception as e: res = {'msg': '输入错误:' + str(e), 'status': 1} else: res = {'msg': '添加成功', 'status': 1} return res
def init_pad(pad, uid): for v in CardDao.find_card(uid): CreditCard(pad, v[0], v[1], int(v[2]), int(v[3]), int(v[4])) for v in CardDao.find_load_account(uid): CreditCard(pad, v[0], v[1], int(v[2]), int(v[3]), int(v[4]), 0) for v in DebtDao.find_debt(uid): pad.get_card(v[0]).consume(v[2], int(v[3])) for v in DebtDao.find_load(uid): pad.get_card(v[0]).consume(v[2], int(v[3])) for v in RepayDao.find_repay(uid): pad.get_card(v[0]).repay(int(v[3])) for v in IncomeDao.find_incomego_sum(uid): pad.set_income(v) return
def quick_repay_by_cash(uid, in_cid, num, date): if not str(in_cid).isdigit(): return {'msg': 'id不存在', 'status': 2} if not is_float(num): return {'msg': '数量错误', 'status': 2} if not is_date(date): return {'msg': '日期错误', 'status': 2} t = dt.datetime.strptime(date, '%Y-%m-%d') try: h = IncomeDao.find_income_before_date(uid, t) c = max(0, num - h) if c: IncomeDao.add_income(uid, t, c) pad = CardPad() for v in IncomeDao.find_incomego_sum(uid): pad.set_income(v) ll = pad.consume(t.date(), num) IncomeDao.add_bulk_incomego(uid, t, ll) RepayDao.add_repay(uid, in_cid, t, num) except Exception as e: res = {'msg': '输入错误:' + str(e), 'status': 1} else: res = {'msg': '添加成功', 'status': 1} return res