Ejemplo n.º 1
0
    def api_get(request):
        """
		商品概况数据
		"""
        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        webapp_id = request.user_profile.webapp_id
        # owner_id = request.user_profile.user_id

        #购买总人数
        buyer_count = stats_util.get_buyer_count(webapp_id, low_date,
                                                 high_date)
        #下单单量
        order_count = stats_util.get_order_count(webapp_id, low_date,
                                                 high_date)
        #总成交件数
        deal_product_count = stats_util.get_deal_product_count(
            webapp_id, low_date, high_date)

        item = {
            'buyer_count': buyer_count,
            'order_count': order_count,
            'deal_product_count': deal_product_count
        }
        response = create_response(200)
        response.data = {'item': item, 'items': [], 'sortAttr': ''}

        return response.get_response()
Ejemplo n.º 2
0
    def api_get(request):
        low_date, high_date, date_range = stats_util.get_date_range(request)
        webapp_id = request.user_profile.webapp_id

        rank_list = _get_member_qrcode_rank(webapp_id, low_date, high_date)

        response = create_response(200)
        response.data = {'items': rank_list, 'sortAttr': ''}

        return response.get_response()
Ejemplo n.º 3
0
    def api_get(request):
        """
		下单单量排行top10
		"""
        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        webapp_id = request.user_profile.webapp_id

        top10_product_list = stats_util.get_top10_product(
            webapp_id, low_date, high_date)

        response = create_response(200)
        response.data = {'items': top10_product_list, 'sortAttr': ''}

        return response.get_response()
Ejemplo n.º 4
0
    def api_get(request):
        """
        返回销售额的EChart数据
        """
        low_date, high_date, date_range = stats_util.get_date_range(request)
        webapp_id = request.cloud_user.get_webapp_id()
        date_list = [
            date.strftime("%m/%d")
            for date in dateutil.get_date_range_list(low_date, high_date)
        ]

        price_trend_values = get_count_list_by_type(webapp_id,
                                                    date_list,
                                                    low_date,
                                                    high_date,
                                                    sign="price")

        name_2_values_list = [{"name": "销售额", "values": price_trend_values}]
        response = get_mobile_chart_response(date_list, name_2_values_list)
        return response
Ejemplo n.º 5
0
    def api_get(request):
        """
		下单单量排行top10柱状图
		"""
        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        webapp_id = request.user_profile.webapp_id

        top10_product_list = stats_util.get_top10_product(
            webapp_id, low_date, high_date)

        x_values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        y_values = []

        for item in top10_product_list:
            # x_values.append(item['rank'])
            y_values.append(item['num'])

        if len(y_values) == 0:
            y_values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        y_values_list = [{
            "name": "下单次数",
            "values": y_values,
            "tooltip": {
                "trigger": "item",
                "formatter": u"次数:{c}"
            },
            "barWidth": 20
        }]

        try:
            return create_bar_chart_response(x_values, y_values_list)
        except:
            if settings.DEBUG:
                raise
            else:
                response = create_response(500)
                response.innerErrMsg = unicode_full_stack()
                return response.get_response()
