Example #1
0
    def get(request):
        promotion_id = request.GET.get('id', None)
        if promotion_id:
            promotion = promotion_models.Promotion.objects.get(owner=request.manager, type=promotion_models.PROMOTION_TYPE_INTEGRAL_SALE, id=promotion_id)
            promotion_models.Promotion.fill_details(request.manager, [promotion], {
                'with_product': True,
                'with_concrete_promotion': True
            })
            promotion.products = sorted(promotion.products, key=lambda x: x.id)
            for product in promotion.products:
                product.models = product.models[1:]

            if promotion.member_grade_id:
                try:
                    promotion.member_grade_name = MemberGrade.objects.get(id=promotion.member_grade_id).name
                except:
                    promotion.member_grade_name = MemberGrade.get_default_grade(request.manager_profile.webapp_id).name


            jsons = [{
                "name": "product_models",
                # "content": promotion.products[0].models
                "content": [p.models for p in promotion.products]
            }]

            for rule in promotion.detail['rules']:
                if rule['member_grade_id'] > 0:
                    try:
                        rule['member_grade_name'] = MemberGrade.objects.get(id=rule['member_grade_id']).name
                    except:
                        pass
                else:
                    rule['member_grade_name'] = '全部等级'

            c = RequestContext(request, {
                'first_nav_name': export.MALL_PROMOTION_AND_APPS_FIRST_NAV,
                'second_navs': export.get_promotion_and_apps_second_navs(request),
                'second_nav_name': export.MALL_PROMOTION_SECOND_NAV,
                'third_nav_name': export.MALL_PROMOTION_INTEGRAL_SALE_NAV,
                'promotion': promotion,
                'jsons': jsons
            })

            return render_to_response('mall/editor/promotion/integral_sale_detail.html', c)
        else:
            member_grades = MemberGrade.get_all_grades_list(request.user_profile.webapp_id)
            c = RequestContext(request, {
                'member_grades': member_grades,
                'first_nav_name': export.MALL_PROMOTION_AND_APPS_FIRST_NAV,
                'second_navs': export.get_promotion_and_apps_second_navs(request),
                'second_nav_name': export.MALL_PROMOTION_SECOND_NAV,
                'third_nav_name': export.MALL_PROMOTION_INTEGRAL_SALE_NAV,
            })

            return render_to_response('mall/editor/promotion/create_integral_sale.html', c)
Example #2
0
def create_new_user_by_agent(request):
    username = request.POST['un']
    password = request.POST['pw']
    key = request.POST['key']
    mail = request.POST.get('mail', '*****@*****.**')
    use_year = int(request.POST.get('uy', 1))
    system_name = request.POST.get('sn', None)
    host_name = request.POST.get('hn', '')
    product_id = int(request.POST.get('pid', -1))
    company_name = request.POST.get('cn', None)
    manager_name = request.POST.get('mn', None)
    store_name = request.POST.get('stn', None)
    settlement_period = int(request.POST.get('sp', 1))
    is_formal = True if request.POST.get('at', 'formal') == 'formal' else False

    exist_users = User.objects.filter(username=username)
    if exist_users.count() > 0:
        response = create_response(DUPLICATE_USERNAME_ERROR_CODE)
        response.errMsg = u'该用户已存在'
        return response.get_response()

    if KEY != key:
        response = create_response(INVALID_KEY_ERROR_CODE)
        response.errMsg = u'非法的key'
        return response.get_response()

    user = None
    try:
        user = User.objects.create_user(username, mail, password)
        profile = user.get_profile()
        profile.expire_date_day = dateutil.yearsafter(use_year)
        profile.system_version = weapp_product_api.get_product_name(product_id)
        profile.host_name = host_name
        profile.store_name = store_name
        profile.settlement_period = settlement_period
        profile.is_formal = is_formal

        #add by duhao 20151016
        #从fans创建子账号时,需要设置manager账号的id
        if manager_name:
            try:
                manager_id = User.objects.get(username=manager_name).id
                profile.manager_id = manager_id
            except:
                pass

        if system_name is not None:
            profile.system_name = system_name

        profile.save()
        # 创建默认会员等级
        MemberGrade.get_default_grade(user.get_profile().webapp_id)
        #添加用户模块
        weapp_product_api.install_product_for_user(user, product_id)

        # 微众卡商户对应系统账号
        create_user = None
        try:
            create_user = User.objects.get(username='******')
        except:
            create_user = User.objects.get(username='******')
        WeizoomCardHasAccount.objects.create(owner=create_user,
                                             account=user,
                                             account_name=company_name)

        response = create_response(200)
    except:
        response = create_response(500)
        response.errMsg = u'创建失败,请稍后重试'
        response.innerErrMsg = unicode_full_stack()

        if user is not None:
            user.delete()

    return response.get_response()
