Ejemplo n.º 1
0
    def handle(self, *args, **options):
        """
        根据carryrecord更新budgetlog
        """
        carry = CarryRecord.objects.filter(id=9637662).first()
        customer = carry.mama.get_mama_customer()
        budget_log_type = CarryRecord.budget_log_type_map(carry.carry_type)
        budget_log_status = CarryRecord.budget_log_status_map(carry.status)

        referal_id = 'carryrecord-%s' % carry.id
        bg = BudgetLog.objects.filter(referal_id=referal_id).first()
        if bg:
            bg.confirm_budget_log()
        else:
            if carry.carry_num > 0:
                BudgetLog.create(customer.id, BudgetLog.BUDGET_IN, carry.carry_num, budget_log_type,
                                 status=budget_log_status,
                                 referal_id=referal_id)

        carry = CarryRecord.objects.filter(id=9637663).first()
        customer = carry.mama.get_mama_customer()
        budget_log_type = CarryRecord.budget_log_type_map(carry.carry_type)
        budget_log_status = CarryRecord.budget_log_status_map(carry.status)

        referal_id = 'carryrecord-%s' % carry.id
        bg = BudgetLog.objects.filter(referal_id=referal_id).first()
        if bg:
            bg.confirm_budget_log()
        else:
            if carry.carry_num > 0:
                BudgetLog.create(customer.id, BudgetLog.BUDGET_IN, carry.carry_num, budget_log_type,
                                 status=budget_log_status,
                                 referal_id=referal_id)
Ejemplo n.º 2
0
    def refund_payment_2_budget(self):
        from .user import BudgetLog

        sorder = self.saleorder
        payment = round(self.refund_fee * 100, 0)
        total_refund = BudgetLog.objects.filter(
            customer_id=self.buyer_id,
            referal_id=self.id,  # 以退款单
            budget_log_type=BudgetLog.BG_REFUND).aggregate(
                t_flow=Sum('flow_amount')).get('t_flow') or 0
        total_refund += payment  # 总退款费用(分)
        if total_refund > round(sorder.payment * 100,
                                0):  # 如果钱包总的退款记录数值大于子订单的实际支付额 抛出异常
            raise Exception(u'超过订单实际支付金额 !')

        with transaction.atomic():
            self.update_good_status(sorder.is_post())  # 更新退货状态字段
            if payment > 0:  # 有退款金额才生成退款余额记录
                BudgetLog.create_salerefund_log(self, payment)
            self.refund_confirm()
        self.send_refund_success_weixin_message()  # 退款成功推送

        #  对于已经兑换精品券的订单,那么还需要扣除妈妈的零钱、取消订单兑换记录、退回她的券、新增券退货流通记录,如果零钱不足,只扣除
        #  零钱(扣为负数),其它3步不做,写入一条退款欠款记录。待妈妈补足欠款后做后3步

        from flashsale.coupon.apis.v1.transfer import saleorder_return_coupon_exchange
        saleorder_return_coupon_exchange(self, payment)
Ejemplo n.º 3
0
def cash_out_2_budget(mama, value):
    # type: (XiaoluMama, int) -> None
    """妈妈钱包 提现到 小鹿钱包
    """
    if not isinstance(value, int):
        raise Exception('参数错误!')
    _verify_cash_out_2_budget(mama, value)
    customer = mama.get_customer()

    with transaction.atomic():
        cashout = CashOut.create(mama.id, value, CashOut.USER_BUDGET)
        cashout.approve_cashout()
        BudgetLog.create_mm_cash_out_2_budget(customer.id, value, cashout.id)

    log_action(customer.user.id, cashout, ADDITION, '代理提现到余额')
Ejemplo n.º 4
0
    def post(self, request):
        # type: (HttpRequest) -> Response
        """发送红包
        """
        content = request.POST or request.data
        customer_id = content.get('customer_id') or None
        customer_id = int(customer_id)
        amount = content.get('amount') or '0'
        memo = content.get('memo') or None

        flow_amount = int(decimal.Decimal(amount) * 100)  # 以分为单位
        if flow_amount == 0:
            return Response({
                'code': 1,
                'info': '红包金额不能为0',
                'data': self.get_budget_data(customer_id)
            })

        # 添加红包钱包记录
        budget_log = BudgetLog.create(customer_id=int(customer_id),
                                      budget_type=BudgetLog.BUDGET_IN,
                                      flow_amount=flow_amount,
                                      budget_log_type=BudgetLog.BG_ENVELOPE)
        log_action(request.user, budget_log, ADDITION, u'赠送红包 %s' % memo)

        data = self.get_budget_data(customer_id)
        return Response({'code': 0, 'info': 'success', 'data': data})