Ejemplo n.º 6
0
    def api_get(request):
        """
		会员概况分析API,获取基础数据和会员来源12项数据
		"""
        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        webapp_id = request.user_profile.webapp_id

        #会员总数
        total_member_count = stats_util.get_total_member_count(webapp_id)
        #新增会员
        new_member_count = stats_util.get_new_member_count(
            webapp_id, low_date, high_date)
        #新增手机绑定
        binding_phone_member_count = stats_util.get_binding_phone_member_count(
            webapp_id, low_date, high_date)
        #关注会员
        subscribed_member_count = stats_util.get_subscribed_member_count(
            webapp_id)
        #下单会员
        bought_member_count = stats_util.get_bought_member_count(
            webapp_id, low_date, high_date)
        #会员复购率
        repeat_buying_member_count = stats_util.get_repeat_buying_member_count(
            webapp_id, low_date, high_date)
        repeat_buying_member_rate = '0.00%'
        if bought_member_count > 0:
            repeat_buying_member_rate = str(
                round((
                    (repeat_buying_member_count + 0.0) / bought_member_count) *
                      100, 2)) + '%'
            if str(repeat_buying_member_rate) == '0.0%':
                repeat_buying_member_rate = '0.00%'
        #发起扫码会员和扫码新增会员
        ori_qrcode_member_count, member_from_qrcode_count = stats_util.get_ori_qrcode_member_count(
            webapp_id, low_date, high_date)
        #发起链接会员
        share_url_member_count = stats_util.get_share_url_member_count(
            webapp_id, low_date, high_date)
        #直接关注会员
        self_follow_member_count = stats_util.get_self_follow_member_count(
            webapp_id, low_date, high_date)
        #分享链接新增会员
        member_from_share_url_count = stats_util.get_member_from_share_url_count(
            webapp_id, low_date, high_date)
        #会员推荐率
        member_recommend_rate = '0.00%'
        _total_member_count = stats_util.get_total_member_count(
            webapp_id, high_date)
        if _total_member_count > 0:
            member_recommend_rate = str(
                round(
                    ((share_url_member_count + ori_qrcode_member_count + 0.0) /
                     _total_member_count) * 100, 2)) + '%'
            if str(member_recommend_rate) == '0.0%':
                member_recommend_rate = '0.00%'

        item = {
            'total_member_count': total_member_count,
            'subscribed_member_count': subscribed_member_count,
            'new_member_count': new_member_count,
            'binding_phone_member_count': binding_phone_member_count,
            'bought_member_count': bought_member_count,
            'repeat_buying_member_rate': repeat_buying_member_rate,
            'ori_qrcode_member_count': ori_qrcode_member_count,
            'share_url_member_count': share_url_member_count,
            'member_from_qrcode_count': member_from_qrcode_count,
            'self_follow_member_count': self_follow_member_count,
            'member_from_share_url_count': member_from_share_url_count,
            'member_recommend_rate': member_recommend_rate
        }
        response = create_response(200)
        response.data = {'items': item, 'sortAttr': ''}

        return response.get_response()
Ejemplo n.º 7
0
    def api_get(request):
        low_date, high_date, date_range = stats_util.get_date_range(request)
        date_formatter = stats_util.TYPE2FORMATTER['day']
        formatted_date_list = stats_util.get_formatted_date_list(
            date_range, date_formatter)
        formatted_date_list.reverse()  #反转日期列表,使之按日期倒序

        #获取当前页数
        cur_page = int(request.GET.get('page', '1'))
        #获取每页个数
        count_per_page = int(request.GET.get('count_per_page', 10))
        #先根据日期进行分页,避免全部查询出来的时候再分页,浪费时间降低效率
        pageinfo, formatted_date_list = paginator.paginate(
            formatted_date_list, cur_page, count_per_page, None)

        #根据当页的日期再获取一次low_date和high_date
        low_date, high_date, date_range = stats_util.get_date_range_for_data(
            request, formatted_date_list[-1], formatted_date_list[0])

        webapp_id = request.user_profile.webapp_id

        #新增会员
        date2new_member_count = stats_util.get_date2new_member_count(
            webapp_id, low_date, high_date)
        #手机绑定会员
        date2binding_phone_member_count = stats_util.get_date2binding_phone_member_count(
            webapp_id, low_date, high_date)
        #发起分享链接
        date2share_url_member_count = stats_util.get_date2share_url_member_count(
            webapp_id, low_date, high_date)
        #发起链接新增
        date2member_from_share_url_count = stats_util.get_date2member_from_share_url_count(
            webapp_id, low_date, high_date)
        #发起扫码和扫码新增
        date2qrcode_member_count = stats_util.get_date2ori_qrcode_member_count(
            webapp_id, low_date, high_date)
        #下单会员
        date2bought_member_count = stats_util.get_date2bought_member_count(
            webapp_id, low_date, high_date)

        items = []
        for date in formatted_date_list:
            new_member_count = 0
            if date2new_member_count.has_key(date):
                new_member_count = date2new_member_count[date]

            binding_phone_member_count = 0
            if date2binding_phone_member_count.has_key(date):
                binding_phone_member_count = date2binding_phone_member_count[
                    date]

            share_url_member_count = 0
            if date2share_url_member_count.has_key(date):
                share_url_member_count = date2share_url_member_count[date]

            member_from_share_url_count = 0
            if date2member_from_share_url_count.has_key(date):
                member_from_share_url_count = date2member_from_share_url_count[
                    date]

            ori_qrcode_member_count = 0
            member_from_qrcode_count = 0
            if date2qrcode_member_count.has_key(date):
                if date2qrcode_member_count[date].has_key(
                        'ori_qrcode_member_count'):
                    ori_qrcode_member_count = date2qrcode_member_count[date][
                        'ori_qrcode_member_count']
                if date2qrcode_member_count[date].has_key(
                        'member_from_qrcode_count'):
                    member_from_qrcode_count = date2qrcode_member_count[date][
                        'member_from_qrcode_count']

            bought_member_count = 0
            if date2bought_member_count.has_key(date):
                bought_member_count = date2bought_member_count[date]

            items.append({
                'date': date,
                'new_member_count': new_member_count,
                'binding_phone_member_count': binding_phone_member_count,
                'share_url_member_count': share_url_member_count,
                'member_from_share_url_count': member_from_share_url_count,
                'ori_qrcode_member_count': ori_qrcode_member_count,
                'member_from_qrcode_count': member_from_qrcode_count,
                'bought_member_count': bought_member_count
            })

        # #获取当前页数
        # cur_page = int(request.GET.get('page', '1'))
        # #获取每页个数
        # count_per_page = int(request.GET.get('count_per_page', 10))

        # pageinfo, items = paginator.paginate(items, cur_page, count_per_page, None)

        response = create_response(200)
        response.data = {
            'items': items,
            'pageinfo': paginator.to_dict(pageinfo),
            'sortAttr': ''
        }

        return response.get_response()
