init: 项目初始代码
This commit is contained in:
175
app/api/controller/v1/Site.php
Normal file
175
app/api/controller/v1/Site.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Site as SiteModel;
|
||||
use app\api\validate\Site as SiteValidate;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 站点类
|
||||
* Class Site
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Site extends Base
|
||||
{
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new SiteValidate();
|
||||
$this->model = new SiteModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 列表接口
|
||||
*/
|
||||
public function siteIndex():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$this->focus['status'] = 0;
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
$data = [];
|
||||
foreach ($result as $item) {
|
||||
$data[] = [
|
||||
'id' => $item['id'],
|
||||
'name' => $item['language_name'],
|
||||
'currency_name' => $this->model->getCoinName($item['currency_id'])
|
||||
];
|
||||
}
|
||||
return $this->msg(200,'获取列表成功',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function read():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->getInfo($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} else {
|
||||
return $this->msg(504,'获取列表失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
//语言包
|
||||
if (isset($inputData['language_id']) || !empty($inputData['language_id']) || $inputData['language_id'] != 0) {
|
||||
$this->focus['language_id'] = $inputData['language_id'];
|
||||
} else {
|
||||
return $this->msg(504,'语言包ID不正确,请检查!');
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//验证站点是否已经添加过
|
||||
$isExits = $this->model->getSiteData($inputData);
|
||||
if (count($isExits) >= 1) {
|
||||
return $this->msg(504,'一个品牌只能添加一个相同语言的站点。');
|
||||
}
|
||||
//增加站点加密算法 语言ID+站点域名,
|
||||
$inputData['app_id'] = md5($inputData['language_id'].$inputData['domain']);
|
||||
$inputData['app_key'] = md5($inputData['app_id']);
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
Cache::set($inputData['app_id'],$inputData['app_key']);
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//验证站点是否已经添加过
|
||||
$isExits = $this->model->getSiteData($inputData);
|
||||
|
||||
if (count($isExits) >= 1 && !in_array($inputData['id'],$isExits)) {
|
||||
return $this->msg(504,'一个品牌只能添加一个相同语言的站点。');
|
||||
}
|
||||
//增加站点加密算法 语言ID+站点域名,
|
||||
$inputData['app_id'] = md5($inputData['language_id'].$inputData['domain']);
|
||||
$inputData['app_key'] = md5($inputData['app_id']);
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
Cache::set($inputData['app_id'],$inputData['app_key']);
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导航数据
|
||||
*/
|
||||
public function getNavigatorList():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
$this->commonValidate(__FUNCTION__,$inputData);
|
||||
$result = $this->model->getNav($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} 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());
|
||||
}
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user