Example #3
0
    def get(request):
        promotion_id = request.GET.get('id', None)
        if promotion_id:
            promotion = promotion_models.Promotion.objects.get(
                owner=request.manager,
                type=promotion_models.PROMOTION_TYPE_PRICE_CUT,
                id=promotion_id)
            promotion_models.Promotion.fill_details(
                request.manager, [promotion], {
                    'with_product': True,
                    'with_concrete_promotion': True
                })

            for product in promotion.products:
                product.models = product.models[1:]

            if promotion.member_grade_id:
                try:
                    promotion.member_grade_name = MemberGrade.objects.get(
                        id=promotion.member_grade_id).name
                except:
                    promotion.member_grade_name = MemberGrade.get_default_grade(
                        request.user_profile.webapp_id).name

            jsons = [{
                "name": "product_models",
                "content": promotion.products[0].models
            }]

            c = RequestContext(
                request, {
                    'first_nav_name':
                    export.MALL_PROMOTION_AND_APPS_FIRST_NAV,
                    'second_navs':
                    export.get_promotion_and_apps_second_navs(request),
                    'second_nav_name':
                    export.MALL_PROMOTION_SECOND_NAV,
                    'third_nav_name':
                    export.MALL_PROMOTION_PRICE_CUT_NAV,
                    'promotion':
                    promotion,
                    'jsons':
                    jsons
                })

            return render_to_response(
                'mall/editor/promotion/price_cut_detail.html', c)
        else:
            member_grades = MemberGrade.get_all_grades_list(
                request.user_profile.webapp_id)

            c = RequestContext(
                request, {
                    'member_grades':
                    member_grades,
                    'first_nav_name':
                    export.MALL_PROMOTION_AND_APPS_FIRST_NAV,
                    'second_navs':
                    export.get_promotion_and_apps_second_navs(request),
                    'second_nav_name':
                    export.MALL_PROMOTION_SECOND_NAV,
                    'third_nav_name':
                    export.MALL_PROMOTION_PRICE_CUT_NAV
                })

            return render_to_response(
                'mall/editor/promotion/create_price_cut.html', c)
