# -*- coding: utf-8 -*-

from __future__ import division

from logs.models import RedpackSendLogInfo
from miniapp.redpack_views import send_jsapi_hb


def exec_send_jsapi_hb(user, elog, amount):
    send_jsapi_hb(user.brand_id, user.openid, amount, transfer=False)

    elog.has_send_redpack = True
    elog.redpack_send_amount = amount
    elog.user_id = user.user_id
    elog.nickname = user.nickname
    elog.save()

    RedpackSendLogInfo.objects.create(
        brand_id=user.brand_id,
        user_id=user.user_id,
        nickname=user.nickname,
        phone=user.phone,
        sn=elog.sn,
        redpack_type=RedpackSendLogInfo.WX_REDPACK,
        redpack_amount=amount,
    )


def exec_clerk_send_jsapi_hb(user, elog, amount):
    send_jsapi_hb(user.brand_id, user.openid, amount, transfer=False, clerk=True)

    elog.has_clerk_send_redpack = True
    elog.clerk_redpack_send_amount = amount
    elog.clerk_user_id = user.user_id
    elog.clerk_nickname = user.nickname
    elog.save()

    RedpackSendLogInfo.objects.create(
        brand_id=user.brand_id,
        user_id=user.user_id,
        nickname=user.nickname,
        phone=user.phone,
        sn=elog.sn,
        redpack_type=RedpackSendLogInfo.WX_REDPACK,
        redpack_amount=amount,
        is_clerk_redpack=True,
    )
