You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.9 KiB
148 lines
4.9 KiB
<?php
|
|
|
|
namespace app\admin\service\document;
|
|
|
|
use app\home\service\BaseHomeService;
|
|
use app\model\LandingPageModel;
|
|
|
|
class LandingPageService extends BaseHomeService
|
|
{
|
|
public function index(): array
|
|
{
|
|
try {
|
|
$rows = [];
|
|
$list = LandingPageModel::where('is_delete', LandingPageModel::IS_DELETE_NO)
|
|
->order('id', 'desc')->select();
|
|
if(!$list->isEmpty()){
|
|
$rows = $list->toArray();
|
|
}
|
|
|
|
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
|
|
}catch (\Exception $exception){
|
|
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
|
|
}
|
|
}
|
|
|
|
public function add($param): array
|
|
{
|
|
try {
|
|
|
|
// 名称
|
|
if(empty($param['name']) || !is_string($param['name'])){
|
|
return $this->toData('1', '名称无效');
|
|
}
|
|
|
|
// 内容
|
|
if(empty($param['content']) || !is_string($param['content'])){
|
|
return $this->toData('1', '内容无效');
|
|
}
|
|
|
|
// 跳转地址
|
|
if(empty($param['link_url']) || !is_string($param['link_url'])){
|
|
$param['link_url'] = '';
|
|
}
|
|
|
|
if(!isset($param['status']) || !in_array($param['status'], [LandingPageModel::STATUS_ON, LandingPageModel::STATUS_OFF])){
|
|
return $this->toData('1', '状态无效');
|
|
}
|
|
|
|
$docExists = LandingPageModel::where('is_delete', LandingPageModel::IS_DELETE_NO)
|
|
->where('name', $param['name'])
|
|
->find();
|
|
if(!empty($docExists)){
|
|
return $this->toData('1', '已存在相同内容');
|
|
}
|
|
|
|
$doc = new LandingPageModel;
|
|
$doc->name = $param['name'];
|
|
$doc->content = $param['content'];
|
|
$doc->click_num = 0;
|
|
$doc->link_url = 0;
|
|
$doc->is_delete = 0;
|
|
$doc->status = 0;
|
|
$doc->create_time = date('Y-m-d H:i:s');
|
|
$doc->update_time = date('Y-m-d H:i:s');
|
|
$doc->save();
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
}catch (\Exception $exception){
|
|
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
|
|
}
|
|
}
|
|
|
|
public function edit($param): array
|
|
{
|
|
try {
|
|
if(empty($param['id']) || !is_numeric($param['id'])){
|
|
return $this->toData('1', '目标不存在');
|
|
}
|
|
|
|
$doc = LandingPageModel::where('id', $param['id'])
|
|
->where('is_delete', LandingPageModel::IS_DELETE_NO)
|
|
->find();
|
|
if(empty($doc)){
|
|
return $this->toData('1', '目标不存在');
|
|
}
|
|
|
|
// 名称
|
|
if(empty($param['name']) || !is_string($param['name'])){
|
|
return $this->toData('1', '名称无效');
|
|
}
|
|
|
|
// 内容
|
|
if(empty($param['content']) || !is_string($param['content'])){
|
|
return $this->toData('1', '内容无效');
|
|
}
|
|
|
|
// 跳转地址
|
|
if(empty($param['link_url']) || !is_string($param['link_url'])){
|
|
$param['link_url'] = '';
|
|
}
|
|
|
|
if(!isset($param['status']) || !in_array($param['status'], [LandingPageModel::STATUS_ON, LandingPageModel::STATUS_OFF])){
|
|
return $this->toData('1', '状态无效');
|
|
}
|
|
|
|
$docExists = LandingPageModel::where('is_delete', LandingPageModel::IS_DELETE_NO)
|
|
->where('id', '<>', $param['id'])
|
|
->where('name', $param['name'])->find();
|
|
if(!empty($docExists)){
|
|
return $this->toData('1', '已存在相同内容');
|
|
}
|
|
|
|
$doc->name = $param['name'];
|
|
$doc->content = $param['content'];
|
|
$doc->status = $param['status'];
|
|
$doc->link_url = $param['link_url'];
|
|
$doc->update_time = date('Y-m-d H:i:s');
|
|
$doc->save();
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
}catch (\Exception $exception){
|
|
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
|
|
}
|
|
}
|
|
|
|
public function del($param): array
|
|
{
|
|
try {
|
|
if(empty($param['id']) || !is_numeric($param['id'])){
|
|
return $this->toData('1', '目标不存在');
|
|
}
|
|
|
|
$doc = LandingPageModel::where('id', $param['id'])
|
|
->where('is_delete', LandingPageModel::IS_DELETE_NO)
|
|
->find();
|
|
if(empty($doc)){
|
|
return $this->toData('1', '目标不存在');
|
|
}
|
|
|
|
$doc->is_delete = LandingPageModel::IS_DELETE_YES;
|
|
$doc->save();
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
}catch (\Exception $exception){
|
|
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
|
|
}
|
|
}
|
|
}
|