Ejemplo n.º 1
0
def index(request, **kwargs):
    """
    会员首页
    """
    error = ""
    template_name = "member/base.html"
    UserBasic = kwargs.pop("Mem")
    request.session["contactor_name"] = UserBasic.name
    print request.session["contactor_name"]
    ValueSetting = value_setting.objects.defer("grade_summit", "mall_VIP_threshold").all()[0]
    UserBasic = get_submmit_level(UserBasic=UserBasic)

    #    cursor = connection.cursor()
    #    try:
    #        cursor.execute('SELECT FA_SUM.father_id as min_id , max(MA_SUM.id) as summit_level FROM (SELECT FATHER.id AS father_id , count(SON.id) AS summit_son_number FROM member_user_recommender AS RECC INNER JOIN member_user_basic AS FATHER ON FATHER.id = RECC.recommending_id INNER JOIN member_user_basic AS SON ON SON.id = RECC.recommended_id ,management_value_setting AS SETTING WHERE SON.mall_team_score > SETTING.grade_summit GROUP BY FATHER.id AS FA_SUM INNER JOIN management_mall_summit AS MA_SUM ON FA_SUM.summit_son_number >= MA_SUM.summit_num where FA_SUM.father_id=%s GROUP BY min_id',UserBasic.id)
    #        cursor.execute('SELECT `V_SETTLE_CWEB_BASIC`.`level_name`,`V_SETTLE_CWEB_BASIC`.`threshold_value`,`V_SETTLE_CWEB_BASIC`.`gain_rate`,`V_SETTLE_CWEB_BASIC`.`is_summit` FROM `rtyk_triple`.`V_SETTLE_CWEB_BASIC` where id=%s',UserBasic.id)
    #        level = cursor.fetchall()[0]
    #        is_summit = level[3]
    #        UserBasic.level = level[0]
    #        UserBasic.is_summit = is_summit
    #    except:
    #        UserBasic.level = "新手上路"
    #        UserBasic.is_summit = False
    notices = Notice.objects.notices_for(request.user, on_site=True, unseen=True)
    request.session["ValueSetting"] = ValueSetting
    request.session["name"] = UserBasic.name
    if request.method == "POST":
        password_2nd = request.POST.get("password_2nd")
        result = verify_password_2nd(password_2nd, request.user)
        if result:
            request.session["password_2nd"] = True
            return HttpResponseRedirect(reverse("member_index"))
        else:
            error = "二级密码错误"
    ctx = {"UserBasic": UserBasic, "error": error, "notices": notices}
    return render_to_response(template_name, RequestContext(request, ctx))
