99 lines
2.8 KiB
PHP
99 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\Backend;
|
|
use app\common\library\DatabaseRoute;
|
|
use think\facade\Db;
|
|
|
|
class Banner extends Backend
|
|
{
|
|
protected array $noNeedLogin = ['*'];
|
|
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
|
|
|
public function selectBannerPage()
|
|
{
|
|
$params = $this->request->param();
|
|
$info = cache('banner'.$params['page'].$params['limit']);
|
|
if ($info) {
|
|
$this->successWithData($info);
|
|
}
|
|
$info = DatabaseRoute::paginateDb('banner', function ($query) use ($params) {
|
|
if (!empty($params['classify'])) {
|
|
$query->where([
|
|
'classify' => $params['classify']
|
|
]);
|
|
}
|
|
|
|
if (!empty($params['state'])) {
|
|
// $query->where([
|
|
// 'state' => $params['state']
|
|
// ]);
|
|
}
|
|
return $query;
|
|
}, $params['page'], $params['limit']);
|
|
cache('banner'.$params['page'].$params['limit'], $info, -1);
|
|
$this->successWithData($info);
|
|
|
|
}
|
|
|
|
public function updateBannerById()
|
|
{
|
|
$params = $this->request->post();
|
|
$params = convertKeysCamelToSnakeRecursive($params);
|
|
unset($params['course']);
|
|
Db::name('banner')->where([
|
|
'id' => $params['id']
|
|
])->update($params);
|
|
deleteRedisKeysByPattern('banner*');
|
|
$this->success();
|
|
}
|
|
|
|
public function insertBanner()
|
|
{
|
|
$params = $this->request->post();
|
|
$params = convertKeysCamelToSnakeRecursive($params);
|
|
$params['state'] = 2;
|
|
$params['create_time'] = getNormalDate();
|
|
unset($params['id']);
|
|
Db::name('banner')->insert($params);
|
|
deleteRedisKeysByPattern('banner*');
|
|
$this->success();
|
|
|
|
}
|
|
|
|
public function deleteBannerById()
|
|
{
|
|
$params = $this->request->param();
|
|
$params['ids'] = explode(',', $params['ids']);
|
|
foreach ($params['ids'] as $id) {
|
|
Db::name('banner')->delete([
|
|
'id' => $id
|
|
]);
|
|
}
|
|
deleteRedisKeysByPattern('banner*');
|
|
$this->success();
|
|
}
|
|
|
|
|
|
// 隐藏banner图
|
|
public function updateBannerStateById()
|
|
{
|
|
$get = $this->request->get();
|
|
if(empty($get['id'])) {
|
|
$this->error('参数不玩这');
|
|
}
|
|
$id = $get['id'];
|
|
$banner = Db::connect(get_slave_connect_name())->name('banner')->where(['id' => $id])->find();
|
|
if(!$banner) {
|
|
$this->error('记录不存在');
|
|
}
|
|
Db::connect(get_master_connect_name())->name('banner')->where(['id' => $id])->update([
|
|
'state' => $banner['state'] == 1 ? 2 : 1,
|
|
]);
|
|
$this->success();
|
|
}
|
|
|
|
|
|
|
|
} |