Example #4
0
def step_impl(context, user, promotion_type):
    if promotion_type == u"促销":
        promotion_type = "all"
    elif promotion_type == u"限时抢购":
        promotion_type = "flash_sale"
    elif promotion_type == u"买赠":
        promotion_type = "premium_sale"
    elif promotion_type == u"积分应用":
        promotion_type = "integral_sale"
    # elif type == u"优惠券":
    #	 type = "coupon"
    url = '/mall2/api/promotion_list/?design_mode=0&version=1&type=%s' % promotion_type
    if hasattr(context, 'query_param'):
        if context.query_param.get('product_name'):
            url += '&name=' + context.query_param['product_name']
        if context.query_param.get('bar_code'):
            url += '&barCode=' + context.query_param['bar_code']
        if context.query_param.get('start_date'):
            url += '&startDate=' + bdd_util.get_datetime_str(
                context.query_param['start_date'])[:16]
        if context.query_param.get('end_date'):
            url += '&endDate=' + bdd_util.get_datetime_str(
                context.query_param['end_date'])[:16]
        if context.query_param.get('status', u'全部') != u'全部':
            if context.query_param['status'] == u'未开始':
                status = 1
            elif context.query_param['status'] == u'进行中':
                status = 2
            elif context.query_param['status'] == u'已结束':
                context.client.get(url)  #先获取一次数据,使status都更新到正常值
                status = 3
            url += '&promotionStatus=%s' % status
    response = context.client.get(url)
    actual = json.loads(response.content)['data']['items']

    # 实际数据
    for promotion in actual:
        if promotion['status'] != u'已结束':
            # 开启这2项操作(实际上在模板中,此时次2项不含hidden属性)。参考 flash_sales.html
            promotion['actions'] = [u'详情', u'结束']
        else:
            promotion['actions'] = [u'详情', u'删除']

        if promotion['promotionTitle'] != '':
            # 含有促销标题的
            promotion['promotion_title'] = promotion['promotionTitle']

        if promotion_type == 'integral_sale':
            for product in promotion['products']:
                if product['display_price_range'] != '':
                    product['price'] = product['display_price_range']
                else:
                    product['price'] = product['display_price']

                if product.get('status') and product['status'] == '在售':
                    product['status'] = ''

            promotion['is_permanant_active'] = str(
                promotion['detail']['is_permanant_active']).lower()
            detail = promotion['detail']
            rules = detail['rules']
            if len(rules) == 1 and rules[0]['member_grade_id'] < 1:
                rule = rules[0]
                rule['member_grade'] = u'全部会员'
                promotion['discount'] = str(rule['discount']) + '%'
                promotion['discount_money'] = rule['discount_money']
            else:
                promotion['discount'] = detail['discount'].replace(' ', '')
                promotion['discount_money'] = detail['discount_money'].replace(
                    ' ', '')
                for rule in rules:
                    rule['member_grade'] = MemberGrade.objects.get(
                        id=rule['member_grade_id']).name

            promotion['rules'] = rules
        else:
            promotion['product_name'] = promotion['product']['name']
            if promotion['product']['display_price_range'] != '':
                promotion['product_price'] = promotion['product'][
                    'display_price_range']
            else:
                promotion['product_price'] = promotion['product'][
                    'display_price']
            promotion['bar_code'] = promotion['product']['bar_code']
            promotion['price'] = promotion['product']['display_price']
            promotion['stocks'] = promotion['product']['stocks']

            if promotion_type == "flash_sale":
                promotion['promotion_price'] = promotion['detail'][
                    'promotion_price']

            else:
                member_grade_id = Promotion.objects.get(
                    id=promotion['id']).member_grade_id
                try:
                    promotion['member_grade'] = MemberGrade.objects.get(
                        id=member_grade_id).name
                except MemberGrade.DoesNotExist:
                    webapp_id = bdd_util.get_webapp_id_for(user)
                    promotion['member_grade'] = MemberGrade.get_default_grade(
                        webapp_id).name
    expected = []
    if context.table:
        expected = [promotion.as_dict() for promotion in context.table]
    else:
        expected = json.loads(context.text)

    # 转化feature中的格式,与actual一致
    for promotion in expected:
        if promotion_type == 'integral_sale':
            promotion['is_permanant_active'] = str(
                promotion.get('is_permanant_active', False)).lower()
        if promotion.has_key('start_date') and promotion.has_key('end_date'):
            if promotion.get('is_permanant_active', 'false') == 'true':
                promotion.pop('start_date')
                promotion.pop('end_date')
            else:
                promotion['start_date'] = bdd_util.get_datetime_str(
                    promotion['start_date'])
                promotion['end_date'] = bdd_util.get_datetime_str(
                    promotion['end_date'])
        if promotion.get('created_at'):
            promotion['created_at'] = bdd_util.get_datetime_str(
                promotion['created_at'])
    bdd_util.assert_list(expected, actual)
Example #5
0
    def api_post(request):
        post_grades = json.loads(request.POST.get('grades', []))
        if not post_grades:
            response = create_response(500)
            return response.get_response()

        webapp_id = request.user_profile.webapp_id
        original_member_grades = MemberGrade.get_all_grades_list(webapp_id)
        original_member_grade_ids = [
            grade.id for grade in original_member_grades
        ]
        default_grade = MemberGrade.get_default_grade(webapp_id)

        tmp_is_all_conditions = request.POST.get('is_all_conditions', '0')
        is_all_conditions = True if tmp_is_all_conditions == '1' else False
        IntegralStrategySttings.objects.filter(webapp_id=webapp_id).update(
            is_all_conditions=is_all_conditions)

        post_ids = []
        for grade in post_grades:
            grade_id = int(grade.get("id", '0'))
            post_ids.append(grade_id)

            name = grade.get("name", 'get none value')
            is_auto_upgrade = bool(int(grade.get("is_auto_upgrade", 0)))
            pay_money = grade.get("pay_money", 0)
            pay_times = grade.get("pay_times", 0)
            # upgrade_lower_bound = grade.get("upgrade_lower_bound", 0)
            upgrade_lower_bound = 0
            shop_discount = grade.get("shop_discount", '10')

            shop_discount = int(float(shop_discount) * 10)

            if grade_id == default_grade.id:
                MemberGrade.objects.filter(id=grade_id).update(
                    name=name, shop_discount=shop_discount)
            elif grade_id in original_member_grade_ids:
                if is_auto_upgrade:
                    MemberGrade.objects.filter(id=grade_id).update(
                        pay_money=pay_money,
                        pay_times=pay_times,
                        upgrade_lower_bound=upgrade_lower_bound,
                        name=name,
                        is_auto_upgrade=is_auto_upgrade,
                        shop_discount=shop_discount)
                else:
                    MemberGrade.objects.filter(id=grade_id).update(
                        name=name,
                        is_auto_upgrade=is_auto_upgrade,
                        shop_discount=shop_discount)
            else:
                if is_auto_upgrade:
                    MemberGrade.objects.create(
                        pay_money=pay_money,
                        pay_times=pay_times,
                        upgrade_lower_bound=upgrade_lower_bound,
                        name=name,
                        is_auto_upgrade=is_auto_upgrade,
                        shop_discount=shop_discount,
                        webapp_id=webapp_id)

                else:
                    MemberGrade.objects.create(name=name,
                                               is_auto_upgrade=is_auto_upgrade,
                                               shop_discount=shop_discount,
                                               webapp_id=webapp_id)

        delete_ids = list(
            set(original_member_grade_ids).difference(set(post_ids)))
        if delete_ids:
            if default_grade.id in delete_ids:
                delete_ids.remove(default_grade.id)

            member_ids = [
                member.id
                for member in Member.objects.filter(grade_id__in=delete_ids)
            ]
            Member.objects.filter(id__in=member_ids).update(
                grade=default_grade)

            MemberGrade.objects.filter(id__in=delete_ids).delete()
            for member_id in member_ids:
                member = Member.objects.get(id=member_id)
                auto_update_grade(member=member, delete=False)

            mall.module_api.update_promotion_status_by_member_grade(delete_ids)

        response = create_response(200)
        return response.get_response()
