def delete_loan(uid,cid): if not str(cid).isdigit(): return {'status':2,'msg':'id 不存在'} try: DebtDao.delete_card_debt(uid, int(cid)) except Exception as e: res = {'msg':'输入错误:' + str(e),'status':2} 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 add_loan(uid,cid,num,ts,en): if not str(cid).isdigit(): return {'status':2,'msg':'id 不存在'} if not is_float(num): return {'status':2,'msg':'数量错误'} if not is_date(ts) or not is_date(en): return {'status':2,'msg':'日期错误'} d = dateRange(ts,en) try: DebtDao.add_bulk_debt(uid, cid, d, num) except Exception as e: res = {'msg':'输入错误:' + str(e),'status':2} else: res = {'msg':'添加成功','status':1} return res
def add_one_debt(uid,cid,num,t): if not str(cid).isdigit(): return {'msg':'id不存在','status':2} if not is_float(num): return {'msg':'数量错误','status':2} if not is_date(t): return {'msg':'日期错误','status':2} ll = [v[0] for v in CardDao.find_card(uid)] if cid not in ll: return {'msg':'id不存在','status':2} try: DebtDao.add_debt(uid, cid, dt.datetime.strptime(t,'%Y-%m-%d'), num) except Exception as e: res = {'msg':'输入错误:' + str(e),'status':2} else: res = {'msg':'添加成功','status':1} return res
def quick_repay_by_card(uid, in_cid, num, date, out_cid): 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') # rl = round(num*1.006,2) try: DebtDao.add_debt(uid, out_cid, t, num) # 临时改rl为 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 debt_list(uid,cid): ll = [] for v in DebtDao.find_card_debt(uid,cid): cl = {} cl['cid'] = v[0] cl['date'] = v[1].strftime("%Y-%m-%d") cl['num'] = v[2] cl['id'] = v[3] ll.append(cl) return {'status':1,'body':{'records':ll}}
def loan_list(uid): ll = [] for v in DebtDao.find_load(uid): cl = {} cl['cid'] = v[0] cl['name'] = v[1] cl['date'] = v[2].date().strftime('%Y-%m-%d') cl['num'] = v[3] cl['id'] = v[4] ll.append(cl) return {'status':1,'body':{'loans':ll}}
def card_list(uid): d = dt.date.today() debtlist = {} for v in DebtDao.find_debt_res(uid): debtlist[v[0]] = v[1] ll = [] for v in CardDao.find_card(uid): cl = {} cl['ct'] = 1 cl['id'] = v[0] cl['name'] = v[1] cl['acdate'] = v[2] cl['padate'] = v[3] cl['freedays'] = (cal_repay_date(d, cl['acdate'], cl['padate']) - d).days used = debtlist.get(v[0]) cl['used'] = used if used else 0 cl['num'] = v[4] cl['avail'] = cl['num'] - cl['used'] ll.append(cl) ll.sort(key=lambda x: x['freedays'], reverse=True) for v in CardDao.find_load_account(uid): cl = {} cl['ct'] = 0 cl['id'] = v[0] cl['name'] = v[1] cl['acdate'] = 0 cl['padate'] = v[3] num = DebtDao.find_card_debt_sum(uid, cl['id']) cl['num'] = num cl['freedays'] = (cal_repay_date(d, cl['padate'], cl['padate']) - d).days used = debtlist.get(v[0]) cl['avail'] = used if used else 0 cl['used'] = cl['num'] - cl['avail'] ll.append(cl) cl = {'ct': 2, 'id': -1, 'name': '工资卡', 'freedays': 0} ll.append(cl) return {'status': 1, 'body': {'cards': ll}}