后台
This commit is contained in:
99
app/czg/controller/BannerController.php
Normal file
99
app/czg/controller/BannerController.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class BannerController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
||||
|
||||
public function selectBannerPage()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user