Example #1
0
def get_spread_user_list(request, **kwargs):
    """
    我的推广者--推广人列表
    :param request:
    :return:
    """
    user_id = kwargs.get("userid")
    pagination = Pagination(request)
    start = pagination.start
    end = pagination.end
    try:
        results, items, has_next = {}, [], False
        user_relations = JieLongSpreadUserRelation.objects.filter(
            invite_sponsor_id=user_id, status=1)
        count = user_relations.count()
        logger.info("spreader_list, user_id: %s; count: %s" % (user_id, count))
        if count > 0:
            user_relations = user_relations.order_by("-update_time")[start:end]
            if count > end:
                has_next = True
            for user_relation in user_relations:
                items_dict = {}
                order_num_result = OrderService.total_commission_price(
                    seller_id=user_id,
                    spread_user_id=user_relation.passport_user_id)
                o_list, order_count = OrderService.order_list(
                    page_size=20,
                    page_no=1,
                    seller_id=user_id,
                    spread_user_id=user_relation.passport_user_id)

                items_dict["id"] = user_relation.passport_user.id
                items_dict["nick"] = jielong_service.get_covert_user_nickname(
                    user_relation.passport_user_id,
                    user_relation.passport_user.wechatuser.nickname)
                items_dict["avatar_url"] = jielong_service.covert_avatar_url(
                    user_relation.passport_user.wechatuser.avatar_url)
                items_dict["status"] = user_relation.status
                items_dict["commission_info"] = "共推广%s单,收入%s元" % (
                    order_count, order_num_result)
                items.append(items_dict)
        results["count"] = count
        results["items"] = items
        results["has_next"] = has_next
        code, msg = 0, "success"
        logger.info("get_spread_user_list: result:%s" % (results))
    except Exception as e:
        print(e)
        logger.info("get_spread_user_list: error:%s" % (e))
        code, msg = 90100, "服务器错误"
        results = {}
    result = {"meta": {"msg": msg, "code": code}, "results": results}
    return JsonResponse(result, encoder=DjangoJSONEncoder)
Example #2
0
def get_jielong_statistics_order_list(request, **kwargs):
    """
    数据统计-分享统计-查看推广详情
    :param request:
    :param kwargs: jielong_id, member_id, is_common
    :return:
    """
    user_id = kwargs.get("userid")
    jielong_id = int(request.GET.get("jielong_id", None))
    member_id = int(request.GET.get("member_id", None))
    is_common = int(request.GET.get("is_common", None))

    if not jielong_id or (is_common not in (1, 0)) or (not member_id):
        code, msg = 90001, "缺少参数"
        result = {"meta": {"msg": msg, "code": code}, "results": {}}
        return JsonResponse(result, encoder=DjangoJSONEncoder)
    results, items, has_next = {}, [], False
    pagination = Pagination(request)
    start, end = pagination.start, pagination.end

    logger.info(
        "jielong_statistics, user_id: %s; jielong_id:%s;member_id: %s;is_common: %s"
        % (user_id, jielong_id, member_id, is_common))
    if is_common:
        # 普通团员
        kwargs = {
            "user_id": member_id,
            "jielong_id": jielong_id,
            "seller_id": user_id
        }
        order_list, count = OrderService.order_list(
            page_size=pagination.page_size,
            page_no=pagination.page_no,
            **kwargs)
        total_order_price = OrderService.total_order_price(**kwargs)

        if order_list:
            if count > end:
                has_next = True

            for order in order_list:
                item_dict = {}

                item_dict["nick"] = jielong_service.get_covert_user_nickname(
                    order["user_id"], order["nickname"])
                item_dict["avatar_url"] = jielong_service.covert_avatar_url(
                    order["avatar_url"])
                item_dict["create_time"] = get_time_span(
                    (order["order_time"].strftime("%Y-%m-%d %H:%M:%S")))
                item_dict["goods_info"] = [
                    "%s ×%s  %s元" % (g["title"], g["buy_num"], g["price"])
                    for g in order["goods"]
                ]
                items.append(item_dict)
        results["subTitle"] = "共成交%s单,交易额%s元" % (count, total_order_price)
    else:
        # 推广人
        kwargs = {
            "spread_user_id": member_id,
            "jielong_id": jielong_id,
            "seller_id": user_id
        }
        order_list, count = OrderService.order_list(
            page_size=pagination.page_size,
            page_no=pagination.page_no,
            **kwargs)
        total_commission_price = OrderService.total_commission_price(**kwargs)
        total_order_price = OrderService.total_order_price(**kwargs)
        browse_nums = get_browse_nums_by_spreaduser(jielong_id, member_id)

        if order_list:
            if count > end:
                has_next = True
            for order in order_list:
                item_dict = {}
                item_dict["nick"] = jielong_service.get_covert_user_nickname(
                    order["user_id"], order["nickname"])
                item_dict["avatar_url"] = jielong_service.covert_avatar_url(
                    order["avatar_url"])
                item_dict["create_time"] = get_time_span(
                    order["order_time"].strftime("%Y-%m-%d %H:%M:%S"))
                item_dict["goods_info"] = [
                    "%s ×%s  %s元" % (g["title"], g["buy_num"], g["price"])
                    for g in order["goods"]
                ]
                item_dict["commission_info"] = "奖励%s元" % order["reward_price"]
                items.append(item_dict)

        results["subTitle"] = "邀请%s人浏览,成交%s单,佣金%s元,交易额%s元" % (
            browse_nums, count, total_commission_price, total_order_price)
    results["has_next"] = has_next
    results["items"] = items
    code, msg = 0, "success"
    result = {"meta": {"msg": msg, "code": code}, "results": results}

    return JsonResponse(result, encoder=DjangoJSONEncoder)