Ejemplo n.º 5
0
def refund_postage(sale_refund, postage_num=0, im_execute=True):
    # type: (SaleRefund, int, bool) -> bool
    """为退款单退邮费
    """
    from flashsale.pay.models import BudgetLog

    if postage_num and postage_num != sale_refund.postage_num:
        sale_refund.postage_num = postage_num
        sale_refund.save(update_fields=['postage_num'])
    if not im_execute:  # 不是立即执行退邮费到用户账户
        return im_execute

    if 0 < sale_refund.postage_num <= 2000:
        BudgetLog.create_salerefund_postage_log(sale_refund,
                                                sale_refund.postage_num)
        return True
    return False
Ejemplo n.º 6
0
def task_envelope_create_budgetlog(envelope):
    budget_logs = BudgetLog.objects.filter(customer_id=envelope.customer_id,
                                           referal_id=envelope.uni_key)
    if budget_logs.count() > 0:
        return

    budget_type = BudgetLog.BUDGET_IN
    budget_log_type = BudgetLog.BG_ENVELOPE
    status = BudgetLog.CANCELED  # initially we put the status as "canceled"

    uni_key = BudgetLog.gen_uni_key(envelope.customer_id, budget_type,
                                    budget_log_type)
    BudgetLog.create(customer_id=envelope.customer_id,
                     budget_type=budget_type,
                     flow_amount=envelope.value,
                     budget_log_type=budget_log_type,
                     referal_id=envelope.uni_key,
                     uni_key=uni_key,
                     status=status)
Ejemplo n.º 7
0
    def refund_envelop(self):
        from flashsale.pay.models import BudgetLog
        from flashsale.xiaolumm.models import CashOut

        # 小鹿钱包提现
        if self.subject == self.XLAPP_CASHOUT:
            bg = BudgetLog.objects.get(id=self.referal_id,
                                       budget_log_type=BudgetLog.BG_CASHOUT)
            bg.confirm_budget_log()
            BudgetLog.create(bg.customer_id, BudgetLog.BUDGET_IN,
                             bg.flow_amount, BudgetLog.BG_CASHOUT_FAIL)

        # 妈妈钱包提现
        if self.subject == self.CASHOUT:
            cashout = CashOut.objects.filter(id=self.referal_id).first()
            if not cashout:
                return
            if cashout.status == CashOut.PENDING:
                cashout.cancel_cashout()
            else:
                cashout.fail_and_return()
Ejemplo n.º 8
0
    def handle(self, *args, **options):
        """
        计算精品汇返点, 并发放
        """

        ym_date = options.get('ymdate')[0]
        year_months = ym_date.split('-')
        if not len(year_months) == 2:
            print 'invalid ymdate, need eg: 2017-06'
            return

        year, month = map(int ,year_months)
        end_month = month % 12 + 1
        end_year  = month / 12 + year
        start_date = datetime(year, month, 1)  # 这里要改
        end_date = datetime(end_year, end_month, 1)  # 这里也要改

        mamas = self.get_mamas_score_gte()

        for mama in mamas:
            res = self.cal_mama_score(mama.id, start_date, end_date)
            fd = res['fd']
            if res['fd'] > 0:
                print '---'
                print res['start_date'], res['end_date']
                print mama.id
                print u'返点:{fd}, 买券额: {payment}, 积分: {score} \n'.format(**res)

                customer_id = mama.customer_id
                flow_amount = int(Decimal(str(fd)) * 100)
                uni_key = 'fd-{month}-{mama_id}'.format(month=month, mama_id=mama.id)
                try:
                    # 创建待确定收入
                    BudgetLog.create(customer_id, BudgetLog.BUDGET_IN, flow_amount, BudgetLog.BG_FANDIAN,
                         status=BudgetLog.PENDING, uni_key=uni_key)
                except Exception:
                    print u'{mama_id}在{month}月的返点已经发过了'.format(mama_id=mama.id, month=month)
                    continue