Ejemplo n.º 2
0
def member_details(request, template_name=None, **kwargs):
    """
    会员和报单中心查看自己的详细信息
    """
    UserBasic = kwargs.pop("UserBasic")
    request.session["subject"] = "member_center"
    UserAddress = ""
    role = ""
    Level = ""
    UserRecommender = ""
    UMid = ""
    UserContactor = ""
    UMax = ""
    error3 = ""
    error1 = request.GET.get("error1")
    error2 = request.GET.get("error2")
    ValueSetting = value_setting.objects.defer("stock_share_out_min_amount").get(id=1)
    if not UserBasic:
        try:
            UserBasic = user_basic.objects.filter(user=request.user)[0]
        except:
            raise Http404
    try:
        UserAddress = user_address.objects.filter(user=UserBasic).order_by("id")[0]
    except:
        UserAddress = None
    try:
        UserRecommender = user_recommender.objects.filter(recommended=UserBasic)[0]
        UserBasic.recommending_id = UserRecommender.recommending.number
        UserBasic.recommending_name = UserRecommender.recommending.name
    except:
        UserRecommender = user_recommender(recommended=UserBasic)
        UserBasic.recommending_id = "无"
        UserBasic.recommending_name = "无"
    if UserBasic.role != "MemMin" and UserBasic.role != "MinVIP":
        try:
            UserMidMem = user_mid_mem.objects.filter(user=UserBasic)
            print UserMidMem, "UserMidMem"
            UMid = UserMidMem[0]
            UserBasic.level = UMid.level.level
            UserBasic.level_name = UMid.level.name
            Level = member_lv_money.objects.all()
        except:
            pass
        try:
            UserContactor = user_contactor.objects.filter(contacted=UserBasic)[0]
            UserBasic.contacting_id = UserContactor.contacting.number
            UserBasic.contacting_name = UserContactor.contacting.name
            UserBasic.contact_area = UserContactor.contact_area
        except:
            UserContactor = user_contactor(contacted=UserBasic)
            UserBasic.contacting_id = "无"
            UserBasic.contacting_name = "无"
            UserBasic.contact_area = "无"

    UserCentralUsual = None
    # 报单中心信息
    if UserBasic.role == "MemMax":
        print UserBasic.role, "================"
        try:
            UserMaxMem = user_max_mem.objects.filter(user_mid=UMid)
            print UserMaxMem, "bbbbbbb"
            UMax = UserMaxMem[0]
            print UMax, "==================="
            if not UMax.is_central:
                try:
                    UserCentralUsual = user_central_usual.objects.filter(user_usual=UMax)[0]
                    print UserCentralUsual, "ssss"
                    UserBasic.user_central_number = UserCentralUsual.user_central.user_mid.user.number
                    UserBasic.user_central_name = UserCentralUsual.user_central.user_mid.user.name
                except:
                    print "sss"
            if UMax.is_central == True:
                UserBasic.is_central = True
            else:
                UserBasic.is_central = False
        except:
            print "ss"
    UserBasic.sum = UserBasic.cash + UserBasic.stock_rebuy + UserBasic.stock_repeat
    try:
        UserAdder = user_adder.objects.defer("adding").filter(added=UserBasic)[0]
    except:
        UserAdder = None
    if request.method == "POST":
        can_share_out = request.POST.get("can_share_out")
        if can_share_out:
            if not UserBasic.can_share_out:
                UserBasic.can_share_out = True
                extra_context = "申请分红成功"
                users = User.objects.filter(is_superuser=True)
                notification.send(UserBasic.user, "share_appl", extra_context, True, request.user)
        else:
            if UserBasic.can_share_out:
                UserBasic.can_share_out = False

        id_card_number = request.POST.get("id_card_number")
        if id_card_number:
            UserBasic.id_card_number = id_card_number
        stock_hold_max = request.POST.get("stock_hold_max")
        if stock_hold_max:
            UserBasic.stock_hold_max = stock_hold_max
        number = request.POST.get("number")
        if number:
            UserBasic.number = request.POST.get("number")
        bank_account_id = request.POST.get("bank_account_id")
        if bank_account_id:
            UserBasic.bank_account_id = bank_account_id
        city = request.POST.get("city")
        if city:
            UserBasic.city = city
        role = request.POST.get("role")
        can_devide = request.POST.get("can_devide")
        if can_devide:
            if not UserBasic.can_devide:
                UserBasic.can_devide = True
        else:
            if UserBasic.can_devide:
                UserBasic.can_devide = False
        is_void = request.POST.get("is_void")
        if is_void:
            if not UserBasic.is_void:
                UserBasic.is_void = True
        else:
            if UserBasic.is_void:
                UserBasic.is_void = False
        if role:
            UserBasic.role = role
            if role == "MemVIP":
                extra_context = "恭喜你成为了商城VIP"
                notification.send(UserBasic.user, "vip_appl", extra_context, True, request.user)
                MinUpgradeRecord = min_upgrade_record.objects.filter(user=UserBasic)
                if MinUpgradeRecord:
                    UserBasic.bank_name = MinUpgradeRecord[0].bank_name
                    UserBasic.bank_account_id = MinUpgradeRecord[0].bank_account_id
                    UserBasic.bank_account_name = MinUpgradeRecord[0].bank_account_name
                    UserBasic.id_card_number = MinUpgradeRecord[0].id_card_number
                    MinUpgradeRecord.state = "sure"
                    MinUpgradeRecord.save()

            elif role == "MemMax":
                UMax = user_max_mem(user_mid=UMid)
                UMax.save()

            elif role == "MemMin":
                try:
                    UMax.delete()
                except:
                    pass
        user_central = request.POST.get("user_central")
        if user_central:
            _userBasic = user_basic.objects.get(number=user_central)
            print _userBasic, "_userBasic"
            if _userBasic:
                _userMidMem = user_mid_mem.objects.get(user=_userBasic)

                print _userMidMem, "_userMidMem"
                if _userMidMem:
                    _userMaxMem = user_max_mem.objects.get(user_mid=_userMidMem)
                    if UserCentralUsual and _userMaxMem:
                        UserCentralUsual.user_central = _userMaxMem
                        UserCentralUsual.save()
                    if not UserCentralUsual and _userMaxMem:
                        print _userMaxMem, "======================"
                        UserCentralUsual = user_central_usual()
                        UserCentralUsual.user_central = _userMaxMem
                        UserCentralUsual.user_usual = UMax
                        UserCentralUsual.save()

        bank_name = request.POST.get("bank_name")
        if bank_name:
            UserBasic.bank_name = bank_name
        phone = request.POST.get("phone")
        if phone:
            UserBasic.phone = phone
        QQ = request.POST.get("QQ")
        if QQ:
            UserBasic.QQ = QQ

        name = request.POST.get("name")
        if name:
            UserBasic.name = name
        bank_account_name = request.POST.get("bank_account_name")
        if bank_account_name:
            UserBasic.bank_account_name = bank_account_name
        mobile = request.POST.get("mobile")
        if mobile:
            UserBasic.mobile = mobile
        gender = request.POST.get("gender")
        if gender:
            UserBasic.gender = gender
        start_date = request.POST.get("start_date")
        if start_date:
            UserBasic.start_date = start_date

        level = request.POST.get("level")
        if level:
            if UMid.level.id != level:
                _Level = Level.get(id=level)
                upgrade_choice = request.POST.get("upgrade_choice")

                # if UserBasic.is_void:
                #   UMid.init_money = _Level.money - UMid.level.money
                #  UserBasic.is_void = False
                # UserBasic.save()
                # else:
                #    UMid.init_money = _Level.money

                if upgrade_choice:
                    if UserBasic.is_void:
                        UMid.init_money = _Level.money - UMid.level.money
                        UserBasic.is_void = False
                        UserBasic.save()
                    else:
                        UMid.init_money = _Level.money
                    call_proc = CallProc()
                    call_proc.CallProcFuc_2("member_update", UserBasic.id, _Level.money)
                UMid.level = _Level
                UMid.save()
        recommending = request.POST.get("recommending")
        if recommending:
            #            try:

            UBasic = user_basic.objects.defer(None).filter(number=recommending)[0]

            UserRecommender.recommending = UBasic
            UserRecommender.save()
        #            except:
        #                error1 = "推荐人不存在"
        proxy_style = request.POST.get("proxy_style")
        if proxy_style:
            if proxy_style == "1":
                UserBasic.proxy_city = None
                UserBasic.proxy_area = None
                UserBasic.proxy_province = None
            else:
                proxy_province = request.POST.get("proxy_province")
                proxy_city = request.POST.get("proxy_city")
                proxy_area = request.POST.get("proxy_area")
                UserBasic.proxy_city = proxy_city
                UserBasic.proxy_area = proxy_area
                UserBasic.proxy_province = proxy_province
        contacting = request.POST.get("contacting")
        if contacting:
            try:
                UBasic = user_basic.objects.defer(None).filter(number=contacting)[0]
                UserContactor.contacting = UBasic
                UserContactor.save()
            except:
                error2 = "接点人不存在"
        contact_area = request.POST.get("contact_area", None)
        if contact_area:
            if UserContactor:
                if UserContactor.contact_area != contact_area:
                    UserContactor.contact_area = contact_area
                    UserContactor.save()
            else:
                UserContactor = user_contactor.objects.filter(contacted=UserBasic)[0]

        style = request.POST.get("style")
        if style:
            if style == "1":
                UMax.is_central = False
            else:
                UMax.is_central = True
            UMax.save()
        try:
            UserBasic.save()
        except:
            error3 = "编号不能重复"
        url = reverse("management_change_mem_info") + "?user_number=" + UserBasic.number
        if error1:
            url += "&error1=" + error1
        if error2:
            url += "&error2=" + error2
        return HttpResponseRedirect(url)
    UserBasic.stock_hold = UserBasic.stock_hold_0devide + UserBasic.stock_hold_1devide + UserBasic.stock_hold_2devide
    #    ValueSetting = request.session.get('ValueSetting')
    try:
        grade_summit = ValueSetting.grade_summit
        mall_VIP_threshold = ValueSetting.mall_VIP_threshold
    except:
        grade_summit = None
        mall_VIP_threshold = None
    UserBasic = get_submmit_level(UserBasic=UserBasic)
    #    count_a = 0
    #    count_b=0
    #    count_sum = 0
    #    count_info = request.session.get("count_info")
    #    if not count_info:
    count_info = getCountInfo(UserBasic.id)
    #    request.session["count_info"] = count_info
    count_a = count_info[5]
    count_b = count_info[6]
    count_sum = count_info[7]

    ctx = {
        "UserBasic": UserBasic,
        "UserAddress": UserAddress,
        "role": UserBasic.role,
        "Level": Level,
        "grade_summit": grade_summit,
        "mall_VIP_threshold": mall_VIP_threshold,
        "stock_share_out_min_amount": ValueSetting.stock_share_out_min_amount,
        "count_a": count_a,
        "count_b": count_b,
        "count_sum": count_sum,
        "UserAdder": UserAdder,
        "error1": error1,
        "error2": error2,
        "error3": error3,
    }
    return render_to_response(template_name, RequestContext(request, ctx))