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