init: 项目初始代码
This commit is contained in:
22
app/AppService.php
Normal file
22
app/AppService.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\Service;
|
||||
|
||||
/**
|
||||
* 应用服务类
|
||||
*/
|
||||
class AppService extends Service
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
// 服务注册
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// 服务启动
|
||||
}
|
||||
}
|
||||
94
app/BaseController.php
Normal file
94
app/BaseController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class BaseController
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
[$validate, $scene] = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
|
||||
return $v->failException(true)->check($data);
|
||||
}
|
||||
|
||||
}
|
||||
58
app/ExceptionHandle.php
Normal file
58
app/ExceptionHandle.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace app;
|
||||
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 应用异常处理类
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
9
app/Request.php
Normal file
9
app/Request.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace app;
|
||||
|
||||
// 应用请求对象类
|
||||
class Request extends \think\Request
|
||||
{
|
||||
// protected $filter = ['trim', 'strip_tags', 'htmlspecialchars'];
|
||||
protected $filter = ['trim', 'strip_tags'];
|
||||
}
|
||||
1
app/api/.htaccess
Normal file
1
app/api/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
deny from all
|
||||
97
app/api/config/ueditor.php
Normal file
97
app/api/config/ueditor.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 百度富文本编辑器配置
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
|
||||
'upload_image' => [
|
||||
/* 上传图片配置项 */
|
||||
"imageActionName" => "uploadimage", /* 执行上传图片的action名称 */
|
||||
"imageFieldName" => "upfile", /* 提交的图片表单名称 */
|
||||
"imageMaxSize" => 204800000, /* 上传大小限制,单位B */
|
||||
"imageAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */
|
||||
"imageCompressEnable"=> true, /* 是否压缩图片,默认是true */
|
||||
"imageCompressBorder"=> 1600, /* 图片压缩最长边限制 */
|
||||
"imageInsertAlign" => "none", /* 插入的图片浮动方式 */
|
||||
"imageUrlPrefix" => "", /* 图片访问路径前缀 */
|
||||
"imagePathFormat" => "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
],
|
||||
'upload_scrawl' => [
|
||||
/* 涂鸦图片上传配置项 */
|
||||
"scrawlActionName" => "uploadscrawl", /* 执行上传涂鸦的action名称 */
|
||||
"scrawlFieldName" => "upfile", /* 提交的图片表单名称 */
|
||||
"scrawlPathFormat" => "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"scrawlMaxSize" => 204800000, /* 上传大小限制,单位B */
|
||||
"scrawlUrlPrefix" => "", /* 图片访问路径前缀 */
|
||||
"scrawlInsertAlign" => "none",
|
||||
],
|
||||
'upload_snap_image' => [
|
||||
/* 截图工具上传 */
|
||||
"snapscreenActionName" => "uploadimage", /* 执行上传截图的action名称 */
|
||||
"snapscreenPathFormat" => "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"snapscreenUrlPrefix" => "", /* 图片访问路径前缀 */
|
||||
"snapscreenInsertAlign" => "none", /* 插入的图片浮动方式 */
|
||||
],
|
||||
'upload_catcher' => [
|
||||
/* 抓取远程图片配置 */
|
||||
"catcherLocalDomain" => ["127.0.0.1", "localhost", "img.baidu.com"],
|
||||
"catcherActionName" => "catchimage", /* 执行抓取远程图片的action名称 */
|
||||
"catcherFieldName" => "source", /* 提交的图片列表表单名称 */
|
||||
"catcherPathFormat" => "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"catcherUrlPrefix" => "", /* 图片访问路径前缀 */
|
||||
"catcherMaxSize" => 204800000, /* 上传大小限制,单位B */
|
||||
"catcherAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */
|
||||
|
||||
],
|
||||
'upload_video' => [
|
||||
/* 上传视频配置 */
|
||||
"videoActionName" => "uploadvideo", /* 执行上传视频的action名称 */
|
||||
"videoFieldName" => "upfile", /* 提交的视频表单名称 */
|
||||
"videoPathFormat" => "/ueditor/php/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"videoUrlPrefix" => "", /* 视频访问路径前缀 */
|
||||
"videoMaxSize" => 102400000, /* 上传大小限制,单位B,默认100MB */
|
||||
"videoAllowFiles" => [
|
||||
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
|
||||
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"
|
||||
], /* 上传视频格式显示 */
|
||||
],
|
||||
'upload_file' => [
|
||||
/* 上传文件配置 */
|
||||
"fileActionName" => "uploadfile", /* controller里,执行上传视频的action名称 */
|
||||
"fileFieldName" => "upfile", /* 提交的文件表单名称 */
|
||||
"filePathFormat" => "/ueditor/php/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"fileUrlPrefix" => "", /* 文件访问路径前缀 */
|
||||
"fileMaxSize" => 51200000, /* 上传大小限制,单位B,默认50MB */
|
||||
"fileAllowFiles" => [
|
||||
".png", ".jpg", ".jpeg", ".gif", ".bmp",
|
||||
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
|
||||
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
|
||||
".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
|
||||
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
|
||||
], /* 上传文件格式显示 */
|
||||
],
|
||||
'upload_list_image' => [
|
||||
/* 列出指定目录下的图片 */
|
||||
"imageManagerActionName" => "listimage", /* 执行图片管理的action名称 */
|
||||
"imageManagerListPath" => "/ueditor/php/upload/image/", /* 指定要列出图片的目录 */
|
||||
"imageManagerListSize" => 20, /* 每次列出文件数量 */
|
||||
"imageManagerUrlPrefix" => "", /* 图片访问路径前缀 */
|
||||
"imageManagerInsertAlign" => "none", /* 插入的图片浮动方式 */
|
||||
"imageManagerAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的文件类型 */
|
||||
|
||||
],
|
||||
'upload_file_list' => [
|
||||
/* 列出指定目录下的文件 */
|
||||
"fileManagerActionName" => "listfile", /* 执行文件管理的action名称 */
|
||||
"fileManagerListPath" => "/ueditor/php/upload/file/", /* 指定要列出文件的目录 */
|
||||
"fileManagerUrlPrefix" => "", /* 文件访问路径前缀 */
|
||||
"fileManagerListSize" => 20, /* 每次列出文件数量 */
|
||||
"fileManagerAllowFiles" => [
|
||||
".png", ".jpg", ".jpeg", ".gif", ".bmp",
|
||||
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
|
||||
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
|
||||
".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
|
||||
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
|
||||
] /* 列出的文件类型 */
|
||||
]
|
||||
];
|
||||
35
app/api/config/whitelist.php
Normal file
35
app/api/config/whitelist.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 中间件-路由白名单
|
||||
// | 用来定义访问不需要鉴权的方法
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
/*路由白名单*/
|
||||
'route' => [
|
||||
'v1/auth/login',
|
||||
'goods/ue_upload',
|
||||
'cdn/get_cdn_url',
|
||||
|
||||
'v1/auth/login_sso',
|
||||
'v1/goods/ue_upload',
|
||||
'v1/investment/export',
|
||||
'v1/cdn/get_cdn_url',
|
||||
'v1/nav/upload',
|
||||
'v1/comment/upload',
|
||||
'v1/ad/upload',
|
||||
'v1/soft_manual/upload',
|
||||
// 'v1/soft_manual/check_file',
|
||||
'v1/goods/upload',
|
||||
'v1/plat/upload',
|
||||
'v1/lang/upload',
|
||||
'v1/video/upload',
|
||||
'v1/ad/uploadImg'
|
||||
],
|
||||
|
||||
/*域名白名单*/
|
||||
'domain' => [
|
||||
// 'yc.test',
|
||||
]
|
||||
|
||||
|
||||
];
|
||||
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,"操作失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
79
app/api/middleware/Auth.php
Normal file
79
app/api/middleware/Auth.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace app\api\middleware;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\facade\Config;
|
||||
use think\facade\Env;
|
||||
use utils\Jwt;
|
||||
|
||||
/**
|
||||
* 全局路由中间件-验证权限
|
||||
* Class Auth
|
||||
* @package app\api\middleware
|
||||
*/
|
||||
class Auth
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
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");
|
||||
$config = [
|
||||
'iss' => Env::get('jwt_config.iss'),
|
||||
'exp' => Env::get('jwt_config.exp')
|
||||
];
|
||||
$jwt = new Jwt($config);
|
||||
$route = strtolower($request->pathinfo());
|
||||
$domain = strtolower($request->host());
|
||||
|
||||
if (in_array($route,Config::get('whitelist.route')) or in_array($domain,Config::get('whitelist.domain'))) {
|
||||
//表示此系列请求不需要鉴权,直接通行
|
||||
return $next($request);
|
||||
} else {
|
||||
//此系列请求需要鉴权。
|
||||
$loginToken = $request->header('x-token');
|
||||
$result = $jwt->checkToken($loginToken);
|
||||
if ($result < 0) {
|
||||
switch ($result) {
|
||||
case -1:
|
||||
show(-1,"token异常");
|
||||
break;
|
||||
case -2:
|
||||
show(-2,"token被篡改");
|
||||
break;
|
||||
case -3:
|
||||
show(-3,"token验签异常");
|
||||
break;
|
||||
case -4:
|
||||
show(-4,"token已过期");
|
||||
break;
|
||||
}
|
||||
} elseif ($result === 200 || $result === 201) {
|
||||
// token通过
|
||||
$adminInfo = $jwt->getUserInfo($loginToken);
|
||||
if (!isset($adminInfo['id'])) {
|
||||
show(-1001, '登录异常');
|
||||
}
|
||||
|
||||
if (empty($adminInfo) || $adminInfo['status'] == 1) {
|
||||
show(-1002, '登录异常');
|
||||
}
|
||||
|
||||
if ($result === 201) {
|
||||
$new_login_token = $jwt->getToken($adminInfo);
|
||||
$data = [
|
||||
'login_token' => $new_login_token,
|
||||
'exp' => Env::get('jwt_config.exp')
|
||||
];
|
||||
|
||||
header("Access-Control-Expose-Headers: X-Token-info");
|
||||
header("X-Token-info: " . base64_encode(json_encode($data)));
|
||||
}
|
||||
$adminInfo['auth_id_list'] = [];//权限菜单下发
|
||||
$request->admin_user_info = $adminInfo;
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
app/api/middleware/LogVisit.php
Normal file
32
app/api/middleware/LogVisit.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace app\api\middleware;
|
||||
|
||||
use app\api\model\LogVisit as LogVisitModel;
|
||||
|
||||
/**
|
||||
* 访问日志
|
||||
*/
|
||||
class LogVisit
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
$url = $request->domain() . $request->url();
|
||||
$params = json_encode($request->param(), JSON_UNESCAPED_UNICODE);
|
||||
$route = strtolower($request->pathinfo());
|
||||
$pathInfo = explode('/',$route);
|
||||
$action = array_pop($pathInfo);
|
||||
$controller = array_pop($pathInfo);
|
||||
$admin_id = 0;
|
||||
$admin_name = '';
|
||||
$platformId = 0;
|
||||
if (isset($request->admin_user_info)) {
|
||||
$admin_id = $request->admin_user_info['id'];
|
||||
$admin_name = $request->admin_user_info['nickname'];
|
||||
$platformId = $request->admin_user_info['platform_id'];
|
||||
}
|
||||
$log = new LogVisitModel();
|
||||
$log->log($url, $params, $controller, $action,$admin_id, $admin_name,$platformId);
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
92
app/api/model/Admin.php
Normal file
92
app/api/model/Admin.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 管理员模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Admin extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'code' => 'string',
|
||||
'username' => 'string',
|
||||
'nickname' => 'string',
|
||||
'password' => 'string',
|
||||
'avatar' => 'string',
|
||||
'role_id' => 'int',
|
||||
'org_id' => 'int',
|
||||
'dept_group_id' => 'int',
|
||||
'dept_id' => 'int',
|
||||
'mobile' => 'string',
|
||||
'create_time' => 'int',
|
||||
'create_ip' => 'string',
|
||||
'last_time' => 'int',
|
||||
'last_ip' => 'string',
|
||||
'status' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取管理员列表
|
||||
* @param array $where
|
||||
* @param int $page
|
||||
* @param int $size
|
||||
* @param string $order
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList($where, $page=1, $size=12, $order='id asc')
|
||||
{
|
||||
$w = [];
|
||||
if (isset($where['username']) && $where['username'] != '') {
|
||||
$w[] = ['username', 'like', $where['username'] . '%'];
|
||||
}
|
||||
|
||||
if (isset($where['role_id']) && $where['role_id'] != 0) {
|
||||
$w[] = ['role_id', '=', $where['role_id']];
|
||||
}
|
||||
|
||||
if ($page < 0) $page = 1;
|
||||
if ($size > 100) $size = 100;
|
||||
|
||||
$result = $this->where($w)->limit(($page-1)*$size, intval($size))->order($order)->withoutField(['password'])->select()->toArray();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名获取信息
|
||||
* @param string $username
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfoByUserName($username)
|
||||
{
|
||||
$result = $this->where(['username' => $username])->find();
|
||||
return $result ? $result->toArray() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param int $id 管理员表主键
|
||||
* @param bool $type
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getUserInfo(int $id,bool $type=false):array
|
||||
{
|
||||
if ($type) {
|
||||
$result = $this->find($id);
|
||||
} else {
|
||||
$result = $this->withoutField('password')->find($id);
|
||||
}
|
||||
return $result ? $result->toArray() : [];
|
||||
}
|
||||
}
|
||||
100
app/api/model/AdvertisePage.php
Normal file
100
app/api/model/AdvertisePage.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 广告页模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class AdvertisePage extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 广告页关系广告位模型
|
||||
*/
|
||||
public function PageSpace()
|
||||
{
|
||||
return $this->hasMany(AdvertiseSpace::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAdSpace($data)
|
||||
{
|
||||
$result = $this->where('id',$data['id'])->with('PageSpace')->find()->toArray();
|
||||
return $result['PageSpace'];
|
||||
}
|
||||
|
||||
}
|
||||
140
app/api/model/AdvertiseSpace.php
Normal file
140
app/api/model/AdvertiseSpace.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class AdvertiseSpace extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'advertise_page_id'=>'int',
|
||||
'max_num' =>'int',
|
||||
'width' =>'int',
|
||||
'height' =>'int',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 一个广告位对应一个多多个广告
|
||||
*/
|
||||
public function pageAd():\think\model\relation\HasMany
|
||||
{
|
||||
return $this->hasMany(Advertisement::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
if (!empty($page)) {
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
||||
$page[$key]['advertise_page_name'] = $this->getAdvertisePageName($item['advertise_page_id']);
|
||||
}
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
if (!empty($page)) {
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
||||
$page[$key]['advertise_page_name'] = $this->getAdvertisePageName($item['advertise_page_id']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 广告位-广告的关联模型
|
||||
*/
|
||||
public function spaceToAD():\think\model\relation\HasMany
|
||||
{
|
||||
return $this->hasMany(Advertisement::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList($data):array
|
||||
{
|
||||
$result = $this->where('site_id',$data['site_id'])->select();
|
||||
if ($result) {
|
||||
foreach ($result as &$item) {
|
||||
$item['use_num'] = $item->spaceToAD()->count();
|
||||
}
|
||||
}
|
||||
return $result->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取此广告位已经使用了的数量
|
||||
* @param $data
|
||||
* @return int
|
||||
*/
|
||||
public function getUseSpaceNum($data):int
|
||||
{
|
||||
return Advertisement::where('advertise_space_id',$data['id'])->where('site_id',$data['site_id'])->count();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAd($data):array
|
||||
{
|
||||
return $this->where('id',$data['id'])->with('pageAd')->find()->toArray()['pageAd'];
|
||||
}
|
||||
}
|
||||
154
app/api/model/Advertisement.php
Normal file
154
app/api/model/Advertisement.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 广告模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Advertisement extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'advertise_space_id' =>'int',
|
||||
'command' =>'string',
|
||||
'name' =>'string',
|
||||
'image' =>'string',
|
||||
'url' =>'string',
|
||||
'start_time' =>'int',
|
||||
'stop_time' =>'int',
|
||||
'play_order' =>'int',
|
||||
'sort' =>'int',
|
||||
'status' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
||||
$page[$key]['advertise_space_name'] = $this->getAdertiseSpaceName($item['advertise_space_id']);
|
||||
$page[$key]['spec'] = $this->getAdvertiseSpaceSpec($item['advertise_space_id']);
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
||||
$page[$key]['advertise_space_name'] = $this->getAdertiseSpaceName($item['advertise_space_id']);
|
||||
$page[$key]['spec'] = $this->getAdvertiseSpaceSpec($item['advertise_space_id']);
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 广告对应广告位,一对一
|
||||
* @return \think\model\relation\BelongsTo
|
||||
*/
|
||||
public function getAdToSpace()
|
||||
{
|
||||
return $this->belongsTo(AdvertiseSpace::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo(array $data):array
|
||||
{
|
||||
$advertisement = $this->find($data['id']);
|
||||
if ($advertisement) {
|
||||
$advertisement['ad_space_max_num'] = $advertisement->getAdToSpace()->value('max_num');
|
||||
$advertisement['size'] = $advertisement->getAdToSpace()->value('width')."x".$advertisement->getAdToSpace()->value('height');
|
||||
}
|
||||
return $advertisement->toArray() ? : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取当前广告位最大的广告数量
|
||||
* @param $data
|
||||
* @return int|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAdvertiseSpaceMaxNum($data):int
|
||||
{
|
||||
$result = AdvertiseSpace::find($data);
|
||||
return $result ? $result['max_num'] : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取当前广告位已经有多少条广告
|
||||
* @param $data
|
||||
* @return int
|
||||
*/
|
||||
public function getAdvertiseUseSpaceNum($data):int
|
||||
{
|
||||
return $this->where('advertise_space_id',$data['advertise_space_id'])->where('site_id',$data['site_id'])->count();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询当前数据是否是修改自己,还是别的项目修改成其他的
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function getBeforeUpdate($data):bool
|
||||
{
|
||||
$result = $this->findOrEmpty($data['id']);
|
||||
if (!empty($result)) {
|
||||
if ($result['advertise_space_id'] == $data['advertise_space_id']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
16
app/api/model/Area.php
Normal file
16
app/api/model/Area.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 全球国家列表
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Area extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'pid' => 'int',
|
||||
'name' => 'string',
|
||||
'level' => 'int',
|
||||
];
|
||||
}
|
||||
96
app/api/model/Article.php
Normal file
96
app/api/model/Article.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Article extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'article_type_id' => 'int',
|
||||
'title' => 'string',
|
||||
'brief' => 'string',
|
||||
'desc' => 'string',
|
||||
'thumb' => 'string',
|
||||
'url' => 'string',
|
||||
'meta_title' => 'string',
|
||||
'keywords' => 'string',
|
||||
'detail' => 'string',
|
||||
'sort' => 'int',
|
||||
'status' => 'int',
|
||||
'is_outer_chain' => 'int',
|
||||
'click_num' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function articleType():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(ArticleType::class,'id','article_type_id')->bind(['article_type_name'=>'name']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function languageName():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['articleType','languageName'])->select()->toArray();
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
return $collection->order($sort)->with(['articleType','languageName'])->select()->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
105
app/api/model/ArticleType.php
Normal file
105
app/api/model/ArticleType.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ArticleType extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'desc' =>'string',
|
||||
'icon' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* article分类与article表模型
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function getArticle()
|
||||
{
|
||||
return $this->hasMany(Article::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return $page;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应分类下的文章内容
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getArticleData($data):array
|
||||
{
|
||||
$article = $this->find($data['id']);
|
||||
if (!empty($article)) {
|
||||
return $article->getArticle()->select()->toArray();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
24
app/api/model/Attachment.php
Normal file
24
app/api/model/Attachment.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Attachment extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'name' => 'string',
|
||||
'type' => 'string',
|
||||
'local' => 'string',
|
||||
'path' => 'string',
|
||||
'hash' => 'string',
|
||||
'md5' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
}
|
||||
34
app/api/model/Attribute.php
Normal file
34
app/api/model/Attribute.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 属性模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Attribute extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'name' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 通过属性ID,查找是否有商品引用属性
|
||||
* @param $data
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getGoodsAttrById($data)
|
||||
{
|
||||
return GoodsAttribute::where('attribute_id',$data['id'])->find();
|
||||
}
|
||||
}
|
||||
417
app/api/model/BaseModel.php
Normal file
417
app/api/model/BaseModel.php
Normal file
@@ -0,0 +1,417 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\library\SSOApi;
|
||||
use think\facade\Env;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 后台模型基类
|
||||
* Class BaseModel
|
||||
* @package app\api\model
|
||||
*/
|
||||
class BaseModel extends Model
|
||||
{
|
||||
use SSOApi;
|
||||
/**
|
||||
* 查看列表数据
|
||||
* @param int $page 分页页码
|
||||
* @param int $pageSize 分页类目数量
|
||||
* @param array $field 需要输入的字段,默认为全部输出,筛选表字段
|
||||
* @param array $vague 需要进行模糊查询的字段,如: a like %a%
|
||||
* @param array $focus 精确搜索条件,如a=1,b=2这种精确等于某个值的
|
||||
* @param array $order 排序字段,如:['id'=>'desc','sort'=>'desc']
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getIndexList(int $page,int $pageSize,array $field = [], array $vague = [],array $focus = [],array $order = []):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($fields,$focus) {
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
})->where(function($query) use ($fields,$vague) {
|
||||
//模糊查询
|
||||
if (!empty($vague)) {
|
||||
foreach ($vague as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->whereOr($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
})->order($order);
|
||||
//判断是否需要分页
|
||||
if (0 == $page || 0 == $pageSize) {
|
||||
//不需要分页
|
||||
return $collection->select()->toArray();
|
||||
} else {
|
||||
//需要分布
|
||||
$totalNum = $collection->count();
|
||||
$data = $collection->page($page)->limit($pageSize)->select()->toArray();;
|
||||
return ['count'=>$totalNum,'data'=>$data];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function addData(array $data) : bool
|
||||
{
|
||||
$result = $this->create($data);
|
||||
return (bool)$result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function editData(array $data) : bool
|
||||
{
|
||||
if (isset($data['id']) && $data['id'] > 0) {
|
||||
$result = $this->find($data['id']);
|
||||
return $result && $result->save($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo(array $data) : array
|
||||
{
|
||||
if (isset($data['id'])) {
|
||||
$result = $this->find($data['id']);
|
||||
return $result ? $result->toArray() : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function delData(array $data) : bool
|
||||
{
|
||||
if (isset($data['id'])) {
|
||||
$result = $this->find($data['id']);
|
||||
return $result && $result->delete();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID获取数据
|
||||
* @param $ids
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getExportData($ids): array
|
||||
{
|
||||
$result = $this->whereIn($this->pk,$ids['ids'])->order('create_time','desc')->select();
|
||||
return $result ? $result->toArray() : [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量修改
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function batchEditData($data):bool
|
||||
{
|
||||
$result = $this->saveAll($data);
|
||||
return (bool)$result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function batchDelData(array $data) : bool
|
||||
{
|
||||
$res = true;
|
||||
foreach ($data as $item) {
|
||||
if (isset($item['id']) && $item['id'] > 0) {
|
||||
$result = $this->find($item['id']);
|
||||
$result = $result->delete();
|
||||
$res = $res && $result;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地区名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAreaNameById($id):string
|
||||
{
|
||||
$data = Area::find($id);
|
||||
return $data ? $data['name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取币种名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getCoinName($id):string
|
||||
{
|
||||
$result = Currency::find($id);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取站点语言名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getSiteLanguageName($id):string
|
||||
{
|
||||
$lang = Site::find($id);
|
||||
$result = Language::find($lang['language_id']);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取语言名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getLanguageName($id):string
|
||||
{
|
||||
$result = Language::find($id);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取语言名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getCountryName($id):string
|
||||
{
|
||||
$result = Country::find($id);
|
||||
return $result ? $result['zh'] : '其他';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取币种名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getPlatformName($id):string
|
||||
{
|
||||
$result = Platform::find($id);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getFileTypeName($id):string
|
||||
{
|
||||
$result = FileType::find($id);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getFaqTypeName($id):string
|
||||
{
|
||||
$result = FaqType::find($id);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAdvertisePageName($id):string
|
||||
{
|
||||
$result = AdvertisePage::find($id);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAdertiseSpaceName($id):string
|
||||
{
|
||||
$result = AdvertiseSpace::find($id);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取尺寸
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAdvertiseSpaceSpec($id):string
|
||||
{
|
||||
$result = AdvertiseSpace::find($id);
|
||||
if ($result) {
|
||||
$width = $result['width'];
|
||||
$height = $result['height'];
|
||||
return $width. 'x' . $height;
|
||||
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取名称
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getGoodsName($id):string
|
||||
{
|
||||
$result = Goods::find($id);
|
||||
return $result ? $result['name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function changeStatus($data):bool
|
||||
{
|
||||
$result = $this->find($data['id']);
|
||||
return $result && $result->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function changeSort($data):bool
|
||||
{
|
||||
$result = $this->find($data['id']);
|
||||
return $result && $result->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子类ID
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function getChildCategory($id):array
|
||||
{
|
||||
$res = $this->where('pid',$id)->column('id');
|
||||
array_push($res,intval($id));
|
||||
return $res ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父类ID
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function getPCategory($id):array
|
||||
{
|
||||
$res = $this->where('id',$id)->column('id');
|
||||
array_push($res,intval($id));
|
||||
return $res ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态数据检测,检测提交过来的数据中ID是否合法
|
||||
* @param $model
|
||||
* @param $condition
|
||||
* @return bool
|
||||
*/
|
||||
public function dynamicCheck($model,$condition):bool
|
||||
{
|
||||
return (bool) $model::where($condition)->find();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
106
app/api/model/Brand.php
Normal file
106
app/api/model/Brand.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Brand extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'brand_type_id' => 'int',
|
||||
'title' => 'string',
|
||||
'brief' => 'string',
|
||||
'desc' => 'string',
|
||||
'thumb' => 'string',
|
||||
'url' => 'string',
|
||||
'meta_title' => 'string',
|
||||
'keywords' => 'string',
|
||||
'detail' => 'string',
|
||||
'sort' => 'int',
|
||||
'status' => 'int',
|
||||
'is_outer_chain' => 'int',
|
||||
'is_on_index' => 'int',
|
||||
'click_num' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
'website' => 'string',
|
||||
'cname' => 'string',
|
||||
// 'en_name' => 'string',
|
||||
'belong' => 'string',
|
||||
// 'turnover' => 'string',
|
||||
'brand_cate' => 'string',
|
||||
'work_address' => 'string',
|
||||
'founded' => 'string',
|
||||
'founder' => 'string'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function BrandType():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(BrandType::class,'id','brand_type_id')->bind(['brand_type_name'=>'name']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function languageName():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['BrandType','languageName'])->select()->toArray();
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
return $collection->order($sort)->with(['BrandType','languageName'])->select()->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
122
app/api/model/BrandType.php
Normal file
122
app/api/model/BrandType.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class BrandType extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'desc' =>'string',
|
||||
'icon' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Brand分类与Brand表模型
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function getBrand()
|
||||
{
|
||||
return $this->hasMany(Brand::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return $page;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应分类下的文章内容
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getBrandData($data):array
|
||||
{
|
||||
$Brand = $this->find($data['id']);
|
||||
if (!empty($Brand)) {
|
||||
return $Brand->getBrand()->select()->toArray();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应分类下的文章内容
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getArticleData($data):array
|
||||
{
|
||||
$article = $this->find($data['id']);
|
||||
if (!empty($article)) {
|
||||
return $article->getBrand()->select()->toArray();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
25
app/api/model/BulkBuy.php
Normal file
25
app/api/model/BulkBuy.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 大批量采购模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class BulkBuy extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'area_id' =>'int',
|
||||
'name' =>'string',
|
||||
'phone' =>'string',
|
||||
'mode_number' =>'string',
|
||||
'email' =>'string',
|
||||
'arrival_country'=>'string',
|
||||
'delivery_time' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
}
|
||||
222
app/api/model/Comment.php
Normal file
222
app/api/model/Comment.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
use think\facade\Env;
|
||||
|
||||
/**
|
||||
* 用户评论表
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Comment extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'avatar' =>'string',
|
||||
'name' =>'string',
|
||||
'nickname' =>'string',
|
||||
'comment' =>'string',
|
||||
'url' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
protected $disuse = ['name'];
|
||||
/**
|
||||
* 反馈附件关联
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function CommentImage()
|
||||
{
|
||||
return $this->hasMany(CommentImage::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
$newCommentImage = [];
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->with('CommentImage')->select()->toArray();
|
||||
if (!empty($page)) {
|
||||
foreach ($page as $key => $value) {
|
||||
$resData[$key]['language_id'] = $value['site_id'];
|
||||
if (isset($value['CommentImage']) && !empty($value['CommentImage'])) {
|
||||
foreach ($value['CommentImage'] as $key1 => $value1) {
|
||||
$newCommentImage[$key1]['name'] = basename($value1['image']);
|
||||
// $newCommentImage[$key1]['url'] = Env::get('QINIU.cdn') . $value1['image'];
|
||||
$newCommentImage[$key1]['url'] = $value1['image'];
|
||||
}
|
||||
$page[$key]['CommentImage'] = $newCommentImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$resData = $collection->order($sort)->with('CommentImage')->select()->toArray();
|
||||
|
||||
if (!empty($resData)) {
|
||||
if ($resData['CommentImage']) {
|
||||
foreach ($resData as $key => $value) {
|
||||
$resData[$key]['language_id'] = $value['site_id'];
|
||||
foreach ($value['CommentImage'] as $key1 => $value1) {
|
||||
$newCommentImage[$key1]['name'] = basename($value1['image']);
|
||||
// $newCommentImage[$key1]['url'] = Env::get('QINIU.cdn') . $value1['image'];
|
||||
$newCommentImage[$key1]['url'] = $value1['image'];
|
||||
}
|
||||
$resData[$key]['CommentImage'] = $newCommentImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $resData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function addData($data):bool
|
||||
{
|
||||
$this->startTrans();
|
||||
try {
|
||||
$data['avatar'] = doImageURLtoRelativePath($data['avatar']);
|
||||
$comment = $this->create($data);
|
||||
//处理数据结构
|
||||
if (!empty($data['CommentImage'])) {
|
||||
foreach ($data['CommentImage'] as &$value) {
|
||||
$value['comment_id'] = $comment->id;
|
||||
$value['image'] = doImageURLtoRelativePath($value['url']);
|
||||
}
|
||||
//模型关联新增
|
||||
$comment->CommentImage()->saveAll($data['CommentImage']);
|
||||
}
|
||||
$this->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo(array $data):array
|
||||
{
|
||||
$comment = $this->find($data['id']);
|
||||
$comment['CommentImage'] = $this->CommentImage()->where('comment_id',$data['id'])->select();
|
||||
if ($comment['CommentImage']) {
|
||||
$newImage = [];
|
||||
foreach ($comment['CommentImage'] as $key1 => $value1) {
|
||||
$newImage[$key1]['name'] = basename($value1['image']);
|
||||
$newImage[$key1]['url'] = $value1['image'];
|
||||
}
|
||||
$comment['CommentImage'] = $newImage;
|
||||
}
|
||||
return $comment->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function editData(array $data):bool
|
||||
{
|
||||
$this->startTrans();
|
||||
try {
|
||||
$data['comment_image'] = $data['CommentImage'];
|
||||
unset($data['CommentImage']);
|
||||
$comment = $this->find($data['id']);
|
||||
$data['avatar'] = doImageURLtoRelativePath($data['avatar']);
|
||||
$result1 = $comment->save($data);
|
||||
//先将原先的全部删除
|
||||
if (!empty($data['comment_image'])) {
|
||||
$result2 = $comment->CommentImage->delete();
|
||||
if ($result1 && $result2) {
|
||||
//处理数据结构
|
||||
$newCommentImage = [];
|
||||
foreach ($data['comment_image'] as $key => $value) {
|
||||
$newCommentImage[] = [
|
||||
'comment_id' => $data['id'],
|
||||
'image' => doImageURLtoRelativePath($value['url']),
|
||||
];
|
||||
}
|
||||
$data['comment_image'] = $newCommentImage;
|
||||
//新增
|
||||
$comment->CommentImage()->saveAll($data['comment_image']);
|
||||
}
|
||||
}
|
||||
$this->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function delData(array $data):bool
|
||||
{
|
||||
$comment = $this->find($data['id']);
|
||||
$result1 = $comment->delete();
|
||||
//先将原先的全部删除
|
||||
$result2 = $comment->CommentImage->delete();;
|
||||
return $result1 && $result2;
|
||||
}
|
||||
|
||||
}
|
||||
16
app/api/model/CommentImage.php
Normal file
16
app/api/model/CommentImage.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class CommentImage extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'comment_id' =>'int',
|
||||
'image' =>'string',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
}
|
||||
23
app/api/model/Country.php
Normal file
23
app/api/model/Country.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 全球国家列表
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Country extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'en' => 'string',
|
||||
'code' => 'string',
|
||||
'tw' => 'string',
|
||||
'zh' => 'string',
|
||||
'icon' => 'string',
|
||||
'locale' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
78
app/api/model/CouponSubscribe.php
Normal file
78
app/api/model/CouponSubscribe.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券订阅
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class CouponSubscribe extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'goods_coupon_id' =>'int',
|
||||
'email' =>'string',
|
||||
'phone' =>'string',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList($data,$simple = null,$focus = null,$sort = null,$field = null)
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->select()->toArray();
|
||||
if (!empty($page)) {
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
||||
}
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
if (!empty($page)) {
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
84
app/api/model/Currency.php
Normal file
84
app/api/model/Currency.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 货币模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Currency extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'name' =>'string',
|
||||
'code' =>'string',
|
||||
'signal' =>'string',
|
||||
'status' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 通过币种ID获取平台是否已经使用
|
||||
* @param $data
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getPlatformCoin($data)
|
||||
{
|
||||
return Platform::where('currency_id',$data)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->select()->toArray();
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
return $collection->order($sort)->select()->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
94
app/api/model/Faq.php
Normal file
94
app/api/model/Faq.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 常见问题
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Faq extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'faq_type_id' =>'int',
|
||||
'question' =>'string',
|
||||
'answer' =>'string',
|
||||
'sort' =>'int',
|
||||
'status' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
// if (!empty($simple)) {
|
||||
// foreach ($simple as $key => $item) {
|
||||
// if (in_array($key,$fields)) {
|
||||
// $query->where($key,'like',"%".$item."%");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
})->where(function ($query) use ($data,$fields,$simple) {
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->whereOr($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
//获取列表名称
|
||||
if (!empty($page)) {
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['faq_type_name'] = $this->getFaqTypeName($item['faq_type_id']);
|
||||
$page[$key]['language_id'] = $this->getFaqTypeName($item['site_id']);
|
||||
}
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
if (!empty($page)) {
|
||||
//获取列表名称
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['faq_type_name'] = $this->getFaqTypeName($item['faq_type_id']);
|
||||
$page[$key]['language_id'] = $this->getFaqTypeName($item['site_id']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
}
|
||||
106
app/api/model/FaqType.php
Normal file
106
app/api/model/FaqType.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 常见问题分类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class FaqType extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'desc' =>'string',
|
||||
'icon' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* faq分类关联faq表模型
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function getFaqContents()
|
||||
{
|
||||
return $this->hasMany(Faq::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return $page;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应分类下的faq内容
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getFaqData($data)
|
||||
{
|
||||
$faqType = $this->find($data['id']);
|
||||
if (!empty($faqType)) {
|
||||
return $faqType->getFaqContents()->select()->toArray();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
130
app/api/model/FileType.php
Normal file
130
app/api/model/FileType.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class FileType extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'desc' =>'string',
|
||||
'icon' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
public function fileTypeSoftManual()
|
||||
{
|
||||
return $this->hasMany(SoftManual::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$resData = $collection->order($sort)->with('fileTypeSoftManual')->select()->toArray();
|
||||
if (!empty($resData)) {
|
||||
foreach ($resData as $key => $item)
|
||||
$resData[$key]['language_id'] = $item['site_id'];{
|
||||
if (count($item['fileTypeSoftManual']) > 0) {
|
||||
$resData[$key]['is_gray'] = 1;
|
||||
} else {
|
||||
$resData[$key]['is_gray'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $resData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前类型下驱动下载文件内容
|
||||
* @param $data
|
||||
* @return false
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getSoftManualData($data)
|
||||
{
|
||||
$softManual = $this->find($data['id']);
|
||||
if (!empty($softManual)) {
|
||||
return $softManual->fileTypeSoftManual()->select()->toArray();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量编辑数据
|
||||
* @param $data
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function batchEditData($data):bool
|
||||
{
|
||||
return (bool)$this->saveAll($data);
|
||||
// $result = $result1 = true;
|
||||
// foreach ($data as $item) {
|
||||
// $models = $this->find($item['id']);
|
||||
// if ($models) {
|
||||
// $result1 = $models->save($item);
|
||||
// }
|
||||
// $result = $result && $result1;
|
||||
// }
|
||||
// return $result;
|
||||
}
|
||||
|
||||
}
|
||||
609
app/api/model/Goods.php
Normal file
609
app/api/model/Goods.php
Normal file
@@ -0,0 +1,609 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 商品模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Goods extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'main_img' =>'string',
|
||||
'model_number' =>'string',
|
||||
'goods_category_id' =>'int',
|
||||
'price' =>'int',
|
||||
'is_new' =>'int',
|
||||
'is_discount' =>'int',
|
||||
'is_hot' =>'int',
|
||||
'is_recommend' =>'int',
|
||||
'details' =>'string',
|
||||
'title' =>'string',
|
||||
'keywords' =>'string',
|
||||
'description' =>'string',
|
||||
'sort' =>'int',
|
||||
'status' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 商品链接关联模型
|
||||
*/
|
||||
public function GoodsBuyNow()
|
||||
{
|
||||
return $this->hasMany(GoodsBuyNow::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品关联商品
|
||||
*/
|
||||
public function GoodsConnect()
|
||||
{
|
||||
return $this->hasMany(GoodsConnect::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品手册关联模型
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function GoodsSoftManual()
|
||||
{
|
||||
return $this->hasMany(GoodsSoftManual::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品主图关联模型
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function GoodsImages()
|
||||
{
|
||||
return $this->hasMany(GoodsImages::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品属性关联
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function goodsAttr()
|
||||
{
|
||||
return $this->hasMany(GoodsAttribute::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
//分类查询
|
||||
if (!empty($data['goods_category_id']) && is_array($data['goods_category_id'])) {
|
||||
$query->whereIn('goods_category_id',implode(',',$data['goods_category_id']));
|
||||
}
|
||||
});
|
||||
//先筛选再分
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->order($sort)->select()->count();
|
||||
$page = $collection->order($sort)->limit((int)$data['size'])->page((int)$data['page'])->select()->toArray();
|
||||
return ['page'=>array_values($page),'count'=>$count];
|
||||
} else {
|
||||
$resData = $collection->order($sort)->select()->toArray();
|
||||
return array_values($resData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function addData(array $data):bool
|
||||
{
|
||||
//开启事务
|
||||
$this->startTrans();
|
||||
//增加主图
|
||||
if (isset($data['goods_images'][0]['url'])) {
|
||||
$data['main_img'] = doImageURLtoRelativePath($data['goods_images'][0]['url']);
|
||||
} else {
|
||||
//TODO::没有上传数据则使用空,后面可以替换为默认图片
|
||||
$data['main_img'] = '';
|
||||
}
|
||||
$goods = $this->create($data);
|
||||
//处理数据结构
|
||||
$newBuyNow = [];
|
||||
foreach ($data['buy_now'] as $key => $value) {
|
||||
if ($value['name'] != '' && $value['url'] != '') {
|
||||
$newBuyNow[$key]['goods_id'] = $goods->id;
|
||||
$newBuyNow[$key]['name'] = $value['name'];
|
||||
$newBuyNow[$key]['url'] = $value['url'];
|
||||
}
|
||||
}
|
||||
$data['buy_now'] = $newBuyNow;
|
||||
if (!empty($data['buy_now'])) {
|
||||
$result1 = $goods->GoodsBuyNow()->saveAll($data['buy_now']);
|
||||
} else {
|
||||
unset($data['buy_now']);
|
||||
$result1 = true;
|
||||
}
|
||||
|
||||
$newGoodsImages = [];
|
||||
foreach ($data['goods_images'] as $key => $value) {
|
||||
if ($key < 8) {
|
||||
$newGoodsImages[$key]['goods_id'] = $goods->id;
|
||||
$newGoodsImages[$key]['image'] = doImageURLtoRelativePath($value['url']);
|
||||
}
|
||||
}
|
||||
$data['goods_images'] = $newGoodsImages;
|
||||
if (!empty($data['goods_images'])) {
|
||||
$result2 = $goods->GoodsImages()->saveAll($data['goods_images']);
|
||||
} else {
|
||||
unset($data['goods_images']);
|
||||
$result2 = true;
|
||||
}
|
||||
|
||||
$newConnectGoods = [];
|
||||
foreach ($data['connect_goods'] as $key => $value) {
|
||||
if ($value['connect_good_id'] != '' && $value['goods_category_id'] != '') {
|
||||
$newConnectGoods[$key]['goods_id'] = $goods->id;
|
||||
$newConnectGoods[$key]['connect_good_id'] = $value['connect_good_id'];
|
||||
$newConnectGoods[$key]['goods_category_id'] = $value['goods_category_id'];
|
||||
}
|
||||
}
|
||||
$data['connect_goods'] = $newConnectGoods;
|
||||
if (!empty($data['connect_goods'])) {
|
||||
$result3 = $goods->GoodsConnect()->saveAll($data['connect_goods']);
|
||||
} else {
|
||||
unset($data['connect_goods']);
|
||||
$result3 = true;
|
||||
}
|
||||
//处理驱动文档数据
|
||||
$newSoft = [];
|
||||
foreach ($data['soft_manual'] as $key => $value) {
|
||||
if ($value['file_type_id'] != '' && $value['soft_manual_id'] != '') {
|
||||
$newSoft[$key]['goods_id'] = $goods->id;
|
||||
$newSoft[$key]['file_type_id'] = $value['file_type_id'];
|
||||
$newSoft[$key]['soft_manual_id'] = $value['soft_manual_id'];
|
||||
}
|
||||
}
|
||||
$data['soft_manual'] = $newSoft;
|
||||
if (!empty($data['soft_manual'])) {
|
||||
$result4 = $goods->GoodsSoftManual()->saveAll($data['soft_manual']);
|
||||
} else {
|
||||
unset($data['soft_manual']);
|
||||
$result4 = true;
|
||||
}
|
||||
|
||||
//处理属性attr
|
||||
$newAttr = [];
|
||||
foreach ($data['attr'] as $key => $item) {
|
||||
if ($item['attribute_id'] != '' && $item['value'] != '') {
|
||||
$newAttr[$key]['goods_id'] = $goods->id;
|
||||
$newAttr[$key]['attribute_id'] = $item['attribute_id'];
|
||||
$newAttr[$key]['value'] = $item['value'];
|
||||
}
|
||||
}
|
||||
$data['attr'] = $newAttr;
|
||||
if (!empty($data['attr'])) {
|
||||
$result5 = $goods->goodsAttr()->saveAll($data['attr']);
|
||||
} else {
|
||||
unset($data['attr']);
|
||||
$result5 = true;
|
||||
}
|
||||
//模型关联新增
|
||||
if($result1 && $result2 && $result3 && $result4 && $result5) {
|
||||
$this->commit();
|
||||
return true;
|
||||
} else {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo(array $data):array
|
||||
{
|
||||
//初始化默认结构
|
||||
$defaultBuyNow = [['name' => '','url' => '']];
|
||||
$defaultSoftManual = [['file_type_id'=>'','soft_manual_id'=>'']];
|
||||
$defaultAttr = [['id'=>'','value'=>'']];
|
||||
$defaultGoodsImages = [['name'=>'','url'=>'']];
|
||||
$defaultConnectGoods = [
|
||||
['connect_good_id'=>'','goods_category_id'=>''],
|
||||
['connect_good_id'=>'','goods_category_id'=>''],
|
||||
['connect_good_id'=>'','goods_category_id'=>''],
|
||||
['connect_good_id'=>'','goods_category_id'=>''],
|
||||
];
|
||||
|
||||
$goods = $this->find($data['id']);
|
||||
$goods['buy_now'] = $this->GoodsBuyNow()->where('goods_id',$data['id'])->select()->toArray();
|
||||
$goods['goods_images'] = $this->GoodsImages()->where('goods_id',$data['id'])->select()->toArray();
|
||||
$goods['connect_goods'] = $this->GoodsConnect()->where('goods_id',$data['id'])->select()->toArray();
|
||||
$goods['soft_manual'] = $this->GoodsSoftManual()->where('goods_id',$data['id'])->select()->toArray();
|
||||
$goods['attr'] = $this->goodsAttr()->where('goods_id',$data['id'])->select()->toArray();
|
||||
|
||||
//处理buynow
|
||||
if (!empty($goods['buy_now'])) {
|
||||
$newBuyNow = [];
|
||||
foreach ($goods['buy_now'] as $key => $item) {
|
||||
$newBuyNow[$key]['name'] = $item['name'];
|
||||
$newBuyNow[$key]['url'] = $item['url'];
|
||||
}
|
||||
$goods['buy_now'] = $newBuyNow;
|
||||
} else {
|
||||
$goods['buy_now'] = $defaultBuyNow;
|
||||
}
|
||||
//处理属性attr
|
||||
if (!empty($goods['attr'])) {
|
||||
$newAttr = [];
|
||||
foreach ($goods['attr'] as $key => $item) {
|
||||
$newAttr[$key]['attribute_id'] = $item['attribute_id'];
|
||||
$newAttr[$key]['value'] = $item['value'];
|
||||
}
|
||||
$goods['attr'] = $newAttr;
|
||||
} else {
|
||||
$goods['attr'] = $defaultAttr;
|
||||
}
|
||||
//处理图片
|
||||
if (!empty($goods['goods_images'])) {
|
||||
$newGoodsImages = [];
|
||||
foreach ($goods['goods_images'] as $key => $item) {
|
||||
if ($key < 8) {
|
||||
$newGoodsImages[$key]['id'] = $item['id'];
|
||||
$newGoodsImages[$key]['name'] = basename($item['image']);
|
||||
$newGoodsImages[$key]['url'] = $item['image'];
|
||||
}
|
||||
}
|
||||
$goods['goods_images'] = $newGoodsImages;
|
||||
} else {
|
||||
$goods['goods_images'] = $defaultGoodsImages;
|
||||
}
|
||||
|
||||
//处理关联产品数据
|
||||
if (!empty($goods['connect_goods'])) {
|
||||
$newConnectGoods = [];
|
||||
foreach ($goods['connect_goods'] as $key => $item) {
|
||||
$newConnectGoods[$key]['id'] = $item['id'];
|
||||
$newConnectGoods[$key]['connect_good_id'] = $item['connect_good_id'];
|
||||
$newConnectGoods[$key]['type'] = $key;
|
||||
$newConnectGoods[$key]['goods_category_id'] = $item['goods_category_id'];
|
||||
}
|
||||
if (count($newConnectGoods) < 4 ) {
|
||||
$arr = [['connect_good_id'=>'','goods_category_id'=>'']];
|
||||
switch (count($newConnectGoods)) {
|
||||
case 1:
|
||||
$newConnectGoods = array_merge(array_merge(array_merge($newConnectGoods,$arr),$arr),$arr);
|
||||
break;
|
||||
case 2:
|
||||
$newConnectGoods = array_merge(array_merge($newConnectGoods,$arr),$arr);
|
||||
break;
|
||||
case 3:
|
||||
$newConnectGoods = array_merge($newConnectGoods,$arr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$goods['connect_goods'] = $newConnectGoods;
|
||||
} else {
|
||||
$goods['connect_goods'] = $defaultConnectGoods;
|
||||
}
|
||||
|
||||
//处理下载驱动手册
|
||||
if (!empty($goods['soft_manual'])) {
|
||||
$newSoft = [];
|
||||
foreach ($goods['soft_manual'] as $key => $good) {
|
||||
$newSoft[$key]['file_type_id'] = $good['file_type_id'];
|
||||
$newSoft[$key]['soft_manual_id'] = $good['soft_manual_id'];
|
||||
$newSoft[$key]['list'] = SoftManual::where('file_type_id',$good['file_type_id'])->select()->toArray();
|
||||
}
|
||||
$goods['soft_manual'] = $newSoft;
|
||||
} else {
|
||||
$goods['soft_manual'] = $defaultSoftManual;
|
||||
}
|
||||
|
||||
return $goods->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function editData(array $data):bool
|
||||
{
|
||||
$this->startTrans();
|
||||
$goods = $this->find($data['id']);
|
||||
//如何编辑商品修改了分类数据,那么需要把相关产品对应的分类一同删除
|
||||
if ($goods['goods_category_id'] != $data['goods_category_id']) {
|
||||
$connect = GoodsConnect::where(['goods_id'=>$data['id'],'goods_category_id'=>$goods['goods_category_id']])->column(['id']);
|
||||
if (!empty($connect)) {
|
||||
GoodsConnect::destroy($connect);
|
||||
}
|
||||
|
||||
}
|
||||
// dd($goods['goods_category_id'] , $data['goods_category_id']);
|
||||
//增加主图
|
||||
$data['main_img'] = doImageURLtoRelativePath($data['goods_images'][0]['url']);
|
||||
$result1 = $goods->save($data);
|
||||
//先将原先的全部删除
|
||||
$result2 = $goods->GoodsBuyNow->delete();
|
||||
$result3 = $goods->GoodsImages->delete();
|
||||
$result4 = $goods->GoodsConnect->delete();
|
||||
$result5 = $goods->GoodsSoftManual->delete();
|
||||
$result6 = $goods->goodsAttr->delete();
|
||||
|
||||
$result = false;
|
||||
|
||||
if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) {
|
||||
//处理数据结构
|
||||
$newBuyNow = [];
|
||||
foreach ($data['buy_now'] as $key => $value) {
|
||||
if ($value['name'] != '' && $value != '') {
|
||||
$newBuyNow[$key]['goods_id'] = $data['id'];
|
||||
$newBuyNow[$key]['name'] = $value['name'];
|
||||
$newBuyNow[$key]['url'] = $value['url'];
|
||||
}
|
||||
}
|
||||
$data['buy_now'] = $newBuyNow;
|
||||
if (!empty($data['buy_now'])) {
|
||||
$result11 = $goods->GoodsBuyNow()->saveAll($data['buy_now']);
|
||||
} else {
|
||||
$result11 = true;
|
||||
}
|
||||
|
||||
$newGoodsImages = [];
|
||||
foreach ($data['goods_images'] as $key => $value) {
|
||||
if ($key < 8) {
|
||||
$newGoodsImages[$key]['goods_id'] = $data['id'];
|
||||
$newGoodsImages[$key]['image'] = doImageURLtoRelativePath($value['url']);
|
||||
}
|
||||
}
|
||||
$data['goods_images'] = $newGoodsImages;
|
||||
if (!empty($data['goods_images'])) {
|
||||
$result22 = $goods->GoodsImages()->saveAll($data['goods_images']);
|
||||
} else {
|
||||
$result22 = true;
|
||||
}
|
||||
|
||||
$newConnectGoods = [];
|
||||
foreach ($data['connect_goods'] as $key => $value) {
|
||||
if ($value['goods_category_id'] != '' && $value['connect_good_id'] != '') {
|
||||
$newConnectGoods[$key]['goods_id'] = $data['id'];
|
||||
$newConnectGoods[$key]['connect_good_id'] = $value['connect_good_id'];
|
||||
$newConnectGoods[$key]['goods_category_id'] = $value['goods_category_id'];
|
||||
}
|
||||
}
|
||||
$data['connect_goods'] = $newConnectGoods;
|
||||
if (!empty($data['connect_goods'])) {
|
||||
$result33 = $goods->GoodsConnect()->saveAll($data['connect_goods']);
|
||||
} else {
|
||||
$result33 = true;
|
||||
}
|
||||
|
||||
|
||||
//处理驱动文档数据
|
||||
$newSoft = [];
|
||||
foreach ($data['soft_manual'] as $key => $value) {
|
||||
if ($value['file_type_id'] != '' && $value['soft_manual_id'] != '') {
|
||||
$newSoft[$key]['goods_id'] = $data['id'];
|
||||
$newSoft[$key]['file_type_id'] = $value['file_type_id'];
|
||||
$newSoft[$key]['soft_manual_id'] = $value['soft_manual_id'];
|
||||
}
|
||||
}
|
||||
$data['soft_manual'] = $newSoft;
|
||||
if (!empty($data['soft_manual'])) {
|
||||
$result44 = $goods->GoodsSoftManual()->saveAll($data['soft_manual']);
|
||||
} else {
|
||||
$result44 = true;
|
||||
}
|
||||
//处理属性attr
|
||||
$newAttr = [];
|
||||
foreach ($data['attr'] as $key => $item) {
|
||||
if ($item['attribute_id'] != '' && $item['value'] != '') {
|
||||
$newAttr[$key]['goods_id'] = $goods->id;
|
||||
$newAttr[$key]['attribute_id'] = $item['attribute_id'];
|
||||
$newAttr[$key]['value'] = $item['value'];
|
||||
}
|
||||
}
|
||||
$data['attr'] = $newAttr;
|
||||
if (!empty($data['attr'])) {
|
||||
$result55 = $goods->goodsAttr()->saveAll($data['attr']);
|
||||
} else {
|
||||
$result55 = true;
|
||||
}
|
||||
|
||||
$result = $result11 && $result22 && $result33 && $result44 && $result55;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$this->commit();
|
||||
return true;
|
||||
} else {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function delData(array $data):bool
|
||||
{
|
||||
$goods = $this->find($data['id']);
|
||||
$result1 = $goods->delete();
|
||||
//先将原先的全部删除
|
||||
$result2 = $goods->GoodsBuyNow->delete();
|
||||
$result3 = $goods->GoodsImages->delete();
|
||||
$result4 = $goods->GoodsConnect->delete();
|
||||
$result5 = $goods->GoodsSoftManual->delete();
|
||||
$result6 = $goods->goodsAttr->delete();
|
||||
|
||||
return $result1 && $result2 && $result3 && $result4 && $result5 && $result6;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取平台语言包列表
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getPlatformLanguage($data)
|
||||
{
|
||||
$result = (new Platform())->getPlatformLanguage($data);
|
||||
if ($result) {
|
||||
foreach ($result as $key => $item) {
|
||||
$result[$key]['language_name'] = $this->getLanguageName($item['site_id']);
|
||||
$result[$key]['coin_name'] = $this->getCoinName($item['currency_id']);
|
||||
foreach ($item['PlatformLanguage'] as $key1 => $item1) {
|
||||
$result[$key]['PlatformLanguage'][$key1]['language_name'] = $this->getLanguageName($item1['site_id']);
|
||||
}
|
||||
foreach ($item['PlatformCoin'] as $key1 => $item1) {
|
||||
$result[$key]['PlatformCoin'][$key1]['coin_name'] = $this->getCoinName($item1['currency_id']);
|
||||
}
|
||||
}
|
||||
return $result->toArray();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过分类ID获取商品列表
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getGoodsInfoByGoodsCategoryId($data)
|
||||
{
|
||||
return $this->where(['goods_category_id'=>$data['goods_category_id'],'status'=>0])->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function batchDelData(array $data):bool
|
||||
{
|
||||
$newResult = true;
|
||||
foreach ($data as $item) {
|
||||
$result = $this->delData($item);
|
||||
$newResult = $newResult && $result;
|
||||
}
|
||||
return $newResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量移除商品分类
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function batchRemoveOldCate($data)
|
||||
{
|
||||
return GoodsCate::whereIn('goods_id',implode(',',$data))->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return bool|\think\Collection
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function goodsBatchEditCategory($data)
|
||||
{
|
||||
$this->startTrans();
|
||||
try {
|
||||
//修改分类时,先查询当前分类下的分类数据
|
||||
foreach ($data as $datum) {
|
||||
$goods = $this->find($datum['id']);
|
||||
if ($goods['goods_category_id'] != $datum['goods_category_id']) {
|
||||
$connect = GoodsConnect::where(['goods_id'=>$datum['id'],'goods_category_id'=>$goods['goods_category_id']])->column('id');
|
||||
if (!empty($connect)) {
|
||||
GoodsConnect::destroy($connect);
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = $this->saveAll($data);
|
||||
if ($result) {
|
||||
$this->commit();
|
||||
return true;
|
||||
} else {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类及其子分类
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllSonCategory($data)
|
||||
{
|
||||
$newData = (new GoodsCategory())->getAllSonCategory($data);
|
||||
array_push($newData,$data['id']);
|
||||
return $newData;
|
||||
}
|
||||
}
|
||||
18
app/api/model/GoodsAttribute.php
Normal file
18
app/api/model/GoodsAttribute.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class GoodsAttribute extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'goods_id' =>'int',
|
||||
'attribute_id' =>'int',
|
||||
'value' =>'string',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
'sort' =>'int',
|
||||
];
|
||||
}
|
||||
21
app/api/model/GoodsBuyNow.php
Normal file
21
app/api/model/GoodsBuyNow.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 商品购买链接模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class GoodsBuyNow extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'goods_id' =>'int',
|
||||
'url' =>'string',
|
||||
'name' =>'string',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
17
app/api/model/GoodsCate.php
Normal file
17
app/api/model/GoodsCate.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class GoodsCate extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'goods_id' =>'int',
|
||||
'goods_category_id' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
}
|
||||
133
app/api/model/GoodsCategory.php
Normal file
133
app/api/model/GoodsCategory.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 商品分类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class GoodsCategory extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'int',
|
||||
'desc' =>'int',
|
||||
'pid' =>'int',
|
||||
'icon' =>'int',
|
||||
'sort' =>'int',
|
||||
'status' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 分类 商品数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getGategoryListData($data)
|
||||
{
|
||||
return (new Goods())->where(['goods_category_id'=>$data['goods_category_id'],'status'=>0])->select()->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分类 商品明细数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getGategoryListDataInfo($data)
|
||||
{
|
||||
if (isset($data['id']) && $data['id'] != 0) {
|
||||
$result = GoodsConnect::where('goods_id',$data['id'])->find();
|
||||
return $result ? $result->toArray() : [] ;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
* @param $data
|
||||
* @param bool $type
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function changeStatus($data,bool $type = false):bool
|
||||
{
|
||||
if (!$type) {
|
||||
$result = $this->find($data['id']);
|
||||
//正常更新
|
||||
if ($result) {
|
||||
return $result->save($data);
|
||||
}
|
||||
} else {
|
||||
$ret = $this->saveAll($data);
|
||||
return (bool) $ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo(array $data):array
|
||||
{
|
||||
$allCategory = $this->select()->toArray();
|
||||
$result = $this->find($data['id']);
|
||||
$newPid = [];
|
||||
if (!empty($allCategory)) {
|
||||
if ($result['pid'] != 0) {
|
||||
$newPid = category_to_all_pid($allCategory,$result['pid']);
|
||||
} else {
|
||||
$newPid = [0];
|
||||
}
|
||||
}
|
||||
$result['pid'] = $newPid;
|
||||
return $result->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找所有子项
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllSonCategory($data):array
|
||||
{
|
||||
$newData = $this->select()->toArray();
|
||||
if (!empty($newData)) {
|
||||
return category_to_all_children_id($newData,$data['id']);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前分类下是否在商品
|
||||
* @param $data
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function hasGoodsOnCategory($data)
|
||||
{
|
||||
return Goods::where('goods_category_id',$data['id'])->find();
|
||||
}
|
||||
}
|
||||
19
app/api/model/GoodsConnect.php
Normal file
19
app/api/model/GoodsConnect.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 关联商品模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class GoodsConnect extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'goods_id' =>'int',
|
||||
'goods_category_id' =>'int',
|
||||
'connect_good_id' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
}
|
||||
35
app/api/model/GoodsCoupon.php
Normal file
35
app/api/model/GoodsCoupon.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 优惠券模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class GoodsCoupon extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'old_code' =>'string',
|
||||
'new_code' =>'string',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $data
|
||||
* @return array|Model|void|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getLatest($data)
|
||||
{
|
||||
return $this->order($this->pk,'desc')->where($data)->find();
|
||||
}
|
||||
}
|
||||
19
app/api/model/GoodsImages.php
Normal file
19
app/api/model/GoodsImages.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 商品主力模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class GoodsImages extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'goods_id' =>'int',
|
||||
'image' =>'string',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
|
||||
];
|
||||
}
|
||||
19
app/api/model/GoodsSoftManual.php
Normal file
19
app/api/model/GoodsSoftManual.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 商品手册驱动模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class GoodsSoftManual extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'goods_id' =>'int',
|
||||
'file_type_id' =>'int',
|
||||
'soft_manual_id'=>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
}
|
||||
44
app/api/model/ImagesFile.php
Normal file
44
app/api/model/ImagesFile.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ImagesFile extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 上传用户昵称关联
|
||||
*/
|
||||
public function uploader()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'up_id')->bind(['uploader_name'=>'nickname']);
|
||||
}
|
||||
|
||||
// 根据ID查询
|
||||
public function scopeId($query, $id)
|
||||
{
|
||||
if (is_array($id)) {
|
||||
$query->where('id', 'in', $id);
|
||||
} else {
|
||||
$query->where('id', '=', $id);
|
||||
}
|
||||
}
|
||||
|
||||
// 根据上传人查询
|
||||
public function scopeUpId($query, $up_id)
|
||||
{
|
||||
$query->where('up_id', '=', $up_id);
|
||||
}
|
||||
|
||||
// 根据文件MD5值查询
|
||||
public function scopeFileMd5($query, $md5)
|
||||
{
|
||||
$query->where('file_md5', '=', $md5);
|
||||
}
|
||||
|
||||
// 根据文件hash值查询
|
||||
public function scopeFileHash($query, $hash)
|
||||
{
|
||||
$query->where('file_hash', '=', $hash);
|
||||
}
|
||||
}
|
||||
107
app/api/model/Investment.php
Normal file
107
app/api/model/Investment.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 招商信息模型
|
||||
*/
|
||||
class Investment extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'country_id' => 'int',
|
||||
'province_id' => 'int',
|
||||
'city_id' => 'int',
|
||||
'from' => 'string',
|
||||
'area' => 'string',
|
||||
'phone' => 'string',
|
||||
'name' => 'string',
|
||||
'email' => 'string',
|
||||
'wechat' => 'string',
|
||||
'qq' => 'string',
|
||||
'desc' => 'string',
|
||||
'sort' => 'int',
|
||||
'is_open' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
/**
|
||||
* 查看列表数据
|
||||
* @param int $page 分页页码
|
||||
* @param int $pageSize 分页类目数量
|
||||
* @param array $field 需要输入的字段,默认为全部输出,筛选表字段
|
||||
* @param array $vague 需要进行模糊查询的字段,如: a like %a%
|
||||
* @param array $focus 精确搜索条件,如a=1,b=2这种精确等于某个值的
|
||||
* @param array $order 排序字段,如:['id'=>'desc','sort'=>'desc']
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getIndexList(int $page,int $pageSize,array $field = [], array $vague = [],array $focus = [],array $order = []):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($fields,$focus) {
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
})->where(function($query) use ($fields,$vague) {
|
||||
//模糊查询
|
||||
if (!empty($vague)) {
|
||||
$query->whereOr('phone','like',"%".$vague['keyword']."%");
|
||||
$query->whereOr('name','like',"%".$vague['keyword']."%");
|
||||
$query->whereOr('wechat','like',"%".$vague['keyword']."%");
|
||||
$query->whereOr('qq','like',"%".$vague['keyword']."%");
|
||||
$query->whereOr('email','like',"%".$vague['keyword']."%");
|
||||
}
|
||||
})->order($order);
|
||||
//判断是否需要分页
|
||||
if (0 == $page || 0 == $pageSize) {
|
||||
//不需要分页
|
||||
return $collection->select()->toArray();
|
||||
} else {
|
||||
//需要分布
|
||||
$totalNum = $collection->count();
|
||||
$data = $collection->page($page)->limit($pageSize)->select()->toArray();;
|
||||
return ['count'=>$totalNum,'data'=>$data];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过ID获取数据
|
||||
* @param $ids
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getExportData($ids): array
|
||||
{
|
||||
$result = $this->whereIn($this->pk,$ids['ids'])->order('create_time','desc')->select()->toArray();
|
||||
foreach ($result as &$item){
|
||||
$item['platform_id'] = $this->getPlatformName($item['platform_id']);
|
||||
$item['language_id'] = $item['site_id'] = $this->getLanguageName($item['site_id']);
|
||||
$item['country_id'] = '中国';
|
||||
$item['province_id'] = $this->getAreaNameById($item['province_id']);
|
||||
$item['city_id'] = $this->getAreaNameById($item['city_id']);
|
||||
$item['is_open'] = $item['is_open'] == 0 ? '同意同类厂家查看,以便获得更多产品代理机会' : '同意意向厂家查看';
|
||||
unset($item['area']);
|
||||
unset($item['qq']);
|
||||
unset($item['sort']);
|
||||
unset($item['update_time']);
|
||||
unset($item['email']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
97
app/api/model/Join.php
Normal file
97
app/api/model/Join.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Join extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'join_type_id' => 'int',
|
||||
'title' => 'string',
|
||||
'brief' => 'string',
|
||||
'desc' => 'string',
|
||||
'thumb' => 'string',
|
||||
'url' => 'string',
|
||||
'meta_title' => 'string',
|
||||
'keywords' => 'string',
|
||||
'detail' => 'string',
|
||||
'sort' => 'int',
|
||||
'status' => 'int',
|
||||
'is_outer_chain' => 'int',
|
||||
'is_on_index' => 'int',
|
||||
'click_num' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function JoinType():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(JoinType::class,'id','join_type_id')->bind(['join_type_name'=>'name']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function languageName():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['JoinType','languageName'])->select()->toArray();
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
return $collection->order($sort)->with(['JoinType','languageName'])->select()->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
105
app/api/model/JoinType.php
Normal file
105
app/api/model/JoinType.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class JoinType extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'desc' =>'string',
|
||||
'icon' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* article分类与article表模型
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function getArticle()
|
||||
{
|
||||
return $this->hasMany(Join::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return $page;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应分类下的文章内容
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getArticleData($data):array
|
||||
{
|
||||
$article = $this->find($data['id']);
|
||||
if (!empty($article)) {
|
||||
return $article->getArticle()->select()->toArray();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
37
app/api/model/Language.php
Normal file
37
app/api/model/Language.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 语言包模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Language extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
'code' => 'string',
|
||||
'icon' => 'string',
|
||||
'locale' => 'string',
|
||||
'coin' => 'string',
|
||||
'sort' => 'int',
|
||||
'status' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
/**
|
||||
* 查找语言包是否被使用
|
||||
* @param $id
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getLanguageUse($id)
|
||||
{
|
||||
return Platform::where('language_id',$id)->find();
|
||||
}
|
||||
}
|
||||
51
app/api/model/LogVisit.php
Normal file
51
app/api/model/LogVisit.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 访问日志
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class LogVisit extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'admin_id' => 'int',
|
||||
'admin_name' => 'string',
|
||||
'url' => 'string',
|
||||
'params' => 'string',
|
||||
'controller' => 'string',
|
||||
'action' => 'string',
|
||||
'ip' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 写入日志
|
||||
* @param $url
|
||||
* @param $params
|
||||
* @param $controller
|
||||
* @param $action
|
||||
* @param $admin_id
|
||||
* @param $admin_name
|
||||
* @param $platformId
|
||||
* @return bool
|
||||
*/
|
||||
public function log($url, $params, $controller, $action,$admin_id, $admin_name,$platformId)
|
||||
{
|
||||
$insert_data = [
|
||||
'url' => $url,
|
||||
'params' => $params,
|
||||
'controller' => $controller,
|
||||
'action' => $action,
|
||||
'admin_id' => $admin_id?:0,
|
||||
'admin_name' => $admin_name?:'',
|
||||
'ip' => get_client_ip(),
|
||||
'platform_id' => $platformId?:0,
|
||||
'create_time' => time()
|
||||
];
|
||||
return $this->save($insert_data);
|
||||
}
|
||||
}
|
||||
119
app/api/model/Navigator.php
Normal file
119
app/api/model/Navigator.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 导航样款模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Navigator extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'pid' => 'int',
|
||||
'name' => 'string',
|
||||
'desc' => 'string',
|
||||
'icon' => 'string',
|
||||
'url' => 'string',
|
||||
'sort' => 'int',
|
||||
'status' => 'int',
|
||||
'is_top' => 'int',
|
||||
'is_foot' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 查询子项
|
||||
* @param $id
|
||||
* @return int
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getPidData($id):int
|
||||
{
|
||||
$result = $this->where('pid',$id)->find();
|
||||
if ($result) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$resData = $collection->order($sort)->select()->toArray();
|
||||
foreach ($resData as $key => $item) {
|
||||
if (1 === $this->getPidData($item['id'])) {
|
||||
$resData[$key]['is_gray'] = 1;
|
||||
} else {
|
||||
$resData[$key]['is_gray'] = 0;
|
||||
}
|
||||
}
|
||||
return $resData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断导航栏是否有子类
|
||||
* @param $id
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getNavigatorIsInUse($id):bool
|
||||
{
|
||||
$result = $this->where('pid',$id['id'])->find();
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
97
app/api/model/News.php
Normal file
97
app/api/model/News.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class News extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'news_type_id' => 'int',
|
||||
'title' => 'string',
|
||||
'brief' => 'string',
|
||||
'desc' => 'string',
|
||||
'thumb' => 'string',
|
||||
'url' => 'string',
|
||||
'meta_title' => 'string',
|
||||
'keywords' => 'string',
|
||||
'detail' => 'string',
|
||||
'sort' => 'int',
|
||||
'status' => 'int',
|
||||
'is_outer_chain' => 'int',
|
||||
'is_on_index' => 'int',
|
||||
'click_num' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function NewsType():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(NewsType::class,'id','news_type_id')->bind(['news_type_name'=>'name']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function languageName():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['NewsType','languageName'])->select()->toArray();
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
return $collection->order($sort)->with(['NewsType','languageName'])->select()->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
105
app/api/model/NewsType.php
Normal file
105
app/api/model/NewsType.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class NewsType extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'desc' =>'string',
|
||||
'icon' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* article分类与article表模型
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function getArticle()
|
||||
{
|
||||
return $this->hasMany(News::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return $page;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应分类下的文章内容
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getArticleData($data):array
|
||||
{
|
||||
$article = $this->find($data['id']);
|
||||
if (!empty($article)) {
|
||||
return $article->getArticle()->select()->toArray();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
279
app/api/model/Platform.php
Normal file
279
app/api/model/Platform.php
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 平台模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Platform extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'vi_color1' => 'string',
|
||||
'vi_color2' => 'string',
|
||||
'vi_color3' => 'string',
|
||||
'language_id' => 'int',
|
||||
'currency_id' => 'int',
|
||||
'name' => 'string',
|
||||
'desc' => 'string',
|
||||
'icon' => 'string',
|
||||
'sort' => 'int',
|
||||
'status' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 平台语言包关联模型
|
||||
*/
|
||||
public function PlatformLanguage():\think\model\relation\HasMany
|
||||
{
|
||||
return $this->hasMany(PlatformLanguage::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台币种关联模型
|
||||
*/
|
||||
public function PlatformCoin():\think\model\relation\HasMany
|
||||
{
|
||||
return $this->hasMany(PlatformCoin::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过平台ID查询平台有没有被使用
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function hasUserPlatform($data):array
|
||||
{
|
||||
return Site::where('platform_id',$data['id'])->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->whereLike($key,'%'.$item.'%');
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit($data['size'])->page($data['page'])->with(['PlatformLanguage'=>function($query) {
|
||||
$query->with(['getLanguage'=>function ($query) {
|
||||
$query->field(['id','name']);
|
||||
}]);
|
||||
},'PlatformCoin'=>function($query) {
|
||||
$query->with(['getCoin'=>function ($query) {
|
||||
$query->field(['id','name']);
|
||||
}]);
|
||||
}])->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_name'] = $this->getLanguageName($item['language_id']);
|
||||
$page[$key]['currency_name'] = $this->getLanguageName($item['currency_id']);
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$resData = $this->where(function ($query) use ($data,$fields) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
} else {
|
||||
$query->where(1);
|
||||
}
|
||||
})->with(['PlatformLanguage'=>function($query) {
|
||||
$query->with(['getLanguage'=>function ($query) {
|
||||
$query->field(['id','name']);
|
||||
}]);
|
||||
},'PlatformCoin'=>function($query) {
|
||||
$query->with(['getCoin'=>function ($query) {
|
||||
$query->field(['id','name']);
|
||||
}]);
|
||||
}])->select()->toArray();
|
||||
|
||||
foreach ($resData as $key => $item) {
|
||||
$resData[$key]['language_name'] = $this->getLanguageName($item['language_id']);
|
||||
$resData[$key]['currency_name'] = $this->getCoinName($item['currency_id']);
|
||||
}
|
||||
|
||||
return $resData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function addData(array $data):bool
|
||||
{
|
||||
unset($data['id']);
|
||||
$platform = $this->create($data);
|
||||
if ($platform) {
|
||||
//处理数据结构
|
||||
foreach ($data['platform_language'] as $k => $value) {
|
||||
$data['platform_language'][$k]['platform_id'] = $platform->id;
|
||||
}
|
||||
|
||||
foreach ($data['platform_coin'] as $k => $value) {
|
||||
$data['platform_coin'][$k]['platform_id'] = $platform->id;
|
||||
}
|
||||
//模型关联新增
|
||||
$result = $platform->PlatformLanguage()->saveAll($data['platform_language']);
|
||||
$result1 = $platform->PlatformCoin()->saveAll($data['platform_coin']);
|
||||
|
||||
return $result && $result1;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo(array $data):array
|
||||
{
|
||||
$platform = $this->find($data['id'])->toArray();
|
||||
if ($platform) {
|
||||
$platform['platform_language'] = $this->PlatformLanguage()->where('platform_id',$data['id'])->select()->toArray();
|
||||
$platform['platform_coin'] = $this->PlatformCoin()->where('platform_id',$data['id'])->select()->toArray();
|
||||
return $platform;
|
||||
}
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function editData(array $data):bool
|
||||
{
|
||||
$this->startTrans();
|
||||
try {
|
||||
$platform = $this->find($data['id']);
|
||||
if ($platform) {
|
||||
$result1 = $platform->save($data);
|
||||
//先将原先的全部删除
|
||||
$result2 = $platform->PlatformLanguage->delete();
|
||||
$result3 = $platform->PlatformCoin->delete();
|
||||
$result = false;
|
||||
if ($result1 && $result2 && $result3) {
|
||||
//处理数据结构
|
||||
foreach ($data['platform_language'] as $k => $value) {
|
||||
$data[$k]['platform_language'] = $data['id'];
|
||||
}
|
||||
|
||||
//处理数据结构
|
||||
foreach ($data['platform_coin'] as $k => $value) {
|
||||
$data[$k]['platform_coin'] = $data['id'];
|
||||
}
|
||||
//新增
|
||||
$result4 = $platform->PlatformLanguage()->saveAll($data['platform_language']);
|
||||
$result5 = $platform->PlatformCoin()->saveAll($data['platform_coin']);
|
||||
$result = $result4 && $result5;
|
||||
}
|
||||
// return $result;
|
||||
}
|
||||
$this->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function delData(array $data):bool
|
||||
{
|
||||
$platform = $this->find($data['id']);
|
||||
if ($platform) {
|
||||
$result1 = $platform->delete();
|
||||
|
||||
//先将原先的全部删除
|
||||
$result2 = $platform->PlatformLanguage->delete();;
|
||||
$result3 = $platform->PlatformCoin->delete();;
|
||||
return $result1 && $result2 && $result3;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getPlatformLanguage($data):array
|
||||
{
|
||||
return $this->where('id',$data)->with(['PlatformLanguage','PlatformCoin'])->select()->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $status
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getLanguageList($field,$status):array
|
||||
{
|
||||
return Language::field($field)->where($status)->select()->toArray();
|
||||
}
|
||||
}
|
||||
25
app/api/model/PlatformCoin.php
Normal file
25
app/api/model/PlatformCoin.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class PlatformCoin extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'currency_id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 平台-币种关联模型
|
||||
* @return \think\model\relation\BelongsTo
|
||||
*/
|
||||
public function getCoin()
|
||||
{
|
||||
return $this->belongsTo(Currency::class,'currency_id','id');
|
||||
}
|
||||
}
|
||||
27
app/api/model/PlatformLanguage.php
Normal file
27
app/api/model/PlatformLanguage.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 平台语言表模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class PlatformLanguage extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'language_id' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 平台-语言包关联模型
|
||||
* @return \think\model\relation\BelongsTo
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->belongsTo(Language::class);
|
||||
}
|
||||
}
|
||||
222
app/api/model/Question.php
Normal file
222
app/api/model/Question.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
use think\facade\Env;
|
||||
|
||||
/**
|
||||
* 用户反馈模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Question extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'area_id' => 'int',
|
||||
'country_id' => 'int',
|
||||
'name' => 'string',
|
||||
'email' => 'string',
|
||||
'phone' => 'string',
|
||||
'order_sn' => 'string',
|
||||
'product_model' => 'string',
|
||||
'os' => 'string',
|
||||
'desc' => 'string',
|
||||
'is_done' => 'int',
|
||||
'is_send_email' => 'int',
|
||||
'is_send_status' => 'int',
|
||||
'send_time' => 'int',
|
||||
'send_details' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
/**
|
||||
* 反馈附件关联
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function QuestionAttachment()
|
||||
{
|
||||
return $this->hasMany(QuestionAttachment::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList($data,$simple = null,$focus = null,$sort = null,$field = null)
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->select()->toArray();
|
||||
if (!empty($page)) {
|
||||
foreach ($page as $key => $item) {
|
||||
$lang = Language::find($data['site_id']);
|
||||
if (!empty($lang)) {
|
||||
if (strtolower($lang['code']) == 'zh-cn' || strtolower($lang['code']) == 'zh_cn') {
|
||||
$page[$key]['country_name'] = '中国';
|
||||
} else {
|
||||
$page[$key]['country_name'] = $this->getCountryName($item['country_id']);
|
||||
}
|
||||
}
|
||||
|
||||
$page[$key]['is_done_name'] = $item['is_done'] == 0 ? '未解决': '已解决';
|
||||
}
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
if (!empty($page)) {
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['country_name'] = $this->getCountryName($item['country_id']);
|
||||
$page[$key]['is_done_name'] = $item['is_done'] == 0 ? '未解决': '已解决';
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param $data
|
||||
* @return bool|void
|
||||
*/
|
||||
public function addData($data)
|
||||
{
|
||||
$this->startTrans();
|
||||
$question = $this->create($data);
|
||||
//处理数据结构
|
||||
foreach ($data['question_attachment'] as $k => $value) {
|
||||
$value['question_id'] = $question->id;
|
||||
}
|
||||
//模型关联新增
|
||||
$result = $question->QuestionAttachment()->saveAll($data['question_attachment']);
|
||||
if ($result && $question) {
|
||||
$this->commit();
|
||||
return true;
|
||||
} else {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo($data)
|
||||
{
|
||||
$question = $this->find($data['id']);
|
||||
$question['question_attachment'] = $this->QuestionAttachment()->where('question_id',$data['id'])->select()->toArray();
|
||||
if (!empty($question['question_attachment'])) {
|
||||
$newAttach = [];
|
||||
foreach ($question['question_attachment'] as $key1 => $value1) {
|
||||
$newAttach[$key1]['name'] = basename($value1['attach']);
|
||||
// $newAttach[$key1]['url'] = Env::get('QINIU.cdn').$value1['image'];
|
||||
$newAttach[$key1]['url'] = $value1['attach'];
|
||||
}
|
||||
$question['question_attachment'] = $newAttach;
|
||||
}
|
||||
return $question;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 编辑数据
|
||||
// * @param $data
|
||||
// * @return bool
|
||||
// * @throws \think\db\exception\DataNotFoundException
|
||||
// * @throws \think\db\exception\DbException
|
||||
// * @throws \think\db\exception\ModelNotFoundException
|
||||
// */
|
||||
// public function editData($data)
|
||||
// {
|
||||
// $question = $this->find($data['id']);
|
||||
// $result1 = $question->save($data);
|
||||
// //先将原先的全部删除
|
||||
// $result2 = $question->QuestionAttachment->delete();
|
||||
// $result = false;
|
||||
// if ($result1 && $result2) {
|
||||
// //处理数据结构
|
||||
// $newData = [];
|
||||
// foreach ($data['question_attachment'] as $key => $value) {
|
||||
// $newData[$key]['question_id'] = $data['id'];
|
||||
// $newData[$key]['attach'] = $value['url'];
|
||||
// }
|
||||
// $data['question_attachment'] = $newData;
|
||||
// //新增
|
||||
// $result = $question->QuestionAttachment()->saveAll($data['question_attachment']);
|
||||
// }
|
||||
// return $result;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function delData($data)
|
||||
{
|
||||
$this->startTrans();
|
||||
$question = $this->find($data['id']);
|
||||
$result1 = $question->delete();
|
||||
//先将原先的全部删除
|
||||
$result2 = $question->QuestionAttachment->delete();;
|
||||
if ($result1 && $result2) {
|
||||
$this->commit();
|
||||
return true;
|
||||
} else {
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解决-未解决
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function isDone($data)
|
||||
{
|
||||
$question = $this->find($data['id']);
|
||||
return $question->save($data);
|
||||
}
|
||||
}
|
||||
27
app/api/model/QuestionAttachment.php
Normal file
27
app/api/model/QuestionAttachment.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 反馈附件类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class QuestionAttachment extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'question_id' =>'int',
|
||||
'attach' =>'string',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 附件-问题关联表
|
||||
* @return \think\model\relation\BelongsTo
|
||||
*/
|
||||
public function getQuestion()
|
||||
{
|
||||
return $this->belongsTo(Question::class);
|
||||
}
|
||||
}
|
||||
98
app/api/model/Resource.php
Normal file
98
app/api/model/Resource.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Resource extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'platform_id' => 'int',
|
||||
'language_id' => 'int',
|
||||
'site_id' => 'int',
|
||||
'resource_type_id' => 'int',
|
||||
'title' => 'string',
|
||||
's_title' => 'string',
|
||||
'brief' => 'string',
|
||||
'desc' => 'string',
|
||||
'thumb' => 'string',
|
||||
'url' => 'string',
|
||||
'meta_title' => 'string',
|
||||
'keywords' => 'string',
|
||||
'detail' => 'string',
|
||||
'sort' => 'int',
|
||||
'status' => 'int',
|
||||
'is_outer_chain' => 'int',
|
||||
'is_on_index' => 'int',
|
||||
'click_num' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function ResourceType():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(ResourceType::class,'id','resource_type_id')->bind(['resource_type_name'=>'name']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function languageName():\think\model\relation\HasOne
|
||||
{
|
||||
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['ResourceType','languageName'])->select()->toArray();
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
return $collection->order($sort)->with(['ResourceType','languageName'])->select()->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
105
app/api/model/ResourceType.php
Normal file
105
app/api/model/ResourceType.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ResourceType extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'platform_id' =>'int',
|
||||
'site_id' =>'int',
|
||||
'name' =>'string',
|
||||
'desc' =>'string',
|
||||
'icon' =>'string',
|
||||
'sort' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* article分类与article表模型
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function getArticle()
|
||||
{
|
||||
return $this->hasMany(Resource::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
$page = $collection->order($sort)->select()->toArray();
|
||||
foreach ($page as $key => $item) {
|
||||
$page[$key]['language_id'] = $item['site_id'];
|
||||
}
|
||||
return $page;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应分类下的文章内容
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getArticleData($data):array
|
||||
{
|
||||
$article = $this->find($data['id']);
|
||||
if (!empty($article)) {
|
||||
return $article->getArticle()->select()->toArray();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
49
app/api/model/Role.php
Normal file
49
app/api/model/Role.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
/**
|
||||
* 角色类
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Role extends BaseModel
|
||||
{
|
||||
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
'desc' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
|
||||
|
||||
protected $disuse = [
|
||||
'desc'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 角色菜单关联
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function RoleToMenu()
|
||||
{
|
||||
return $this->hasMany(RoleToMenu::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo(array $data):array
|
||||
{
|
||||
$result = $this->find($data['role_id']);
|
||||
return $result ? $result->toArray() : [];
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user