99 lines
3.1 KiB
PHP
99 lines
3.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace app\api\controller\v1;
|
|
|
|
use app\api\model\AdvertisePage as AdvertisePageModel;
|
|
use app\api\validate\AdvertisePage as AdvertisePageValidate;
|
|
|
|
/**
|
|
* 广告所属页类
|
|
* Class AdvertisePage
|
|
* @package app\api\controller
|
|
*/
|
|
class AdvertisePage extends Base
|
|
{
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
$this->validate = new AdvertisePageValidate();
|
|
$this->model = new AdvertisePageModel();
|
|
}
|
|
|
|
/**
|
|
* 更新
|
|
*/
|
|
public function update():\think\Response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
$updateData = $insertData = [];
|
|
if (count($inputData['data']) > 0) {
|
|
foreach ($inputData['data'] as &$item) {
|
|
$item['site_id'] = $item['language_id'];
|
|
unset($item['language_id']);
|
|
if (isset($item['id']) && $item['id'] != '') {
|
|
if (!$this->commonValidate(__FUNCTION__,$item)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
$updateData[] =[
|
|
'id' => $item['id'],
|
|
'site_id' => $item['site_id'],
|
|
'name' => htmlspecialchars($item['name']),
|
|
'platform_id'=>$this->platformId
|
|
];
|
|
} else {
|
|
if (!$this->commonValidate('create',$item)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
$insertData[] = [
|
|
'id' => null,
|
|
'name' => htmlspecialchars($item['name']),
|
|
'site_id' => $item['site_id'],
|
|
'platform_id'=>$this->platformId
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!empty($updateData)) {
|
|
$result = $this->model->batchEditData($updateData);
|
|
} else {
|
|
$result = true;
|
|
}
|
|
if (!empty($insertData)) {
|
|
$result1 = $this->model->saveAll($insertData);
|
|
} else {
|
|
$result1 = true;
|
|
}
|
|
|
|
if ($result && $result1) {
|
|
return $this->msg(200,'更新成功');
|
|
} else {
|
|
return $this->msg(504,'更新失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
public function del():\think\Response\Json
|
|
{
|
|
$inputData = $this->request->param(['id']);
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
//查找是否有子类。
|
|
$hasData = $this->model->getAdSpace($inputData);
|
|
if (empty($hasData)) {
|
|
$result = $this->model->delData($inputData);
|
|
if ($result) {
|
|
return $this->msg(200,"删除成功");
|
|
} else {
|
|
return $this->msg(504,"删除失败");
|
|
}
|
|
} else {
|
|
return $this->msg(504,"该广告页下有内容,不能删除");
|
|
}
|
|
}
|
|
}
|