Ejemplo n.º 8
0
    def api_get(request):
        low_date, high_date, date_range = stats_util.get_date_range(request)
        webapp_id = request.user_profile.webapp_id
        date_formatter = stats_util.TYPE2FORMATTER['day']

        #新增会员数
        date2new_member_count = stats_util.get_date2new_member_count(
            webapp_id, low_date, high_date)

        #下单会员数
        date2bought_member_count = stats_util.get_date2bought_member_count(
            webapp_id, low_date, high_date)

        #绑定手机会员数
        date2binding_phone_member_count = stats_util.get_date2binding_phone_member_count(
            webapp_id, low_date, high_date)

        formatted_date_list = stats_util.get_formatted_date_list(
            date_range, date_formatter)

        #准备X轴日期数据
        x_values = formatted_date_list

        #准备Y轴数据
        new_member_count_list = []
        bought_member_count_list = []
        binding_phone_member_count_list = []

        for date in formatted_date_list:
            new_member_count = 0  #新增会员数
            if date2new_member_count.has_key(date):
                new_member_count = date2new_member_count[date]

            new_member_count_list.append(new_member_count)

            bought_member_count = 0  #下单会员数
            if date2bought_member_count.has_key(date):
                bought_member_count = date2bought_member_count[date]

            bought_member_count_list.append(bought_member_count)

            binding_phone_member_count = 0  #绑定手机会员数
            if date2binding_phone_member_count.has_key(date):
                binding_phone_member_count = date2binding_phone_member_count[
                    date]

            binding_phone_member_count_list.append(binding_phone_member_count)

        y_values = [
            {
                "name": "新增会员数",
                "values": new_member_count_list,
            },
            {
                "name": "下单会员数",
                "values": bought_member_count_list,
                # },{
                # 	"name": "绑定手机会员数",
                # 	"values" : binding_phone_member_count_list,
            }
        ]
        return create_line_chart_response('', '', x_values, y_values)
