# -*- 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.openid, amount, transfer=False)

    elog.has_send_redpack = True
    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,
    )