Example #6
0
    def get(request):
        """
        浏览限时抢购详情.
        """
        _type = request.GET.get('type')
        if not _type:
            promotion_id = request.GET['id']
            promotion = models.Promotion.objects.get(
                owner=request.manager,
                type=models.PROMOTION_TYPE_FLASH_SALE,
                id=promotion_id)
            models.Promotion.fill_details(request.manager, [promotion], {
                'with_product': True,
                'with_concrete_promotion': True
            })

            for product in promotion.products:
                product.models = product.models[1:]

            if promotion.member_grade_id:
                try:
                    promotion.member_grade_name = MemberGrade.objects.get(
                        id=promotion.member_grade_id).name
                except:
                    promotion.member_grade_name = MemberGrade.get_default_grade(
                        request.user_profile.webapp_id).name

            jsons = [{
                "name": "product_models",
                "content": promotion.products[0].models
            }]

            c = RequestContext(
                request, {
                    'first_nav_name':
                    export.MALL_PROMOTION_AND_APPS_FIRST_NAV,
                    'second_navs':
                    export.get_promotion_and_apps_second_navs(request),
                    'second_nav_name':
                    export.MALL_PROMOTION_SECOND_NAV,
                    'third_nav_name':
                    export.MALL_PROMOTION_FLASH_SALE_NAV,
                    'promotion':
                    promotion,
                    'jsons':
                    jsons
                })

            return render_to_response(
                'mall/editor/promotion/flash_sale_detail.html', c)
        elif _type == 'copy':
            """
            拷贝限时抢购

            @param id: promotion_id

            """
            promotion_id = request.GET['id']
            promotion = models.Promotion.objects.get(id=promotion_id)
            models.Promotion.fill_details(request.manager, [promotion],
                                          {'with_concrete_promotion': True})

            c = RequestContext(
                request, {
                    'first_nav_name':
                    export.MALL_PROMOTION_AND_APPS_FIRST_NAV,
                    'second_navs':
                    export.get_promotion_and_apps_second_navs(request),
                    'second_nav_name':
                    export.MALL_PROMOTION_SECOND_NAV,
                    'third_nav_name':
                    export.MALL_PROMOTION_FLASH_SALE_NAV,
                    'promotion':
                    promotion
                })

            return render_to_response(
                'mall/editor/promotion/create_flash_sale.html', c)
        elif _type == 'create':
            member_grades = MemberGrade.get_all_grades_list(
                request.user_profile.webapp_id)

            c = RequestContext(
                request, {
                    'member_grades':
                    member_grades,
                    'first_nav_name':
                    export.MALL_PROMOTION_AND_APPS_FIRST_NAV,
                    'second_navs':
                    export.get_promotion_and_apps_second_navs(request),
                    'second_nav_name':
                    export.MALL_PROMOTION_SECOND_NAV,
                    'third_nav_name':
                    export.MALL_PROMOTION_FLASH_SALE_NAV
                })

            return render_to_response(
                'mall/editor/promotion/create_flash_sale.html', c)