Ejemplo n.º 9
0
    def api_get(request):
        """
		获取订单概况数据	
		"""
        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        start_time = low_date
        end_time = high_date

        webapp_id = request.user_profile.webapp_id
        total_orders = belong_to(webapp_id)
        qualified_orders = total_orders.prefetch_related(
            'orderhasproduct_set').filter(
                #created_at__gte=start_time, created_at__lt=end_time,
                created_at__range=(start_time, end_time),
                status__in=[
                    models.ORDER_STATUS_PAYED_NOT_SHIP,
                    models.ORDER_STATUS_PAYED_SHIPED,
                    models.ORDER_STATUS_SUCCESSED
                ])

        order_num = qualified_orders.count()
        # 【成交金额】=∑订单.实付金额
        paid_amount = 0.0
        # 【成交商品】=∑订单.商品件数
        product_num = 0
        # 【优惠抵扣】=∑订单.积分抵扣金额 + +∑订单.优惠券抵扣金额
        discount_amount = 0.0

        for order in qualified_orders:
            # debug
            # order_id_str += order.order_id + "\n"
            if order.origin_order_id > 0:
                #商户从微众自营商城同步的子订单需要计算采购价
                tmp_paid_amount = order.total_purchase_price
            else:
                tmp_paid_amount = order.final_price + order.weizoom_card_money
            paid_amount += tmp_paid_amount

            for r in order.orderhasproduct_set.all():
                product_num += r.number

            discount_amount += float(order.integral_money) + float(
                order.coupon_money)
            #postage_amount += float(order.postage)

        item = {
            # 【成交订单】=∑订单.个数
            'order_num': order_num,
            # 【成交金额】=∑订单.实付金额
            'paid_amount': paid_amount,
            # 【成交商品】=∑订单.商品件数
            'product_num': product_num,
            # 【优惠抵扣】=∑订单.积分抵扣金额 + +∑订单.优惠券抵扣金额
            'discount_amount': discount_amount
        }

        if start_time and end_time:
            response = create_response(200)
            response.data = {'items': item, 'sortAttr': ''}
            return response.get_response()
        else:
            response = create_response(500)
            response.errMsg = u'未指定查询时间段'
            return response.get_response()
Ejemplo n.º 10
0
    def api_get(request):

        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        start_time = low_date
        end_time = high_date

        webapp_id = request.user_profile.webapp_id
        total_orders = belong_to(webapp_id)
        qualified_orders = total_orders.prefetch_related(
            'orderhasproduct_set').filter(
                # created_at__gte=start_time, created_at__lt=end_time,
                created_at__range=(start_time, end_time),
                status__in=[
                    models.ORDER_STATUS_PAYED_NOT_SHIP,
                    models.ORDER_STATUS_PAYED_SHIPED,
                    models.ORDER_STATUS_SUCCESSED
                ])

        # 【优惠抵扣】=∑订单.积分抵扣金额 + +∑订单.优惠券抵扣金额
        discount_amount = 0.0
        # 【总运费】=∑订单.运费金额
        postage_amount = 0.0
        # 【在线付款订单】=∑订单.个数
        online_order_num = 0
        # 【在线付款订单金额】=∑订单.实付金额
        online_paid_amount = 0.0
        # 【货到付款订单】=∑订单.个数
        cod_order_num = 0
        # 【货到付款订单金额】=∑订单.实付金额
        cod_amount = 0.0
        # 支付宝支付金额:=∑订单.支付宝支付金额
        alipay_amount = 0.0
        # 微信支付金额:=∑订单.微信支付金额
        weixinpay_amount = 0.0
        # 微众卡支付金额:=∑订单.微众卡支付金额
        wezoom_card_amount = 0.0
        # 复购订单数
        repeated_num = 0
        bestpay_amount = 0.0  #翼支付金额
        kangou_amount = 0.0  #看购支付金额

        for order in qualified_orders:
            # debug
            # order_id_str += order.order_id + "\n"
            if order.origin_order_id > 0:
                #商户从微众自营商城同步的子订单需要计算采购价
                tmp_paid_amount = order.total_purchase_price
            else:
                tmp_paid_amount = order.final_price + order.weizoom_card_money
            # paid_amount += tmp_paid_amount

            # for r in order.orderhasproduct_set.all():
            # 	product_num += r.number

            discount_amount += float(order.integral_money) + float(
                order.coupon_money)
            postage_amount += float(order.postage)

            if order.pay_interface_type == models.PAY_INTERFACE_COD:
                cod_order_num += 1
                cod_amount += float(order.final_price)
            else:
                # 在线付款需求修改时去掉
                # online_order_num += 1
                # online_paid_amount += tmp_paid_amount

                if order.pay_interface_type == models.PAY_INTERFACE_ALIPAY:
                    alipay_amount += float(order.final_price)
                elif order.pay_interface_type == models.PAY_INTERFACE_BEST_PAY:
                    bestpay_amount += float(order.final_price)
                elif order.pay_interface_type == models.PAY_INTERFACE_KANGOU:
                    kangou_amount += float(order.final_price)
                elif order.pay_interface_type == models.PAY_INTERFACE_WEIXIN_PAY:
                    if order.origin_order_id > 0:  #判断同步订单
                        weixinpay_amount += float(order.total_purchase_price)
                    else:
                        weixinpay_amount += float(order.final_price)

            wezoom_card_amount += float(order.weizoom_card_money)

        #在线付款需求修改时添加
        #online_order_num = order_num - cod_order_num
        #online_paid_amount = paid_amount - cod_amount

        # 系统封装的饼图方法,由于数据次序不统一,故舍弃使用
        # return create_pie_chart_response('',
        # 		{
        # 			# 'discount_amount': discount_amount,
        # 			# 'postage_amount': postage_amount,
        # 			# 'online_order_num': online_order_num,
        # 			# 'online_paid_amount': online_paid_amount,
        # 			# 'cod_order_num': cod_order_num,
        # 			'支付宝': round(alipay_amount,2),
        # 			'微信支付': round(weixinpay_amount,2),
        # 			'货到付款': round(cod_amount,2),
        # 			'微众卡支付': round(wezoom_card_amount,2),
        # 			'翼支付': round(bestpay_amount,2),
        # 			'看购支付': round(kangou_amount,2)
        # 		}
        # 	)

        response = create_response(200)
        response.data = {
            "alipay_amount": round(alipay_amount, 2),
            "weixinpay_amount": round(weixinpay_amount, 2),
            "cod_amount": round(cod_amount, 2),
            "wezoom_card_amount": round(wezoom_card_amount, 2),
            "bestpay_amount": round(bestpay_amount, 2),
            "kangou_amount": round(kangou_amount, 2)
        }

        return response.get_response()
