def get_specify_datetime_scores(cls, specify_datetime, table='scores'): """ 指定日期积分记录总览 --> scores """ db = MongoConnect.get_current_db() params = [{ "$match": { "created_at": { "$gte": string_to_datetime(specify_datetime), "$lt": get_days_before_current_datetime(specify_datetime) } } }, { "$group": { "_id": "$toUid", "score_specify_total_score": { "$sum": "$score_diff" }, "score_specify_total_count": { "$sum": 1 } }, }, { "$project": { "msg": 0, "user": 0 }, }, { "$sort": { "finished_at": -1 } }] obj = db[table].aggregate(params) for item in obj: yield item
def get_aggregate_scores(cls, table='scores'): """ 历史总览 scores """ db = MongoConnect.get_current_db() params = [{ "$match": { "score_type": { "$eq": 2 }, }, }, { "$group": { "_id": "$toUid", "score_total_score": { "$sum": "$score_diff" }, "score_total_count": { "$sum": 1 } } }] obj = db[table].aggregate(params) for item in obj: yield item
def get_aggregate_recharges(cls, table='recharges'): """ 历史总览 """ db = MongoConnect.get_current_db() params = [{ "$match": { "status": { "$eq": 2 } } }, { "$group": { "_id": "$toUid", "recharge_total_amount": { "$sum": "$amount" }, "recharge_total_score": { "$sum": "$score" }, "recharge_total_count": { "$sum": 1 } } }] obj = db[table].aggregate(params) for item in obj: yield item
def get_week_aggregate_scores(cls, table='scores'): """ 一周总览 scores """ db = MongoConnect.get_current_db() params = [{ "$match": { "score_type": { "$eq": 2 }, "created_at": { "$gte": get_weeks_before_toady(), "$lt": datetime.datetime.now() } } }, { "$group": { "_id": "$toUid", "score_week_total_score": { "$sum": "$score_diff" }, "score_week_total_count": { "$sum": 1 } }, }, { "$project": { "_id": 0 } }] obj = db[table].aggregate(params) for item in obj: yield item
def get_week_recharge_record(cls, page, table='recharges', show_num=20): """ 一周充值记录 :param page: :param table: :param show_num: 每页显示数据条数 :return: """ db = MongoConnect.get_current_db() params = [{ "$match": { "finished_at": { "$gte": get_weeks_before_toady(), "$lt": datetime.datetime.now() } } }, { '$lookup': { 'from': 'users', 'localField': 'user', 'foreignField': '_id', 'as': 'userinfo', }, }, { "$project": { "msg": 0, "user": 0 }, }, { "$sort": { "finished_at": -1 }, }, { "$limit": show_num * page }, { "$skip": (page - 1) * show_num }] record_obj = db[table].aggregate(params) for item in record_obj: new_item = transform_payment_status_type( json.loads(JsonEncoder().encode(item))) yield new_item
def get_recharge_specify_datetime_record(cls, specify_datetime, table='recharges', show_num=20000): """ 指定日期查询充值记录 """ db = MongoConnect.get_current_db() params = [{ "$match": { "finished_at": { "$gte": string_to_datetime(specify_datetime), "$lt": get_days_before_current_datetime(specify_datetime) } } }, { '$lookup': { 'from': 'users', 'localField': 'user', 'foreignField': '_id', 'as': 'userinfo', }, }, { "$project": { "msg": 0, "user": 0 }, }, { "$sort": { "finished_at": -1 }, }, { "$limit": show_num }] record_obj = db[table].aggregate(params) for item in record_obj: new_item = transform_payment_status_type( json.loads(JsonEncoder().encode(item))) yield new_item
def get_specify_datetime_recharges(cls, specify_datetime, table='recharges'): """ 指定日期充值记录总览 -- > recharges """ db = MongoConnect.get_current_db() params = [{ "$match": { "status": { "$eq": 2 }, "finished_at": { "$gte": string_to_datetime(specify_datetime), "$lt": get_days_before_current_datetime(specify_datetime) } } }, { "$group": { "_id": "$toUid", "recharge_specify_total_amount": { "$sum": "$amount" }, "recharge_specify_total_score": { "$sum": "$score" }, "recharge_specify_total_count": { "$sum": 1 } }, }, { "$project": { "_id": 0 } }] obj = db[table].aggregate(params) for item in obj: yield item
def get_week_aggregate_recharges(cls, table='recharges'): """ 一周总览 """ db = MongoConnect.get_current_db() params = [{ "$match": { "status": { "$eq": 2 }, "finished_at": { "$gte": get_weeks_before_toady(), "$lt": datetime.datetime.now() } } }, { "$group": { "_id": "$toUid", "recharge_week_total_amount": { "$sum": "$amount" }, "recharge_week_total_score": { "$sum": "$score" }, "recharge_week_total_count": { "$sum": 1 } }, }, { "$project": { "_id": 0 } }] obj = db[table].aggregate(params) for item in obj: yield item
# -*-coding:utf-8 -*- import os import uuid import base64 from models import user from db.mongohelper import MongoWrapper from db.mongo_query import MongodbFetch from db.mongohelper import MongoConnect mongo_db = MongodbFetch db = MongoConnect.get_current_db() cookie_secret = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes) setting = { 'debug': True, 'template_path': os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates/"), 'static_path': os.path.join(os.path.dirname(os.path.abspath(__file__)), "static/"), 'mongo_db': mongo_db, 'db': db, 'cookie_secret': cookie_secret, 'pycket': { 'engine': 'redis', 'storage': { 'host': 'localhost', 'port': 6379, 'db_sessions': 10, 'db_notifications': 11, },