filter = [] filter.append(PayLog.objectid == current_user['id']) filter.append(PayLog.type == current_app.config['PAY_USETYPE_APPLY_MONEY']) if info['unit'] == 1: dateC = datetime.date.today().replace(day=1) start = int(time.mktime(dateC.timetuple())) endC = dateC + relativedelta(months=+1) end = int(time.mktime(endC.timetuple())) filter.append(PayLog.createtime < end) filter.append(PayLog.createtime >= start) elif info['unit'] == 2: dateC = datetime.date.today() start = int(time.mktime(dateC.timetuple())) endC = dateC + relativedelta(days=+1) end = int(time.mktime(endC.timetuple())) filter.append(PayLog.createtime < end) filter.append(PayLog.createtime >= start) elif info['unit'] == 3: dateC = datetime.date.today().replace(day=1) sdateC = dateC + relativedelta(months=-3) start = int(time.mktime(sdateC.timetuple())) endC = dateC + relativedelta(months=+1) end = int(time.mktime(endC.timetuple())) filter.append(PayLog.createtime < end) filter.append(PayLog.createtime >= start) count = PayLog.query.filter(*filter).count()