コード例 #1
0
def apiRemCardBonus(request, card_code, salt):
    t_type = Operations.bonus_reduce
    if request.method == 'POST':
        data = request.POST
        if ('key' in data) and ('session_key' in data):
            box = check_license(data['key'], data['session_key'])
            if box:
                try:
                    org = box.co_unit.org
                except:
                    return HttpResponse(status=403)
                    org = None
            else:
                return HttpResponse(status=403)
            if org is not None:
                if org.is_active:
                    try:
                        if 'value' in data:
                            trans = Transaction().create(data)
                            trans.date = datetime.now()

                            card = Card.objects.get(code=card_code, org=org.pk)

                            trans.bonus_before = card.get_total_bonus()

                            # пишем статистику
                            trans.org = org
                            trans.card = card
                            trans.sum = 0
                            trans.bonus_reduce = float(data['value'])
                            trans.type = t_type
                            trans.save()

                            value = float(data['value'])
                            rem_bonus(card, value)

                            return HttpResponse(data['value'])
                        else:
                            return HttpResponse(status='404')
                    except ObjectDoesNotExist as e:
                        return HttpResponse(status='404')
                else:
                    return HttpResponse(status='503')
            else:
                return HttpResponse(status='503')
        else:
            return HttpResponse(status='503')
コード例 #2
0
def apiToCardFromService(request):
    if request.method == 'POST':
        data = request.POST
        if ('key' in data) and ('vtikeeper' in data):
            box = CashBox.get_by_key(data['key'])
            if box:
                try:
                    org = box.co_unit.org
                except:
                    org = None
            if org is not None:
                if org.is_active:
                    try:
                        if 'type' in data:
                            if data['type'] == 'add':
                                t_type = Operations.sell
                                if 'value' in data and 'card' in data:
                                    trans = Transaction().create(data)
                                    trans.date = datetime.strptime(
                                        data['datetime'], "%d.%m.%Y %H:%M:%S")
                                    card = Card.objects.get(code=data['card'],
                                                            org=org.pk)

                                    trans.bonus_before = card.get_total_bonus()

                                    d_plan = DiscountPlan.objects.get(
                                        org_id__exact=org.pk)
                                    algorithm = d_plan.algorithm
                                    card.accumulation += float(data['value'])
                                    card.last_transaction_date = datetime.now(
                                    ).date()
                                    card.save()

                                    # пишем статистику
                                    trans.org = org
                                    trans.card = card
                                    trans.sum = float(data['value'])
                                    trans.bonus_reduce = 0
                                    trans.type = t_type

                                    try:
                                        trans.base_doc_date = parse(
                                            data['base_doc_date'])
                                    except:
                                        trans.base_doc_date = None

                                    trans.save()

                                    try:  # Добавляем задание
                                        task = Task(
                                            queue_date=datetime.now(),
                                            execution_date=trans.date +
                                            relativedelta(
                                                days=d_plan.time_delay),
                                            data=data['value'],
                                            card=card,
                                            operation=identify_task_operation(
                                                card, d_plan),
                                            d_plan=d_plan,
                                            transaction=trans,
                                            org=card.org)
                                        task.save()
                                    except:
                                        pass

                                    return HttpResponse(data['value'])
                                else:
                                    return HttpResponse(status='404')
                            if data['type'] == 'rem':
                                t_type = Operations.bonus_reduce
                                if 'value' in data and 'card' in data:
                                    trans = Transaction().create(data)
                                    trans.date = datetime.strptime(
                                        data['datetime'], "%d.%m.%Y %H:%M:%S")
                                    card = Card.objects.get(code=data['card'],
                                                            org=org.pk)

                                    trans.bonus_before = card.get_total_bonus()

                                    # пишем статистику
                                    trans.org = org
                                    trans.card = card
                                    trans.sum = 0
                                    trans.bonus_reduce = float(data['value'])
                                    trans.type = t_type
                                    trans.save()

                                    value = float(data['value'])
                                    rem_bonus(card, value)

                                    return HttpResponse(data['value'])
                                else:
                                    return HttpResponse(status='404')

                    except ObjectDoesNotExist as e:
                        return HttpResponse(status='404')
                else:
                    return HttpResponse(status='503')
            else:
                return HttpResponse(status='503')
        else:
            return HttpResponse(status='503')
コード例 #3
0
def apiAddAccumToCard(request, card_code, salt):
    t_type = Operations.sell
    if request.method == 'POST':
        data = request.POST
        if ('key' in data) and ('session_key' in data):
            box = check_license(data['key'], data['session_key'])
            if box:
                try:
                    org = box.co_unit.org
                except:
                    return HttpResponse(status=403)
                    org = None
            else:
                return HttpResponse(status=403)
            if org is not None:
                if org.is_active:
                    try:
                        if 'value' in data:
                            value = float(data['value'])
                            trans = Transaction().create(data)
                            trans.date = datetime.now()
                            card = Card.objects.get(code=card_code, org=org.pk)

                            trans.bonus_before = card.get_total_bonus()
                            trans.org = org
                            trans.card = card
                            trans.sum = float(data['value'])
                            trans.bonus_reduce = 0
                            trans.type = t_type
                            try:
                                trans.base_doc_date = parse(
                                    data['base_doc_date'])
                            except:
                                trans.base_doc_date = None

                            d_plan = DiscountPlan.objects.get(
                                org_id__exact=org.pk)

                            algorithm = d_plan.algorithm
                            card.accumulation += float(data['value'])
                            card.last_transaction_date = datetime.now().date()
                            card.save()

                            if value < 0:
                                t_type = Operations.refund
                                trans.type = t_type
                                _handler = __import__(
                                    'core.lib.%s' %
                                    identify_task_operation(card, d_plan),
                                    globals(), locals(), ['count'], 0)
                                card = _handler.count(value, card, d_plan,
                                                      trans)
                                card.save()

                            trans.save()

                            if value > 0:
                                try:  # Добавляем задание
                                    # task = Task(queue_date=datetime.now(),
                                    #             execution_date= datetime.now().date() + relativedelta(days=d_plan.time_delay),
                                    #             data=data['value'],
                                    #             card=card,
                                    #             operation=identify_task_operation(card, d_plan),
                                    #             d_plan=d_plan,
                                    #             transaction=trans,
                                    #             org=card.org)
                                    # task.save()

                                    _handler = __import__(
                                        'core.lib.%s' %
                                        identify_task_operation(card, d_plan),
                                        globals(), locals(), ['count'], 0)
                                    card = _handler.count(
                                        value, card, d_plan, trans)
                                    card.save()

                                except:
                                    pass

                            return HttpResponse(data['value'])
                        else:
                            return HttpResponse(status='404')
                    except ObjectDoesNotExist as e:
                        return HttpResponse(status='404')
                else:
                    return HttpResponse(status='503')
            else:
                return HttpResponse(status='503')
        else:
            return HttpResponse(status='503')