bztang-admin/plugins/point-mall/src/service/SetService.php

72 lines
1.5 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: CJVV
* Date: 2020/10/16
* Time: 15:27
*/
namespace Yunshop\PointMall\service;
use Yunshop\PointMall\models\PointMallSetModel;
class SetService
{
/**
* 获取插件设置信息
* @param string $select
* @return mixed
*/
public static function getData($select = '*')
{
$set = PointMallSetModel::uniacid()
->selectRaw($select)
->first();
if ($set) {
$set = $set->toArray();
} else {
$set = [];
}
return $set;
}
/**
* 设置插件数据
* @param $setData
* @return bool
* @throws \Exception
*/
public static function setData($setData)
{
if (empty($setData)){
throw new \Exception('参数错误');
}
$setModel = PointMallSetModel::uniacid()->first();
if (!$setModel) {
$setModel = new PointMallSetModel(['uniacid' => \YunShop::app()->uniacid]);
}
$setModel->fill($setData);
if ($setModel->save()){
return true;
}
throw new \Exception('设置失败');
}
/**
* 获取插件开启状态
* @return bool|mixed
*/
public static function getPluginStatus()
{
if (!app('plugins')->isEnabled('point-mall')){
return false;
}
$setModel = PointMallSetModel::uniacid()->first();
if (!$setModel) {
return false;
}
return $setModel->is_open;
}
}