138 lines
3.8 KiB
PHP
138 lines
3.8 KiB
PHP
<?php
|
|
namespace app\admin\controller;
|
|
|
|
use app\admin\controller\Base;
|
|
use app\common\model\FloatBallConfig;
|
|
use think\facade\Db;
|
|
use think\facade\View;
|
|
|
|
class FloatBall extends Base
|
|
{
|
|
/**
|
|
* 悬浮球配置列表
|
|
*/
|
|
public function index()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$limit = input('param.limit', 15);
|
|
$offset = input('param.offset', 0);
|
|
$where = [];
|
|
|
|
$res = FloatBallConfig::where($where)
|
|
->order('id', 'desc')
|
|
->limit($offset, $limit)
|
|
->select();
|
|
|
|
$total = FloatBallConfig::where($where)->count();
|
|
|
|
return $this->renderTable('获取成功', $total, $res, 0);
|
|
}
|
|
|
|
return View::fetch();
|
|
}
|
|
|
|
/**
|
|
* 添加悬浮球配置
|
|
*/
|
|
public function add()
|
|
{
|
|
if (request()->isPost()) {
|
|
$param = input('post.');
|
|
$validate = $this->validate($param, [
|
|
'type' => 'require|number',
|
|
'image' => 'require',
|
|
'position_x' => 'require',
|
|
'position_y' => 'require',
|
|
'width' => 'require',
|
|
'height' => 'require',
|
|
'effect' => 'require|number',
|
|
]);
|
|
|
|
if (true !== $validate) {
|
|
return $this->renderError($validate);
|
|
}
|
|
|
|
$param['status'] = isset($param['status']) ? 1 : 0;
|
|
|
|
$res = FloatBallConfig::create($param);
|
|
if ($res) {
|
|
return $this->renderSuccess('添加成功', ['url' => (string)url('float_ball')]);
|
|
} else {
|
|
return $this->renderError('添加失败');
|
|
}
|
|
}
|
|
|
|
return View::fetch();
|
|
}
|
|
|
|
/**
|
|
* 编辑悬浮球配置
|
|
*/
|
|
public function edit()
|
|
{
|
|
$id = input('param.id', 0);
|
|
$info = FloatBallConfig::where('id', $id)->find();
|
|
if (empty($info)) {
|
|
return $this->renderError('数据不存在');
|
|
}
|
|
|
|
if (request()->isPost()) {
|
|
$param = input('post.');
|
|
// $validate = $this->validate($param, [
|
|
// 'type' => 'require|number',
|
|
// 'image' => 'require',
|
|
// 'position_x' => 'require',
|
|
// 'position_y' => 'require',
|
|
// 'width' => 'require',
|
|
// 'height' => 'require',
|
|
// 'effect' => 'require|number',
|
|
// ]);
|
|
|
|
// if (true !== $validate) {
|
|
// return $this->renderError($validate);
|
|
// }
|
|
|
|
$param['status'] = isset($param['status']) ? 1 : 0;
|
|
|
|
$res = FloatBallConfig::update($param, ['id' => $id]);
|
|
if ($res) {
|
|
return $this->renderSuccess('编辑成功', ['url' => (string)url('float_ball')]);
|
|
} else {
|
|
return $this->renderError('编辑失败');
|
|
}
|
|
}
|
|
|
|
View::assign('info', $info);
|
|
return View::fetch();
|
|
}
|
|
|
|
/**
|
|
* 修改状态
|
|
*/
|
|
public function status()
|
|
{
|
|
$id = input('param.id', 0);
|
|
$status = input('param.status', 0);
|
|
|
|
$res = FloatBallConfig::update(['status' => $status], ['id' => $id]);
|
|
if ($res) {
|
|
return $this->renderSuccess('操作成功');
|
|
} else {
|
|
return $this->renderError('操作失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除悬浮球配置
|
|
*/
|
|
public function del()
|
|
{
|
|
$id = input('param.id', 0);
|
|
$res = FloatBallConfig::destroy($id);
|
|
if ($res) {
|
|
return $this->renderSuccess('删除成功');
|
|
} else {
|
|
return $this->renderError('删除失败');
|
|
}
|
|
}
|
|
}
|