Beispiel #1
0
def details(request):
    ''' 余额明细区分WEB和IOS '''
    user_id = request.user['id']
    params = request.query_params
    statement_type = params.get('statement_type', None)
    is_receipt = str_to_bool(params.get('is_receipt', None))
    page = params.get('page_index', 1)
    page_size = params.get('page_size', 10)
    start_time = timestamp_to_datetime(
        params.get('start_time')) or get_yesterday()
    end_time = timestamp_to_datetime(params.get('end_time')) or get_tomorrow()
    UA = str.lower(request.META.get('HTTP_USER_AGENT', ''))
    if 'ios' in UA or 'iphone' in UA:
        paginator = BalanceService().\
            statistics_ios(user_id=user_id, statement_type=statement_type,
                           page_size=page_size, is_receipt=is_receipt)
    else:
        paginator = BalanceService().\
            statistics(user_id=user_id, statement_type=statement_type,
                       page_size=page_size, start_time=start_time,
                       is_receipt=is_receipt,
                       end_time=end_time)
    paginator.current_page = page
    paginator.serializer = ReceiptDisbursenmentSerializer
    return JsonResponse(data=paginator)
Beispiel #2
0
def withdraw(request):
    user_id = request.user['id']
    data = request.data
    amount = data['amount']
    channel = data['channel']
    recipient = data['recipient']
    recipient_name = data['recipient_name']
    withdraw = BalanceService().\
        withdraw_balance(user_id=user_id,
                         amount=amount,
                         channel=channel,
                         recipient=recipient,
                         recipient_name=recipient_name)
    serializer = WithdrawSerializer(withdraw)
    return JsonResponse(data=serializer.data)
Beispiel #3
0
def charge(request):
    user_id = request.user['id']
    data = request.data
    channel = data['channel']
    amount = data['amount']
    client_ip = data.get('client_ip', '127.0.0.1')
    extra = {}
    if channel == 'alipay_pc_direct':
        extra = dict(success_url=data['success_url'])
    ch = BalanceService().\
        charge_balance(user_id=user_id,
                       channel=channel,
                       amount=amount,
                       extra=extra,
                       client_ip=client_ip)
    return JsonResponse(data=ch)
 def paid(self, ch):
     ''' 支付完成回调,支持失败重试机制 '''
     charge = None
     try:
         charge = Charge.objects.\
             get(charge_id=ch['data']['object']['id'])
     except Charge.DoesNotExist as e:
         logger.warn('支付凭证不存在:%s' % ch['data']['object']['id'])
         raise PingppException('支付凭证不存在')
     # 修改支付凭证状态
     try:
         charge.paid = True
         charge.time_paid = int(time.time())
         charge.save()
         if charge.pay_type == 3:  # 保证金充值
             # 保证金增加
             deposit_ser = DepositService()
             deposit_ser.\
                 add_deposit(user_id=charge.user_id,
                             amount=charge.amount)
             # 记录流水
             deposit_ser.\
                 receipt_deposit(user_id=charge.user_id,
                                 amount=charge.amount)
         elif charge.pay_type == 1:  # 余额充值
             BalanceService().\
                 add_balance(user_id=charge.user_id,
                             amount=charge.amount)
             ReceiptDisbursementService().\
                 receipt(user_id=charge.user_id,
                         statement_type=1,
                         amount=charge.amount)
         elif charge.pay_type == 2:  # 账单支付
             # 找到支付凭证关联的账单
             order_bills = OrderBill.objects.\
                 filter(user_id=charge.user_id,
                        charge_id=charge.id)
             storge_bills = StorgeBill.objects.\
                 filter(user_id=charge.user_id,
                        charge_id=charge.id)
             overdue_bill = OverdueBill.objects.\
                 filter(user_id=charge.user_id,
                        charge_id=charge.id)
             # 修改账单状态
             now = datetime.datetime.now()
             for ob in order_bills:
                 ob.paid = True
                 ob.paid_time = now
                 ob.save()
             for sb in storge_bills:
                 sb.paid = True
                 sb.paid_time = now
                 sb.save()
             if overdue_bill:
                 overdue_bill.paid = True
                 overdue_bill.paid_time = now
                 overdue_bill.save()
         elif charge.pay_type == 4:  # 开发者认证支付
             # 发起掉用仓妈咪相关接口
             result = requests.\
                 get(url='http://47.95.235.167:8002/api/developers/paid?user_id=' + str(charge.user_id)).\
                 json()
             print(result)
             print("ooooooooooooooooooooooo")
     except Exception as e:
         raise PingppException(str(e))
     return True
Beispiel #5
0
 def __init__(self, *args, **kwargs):
     self.fee_ser = FeeService()
     self.bill_ser = BillService()
     self.balance_ser = BalanceService()
     self.receipt_ser = ReceiptService()
     self.rd_ser = ReceiptDisbursementService()
Beispiel #6
0
def recent(request):
    user_id = request.user['id']
    rds = BalanceService().recent(user_id=user_id)
    serializer = ReceiptDisbursenmentSerializer(rds, many=True)
    return JsonResponse(data=serializer.data)
Beispiel #7
0
def balance(request):
    user_id = request.user['id']
    amount = BalanceService().show_balance(user_id=user_id)
    return JsonResponse(data={"amount": amount})