예제 #1
0
    def list(self, request):
        '''
        # 账户列表
        '''
        # 过滤
        query_param = {
            'payment_account_uuid': request.GET.get('payment_account_uuid',
                                                    None),
            'is_valid': request.GET.get('is_valid', None),
            'user_uuid': request.GET.get('user_uuid', None),
            'balance__gte': request.GET.get('balance__gte', None),
            'balance__lte': request.GET.get('balance__lte', None),
            'credit__gte': request.GET.get('credit__gte', None),
            'credit__lte': request.GET.get('credit__lte', None),
        }
        try:
            records = PaymentAccount.objects.filter(**get_kwargs(query_param))
            count = records.count()
        except ValueError:
            log.error('[account] list account error, queryParams: %s',
                      str(query_param))
            return Response({
                'detail': '参数错误',
                'error_code': '1400'
            },
                            status=status.HTTP_400_BAD_REQUEST)

        # 排序分页
        desc, limit, offset = get_query_paganaiton(request)
        queryset = records.order_by(desc + 'create_time')[offset:offset +
                                                          limit]
        serializer = PaymentAccountListCreateSerializer(queryset, many=True)
        return Response({'count': count, 'content': serializer.data})
예제 #2
0
파일: views.py 프로젝트: liyq1406/haihang
    def list(self, request):
        """
        对账异常列表
        """
        # 过滤
        query_param = {
            'payment_no': request.GET.get('payment_no', None),
            'error_type': request.GET.get('error_type', None),
            'deal_status': request.GET.get('deal_status', None),
        }
        try:
            records = Reconciliation.objects.filter(**get_kwargs(query_param))
            count = records.count()
        except ValueError:
            return Response({
                'detail': '参数错误',
                'error_code': '4400'
            },
                            status=status.HTTP_400_BAD_REQUEST)

        # 排序分页
        desc, limit, offset = get_query_paganaiton(request)
        queryset = records.order_by(desc + 'create_time')[offset:offset +
                                                          limit]
        serializer = ReconciliationSerializer(queryset, many=True)
        return Response({'count': count, 'content': serializer.data})
예제 #3
0
 def retrieve(self, request, pk=None):
     '''
     通过账户uuid查询指定账户记录
     '''
     # 过滤
     query_param = {
         'modify_balance__gte': request.GET.get('modify_balance__gte',
                                                None),
         'modify_balance__lte': request.GET.get('modify_balance__lte',
                                                None),
         'modify_source_uuid': request.GET.get('modify_source_uuid', None),
         'modify_source_type': request.GET.get('modify_source_type', None),
         'payment_account_uuid': pk
     }
     try:
         records = AccountRecord.objects.filter(**get_kwargs(query_param))
         count = records.count()
     except ValueError:
         log.error(
             '[account] get account info error, payment_account_uuid: %s',
             pk)
         return Response({
             'detail': '参数错误',
             'error_code': '1400'
         },
                         status=status.HTTP_400_BAD_REQUEST)
     # 排序分页
     desc, limit, offset = get_query_paganaiton(request)
     queryset = records.order_by(desc + 'create_time')[offset:offset +
                                                       limit]
     serializer = AccountRecordSerializer(queryset, many=True)
     return Response({'count': count, 'content': serializer.data})
