175 行
5.6 KiB
PHP
可执行文件
175 行
5.6 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Super\Business;
|
|
|
|
use Common\Model\PlugSetModel;
|
|
|
|
//[1.8.20]
|
|
|
|
/**
|
|
* 插件配置类
|
|
* Class PlugSet
|
|
* [
|
|
* 插件配置信息 setInfo
|
|
* 插件配置 plugSet
|
|
* 插件配置的参数验证 plugSetVerify
|
|
* ]
|
|
* @package Super\Business
|
|
*/
|
|
class PlugSet
|
|
{
|
|
/**
|
|
* 插件配置信息
|
|
* @param $param
|
|
* [
|
|
* identification 插件标识
|
|
* ]
|
|
* @return mixed
|
|
*/
|
|
public function setInfo($param)
|
|
{
|
|
if (empty($param['identification'])) {
|
|
return callBack(statusCode()['error'], '缺少唯一标识');
|
|
}
|
|
$PlugSetModel = new PlugSetModel();
|
|
$list = $PlugSetModel->getSelect([
|
|
'identification' => $param['identification']
|
|
], '*');
|
|
$info = [];
|
|
if (!empty($list)) {
|
|
foreach ($list as $val) {
|
|
$info[$val['key']] = $val['value'];
|
|
}
|
|
} else {
|
|
$info['duration_type'] = '1';
|
|
$info['duration_time'] = '';
|
|
$info['duration_start_type'] = '1';
|
|
$info['space'] = '';
|
|
}
|
|
return callBack(statusCode()['success'], '查询成功', $info);
|
|
}
|
|
|
|
|
|
/**
|
|
* 插件配置
|
|
* @param $param
|
|
* [
|
|
* operator_id 操作者id
|
|
* identification 插件标识
|
|
* param =>[
|
|
* duration_type 1永久时长 2固定时长
|
|
* duration_time 固定的时长
|
|
* duration_start_type 开始计时的时候 1确认收货后 2首次扫码后
|
|
* space 上传视频语言的空间
|
|
* ]
|
|
* ]
|
|
* @return mixed
|
|
*/
|
|
public function plugSet($param)
|
|
{
|
|
$verifyResult = $this->plugSetVerify($param);
|
|
if ($verifyResult['status'] != 1) {
|
|
return $verifyResult;
|
|
}
|
|
$info = $param['param'];
|
|
$where = [
|
|
'identification' => $param['identification']
|
|
];
|
|
try {
|
|
M()->startTrans();
|
|
$PlugSetModel = new PlugSetModel();
|
|
$id = $PlugSetModel->getFind($where, 'id');
|
|
$time = $_SERVER['REQUEST_TIME'];
|
|
if (!empty($id)) {
|
|
//编辑
|
|
switch ($param['identification']) {
|
|
case 'blessing':
|
|
foreach ($info as $key => $value) {
|
|
$where['key'] = $key;
|
|
$PlugSetModel->updateOrder($where, [
|
|
'value' => $value ? $value : ''
|
|
]);
|
|
}
|
|
break;
|
|
}
|
|
$where['key'] = 'update_time';
|
|
$PlugSetModel->updateOrder($where, [
|
|
'value' => $time
|
|
]);
|
|
$where['key'] = 'operator_id';
|
|
$PlugSetModel->updateOrder($where, [
|
|
'value' => $param['operator_id']
|
|
]);
|
|
} else {
|
|
//添加
|
|
$add_arr = [];
|
|
$data = [
|
|
'identification' => $param['identification'],
|
|
];
|
|
switch ($param['identification']) {
|
|
case 'blessing':
|
|
foreach ($info as $key => $value) {
|
|
$data['key'] = $key;
|
|
$data['value'] = $value ? $value : '';
|
|
$add_arr[] = $data;
|
|
}
|
|
break;
|
|
}
|
|
$data['key'] = 'update_time';
|
|
$data['value'] = $time;
|
|
$add_arr[] = $data;
|
|
$data['key'] = 'operator_id';
|
|
$data['value'] = $param['operator_id'];
|
|
$add_arr[] = $data;
|
|
$result = $PlugSetModel->addAll($add_arr);
|
|
if (!$result) {
|
|
M()->rollback();
|
|
return callBack(statusCode()['error'], '操作失败');
|
|
}
|
|
}
|
|
M()->commit();
|
|
return callBack(statusCode()['success'], '操作成功');
|
|
} catch (\Exception $e) {
|
|
return callBack(statusCode()['error'], '操作失败');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 插件配置的参数验证
|
|
* @param $param
|
|
* [
|
|
* operator_id 操作者id
|
|
* identification 插件标识
|
|
* param =>[
|
|
* duration_type 1永久时长 2固定时长
|
|
* duration_time 固定的时长
|
|
* duration_start_type 开始计时的时候 1确认收货后 2首次扫码后
|
|
* space 上传视频语言的空间
|
|
* ]
|
|
* ]
|
|
* @return mixed
|
|
*/
|
|
public function plugSetVerify(&$param)
|
|
{
|
|
if (empty($param['operator_id']) || empty($param['identification'])) {
|
|
return callBack(statusCode()['error'], '缺少唯一标识');
|
|
}
|
|
$info = json_decode(htmlspecialchars_decode($param['param']), true);
|
|
switch ($param['identification']) {
|
|
case 'blessing':
|
|
if ($info['duration_type'] == 2 && empty($info['duration_time'])) {
|
|
return callBack(statusCode()['error'], '请输入固定时长');
|
|
}
|
|
if (empty($info['duration_start_type'])) {
|
|
return callBack(statusCode()['error'], '请选择强化规则');
|
|
}
|
|
if (!empty($info['space']) && (!preg_match("/^\+?[1-9][0-9]*$/", $info['space']) || $info['space'] > 10000)) {
|
|
return callBack(statusCode()['error'], '请输入正确的字节数,最大10000兆');
|
|
}
|
|
break;
|
|
}
|
|
$param['param'] = $info;
|
|
return callBack(statusCode()['success'], '验证成功');
|
|
}
|
|
} |