127 lines
4.5 KiB
PHP
127 lines
4.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace app\api\controller\v1;
|
|
|
|
use app\api\model\AdvertiseSpace as AdvertiseSpaceModel;
|
|
use app\api\validate\AdvertiseSpace as AdvertiseSpaceValidate;
|
|
|
|
/**
|
|
* 广告位类
|
|
* Class AdvertiseSpace
|
|
* @package app\api\controller
|
|
*/
|
|
class AdvertiseSpace extends Base
|
|
{
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
$this->validate = new AdvertiseSpaceValidate();
|
|
$this->model = new AdvertiseSpaceModel();
|
|
}
|
|
|
|
|
|
/**
|
|
* 列表
|
|
*/
|
|
public function index():\think\Response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
|
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
|
unset($inputData['language_id']);
|
|
}
|
|
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
|
|
if (isset($inputData['advertise_page_id']) && $inputData['advertise_page_id'] != '' && $inputData['advertise_page_id'] != 0) {
|
|
$this->focus['advertise_page_id'] = $inputData['advertise_page_id'];
|
|
}
|
|
$this->orderby['create_time'] = 'desc';
|
|
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->orderby,$this->field);
|
|
|
|
return $this->msg(200,'获取列表成功',$result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 修改
|
|
*/
|
|
public function update():\think\Response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
|
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
|
unset($inputData['language_id']);
|
|
}
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
//修改前,先判断广告位数量 上限,如果已经使用的位置比当前修改提交过来的 数量大,则不让修改
|
|
$useNum = $this->model->getUseSpaceNum($inputData);
|
|
if ($useNum > $inputData['max_num']) {
|
|
return $this->msg(504,'此广告位已经使用了'.$useNum.',不能修改比使用数量小的数值!');
|
|
}
|
|
$result = $this->model->editData($inputData);
|
|
if ($result) {
|
|
return $this->msg(200,'更改成功');
|
|
} else {
|
|
return $this->msg(504,'更改失败');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取可用的列表
|
|
*/
|
|
public function invalidList():\think\Response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
|
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
|
unset($inputData['language_id']);
|
|
}
|
|
$result = $this->model->getList($inputData);
|
|
// $result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->orderby,$this->field);
|
|
if ($result) {
|
|
foreach ($result as $key => $item) {
|
|
if ($result[$key]['max_num'] - $result[$key]['use_num'] <= 0) {
|
|
$result[$key]['is_show'] = 0; //不显示列表项
|
|
} else {
|
|
$result[$key]['is_show'] = 1; //显示列表项
|
|
}
|
|
}
|
|
}
|
|
//查询出当前广告位已经存在多少广告,
|
|
return $this->msg(200,'获取列表成功',$result);
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
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->getAd($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,"该广告位已经被使用,不能删除");
|
|
}
|
|
}
|
|
}
|