예제 #4
0
파일: views.py 프로젝트: liyq1406/haihang
    def list_all(self, request):
        """
        优惠码列表
        """
        # 过滤
        query_param = {
            'coupon_code': request.GET.get('coupon_code', None),
            'coupon_uuid': request.GET.get('coupon_uuid', None),
            'coupon_type': request.GET.get('coupon_type', None),
            'coupon_value__gte': request.GET.get('coupon_value__gte', None),
            'coupon_value__lte': request.GET.get('coupon_value__lte', None),
            'valid_datetime_start__lte': request.GET.get('valid_datetime_start__lte', None),
            'valid_datetime_end__gte': request.GET.get('valid_datetime_end__gte', None),
        }
        try:
            records = Coupon.objects.filter(**get_kwargs(query_param))
            count = records.count()
        except ValueError:
            log.error('[coupon] list coupon error queryset: %s', str(queryset))
            return Response({
                'detail': '参数错误',
                'error_code': '2400'
            }, status=status.HTTP_400_BAD_REQUEST)

        # 排序分页
        desc, limit, offset = get_query_paganaiton(request)
        queryset = records.order_by(desc + 'create_time')[offset:offset+limit]
        serializer = CouponSerialzer(queryset, many=True)
        return Response({'count':count,'content':serializer.data})
예제 #5
0
파일: views.py 프로젝트: liyq1406/haihang
    def usage(self, request):
        """
        # 查询指定条件下优惠码使用记录
        """
        # 过滤
        query_param = {
            'coupon_code': request.GET.get('coupon_code', None),
            'user_uuid': request.GET.get('user_uuid', None),
            'coupon_usage_uuid': request.GET.get('coupon_usage_uuid', None),
            'usage_source_type': request.GET.get('usage_source_type', None),
            'usage_source_uuid': request.GET.get('usage_source_uuid', None),
        }
        try:
            records = CouponUsage.objects.filter(**get_kwargs(query_param))
            count = records.count()
        except ValueError:
            return Response({
                'detail': '参数错误',
                'error_code': '2400'
            }, status=status.HTTP_400_BAD_REQUEST)

        # 排序分页
        desc, limit, offset = get_query_paganaiton(request)
        queryset = records.order_by(desc + 'use_time')[offset:offset+limit]
        serializer = CouponUsageSerialzer(queryset, many=True)
        return Response({'count':count,'content':serializer.data})
예제 #6
0
파일: tasks.py 프로젝트: liyq1406/haihang
def check_paypal_detail(paypal_history, writer):
    for payment in paypal_history.payments:
        # 获取账单金额
        for transaction in payment.transactions:
            payment_amount = transaction.amount.total

        record = {
            'payment_no': payment.id,
            'payment_record': u' ',
            'third_record': str(payment)
        }
        csvrow = []
        try:
            payment_record = Payment.objects.get(payment_no=payment.id)
            record['payment_record'] = payment_record.payment_uuid
            if abs(payment_record.real_price -
                   float(payment_amount) * 100) > 0.01:
                record['error_type'] = u'amount'
                reconciliation_save(**get_kwargs(record))
                log.error('[reconciliation] paypal amount valid fail %s',
                          payment.id)
            if payment.state == 'approved' and payment_record.paid_status != 'success':
                record['error_type'] = u'status'
                reconciliation_save(**get_kwargs(record))
                log.error('[reconciliation] paypal status valid fail %s',
                          payment.id)
            csvrow = get_payment_info(payment_record) + get_paypal_info(
                payment)
        except Payment.DoesNotExist:
            record['error_type'] = u'miss'
            reconciliation_save(**get_kwargs(record))
            log.error('[reconciliation] paypal record miss %s', payment.id)
            csvrow = get_payment_info() + get_paypal_info(payment)
        except Payment.MultipleObjectsReturned:
            record['error_type'] = u'multi'
            reconciliation_save(**get_kwargs(record))
            log.error('[reconciliation] paypal record multi %s', payment.id)
            csvrow = get_payment_info() + get_paypal_info(payment)
        log.info(csvrow)
        writer.writerow(csvrow)
예제 #7
0
파일: cms.py 프로젝트: liyq1406/haihang
def create_account(request):
    if request.method == 'POST':
        account_form = AccountForm(request.POST)
        if account_form.is_valid():
            account = PaymentAccount(**get_kwargs(account_form.cleaned_data))
            account.save()
            log.info("[account] payment account %s create success",
                     account.payment_account_uuid)
            return HttpResponseRedirect('/cms/price/?page=1')
        else:
            data = {'account_form': account_form, 'mode': u'create'}
            log.info("bad request")
            return render(request, 'account_edit.html', data)
    else:
        data = {'account_form': AccountForm(), 'mode': u'create'}
    return render(request, 'account_edit.html', data)
