import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/zhoumolibao/PtlOpen";
import {PayFun} from "../../../public/pay";
import {HuoDongFun} from "../../../public/huodongfun";
import {PublicShared} from "../../../shared/public/public";


export default async function (call: ApiCall<ReqOpen, ResOpen>) {
    let data = await G.mongodb.cEvent('pobinglibao').findOne({uid: call.uid, type: 'pobinglibao'})

    let _hd = (await HuoDongFun.gethdList(call, 10))[0]
    if (!_hd) return call.errorCode(-1)

    let payIds = _hd?.data?.gift?.filter(i => i.payId)?.map(i => i.payId)

    let payLog: any = await PayFun.getPayLogs(call.uid, payIds)

    for (let key in payLog) {
        payLog[key]?.filter(i => i.time > _hd.stime && i.time < _hd.etime)
    }

    call.succ({
        record: data?.record || {},
        buyLog: payLog
    })
}