Example #3
0
def get_jielong_share_statistics(request, **kwargs):
    """
    数据统计-分享统计
    :param request: jielong_id, is_common
    :return:
    """
    user_id = kwargs.get("userid")
    jielong_id = int(request.GET.get("jielong_id", None))
    is_common = int(request.GET.get("is_common", None))
    if not jielong_id or (is_common not in (1, 0)):
        code, msg = 2, "缺少参数"
        result = {"meta": {"msg": msg, "code": code}, "results": {}}
        return JsonResponse(result, encoder=DjangoJSONEncoder)
    pagination = Pagination(request)
    start, end = pagination.start, pagination.end
    results, items, has_next = {}, [], False
    total_count, total_money, total_commission = 0, 0, 0
    spreaders = JieLongSpreadUserRelation.objects.filter(
        invite_sponsor_id=user_id, status=1)
    spreaders_ids = [sp.passport_user_id for sp in spreaders]
    logger.info("share_statistics,user_id:%s, jielong_id: %s, is_common: %s" %
                (user_id, jielong_id, is_common))
    try:
        if not is_common:
            # 推广人
            kwargs = {
                "jielong_id": jielong_id,
                "seller_id": user_id,
                # "other_query": Q(buyer_id__in=spreaders_ids),
                "spread_user_ids": spreaders_ids,
            }

            _, total_count = OrderService.order_list(**kwargs)
            total_money = OrderService.total_order_price(**kwargs)
            total_commission = OrderService.total_commission_price(**kwargs)

            order_users = OrderService.order_queryset(**kwargs)
            if order_users:
                user_ids = order_users.values_list("spread_user_id",
                                                   flat=True).distinct()
                # user_ids = [u for u in user_ids if u in spreaders_ids]
                logger.info("share_statistics, is_common: %s, user_ids: %s" %
                            (is_common, user_ids))
                count = user_ids.count()
                if count:
                    if count > end:
                        has_next = True
                    user_ids = user_ids[start:end]
                    for u_id in user_ids:
                        _, u_count = OrderService.order_list(
                            page_size=20,
                            page_no=1,
                            jielong_id=jielong_id,
                            spread_user_id=u_id)
                        u_commission = OrderService.total_commission_price(
                            jielong_id=jielong_id, spread_user_id=u_id)
                        we_user = WechatUser.objects.get(passport_user_id=u_id)
                        u_browse = ShareUserRelation.objects.filter(
                            jielong_id=jielong_id,
                            share_user_id=u_id).aggregate(
                                browse=Sum("browse_num"))["browse"] or 0
                        item_dict = {}
                        item_dict["member_id"] = u_id
                        item_dict[
                            "imageUrl"] = jielong_service.covert_avatar_url(
                                we_user.avatar_url)
                        item_dict[
                            "name"] = jielong_service.get_covert_user_nickname(
                                u_id, we_user.nickname)
                        item_dict["title"] = "邀请%s人浏览,成交%s单,佣金%s元" % (
                            u_browse, u_count, u_commission)
                        items.append(item_dict)
            sub_title = "共推广%s单,交易金额%s元,佣金%s元" % (total_count, total_money,
                                                  total_commission)
        else:
            # 普通团员
            kwargs = {
                "jielong_id": jielong_id,
                "seller_id": user_id,
                # "other_query": ~Q(buyer_id__in=spreaders_ids),
                "spread_user_id": user_id,
            }

            _, total_count = OrderService.order_list(**kwargs)
            total_money = OrderService.total_order_price(**kwargs)
            order_users = OrderService.order_queryset(**kwargs)
            if order_users:
                user_ids = order_users.values_list("buyer_id",
                                                   flat=True).distinct()
                logger.info("share_statistics, is_common: %s, user_ids: %s" %
                            (is_common, user_ids))
                count = user_ids.count()
                if count:
                    if count > end:
                        has_next = True
                    user_ids = user_ids[start:end]
                    for u_id in user_ids:
                        _, u_count = OrderService.order_list(
                            page_size=20,
                            page_no=1,
                            jielong_id=jielong_id,
                            user_id=u_id)
                        we_user = WechatUser.objects.get(passport_user_id=u_id)
                        u_browse = ShareUserRelation.objects.filter(
                            jielong_id=jielong_id,
                            share_user_id=u_id).aggregate(
                                browse=Sum("browse_num"))["browse"] or 0
                        item_dict = {}
                        item_dict["member_id"] = u_id
                        item_dict[
                            "imageUrl"] = jielong_service.covert_avatar_url(
                                we_user.avatar_url)
                        item_dict[
                            "name"] = jielong_service.get_covert_user_nickname(
                                u_id, we_user.nickname)
                        item_dict["title"] = "邀请%s人浏览,成交%s单" % (u_browse,
                                                                u_count)
                        items.append(item_dict)
            sub_title = "共成交%s单,交易额%s元" % (total_count, total_money)
        results["subTitle"] = sub_title
        results["items"] = items
        code, msg = 0, "success"
    except Exception as e:
        logger.info("share_statistics, Exception: %s" % e)
        code, msg = 90100, "服务器错误"
    results["has_next"] = has_next
    result = {"meta": {"msg": msg, "code": code}, "results": results}

    return JsonResponse(result, encoder=DjangoJSONEncoder)