<?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\Consume as ConsumeModel;

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

    /**
     * 获取
     * @return array|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function detail(){
        return ConsumeModel::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 = ConsumeModel::where("1=1")->find();
        if(empty($row)){
            $params["create_time"] = time();
            return ConsumeModel::create($params)->id;
        }

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

}