当前位置: 首页>>代码示例>>Python>>正文


Python Method.dateRange方法代码示例

本文整理汇总了Python中sellcard.common.Method.dateRange方法的典型用法代码示例。如果您正苦于以下问题:Python Method.dateRange方法的具体用法?Python Method.dateRange怎么用?Python Method.dateRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sellcard.common.Method的用法示例。


在下文中一共展示了Method.dateRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: date_detail

# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import dateRange [as 别名]
def date_detail(request):
    shop = mth.getReqVal(request, 'shopcode','')
    start = mth.getReqVal(request, 'start','')
    end = mth.getReqVal(request, 'end','')
    endTime = str(datetime.datetime.strptime(end,'%Y-%m-%d').date() + datetime.timedelta(1))
    page = mth.getReqVal(request, 'page', 1)

    conn = mth.getMysqlConn()
    cur = conn.cursor()
    sale_sql = "select DATE_FORMAT(a.add_time, '%Y-%m-%d') as add_time,b.pay_id,sum(b.pay_value) as pay_value " \
               " from orders as a, order_payment_info as b" \
               " where a.order_sn = b.order_id and a.add_time>='{start}' and a.add_time<='{end}' and a.shop_code ='{shop}'" \
               " group by DATE_FORMAT(a.add_time, '%Y-%m-%d'),b.pay_id" \
                .format(start=start,end=endTime,shop=shop)
    cur.execute(sale_sql)
    data_sale = cur.fetchall()

    sale_disc_sql="select DATE_FORMAT(add_time, '%Y-%m-%d') as add_time," \
                  "SUM(case when disc_amount>=y_cash then disc_amount else diff_price+disc_amount end) as disc, " \
                  "SUM(y_cash) as disc_cash,"  \
                  "SUM(case when disc_amount>=y_cash then disc_amount-y_cash else disc_amount+diff_price-y_cash end) as disc_card " \
                  "from orders " \
                  "where add_time>='{start}' and add_time<='{end}' and shop_code ='{shop}' "  \
                  "group by DATE_FORMAT(add_time, '%Y-%m-%d') " \
                    .format(start=start, end=endTime, shop=shop)
    cur.execute(sale_disc_sql)
    data_sale_disc = cur.fetchall()

    change_sql = "select DATE_FORMAT(a.add_time, '%Y-%m-%d') as add_time,b.pay_id,sum(b.pay_value) as pay_value " \
               " from order_change_card as a, order_change_card_payment as b" \
               " where a.order_sn = b.order_id and a.add_time>='{start}' and a.add_time<='{end}' and a.shop_code ='{shop}'" \
               " group by DATE_FORMAT(a.add_time, '%Y-%m-%d'),b.pay_id" \
                .format(start=start,end=endTime,shop=shop)
    cur.execute(change_sql)
    data_change = cur.fetchall()

    change_disc_sql = "select DATE_FORMAT(add_time, '%Y-%m-%d') as add_time," \
                      "SUM(case when disc>=disc_cash then disc else disc_pay+disc end) as disc," \
                    "SUM(disc_cash) as disc_cash," \
                    "SUM(case when disc>=disc_cash then disc-disc_cash else disc+disc_pay-disc_cash end) as disc_card " \
                    "from order_change_card " \
                    "where add_time>='{start}' and add_time<='{end}' and shop_code ='{shop}' " \
                    "group by  DATE_FORMAT(add_time, '%Y-%m-%d') " \
        .format(start=start, end=endTime, shop=shop)
    cur.execute(change_disc_sql)
    data_change_disc = cur.fetchall()

    fill_sql = "select DATE_FORMAT(add_time, '%Y-%m-%d') as add_time,sum(diff_price) as pay_value" \
               " from order_up_card" \
               " where add_time>='{start}' and add_time<='{end}' and shop_code ='{shop}'" \
               " group by  DATE_FORMAT(add_time, '%Y-%m-%d') " \
                .format(start=start, end=endTime, shop=shop)
    cur.execute(fill_sql)
    data_fill = cur.fetchall()

    dates = mth.dateRange(start,end)

    res_list = []
    paymentsRate = Payment.objects.values('id', 'dis_rate').filter(dis_rate__gte=0)
    paymentsRateDict = {item['id']: float(item['dis_rate']) for item in paymentsRate}
    for date in dates:
        item = {'date': '',
                'disc': 0, 'disc_6': 0, 'disc_7': 0, 'disc_8': 0, 'disc_10': 0, 'disc_11': 0, 'disc_cash': 0,
                'disc_card': 0,
                'inSub': 0, 'pay_1': 0, 'pay_2': 0, 'pay_3': 0, 'pay_4': 0, 'pay_5': 0, 'pay_6': 0, 'pay_7': 0,
                'pay_8': 0,
                'pay_9': 0, 'pay_10': 0, 'pay_11': 0, }
        item['date'] = date
        for sale in data_sale:
            if sale['add_time'] == date:
                # 横向各门店售卡汇总赋值
                # pay_id = sale['pay_id']
                if sale['pay_id'] == 1:
                    item['pay_1'] += float(sale['pay_value'])
                    item['inSub'] += float(sale['pay_value'])
                if sale['pay_id'] == 2:
                    item['pay_2'] += float(sale['pay_value'])
                    item['inSub'] += float(sale['pay_value'])
                if sale['pay_id'] == 3:
                    item['pay_3'] += float(sale['pay_value'])
                    item['inSub'] += float(sale['pay_value'])
                if sale['pay_id'] == 4:
                    item['pay_4'] += float(sale['pay_value'])
                    item['inSub'] += float(sale['pay_value'])
                if sale['pay_id'] == 5:
                    item['pay_5'] += float(sale['pay_value'])
                    item['inSub'] += float(sale['pay_value'])
                if sale['pay_id'] == 6:
                    item['pay_6'] += float(sale['pay_value'])
                    item['disc_6'] += float(sale['pay_value']) * paymentsRateDict[6]
                    item['inSub'] += float(sale['pay_value'])
                if sale['pay_id'] == 7:
                    item['pay_7'] += float(sale['pay_value'])
                    item['disc_7'] += float(sale['pay_value']) * paymentsRateDict[7]
                    item['inSub'] += float(sale['pay_value'])
                if sale['pay_id'] == 8:
                    item['pay_8'] += float(sale['pay_value'])
                    item['disc_8'] += float(sale['pay_value']) * paymentsRateDict[8]
                    item['inSub'] += float(sale['pay_value'])
                if sale['pay_id'] == 9:
#.........这里部分代码省略.........
开发者ID:KGPython,项目名称:kggroup,代码行数:103,代码来源:saleGroupByShop.py


注:本文中的sellcard.common.Method.dateRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。