<?php

namespace app\api\controller;

use app\api\model\Invite\InviteLog;
use app\common\model\invite\InviteConfig;
use cores\exception\BaseException;
use think\db\exception\DbException;
use think\response\Json;

class Invite extends Controller
{
    /**
     * @notes:基本信息
     * @return Json
     * @throws BaseException
     * @author: wanghousheng
     */
    public function index(): Json
    {
        $info = InviteConfig::detail([], ['coupon']);
        $data = [];
        if ($info) {
            $data['one_order_rate'] = $info['one_order_rate'];
            $data['integral'] = $info['integral'];
            $data['coupon_name'] = $info['coupon']['name'];
            $model = new InviteLog();
            $data['money'] = $model->sumMoney();
            $data['count_people'] = $model->countPeople();
        }
        return $this->renderSuccess($data);
    }

    /**
     * @notes:邀请记录
     * @throws BaseException
     * @throws DbException
     * @author: wanghousheng
     */
    public function getList(): Json
    {
        $model = new InviteLog();
        $list = $model->getList();
        return $this->renderSuccess(compact('list'));
    }
}