Ejemplo n.º 11
0
    def api_get(request):

        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        start_time = low_date
        end_time = high_date

        webapp_id = request.user_profile.webapp_id
        total_orders = belong_to(webapp_id)
        qualified_orders = total_orders.prefetch_related(
            'orderhasproduct_set').filter(
                # created_at__gte=start_time, created_at__lt=end_time,
                created_at__range=(start_time, end_time),
                status__in=[
                    models.ORDER_STATUS_PAYED_NOT_SHIP,
                    models.ORDER_STATUS_PAYED_SHIPED,
                    models.ORDER_STATUS_SUCCESSED
                ])

        # 优惠抵扣统计
        discount_stats = {
            # 订单总量:=∑订单.个数
            'discount_order_num': 0,
            # 微众卡支付:=∑订单.个数
            'wezoom_num': 0,
            # 微众卡支付金额:=∑订单.微众卡支付金额
            'wezoom_amount': 0.0,
            # 积分抵扣:=∑订单.个数
            'integral_num': 0,
            # 积分抵扣金额:=∑订单.积分抵扣金额
            'integral_amount': 0.0,
            # 优惠券:=∑订单.个数
            'coupon_num': 0,
            # 优惠券金额:=∑订单.优惠券金额
            'coupon_amount': 0.0,
            # 微众卡+积分:=∑订单.个数
            'wezoom_integral_num': 0,
            # (微众卡+积分)金额:=∑订单.(微众卡+积分)金额
            'wezoom_integral_amount': 0.0,
            # 微众卡+优惠券:=∑订单.个数
            'wezoom_coupon_num': 0,
            # (微众卡+优惠券)金额:=∑订单.(微众卡+优惠券)金额
            'wezoom_coupon_amount': 0.0,
            # 积分+优惠券:=∑订单.个数
            # 'integral_coupon_num': 0,
            # (积分+优惠券)金额:=∑订单.(积分+优惠券)金额
            # 'integral_coupon_amount': 0.0,
            # 微众卡+积分+优惠券:=∑订单.个数
            #'wezoom_integral_coupon_num': 0,
            # (微众卡+积分+优惠券)金额:=∑订单.(微众卡+积分+优惠券)金额
            #'wezoom_integral_coupon_amount': 0.0
        }
        for order in qualified_orders:
            _do_discount_stats(discount_stats, order)
            discount_stats['discount_order_num'] = discount_stats[
                'wezoom_num'] + discount_stats['coupon_num'] + discount_stats[
                    'integral_num'] + discount_stats[
                        'wezoom_coupon_num'] + discount_stats[
                            'wezoom_integral_num']

        response = create_response(200)
        response.data = {'discount_stats': discount_stats, 'sortAttr': ''}

        return response.get_response()
