<?php
// +----------------------------------------------------------------------
// | A3Mall
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: xzncit <158373108@qq.com>
// +----------------------------------------------------------------------

namespace app\adminapi\service\promotion;

use app\common\model\promotion\Invite as InviteModel;

/**
 * @package app\adminapi\service\promotion
 * @class Invite
 * @author xzncit 2024-02-19
 */
class Invite {

    /**
     * 获取
     * @return array|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function detail(){
        return InviteModel::where("1=1")->find();
    }

    /**
     * 保存
     * @param array $params
     * @return bool|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function save($params=[]){
        $row = InviteModel::where("1=1")->find();
        if(empty($row)){
            $params["create_time"] = time();
            return InviteModel::create($params)->id;
        }

        return InviteModel::where("id",$row["id"])->save($params);
    }

}