init: 项目初始代码
This commit is contained in:
124
app/api/controller/v1/Advertisement.php
Normal file
124
app/api/controller/v1/Advertisement.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Advertisement as AdvertisementModel;
|
||||
use app\api\validate\Advertisement as AdvertisementValidate;
|
||||
|
||||
/**
|
||||
* 广告类
|
||||
* Class Advertisement
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Advertisement extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new AdvertisementValidate();
|
||||
$this->model = new AdvertisementModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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_space_id']) && $inputData['advertise_space_id'] != '' && $inputData['advertise_space_id'] != 0) {
|
||||
$this->focus['advertise_space_id'] = $inputData['advertise_space_id'];
|
||||
}
|
||||
|
||||
if (isset($inputData['name']) && $inputData['name'] != '') {
|
||||
$this->simple['name'] = $inputData['name'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order,$this->field);
|
||||
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\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());
|
||||
}
|
||||
//动态检测数据是否完整
|
||||
$isExitsSpace = $this->model->dynamicCheck(\app\api\model\AdvertiseSpace::class,['id'=>$inputData['advertise_space_id']]);
|
||||
if (!$isExitsSpace) {
|
||||
return $this->msg(504,'广告位数据有变动,请重新填写再提交!');
|
||||
}
|
||||
//查询是否满足广告位数量上限
|
||||
$isFull = $this->model->getAdvertiseSpaceMaxNum($inputData['advertise_space_id']);
|
||||
$useNum = $this->model->getAdvertiseUseSpaceNum($inputData);
|
||||
if ($useNum+1 > $isFull) {
|
||||
return $this->msg(504,'广告位已经数量达到上限!');
|
||||
}
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\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());
|
||||
}
|
||||
//动态检测数据是否完整
|
||||
$isExitsSpace = $this->model->dynamicCheck(\app\api\model\AdvertiseSpace::class,['id'=>$inputData['advertise_space_id']]);
|
||||
if (!$isExitsSpace) {
|
||||
return $this->msg(504,'广告位数据有变动,请重新填写再提交!');
|
||||
}
|
||||
//查询是否满足广告位数量上限
|
||||
$isFull = $this->model->getAdvertiseSpaceMaxNum($inputData['advertise_space_id']);
|
||||
$useNum = $this->model->getAdvertiseUseSpaceNum($inputData);
|
||||
//判断是自己修改,还是其他条目修改过来
|
||||
$ret = $this->model->getBeforeUpdate($inputData);
|
||||
$useNum = $ret ? $useNum : $useNum + 1;
|
||||
if ($useNum > $isFull) {
|
||||
return $this->msg(504,'广告位已经数量达到上限!');
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user