init: 项目初始代码
This commit is contained in:
90
app/api/controller/v1/Admin.php
Normal file
90
app/api/controller/v1/Admin.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Admin as AdminModel;
|
||||
use app\api\validate\Admin as AdminValidate;
|
||||
|
||||
/**
|
||||
* 后台管理员类
|
||||
* Class Admin
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Admin extends Base
|
||||
{
|
||||
const EMPTY_ADMINID = '-100';
|
||||
const EMPTY_ADMIN = '-101';
|
||||
const ERR_ADD = '-300';
|
||||
const ERR_EDIT = '-301';
|
||||
const ERR_FORBIDDEN = '-302';
|
||||
|
||||
|
||||
const ERROR = [
|
||||
self::ERR_ADD => '添加管理员失败',
|
||||
self::ERR_EDIT => '编辑管理员失败',
|
||||
self::ERR_FORBIDDEN => '禁用管理员失败',
|
||||
self::EMPTY_ADMINID => 'id不能为空',
|
||||
self::EMPTY_ADMIN => '没有找到该管理员'
|
||||
];
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new AdminValidate();
|
||||
$this->model = new AdminModel();
|
||||
}
|
||||
|
||||
protected $errorMsg = [
|
||||
self::EMPTY_ADMINID
|
||||
];
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @return \think\Response
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
$inputData = $this->request->param(['admin_id']);
|
||||
|
||||
if ($inputData['admin_id'] <= 0) {
|
||||
return $this->msg(self::EMPTY_ADMINID, self::ERROR[self::EMPTY_ADMINID]);
|
||||
}
|
||||
|
||||
$info = $this->model->getInfo($inputData['admin_id']);
|
||||
if (empty($info)) {
|
||||
return $this->msg(self::EMPTY_ADMIN, self::ERROR[self::EMPTY_ADMIN]);
|
||||
}
|
||||
return $this->msg(200, '获取管理员信息成功', $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$inputData = $this->request->param(['admin_id', 'password', 'role_id', 'mobile']);
|
||||
$inputData['password'] = md5($inputData['password']);
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
if ($inputData['password'] == '') {
|
||||
unset($inputData['password']);
|
||||
}
|
||||
|
||||
$result = $this->model->edit($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200, '编辑管理员成功');
|
||||
} else {
|
||||
return $this->msg(504, '编辑管理员失败');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
98
app/api/controller/v1/AdvertisePage.php
Normal file
98
app/api/controller/v1/AdvertisePage.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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,"该广告页下有内容,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
126
app/api/controller/v1/AdvertiseSpace.php
Normal file
126
app/api/controller/v1/AdvertiseSpace.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?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,"该广告位已经被使用,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
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,'更改失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
135
app/api/controller/v1/Article.php
Normal file
135
app/api/controller/v1/Article.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Article as ArticleModel;
|
||||
use app\api\validate\Article as ArticleValidate;
|
||||
|
||||
/**
|
||||
* 文章新闻模块
|
||||
* Class Article
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Article extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new ArticleValidate();
|
||||
$this->model = new ArticleModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['article_type_id']) && $inputData['article_type_id'] != '' && $inputData['article_type_id'] != 0) {
|
||||
$this->focus['article_type_id'] = $inputData['article_type_id'];
|
||||
}
|
||||
|
||||
if (isset($inputData['title']) && $inputData['title'] != '') {
|
||||
$this->simple['title'] = $inputData['title'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
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 create():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time']) && !$inputData['create_time']) {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time'])) {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
131
app/api/controller/v1/ArticleType.php
Normal file
131
app/api/controller/v1/ArticleType.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\ArticleType as ArticleTypeModel;
|
||||
use app\api\validate\ArticleType as ArticleTypeValidate;
|
||||
|
||||
/**
|
||||
* 文章类型类
|
||||
* Class FileType
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class ArticleType extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new ArticleTypeValidate();
|
||||
$this->model = new ArticleTypeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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['sort']) && $inputData['sort'] != '') {
|
||||
$this->orderby['sort'] = $inputData['sort'];
|
||||
} else {
|
||||
$this->orderby['sort'] = 'asc';
|
||||
}
|
||||
|
||||
$this->field = ['id','platform_id','site_id','icon','name','sort'];
|
||||
|
||||
$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();
|
||||
$updateData = $insertData = [];
|
||||
if (count($inputData['data']) > 0) {
|
||||
foreach ($inputData['data'] as &$item) {
|
||||
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['language_id'],
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'sort' => $item['sort'],
|
||||
'platform_id'=>$this->platformId
|
||||
];
|
||||
} else {
|
||||
if (!$this->commonValidate('create',$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$insertData[] = [
|
||||
'id' => null,
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'site_id' => $item['language_id'],
|
||||
'sort' => $item['sort'],
|
||||
'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->getArticleData($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,"该类型下有内容,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
73
app/api/controller/v1/Attribute.php
Normal file
73
app/api/controller/v1/Attribute.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Attribute as AttributeModel;
|
||||
use app\api\validate\Attribute as AttributeValidate;
|
||||
|
||||
/**
|
||||
* Class Attribute
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Attribute extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new AttributeModel();
|
||||
$this->validate = new AttributeValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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['page']) && $inputData['page'] != '') {
|
||||
$this->page = $inputData['page'];
|
||||
}
|
||||
|
||||
if (isset($inputData['size']) && $inputData['size'] != '') {
|
||||
$this->page = $inputData['size'];
|
||||
}
|
||||
|
||||
$result = $this->model->getIndexList($this->page,$this->size,$this->simple,$this->focus,$this->order,$this->field);
|
||||
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());
|
||||
}
|
||||
$hasGoodsAttr = $this->model->getGoodsAttrById($inputData);
|
||||
|
||||
if (!$hasGoodsAttr) {
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,"此属性有商品引用,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
157
app/api/controller/v1/Auth.php
Normal file
157
app/api/controller/v1/Auth.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Admin as model;
|
||||
use app\api\validate\Admin as AdminValidate;
|
||||
use app\api\model\Role as RoleModel;
|
||||
|
||||
use encryption\Rsa;
|
||||
use sso\SSOClient;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Config;
|
||||
use think\facade\Env;
|
||||
use think\facade\Filesystem;
|
||||
|
||||
/**
|
||||
* Class Auth
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Auth extends Base
|
||||
{
|
||||
const EMPTY_ADMIN = -100;
|
||||
const ERR_PASSWORD = -101;
|
||||
const ERR_TOKEN = -102;
|
||||
const EMPTY_ROLE = -103;
|
||||
const ERR_CLOSED = -104;
|
||||
const ERR_PWD = -300;
|
||||
const EMPTY_HEADIMG = -105;
|
||||
const ERR_MOBILE = -301;
|
||||
const ERR_SAMEPWD = -302;
|
||||
|
||||
const ERROR = [
|
||||
self::EMPTY_ADMIN => '该用户不存在',
|
||||
self::ERR_PASSWORD => '用户名或密码错误',
|
||||
self::ERR_TOKEN => 'token解析失败',
|
||||
self::EMPTY_ROLE => '当前用户没有分配角色',
|
||||
self::ERR_CLOSED => '该用户被禁用',
|
||||
self::ERR_PWD => '旧密码错误',
|
||||
self::EMPTY_HEADIMG => '请选择头像',
|
||||
self::ERR_MOBILE => '手机号格式错误',
|
||||
self::ERR_SAMEPWD => '新密码不能与旧密码相同'
|
||||
];
|
||||
|
||||
//后台管理员控制器
|
||||
protected $validate = null;
|
||||
//定义管理员模型
|
||||
protected $model = null;
|
||||
//定义管理员模型
|
||||
protected $roleModel = null;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new model();
|
||||
$this->validate = new AdminValidate();
|
||||
$this->roleModel = new RoleModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 后台登录接口
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
//获取输入数据
|
||||
$inputData = $this->request->param(['username', 'password']);
|
||||
//验证器验证
|
||||
$this->commonValidate(__FUNCTION__,$inputData);
|
||||
|
||||
$adminInfo = $this->model->getInfoByUsername($inputData['username']);
|
||||
|
||||
if (empty($adminInfo)) {
|
||||
return $this->msg(self::EMPTY_ADMIN, self::ERROR[self::EMPTY_ADMIN]);
|
||||
}
|
||||
|
||||
if ($inputData['password'] != $adminInfo['password']) {
|
||||
return $this->msg(self::ERR_PASSWORD, self::ERROR[self::ERR_PASSWORD]);
|
||||
}
|
||||
|
||||
if ($adminInfo['status'] == 1) {
|
||||
return $this->msg(self::ERR_CLOSED, self::ERROR[self::ERR_CLOSED]);
|
||||
}
|
||||
unset($adminInfo['password']);
|
||||
$login_token = $this->jwt->getToken($adminInfo);
|
||||
Cache::set('api-info',$adminInfo,300);
|
||||
$data = [
|
||||
'login_token' => $login_token,
|
||||
'exp' => Env::get('jwt_config.exp'),
|
||||
'need_update_pwd' => $inputData['password'] == md5('Aa-1221') ? 1 : 0
|
||||
];
|
||||
return $this->msg(200, '登录成功', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员基本信息
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$role = $this->roleModel->getInfo($this->adminInfo);
|
||||
if (empty($role)) {
|
||||
return $this->msg(self::EMPTY_ROLE, self::ERROR[self::EMPTY_ROLE]);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'roles' => [$role['role_name'] ?? $role['name']],
|
||||
'name' => $this->adminInfo['username'],
|
||||
'avatar' => $this->adminInfo['avatar']
|
||||
];
|
||||
|
||||
return $this->msg(200, '获取用户信息成功', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户所有权限
|
||||
*/
|
||||
public function getAuth()
|
||||
{
|
||||
$data = [
|
||||
'auth_list' => $this->adminInfo['auth_id_list']
|
||||
];
|
||||
return $this->msg(200, '获取权限成功', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
if (!Session::has('signed_in') || !Session::get('signed_in')) {
|
||||
return success('操作成功');
|
||||
}
|
||||
$sso = new SSOClient();
|
||||
$access_token = Session::get('access_token');
|
||||
if (empty($access_token)) {
|
||||
return error('请选登录');
|
||||
}
|
||||
$result = $sso->notifySSOServerSigninOut($access_token, Session::get('uc_sessid'));
|
||||
if (empty($result)) {
|
||||
return error('操作失败');
|
||||
}
|
||||
if (0 != $result['errno']) {
|
||||
return error($result['errmsg']);
|
||||
}
|
||||
Session::clear();
|
||||
return success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员列表
|
||||
*/
|
||||
public function list(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1138
app/api/controller/v1/Base.php
Normal file
1138
app/api/controller/v1/Base.php
Normal file
File diff suppressed because it is too large
Load Diff
135
app/api/controller/v1/Brand.php
Normal file
135
app/api/controller/v1/Brand.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Brand as BrandModel;
|
||||
use app\api\validate\Brand as BrandValidate;
|
||||
|
||||
/**
|
||||
* 文章新闻模块
|
||||
* Class Brand
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Brand extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new BrandValidate();
|
||||
$this->model = new BrandModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['Brand_type_id']) && $inputData['Brand_type_id'] != '' && $inputData['Brand_type_id'] != 0) {
|
||||
$this->focus['Brand_type_id'] = $inputData['Brand_type_id'];
|
||||
}
|
||||
|
||||
if (isset($inputData['title']) && $inputData['title'] != '') {
|
||||
$this->simple['title'] = $inputData['title'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
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 create():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time']) && !$inputData['create_time']) {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time'])) {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
131
app/api/controller/v1/BrandType.php
Normal file
131
app/api/controller/v1/BrandType.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\BrandType as BrandTypeModel;
|
||||
use app\api\validate\BrandType as BrandTypeValidate;
|
||||
|
||||
/**
|
||||
* 文章类型类
|
||||
* Class FileType
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class BrandType extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new BrandTypeValidate();
|
||||
$this->model = new BrandTypeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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['sort']) && $inputData['sort'] != '') {
|
||||
$this->orderby['sort'] = $inputData['sort'];
|
||||
} else {
|
||||
$this->orderby['sort'] = 'asc';
|
||||
}
|
||||
|
||||
$this->field = ['id','platform_id','site_id','icon','name','sort'];
|
||||
|
||||
$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();
|
||||
$updateData = $insertData = [];
|
||||
if (count($inputData['data']) > 0) {
|
||||
foreach ($inputData['data'] as &$item) {
|
||||
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['language_id'],
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'sort' => $item['sort'],
|
||||
'platform_id'=>$this->platformId
|
||||
];
|
||||
} else {
|
||||
if (!$this->commonValidate('create',$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$insertData[] = [
|
||||
'id' => null,
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'site_id' => $item['language_id'],
|
||||
'sort' => $item['sort'],
|
||||
'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->getArticleData($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,"该类型下有内容,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
44
app/api/controller/v1/BulkBuy.php
Normal file
44
app/api/controller/v1/BulkBuy.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\BulkBuy as BulkBuyModel;
|
||||
use app\api\validate\BulkBuy as BulkBuyValidate;
|
||||
|
||||
/**
|
||||
* 大批量采购类
|
||||
* Class BulkBuy
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class BulkBuy extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new BulkBuyModel();
|
||||
$this->validate = new BulkBuyValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$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());
|
||||
}
|
||||
$this->orderby['create_time'] = 'desc';
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->orderby,$this->field);
|
||||
foreach ($result['page'] as $key => $item) {
|
||||
$result['page'][$key]['area_name'] = $this->model->getAreaNameById(substr($item['area_id'],0,2)).$this->model->getAreaNameById($item['area_id']);
|
||||
$result['page'][$key]['delivery_time'] = date('Y-m-d',$item['delivery_time']);
|
||||
}
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
}
|
||||
59
app/api/controller/v1/Comment.php
Normal file
59
app/api/controller/v1/Comment.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Comment as CommentModel;
|
||||
use app\api\validate\Comment as CommentValidate;
|
||||
/**
|
||||
* 用户评价类
|
||||
* Class Comment
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Comment extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new CommentModel();
|
||||
$this->validate = new CommentValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['nickname']) && $inputData['nickname'] != '') {
|
||||
$this->simple['nickname'] = $inputData['nickname'];
|
||||
}
|
||||
|
||||
if (isset($inputData['comment']) && $inputData['comment'] != '') {
|
||||
$this->simple['comment'] = $inputData['comment'];
|
||||
}
|
||||
|
||||
//正常数据验证器验证
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
if (!empty($this->focus)) {
|
||||
if (!$this->commonValidate(__FUNCTION__,$this->focus)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
}
|
||||
$this->order['create_time'] = 'desc';
|
||||
//过滤字段
|
||||
$this->field = ['id','platform_id','language_id','site_id','avatar','name','nickname','comment','url','sort','create_time'];
|
||||
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order,$this->field);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
}
|
||||
18
app/api/controller/v1/Country.php
Normal file
18
app/api/controller/v1/Country.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Country as CountryModel;
|
||||
|
||||
/**
|
||||
* Class Country
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Country extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new CountryModel();
|
||||
}
|
||||
|
||||
}
|
||||
41
app/api/controller/v1/CouponSubscribe.php
Normal file
41
app/api/controller/v1/CouponSubscribe.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\CouponSubscribe as CouponSubscribeModel;
|
||||
use app\api\validate\CouponSubscribe as CouponSubscribeValidate;
|
||||
|
||||
/**
|
||||
* 优惠券领用表
|
||||
* Class CouponSubscribe
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class CouponSubscribe extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new CouponSubscribeModel();
|
||||
$this->validate = new CouponSubscribeValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$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());
|
||||
}
|
||||
$this->orderby = ['create_time'=>'desc'];
|
||||
$this->field = ['id','platform_id','site_id','email','phone','create_time'];
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->orderby,$this->field);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
}
|
||||
129
app/api/controller/v1/Currency.php
Normal file
129
app/api/controller/v1/Currency.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Currency as CurrencyModel;
|
||||
use app\api\validate\Currency as CurrencyValidate;
|
||||
|
||||
/**
|
||||
* 货币类
|
||||
* Class Currency
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Currency extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
$this->model = new CurrencyModel();
|
||||
$this->validate = new CurrencyValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index(): \think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['status']) && $inputData['status'] != '') {
|
||||
$this->focus['status'] = $inputData['status'];
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order,$this->field);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id','status']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//查找是否有平台使用此币种。
|
||||
$data = $this->model->find($inputData['id']);
|
||||
$hasPlatformUse = $this->model->getPlatformCoin($inputData['id']);
|
||||
if (!$hasPlatformUse || $data['status'] == 1) {
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"操作成功");
|
||||
} else {
|
||||
return $this->msg(504,"操作失败");
|
||||
}
|
||||
} 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());
|
||||
}
|
||||
//查找是否有平台使用此币种。
|
||||
$hasPlatformUse = $this->model->getPlatformCoin($inputData['id']);
|
||||
if (!$hasPlatformUse) {
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,"有平台使用此币种,不能进行删除操作");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
60
app/api/controller/v1/Faq.php
Normal file
60
app/api/controller/v1/Faq.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Faq as FaqModel;
|
||||
use app\api\validate\Faq as FaqValidate;
|
||||
|
||||
/**
|
||||
* 常见问题类
|
||||
* Class Faq
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Faq extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new FaqModel();
|
||||
$this->validate = new FaqValidate();
|
||||
}
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['faq_type_id']) && $inputData['faq_type_id'] != '' && $inputData['faq_type_id'] != 0) {
|
||||
$this->focus['faq_type_id'] = $inputData['faq_type_id'];
|
||||
}
|
||||
|
||||
|
||||
if (isset($inputData['answer']) && $inputData['answer'] != '') {
|
||||
$this->simple['answer'] = $inputData['answer'];
|
||||
$this->simple['question'] = $inputData['answer'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
if (!empty($this->focus)) {
|
||||
if (!$this->commonValidate(__FUNCTION__,$this->focus)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order,$this->field);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
}
|
||||
129
app/api/controller/v1/FaqType.php
Normal file
129
app/api/controller/v1/FaqType.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\FaqType as FaqTypeModel;
|
||||
use app\api\validate\FaqType as FaqTypeValidate;
|
||||
|
||||
/**
|
||||
* Class FaqType
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class FaqType extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
$this->model = new FaqTypeModel();
|
||||
$this->validate = new FaqTypeValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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['sort']) && $inputData['sort'] != '') {
|
||||
$this->order['sort'] = $inputData['sort'];
|
||||
}
|
||||
//过滤字段
|
||||
$this->field = ['id','platform_id','language_id','icon','site_id','name','sort'];
|
||||
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order,$this->field);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$updateData = $insertData = [];
|
||||
if (count($inputData['data']) > 0) {
|
||||
foreach ($inputData['data'] as $key => $item) {
|
||||
if (isset($item['id'])) {
|
||||
if (!$this->commonValidate(__FUNCTION__,$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$updateData[] =[
|
||||
'id' => $item['id'],
|
||||
'name' => $item['name'],
|
||||
'site_id' => $item['language_id'],
|
||||
'icon' => $item['icon']??0,
|
||||
'sort' => $item['sort'],
|
||||
'platform_id' =>$this->platformId
|
||||
];
|
||||
unset($item['language_id']);
|
||||
} else {
|
||||
$item['site_id'] = $item['language_id'];
|
||||
unset($item['language_id']);
|
||||
if (!$this->commonValidate('create',$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$insertData[] = [
|
||||
'id' => null,
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??0,
|
||||
'site_id' => $item['site_id'],
|
||||
'sort' => $item['sort'],
|
||||
'platform_id'=>$this->platformId
|
||||
];
|
||||
unset($item['language_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = $result1 = false;
|
||||
if (!empty($updateData)) {
|
||||
$result = $this->model->batchEditData($updateData);
|
||||
$result1 = true;
|
||||
}
|
||||
if (!empty($insertData)) {
|
||||
$result1 = $this->model->saveAll($insertData);
|
||||
$result = 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->getFaqData($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,"该类型下有内容,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
135
app/api/controller/v1/FileType.php
Normal file
135
app/api/controller/v1/FileType.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\FileType as FileTypeModel;
|
||||
use app\api\validate\FileType as FileTypeValidate;
|
||||
|
||||
/**
|
||||
* 文件类型类
|
||||
* Class FileType
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class FileType extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new FileTypeValidate();
|
||||
$this->model = new FileTypeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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['sort']) && $inputData['sort'] != '') {
|
||||
$this->order['sort'] = $inputData['sort'];
|
||||
} else {
|
||||
$this->order['sort'] = 'asc';
|
||||
}
|
||||
|
||||
$this->field = ['id','platform_id','language_id','icon','site_id','name','sort'];
|
||||
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order,$this->field);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$updateData = $insertData = [];
|
||||
if (count($inputData['data']) > 0) {
|
||||
foreach ($inputData['data'] as &$item) {
|
||||
if (isset($item['id'])) {
|
||||
//欺骗验证器
|
||||
$item['site_id'] = $item['language_id'];
|
||||
if (!$this->commonValidate(__FUNCTION__,$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$updateData[] =[
|
||||
'id' => $item['id'],
|
||||
'site_id' => $item['language_id'],
|
||||
'icon' => $item['icon']??0,
|
||||
'name' => $item['name'],
|
||||
'sort' => $item['sort'],
|
||||
'platform_id'=>$this->platformId
|
||||
];
|
||||
} else {
|
||||
//欺骗验证器
|
||||
$item['site_id'] = $item['language_id'];
|
||||
if (!$this->commonValidate('create',$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$insertData[] = [
|
||||
'id' => null,
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??0,
|
||||
'site_id' => $item['language_id'],
|
||||
'sort' => $item['sort'],
|
||||
'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->getSoftManualData($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,"该类型下有内容,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
487
app/api/controller/v1/Goods.php
Normal file
487
app/api/controller/v1/Goods.php
Normal file
@@ -0,0 +1,487 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Goods as GoodsModel;
|
||||
use app\api\validate\Goods as GoodsValidate;
|
||||
|
||||
/**
|
||||
* 商品类
|
||||
* Class Goods
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Goods extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new GoodsModel();
|
||||
$this->validate = new GoodsValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['goods_category_id']) && $inputData['goods_category_id'] != '' && $inputData['goods_category_id'] != 0 ) {
|
||||
//批量获取当前类与子类ID
|
||||
$inputData['goods_category_id'] = $this->model->getAllSonCategory(['id'=>$inputData['goods_category_id']]);
|
||||
}
|
||||
|
||||
if (isset($inputData['status']) && $inputData['status'] != '' ) {
|
||||
$this->focus['status'] = $inputData['status'];
|
||||
}
|
||||
|
||||
//组建查询条件
|
||||
if (isset($inputData['keyword']) && $inputData['keyword'] != '') {
|
||||
$this->simple['model_number'] = $inputData['keyword'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
if (!empty($this->focus)) {
|
||||
if (!$this->commonValidate(__FUNCTION__,$this->focus)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
}
|
||||
|
||||
//强制商品列表按添加时间倒序
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
if (!empty($result['page'])) {
|
||||
foreach ($result['page'] as &$value) {
|
||||
$value['language_id'] = $value['site_id'];
|
||||
$value['language_name'] = $this->model->getLanguageName($value['site_id']);
|
||||
$value['platform_name'] = $this->model->getPlatformName($value['platform_id']);
|
||||
}
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} else {
|
||||
if (isset($inputData['keyword']) && $inputData['keyword'] != '') {
|
||||
if (isset($this->simple['model_number'])) {
|
||||
unset($this->simple['model_number']);
|
||||
}
|
||||
$this->simple['name'] = $inputData['keyword'];
|
||||
}
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
if (!empty($result['page'])) {
|
||||
foreach ($result['page'] as &$value) {
|
||||
$value['language_name'] = $this->model->getLanguageName($value['site_id']);
|
||||
$value['platform_name'] = $this->model->getPlatformName($value['platform_id']);
|
||||
}
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
// if (isset($result['count']) && $result['count'] == 0) {
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
// } else {
|
||||
// return $this->msg(504,'获取列表失败');
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\think\Response\Json
|
||||
{
|
||||
$details = $this->request->param('details','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['details'] = $details;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
// 过滤ID
|
||||
if (isset($inputData['id']) && $inputData['id'] == '') {
|
||||
unset($inputData['id']);
|
||||
}
|
||||
|
||||
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 ((isset($inputData['attr'][0]['attribute_id']) && $inputData['attr'][0]['attribute_id'] == '') || (isset($inputData['attr'][0]['value']) && $inputData['attr'][0]['value'] == "")) {
|
||||
return $this->msg(504,'主要参数必填,请检查!');
|
||||
}
|
||||
|
||||
//主要参数不能为空
|
||||
if (isset($inputData['goods_images']) && empty($inputData['goods_images'])) {
|
||||
return $this->msg(504,'必须上传商品主图,请检查!');
|
||||
}
|
||||
|
||||
//主要参数不能为空
|
||||
if (!isset($inputData['details']) || empty($inputData['details'])) {
|
||||
return $this->msg(504,'图文介绍必填,请检查!');
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
//动态检测数据是否完整
|
||||
// $isExitsLang = $this->model->dynamicCheck(\app\api\model\Site::class,['status'=>0,'id'=>$inputData['site_id']]);
|
||||
// if (!$isExitsLang) {
|
||||
// return $this->msg(504,'语言数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// $isExitsGoodsCategory = $this->model->dynamicCheck(\app\api\model\GoodsCategory::class,['status'=>0,'id'=>$inputData['goods_category_id']]);
|
||||
// if (!$isExitsGoodsCategory) {
|
||||
// return $this->msg(504,'商品分类数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// $flag = true;
|
||||
// foreach ($inputData['attr'] as $datum) {
|
||||
// $isExitsAttr = $this->model->dynamicCheck(\app\api\model\Attribute::class,['id'=>$datum['attribute_id']]);
|
||||
// $flag = $isExitsAttr && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'商品参数有变动,请重新填写再提交!');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// foreach ($inputData['connect_goods'] as $item) {
|
||||
// $isExitsGoodsCategory = $this->model->dynamicCheck(\app\api\model\GoodsCategory::class,['status'=>0,'id'=>$item['goods_category_id']]);
|
||||
// $flag = $isExitsGoodsCategory && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'商品分类数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// $isExitsGoods = $this->model->dynamicCheck(\app\api\model\Goods::class,['status'=>0,'id'=>$item['connect_good_id']]);
|
||||
// $flag = $isExitsGoods && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'关联商品数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// foreach ($inputData['soft_manual'] as $item) {
|
||||
// $isExitsSoft = $this->model->dynamicCheck(\app\api\model\Download::class,['status'=>0,'id'=>$item['soft_manual_id']]);
|
||||
// $flag = $isExitsSoft && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'下载文件数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// $isExitsFileType = $this->model->dynamicCheck(\app\api\model\FileType::class,['status'=>0,'id'=>$item['file_type_id']]);
|
||||
// $flag = $isExitsFileType && $flag;
|
||||
// if (!$flag) {
|
||||
// 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
|
||||
{
|
||||
$details = $this->request->param('details','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['details'] = $details;
|
||||
$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 ((isset($inputData['attr'][0]['attribute_id']) && $inputData['attr'][0]['attribute_id'] == '') || (isset($inputData['attr'][0]['value']) && $inputData['attr'][0]['value'] == "")) {
|
||||
return $this->msg(504,'主要参数必填,请检查!');
|
||||
}
|
||||
|
||||
//主要参数不能为空
|
||||
if (isset($inputData['goods_images']) && empty($inputData['goods_images'])) {
|
||||
return $this->msg(504,'必须上传商品主图,请检查!');
|
||||
}
|
||||
|
||||
//主要参数不能为空
|
||||
if (!isset($inputData['details']) || empty($inputData['details'])) {
|
||||
return $this->msg(504,'图文介绍必填,请检查!');
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
// //动态检测数据是否完整
|
||||
// $isExitsLang = $this->model->dynamicCheck(\app\api\model\Site::class,['status'=>0,'id'=>$inputData['site_id']]);
|
||||
// if (!$isExitsLang) {
|
||||
// return $this->msg(504,'语言数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// $isExitsGoodsCategory = $this->model->dynamicCheck(\app\api\model\GoodsCategory::class,['status'=>0,'id'=>$inputData['goods_category_id']]);
|
||||
// if (!$isExitsGoodsCategory) {
|
||||
// return $this->msg(504,'商品分类数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// $flag = true;
|
||||
// foreach ($inputData['attr'] as $datum) {
|
||||
// $isExitsAttr = $this->model->dynamicCheck(\app\api\model\Attribute::class,['id'=>$datum['attribute_id']]);
|
||||
// $flag = $isExitsAttr && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'商品参数有变动,请重新填写再提交!');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// foreach ($inputData['connect_goods'] as $item) {
|
||||
// $isExitsGoodsCategory = $this->model->dynamicCheck(\app\api\model\GoodsCategory::class,['status'=>0,'id'=>$item['goods_category_id']]);
|
||||
// $flag = $isExitsGoodsCategory && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'关联商品,商品分类数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// $isExitsGoods = $this->model->dynamicCheck(\app\api\model\Goods::class,['status'=>0,'id'=>$item['connect_good_id']]);
|
||||
// $flag = $isExitsGoods && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'关联商品数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// foreach ($inputData['soft_manual'] as $item) {
|
||||
// $isExitsSoft = $this->model->dynamicCheck(\app\api\model\Download::class,['status'=>0,'id'=>$item['soft_manual_id']]);
|
||||
// $flag = $isExitsSoft && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'下载文件数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// $isExitsFileType = $this->model->dynamicCheck(\app\api\model\FileType::class,['status'=>0,'id'=>$item['file_type_id']]);
|
||||
// $flag = $isExitsFileType && $flag;
|
||||
// if (!$flag) {
|
||||
// return $this->msg(504,'文件分类数据有变动,请重新填写再提交!');
|
||||
// }
|
||||
// }
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function read():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
$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());
|
||||
}
|
||||
$result = $this->model->getInfo($inputData);
|
||||
$result['details'] = htmlspecialchars_decode($result['details']);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} else {
|
||||
return $this->msg(504,'获取列表失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前品牌语言列表
|
||||
* @return mixed
|
||||
*/
|
||||
public function languageList():\think\Response\Json
|
||||
{
|
||||
$result = $this->model->getPlatformLanguage($this->platformId);
|
||||
return $this->msg(200,'获取成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改分类
|
||||
*/
|
||||
public function batchCategoryModify():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
|
||||
if (count($inputData['id']) > 0) {
|
||||
//构建分类数据
|
||||
$newCateData = [];
|
||||
foreach ($inputData['id'] as $item) {
|
||||
//分类不能超过3个,
|
||||
$newCateData[] = [
|
||||
'id' => $item,
|
||||
'goods_category_id' => $inputData['goods_category_id']
|
||||
];
|
||||
}
|
||||
|
||||
$result = $this->model->goodsBatchEditCategory($newCateData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,'提交的数据有问题,请检查后再提交');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
public function batchGoodsDel():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (count($inputData['id']) > 0) {
|
||||
$newData = [];
|
||||
//构建数据
|
||||
foreach ($inputData['id'] as $item) {
|
||||
$newData[] = [
|
||||
'id' => $item,
|
||||
];
|
||||
}
|
||||
|
||||
$result = $this->model->batchDelData($newData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'删除成功');
|
||||
} else {
|
||||
return $this->msg(504,'删除失败');
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,'提交的数据有问题,请检查后再提交');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量启用
|
||||
*/
|
||||
public function batchGoodsEnable():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (count($inputData['id']) > 0) {
|
||||
//验证分类ID
|
||||
$newData = [];
|
||||
if (count($inputData['id']) > 0) {
|
||||
foreach ($inputData['id'] as $item) {
|
||||
$newData[] = [
|
||||
'id' => $item,
|
||||
'status' => 0
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->model->batchEditData($newData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'启用成功');
|
||||
} else {
|
||||
return $this->msg(504,'启用失败');
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->msg(504,'提交的数据有问题,请检查后再提交');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
public function changeSort():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id','sort']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeSort($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"操作成功");
|
||||
} else {
|
||||
return $this->msg(504,"操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id','status']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"操作成功");
|
||||
} else {
|
||||
return $this->msg(504,"操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类商品
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function categoryGoodsInfo():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['goods_category_id','type']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//
|
||||
if (isset($inputData['goods_category_id'])) {
|
||||
$list = $this->model->getGoodsInfoByGoodsCategoryId($inputData);
|
||||
if ($list) {
|
||||
$list['type'] = $inputData['type'];
|
||||
return $this->msg(200, '获取列表成功', $list);
|
||||
} else {
|
||||
return $this->msg(504, '获取列表失败');
|
||||
}
|
||||
} else {
|
||||
// $list['type'] = $inputData['type'];
|
||||
$list = [
|
||||
['connect_good_id'=>'','category'=>''],
|
||||
['connect_good_id'=>'','category'=>''],
|
||||
['connect_good_id'=>'','category'=>''],
|
||||
['connect_good_id'=>'','category'=>''],
|
||||
];
|
||||
return $this->msg(200, '获取列表成功', $list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量禁用
|
||||
*/
|
||||
public function batchGoodsDisable():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (count($inputData['id']) > 0) {
|
||||
//验证分类ID
|
||||
$newData = [];
|
||||
if (count($inputData['id']) > 0) {
|
||||
foreach ($inputData['id'] as $item) {
|
||||
$newData[] = [
|
||||
'id' => $item,
|
||||
'status' => 1
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->model->batchEditData($newData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'禁用成功');
|
||||
} else {
|
||||
return $this->msg(504,'禁用失败');
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,'提交的数据有问题,请检查后再提交');
|
||||
}
|
||||
}
|
||||
}
|
||||
20
app/api/controller/v1/GoodsBuyNow.php
Normal file
20
app/api/controller/v1/GoodsBuyNow.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\GoodsBuyNow as GoodsBuyNowModel;
|
||||
use app\api\validate\GoodsBuyNow as GoodsBuyNowValidate;
|
||||
|
||||
/**
|
||||
* 商品购买链接类
|
||||
* Class GoodsBuyNow
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class GoodsBuyNow extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new GoodsBuyNowModel();
|
||||
$this->validate = new GoodsBuyNowValidate();
|
||||
}
|
||||
}
|
||||
316
app/api/controller/v1/GoodsCategory.php
Normal file
316
app/api/controller/v1/GoodsCategory.php
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\GoodsCategory as GoodsCategoryModel;
|
||||
use app\api\validate\GoodsCategory as GoodsCategoryValidate;
|
||||
|
||||
/**
|
||||
* 商品分类
|
||||
* Class GoodsCategory
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class GoodsCategory extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new GoodsCategoryModel();
|
||||
$this->validate = new GoodsCategoryValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表树
|
||||
*/
|
||||
public function tree():\think\Response\Json
|
||||
{
|
||||
$inputData['type'] = 0;
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$this->order['sort'] = 'desc';
|
||||
//默认接口列表为全部输出
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['language_id'];
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
//前台勾选显示正常启用列表,用status字段来进行筛选
|
||||
if (isset($inputData['status'])) {
|
||||
switch ($inputData['status']) {
|
||||
case 0:
|
||||
unset($inputData['status']);
|
||||
break;
|
||||
default:
|
||||
$this->focus['status'] = 0;
|
||||
unset($inputData['status']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$list = $this->model->getIndexList($this->page,$this->size,$this->field,$this->simple,$this->focus,$this->order);
|
||||
//策划规定,尤达品牌只做2级分类,不允许添加3级或者4级
|
||||
// if ($inputData['type'] == 1) {
|
||||
$indexTree = list_to_tree($list);
|
||||
$addEditList = list_to_tree($list,3);//表示遇到第三级就跳出
|
||||
$tree = ['add'=>$addEditList,'index'=>$indexTree];
|
||||
// } else {
|
||||
// $tree = list_to_tree($list);
|
||||
// $tree = ['add'=>$tree,'index'=>$tree];
|
||||
// }
|
||||
return $this->msg(200, '获取列表成功', $tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function create():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
// //策划规定,尤达品牌只做2级分类,不允许添加3级或者4级
|
||||
// if ($inputData['platform_id'] == 1) {
|
||||
// $inputData['pid'] = [$inputData['pid']];
|
||||
// }
|
||||
//语言包
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['language_id'];
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
//处理PID结构
|
||||
// if (count($inputData['pid']) >= 1) {
|
||||
// $inputData['pid'] = array_pop($inputData['pid']);
|
||||
// } else {
|
||||
// return $this->msg(-1,'pid必填');
|
||||
// }
|
||||
if (isset($inputData['pid']) && $inputData['pid'] == '') {
|
||||
$inputData['pid'] = 0;
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function read():\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());
|
||||
}
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['language_id'];
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
$result = $this->model->getInfo($inputData);
|
||||
//获取当前分类的所有子类
|
||||
$sonCategory = $this->model->getChildCategory($inputData['id']);
|
||||
//获取所有分类数据
|
||||
$cates = $this->model->where(['status'=>0,'site_id'=>$result['site_id'],'platform_id'=>$this->platformId])->select()->toArray();
|
||||
//取出编辑时上级分类列表。
|
||||
$list = [];
|
||||
foreach ($cates as $cate) {
|
||||
if (!in_array($cate['id'],$sonCategory)) {
|
||||
$list[] = $cate;
|
||||
}
|
||||
}
|
||||
$addEditList = list_to_tree($list,3);//表示遇到第三级就跳出
|
||||
$result['list'] = $addEditList;
|
||||
//获取当前分类下是否有子分类。
|
||||
$hasChild = $this->model->where('pid',$inputData['id'])->find();
|
||||
$result['has_child'] = (bool) $hasChild;
|
||||
if ($result) {
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} else {
|
||||
return $this->msg(504,'获取列表失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
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['language_id'];
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
// //策划规定,尤达品牌只做2级分类,不允许添加3级或者4级
|
||||
// if ($inputData['platform_id'] == 1) {
|
||||
// $inputData['pid'] = [$inputData['pid']];
|
||||
// }
|
||||
// dd($inputData);
|
||||
//处理PID结构
|
||||
// $inputData['pid'] = $inputData['pid'][0];
|
||||
if (isset($inputData['pid']) && $inputData['pid'] == '') {
|
||||
$inputData['pid'] = 0;
|
||||
}
|
||||
|
||||
if ($inputData['pid'] == $inputData['id']) {
|
||||
return $this->msg(-1,'不能选择当前分类为自己的父分类');
|
||||
}
|
||||
//状态修改判断
|
||||
if (isset($inputData['status']) && $inputData['status'] != '' && $inputData['status'] == 1) {
|
||||
//判断当前修改的分类是否有子分类。如果有,将所有子分类全部禁用
|
||||
$sonCategory = $this->model->getChildCategory($inputData['id']);
|
||||
$newData = [];
|
||||
foreach ($sonCategory as $item) {
|
||||
$newData[] = [
|
||||
'id' => $item,
|
||||
'status'=> 1
|
||||
];
|
||||
}
|
||||
$this->model->changeStatus($newData,true);
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类商品
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function categoryGoodsList():\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['language_id'];
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
if ($inputData['goods_category_id'] == '') {
|
||||
return $this->msg(200, '获取列表成功', []);
|
||||
}
|
||||
|
||||
$list = $this->model->getGategoryListData($inputData);
|
||||
//商品编辑的时候。去除当前分类当前商品ID
|
||||
if (isset($inputData['goods_id']) && $inputData['goods_id'] > 0) {
|
||||
foreach ($list as $key => $item) {
|
||||
if ($item['id'] == $inputData['goods_id']) {
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($list)) {
|
||||
$newList = [];
|
||||
$newList['page'] = array_merge($list,[]);
|
||||
$newList['type'] = $inputData['type']??0;
|
||||
return $this->msg(200, '获取列表成功', $newList);
|
||||
} else {
|
||||
return $this->msg(504, '此分类下没有商品,请重新选择');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类商品
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function categoryGoodsInfo():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id','type']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['language_id'];
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
// dd($inputData);
|
||||
//
|
||||
if (isset($inputData['id'])) {
|
||||
$list = $this->model->getGategoryListDataInfo($inputData);
|
||||
dd($list);
|
||||
// if ($list) {
|
||||
$list['type'] = $inputData['type']??0;
|
||||
return $this->msg(200, '获取列表成功', $list);
|
||||
// } else {
|
||||
// return $this->msg(504, '获取列表失败');
|
||||
// }
|
||||
} else {
|
||||
// $list['type'] = $inputData['type'];
|
||||
$list = [
|
||||
['connect_good_id'=>'','goods_category_id'=>''],
|
||||
['connect_good_id'=>'','goods_category_id'=>''],
|
||||
['connect_good_id'=>'','goods_category_id'=>''],
|
||||
['connect_good_id'=>'','goods_category_id'=>''],
|
||||
];
|
||||
return $this->msg(200, '获取列表成功', $list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
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());
|
||||
}
|
||||
//查找是否有子类。
|
||||
$hasChild = $this->model->where('pid',$inputData['id'])->find();
|
||||
//查找是否有商品。
|
||||
$hasGoods = $this->model->hasGoodsOnCategory($inputData);
|
||||
if (empty($hasChild) && empty($hasGoods)) {
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,"有子分类或者分类下有商品,不能删除");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
21
app/api/controller/v1/GoodsConnect.php
Normal file
21
app/api/controller/v1/GoodsConnect.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\GoodsConnect as GoodsConnectModel;
|
||||
use app\api\validate\GoodsConnect as GoodsConnectValidate;
|
||||
|
||||
/**
|
||||
* 关联商品类
|
||||
* Class GoodsConnect
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class GoodsConnect extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new GoodsConnectModel();
|
||||
$this->validate = new GoodsConnectValidate();
|
||||
}
|
||||
|
||||
}
|
||||
66
app/api/controller/v1/GoodsCoupon.php
Normal file
66
app/api/controller/v1/GoodsCoupon.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\GoodsCoupon as GoodsCouponModel;
|
||||
use app\api\validate\GoodsCoupon as GoodsCouponValidate;
|
||||
|
||||
/**
|
||||
* 优惠券口令类
|
||||
* Class GoodsCoupon
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class GoodsCoupon extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
$this->model = new GoodsCouponModel();
|
||||
$this->validate = new GoodsCouponValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
// //语言包
|
||||
// if (isset($inputData['language_id']) && $inputData['language_id'] != '' && $inputData['language_id'] != 0) {
|
||||
// $this->focus['language_id'] = $inputData['language_id'];
|
||||
// } else {
|
||||
// return $this->msg(504,'语言包ID不正确,请检查!');
|
||||
// }
|
||||
|
||||
$data = [
|
||||
// 'language_id'=>$inputData['language_id'],
|
||||
'platform_id'=>$this->platformId
|
||||
];
|
||||
|
||||
$result = $this->model->getLatest($data);
|
||||
$result = ['old_code'=>$result['new_code']];
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
$inputData['new_code'] = htmlspecialchars_decode($inputData['new_code']);
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$inputData['new_code'] = htmlspecialchars($inputData['new_code']);
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
20
app/api/controller/v1/GoodsImages.php
Normal file
20
app/api/controller/v1/GoodsImages.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\GoodsImages as GoodsImagesModel;
|
||||
use app\api\validate\GoodsImages as GoodsImagesValidate;
|
||||
|
||||
/**
|
||||
* Class GoodsImages
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class GoodsImages extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new GoodsImagesModel();
|
||||
$this->validate = new GoodsImagesValidate();
|
||||
}
|
||||
|
||||
}
|
||||
20
app/api/controller/v1/GoodsSoftManual.php
Normal file
20
app/api/controller/v1/GoodsSoftManual.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\GoodsSoftManual as GoodsSoftManualModel;
|
||||
use app\api\validate\GoodsSoftManual as GoodsSoftManualValidate;
|
||||
|
||||
|
||||
/**
|
||||
* Class GoodsSoftManual
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class GoodsSoftManual extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new GoodsSoftManualModel();
|
||||
$this->validate = new GoodsSoftManualValidate();
|
||||
}
|
||||
}
|
||||
213
app/api/controller/v1/ImagesFile.php
Normal file
213
app/api/controller/v1/ImagesFile.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Attachment;
|
||||
use app\api\model\ImagesFile as ImagesFileModel;
|
||||
use app\api\model\SoftManualBtn;
|
||||
use storage\LocalUploader;
|
||||
use think\facade\Env;
|
||||
use utils\QiniuUploader;
|
||||
|
||||
|
||||
/**
|
||||
* 菜单设置
|
||||
*/
|
||||
class ImagesFile extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 上传大文件
|
||||
*/
|
||||
public function uploadFile()
|
||||
{
|
||||
header("Access-Control-Allow-Origin:*");
|
||||
header("Access-Control-Allow-Methods:GET, POST, PATCH, PUT, DELETE,OPTIONS");
|
||||
header("Access-Control-Allow-Credentials:true");
|
||||
header("Access-Control-Allow-Headers:Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With,x_requested_with,x-token");
|
||||
|
||||
try {
|
||||
$field = [
|
||||
'hash' => "",
|
||||
'md5' => "",
|
||||
'chunks' => "",
|
||||
'chunk' => 0,
|
||||
'is_test' => 1,
|
||||
'file_name' => '',
|
||||
];
|
||||
$newData = $this->request->post($field);
|
||||
$file = $this->request->file('file');
|
||||
if (empty($file)) {
|
||||
return $this->msg(504,'文件不能为空');
|
||||
}
|
||||
if (!$newData['hash']) {
|
||||
return $this->msg(504,'hash值不能为空');
|
||||
}
|
||||
//分片数据为第一片时 校验文件是否已经上传 如果上传直接返回地址
|
||||
if ($newData['chunk'] == 0) {
|
||||
$file_data = Attachment::where('hash', $newData['hash'])
|
||||
->find();
|
||||
if (!empty($file_data)) {
|
||||
$file_data['id'] = (int)$file_data['id'];
|
||||
if ($file_data['id'] > 0 ) {
|
||||
return $this->msg(200, $file_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
$uploader = new LocalUploader();
|
||||
$result = $uploader->uploadFile($newData, $file);
|
||||
//异常
|
||||
if ($result['code'] == -1) {
|
||||
return $this->msg(504,$uploader->getError());
|
||||
}
|
||||
if ($result['code'] == 1) {
|
||||
// $data = [
|
||||
// 'path' => $result['data']['save_path'],
|
||||
// 'url' => $result['data']['file_path'],
|
||||
// ];
|
||||
|
||||
//上传到七牛
|
||||
$res = $this->qn->uploadLocalFile(public_path().ltrim($result['data']['save_path'],'/'),$result['data']['file_path']);
|
||||
$ret = [
|
||||
'code' => 1,
|
||||
'data' => [
|
||||
'cdn' => Env::get('QINIU.cdn'),
|
||||
'origin_name' => $file->getOriginalName(),
|
||||
'filename' => explode('/',$res['filename'])[count(explode('/',$res['filename']))-1],
|
||||
'md5' => $newData['hash'],
|
||||
'url' => $res['remote_url'],
|
||||
'relative_path' => $res['filename']
|
||||
]
|
||||
];
|
||||
//构建数据
|
||||
$attach = [
|
||||
'platform_id' => $this->platformId,
|
||||
'site_id' => '',
|
||||
'name' => $file->getOriginalName(),
|
||||
'type' => $file->getMime(),
|
||||
'local' => $result['data']['save_path'],
|
||||
'path' => $res['filename'],
|
||||
'md5' => $newData['hash'],
|
||||
'hash' => $newData['hash']
|
||||
];
|
||||
Attachment::create($attach);
|
||||
return $this->msg(200, '上传成功', $ret);
|
||||
} else {
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'data' => $result['data'],
|
||||
];
|
||||
return $this->msg(200, '文件包不完整', $data);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->msg(504,$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分片上传文件检测
|
||||
*/
|
||||
public function checkFile()
|
||||
{
|
||||
header("Access-Control-Allow-Origin:*");
|
||||
header("Access-Control-Allow-Methods:GET, POST, PATCH, PUT, DELETE,OPTIONS");
|
||||
header("Access-Control-Allow-Credentials:true");
|
||||
header("Access-Control-Allow-Headers:Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With,x_requested_with,x-token");
|
||||
|
||||
$hash = $this->request->param('hash');
|
||||
$chunks = $this->request->param('chunks');
|
||||
if (!$hash) {
|
||||
return $this->msg(504,'hash值异常');
|
||||
}
|
||||
if ($chunks <= 0) {
|
||||
return $this->msg(504,'分片总数错误');
|
||||
}
|
||||
// $file_data = ImagesFileModel::where('file_hash', '=', $hash)
|
||||
// ->with('uploader')
|
||||
// ->find();
|
||||
//查询该上传的文件是否存在
|
||||
$file_data = Attachment::where('hash',$hash)->findOrEmpty();
|
||||
|
||||
if (!empty($file_data)) {
|
||||
$file_data['id'] = (int)$file_data['id'];
|
||||
if ($file_data['id'] > 0) {
|
||||
$arr = explode('/',$file_data['path']);
|
||||
$data = [
|
||||
'cdn' => Env::get('QINIU.cdn'),
|
||||
'origin_name' => $file_data['name'],
|
||||
'filename' => array_pop($arr),
|
||||
'md5' => $file_data['md5'],
|
||||
'url' => Env::get('QINIU.cdn').$file_data['path'],
|
||||
'relative_path' => $file_data['path']
|
||||
];
|
||||
return $this->msg(200,'成功', ['code' => 1, 'data' => $data]);
|
||||
}
|
||||
}
|
||||
//如果为需要上传的文件 则检测文件的分片情况
|
||||
$uploader = new LocalUploader();
|
||||
$result = $uploader->checkFile($hash, $chunks);
|
||||
return $this->msg(200,'成功', ['code' => 0, 'data' => $result]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*/
|
||||
public function uploadImg()
|
||||
{
|
||||
try {
|
||||
$uploader = new QiniuUploader();
|
||||
$file = $this->request->file('file');
|
||||
$result = $uploader->uploadFile('file');
|
||||
$data = [
|
||||
'up_id' => isset($this->user['id']) ? $this->user['id'] : 0,
|
||||
'path' => $result['filename'],
|
||||
'url' => $result['remote_url'],
|
||||
'file_hash' => $result['hash'],
|
||||
'file_md5' => $file->md5(),
|
||||
'created_at' => date("Y-m-d H:i:s"),
|
||||
'file_name' => $file->getOriginalName(),
|
||||
'file_type' => $file->getOriginalMime(),
|
||||
'storage_type' => 'qiniu',
|
||||
];
|
||||
$file_id = ImagesFileModel::insert($data, true);
|
||||
$data['id'] = (int)$file_id;
|
||||
return $this->msg(200,'成功', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->msg(504,$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function deleteFile()
|
||||
{
|
||||
$file_id = $this->request->get('file_id/d');
|
||||
if ($file_id <= 0) {
|
||||
return $this->msg(504,'请求参数异常');
|
||||
}
|
||||
$file_info = ImagesFileModel::where('id', '=', $file_id)->find();
|
||||
|
||||
switch ($file_info['storage_type']) {
|
||||
case 'qiniu':
|
||||
$uploader = new QiniuUploader();
|
||||
$uploader->deleteFile($file_info['path']);
|
||||
break;
|
||||
case 'local':
|
||||
$uploader = new LocalUploader();
|
||||
$uploader->deleteFile($file_info['path']);
|
||||
break;
|
||||
}
|
||||
ImagesFileModel::where('id', '=', $file_id)->delete();
|
||||
return $this->msg(504,'操作成功');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
153
app/api/controller/v1/Investment.php
Normal file
153
app/api/controller/v1/Investment.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Investment as InvestmentModel;
|
||||
use app\api\validate\Investment as InvestmentValidate;
|
||||
use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
/**
|
||||
* 招商引资信息留言控制器
|
||||
*/
|
||||
class Investment extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new InvestmentModel();
|
||||
$this->validate = new InvestmentValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*/
|
||||
public function index():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$this->focus['platform_id'] = $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 (isset($inputData['page']) && $inputData['page'] != 0) {
|
||||
$this->page = (int)$inputData['page'];
|
||||
}
|
||||
if (isset($inputData['size']) && $inputData['size'] != 0) {
|
||||
$this->size = (int)$inputData['size'];
|
||||
}
|
||||
|
||||
if (isset($inputData['create_time']) && $inputData['create_time'] != '') {
|
||||
$this->order['create_time'] = $inputData['create_time'];
|
||||
}
|
||||
|
||||
if (isset($inputData['keyword']) && $inputData['keyword'] != '') {
|
||||
$this->simple['keyword'] = $inputData['keyword'];
|
||||
}
|
||||
|
||||
$result = $this->model->getIndexList($this->page,$this->size,$this->field,$this->simple,$this->focus,$this->order);
|
||||
|
||||
if (isset($result['data']) && !empty($result['data'])) {
|
||||
foreach ($result['data'] as $key => $item) {
|
||||
$result['data'][$key]['province_id'] = $this->model->getAreaNameById($item['province_id']);
|
||||
$result['data'][$key]['city_id'] = $this->model->getAreaNameById($item['city_id']);
|
||||
}
|
||||
}
|
||||
//构建返回数据结构
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格导出数据前置方法
|
||||
*/
|
||||
public function export():\think\Response\Json
|
||||
{
|
||||
$ids = $this->request->param();
|
||||
if ($this->commonValidate(__FUNCTION__,$ids)) {
|
||||
return $this->msg(-1,'获取列表成功');
|
||||
}
|
||||
$data = $this->model->getExportData($ids);
|
||||
$fields = [
|
||||
'id','platform_id','language_id','site_id','country_id',
|
||||
'province_id','city_id','area','from','phone','name','email',
|
||||
'wechat','qq','desc','sort','is_open','create_time','update_time'
|
||||
];
|
||||
//处理数据
|
||||
// foreach ($data as &$datum) {
|
||||
// $datum['admin_id'] = $datum['admin_name'];
|
||||
// $datum['country_timezone_id'] = $datum['country_name'];
|
||||
// $datum['is_cooperation'] = $datum['is_cooperation'] == 0 ? "无" : "有";
|
||||
// $datum['follow_up_stage_id'] = !empty($datum['follow_up_stage_name']) ?$datum['follow_up_stage_name']: '无';
|
||||
// $datum['customer_from_id'] = !empty($datum['customer_from_name']) ?$datum['customer_from_name'] : '无';
|
||||
// $datum['customer_level_id'] = !empty($datum['customer_level_name']) ? $datum['customer_level_name']: '无';
|
||||
// foreach ($datum as $key => $value) {
|
||||
// if (!in_array($key,$fields)) {
|
||||
// unset($datum[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
|
||||
$this->importHeadType = 'name';
|
||||
$table = $this->model->getTable();
|
||||
$database = Env::get('database.database');
|
||||
//字段名与注释的数组,
|
||||
$fieldArr = [];
|
||||
$list = Db::query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
|
||||
foreach ($list as $v) {
|
||||
if (in_array($v['COLUMN_NAME'],$fields)) {
|
||||
if ($this->importHeadType == 'comment') {
|
||||
$fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
|
||||
} else {
|
||||
$fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_COMMENT'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$newData = [];/*表格数据*/
|
||||
$newHeader = [];/*表格表头*/
|
||||
$cols = []; /*分别占用表格哪几列*/
|
||||
if (array_key_exists(0,$data)) {
|
||||
$header = array_keys($data[0]);
|
||||
foreach ($header as $k => $v) {
|
||||
if ($k <= 25) {
|
||||
$newHeader[chr($k+65).'1'] = $fieldArr[$v]?:$v;
|
||||
$cols[$k] = chr($k+65);
|
||||
} else {
|
||||
$newHeader[chr(65).chr($k-26+65).'1'] = $fieldArr[$v]?:$v;
|
||||
$cols[$k] = chr(65).chr($k-26+65);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $k => $v) {
|
||||
$index = 0;
|
||||
foreach ($v as $v1) {
|
||||
if ($index <= 25) {
|
||||
$header = chr($index+65);
|
||||
$header .= $k+2;
|
||||
$newData[$header] = $v1;/*获取表头*/
|
||||
} else {
|
||||
$header = chr(65).chr($index-26+65);
|
||||
$header .= $k+2;
|
||||
$newData[$header] = $v1;/*获取表头*/
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
$newData = array_merge($newHeader,$newData);
|
||||
$options = [
|
||||
'print' =>false,
|
||||
'freezePane'=>'A2',
|
||||
// 'setWidth'=>['A'=>40,'B'=>30,'C'=>20,'D'=>25,'E'=>20,'F'=>15,'G'=>10,'H'=>10],
|
||||
'setBorder'=>true,
|
||||
'alignCenter'=>$cols,
|
||||
'bold'=>array_keys($newHeader),
|
||||
];
|
||||
return $this->excelExport($newData,count($fields),'招商信息导出-'.date('YmdHis',time()).'.xlsx',$options);
|
||||
}
|
||||
}
|
||||
135
app/api/controller/v1/Join.php
Normal file
135
app/api/controller/v1/Join.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Join as JoinModel;
|
||||
use app\api\validate\Join as JoinValidate;
|
||||
|
||||
/**
|
||||
* 文章新闻模块
|
||||
* Class Join
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Join extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new JoinValidate();
|
||||
$this->model = new JoinModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['join_type_id']) && $inputData['join_type_id'] != '' && $inputData['join_type_id'] != 0) {
|
||||
$this->focus['join_type_id'] = $inputData['join_type_id'];
|
||||
}
|
||||
|
||||
if (isset($inputData['title']) && $inputData['title'] != '') {
|
||||
$this->simple['title'] = $inputData['title'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
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 create():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time']) && !$inputData['create_time']) {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time'])) {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
131
app/api/controller/v1/JoinType.php
Normal file
131
app/api/controller/v1/JoinType.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\JoinType as JoinTypeModel;
|
||||
use app\api\validate\JoinType as JoinTypeValidate;
|
||||
|
||||
/**
|
||||
* 文章类型类
|
||||
* Class FileType
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class JoinType extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new JoinTypeValidate();
|
||||
$this->model = new JoinTypeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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['sort']) && $inputData['sort'] != '') {
|
||||
$this->orderby['sort'] = $inputData['sort'];
|
||||
} else {
|
||||
$this->orderby['sort'] = 'asc';
|
||||
}
|
||||
|
||||
$this->field = ['id','platform_id','site_id','icon','name','sort'];
|
||||
|
||||
$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();
|
||||
$updateData = $insertData = [];
|
||||
if (count($inputData['data']) > 0) {
|
||||
foreach ($inputData['data'] as &$item) {
|
||||
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['language_id'],
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'sort' => $item['sort'],
|
||||
'platform_id'=>$this->platformId
|
||||
];
|
||||
} else {
|
||||
if (!$this->commonValidate('create',$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$insertData[] = [
|
||||
'id' => null,
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'site_id' => $item['language_id'],
|
||||
'sort' => $item['sort'],
|
||||
'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->getArticleData($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,"该类型下有内容,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
128
app/api/controller/v1/Language.php
Normal file
128
app/api/controller/v1/Language.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Language as LanguageModel;
|
||||
use app\api\validate\Language as LanguageValidate;
|
||||
/**
|
||||
* 语言包类
|
||||
* Class Language
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Language extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new LanguageValidate();
|
||||
$this->model = new LanguageModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
if (isset($inputData['status']) && $inputData['status'] != '') {
|
||||
$this->focus['status'] = $inputData['status'];
|
||||
}
|
||||
$this->field = ['id','name','code','icon','status'];
|
||||
$result = $this->model->getIndexList($this->page,$this->size,$this->field,$this->simple,$this->focus,$this->order);
|
||||
return $result ? $this->msg(200,'获取列表成功',$result) : $this->msg(504,'获取列表失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$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 (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id','status']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//判断是否是否使用
|
||||
$hasUsed = $this->model->getLanguageUse($inputData['id']);
|
||||
if (!$hasUsed) {
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"操作成功");
|
||||
} else {
|
||||
return $this->msg(504,"操作失败");
|
||||
}
|
||||
} 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());
|
||||
}
|
||||
//判断是否是否使用
|
||||
$hasUsed = $this->model->getLanguageUse($inputData['id']);
|
||||
if (!$hasUsed) {
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,"此语言包已经被使用,不能删除");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
18
app/api/controller/v1/LogVisit.php
Normal file
18
app/api/controller/v1/LogVisit.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\LogVisit as LogVisitModel;
|
||||
|
||||
/**
|
||||
* 后台日志类
|
||||
* Class LogVisit
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class LogVisit extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new LogVisitModel();
|
||||
}
|
||||
}
|
||||
196
app/api/controller/v1/Navigator.php
Normal file
196
app/api/controller/v1/Navigator.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Navigator as NavigatorModel;
|
||||
use app\api\validate\Navigator as NavigatorValidate;
|
||||
|
||||
class Navigator extends Base
|
||||
{
|
||||
//管理员模型
|
||||
protected $model = null;
|
||||
//后台管理员控制器
|
||||
protected $validate = null;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new NavigatorValidate();
|
||||
$this->model = new NavigatorModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function read():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->getInfo($inputData);
|
||||
if ($result['pid'] != 0) {
|
||||
$pidName = $this->model->where('id',$result['pid'])->find()->toArray();
|
||||
$result['pid_name'] = $pidName['name'];
|
||||
} else {
|
||||
$result['pid_name'] = '';
|
||||
}
|
||||
$result['language_id'] = $result['site_id'];
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表树
|
||||
*/
|
||||
public function tree():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != '' && $inputData['language_id'] != 0) {
|
||||
$this->focus['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
$this->order['sort'] = 'desc';
|
||||
|
||||
$list = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
$tree = list_to_tree($list);
|
||||
return $this->msg(200, '获取列表成功', $tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 顶级列表树
|
||||
*/
|
||||
public function topTree():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != '' && $inputData['language_id'] != 0) {
|
||||
$this->focus['site_id'] = $inputData['language_id'];
|
||||
//$this->focus['pid'] = 0;
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
$list = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
//echo "<pre>=="; print_r($list);
|
||||
//去除自己的顶级
|
||||
if (isset($inputData['id']) && $inputData['id'] != '') {
|
||||
//查找当前分类是否有子类。
|
||||
$nav = $this->model->find($inputData['id']);
|
||||
$hasSon = $this->model->where('pid',$inputData['id'])->find();
|
||||
|
||||
if($hasSon) {
|
||||
$tree = [];
|
||||
}
|
||||
else{
|
||||
foreach ($list as $key => $item) {
|
||||
if ($inputData['id'] == $item['id']){
|
||||
unset($list[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$tree = list_to_tree($list);
|
||||
}
|
||||
|
||||
/*if ($nav) {
|
||||
if (!empty($son)) {
|
||||
$tree = [];
|
||||
} else {
|
||||
foreach ($list as $key => $item) {
|
||||
if ($inputData['id'] == $item['id']){
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
$tree = list_to_tree($list);
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
/*foreach ($list as $key => $item) {
|
||||
if ($inputData['id'] == $item['id']){
|
||||
unset($list[$key]);
|
||||
}
|
||||
}*/
|
||||
|
||||
$tree = list_to_tree($list);
|
||||
|
||||
}
|
||||
//echo "<pre>---"; print_r($tree);
|
||||
return $this->msg(200, '获取列表成功', $tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改是否是顶部状态
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
if (isset($inputData['is_foot']) && $inputData['is_foot'] == '') {
|
||||
unset($inputData['is_foot']);
|
||||
}
|
||||
|
||||
if (isset($inputData['is_top']) && $inputData['is_top'] == '') {
|
||||
unset($inputData['is_top']);
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//不能都提交为空
|
||||
if (count($inputData) < 3) {
|
||||
return $this->msg(504,"参数错误");
|
||||
}
|
||||
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
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->getNavigatorIsInUse($inputData);
|
||||
if (!$hasData) {
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,"该导航下有子分类,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
135
app/api/controller/v1/News.php
Normal file
135
app/api/controller/v1/News.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\News as NewsModel;
|
||||
use app\api\validate\News as NewsValidate;
|
||||
|
||||
/**
|
||||
* 文章新闻模块
|
||||
* Class News
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class News extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new NewsValidate();
|
||||
$this->model = new NewsModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['News_type_id']) && $inputData['News_type_id'] != '' && $inputData['News_type_id'] != 0) {
|
||||
$this->focus['News_type_id'] = $inputData['News_type_id'];
|
||||
}
|
||||
|
||||
if (isset($inputData['title']) && $inputData['title'] != '') {
|
||||
$this->simple['title'] = $inputData['title'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
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 create():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time']) && $inputData['create_time'] != '') {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time']) && $inputData['create_time'] != '') {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
131
app/api/controller/v1/NewsType.php
Normal file
131
app/api/controller/v1/NewsType.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\NewsType as NewsTypeModel;
|
||||
use app\api\validate\NewsType as NewsTypeValidate;
|
||||
|
||||
/**
|
||||
* 文章类型类
|
||||
* Class FileType
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class NewsType extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new NewsTypeValidate();
|
||||
$this->model = new NewsTypeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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['sort']) && $inputData['sort'] != '') {
|
||||
$this->orderby['sort'] = $inputData['sort'];
|
||||
} else {
|
||||
$this->orderby['sort'] = 'asc';
|
||||
}
|
||||
|
||||
$this->field = ['id','platform_id','site_id','icon','name','sort'];
|
||||
|
||||
$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();
|
||||
$updateData = $insertData = [];
|
||||
if (count($inputData['data']) > 0) {
|
||||
foreach ($inputData['data'] as &$item) {
|
||||
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['language_id'],
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'sort' => $item['sort'],
|
||||
'platform_id'=>$this->platformId
|
||||
];
|
||||
} else {
|
||||
if (!$this->commonValidate('create',$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$insertData[] = [
|
||||
'id' => null,
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'site_id' => $item['language_id'],
|
||||
'sort' => $item['sort'],
|
||||
'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->getArticleData($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,"该类型下有内容,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
133
app/api/controller/v1/Platform.php
Normal file
133
app/api/controller/v1/Platform.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Platform as PlatformModel;
|
||||
use app\api\validate\Platform as PlatformValidate;
|
||||
|
||||
/**
|
||||
* 平台类
|
||||
* Class Platform
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Platform extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new PlatformValidate();
|
||||
$this->model = new PlatformModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 languageList():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$this->field = ['id','name','code','icon','status'];
|
||||
$result = $this->model->getLanguageList($this->field,['status'=>0]);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$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();
|
||||
// 已经注册的平台,如果被使用,则不允许修改品牌名
|
||||
//TODO::暂时限制不能更改品牌名称
|
||||
$isExist = $this->model->hasUserPlatform($inputData);
|
||||
if (count($isExist) >= 1) {
|
||||
unset($inputData['name']);
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function read():\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->getInfo($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} else {
|
||||
return $this->msg(504,'获取列表失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//删除前检测
|
||||
$isExist = $this->model->hasUserPlatform($inputData);
|
||||
if (count($isExist) >= 1) {
|
||||
return $this->msg(504,"平台被使用,不能删除");
|
||||
}
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
549
app/api/controller/v1/Question.php
Normal file
549
app/api/controller/v1/Question.php
Normal file
@@ -0,0 +1,549 @@
|
||||
<?php
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Question as QuestionModel;
|
||||
use app\api\validate\Question as QuestionValidate;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\DNSCheckValidation;
|
||||
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Csv;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
||||
use think\db\exception\PDOException;
|
||||
use think\facade\Env;
|
||||
|
||||
/**
|
||||
* 用户反馈类
|
||||
* Class Question
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Question extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new QuestionValidate();
|
||||
$this->model = new QuestionModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$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 (isset($inputData['is_done']) && $inputData['is_done'] != '') {
|
||||
$this->focus['is_done'] = $inputData['is_done'];
|
||||
}
|
||||
|
||||
if (isset($inputData['product_model']) && $inputData['product_model'] != '') {
|
||||
$this->simple['product_model'] = $inputData['product_model'];
|
||||
}
|
||||
|
||||
if (isset($inputData['create_time']) && $inputData['create_time'] != '') {
|
||||
$this->orderby['create_time'] = $inputData['create_time'];
|
||||
}
|
||||
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
if (!empty($this->focus)) {
|
||||
if (!$this->commonValidate(__FUNCTION__,$this->focus)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->simple)) {
|
||||
if (!$this->commonValidate(__FUNCTION__,$this->simple)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->orderby)) {
|
||||
if (!$this->commonValidate(__FUNCTION__,$this->orderby)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
}
|
||||
//字段过滤
|
||||
$this->field = ['id','platform_id','language_id','site_id','country_id','name','phone','email','order_sn','product_model','os','sort','is_done','create_time'];
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->orderby,$this->field);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 已解决
|
||||
*/
|
||||
public function isDone()
|
||||
{
|
||||
$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());
|
||||
}
|
||||
$result = $this->model->isDone($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel导出,
|
||||
* @param array $data
|
||||
* @param string $fileName
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function export($data = [], $fileName = '', $options = [])
|
||||
{
|
||||
try {
|
||||
if (empty($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
set_time_limit(0);
|
||||
$objSpreadsheet = new Spreadsheet();
|
||||
/* 设置默认文字居左,上下居中 */
|
||||
$styleArray = [
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_LEFT,
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
],
|
||||
];
|
||||
$objSpreadsheet->getDefaultStyle()->applyFromArray($styleArray);
|
||||
/* 设置Excel Sheet */
|
||||
$activeSheet = $objSpreadsheet->setActiveSheetIndex(0);
|
||||
|
||||
/* 打印设置 */
|
||||
if (isset($options['print']) && $options['print']) {
|
||||
/* 设置打印为A4效果 */
|
||||
$activeSheet->getPageSetup()->setPaperSize(PageSetup:: PAPERSIZE_A4);
|
||||
/* 设置打印时边距 */
|
||||
$pValue = 1 / 2.54;
|
||||
$activeSheet->getPageMargins()->setTop($pValue / 2);
|
||||
$activeSheet->getPageMargins()->setBottom($pValue * 2);
|
||||
$activeSheet->getPageMargins()->setLeft($pValue / 2);
|
||||
$activeSheet->getPageMargins()->setRight($pValue / 2);
|
||||
}
|
||||
|
||||
$row = 2;
|
||||
$col = 0;
|
||||
/* 行数据处理 */
|
||||
foreach ($data as $sKey => $sItem) {
|
||||
/* 默认文本格式 */
|
||||
$pDataType = DataType::TYPE_STRING;
|
||||
|
||||
/* 设置单元格格式 */
|
||||
if (isset($options['format']) && !empty($options['format'])) {
|
||||
$colRow = Coordinate::coordinateFromString($sKey);
|
||||
|
||||
/* 存在该列格式并且有特殊格式 */
|
||||
if (isset($options['format'][$colRow[0]]) &&
|
||||
NumberFormat::FORMAT_GENERAL != $options['format'][$colRow[0]]) {
|
||||
$activeSheet->getStyle($sKey)->getNumberFormat()
|
||||
->setFormatCode($options['format'][$colRow[0]]);
|
||||
|
||||
if (false !== strpos($options['format'][$colRow[0]], '0.00') &&
|
||||
is_numeric(str_replace(['¥', ','], '', $sItem))) {
|
||||
/* 数字格式转换为数字单元格 */
|
||||
$pDataType = DataType::TYPE_NUMERIC;
|
||||
$sItem = str_replace(['¥', ','], '', $sItem);
|
||||
}
|
||||
} elseif (is_int($sItem)) {
|
||||
$pDataType = DataType::TYPE_NUMERIC;
|
||||
}
|
||||
}
|
||||
|
||||
if ($col < count($options['alignCenter'])) {
|
||||
$activeSheet->getColumnDimension($options['alignCenter'][$col])->setAutoSize(true);
|
||||
}
|
||||
$activeSheet->getRowDimension($row)->setRowHeight(65);
|
||||
$activeSheet->setCellValueExplicit($sKey, $sItem, $pDataType);
|
||||
$row++;
|
||||
$col++;
|
||||
/* 存在:形式的合并行列,列入A1:B2,则对应合并 */
|
||||
if (false !== strstr($sKey, ":")) {
|
||||
$options['mergeCells'][$sKey] = $sKey;
|
||||
}
|
||||
|
||||
if (is_image(Env::get('root_path').'public'.$sItem) && file_exists(Env::get('root_path').'public'.$sItem)) {
|
||||
$activeSheet->setCellValueExplicit($sKey, '', $pDataType);
|
||||
$drawing = new Drawing();
|
||||
$drawing->setName('Logo');
|
||||
$drawing->setDescription('Logo');
|
||||
$drawing->setPath(Env::get('root_path').'public'.$sItem);
|
||||
$drawing->setResizeProportional(false);
|
||||
$drawing->setHeight(50);
|
||||
$drawing->setCoordinates($sKey);
|
||||
$drawing->setOffsetX(12);
|
||||
$drawing->setOffsetY(12);
|
||||
$drawing->getShadow()->setVisible(true);
|
||||
// $drawing->getShadow()->setDirection(45);
|
||||
$drawing->setWorksheet($objSpreadsheet->getActiveSheet());
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
|
||||
/* 设置锁定行 */
|
||||
if (isset($options['freezePane']) && !empty($options['freezePane'])) {
|
||||
$activeSheet->freezePane($options['freezePane']);
|
||||
unset($options['freezePane']);
|
||||
}
|
||||
|
||||
/* 设置宽度 */
|
||||
if (isset($options['setWidth']) && !empty($options['setWidth'])) {
|
||||
foreach ($options['setWidth'] as $swKey => $swItem) {
|
||||
$activeSheet->getColumnDimension($swKey)->setWidth($swItem);
|
||||
}
|
||||
|
||||
unset($options['setWidth']);
|
||||
}
|
||||
|
||||
/* 设置背景色 */
|
||||
if (isset($options['setARGB']) && !empty($options['setARGB'])) {
|
||||
foreach ($options['setARGB'] as $sItem) {
|
||||
$activeSheet->getStyle($sItem)
|
||||
->getFill()->setFillType(Fill::FILL_SOLID)
|
||||
->getStartColor()->setARGB(Color::COLOR_YELLOW);
|
||||
}
|
||||
|
||||
unset($options['setARGB']);
|
||||
}
|
||||
|
||||
/* 设置公式 */
|
||||
if (isset($options['formula']) && !empty($options['formula'])) {
|
||||
foreach ($options['formula'] as $fKey => $fItem) {
|
||||
$activeSheet->setCellValue($fKey, $fItem);
|
||||
}
|
||||
|
||||
unset($options['formula']);
|
||||
}
|
||||
|
||||
/* 合并行列处理 */
|
||||
if (isset($options['mergeCells']) && !empty($options['mergeCells'])) {
|
||||
$activeSheet->setMergeCells($options['mergeCells']);
|
||||
unset($options['mergeCells']);
|
||||
}
|
||||
|
||||
/* 设置居中 */
|
||||
if (isset($options['alignCenter']) && !empty($options['alignCenter'])) {
|
||||
$styleArray = [
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($options['alignCenter'] as $acItem) {
|
||||
$activeSheet->getStyle($acItem)->applyFromArray($styleArray);
|
||||
}
|
||||
|
||||
unset($options['alignCenter']);
|
||||
}
|
||||
|
||||
/* 设置加粗 */
|
||||
if (isset($options['bold']) && !empty($options['bold'])) {
|
||||
foreach ($options['bold'] as $bItem) {
|
||||
$activeSheet->getStyle($bItem)->getFont()->setBold(true);
|
||||
}
|
||||
|
||||
unset($options['bold']);
|
||||
}
|
||||
|
||||
/* 设置单元格边框,整个表格设置即可,必须在数据填充后才可以获取到最大行列 */
|
||||
if (isset($options['setBorder']) && $options['setBorder']) {
|
||||
$border = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN, // 设置border样式
|
||||
'color' => ['argb' => 'FF000000'], // 设置border颜色
|
||||
],
|
||||
],
|
||||
];
|
||||
$setBorder = 'A1:' . $activeSheet->getHighestColumn() . $activeSheet->getHighestRow();
|
||||
$activeSheet->getStyle($setBorder)->applyFromArray($border);
|
||||
unset($options['setBorder']);
|
||||
}
|
||||
|
||||
$fileName = !empty($fileName) ? $fileName : (date('YmdHis') . '.xlsx');
|
||||
|
||||
if (!isset($options['savePath'])) {
|
||||
/* 直接导出Excel,无需保存到本地,输出07Excel文件 */
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
header(
|
||||
"Content-Disposition:attachment;filename=" . iconv(
|
||||
"utf-8", "GB2312//TRANSLIT", $fileName
|
||||
)
|
||||
);
|
||||
header('Cache-Control: max-age=0');//禁止缓存
|
||||
$savePath = 'php://output';
|
||||
} else {
|
||||
$savePath = $options['savePath'];
|
||||
}
|
||||
|
||||
ob_clean();
|
||||
ob_start();
|
||||
$objWriter = IOFactory::createWriter($objSpreadsheet, 'Xlsx');
|
||||
$objWriter->save($savePath);
|
||||
/* 释放内存 */
|
||||
$objSpreadsheet->disconnectWorksheets();
|
||||
unset($objSpreadsheet);
|
||||
ob_end_flush();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
$file = $this->request->request('file');
|
||||
if (!$file) {
|
||||
return $this->msg(504,'Parameter %s can not be empty');
|
||||
}
|
||||
$filePath = Env::get('root_path') . '/public/' . $file;
|
||||
if (!is_file($filePath)) {
|
||||
return $this->msg(504,'No results were found');
|
||||
}
|
||||
//实例化reader
|
||||
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
|
||||
if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
|
||||
return $this->msg(504,'Unknown data format');
|
||||
}
|
||||
if ($ext === 'csv') {
|
||||
$file = fopen($filePath, 'r');
|
||||
$filePath = tempnam(sys_get_temp_dir(), 'import_csv');
|
||||
$fp = fopen($filePath, "w");
|
||||
$n = 0;
|
||||
while ($line = fgets($file)) {
|
||||
$line = rtrim($line, "\n\r\0");
|
||||
$encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
|
||||
if ($encoding != 'utf-8') {
|
||||
$line = mb_convert_encoding($line, 'utf-8', $encoding);
|
||||
}
|
||||
if ($n == 0 || preg_match('/^".*"$/', $line)) {
|
||||
fwrite($fp, $line . "\n");
|
||||
} else {
|
||||
fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
|
||||
}
|
||||
$n++;
|
||||
}
|
||||
fclose($file) || fclose($fp);
|
||||
|
||||
$reader = new Csv();
|
||||
} elseif ($ext === 'xls') {
|
||||
$reader = new Xls();
|
||||
} else {
|
||||
$reader = new Xlsx();
|
||||
}
|
||||
|
||||
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
|
||||
$importHeadType = isset($this->importHeadType) ? $this->importHeadType : 'comment';
|
||||
|
||||
$table = $this->model->getQuery()->getTable();
|
||||
$database = Config::get('database.database');
|
||||
$fieldArr = [];
|
||||
$list = db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
|
||||
foreach ($list as $k => $v) {
|
||||
if ($importHeadType == 'comment') {
|
||||
$fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
|
||||
} else {
|
||||
$fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_NAME'];
|
||||
}
|
||||
}
|
||||
|
||||
//加载文件
|
||||
$insert = [];
|
||||
try {
|
||||
if (!$PHPExcel = $reader->load($filePath)) {
|
||||
return $this->msg(504,'Unknown data format');
|
||||
}
|
||||
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
|
||||
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
|
||||
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
|
||||
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
|
||||
$fields = [];
|
||||
for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
|
||||
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
|
||||
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
|
||||
$fields[] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
|
||||
$values = [];
|
||||
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
|
||||
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
|
||||
$values[] = is_null($val) ? '' : $val;
|
||||
}
|
||||
$row = [];
|
||||
$temp = array_combine($fields, $values);
|
||||
foreach ($temp as $k => $v) {
|
||||
if (isset($fieldArr[$k]) && $k !== '') {
|
||||
$row[$fieldArr[$k]] = $v;
|
||||
}
|
||||
}
|
||||
if ($row) {
|
||||
$insert[] = $row;
|
||||
}
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
return $this->msg(504,$exception->getMessage());
|
||||
}
|
||||
if (!$insert) {
|
||||
return $this->msg(504,'No rows were updated');
|
||||
}
|
||||
|
||||
try {
|
||||
//是否包含admin_id字段
|
||||
$has_admin_id = false;
|
||||
foreach ($fieldArr as $name => $key) {
|
||||
if ($key == 'admin_id') {
|
||||
$has_admin_id = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($has_admin_id) {
|
||||
$auth = Auth::instance();
|
||||
foreach ($insert as &$val) {
|
||||
if (!isset($val['admin_id']) || empty($val['admin_id'])) {
|
||||
$val['admin_id'] = $auth->isLogin() ? $auth->id : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->model->saveAll($insert);
|
||||
} catch (PDOException $exception) {
|
||||
$msg = $exception->getMessage();
|
||||
if (preg_match("/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is", $msg, $matches)) {
|
||||
$msg = "导入失败,包含【{$matches[1]}】的记录已存在";
|
||||
};
|
||||
return $this->msg(504,$msg);
|
||||
} catch (\Exception $e) {
|
||||
return $this->msg(504,$e->getMessage());
|
||||
}
|
||||
|
||||
return $this->msg(200,'导入成功!!');
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 发送邮件
|
||||
// */
|
||||
// public function sendEmail()
|
||||
// {
|
||||
// $translate = [
|
||||
// 'language_id' => '所属站点',
|
||||
// 'country_id' => '国家/地区',
|
||||
// 'name' => '客户名称',
|
||||
// 'email' => '客户邮箱',
|
||||
// 'order_sn' => '订单号',
|
||||
// 'product_model' => '产品型号',
|
||||
// 'os' => '操作系统',
|
||||
// 'desc' => '问题详情',
|
||||
// 'question_attachment' => '反馈附件',
|
||||
// 'create_time' => '反馈时间'
|
||||
// ];
|
||||
//
|
||||
// $data = $this->request->param();
|
||||
// $data['create_time'] = date('Y-m-d H:i:s',time());
|
||||
// $mail = new PHPMailer();
|
||||
// $mail->CharSet = "UTF8";
|
||||
// $mail->SMTPDebug = 0; //Enable verbose debug output
|
||||
// $mail->isSMTP(); //Send using SMTP
|
||||
// $mail->Host = Env::get('EMAIL.MAIL_HOST'); //Set the SMTP server to send through
|
||||
// $mail->SMTPAuth = true; //Enable SMTP authentication
|
||||
// $mail->Username = Env::get('EMAIL.MAIL_USERNAME'); //SMTP username
|
||||
// $mail->Password = Env::get('EMAIL.MAIL_PASSWORD'); //SMTP password
|
||||
// $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
|
||||
// $mail->Port = Env::get('EMAIL.MAIL_PORT'); //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
|
||||
//
|
||||
// //Recipients
|
||||
// $mail->setFrom(Env::get('EMAIL.MAIL_FROM_ADDRESS'), Env::get('EMAIL.MAIL_FROM_ADDRESS'));
|
||||
// $mail->addAddress('yulinzhihou@163.com', 'yulinzhihou'); //Add a recipient
|
||||
//
|
||||
// //Content
|
||||
// $mail->isHTML(true); //Set email format to HTML
|
||||
// $mail->Subject = '尤达官网用户问题反馈'.$data['name'].date('Y-m-d H:i:s');
|
||||
// $body = '';
|
||||
// $body .= <<<EOF
|
||||
//<style>
|
||||
// table,tr,td,th {
|
||||
// border: 1px solid #ccc;
|
||||
// border-collapse: collapse;
|
||||
// text-align: justify;
|
||||
// }
|
||||
// .item1 {
|
||||
// width: 20%;
|
||||
// }
|
||||
//</style>
|
||||
//<table>
|
||||
//EOF;
|
||||
// foreach ($data as $key => $value) {
|
||||
// if (is_array($value)) {
|
||||
// foreach ($value as $item) {
|
||||
// $body .= '<tr><td class="item1">'.$translate[$key].'</td>'.'<td><a href='.$item['attach'].'>点击查看附件</a></td></tr>';
|
||||
// }
|
||||
// } else {
|
||||
// $body .= '<tr><td class="item1">'.$translate[$key].'</td>'.'<td>'.$value.'</td></tr>';
|
||||
// }
|
||||
// }
|
||||
// $body .= '</table>';
|
||||
// $mail->Body = $body;
|
||||
// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||
// $result = $mail->send();
|
||||
// dd($result);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public function validateEmail()
|
||||
// {
|
||||
// $inputData = $this->request->param();
|
||||
// $validator = new EmailValidator();
|
||||
// $multipleValidations = new MultipleValidationWithAnd([
|
||||
// new RFCValidation(),
|
||||
// new DNSCheckValidation()
|
||||
// ]);
|
||||
// //ietf.org has MX records signaling a server with email capabilites
|
||||
// $result = $validator->isValid($inputData['email'], $multipleValidations); //true
|
||||
// if ($result) {
|
||||
// return $this->msg(200,'邮箱有效');
|
||||
// } else {
|
||||
// return $this->msg(504,'邮箱无效');
|
||||
// }
|
||||
// }
|
||||
}
|
||||
135
app/api/controller/v1/Resource.php
Normal file
135
app/api/controller/v1/Resource.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Resource as ResourceModel;
|
||||
use app\api\validate\Resource as ResourceValidate;
|
||||
|
||||
/**
|
||||
* 文章新闻模块
|
||||
* Class Resource
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Resource extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new ResourceValidate();
|
||||
$this->model = new ResourceModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['resource_type_id']) && $inputData['resource_type_id'] != '' && $inputData['resource_type_id'] != 0) {
|
||||
$this->focus['resource_type_id'] = $inputData['resource_type_id'];
|
||||
}
|
||||
|
||||
if (isset($inputData['title']) && $inputData['title'] != '') {
|
||||
$this->simple['title'] = $inputData['title'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
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 create():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time']) && !$inputData['create_time']) {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time'])) {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
131
app/api/controller/v1/ResourceType.php
Normal file
131
app/api/controller/v1/ResourceType.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\ResourceType as ResourceTypeModel;
|
||||
use app\api\validate\ResourceType as ResourceTypeValidate;
|
||||
|
||||
/**
|
||||
* 文章类型类
|
||||
* Class FileType
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class ResourceType extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new ResourceTypeValidate();
|
||||
$this->model = new ResourceTypeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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['sort']) && $inputData['sort'] != '') {
|
||||
$this->orderby['sort'] = $inputData['sort'];
|
||||
} else {
|
||||
$this->orderby['sort'] = 'asc';
|
||||
}
|
||||
|
||||
$this->field = ['id','platform_id','site_id','icon','name','sort'];
|
||||
|
||||
$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();
|
||||
$updateData = $insertData = [];
|
||||
if (count($inputData['data']) > 0) {
|
||||
foreach ($inputData['data'] as &$item) {
|
||||
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['language_id'],
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'sort' => $item['sort'],
|
||||
'platform_id'=>$this->platformId
|
||||
];
|
||||
} else {
|
||||
if (!$this->commonValidate('create',$item)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$insertData[] = [
|
||||
'id' => null,
|
||||
'name' => $item['name'],
|
||||
'icon' => $item['icon']??'',
|
||||
'site_id' => $item['language_id'],
|
||||
'sort' => $item['sort'],
|
||||
'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->getArticleData($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,"该类型下有内容,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
21
app/api/controller/v1/Role.php
Normal file
21
app/api/controller/v1/Role.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
declare(strict_types =1 );
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Role as RoleModel;
|
||||
use app\api\validate\Role as RoleValidate;
|
||||
|
||||
/**
|
||||
* 角色类控制器
|
||||
* Class Role
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Role extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new RoleModel();
|
||||
$this->validate = new RoleValidate();
|
||||
}
|
||||
}
|
||||
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,"删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
236
app/api/controller/v1/SoftManual.php
Normal file
236
app/api/controller/v1/SoftManual.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\SoftManual as SoftManualModel;
|
||||
use app\api\validate\SoftManual as SoftManualValidate;
|
||||
use think\facade\Env;
|
||||
|
||||
/**
|
||||
* 驱动-文档手册类
|
||||
* Class Download
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SoftManual extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new SoftManualValidate();
|
||||
$this->model = new SoftManualModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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 (isset($inputData['file_type_id']) && $inputData['file_type_id'] != '' && $inputData['file_type_id'] != 0) {
|
||||
$this->focus['file_type_id'] = $inputData['file_type_id'];
|
||||
}
|
||||
|
||||
if (isset($inputData['name']) && $inputData['name'] != '') {
|
||||
$this->simple['name'] = $inputData['name'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
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 create():\think\Response\Json
|
||||
{
|
||||
$introduce = $this->request->param('introduce','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['introduce'] = $introduce;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
unset($inputData['create_time']);
|
||||
unset($inputData['update_time']);
|
||||
|
||||
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 (isset($inputData['softBtn']) && empty($inputData['softBtn'])) {
|
||||
$this->msg(504,'还没有填写按钮信息,请检查!');
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$introduce = $this->request->param('introduce','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['introduce'] = $introduce;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
unset($inputData['create_time']);
|
||||
unset($inputData['update_time']);
|
||||
|
||||
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 (empty($inputData['softBtn'])) {
|
||||
return $this->msg(504,'还没有填写按钮信息,请检查!');
|
||||
}
|
||||
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改排序
|
||||
*/
|
||||
public function changeSort():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeSort($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 图片,ICON上传
|
||||
*/
|
||||
public function upload():\think\Response\Json
|
||||
{
|
||||
$files = $this->request->file();
|
||||
if (!$files) {
|
||||
return $this->msg(-1, "请选择上传的文件");
|
||||
}
|
||||
$field = array_keys($files)[0];
|
||||
$data = [];
|
||||
//兼容多图上传
|
||||
if (is_array($files) && count($files) > 1 ) {
|
||||
//不同字段文件名上传 image img ico
|
||||
//上传到七牛
|
||||
foreach ($files as $key => $fileSimple) {
|
||||
// if (!$this->commonValidate(__FUNCTION__, [$key => $fileSimple])) {
|
||||
// return $this->msg(200, $this->validate->getError());
|
||||
// }
|
||||
$result[$key] = $this->qn->uploadFile($key);
|
||||
}
|
||||
|
||||
foreach ($result as $key => $item) {
|
||||
$data[] = [
|
||||
'cdn' => Env::get('QINIU.cdn'),
|
||||
'origin_name' => $files[$key]->getOriginalName(),
|
||||
'filename' => explode('/', $item['filename'])[count(explode('/', $item['filename'])) - 1],
|
||||
'md5' => md5_file($files[$key]->getPathname()),
|
||||
'url' => $item['remote_url'],
|
||||
'relative_path' => $item['filename']
|
||||
];
|
||||
}
|
||||
} elseif (is_array($files[$field]) && count($files[$field]) > 1) {
|
||||
//同一名称的数组文件上传.image[0] image[1]
|
||||
// foreach ($files as $key => $fileSimple) {
|
||||
// if (!$this->commonValidate(__FUNCTION__, [$key => $fileSimple])) {
|
||||
// return $this->msg(200, $this->validate->getError());
|
||||
// }
|
||||
// }
|
||||
//上传到七牛
|
||||
$result = $this->qn->uploadFile($field, true, count($files[$field]));
|
||||
|
||||
foreach ($result as $key => $item) {
|
||||
$data[] = [
|
||||
'cdn' => Env::get('QINIU.cdn'),
|
||||
'origin_name' => $files[$field][$key]->getOriginalName(),
|
||||
'filename' => explode('/', $item['filename'])[count(explode('/', $item['filename'])) - 1],
|
||||
'md5' => md5_file($files[$field][$key]->getPathname()),
|
||||
'url' => $item['remote_url'],
|
||||
'relative_path' => $item['filename']
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// if (!$this->commonValidate(__FUNCTION__,[$field=>$files])) {
|
||||
// return $this->msg(200,$this->validate->getError());
|
||||
// }
|
||||
//上传到七牛
|
||||
$result = $this->qn->uploadFile($field);
|
||||
$data = [
|
||||
'cdn' => Env::get('QINIU.cdn'),
|
||||
'origin_name' => $files[$field]->getOriginalName(),
|
||||
'filename' => explode('/',$result['filename'])[count(explode('/',$result['filename']))-1],
|
||||
'md5' => md5_file($files[$field]->getPathname()),
|
||||
'url' => $result['remote_url'],
|
||||
'relative_path' => $result['filename']
|
||||
];
|
||||
}
|
||||
|
||||
return $this->msg(200, '上传成功', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
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());
|
||||
}
|
||||
//查询是否有被使用
|
||||
$hasUsed = $this->model->getSoftManualUsed($inputData);
|
||||
if ($hasUsed) {
|
||||
return $this->msg(504,'已被使用,不能删除!');
|
||||
}
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
145
app/api/controller/v1/SystemConfig.php
Normal file
145
app/api/controller/v1/SystemConfig.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\SystemConfig as SystemConfigModel;
|
||||
use app\api\validate\SystemConfig as SystemConfigValidate;
|
||||
/**
|
||||
* 系统配置
|
||||
*/
|
||||
class SystemConfig extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new SystemConfigModel();
|
||||
$this->validate = new SystemConfigValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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());
|
||||
}
|
||||
$result = $this->model->getIndexList($this->page,$this->size,$this->field, $this->simple, $this->focus,$this->order);
|
||||
if (isset($result['data']) && !empty($result['data'])) {
|
||||
foreach ($result['data'] as $key => $item) {
|
||||
if (!empty($item['image'])) {
|
||||
$result['data'][$key]['image'] = json_decode($item['image'],true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function read():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
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());
|
||||
}
|
||||
$result = $this->model->getInfo($inputData);
|
||||
if ($result['type'] == 2 || $result['type'] == 4) {
|
||||
// 处理图片
|
||||
if (isset($result['image']) && !empty($result['image'])) {
|
||||
$result['image'] = json_decode($result['image'],true);
|
||||
} else {
|
||||
$result['image'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$result['language_id'] = $result['site_id'];
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} else {
|
||||
return $this->msg(200,'获取列表成功',[]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
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 (isset($inputData['site_id']) || !empty($inputData['site_id']) || $inputData['site_id'] != 0) {
|
||||
$this->focus['site_id'] = $inputData['site_id'];
|
||||
} else {
|
||||
return $this->msg(504,'语言包/所属站点参数,不正确,请检查!');
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
// 处理图片
|
||||
if (isset($inputData['image']) && !empty($inputData['image'])) {
|
||||
$inputData['image'] = json_encode($inputData['image']);
|
||||
}
|
||||
|
||||
$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();
|
||||
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());
|
||||
}
|
||||
|
||||
// 处理图片
|
||||
if (isset($inputData['image']) && !empty($inputData['image'])) {
|
||||
$inputData['image'] = json_encode($inputData['image']);
|
||||
}
|
||||
|
||||
$result = $this->model->editData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
66
app/api/controller/v1/Video.php
Normal file
66
app/api/controller/v1/Video.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Video as VideoModel;
|
||||
use app\api\validate\Video as VideoValidate;
|
||||
|
||||
/**
|
||||
* 产品视频管理
|
||||
*/
|
||||
class Video extends Base
|
||||
{
|
||||
//管理员模型
|
||||
protected $model = null;
|
||||
//后台管理员控制器
|
||||
protected $validate = null;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new VideoValidate();
|
||||
$this->model = new VideoModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
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());
|
||||
}
|
||||
$this->simple['name'] = $inputData['name'] ?? '';
|
||||
$result = $this->model->getIndexList($this->page,$this->size,$this->field, $this->simple, $this->focus,$this->order);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\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']);
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"操作成功");
|
||||
} else {
|
||||
return $this->msg(504,"操作失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user