import { ApiCall } from "tsrpc";
import { PayFun } from "../../public/pay";
import { ReqRenownOpen, ResRenownOpen } from "../../shared/protocols/user/PtlRenownOpen";

export default async function (call: ApiCall<ReqRenownOpen, ResRenownOpen>) {

    let conf = G.gc.mw_com['gift'][0];
    let buyLog = await PayFun.getPayLog(call.uid, conf.payId);

    let _data
    let _mydata = await G.mongodb.collection('playerInfo', 'juewei').findOne({ uid: call.conn.uid, type: 'juewei' });
    if (!_mydata || buyLog.length > 0) {
        _data = {
            // 礼包相关数据
            record: _mydata?.record || {},
            // 领取时间
            tequan: {
                istq: buyLog.length > 0 ? 1 : 0,
                recTime: _mydata?.tequan?.recTime || 0
            }
        }
        G.mongodb.collection('playerInfo', 'juewei').updateOne({ uid: call.conn.uid, type: 'juewei' }, { $set: _data }, { upsert: true });
        Object.assign(_mydata, _data)
    }

    call.succ({
        mydata: _mydata || _data
    });
}