Ejemplo n.º 12
0
    def api_get(request):

        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        start_time = low_date
        end_time = high_date

        webapp_id = request.user_profile.webapp_id
        total_orders = belong_to(webapp_id)
        qualified_orders = total_orders.prefetch_related(
            'orderhasproduct_set').filter(
                # created_at__gte=start_time, created_at__lt=end_time,
                created_at__range=(start_time, end_time),
                status__in=[
                    models.ORDER_STATUS_PAYED_NOT_SHIP,
                    models.ORDER_STATUS_PAYED_SHIPED,
                    models.ORDER_STATUS_SUCCESSED
                ])

        status_qualified_orders = total_orders.filter(status__in=[
            models.ORDER_STATUS_PAYED_NOT_SHIP,
            models.ORDER_STATUS_PAYED_SHIPED, models.ORDER_STATUS_SUCCESSED
        ])
        pre_status_qualified_orders = status_qualified_orders.filter(
            created_at__lt=start_time)
        past_status_qualified_orders = status_qualified_orders.filter(
            created_at__lt=end_time)

        #买家来源
        buyer_source_stats = {
            # “直接关注购买”:=∑订单.个数
            'sub_source_num': 0,
            # “推广扫码购买”:=∑订单.个数
            'qrcode_source_num': 0,
            # “分享链接购买”:=∑订单.个数
            'url_source_num': 0,
            # “其他”:=∑订单.个数
            'other_source_num': 0
        }

        webapp_user_ids = set(
            [order.webapp_user_id for order in past_status_qualified_orders])
        webappuser2member = Member.members_from_webapp_user_ids(
            webapp_user_ids)
        for order in qualified_orders:
            tmp_member = webappuser2member.get(order.webapp_user_id, None)
            if tmp_member:
                if tmp_member.source == SOURCE_SELF_SUB:
                    buyer_source_stats['sub_source_num'] += 1
                elif tmp_member.source == SOURCE_MEMBER_QRCODE:
                    buyer_source_stats['qrcode_source_num'] += 1
                elif tmp_member.source == SOURCE_BY_URL:
                    buyer_source_stats['url_source_num'] += 1
                else:
                    buyer_source_stats['other_source_num'] += 1
            else:
                buyer_source_stats['other_source_num'] += 1

        # 系统封装的饼图方法,由于数据次序不统一,故舍弃使用
        # return create_pie_chart_response('',
        # 		{
        # 			"直接关注购买":buyer_source_stats['sub_source_num'],
        # 		 	"推广扫码购买":buyer_source_stats['qrcode_source_num'],
        # 		 	"分享链接购买":buyer_source_stats['url_source_num'],
        # 		 	"其他":buyer_source_stats['other_source_num']
        # 		}
        # 	)

        response = create_response(200)
        response.data = {
            "sub_source_num": buyer_source_stats['sub_source_num'],
            "qrcode_source_num": buyer_source_stats['qrcode_source_num'],
            "url_source_num": buyer_source_stats['url_source_num'],
            "other_source_num": buyer_source_stats['other_source_num']
        }

        return response.get_response()
