更新
This commit is contained in:
@@ -20,7 +20,6 @@ class Ad extends Base {
|
|||||||
* @title 广告位管理
|
* @title 广告位管理
|
||||||
*/
|
*/
|
||||||
public function index(Adservice $service) {
|
public function index(Adservice $service) {
|
||||||
|
|
||||||
$list = $service->getAdPlaceList($this->request);
|
$list = $service->getAdPlaceList($this->request);
|
||||||
|
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
@@ -33,14 +32,13 @@ class Ad extends Base {
|
|||||||
/**
|
/**
|
||||||
* @title 广告位添加
|
* @title 广告位添加
|
||||||
*/
|
*/
|
||||||
public function add() {
|
public function add(Adservice $service) {
|
||||||
if ($this->request->isPost()) {
|
if ($this->request->isPost()) {
|
||||||
$data = $this->request->post();
|
try {
|
||||||
$result = AdPlace::create($data);
|
$service->createAdPlace($this->request);
|
||||||
if (false !== $result) {
|
return $this->success("添加成功!", url('/admin/ad/index'));
|
||||||
return $this->success("添加成功!");
|
} catch (\think\Exception $e) {
|
||||||
} else {
|
return $this->error($e->getMessage());
|
||||||
return $this->error('添加失败!');
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
@@ -53,22 +51,17 @@ class Ad extends Base {
|
|||||||
/**
|
/**
|
||||||
* @title 广告位编辑
|
* @title 广告位编辑
|
||||||
*/
|
*/
|
||||||
public function edit($id = null) {
|
public function edit(Adservice $service) {
|
||||||
if ($this->request->isPost()) {
|
if ($this->request->isPost()) {
|
||||||
$data = $this->request->post();
|
try {
|
||||||
$result = AdPlace::update($data, ['id' => $data['id']]);
|
$service->updateAdPlace($this->request);
|
||||||
if ($result) {
|
|
||||||
return $this->success("修改成功!", url('/admin/ad/index'));
|
return $this->success("修改成功!", url('/admin/ad/index'));
|
||||||
} else {
|
} catch (\think\Exception $e) {
|
||||||
return $this->error('修改失败!');
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$info = AdPlace::find($id);
|
|
||||||
if (!$info) {
|
|
||||||
return $this->error("非法操作!");
|
|
||||||
}
|
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'info' => $info,
|
'info' => $service->getAdPlaceDetail($this->request),
|
||||||
'keyList' => \app\model\ads\AdPlace::$keyList,
|
'keyList' => \app\model\ads\AdPlace::$keyList,
|
||||||
);
|
);
|
||||||
return $this->fetch('admin/public/edit');
|
return $this->fetch('admin/public/edit');
|
||||||
@@ -96,13 +89,10 @@ class Ad extends Base {
|
|||||||
/**
|
/**
|
||||||
* @title 广告列表
|
* @title 广告列表
|
||||||
*/
|
*/
|
||||||
public function lists($id = null) {
|
public function lists(Adservice $service) {
|
||||||
$map[] = ['place_id', '=', $id];
|
$list = $service->getAdByPlace($this->request);
|
||||||
$order = "id desc";
|
|
||||||
|
|
||||||
$list = AdModel::where($map)->order($order)->paginate($this->request->pageConfig);
|
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'id' => $id,
|
'id' => $this->request->get('id', 0),
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'page' => $list->render(),
|
'page' => $list->render(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class Index extends Base {
|
|||||||
*/
|
*/
|
||||||
public function clear() {
|
public function clear() {
|
||||||
if ($this->request->isPost()) {
|
if ($this->request->isPost()) {
|
||||||
$clear = input('post.clear/a', array());
|
$clear = $this->request->param('clear', []);
|
||||||
foreach ($clear as $key => $value) {
|
foreach ($clear as $key => $value) {
|
||||||
if ($value == 'cache') {
|
if ($value == 'cache') {
|
||||||
\think\facade\Cache::clear(); // 清空缓存数据
|
\think\facade\Cache::clear(); // 清空缓存数据
|
||||||
|
|||||||
@@ -26,4 +26,46 @@ class AdService{
|
|||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title 获取广告位信息
|
||||||
|
*
|
||||||
|
* @param [type] $request
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function getAdPlaceDetail($request){
|
||||||
|
$id = $request->param('id', 0);
|
||||||
|
$place = AdPlace::where('id', '=', $id)->findOrEmpty();
|
||||||
|
return $place->isEmpty() ? [] : $place;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title 创建广告位
|
||||||
|
*
|
||||||
|
* @param [type] $request
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function createAdPlace($request){
|
||||||
|
$data = $request->post();
|
||||||
|
|
||||||
|
return AdPlace::create($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAdPlace($request){
|
||||||
|
$data = $request->post();
|
||||||
|
|
||||||
|
return AdPlace::update($data, ['id' => $data['id']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdByPlace($request){
|
||||||
|
$param = $request->param();
|
||||||
|
$order = "id desc";
|
||||||
|
|
||||||
|
if(isset($param['id']) && $param['id']){
|
||||||
|
$map[] = ['place_id', '=', $param['id']];
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = Ad::where($map)->order($order)->paginate($request->pageConfig);
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
{
|
{
|
||||||
"name": "molong",
|
"name": "molong",
|
||||||
"email": "molong@tensent.cn"
|
"email": "molong@tensent.cn"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.1.0",
|
"php": ">=7.1.0",
|
||||||
@@ -52,5 +52,6 @@
|
|||||||
"@php think service:discover",
|
"@php think service:discover",
|
||||||
"@php think vendor:publish"
|
"@php think vendor:publish"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"prefer-stable": true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user