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)
def get_jielong_order_list(request): jielong_id = request.GET.get("jielong_id", None) if not jielong_id: result = {"meta": {"msg": "API请求参数错误", "code": 90001}} logger.info("get_jielong_order_list result jielong_id %s" % (jielong_id)) return JsonResponse(result, encoder=DjangoJSONEncoder) pagination = Pagination(request) order_list, count = OrderService.order_list(page_no=pagination.page_no, page_size=pagination.page_size, jielong_id=jielong_id) has_next = False if len(order_list) <= pagination.page_size else True orders = [] if len(order_list) > 0: index = len(order_list) for o in order_list: goods_info = [] goods = o["goods"] if len(goods): for g in goods: g_info = "%s(%s元) x %s" % (g["title"], g["price"], g["buy_num"]) goods_info.append(g_info) item = { "index": index, "nick": jielong_service.get_covert_user_nickname( o["user_id"], o["nickname"]), "avatar_url": jielong_service.covert_avatar_url(o["avatar_url"]), "create_time": get_time_span(o["order_time"].strftime("%Y-%m-%d %H:%M:%S")), "order_info": "已支付%s元" % (o["order_price"]), "specifications_info": goods_info } orders.append(item) index -= 1 result = { "meta": { "msg": "", "code": 0 }, "results": { "has_next": has_next, "items": orders } } return JsonResponse(result, encoder=DjangoJSONEncoder)
def get_share_browse_user_list(request, **kwargs): """ 我的分享:浏览的人 :param request: :return: """ user_id = kwargs.get("userid") jielong_id = request.GET.get("jielong_id", None) pagination = Pagination(request) start = pagination.start end = pagination.end results, items, has_next = {}, [], False if not jielong_id: code, msg = 90001, "缺少参数" logger.info("share_browser_list, user_id: %s, code:%s; msg: %s" % (user_id, code, msg)) result = {"meta": {"msg": msg, "code": code}, "results": results} return JsonResponse(result, encoder=DjangoJSONEncoder) jielong_id = int(jielong_id) share_user_relations = ShareUserRelation.objects.filter( share_user_id=user_id, jielong_id=jielong_id) count = share_user_relations.count() logger.info("share_browser, jielong_id:%s; count:%s, user_id: %s" % (jielong_id, count, user_id)) if count > 0: share_user_relations = share_user_relations.order_by( "-update_time")[start:end] if count > end: has_next = True for share_user_relation in share_user_relations: items_dict = {} browse_user = share_user_relation.browse_user items_dict["avatar_url"] = jielong_service.covert_avatar_url( browse_user.wechatuser.avatar_url) items_dict["nick"] = jielong_service.get_covert_user_nickname( browse_user.id, browse_user.wechatuser.nickname) items_dict["create_time"] = get_time_span( UtilDateTime.utc2local(share_user_relation.update_time)) items.append(items_dict) results["has_next"] = has_next results["items"] = items results["subTitle"] = "%s人浏览" % count code, msg = 0, "success" result = {"meta": {"msg": msg, "code": code}, "results": results} return JsonResponse(result, encoder=DjangoJSONEncoder)
def get_my_fans_by_user_id(cls, user_id, pagination=None): """ 我的粉丝 """ if not pagination: pagination = cls.paginator() fans = JieLongUserRelation.objects.filter(jielong__passport_user_id=user_id).values_list("passport_user_id", flat=True).distinct() count = fans.count() logger.info("my_fans, user_id: %s, count: %s" % (user_id, count)) fans = fans[pagination.start: pagination.end] fans_list = [] if fans: for f_id in fans: items_dict = {} we_user = WechatUser.objects.get(passport_user_id=f_id) items_dict["id"] = f_id items_dict["nick"] = get_covert_user_nickname(f_id, we_user.nickname) items_dict["avatar_url"] = covert_avatar_url(we_user.avatar_url) fans_list.append(items_dict) return fans_list, count
def get_my_follows_list(request, **kwargs): """ 个人中心: 我的关注 :param request: :param kwargs: :return: """ user_id = kwargs.get("userid") pagination = Pagination(request) kwargs = { "user_id": user_id, "other_query": ~Q(seller_id=user_id), "pagination": pagination } start, end = pagination.start, pagination.end follows, count = CustomerService.get_my_follows(**kwargs) result, items, has_next = {}, [], False if follows: if count > end: has_next = True for follow in follows: items_dict = {} p_user = PassportUser.objects.get(id=follow) items_dict["nick"] = jielong_service.get_covert_user_nickname( follow, p_user.wechatuser.nickname) items_dict["avatar_url"] = jielong_service.covert_avatar_url( p_user.wechatuser.avatar_url) items.append(items_dict) result = { "meta": { "msg": "success", "code": 0 }, "results": { "count_info": "共关注了%s人" % count, "has_next": has_next, "items": items } } return JsonResponse(result, encoder=DjangoJSONEncoder)
def get_jielong_list(request, **kwargs): pagination = Pagination(request) start = pagination.start end = pagination.end user_id = kwargs.get("userid", None) ############################## c_ids, p_ids, m_ids = jielong_service.get_jielong_ids(user_id) jielongs = JieLong.objects.filter(id__in=m_ids).order_by( "-display_order", "-create_time")[start:end] # count = jielongs.count() count = len(m_ids) ############################## # jielongs = jielongs[start:end] if count > end: has_next = True else: has_next = False jielong = [] if jielongs: for j in jielongs: order_list, count = OrderService.order_list(page_no=1, page_size=5, jielong_id=j.id) jielong_detail = { "id": j.id, "avatar_url": jielong_service.covert_avatar_url( j.passport_user.wechatuser.avatar_url), "nickname": jielong_service.get_covert_user_nickname( j.passport_user.id, j.passport_user.wechatuser.nickname), "time_info": "%s发起 , %s人看过 , %s人参与" % (get_time_span(UtilDateTime.utc2local( j.create_time)), j.browse_num, count), "title": j.title, "thumb_images": [sm for sm in j.small_images.split(" ")] if j.small_images else [], "status": jielong_service.get_jielong_status(j.id), "details": jielong_service.format_index_jielong_order(order_list), "label": jielong_service.get_jielong_label(j.id, c_ids, p_ids) } jielong.append(jielong_detail) result = { "meta": { "msg": "", "code": 0 }, "results": { "has_next": has_next, "items": jielong } } return JsonResponse(result, encoder=DjangoJSONEncoder)
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)
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)
def get_share_join_user_list(request, **kwargs): """ 我的分享:参与的人 :param request: jielong_id :return: """ user_id = kwargs.get("userid") pagination = Pagination(request) jielong_id = request.GET.get("jielong_id", None) if not jielong_id: code, msg = 2, "缺少参数" result = {"meta": {"msg": msg, "code": code}, "results": {}} return JsonResponse(result, encoder=DjangoJSONEncoder) jielong_id = int(jielong_id) jielong = JieLong.objects.get(id=jielong_id) inviter_id = jielong.passport_user_id spreader_ids, _ = CustomerService.get_my_spreaders_by_inviter_id( inviter_id, pagination=pagination, is_all=True) results, items, is_spreader = {}, [], False if user_id in spreader_ids: is_spreader = True logger.info( "share_join_users,user_id:%s; jielong_id: %s; inviter_id: inviter_id: %s; is_spreader: %s" % (user_id, jielong_id, inviter_id, is_spreader)) order_list, count = OrderService.order_list(page_no=pagination.page_no, page_size=pagination.page_size, spread_user_id=user_id, jielong_id=jielong_id) commission_info = OrderService.count_data(spread_user_id=user_id, jielong_id=jielong_id) total_commssion_price = commission_info["order_commission_price"] total_order_num = commission_info["order_num"] has_next = False if len(order_list) <= pagination.page_size else True if len(order_list) > 0: for o in order_list: goods_info = [] goods = o["goods"] if len(goods) > 0: for g in goods: g_info = "%s(%s) x%s" % (g["title"], g["sku_desc"], g["buy_num"]) goods_info.append(g_info) items_dict = { "nick": jielong_service.get_covert_user_nickname( o["user_id"], o["nickname"]), "avatar_url": jielong_service.covert_avatar_url(o["avatar_url"]), "create_time": get_time_span(o["order_time"].strftime("%Y-%m-%d %H:%M:%S")), "goods_info": goods_info, } if is_spreader: items_dict["commission_info"] = "奖励%s元" % o["reward_price"] items.append(items_dict) results = { "has_next": has_next, "subTitle": "%s人下单" % total_order_num, "items": items } if is_spreader: results["total_commission"] = "共获得%s元奖励" % total_commssion_price result = { "meta": { "msg": "success", "code": 0, }, "results": results } logger.info("get_share_join_user_list, results: %s;" % (results)) return JsonResponse(result, encoder=DjangoJSONEncoder)