Ejemplo n.º 13
0
    def api_get(request):

        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        start_time = low_date
        end_time = high_date

        # 用于检查复购订单的辅助List
        wuid_dict = {'pos': 0}

        webapp_id = request.user_profile.webapp_id
        total_orders = belong_to(webapp_id)
        qualified_orders = total_orders.prefetch_related(
            'orderhasproduct_set').filter(
                # created_at__gte=start_time, created_at__lt=end_time,
                created_at__range=(start_time, end_time),
                status__in=[
                    models.ORDER_STATUS_PAYED_NOT_SHIP,
                    models.ORDER_STATUS_PAYED_SHIPED,
                    models.ORDER_STATUS_SUCCESSED
                ])

        status_qualified_orders = total_orders.filter(status__in=[
            models.ORDER_STATUS_PAYED_NOT_SHIP,
            models.ORDER_STATUS_PAYED_SHIPED, models.ORDER_STATUS_SUCCESSED
        ])
        pre_status_qualified_orders = status_qualified_orders.filter(
            created_at__lt=start_time)
        past_status_qualified_orders = status_qualified_orders.filter(
            created_at__lt=end_time)

        # 订单总量
        order_num = qualified_orders.count()
        # 重复购买
        repeated_num = 0

        webapp_user_ids = set(
            [order.webapp_user_id for order in past_status_qualified_orders])
        webappuser2member = Member.members_from_webapp_user_ids(
            webapp_user_ids)

        for order in qualified_orders:
            tmp_member_two = webappuser2member.get(order.webapp_user_id, None)

            # t0 = time.clock()
            # t1 = time.time()
            # print ">>>>>"
            repeated_num += _get_repeated_num_increment(
                order.webapp_user_id, wuid_dict, tmp_member_two,
                webappuser2member, pre_status_qualified_orders)
            # __report_performance(t0, t1, "repeat counter")

        # 初次购买
        first_buy = order_num - repeated_num

        # 系统封装的饼图方法,由于数据次序不统一,故舍弃使用
        # return create_pie_chart_response('',
        # 		{
        # 			"重复购买":repeated_num,
        # 		 	"初次购买":first_buy
        # 		}
        # 	)

        response = create_response(200)
        response.data = {"first_buy": first_buy, "repeated_num": repeated_num}

        return response.get_response()
Ejemplo n.º 14
0
    def api_get(request):

        # 时间区间
        low_date, high_date, date_range = stats_util.get_date_range(request)
        start_time = low_date
        end_time = high_date

        webapp_id = request.user_profile.webapp_id
        total_orders = belong_to(webapp_id)
        qualified_orders = total_orders.prefetch_related(
            'orderhasproduct_set').filter(
                #created_at__gte=start_time, created_at__lt=end_time,
                created_at__range=(start_time, end_time),
                status__in=[
                    models.ORDER_STATUS_PAYED_NOT_SHIP,
                    models.ORDER_STATUS_PAYED_SHIPED,
                    models.ORDER_STATUS_SUCCESSED
                ])

        orders = qualified_orders

        # 待发货:已付款,未发货
        order_count = orders.count()
        if order_count > 0:
            data = [(order.id, order.status) for order in orders]
            df = pd.DataFrame(data, columns=['id', 'status'])
            counts = df['status'].value_counts()  # 按status的值统计频度

            #not_shipped_num = orders.filter(status=models.ORDER_STATUS_PAYED_NOT_SHIP).count()
            not_shipped_num = int(
                counts.get(models.ORDER_STATUS_PAYED_NOT_SHIP, 0))
            # 已发货:已付款,已发货
            #shipped_num = orders.filter(status=models.ORDER_STATUS_PAYED_SHIPED).count()
            shipped_num = int(counts.get(models.ORDER_STATUS_PAYED_SHIPED, 0))
            # 已完成:自下单10日后自动置为已完成状态
            #succeeded_num = orders.filter(status=models.ORDER_STATUS_SUCCESSED).count()
            succeeded_num = int(counts.get(models.ORDER_STATUS_SUCCESSED, 0))
        else:
            not_shipped_num = 0
            # 已发货:已付款,已发货
            shipped_num = 0
            # 已完成:自下单10日后自动置为已完成状态
            succeeded_num = 0

        # 系统封装的饼图方法,由于数据次序不统一,故舍弃使用
        # return create_pie_chart_response('',
        # 		{
        # 			"待发货":not_shipped_num,
        # 		 	"已发货":shipped_num,
        # 		 	"已完成":succeeded_num
        # 		}
        # 	)

        response = create_response(200)
        response.data = {
            "not_shipped_num": not_shipped_num,
            "shipped_num": shipped_num,
            "succeeded_num": succeeded_num
        }

        return response.get_response()
