def get_spreaders_by_orderuser(cls, **kwargs): # query = OrderService._parse_query_params(**kwargs) logger.info("get_spreaders_by_orderuser, kwargs: %s") spread_user_ids = OrderService.order_queryset(**kwargs).values("spread_user_id").distinct() count = spread_user_ids.count() if count > 0: spread_user_ids = [s["spread_user_id"] for s in spread_user_ids] return spread_user_ids, count
def get_jielong_ids(user_id): ''' 获取用户创建和参与的活动id :param user_id: :return: c_ids,p_ids,m_ids ''' c_jielongs = JieLong.objects.filter(passport_user_id=user_id).order_by( "-create_time", "status") c_ids = [] p_ids = [] m_ids = [] for c in c_jielongs: c_id = c.id c_ids.append(c_id) m_ids.append(c_id) p_jielongs = OrderService.order_queryset(user_id=user_id).values_list( "activity_id", flat=True).distinct() for p in p_jielongs: p_id = int(p) p_ids.append(p_id) m_ids.append(p_id) a_user = JieLongUserRelation.objects.filter(passport_user_id=user_id, is_attention=0) a_user_ids = [] for u in a_user: a_user_ids.append(u.jielong.passport_user_id) a_user_ids = list(set(a_user_ids)) a_jielongs = JieLong.objects.filter( passport_user_id__in=a_user_ids).order_by("-create_time", "status") a_ids = [] for a in a_jielongs: a_ids.append(a.id) m_ids.append(a.id) s_user_ids = [] # s_user = JieLongSpreadUserRelation.objects.filter(passport_user_id = user_id,status = 1) # for s in s_user: # s_user_ids.append(s.invite_sponsor_id) # s_jielongs = JieLong.objects.filter(passport_user_id__in=s_user_ids) # s_ids = [] # for s in s_jielongs: # s_ids.append(s.id) # m_ids.append(s.id) func = lambda x, y: x if y in x else x + [y] m_ids = reduce(func, [ [], ] + m_ids) logger.info("get_jielong_ids user-info a_user_ids: %s;s_user_ids:%s" % (a_user_ids, s_user_ids)) return c_ids, p_ids, m_ids
def get_my_follows(cls, **kwargs): """ 我的关注 """ pagination = kwargs.get("pagination", None) if not pagination: pagination = cls.paginator() follows = OrderService.order_queryset(**kwargs).values("seller_id").distinct() count = follows.count() follows = follows[pagination.start: pagination.end] if follows: follows = [f["seller_id"] for f in follows] logger.info("my_follows, kwargs: %s, count:%s, follows: %s" % (kwargs, count, follows)) return follows, count
def get_jielong_order(self, jielong_id): """ 根据接龙活动查订单 :param jielong_id: :return: channel order list """ other_query = ~Q( status__in=[OrderState.REFUNDING, OrderState.REFUNDED]) order_list = OrderService.order_queryset(jielong_id=jielong_id, other_query=other_query) count = order_list.count() print("channel:%s order num:%s" % (jielong_id, count)) return order_list
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)