Example #7
0
    def inner_func():
        #user profile
        user_profile = account_models.UserProfile.objects.get(user_id=webapp_owner_id)
        webapp_id = user_profile.webapp_id

        #mpuser preview info
        try:
            mpuser = weixin_user_models.WeixinMpUser.objects.get(owner_id=webapp_owner_id)
            mpuser_preview_info = weixin_user_models.MpuserPreviewInfo.objects.get(mpuser=mpuser)
            try:
                weixin_mp_user_access_token = weixin_user_models.WeixinMpUserAccessToken.objects.get(mpuser=mpuser)
            except:
                weixin_mp_user_access_token = weixin_user_models.WeixinMpUserAccessToken()
        except:
            error_msg = u"获得user('{}')对应的mpuser_preview_info构建cache失败, cause:\n{}"\
                    .format(webapp_owner_id, unicode_full_stack())
            watchdog_warning(error_msg, user_id=webapp_owner_id)
            mpuser_preview_info = weixin_user_models.MpuserPreviewInfo()
            weixin_mp_user_access_token = weixin_user_models.WeixinMpUserAccessToken()
            mpuser = weixin_user_models.WeixinMpUser()

        #webapp
        try:
            webapp = webapp_models.WebApp.objects.get(owner_id=webapp_owner_id)
        except:
            error_msg = u"获得user('{}')对应的webapp构建cache失败, cause:\n{}"\
                    .format(webapp_owner_id, unicode_full_stack())
            watchdog_error(error_msg, user_id=webapp_owner_id, noraise=True)
            webapp = webapp_models.WebApp()

        #integral strategy
        try:
            integral_strategy_settings = member_models.IntegralStrategySttings.objects.get(webapp_id=webapp_id)
        except:
            error_msg = u"获得user('{}')对应的IntegralStrategySttings构建cache失败, cause:\n{}"\
                    .format(webapp_owner_id, unicode_full_stack())
            watchdog_error(error_msg, user_id=webapp_owner_id, noraise=True)
            integral_strategy_settings = member_models.IntegralStrategySttings()

        #member grade
        try:
            MemberGrade.get_default_grade(webapp_id)
            member_grades = [member_grade.to_dict() for member_grade in member_models.MemberGrade.objects.filter(webapp_id=webapp_id)]
        except:
            error_msg = u"获得user('{}')对应的MemberGrade构建cache失败, cause:\n{}"\
                    .format(webapp_owner_id, unicode_full_stack())
            watchdog_error(error_msg, user_id=webapp_owner_id, noraise=True)
            member_grades = []

        #pay interface
        try:
            pay_interfaces = [pay_interface.to_dict() for pay_interface in mall_models.PayInterface.objects.filter(owner_id=webapp_owner_id)]
        except:
            error_msg = u"获得user('{}')对应的PayInterface构建cache失败, cause:\n{}"\
                    .format(webapp_owner_id, unicode_full_stack())
            watchdog_error(error_msg, user_id=webapp_owner_id, noraise=True)
            pay_interfaces = []

        # 微众卡权限
        has_permission = AccountHasWeizoomCardPermissions.is_can_use_weizoom_card_by_owner_id(webapp_owner_id)

        try:
            operation_settings = account_models.OperationSettings.get_settings_for_user(webapp_owner_id)
        except:
            error_msg = u"获得user('{}')对应的OperationSettings构建cache失败, cause:\n{}"\
                    .format(webapp_owner_id, unicode_full_stack())
            watchdog_error(error_msg, user_id=webapp_owner_id, noraise=True)
            operation_settings = account_models.OperationSettings()
        #全局导航 ad by bert
        try:
            global_navbar = termite2_models.TemplateGlobalNavbar.get_object(webapp_owner_id)
        except:
            global_navbar = termite2_models.TemplateGlobalNavbar()

        try:
            auth_appid = ComponentAuthedAppid.objects.filter(user_id=webapp_owner_id)[0]
            auth_appid_info = ComponentAuthedAppidInfo.objects.filter(auth_appid=auth_appid)[0]
        except:
            auth_appid_info = ComponentAuthedAppidInfo()

            #member default tags
        try:
            default_member_tag = member_models.MemberTag.get_default_tag(webapp_id)
        except:
            default_member_tag = member_models.MemberTag()


        return {
            'value': {
                'weixin_mp_user_access_token': weixin_mp_user_access_token.to_dict(),
                "mpuser_preview_info": mpuser_preview_info.to_dict(),
                'webapp': webapp.to_dict(),
                'user_profile': user_profile.to_dict(),
                'mpuser': mpuser.to_dict(),
                'integral_strategy_settings': integral_strategy_settings.to_dict(),
                'member_grades': member_grades,
                'pay_interfaces': pay_interfaces,
                'has_permission': has_permission,
                'operation_settings': operation_settings.to_dict(),
                'global_navbar': global_navbar.to_dict(),
                'auth_appid_info': auth_appid_info.to_dict(),
                'default_member_tag': default_member_tag.to_dict()
            }
        }