def account_out(page, num): """支出 (分为 消费者消费支出/发布者广告支出)""" appkey = g.appkey username = request.json.get('username') # with_entities的field可以使用lable指定别名 records = Content.query.with_entities(Content.claim_id, Content.author, Content.title, Consume.txid, Consume.customer, db.func.abs(Consume.price).label('price'), Consume.create_timed). \ join(Consume, Content.claim_id == Consume.claim_id). \ filter(Content.appkey==appkey). \ filter(db.and_(Content.author == username,Consume.price<0)| db.and_(Consume.customer==username,Consume.price>0)). \ order_by(Consume.create_timed.desc()). \ paginate(page, num, error_out=False) total = records.total pages = records.pages records = consumeinouts_schema.dump(records.items).data return return_result(result=dict(total=total, pages=pages, records=records))
def account_out(page, num): """expenditure statement Consumer Resource Expenditure and Publisher Ad Spending """ appkey = g.appkey username = request.json.get('username') records = Content.query.with_entities(Content.claim_id, Content.author, Content.title, Consume.txid, Consume.customer, db.func.abs(Consume.price).label('price'), Consume.create_timed). \ join(Consume, Content.claim_id == Consume.claim_id). \ filter(Content.appkey==appkey). \ filter(db.and_(Content.author == username,Consume.price<0)| db.and_(Consume.customer==username,Consume.price>0)). \ order_by(Consume.create_timed.desc()). \ paginate(page, num, error_out=False) total = records.total pages = records.pages records = add_timestamp(records.items) return return_result(result=dict(total=total, pages=pages, records=records))
def account_in(page, num): """income statement Publisher resource income and consumer advertising revenue """ appkey = g.appkey username = g.form.username.data records = Content.query.with_entities( Content.claim_id, Content.author, Content.title, Consume.txid, Consume.customer, db.func.abs(Consume.price).label('price'), Consume.create_timed).join( Consume, Content.claim_id == Consume.claim_id).filter( Content.appkey == appkey).filter( db.and_(Content.author == username, Consume.price > 0) | db.and_(Consume.customer == username, Consume.price < 0) ).order_by(Consume.create_timed.desc()).paginate( page, num, error_out=False) total = records.total pages = records.pages records = add_timestamp(records.items) return return_result( result=dict(total=total, pages=pages, records=records))
def account_out(page, num): """expenditure statement Consumer Resource Expenditure and Publisher Ad Spending Args: page: Show the page num: How many pages per page category: 0 - Resource spending, 1 - Advertising income """ appkey = g.appkey username = g.form.username.data category = g.form.category.data sdate = g.form.sdate.data edate = g.form.edate.data query = Content.query.with_entities( Content.claim_id, Content.author, Content.title, Consume.txid, Consume.customer, db.func.abs(Consume.price).label('price'), Consume.create_timed).join( Consume, Content.claim_id == Consume.claim_id).filter( Content.appkey == appkey).filter(Consume.create_timed >= sdate, Consume.create_timed <= edate) if category == 0: query = query.filter(Consume.customer == username, Consume.price > 0) elif category == 1: query = query.filter(Content.author == username, Consume.price < 0) else: query = query.filter( db.and_(Content.author == username, Consume.price < 0) | db.and_(Consume.customer == username, Consume.price > 0)) records = query.order_by(Consume.create_timed.desc()).paginate( page, num, error_out=False) total = records.total pages = records.pages records = add_timestamp(records.items) return return_result( result=dict(total=total, pages=pages, records=records))