Ejemplo n.º 15
0
    def api_get(request):
        """
		经营概况分析API  获取店铺经营概况各项统计数据

		"""
        low_date, high_date, date_range = stats_util.get_date_range(request)
        webapp_id = request.user_profile.webapp_id

        #商品复购率

        #商品推荐指数

        #成交金额
        transaction_money, transaction_orders = stats_util.get_transaction_money_order_count(
            webapp_id, low_date, high_date)
        #成交订单

        #购买总人数
        buyer_count = stats_util.get_buyer_count(webapp_id, low_date,
                                                 high_date)

        #客单价
        if transaction_orders > 0:
            vis_price = transaction_money / transaction_orders
        else:
            vis_price = 0

        #发起扫码会员和扫码新增会员
        # ori_qrcode_member_count, member_from_qrcode_count = stats_util.get_ori_qrcode_member_count(webapp_id, low_date, high_date)

        #发起分享链接会员
        # share_url_member_count = stats_util.get_share_url_member_count(webapp_id, low_date, high_date)

        #分享链接新增会员
        # member_from_share_url_count = stats_util.get_member_from_share_url_count(webapp_id, low_date, high_date)

        #会员复购率
        # bought_member_count = stats_util.get_bought_member_count(webapp_id, low_date, high_date)
        # repeat_buying_member_count = stats_util.get_repeat_buying_member_count(webapp_id, low_date, high_date)
        # repeat_buying_member_rate = '0.00%'
        # if bought_member_count > 0:
        #	 repeat_buying_member_rate = "%.2f%%" % (repeat_buying_member_count * 100.0 / bought_member_count)

        #会员推荐率
        # member_recommend_rate = '0.00%'
        # total_member_count = stats_util.get_total_member_count(webapp_id,high_date)
        # if total_member_count > 0:
        #	 member_recommend_rate = "%.2f%%" % ((share_url_member_count + ori_qrcode_member_count)*100.0 / total_member_count)
        result = {
            # 'repeat_buying_member_rate': repeat_buying_member_rate,
            # 'member_recommend_rate': member_recommend_rate,
            'transaction_orders': transaction_orders,
            # 'ori_qrcode_member_count': ori_qrcode_member_count,
            # 'member_from_qrcode_count': member_from_qrcode_count,
            # 'share_url_member_count': share_url_member_count,
            # 'member_from_share_url_count': member_from_share_url_count,
            'transaction_money': "%.2f" % transaction_money,
            'vis_price': "%.2f" % vis_price,
            'buyer_count': buyer_count
        }

        response = create_response(200)
        response.data = {'items': result, 'sortAttr': ''}

        return response.get_response()
Ejemplo n.º 16
0
    def api_get(request):
        low_date, high_date, date_range = stats_util.get_date_range(request)
        try:
            webapp_id = request.user_profile.webapp_id
            date_list = [
                date.strftime("%Y-%m-%d")
                for date in dateutil.get_date_range_list(low_date, high_date)
            ]

            date2count = dict()
            date2price = dict()

            # 11.20从查询mall_purchase_daily_statistics变更为直接统计订单表,解决mall_purchase_daily_statistics遗漏统计订单与统计时间不一样导致的统计结果不同的问题。
            orders = Order.objects.belong_to(webapp_id).filter(
                created_at__range=(low_date, (high_date + timedelta(days=1))))
            statuses = set([
                ORDER_STATUS_PAYED_SUCCESSED, ORDER_STATUS_PAYED_NOT_SHIP,
                ORDER_STATUS_PAYED_SHIPED, ORDER_STATUS_SUCCESSED
            ])
            orders = [
                order for order in orders
                if (order.type != 'test') and (order.status in statuses)
            ]
            for order in orders:
                # date = dateutil.normalize_date(order.created_at)
                date = order.created_at.strftime("%Y-%m-%d")
                if order.webapp_id != webapp_id:
                    order_price = Order.get_order_has_price_number(
                        order) + order.postage
                else:
                    order_price = order.final_price + order.weizoom_card_money

                if date in date2count:
                    old_count = date2count[date]
                    date2count[date] = old_count + 1
                else:
                    date2count[date] = 1

                if date in date2price:
                    old_price = date2price[date]
                    date2price[date] = old_price + order_price
                else:
                    date2price[date] = order_price

            price_trend_values = []

            #当最后一天是今天时,折线图中不显示最后一天的数据 duhao 2015-08-12
            #当起止日期都是今天时,数据正常显示
            today = dateutil.get_today()
            if len(date_list) > 1 and date_list[-1] == today:
                del date_list[-1]

            for date in date_list:
                price_trend_values.append("%.2f" % (date2price.get(date, 0.0)))

            return create_line_chart_response('', '', date_list,
                                              [{
                                                  "name": "销售额",
                                                  "values": price_trend_values
                                              }])
        except:
            if settings.DEBUG:
                raise
            else:
                response = create_response(500)
                response.innerErrMsg = unicode_full_stack()
                return response.get_response()