예제 #8
0
파일: views.py 프로젝트: liyq1406/haihang
    def get_bills_bycondition(self, request):
        """
        后台根据条件产看账单
        :param request:
        :return:
        """
        query_param = {
            'bill_uuid':
            request.GET.get('bill_uuid', None),
            'user_uuid':
            request.GET.get('user_uuid', None),
            'host_uuid':
            request.GET.get('host_uuid', None),
            'pay_status':
            request.GET.get('pay_status', None),
            'bill_account_time__gte':
            request.GET.get('bill_account_time__gte', None),
            'bill_account_time__lte':
            request.GET.get('bill_account_time__lte', None)
        }

        try:
            total_bills = Bill.objects.filter(**get_kwargs(query_param))
            count = total_bills.count()
            desc, limit, offset = get_query_paganaiton(request)
            bills = total_bills.order_by('bill_account_time')[offset:offset +
                                                              limit]
            serializer = BillSerializer(bills, many=True)
            return Response({'content': serializer.data, 'count': count})
        except KeyError:
            return Response({
                'detail': 'key error',
                'error_code': '5400'
            },
                            status=status.HTTP_400_BAD_REQUEST)
        except ValueError:
            return Response({'content': {}, 'count': 0})
        except Exception as e:
            log.error('[bill] views.get_bills_bycondition.e:{}'.format(
                e.__str__()))
            return Response(
                {
                    'detail:': 'value has an invalid format',
                    'error_code': '5400'
                },
                status=status.HTTP_400_BAD_REQUEST)
예제 #9
0
def binding_coupon(pk, payment_account_uuid, user_uuid):
    """
    绑定优惠码, 如果需要新增绑定关系, 需要传入优惠码, user_uuid, payment_account_uuid
    """
    if len(pk) == MODULE_COUPON['COUPON_CODE_LEN']:
        coupon_code_or_id = {'coupon_code': pk}
    else:
        coupon_code_or_id = {'coupon_uuid': pk}
    coupon_identify = get_kwargs(coupon_code_or_id)
    now = timezone.now()
    try:
        # 存在绑定关系, 检查剩余使用时间和次数是否满足
        coupon = Coupon.objects.get(**coupon_identify)
        coupon_user = CouponUser.objects.get(user_uuid=user_uuid,
                                             **coupon_identify)
        if coupon_user.using_count_left > 0 and now <= coupon.valid_datetime_end:
            log.info('[coupon] coupon %s is valid', coupon.coupon_code)
            return coupon_user, coupon
    except CouponUser.DoesNotExist:
        # 如果未发现绑定关系, 检查优惠码是否还有剩余可用人数, 如果有新建绑定关系
        coupon = Coupon.objects.get(**coupon_identify)
        if coupon.using_user_left > 0 and now <= coupon.valid_datetime_end:
            coupon_user = CouponUser(
                coupon_uuid=coupon,
                user_uuid=user_uuid,
                coupon_code=coupon.coupon_code,
                coupon_type=coupon.coupon_type,
                coupon_value=coupon.coupon_value,
                payment_account_uuid=payment_account_uuid,
                valid_datetime_start=coupon.valid_datetime_start,
                valid_datetime_end=coupon.valid_datetime_end,
                using_count_left=coupon.coupon_using_count)
            coupon_user.save()
            coupon.using_user_left = coupon.using_user_left - 1
            coupon.save()
            log.info('[coupon] user_uuid %s binding coupon_uuid: %s',
                     user_uuid, coupon.coupon_uuid)
            return coupon_user, coupon
    except Coupon.DoesNotExist:
        log.error('[coupon] coupon %s does not exist', pk)
    except Exception as e:
        log.error(e)
    log.error('[coupon] coupon %s is invalid', coupon_code_or_id)
    return False, False
