def get(self, *args, **kwargs): now = datetime.datetime.now() date_before_30days = now + datetime.timedelta(days=-30) default_date_from = getFormatDate(date=date_before_30days, format="%Y-%m-%d") default_date_to = getFormatDate(date=now, format="%Y-%m-%d") resp_data = {} date_from = self.get_argument('date_from', default_date_from) date_to = self.get_argument('date_to',default_date_to) query = session.query(StatDailyMember).filter(StatDailyMember.date >= date_from) \ .filter(StatDailyMember.date <= date_to) list = query.order_by(StatDailyMember.id.desc()).limit(100).all() date_list = [] if list: member_map = getDictFilterField(Member, Member.id, "id", selectFilterObj(list, "member_id")) for item in list: tmp_member_info = member_map[item.member_id] if item.member_id in member_map else {} tmp_data = { "date": item.date, "total_pay_money": item.total_pay_money, "total_shared_count": item.total_shared_count, 'member_info': tmp_member_info } date_list.append(tmp_data) resp_data['list'] = date_list resp_data['current'] = 'member' resp_data['search_con'] = { 'date_from': date_from, 'date_to': date_to } self.render("stat/member.html", **resp_data)
def get(self, *args, **kwargs): now = datetime.datetime.now() date_before_30days = now + datetime.timedelta(days=-30) date_from = getFormatDate(date=date_before_30days, format="%Y-%m-%d") date_to = getFormatDate(date=now, format="%Y-%m-%d") list = session.query(StatDailySite).filter(StatDailySite.date >= date_from) \ .filter(StatDailySite.date <= date_to).order_by(StatDailySite.id.asc()) \ .all() resp = {'code': 200, 'msg': '操作成功~~', 'data': {}} data = { "categories": [], "series": [ { "name": "会员总数", "data": [] }, { "name": "订单总数", "data": [] }, ] } if list: for item in list: data['categories'].append( getFormatDate(date=item.date, format="%Y-%m-%d")) data['series'][0]['data'].append(item.total_member_count) data['series'][1]['data'].append(item.total_order_count) resp['data'] = data self.finish(resp)
def get(self, *args, **kwargs): resp_data = { 'data': { 'finance': { 'today': 0, 'month': 0 }, 'member': { 'today_new': 0, 'month_new': 0, 'total': 0 }, 'order': { 'today': 0, 'month': 0 }, 'shared': { 'today': 0, 'month': 0 }, } } now = datetime.datetime.now() date_before_30days = now + datetime.timedelta(days=-30) date_from = getFormatDate(date=date_before_30days, format="%Y-%m-%d") date_to = getFormatDate(date=now, format="%Y-%m-%d") list = session.query(StatDailySite).filter(StatDailySite.date >= date_from) \ .filter(StatDailySite.date <= date_to).order_by(StatDailySite.id.asc()) \ .all() data = resp_data['data'] if list: for item in list: data['finance']['month'] += item.total_pay_money data['member']['month_new'] += item.total_new_member_count data['member']['total'] = item.total_member_count data['order']['month'] += item.total_order_count data['shared']['month'] += item.total_shared_count if getFormatDate(date=item.date, format="%Y-%m-%d") == date_to: data['finance']['today'] = item.total_pay_money data['member']['today_new'] = item.total_new_member_count data['order']['today'] = item.total_order_count data['shared']['today'] = item.total_shared_count self.render("index/index.html", **resp_data)
def get(self, *args, **kwargs): now = datetime.datetime.now() date_before_30days = now + datetime.timedelta(days=-30) default_date_from = getFormatDate(date=date_before_30days, format="%Y-%m-%d") default_date_to = getFormatDate(date=now, format="%Y-%m-%d") resp_data = {} date_from = self.get_argument('date_from', default_date_from) date_to = self.get_argument('date_to', default_date_to) query = session.query(StatDailySite).filter(StatDailySite.date >= date_from) \ .filter(StatDailySite.date <= date_to) list = query.order_by(StatDailySite.id.desc()).limit(100).all() resp_data['list'] = list resp_data['current'] = 'share' resp_data['search_con'] = { 'date_from': date_from, 'date_to': date_to } self.render("stat/share.html", **resp_data)
import logging from celery.schedules import crontab from celery import Celery,platforms platforms.C_FORCE_ROOT = True # linux下便于使用root权限运行 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='test.log', filemode='w') worker = Celery("tasks",broker="redis://127.0.0.1:6379/0", backend="redis://127.0.0.1:6379/1") worker.conf['worker_hijack_root_logger'] = False # 让日志输出到文件,否则celery会拦截 date = getFormatDate(getCurrentDate(),"%Y-%m-%d") date_from = date + " 00:00:00" date_to = date + " 23:59:59" params = { 'date': date, 'date_from': date_from, 'date_to': date_to } # 会员统计 @worker.task() def statMember(params): date = params['date'] date_from = params['date_from'] date_to = params['date_to'] logging.info("act:{0},from:{1},to:{2}".format("会员统计", date_from, date_to))