예제 #10
0
파일: tasks.py 프로젝트: liyq1406/haihang
def check_alipay_detail(page_no, yesterday_str, today_str, page_size, writer):
    try:
        url = alipay_payment_history(page_no, yesterday_str, today_str,
                                     page_size)
        log.info('[reconciliation] query %s success', url)
        fp = urlopen(url)
        if fp.getcode() != 200:
            log.error('[reconciliation] query %s error', url)
        else:
            tree = ET.parse(fp)
            root = tree.getroot()
            is_success = root.findtext('is_success')
            sign = root.findtext('sign')
            result = root.find('response/account_page_query_result')
            has_next_page = result.findtext('has_next_page')
            page_no = result.findtext('page_no')
            page_size = result.findtext('page_size')
            account_log_list = result.find('account_log_list')
            try:
                log_str = ET.tostring(account_log_list,
                                      encoding='utf-8').replace(" ", "")
            except Exception, e:
                log_str = ET.tostring(account_log_list, encoding='utf-8')

            params = {
                'account_log_list': log_str,
                'has_next_page': has_next_page,
                'page_no': page_no,
                'page_size': page_size,
                'sign': sign
            }
            if xml_verify(params):
                for item in account_log_list.iterfind(
                        'AccountQueryAccountLogVO'):
                    merchant_out_order_no = item.findtext(
                        'merchant_out_order_no')
                    total_fee = item.findtext('total_fee')
                    trade_refund_amount = item.findtext('trade_refund_amount')
                    service_fee = item.findtext('service_fee')
                    trade_no = item.findtext('trade_no')
                    trans_date = item.findtext('trans_date')
                    buyer_account = item.findtext('buyer_account').encode(
                        'utf-8')
                    record = {
                        'payment_no': merchant_out_order_no,
                        'payment_record': u' ',
                        'third_record': ET.tostring(item, encoding='utf-8')
                    }
                    csvrow = []
                    try:
                        payment_record = Payment.objects.get(
                            payment_no=merchant_out_order_no)
                        record['payment_record'] = payment_record.payment_uuid
                        if abs(payment_record.real_price -
                               float(total_fee) * 100) > 0.01:
                            record['error_type'] = u'amount'
                            reconciliation_save(**get_kwargs(record))
                            log.error(
                                '[reconciliation] alipay amount valid fail %s',
                                merchant_out_order_no)
                        if trade_refund_amount == '0.00' and payment_record.paid_status != 'success':
                            record['error_type'] = u'status'
                            reconciliation_save(**get_kwargs(record))
                            log.error(
                                '[reconciliation] alipay status valid fail %s',
                                merchant_out_order_no)
                        csvrow = get_payment_info(payment_record) + [merchant_out_order_no, total_fee, \
                            trade_refund_amount, service_fee, trade_no, trans_date, buyer_account]
                    except Payment.DoesNotExist:
                        record['error_type'] = u'miss'
                        reconciliation_save(**get_kwargs(record))
                        log.error('[reconciliation] alipay record miss %s',
                                  merchant_out_order_no)
                        csvrow = get_payment_info() + [merchant_out_order_no, total_fee, \
                            trade_refund_amount, service_fee, trade_no, trans_date, buyer_account]
                    except Payment.MultipleObjectsReturned:
                        record['error_type'] = u'multi'
                        reconciliation_save(**get_kwargs(record))
                        log.error('[reconciliation] alipay record multi %s',
                                  merchant_out_order_no)
                        csvrow = get_payment_info() + [merchant_out_order_no, total_fee, \
                            trade_refund_amount, service_fee, trade_no, trans_date, buyer_account]
                    log.info(csvrow)
                    writer.writerow(csvrow)

            else:
                log.error('[reconciliation] verify error: %s', url)
        fp.close()
        return has_next_page