cms first commit
This commit is contained in:
parent
0f24c9c580
commit
f81eaf40af
25
catch/cms/CmsService.php
Normal file
25
catch/cms/CmsService.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms;
|
||||
|
||||
use catcher\ModuleService;
|
||||
|
||||
class CmsService extends ModuleService
|
||||
{
|
||||
public function loadRouteFrom()
|
||||
{
|
||||
// TODO: Implement loadRouteFrom() method.
|
||||
return __DIR__ . DIRECTORY_SEPARATOR . 'route.php';
|
||||
}
|
||||
}
|
6
catch/cms/README.md
Normal file
6
catch/cms/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
## 内容管理系统
|
||||
|
||||
#### 安装
|
||||
```shell
|
||||
composer require xaboy/form-builder:~2.0
|
||||
```
|
80
catch/cms/controller/Articles.php
Normal file
80
catch/cms/controller/Articles.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\Articles as articlesModel;
|
||||
|
||||
class Articles extends CatchController
|
||||
{
|
||||
protected $articlesModel;
|
||||
|
||||
public function __construct(ArticlesModel $articlesModel)
|
||||
{
|
||||
$this->articlesModel = $articlesModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 19:40
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->articlesModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 19:40
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->articlesModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 19:40
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->articlesModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 19:40
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->articlesModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 19:40
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->articlesModel->deleteBy($id));
|
||||
}
|
||||
}
|
80
catch/cms/controller/Banners.php
Normal file
80
catch/cms/controller/Banners.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\Banners as bannersModel;
|
||||
|
||||
class Banners extends CatchController
|
||||
{
|
||||
protected $bannersModel;
|
||||
|
||||
public function __construct(BannersModel $bannersModel)
|
||||
{
|
||||
$this->bannersModel = $bannersModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 19:58
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->bannersModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 19:58
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->bannersModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 19:58
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->bannersModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 19:58
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->bannersModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 19:58
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->bannersModel->deleteBy($id));
|
||||
}
|
||||
}
|
91
catch/cms/controller/Category.php
Normal file
91
catch/cms/controller/Category.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\Category as categoryModel;
|
||||
use catcher\CatchUpload;
|
||||
use catcher\library\excel\reader\Reader;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class Category extends CatchController
|
||||
{
|
||||
protected $categoryModel;
|
||||
|
||||
public function __construct(CategoryModel $categoryModel)
|
||||
{
|
||||
$this->categoryModel = $categoryModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 19:15
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
return CatchResponse::success($this->categoryModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 19:15
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
return CatchResponse::success($this->categoryModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 19:15
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
return CatchResponse::success($this->categoryModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 19:15
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
return CatchResponse::success($this->categoryModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 19:15
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return CatchResponse::success($this->categoryModel->deleteBy($id));
|
||||
}
|
||||
|
||||
}
|
80
catch/cms/controller/Comments.php
Normal file
80
catch/cms/controller/Comments.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\Comments as commentsModel;
|
||||
|
||||
class Comments extends CatchController
|
||||
{
|
||||
protected $commentsModel;
|
||||
|
||||
public function __construct(CommentsModel $commentsModel)
|
||||
{
|
||||
$this->commentsModel = $commentsModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 19:53
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->commentsModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 19:53
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->commentsModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 19:53
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->commentsModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 19:53
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->commentsModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 19:53
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->commentsModel->deleteBy($id));
|
||||
}
|
||||
}
|
80
catch/cms/controller/FormData.php
Normal file
80
catch/cms/controller/FormData.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\FormData as formDataModel;
|
||||
|
||||
class FormData extends CatchController
|
||||
{
|
||||
protected $formDataModel;
|
||||
|
||||
public function __construct(FormDataModel $formDataModel)
|
||||
{
|
||||
$this->formDataModel = $formDataModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 20:35
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->formDataModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 20:35
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formDataModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 20:35
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formDataModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 20:35
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formDataModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 20:35
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formDataModel->deleteBy($id));
|
||||
}
|
||||
}
|
80
catch/cms/controller/FormFields.php
Normal file
80
catch/cms/controller/FormFields.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\FormFields as formFieldsModel;
|
||||
|
||||
class FormFields extends CatchController
|
||||
{
|
||||
protected $formFieldsModel;
|
||||
|
||||
public function __construct(FormFieldsModel $formFieldsModel)
|
||||
{
|
||||
$this->formFieldsModel = $formFieldsModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 20:28
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->formFieldsModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 20:28
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formFieldsModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 20:28
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formFieldsModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 20:28
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formFieldsModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 20:28
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formFieldsModel->deleteBy($id));
|
||||
}
|
||||
}
|
80
catch/cms/controller/Forms.php
Normal file
80
catch/cms/controller/Forms.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\Forms as formsModel;
|
||||
|
||||
class Forms extends CatchController
|
||||
{
|
||||
protected $formsModel;
|
||||
|
||||
public function __construct(FormsModel $formsModel)
|
||||
{
|
||||
$this->formsModel = $formsModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 20:19
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->formsModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 20:19
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formsModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 20:19
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formsModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 20:19
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formsModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 20:19
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->formsModel->deleteBy($id));
|
||||
}
|
||||
}
|
95
catch/cms/controller/ModelFields.php
Normal file
95
catch/cms/controller/ModelFields.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catchAdmin\cms\support\Table;
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\ModelFields as ModelFieldsModel;
|
||||
use catchAdmin\cms\model\Models;
|
||||
use catcher\exceptions\FailedException;
|
||||
|
||||
class ModelFields extends CatchController
|
||||
{
|
||||
protected $modelFields;
|
||||
|
||||
public function __construct(ModelFieldsModel $modelFields)
|
||||
{
|
||||
$this->modelFields = $modelFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月29日 21:00
|
||||
* @param Request $request
|
||||
* @param Models $models
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index(Request $request): \think\response\Json
|
||||
{
|
||||
// $columns = Table::columns($models::where('id',$request->param('model_id'))->value('table_name'));
|
||||
|
||||
//foreach ($columns as &$column) {
|
||||
// $column['title'] = $column['comment'];
|
||||
// }
|
||||
|
||||
return CatchResponse::success($this->modelFields->getFieldsByModelId($request->param('model_id')));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月29日 21:00
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function save(Request $request): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($this->modelFields->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月29日 21:00
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function read($id): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($this->modelFields->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月29日 21:00
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function update(Request $request, $id): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($this->modelFields->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月29日 21:00
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($this->modelFields->deleteBy($id));
|
||||
}
|
||||
}
|
85
catch/cms/controller/Models.php
Normal file
85
catch/cms/controller/Models.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\Models as CmsModel;
|
||||
|
||||
class Models extends CatchController
|
||||
{
|
||||
protected $cmsModel;
|
||||
|
||||
public function __construct(CmsModel $cmsModel)
|
||||
{
|
||||
$this->cmsModel = $cmsModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月29日 20:02
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index(Request $request): \think\response\Json
|
||||
{
|
||||
return CatchResponse::paginate($this->cmsModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月29日 20:02
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function save(Request $request): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($this->cmsModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月29日 20:02
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function read($id): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($this->cmsModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月29日 20:02
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function update(Request $request, $id): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($this->cmsModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月29日 20:02
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($this->cmsModel->deleteBy($id));
|
||||
}
|
||||
}
|
80
catch/cms/controller/SiteLinks.php
Normal file
80
catch/cms/controller/SiteLinks.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\SiteLinks as siteLinksModel;
|
||||
|
||||
class SiteLinks extends CatchController
|
||||
{
|
||||
protected $siteLinksModel;
|
||||
|
||||
public function __construct(SiteLinksModel $siteLinksModel)
|
||||
{
|
||||
$this->siteLinksModel = $siteLinksModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 20:02
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->siteLinksModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 20:02
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->siteLinksModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 20:02
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->siteLinksModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 20:02
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->siteLinksModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 20:02
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->siteLinksModel->deleteBy($id));
|
||||
}
|
||||
}
|
69
catch/cms/controller/Tags.php
Normal file
69
catch/cms/controller/Tags.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\Tags as tagsModel;
|
||||
|
||||
class Tags extends CatchController
|
||||
{
|
||||
protected $tagsModel;
|
||||
|
||||
public function __construct(TagsModel $tagsModel)
|
||||
{
|
||||
$this->tagsModel = $tagsModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 19:44
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->tagsModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 19:44
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->tagsModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 19:44
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->tagsModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 19:44
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->tagsModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 19:44
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->tagsModel->deleteBy($id));
|
||||
}
|
||||
}
|
69
catch/cms/controller/Upload.php
Normal file
69
catch/cms/controller/Upload.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catchAdmin\system\model\Attachments;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\base\CatchRequest;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\CatchUpload;
|
||||
use catcher\exceptions\FailedException;
|
||||
|
||||
class Upload extends CatchController
|
||||
{
|
||||
protected $attachment;
|
||||
|
||||
public function __construct(Attachments $attachment)
|
||||
{
|
||||
$this->attachment = $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* image upload
|
||||
*
|
||||
* @time 2020年01月25日
|
||||
* @param CatchRequest $request
|
||||
* @param CatchUpload $upload
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function image(CatchRequest $request, CatchUpload $upload): \think\response\Json
|
||||
{
|
||||
$images = $request->file();
|
||||
|
||||
if (!$images) {
|
||||
throw new FailedException('请选择图片上传');
|
||||
}
|
||||
|
||||
return CatchResponse::success([
|
||||
'filePath' => $upload->checkImages($images)->multiUpload($images['image'])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* file upload
|
||||
*
|
||||
* @time 2020年01月25日
|
||||
* @param CatchRequest $request
|
||||
* @param CatchUpload $upload
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function file(CatchRequest $request, CatchUpload $upload): \think\response\Json
|
||||
{
|
||||
$files = $request->file();
|
||||
|
||||
return CatchResponse::success([
|
||||
'src' => $upload->checkFiles($files)->multiUpload($files['file'])
|
||||
]);
|
||||
}
|
||||
}
|
80
catch/cms/controller/Users.php
Normal file
80
catch/cms/controller/Users.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\cms\model\Users as usersModel;
|
||||
|
||||
class Users extends CatchController
|
||||
{
|
||||
protected $usersModel;
|
||||
|
||||
public function __construct(UsersModel $usersModel)
|
||||
{
|
||||
$this->usersModel = $usersModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time 2020年12月27日 19:04
|
||||
* @param Request $request
|
||||
*/
|
||||
public function index(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::paginate($this->usersModel->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time 2020年12月27日 19:04
|
||||
* @param Request $request
|
||||
*/
|
||||
public function save(Request $request) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->usersModel->storeBy($request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time 2020年12月27日 19:04
|
||||
* @param $id
|
||||
*/
|
||||
public function read($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->usersModel->findBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time 2020年12月27日 19:04
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->usersModel->updateBy($id, $request->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time 2020年12月27日 19:04
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id) : \think\Response
|
||||
{
|
||||
return CatchResponse::success($this->usersModel->deleteBy($id));
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsHomeUsers extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_users', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '用户表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('username', 'string', ['limit' => 100,'null' => true,'signed' => true,'comment' => '用户名',])
|
||||
->addColumn('email', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '邮箱',])
|
||||
->addColumn('mobile', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '手机号',])
|
||||
->addColumn('avatar', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '头像',])
|
||||
->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 正常 2 禁用',])
|
||||
->addColumn('password', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '密码',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsCategory extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_category', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '分类表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('name', 'string', ['limit' => 100,'null' => true,'signed' => true,'comment' => '栏目名称',])
|
||||
->addColumn('parent_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 0,'signed' => true,'comment' => '父级ID',])
|
||||
->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'seo标题',])
|
||||
->addColumn('keywords', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'seo关键词',])
|
||||
->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '描述',])
|
||||
->addColumn('url', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '自定义 URL',])
|
||||
->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '状态',])
|
||||
->addColumn('is_can_contribute', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '是否可以投稿',])
|
||||
->addColumn('is_can_comment', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '是否可以评论',])
|
||||
->addColumn('type', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '页面模式',])
|
||||
->addColumn('weight', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 1,'signed' => true,'comment' => '权重',])
|
||||
// ->addColumn('is_link_out', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '1 是 2 否',])
|
||||
->addColumn('link_to', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '链接外部地址',])
|
||||
->addColumn('limit', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 10,'signed' => true,'comment' => '每页数量',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsArticles extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_articles', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '文章表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('title', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '文章标题',])
|
||||
->addColumn('category_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => true,'signed' => true,'comment' => '分类ID',])
|
||||
->addColumn('images', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '多图集合',])
|
||||
->addColumn('tags', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '标签集合',])
|
||||
->addColumn('url', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '自定义URL',])
|
||||
->addColumn('content', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => false,'signed' => true,'comment' => '内容',])
|
||||
->addColumn('keywords', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '关键字',])
|
||||
->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '描述',])
|
||||
->addColumn('pv', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '浏览量',])
|
||||
->addColumn('likes', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '喜欢',])
|
||||
->addColumn('comments', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '评论数',])
|
||||
->addColumn('is_top', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '1 置顶 2 非置顶',])
|
||||
->addColumn('is_recommend', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '1 推荐 2 不推荐',])
|
||||
->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 展示 2 隐藏',])
|
||||
->addColumn('is_can_comment', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 允许 2 不允许',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
43
catch/cms/database/migrations/20201227194430_cms_tags.php
Normal file
43
catch/cms/database/migrations/20201227194430_cms_tags.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsTags extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_tags', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '标签表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '标签名称',])
|
||||
->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'seo 标签',])
|
||||
->addColumn('keywords', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '关键字',])
|
||||
->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '描述',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsArticleRelateTags extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_article_relate_tags', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '文章关联标签表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('article_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => false,'comment' => '文章ID',])
|
||||
->addColumn('tag_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => false,'comment' => '标签ID',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsComments extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_comments', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('article_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => false,'comment' => '文章ID',])
|
||||
->addColumn('content', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '内容',])
|
||||
->addColumn('parent_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '父ID',])
|
||||
->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => false,'comment' => '评论者ID',])
|
||||
->addColumn('ip', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'ip 地址',])
|
||||
->addColumn('user_agent', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'agent',])
|
||||
->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 展示 2 隐藏',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
43
catch/cms/database/migrations/20201227195847_cms_banners.php
Normal file
43
catch/cms/database/migrations/20201227195847_cms_banners.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsBanners extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_banners', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => 'banner 图' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'banner 标题',])
|
||||
->addColumn('banner_img', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'banner 图片',])
|
||||
->addColumn('category_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 0,'signed' => true,'comment' => '默认 0 代表首页展示',])
|
||||
->addColumn('link_to', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '链接地址',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsSiteLinks extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_site_links', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '友情链接' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '友情链接标题',])
|
||||
->addColumn('link_to', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '跳转地址',])
|
||||
->addColumn('weight', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 1,'signed' => true,'comment' => '权重',])
|
||||
->addColumn('is_show', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 展示 2 隐藏',])
|
||||
->addColumn('icon', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '网站图标',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
49
catch/cms/database/migrations/20201227201933_cms_forms.php
Normal file
49
catch/cms/database/migrations/20201227201933_cms_forms.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsForms extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_forms', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '动态表单' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单名称',])
|
||||
->addColumn('alias', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单别名',])
|
||||
->addColumn('submit_url', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单提交的 URL',])
|
||||
->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单标题',])
|
||||
->addColumn('keywords', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '关键词',])
|
||||
->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '描述',])
|
||||
->addColumn('success_message', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '成功提示信息',])
|
||||
->addColumn('failed_message', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '失败提示信息',])
|
||||
->addColumn('success_link_to', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '成功后跳转',])
|
||||
->addColumn('is_login_to_submit', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 需要 2 不需要',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsFormFields extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_form_fields', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '动态表单字段' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('form_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => 'form id',])
|
||||
->addColumn('label', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '字段 label',])
|
||||
->addColumn('name', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '表单字段name',])
|
||||
->addColumn('default_value', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '默认值',])
|
||||
->addColumn('type', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 1,'signed' => false,'comment' => '类型',])
|
||||
->addColumn('rule', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '验证规则',])
|
||||
->addColumn('length', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 0,'signed' => true,'comment' => '字段长度',])
|
||||
->addColumn('failed_message', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '验证失败信息',])
|
||||
->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 展示 2 隐藏',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsFormData extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_form_data', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '动态提交的表单数据' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('form_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '表单ID',])
|
||||
->addColumn('data', 'json', ['null' => false,'signed' => true,'comment' => 'json字段',])
|
||||
->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '用户ID',])
|
||||
->addColumn('ip', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'ip 地址',])
|
||||
->addColumn('user_agent', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'agent',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
43
catch/cms/database/migrations/20201229200249_cms_model.php
Normal file
43
catch/cms/database/migrations/20201229200249_cms_model.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsModel extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_models', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '模型表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '模型名称',])
|
||||
->addColumn('alias', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '模型别名',])
|
||||
->addColumn('table_name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '模型关联的表名,数据来源',])
|
||||
->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '模型描述',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class CmsModelFields extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('cms_model_fields', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '模型字段' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '字段中文名称',])
|
||||
->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单字段名称',])
|
||||
->addColumn('type', 'string', ['limit' => 50, 'null' => false,'signed' => true,'comment' => '类型',])
|
||||
->addColumn('length', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => true,'signed' => true,'comment' => '字段长度',])
|
||||
->addColumn('default_value', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '默认值',])
|
||||
->addColumn('options', 'string', ['limit' => 1000,'null' => false,'default' => '', 'comment' => '选项',])
|
||||
->addColumn('is_index', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '是否是索引 1 是 2 否',])
|
||||
->addColumn('is_unique', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '是否唯一 1 是 2 否',])
|
||||
->addColumn('rules', 'string', ['limit' => 255,'null' => false,'default' => '', 'comment' => '验证规则',])
|
||||
->addColumn('pattern', 'string', ['limit' => 255,'null' => false,'default' => '', 'comment' => '正则',])
|
||||
->addColumn('model_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => true,'signed' => true,'comment' => '模型ID',])
|
||||
->addColumn('use_at_list', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '展示在列表 1 是 2 否',])
|
||||
->addColumn('use_at_detail', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '展示在详情 1 是 2 否',])
|
||||
->addColumn('use_at_search', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '用作是否搜索 1 是 2 否',])
|
||||
->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
|
||||
->addColumn('sort', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 1,'signed' => false,'comment' => '排序',])
|
||||
->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_TINY,'null' => false,'default' => 1,'signed' => false,'comment' => '状态 1显示 2隐藏',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
use \Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class ModelAuxiliaryTable extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
|
||||
$table = $this->table('cms_model_auxiliary_table', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '模型副表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
|
||||
$table->addColumn('model_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '模型ID',])
|
||||
->addColumn('table_name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '副表表明',])
|
||||
->addColumn('used', 'integer', ['limit' => MysqlAdapter::INT_TINY,'null' => false,'default' => 2,'signed' => true,'comment' => '默认使用 1 不使用 2 使用',])
|
||||
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
|
||||
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
|
||||
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
|
||||
class AddModelFields extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
if ($this->hasTable('cms_models')) {
|
||||
$this->table('cms_models')
|
||||
->addColumn('used_at_list', 'string', ['limit' => 512,'null' => false,'default' => '','signed' => true,'comment' => '用在列表的字段', 'after' => 'description'])
|
||||
->addColumn('used_at_search', 'string', ['limit' => 512,'null' => false,'default' => '','signed' => true,'comment' => '用在搜索的字段', 'after' => 'description'])
|
||||
->addColumn('used_at_detail', 'string', ['limit' => 512,'null' => false,'default' => '','signed' => true,'comment' => '用在详情的字段', 'after' => 'description'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
|
||||
class AddArticleColumns extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
if ($this->hasTable('cms_articles')) {
|
||||
$table = $this->table('cms_articles');
|
||||
|
||||
$table->addColumn('weight', 'integer', [
|
||||
'default' => 1,
|
||||
'comment' => '文章权重',
|
||||
'after' => 'status'
|
||||
])->update();
|
||||
|
||||
$table->addColumn('cover', 'string', [
|
||||
'limit' => 255,
|
||||
'default' => '',
|
||||
'comment' => '封面地址',
|
||||
'after' => 'category_id'
|
||||
])->update();
|
||||
}
|
||||
}
|
||||
}
|
24
catch/cms/exceptions/ColumnException.php
Normal file
24
catch/cms/exceptions/ColumnException.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catchAdmin\cms\exceptions;
|
||||
|
||||
use catcher\exceptions\CatchException;
|
||||
|
||||
class ColumnException extends CatchException
|
||||
{
|
||||
protected $code = 20002;
|
||||
|
||||
}
|
23
catch/cms/exceptions/TableException.php
Normal file
23
catch/cms/exceptions/TableException.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catchAdmin\cms\exceptions;
|
||||
|
||||
use catcher\exceptions\CatchException;
|
||||
|
||||
class TableException extends CatchException
|
||||
{
|
||||
protected $code = 20001;
|
||||
}
|
91
catch/cms/model/Articles.php
Normal file
91
catch/cms/model/Articles.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\events\ArticlesEvent;
|
||||
|
||||
class Articles extends BaseModel
|
||||
{
|
||||
use ArticlesEvent;
|
||||
|
||||
// 表名
|
||||
public $name = 'cms_articles';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 文章标题
|
||||
'title',
|
||||
// 分类ID
|
||||
'category_id',
|
||||
'cover', // 封面
|
||||
// 多图集合
|
||||
'images',
|
||||
// 标签集合
|
||||
'tags',
|
||||
// 自定义URL
|
||||
'url',
|
||||
// 内容
|
||||
'content',
|
||||
// 关键字
|
||||
'keywords',
|
||||
// 描述
|
||||
'description',
|
||||
// 浏览量
|
||||
'pv',
|
||||
// 喜欢
|
||||
'likes',
|
||||
// 评论数
|
||||
'comments',
|
||||
// 1 置顶 2 非置顶
|
||||
'is_top',
|
||||
// 1 推荐 2 不推荐
|
||||
'is_recommend',
|
||||
// 1 展示 2 隐藏
|
||||
'status',
|
||||
'weight', // 权重
|
||||
// 1 允许 2 不允许
|
||||
'is_can_comment',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
const TOP = 1; // 置顶
|
||||
const UN_TOP = 2; // 不置顶
|
||||
|
||||
const RECOMMEND = 1; // 推荐
|
||||
const UN_RECOMMEND = 2; // 不推荐
|
||||
|
||||
const CAN_COMMENT = 1; // 评论允许
|
||||
const UN_CAN_COMMENT = 2; // 评论不允许
|
||||
|
||||
|
||||
/**
|
||||
* 文章标签
|
||||
*
|
||||
* @time 2021年05月17日
|
||||
* @return \think\model\relation\BelongsToMany
|
||||
*/
|
||||
public function tags(): \think\model\relation\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Tags::class, 'cms_article_relate_tags',
|
||||
'tag_id', 'article_id'
|
||||
);
|
||||
}
|
||||
}
|
40
catch/cms/model/Banners.php
Normal file
40
catch/cms/model/Banners.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
class Banners extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_banners';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// banner 标题
|
||||
'title',
|
||||
// banner 图片
|
||||
'banner_img',
|
||||
// 默认 0 代表首页展示
|
||||
'category_id',
|
||||
// 链接地址
|
||||
'link_to',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
}
|
27
catch/cms/model/BaseModel.php
Normal file
27
catch/cms/model/BaseModel.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catcher\base\CatchModel as Model;
|
||||
use catcher\Utils;
|
||||
|
||||
class BaseModel extends Model
|
||||
{
|
||||
public function __construct($data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
|
||||
$this->field = $this->getTableFields(Utils::tableWithPrefix($this->name));
|
||||
}
|
||||
}
|
103
catch/cms/model/Category.php
Normal file
103
catch/cms/model/Category.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\events\CategoryEvent;
|
||||
use catchAdmin\cms\model\scopes\CategoryScope;
|
||||
|
||||
class Category extends BaseModel
|
||||
{
|
||||
use CategoryEvent, CategoryScope;
|
||||
|
||||
// 表名
|
||||
public $name = 'cms_category';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 分类名称
|
||||
'name',
|
||||
// 父级ID
|
||||
'parent_id',
|
||||
// seo标题
|
||||
'title',
|
||||
// seo关键词
|
||||
'keywords',
|
||||
// 描述
|
||||
'description',
|
||||
// 自定义 URL
|
||||
'url',
|
||||
// 1 显示 2 隐藏
|
||||
'status',
|
||||
// 是否可以投稿
|
||||
'is_can_contribute',
|
||||
// 是否可以评论
|
||||
'is_can_comment',
|
||||
// 是否是单页面 1 是 2 否
|
||||
'type',
|
||||
// 权重
|
||||
'weight',
|
||||
// 1 是 2 否
|
||||
'is_link_out',
|
||||
// 链接外部地址
|
||||
'link_to',
|
||||
// 创建人
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
const LIST_TYPE = 1; // 列表
|
||||
const PAGE_TYPE = 2; // 单页
|
||||
const COVER_TYPE = 3; // 封面
|
||||
|
||||
const CAN_COMMENT = 1; // 可以评论
|
||||
const CAN_NOT_COMMENT = 2; // 不可以评论
|
||||
|
||||
const CAN_CONTRIBUTE = 1; // 可以投稿
|
||||
const CAN_NOT_CONTRIBUTE = 2; // 不可以投稿
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @time 2021年03月03日
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
return $this->quickSearch()
|
||||
->field(['*'])
|
||||
->catchOrder()
|
||||
->articlesCount()
|
||||
->select()->toTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在下级
|
||||
*
|
||||
* @time 2021年03月03日
|
||||
* @param int $id
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return array|\think\Model|null
|
||||
*/
|
||||
public function hasNextLevel($id = 0)
|
||||
{
|
||||
return $this->where('parent_id', $id ? :$this->getKey())->find();
|
||||
}
|
||||
}
|
46
catch/cms/model/Comments.php
Normal file
46
catch/cms/model/Comments.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
class Comments extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_comments';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 文章ID
|
||||
'article_id',
|
||||
// 内容
|
||||
'content',
|
||||
// 父ID
|
||||
'parent_id',
|
||||
// 评论者ID
|
||||
'user_id',
|
||||
// ip 地址
|
||||
'ip',
|
||||
// agent
|
||||
'user_agent',
|
||||
// 1 展示 2 隐藏
|
||||
'status',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
}
|
42
catch/cms/model/FormData.php
Normal file
42
catch/cms/model/FormData.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
class FormData extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_form_data';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 表单ID
|
||||
'form_id',
|
||||
// json字段
|
||||
'data',
|
||||
// 用户ID
|
||||
'user_id',
|
||||
// ip 地址
|
||||
'ip',
|
||||
// agent
|
||||
'user_agent',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
}
|
50
catch/cms/model/FormFields.php
Normal file
50
catch/cms/model/FormFields.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
class FormFields extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_form_fields';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// form id
|
||||
'form_id',
|
||||
// 字段 label
|
||||
'label',
|
||||
// 表单字段name
|
||||
'name',
|
||||
// 默认值
|
||||
'default_value',
|
||||
// 类型
|
||||
'type',
|
||||
// 验证规则
|
||||
'rule',
|
||||
// 字段长度
|
||||
'length',
|
||||
// 验证失败信息
|
||||
'failed_message',
|
||||
// 1 展示 2 隐藏
|
||||
'status',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
}
|
41
catch/cms/model/Forms.php
Normal file
41
catch/cms/model/Forms.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
class Forms extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_forms';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 表单名称
|
||||
'name',
|
||||
// 表单别名
|
||||
'alias',
|
||||
// 表单提交的 URL
|
||||
'submit_url',
|
||||
// 表单标题
|
||||
'title',
|
||||
// 关键词
|
||||
'keywords',
|
||||
// 描述
|
||||
'description',
|
||||
// 成功提示信息
|
||||
'success_message',
|
||||
// 失败提示信息
|
||||
'failed_message',
|
||||
// 成功后跳转
|
||||
'success_link_to',
|
||||
// 1 需要 2 不需要
|
||||
'is_login_to_submit',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
}
|
104
catch/cms/model/ModelAuxiliaryTable.php
Normal file
104
catch/cms/model/ModelAuxiliaryTable.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catcher\exceptions\FailedException;
|
||||
|
||||
class ModelAuxiliaryTable extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_model_auxiliary_table';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 模型ID
|
||||
'model_id',
|
||||
// 副表名称
|
||||
'table_name',
|
||||
// 默认使用
|
||||
'used',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
const USED = 1;
|
||||
const NOT_USE = 2;
|
||||
|
||||
|
||||
/**
|
||||
* 获取默认使用的副表
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $modelId
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return array|\think\Model|null
|
||||
*/
|
||||
public static function getDefaultUsed(int $modelId)
|
||||
{
|
||||
return self::where('model_id', $modelId)
|
||||
->where('used', self::USED)
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认使用
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function used(int $id)
|
||||
{
|
||||
$t = $this->findBy($id);
|
||||
|
||||
$t->used = self::USED;
|
||||
|
||||
if ($t->save()) {
|
||||
self::where('id', '<>', $id)
|
||||
->where('model_id', $t->model_id)
|
||||
->update([
|
||||
'used' => self::NOT_USE,
|
||||
]);
|
||||
|
||||
return $t;
|
||||
}
|
||||
|
||||
throw new FailedException('启用失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取使用
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $modelId
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return array|\think\Model|null
|
||||
*/
|
||||
public function getUsed($modelId)
|
||||
{
|
||||
return $this->where('model_id', $modelId)
|
||||
->where('used', self::USED)
|
||||
->find();
|
||||
|
||||
}
|
||||
}
|
112
catch/cms/model/ModelFields.php
Normal file
112
catch/cms/model/ModelFields.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\events\ModelFieldsEvent;
|
||||
use catchAdmin\cms\support\Helper;
|
||||
use catcher\Utils;
|
||||
|
||||
class ModelFields extends BaseModel
|
||||
{
|
||||
use ModelFieldsEvent;
|
||||
|
||||
// 表名
|
||||
public $name = 'cms_model_fields';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 字段中文名称
|
||||
'title',
|
||||
// 表单字段名称
|
||||
'name',
|
||||
// 类型
|
||||
'type',
|
||||
// 长度
|
||||
'length',
|
||||
// 默认值
|
||||
'default_value',
|
||||
'is_index', // 是否是索引
|
||||
'is_unique', // 是否是唯一
|
||||
'options', // 列表
|
||||
'rules', // 验证规则
|
||||
'pattern', // 字段正则
|
||||
// 模型ID
|
||||
'model_id',
|
||||
// 展示在列表 1 是 2 否
|
||||
'use_at_list',
|
||||
// 展示在详情 1 是 2 否
|
||||
'use_at_detail',
|
||||
// 用作是否搜索 1 是 2 否
|
||||
'use_at_search',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
'sort',
|
||||
'status',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
|
||||
const IS_UNIQUE = 1;
|
||||
const NOT_UNIQUE = 2;
|
||||
|
||||
const IS_INDEX = 1;
|
||||
const NOT_INDEX = 2;
|
||||
|
||||
/**
|
||||
* 获取模型的动态字段
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $modelId
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return \think\Collection
|
||||
*/
|
||||
public function getFieldsByModelId($modelId): \think\Collection
|
||||
{
|
||||
return $this->withoutField([
|
||||
'created_at', 'deleted_at', 'updated_at',
|
||||
])->where('model_id', $modelId)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取规则
|
||||
*
|
||||
* @time 2021年03月07日
|
||||
* @param $value
|
||||
* @return string[]
|
||||
*/
|
||||
public function getRulesAttr($value): array
|
||||
{
|
||||
return Utils::stringToArrayBy($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选项
|
||||
*
|
||||
* @time 2021年03月07日
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOptionsAttr($value)
|
||||
{
|
||||
// return Helper::getOptions($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
62
catch/cms/model/Models.php
Normal file
62
catch/cms/model/Models.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\events\ModelsEvent;
|
||||
|
||||
class Models extends BaseModel
|
||||
{
|
||||
use ModelsEvent;
|
||||
|
||||
// 表名
|
||||
public $name = 'cms_models';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 模型名称
|
||||
'name',
|
||||
// 模型别名
|
||||
'alias',
|
||||
// 模型关联的表名,数据来源
|
||||
'table_name',
|
||||
// 模型描述
|
||||
'description',
|
||||
// 列表字段
|
||||
'used_at_list',
|
||||
// 搜索字段
|
||||
'used_at_search',
|
||||
// 详情字段
|
||||
'used_at_detail',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* 模型字段
|
||||
*
|
||||
* @time 2021年05月11日
|
||||
* @return \think\model\relation\HasMany
|
||||
*/
|
||||
public function fields(): \think\model\relation\HasMany
|
||||
{
|
||||
return $this->hasMany(ModelFields::class, 'model_id', 'id');
|
||||
}
|
||||
}
|
56
catch/cms/model/SiteLinks.php
Normal file
56
catch/cms/model/SiteLinks.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
class SiteLinks extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_site_links';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 友情链接标题
|
||||
'title',
|
||||
// 跳转地址
|
||||
'link_to',
|
||||
// 权重
|
||||
'weight',
|
||||
// 1 展示 2 隐藏
|
||||
'is_show',
|
||||
// 网站图标
|
||||
'icon',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
/**
|
||||
* 标题搜索
|
||||
*
|
||||
* @time 2021年05月09日
|
||||
* @param $query
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchTitleAttr($query, $value, $data)
|
||||
{
|
||||
return $query->whereLike('title', $value);
|
||||
}
|
||||
}
|
46
catch/cms/model/Tags.php
Normal file
46
catch/cms/model/Tags.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
class Tags extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_tags';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 标签名称
|
||||
'name',
|
||||
// seo 标签
|
||||
'title',
|
||||
// 关键字
|
||||
'keywords',
|
||||
// 描述
|
||||
'description',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
|
||||
public function searchNameAttr($query, $value)
|
||||
{
|
||||
$query->whereLike('name', $value);
|
||||
}
|
||||
}
|
42
catch/cms/model/Users.php
Normal file
42
catch/cms/model/Users.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
class Users extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
public $name = 'cms_users';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 用户名
|
||||
'username',
|
||||
// 邮箱
|
||||
'email',
|
||||
// 手机号
|
||||
'mobile',
|
||||
// 头像
|
||||
'avatar',
|
||||
// 1 正常 2 禁用
|
||||
'status',
|
||||
// 密码
|
||||
'password',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
}
|
58
catch/cms/model/events/ArticlesEvent.php
Normal file
58
catch/cms/model/events/ArticlesEvent.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\events;
|
||||
|
||||
use catchAdmin\cms\model\Articles;
|
||||
use catchAdmin\cms\model\Tags;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\Utils;
|
||||
|
||||
trait ArticlesEvent
|
||||
{
|
||||
/**
|
||||
* 插入前
|
||||
*
|
||||
* @time 2021年05月21日
|
||||
* @param Articles $model
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeInsert(Articles $model)
|
||||
{
|
||||
$model->category_id = $model->category_id[0];
|
||||
|
||||
$model->images = implode(',', $model->images);
|
||||
|
||||
$model->tags = implode(',', $model->tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 插入后
|
||||
*
|
||||
* @time 2021年05月21日
|
||||
* @param Articles $model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return void
|
||||
*/
|
||||
public static function onAfterInsert(Articles $model)
|
||||
{
|
||||
$tags = Utils::stringToArrayBy($model->tags);
|
||||
|
||||
$tagModel = new Tags;
|
||||
$existTags = $tagModel->whereIn('name', $tags)->select()->toArray();
|
||||
$existTagsName = array_column($existTags, 'name');
|
||||
|
||||
$tagsIds = [];
|
||||
foreach ($tags as $tag) {
|
||||
if (! in_array($tag, $existTagsName)) {
|
||||
$tagsIds[] = $tagModel->createBy([
|
||||
'name' => $tag
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$model->tags()->attach(array_merge(array_column($existTags, 'id'), $tagsIds));
|
||||
}
|
||||
}
|
83
catch/cms/model/events/CategoryEvent.php
Normal file
83
catch/cms/model/events/CategoryEvent.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model\events;
|
||||
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\Utils;
|
||||
|
||||
trait CategoryEvent
|
||||
{
|
||||
/**
|
||||
* 插入前
|
||||
*
|
||||
* @time 2021年03月03日
|
||||
* @param \think\Model $category
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeInsert($category): void
|
||||
{
|
||||
$category->data(self::changeData($category->getData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*
|
||||
* @time 2021年03月03日
|
||||
* @param \think\Model $category
|
||||
* @return mixed|void
|
||||
*/
|
||||
public static function onBeforeUpdate($category)
|
||||
{
|
||||
// $category->data(self::changeData($category->getData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*
|
||||
* @time 2021年03月03日
|
||||
* @param $category
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeDelete($category)
|
||||
{
|
||||
if ($category->hasNextLevel()) {
|
||||
throw new FailedException('存在下级栏目, 无法删除');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Data
|
||||
*
|
||||
* @time 2021年03月03日
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function changeData($data)
|
||||
{
|
||||
/**
|
||||
if (isset($data['parent_id'])) {
|
||||
$parentId = $data['parent_id'];
|
||||
|
||||
if (!is_array($parentId)) {
|
||||
// $parentId = Utils::dealWithFormArrayString($parentId);
|
||||
}
|
||||
|
||||
$parentId = count($parentId) ? array_pop($parentId) : 0;
|
||||
|
||||
$data['parent_id'] = $parentId;
|
||||
}
|
||||
|
||||
return $data;*/
|
||||
}
|
||||
}
|
167
catch/cms/model/events/ModelFieldsEvent.php
Normal file
167
catch/cms/model/events/ModelFieldsEvent.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\events;
|
||||
|
||||
use catchAdmin\cms\exceptions\ColumnException;
|
||||
use catchAdmin\cms\model\Models;
|
||||
use catchAdmin\cms\support\Table;
|
||||
use catchAdmin\cms\support\TableColumn;
|
||||
use catchAdmin\cms\tables\Model;
|
||||
use catcher\exceptions\FailedException;
|
||||
|
||||
trait ModelFieldsEvent
|
||||
{
|
||||
protected static $modelTableName = null;
|
||||
|
||||
/**
|
||||
* 插入前
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $modelFields
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeInsert($modelFields)
|
||||
{
|
||||
$tableName = self::getModelTableName($modelFields->getData('model_id'));
|
||||
|
||||
if ($tableName && Table::hasColumn($tableName, $modelFields->getData('name'))) {
|
||||
throw new ColumnException(sprintf('Column [%s] already exist in Table [%s]', $modelFields->getData('name'), $tableName));
|
||||
}
|
||||
|
||||
$modelFields->data(self::changeData($modelFields->getData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新后
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $modelFields
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeUpdate($modelFields)
|
||||
{
|
||||
$modelFields->data(self::changeData($modelFields->getData(), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入之后
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $modelFields
|
||||
* @return void
|
||||
*/
|
||||
public static function onAfterInsert($modelFields)
|
||||
{
|
||||
if ($modelFields->getKey()) {
|
||||
try {
|
||||
$tableName = self::getModelTableName($modelFields->getData('model_id'));
|
||||
|
||||
if ($tableName) {
|
||||
Table::addColumn($tableName, (new TableColumn($modelFields->getData()))->get());
|
||||
}
|
||||
|
||||
self::addIndexForField($tableName, $modelFields->getData('name'), $modelFields->getData('is_index'));
|
||||
} catch (\Exception $e) {
|
||||
$modelFields->delete();
|
||||
throw new FailedException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新之后
|
||||
*
|
||||
* @time 2021年04月30日
|
||||
* @param \think\Model $modelFields
|
||||
* @return void
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
*/
|
||||
public static function onAfterUpdate(\think\Model $modelFields)
|
||||
{
|
||||
$field = $modelFields->find($modelFields->getWhere());
|
||||
|
||||
self::addIndexForField(self::getModelTableName($field['model_id']), $field['name'], $field['is_index']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加索引
|
||||
*
|
||||
* @time 2021年04月30日
|
||||
* @param $table
|
||||
* @param string $column
|
||||
* @param $isIndex
|
||||
* @return void
|
||||
*/
|
||||
protected static function addIndexForField($table, string $column, $isIndex)
|
||||
{
|
||||
if (! Table::isIndex($table, $column) && $isIndex == self::IS_INDEX) {
|
||||
Table::addIndex($table, $column);
|
||||
}
|
||||
|
||||
if (Table::isIndex($table, $column) && $isIndex == self::NOT_INDEX) {
|
||||
Table::dropIndex($table, $column);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字段
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $modelFields
|
||||
* @return void
|
||||
*/
|
||||
public static function onAfterDelete($modelFields)
|
||||
{
|
||||
$tableName = self::getModelTableName($modelFields->getData('model_id'));
|
||||
|
||||
$columnName = $modelFields->getData('name');
|
||||
|
||||
if (Table::hasColumn($tableName, $columnName)) {
|
||||
Table::dropColumn($tableName, $columnName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $data
|
||||
* @param bool $update
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function changeData($data, $update = false)
|
||||
{
|
||||
if (isset($data['type']) && !in_array($data['type'], ['string', 'int'])) {
|
||||
$data['length'] = 0;
|
||||
}
|
||||
|
||||
// 更新不会校验
|
||||
if (!$update) {
|
||||
if (Table::hasColumn(self::getModelTableName($data['model_id']), $data['name'])) {
|
||||
throw new ColumnException(sprintf('Column [%s] already exist in Table [%s]', $data['name'], self::getModelTableName($data['model_id'])));
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型关联的表
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param $modelId
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected static function getModelTableName($modelId)
|
||||
{
|
||||
if (self::$modelTableName) {
|
||||
return self::$modelTableName;
|
||||
}
|
||||
|
||||
self::$modelTableName = Models::where('id', $modelId)->value('table_name');
|
||||
|
||||
return self::$modelTableName;
|
||||
}
|
||||
}
|
52
catch/cms/model/events/ModelsEvent.php
Normal file
52
catch/cms/model/events/ModelsEvent.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model\events;
|
||||
|
||||
use catchAdmin\cms\support\Table;
|
||||
use catcher\exceptions\FailedException;
|
||||
|
||||
trait ModelsEvent
|
||||
{
|
||||
/**
|
||||
* 插入前
|
||||
*
|
||||
* @time 2021年03月03日
|
||||
* @param \think\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeInsert($model): void
|
||||
{
|
||||
if (!Table::exist($model->getData('table_name'))) {
|
||||
throw new FailedException('模型关联的表【' .$model->getData('table_name'). '】不存在');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*
|
||||
* @time 2021年03月03日
|
||||
* @param \think\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeUpdate($model): void
|
||||
{
|
||||
$data = $model->getData();
|
||||
|
||||
$tableName = $data['table_name'] ?? null;
|
||||
|
||||
if ($tableName && !Table::exist($model->getData('table_name'))) {
|
||||
throw new FailedException('模型关联的表【' .$model->getData('table_name'). '】不存在');
|
||||
}
|
||||
}
|
||||
}
|
36
catch/cms/model/scopes/CategoryScope.php
Normal file
36
catch/cms/model/scopes/CategoryScope.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\model\scopes;
|
||||
|
||||
use catchAdmin\cms\model\Articles;
|
||||
use think\facade\Db;
|
||||
|
||||
trait CategoryScope
|
||||
{
|
||||
/**
|
||||
* 文章数量
|
||||
*
|
||||
* @time 2020年06月17日
|
||||
* @param $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeArticlesCount($query)
|
||||
{
|
||||
return $query->addSelectSub(function () {
|
||||
$article = app(Articles::class);
|
||||
return $article->field(Db::raw('count(*)'))
|
||||
->whereColumn($this->aliasField('id'), $article->aliasField('category_id'));
|
||||
}, 'articles');
|
||||
}
|
||||
}
|
18
catch/cms/module.json
Normal file
18
catch/cms/module.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "内容管理",
|
||||
"alias": "cms",
|
||||
"description": "cms 模块管理",
|
||||
"version": "1.0.0",
|
||||
"keywords": [
|
||||
"cms",
|
||||
"admin"
|
||||
],
|
||||
"order": 0,
|
||||
"services": [
|
||||
"\\catchAdmin\\cms\\CmsService"
|
||||
],
|
||||
"aliases": [],
|
||||
"files": [],
|
||||
"requires": [],
|
||||
"enable": true
|
||||
}
|
49
catch/cms/route.php
Normal file
49
catch/cms/route.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
/* @var $router \think\Route */
|
||||
$router->group('cms', function () use ($router){
|
||||
// users路由
|
||||
$router->resource('users', '\catchAdmin\cms\controller\Users');
|
||||
// category路由
|
||||
$router->resource('category', '\catchAdmin\cms\controller\Category');
|
||||
$router->post('import/category', '\catchAdmin\cms\controller\Category@import');
|
||||
|
||||
// articles路由
|
||||
$router->resource('articles', '\catchAdmin\cms\controller\Articles');
|
||||
// tags路由
|
||||
$router->resource('tags', '\catchAdmin\cms\controller\Tags');
|
||||
// comments路由
|
||||
$router->resource('comments', '\catchAdmin\cms\controller\Comments');
|
||||
// banners路由
|
||||
$router->resource('banners', '\catchAdmin\cms\controller\Banners');
|
||||
// siteLInks路由
|
||||
$router->resource('site/links', '\catchAdmin\cms\controller\SiteLinks');
|
||||
// forms路由
|
||||
$router->resource('forms', '\catchAdmin\cms\controller\Forms');
|
||||
// formFields路由
|
||||
$router->resource('formFields', '\catchAdmin\cms\controller\FormFields');
|
||||
// formData路由
|
||||
$router->resource('formData', '\catchAdmin\cms\controller\FormData');
|
||||
// model路由
|
||||
$router->resource('model', '\catchAdmin\cms\controller\Models');
|
||||
// modelFields路由
|
||||
$router->resource('modelFields', '\catchAdmin\cms\controller\ModelFields');
|
||||
// form create
|
||||
$router->get('form/<name>/create', '\catchAdmin\cms\controller\Form@create');
|
||||
// 上传
|
||||
$router->group('upload', function () use ($router){
|
||||
$router->post('image', '\catchAdmin\cms\controller\Upload@image');
|
||||
$router->post('file', '\catchAdmin\cms\controller\Upload@file');
|
||||
})->middleware(\catcher\middlewares\JsonResponseMiddleware::class);
|
||||
})->middleware('auth');
|
113
catch/cms/support/AuxiliaryTable.php
Normal file
113
catch/cms/support/AuxiliaryTable.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\support;
|
||||
|
||||
use catchAdmin\cms\model\ModelAuxiliaryTable;
|
||||
use catchAdmin\cms\model\Models;
|
||||
use catcher\exceptions\FailedException;
|
||||
|
||||
class AuxiliaryTable
|
||||
{
|
||||
protected $suffixes = [
|
||||
'first', 'second', 'third', 'fourth', 'fifth',
|
||||
'sixth', 'seventh', 'eighth', 'ninth', 'tenth'
|
||||
];
|
||||
|
||||
protected $mainTableId = 'main_id';
|
||||
|
||||
protected $auxiliaryTableName = null;
|
||||
|
||||
/**
|
||||
* 创建副表
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param int $modelId
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return string
|
||||
*/
|
||||
public function create(int $modelId): string
|
||||
{
|
||||
try {
|
||||
// 查询主表名称
|
||||
$tableName = Models::where('id', $modelId)->value('table_name');
|
||||
// 查询副表
|
||||
$auxiliaryTables = ModelAuxiliaryTable::where('model_id', $modelId)->select();
|
||||
// 目前最多允许创建 10 个副表
|
||||
if ($auxiliaryTables->count() > count($this->suffixes)) {
|
||||
throw new FailedException('最多只允许创建 ' . count($this->suffixes) . ' 个副表');
|
||||
}
|
||||
$defaultUsed = ModelAuxiliaryTable::NOT_USE;
|
||||
// 如果模型还没有关联的副表
|
||||
// 默认创建副表
|
||||
if (!$auxiliaryTables->count()) {
|
||||
$defaultUsed = ModelAuxiliaryTable::USED;
|
||||
|
||||
$this->auxiliaryTableName = $this->getName($tableName, array_shift($this->suffixes));
|
||||
} else {
|
||||
$existSuffixes = [];
|
||||
|
||||
$auxiliaryTables->each(function ($table) use (&$existSuffixes) {
|
||||
$name = explode('_', $table->name);
|
||||
|
||||
$existSuffixes[] = array_pop($name);
|
||||
});
|
||||
|
||||
$notUsed = array_diff($this->suffixes, $existSuffixes);
|
||||
|
||||
$this->auxiliaryTableName = $this->getName($tableName, array_shift($notUsed));
|
||||
}
|
||||
|
||||
if (Table::create($this->auxiliaryTableName)) {
|
||||
Table::addColumn($this->auxiliaryTableName, (new TableColumn([
|
||||
'type' => 'int',
|
||||
'name' => $this->mainTableId,
|
||||
'length' => 10,
|
||||
'title' => '主表数据的ID',
|
||||
'default_value' => 0,
|
||||
]))->get());
|
||||
}
|
||||
|
||||
app(ModelAuxiliaryTable::class)->storeBy([
|
||||
'model_id' => $modelId,
|
||||
'table_name' => $this->auxiliaryTableName,
|
||||
'used' => $defaultUsed,
|
||||
]);
|
||||
|
||||
return $this->auxiliaryTableName;
|
||||
} catch (\Exception $exception) {
|
||||
throw new FailedException($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认使用的副表
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param int $modelId
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUsedAuxiliaryTable(int $modelId)
|
||||
{
|
||||
$auxiliaryTable = app(ModelAuxiliaryTable::class)->getUsed($modelId);
|
||||
|
||||
return $auxiliaryTable ? $auxiliaryTable->table_name : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取副表名称
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $mainTable
|
||||
* @param string $suffix
|
||||
* @return string
|
||||
*/
|
||||
protected function getName(string $mainTable, string $suffix): string
|
||||
{
|
||||
return $mainTable . '_relate_' . $suffix;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
384
catch/cms/support/DynamicFormFields.php
Normal file
384
catch/cms/support/DynamicFormFields.php
Normal file
@ -0,0 +1,384 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\support;
|
||||
|
||||
use catchAdmin\cms\model\Models;
|
||||
use catcher\library\form\Form;
|
||||
use catchAdmin\cms\model\ModelFields;
|
||||
|
||||
class DynamicFormFields
|
||||
{
|
||||
protected $defaultRules = [
|
||||
'alpha' => ['^[A-Za-z]+$', '必须为纯字母'],
|
||||
'alphaNum' => ['^[A-Za-z0-9]+$', '必须为字母和数字'],
|
||||
'alphaDash' => ['^[A-Za-z0-9\-\_]+$', '必须为字母和数字,下划线_及破折号-'],
|
||||
'mobile' => ['^1[3-9]\d{9}$','请输入正确的手机号格式'],
|
||||
'idCard' => ['(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)','身份证输入格式不正确'],
|
||||
'zip' => ['\d{6}','请输入有效的邮政编码'],
|
||||
'ip' => ['((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))', '请输入正确的 IP 地址'],
|
||||
'password' => ['^[a-zA-Z]\w{5,17}$', '以字母开头,长度在6~18之间,只能包含字母、数字和下划线'],
|
||||
'strong_password' => ['^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$', '必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间'],
|
||||
'landLine' => ['\d{3}-\d{8}|\d{4}-\d{7}', '请输入正确的座机格式'],
|
||||
'chinese_character' => ['^[\u4e00-\u9fa5]{0,}$', '必须为纯汉字']
|
||||
];
|
||||
|
||||
/**
|
||||
* build form field
|
||||
*
|
||||
* @time 2021年03月10日
|
||||
* @param $modelId
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return array
|
||||
*/
|
||||
public function build($tableName): array
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
ModelFields::whereIn('model_id', Models::where('table_name', $tableName)->column('id'))
|
||||
->where('status', ModelFields::ENABLE)
|
||||
->select()
|
||||
->each(function ($field) use (&$fields){
|
||||
$formField = $this->{$field['type']}($field);
|
||||
|
||||
$formField = $this->getOptions($formField, $field['options'] ?? '');
|
||||
|
||||
$formField = $this->appendValidates($formField, $field['rules']);
|
||||
|
||||
$formField = $this->pattern($formField, $field['pattern']);
|
||||
|
||||
$fields[] = $formField;
|
||||
});
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Input
|
||||
*/
|
||||
public function string($field): \FormBuilder\UI\Elm\Components\Input
|
||||
{
|
||||
return Form::input($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 整型
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\InputNumber
|
||||
*/
|
||||
public function int($field): \FormBuilder\UI\Elm\Components\InputNumber
|
||||
{
|
||||
return Form::number($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 浮点
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\InputNumber
|
||||
*/
|
||||
public function float($field): \FormBuilder\UI\Elm\Components\InputNumber
|
||||
{
|
||||
return Form::number($field['name'], $field['tittle']);
|
||||
}
|
||||
|
||||
/**
|
||||
* textarea
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Input
|
||||
*/
|
||||
public function textarea($field): \FormBuilder\UI\Elm\Components\Input
|
||||
{
|
||||
return Form::textarea($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑器
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return mixed
|
||||
*/
|
||||
public function text($field)
|
||||
{
|
||||
return Form::editor($field['name'], $field['title'])->language();
|
||||
}
|
||||
|
||||
/**
|
||||
* longtext
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return mixed
|
||||
*/
|
||||
public function longtext($field)
|
||||
{
|
||||
return Form::editor($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期类型
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\DatePicker
|
||||
*/
|
||||
public function date($field): \FormBuilder\UI\Elm\Components\DatePicker
|
||||
{
|
||||
return Form::date($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期时间
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\DatePicker
|
||||
*/
|
||||
public function datetime($field): \FormBuilder\UI\Elm\Components\DatePicker
|
||||
{
|
||||
return Form::dateTime($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Upload
|
||||
*/
|
||||
public function image($field): \FormBuilder\UI\Elm\Components\Upload
|
||||
{
|
||||
return Form::image($field['title'], $field['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多图
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Upload
|
||||
*/
|
||||
public function images($field): \FormBuilder\UI\Elm\Components\Upload
|
||||
{
|
||||
return Form::images($field['title'], $field['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return mixed
|
||||
*/
|
||||
public function file($field)
|
||||
{
|
||||
return Form::file($field['title'], $field['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传多个文件
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return mixed
|
||||
*/
|
||||
public function files($field)
|
||||
{
|
||||
return Form::files($field['title'], $field['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉框
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Select
|
||||
*/
|
||||
public function select($field): \FormBuilder\UI\Elm\Components\Select
|
||||
{
|
||||
return Form::select($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* checkbox
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Select
|
||||
*/
|
||||
public function checkbox($field): \FormBuilder\UI\Elm\Components\Select
|
||||
{
|
||||
return Form::select($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* radio
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Select
|
||||
*/
|
||||
public function radio($field): \FormBuilder\UI\Elm\Components\Select
|
||||
{
|
||||
return Form::select($field['name'], $field['title'])->options($this->getOptions($field['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Input
|
||||
*/
|
||||
public function password($field): \FormBuilder\UI\Elm\Components\Input
|
||||
{
|
||||
return Form::password($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 颜色
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\ColorPicker
|
||||
*/
|
||||
public function color($field): \FormBuilder\UI\Elm\Components\ColorPicker
|
||||
{
|
||||
return Form::color($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 省市选择
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Cascader
|
||||
*/
|
||||
public function city($field): \FormBuilder\UI\Elm\Components\Cascader
|
||||
{
|
||||
return Form::city($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 省市区选择
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $field
|
||||
* @return \FormBuilder\UI\Elm\Components\Cascader
|
||||
*/
|
||||
public function area($field): \FormBuilder\UI\Elm\Components\Cascader
|
||||
{
|
||||
return Form::cityArea($field['name'], $field['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* options
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $formField
|
||||
* @param $options
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getOptions($formField, $options)
|
||||
{
|
||||
if (!$options) {
|
||||
return $formField;
|
||||
}
|
||||
|
||||
return $formField->options(Helper::getOptions($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $formField
|
||||
* @param $validates
|
||||
* @return mixed
|
||||
*/
|
||||
protected function appendValidates($formField, $validates)
|
||||
{
|
||||
if (count($validates)) {
|
||||
foreach ($validates as $validate) {
|
||||
if ($validate === 'require') {
|
||||
$formField = $formField->required();
|
||||
}
|
||||
|
||||
switch ($validate) {
|
||||
case 'number':
|
||||
$formField->appendValidate(Form::validateNum()->message('请输入数字'));
|
||||
break;
|
||||
case 'integer':
|
||||
$formField->appendValidate(Form::validateInt()->message('请输入整型数字'));
|
||||
break;
|
||||
case 'float':
|
||||
$formField->appendValidate(Form::validateFloat()->message('请输入浮点型数字'));
|
||||
break;
|
||||
case in_array($validate, ['email', 'url', 'date']):
|
||||
$message = [
|
||||
'email' => '邮箱格式不正确',
|
||||
'url' => 'url 地址格式不正确',
|
||||
'date' => '日期格式不正确'
|
||||
];
|
||||
$method = 'validate' . ucfirst($validate);
|
||||
$formField->appendValidate(Form::{$method}()->message($message[$validate]));
|
||||
break;
|
||||
default:
|
||||
if (isset($this->defaultRules[$validate])) {
|
||||
list($pattern, $message) = $this->defaultRules[$validate];
|
||||
|
||||
$formField->appendValidate(
|
||||
Form::validateStr()->pattern($pattern)->message($message)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $formField;
|
||||
}
|
||||
|
||||
/**
|
||||
* 正则
|
||||
*
|
||||
* @time 2021年03月10日
|
||||
* @param $formField
|
||||
* @param $pattern
|
||||
* @return mixed
|
||||
*/
|
||||
protected function pattern($formField, $pattern)
|
||||
{
|
||||
if ($pattern) {
|
||||
list($pattern, $message) = explode('|', $pattern);
|
||||
|
||||
return $formField->appendValidate(
|
||||
Form::validateStr()->pattern($pattern)->message($message)
|
||||
);
|
||||
}
|
||||
|
||||
return $formField;
|
||||
}
|
||||
}
|
68
catch/cms/support/Helper.php
Normal file
68
catch/cms/support/Helper.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\support;
|
||||
|
||||
use catcher\Utils;
|
||||
|
||||
class Helper
|
||||
{
|
||||
/**
|
||||
* 获取数组格式 options
|
||||
*
|
||||
* @time 2021年03月09日
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getOptions(string $value)
|
||||
{
|
||||
$options = [];
|
||||
|
||||
if (!$value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
foreach (Utils::stringToArrayBy($value, PHP_EOL) as $option) {
|
||||
if ($option) {
|
||||
$option = explode('|', $option);
|
||||
|
||||
$options[] = [
|
||||
'value' => $option[0],
|
||||
'label' => $option[1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理表单数组字符
|
||||
*
|
||||
* "[1, 2, 3, 4, 5]"
|
||||
*
|
||||
* @time 2021年03月07日
|
||||
* @param $arrayString
|
||||
* @return array|string[]
|
||||
*/
|
||||
public static function dealWithFormArrayString($arrayString): array
|
||||
{
|
||||
$array = trim(trim($arrayString, '['), ']');
|
||||
|
||||
if (!$array) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Utils::stringToArrayBy($array);
|
||||
}
|
||||
}
|
52
catch/cms/support/Table.php
Normal file
52
catch/cms/support/Table.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\support;
|
||||
|
||||
use catcher\generate\support\Table as _Table;
|
||||
|
||||
/**
|
||||
* @method static create(string $primaryKey, string $engine, string $comment)
|
||||
* @method static exist($tableName)
|
||||
* @method static drop($tableName)
|
||||
* @method static addColumn($tableName, $column)
|
||||
* @method static hasColumn($tableName, string $column)
|
||||
* @method static columns($tableName)
|
||||
* @method static dropColumn($tableName, string $column)
|
||||
* @method static addUniqueIndex($tableName, string $column)
|
||||
* @method static addIndex($tableName, string $column)
|
||||
* @method static addFulltextIndex($tableName, string $column)
|
||||
* @method static dropIndex($tableName, string $column)
|
||||
* @method static isIndex($tableName, string $column)
|
||||
*
|
||||
* @time 2021年04月30日
|
||||
*/
|
||||
class Table
|
||||
{
|
||||
/**
|
||||
* 静态访问
|
||||
*
|
||||
* @time 2021年04月30日
|
||||
* @param $method
|
||||
* @param $params
|
||||
* @return false|mixed
|
||||
*/
|
||||
public static function __callStatic($method, $params)
|
||||
{
|
||||
$table = new _Table($params[0]);
|
||||
|
||||
unset($params[0]);
|
||||
|
||||
return call_user_func_array([$table, $method], $params);
|
||||
}
|
||||
}
|
321
catch/cms/support/TableColumn.php
Normal file
321
catch/cms/support/TableColumn.php
Normal file
@ -0,0 +1,321 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\support;
|
||||
|
||||
use catchAdmin\cms\model\ModelFields;
|
||||
use catchAdmin\permissions\model\search\DepartmentSearch;
|
||||
use think\migration\db\Column;
|
||||
|
||||
class TableColumn
|
||||
{
|
||||
/**
|
||||
* ['value' => 'string', 'label' => '字符串'],
|
||||
['value' => 'int', 'label' => '整数'],
|
||||
['value' => 'float', 'label' => '小数'],
|
||||
['value' => 'textarea', 'label' => 'textarea文本'],
|
||||
['value' => 'text', 'label' => '编辑器(建议)'],
|
||||
['value' => 'longtext', 'label' => '编辑器(支持超大文本)'],
|
||||
['value' => 'date', 'label' => '日期型'],
|
||||
['value' => 'datetime', 'label' => '日期时间型'],
|
||||
['value' => 'image', 'label' => '图片上传'],
|
||||
['value' => 'images', 'label' => '多图上传'],
|
||||
['value' => 'file', 'label' => '文件上传'],
|
||||
['value' => 'files', 'label' => '多文件上传'],
|
||||
['value' => 'select', 'label' => '列表'],
|
||||
['value' => 'checkbox', 'label' => '复选框'],
|
||||
['value' => 'password', 'label' => '密码框'],
|
||||
['value' => 'color', 'label' => '颜色选项'],
|
||||
['value' => 'radio', 'label' => '单选'],
|
||||
['value' => 'city', 'label' => '省市二级级联动'],
|
||||
['value' => 'area', 'label' => '省市区三级联动'],
|
||||
*/
|
||||
|
||||
protected $column;
|
||||
|
||||
/**
|
||||
* TableColumn constructor.
|
||||
* @param array $field
|
||||
*/
|
||||
public function __construct(array $field)
|
||||
{
|
||||
/* $column \think\migration\db\Column */
|
||||
$length = $field['length'] ?? 0;
|
||||
|
||||
$column = $this->{$field['type']}($field['name'], (int)$length);
|
||||
|
||||
if ($field['default_value']) {
|
||||
$column->setDefault($field['default_value'] ?: '');
|
||||
}
|
||||
|
||||
$column->setComment($field['title'] ? : '');
|
||||
|
||||
if (isset($field['is_unique']) && $field['is_unique'] == ModelFields::IS_UNIQUE) {
|
||||
$column->setUnique();
|
||||
}
|
||||
|
||||
if (isset($field['is_index']) && $field['is_index'] == ModelFields::IS_INDEX) {
|
||||
$column->be_index = true;
|
||||
}
|
||||
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取结果
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return $this->column;
|
||||
}
|
||||
|
||||
/**
|
||||
* string 类型
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function string(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* int 类型
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function int(string $name, int $length): Column
|
||||
{
|
||||
return Column::integer($name)->setLimit($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 浮点数
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function float(string $name, int $length): Column
|
||||
{
|
||||
return Column::float($name)->setLimit($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* varchar 类型
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function textarea(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(2000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通文本
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function text(string $name, int $length): Column
|
||||
{
|
||||
return Column::text($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 超大文本
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function longtext(string $name, int $length): Column
|
||||
{
|
||||
return Column::longText($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间类型
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function date(string $name, int $length): Column
|
||||
{
|
||||
return Column::date($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期时间
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function datetime(string $name, int $length): Column
|
||||
{
|
||||
return Column::dateTime($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片存储
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function image(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(255);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片集合存储
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function images(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件存储
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function file(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(255);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件集合
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function files(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表类型
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function select(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* checkbox 类型
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function checkbox(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function password(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(255);
|
||||
}
|
||||
|
||||
/**
|
||||
* 颜色
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function color(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(50);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单选
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function radio(string $name, int $length): Column
|
||||
{
|
||||
return Column::string($name)->setLimit(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* 省市
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function city(string $name, int $length): Column
|
||||
{
|
||||
// province_name/city_name
|
||||
return Column::string($name)->setLimit(255);
|
||||
}
|
||||
|
||||
/**
|
||||
* 省市区
|
||||
*
|
||||
* @time 2021年03月08日
|
||||
* @param string $name
|
||||
* @param int $length
|
||||
* @return Column
|
||||
*/
|
||||
public function area(string $name, int $length): Column
|
||||
{
|
||||
// province_name/city_name/district_name
|
||||
return Column::string($name)->setLimit(255);
|
||||
}
|
||||
}
|
47
catch/cms/tables/Articles.php
Normal file
47
catch/cms/tables/Articles.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
use catcher\CatchTable;
|
||||
use catchAdmin\cms\tables\forms\Factory;
|
||||
use catcher\library\table\Actions;
|
||||
use catcher\library\table\HeaderItem;
|
||||
|
||||
class Articles extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return $this->getTable('articles')
|
||||
->header([
|
||||
HeaderItem::label('编号')->prop('id'),
|
||||
|
||||
HeaderItem::label('栏目')->prop('category'),
|
||||
|
||||
HeaderItem::label('标题')->prop('title'),
|
||||
|
||||
HeaderItem::label('权重')->prop('weight')->withEditNumberComponent(),
|
||||
|
||||
HeaderItem::label('状态')->prop('status')->withSwitchComponent(),
|
||||
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
|
||||
HeaderItem::label('操作')->actions([
|
||||
Actions::update()->to('/cms/articles/detail'),
|
||||
Actions::delete()
|
||||
])
|
||||
])
|
||||
->withBind()
|
||||
->withApiRoute('cms/articles')
|
||||
->withActions([
|
||||
Actions::create()->to('/cms/articles/detail/')
|
||||
])
|
||||
->render();
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return Factory::create('articles');
|
||||
}
|
||||
|
||||
}
|
59
catch/cms/tables/Category.php
Normal file
59
catch/cms/tables/Category.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
use catchAdmin\cms\tables\forms\Factory;
|
||||
use catcher\CatchTable;
|
||||
use catcher\library\table\Actions;
|
||||
use catcher\library\table\Excel;
|
||||
use catcher\library\table\HeaderItem;
|
||||
use catcher\library\table\Search;
|
||||
|
||||
class Category extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return $this->getTable('category')
|
||||
->header([
|
||||
HeaderItem::label('分类名称')->prop('name'),
|
||||
HeaderItem::label('自定义链接')->prop('url')->withCopyComponent(),
|
||||
HeaderItem::label('栏目类型')->prop('type')->withSelectComponent([
|
||||
['value' => 1, 'label' => '列表模式'],
|
||||
['value' => 2, 'label' => '单页模式'],
|
||||
['value' => 3, 'label' => '封面模式'],
|
||||
]),
|
||||
HeaderItem::label('投稿')->prop('is_can_contribute')->withSwitchComponent([
|
||||
['value' => 1, 'label' => '是'],
|
||||
['value' => 2, 'label' => '否'],
|
||||
]),
|
||||
HeaderItem::label('评论')->prop('is_can_comment')->withSwitchComponent(),
|
||||
HeaderItem::label('状态')->prop('status')->withSwitchComponent(),
|
||||
HeaderItem::label('权重')->prop('weight')->withEditNumberComponent(),
|
||||
// HeaderItem::label('创建时间')->prop('created_at'),
|
||||
HeaderItem::label('操作')->actions([
|
||||
Actions::update(),
|
||||
Actions::delete()
|
||||
])->width(230)
|
||||
])
|
||||
->withActions([
|
||||
Actions::create()
|
||||
])
|
||||
->withSearch([
|
||||
Search::label('分类名称')->name('请输入分类名称'),
|
||||
Search::label('状态')->status(),
|
||||
])
|
||||
->forceUpdate()
|
||||
->withApiRoute('cms/category')
|
||||
->toTreeTable()
|
||||
->withDialogWidth('40%')
|
||||
->render();
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return Factory::create('category');
|
||||
}
|
||||
|
||||
|
||||
}
|
50
catch/cms/tables/Fields.php
Normal file
50
catch/cms/tables/Fields.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
use catchAdmin\cms\tables\forms\Factory;
|
||||
use catcher\CatchTable;
|
||||
use catcher\library\table\Actions;
|
||||
use catcher\library\table\HeaderItem;
|
||||
use catcher\library\table\Search;
|
||||
|
||||
class Fields extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
return $this->getTable('fields')
|
||||
->header([
|
||||
HeaderItem::label('编号')->prop('id')->width(80),
|
||||
HeaderItem::label('字段名称')->prop('name'),
|
||||
HeaderItem::label('label名称')->prop('title'),
|
||||
HeaderItem::label('类型')->prop('type'),
|
||||
// HeaderItem::label('列表显示')->prop('use_at_list')->withSwitchComponent( ),
|
||||
// HeaderItem::label('搜索')->prop('use_at_search')->withSwitchComponent(),
|
||||
// HeaderItem::label('详情')->prop('use_at_detail')->withSwitchComponent(),
|
||||
HeaderItem::label('状态')->prop('status')->withSwitchComponent( ),
|
||||
HeaderItem::label('设置索引')->prop('is_index')->withSwitchComponent( ),
|
||||
|
||||
HeaderItem::label('操作')->width(260)->isBubble()->actions([
|
||||
Actions::update(),
|
||||
Actions::delete()
|
||||
]),
|
||||
])
|
||||
->withActions([
|
||||
Actions::create(),
|
||||
])
|
||||
->withSearch([
|
||||
Search::hidden('model_id', '')
|
||||
])
|
||||
->withHiddenPaginate()
|
||||
->withDialogWidth('40%')
|
||||
->withDefaultQueryParams(['model_id'])
|
||||
->withBind()
|
||||
->withApiRoute('cms/modelFields')
|
||||
->render();
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return Factory::create('field');
|
||||
}
|
||||
}
|
48
catch/cms/tables/Model.php
Normal file
48
catch/cms/tables/Model.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
use catchAdmin\cms\tables\forms\Factory;
|
||||
use catcher\CatchTable;
|
||||
use catcher\library\table\Actions;
|
||||
use catcher\library\table\HeaderItem;
|
||||
use catcher\library\table\Search;
|
||||
|
||||
class Model extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return $this->getTable('model')
|
||||
->header([
|
||||
HeaderItem::label('编号')->prop('id'),
|
||||
HeaderItem::label('模型名称')->prop('name'),
|
||||
HeaderItem::label('模型别名')->prop('alias'),
|
||||
HeaderItem::label('模型关联表')->prop('table_name'),
|
||||
HeaderItem::label('模型信息')->prop('')->width(200)->component('operate'),
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
HeaderItem::label('操作')->actions([
|
||||
Actions::update(),
|
||||
Actions::delete()
|
||||
])->width(230)
|
||||
])
|
||||
->withActions([
|
||||
Actions::create()
|
||||
])
|
||||
->withSearch([
|
||||
Search::label('模型名称')->name('请填写模型名称'),
|
||||
])
|
||||
->forceUpdate()
|
||||
->withApiRoute('cms/model')
|
||||
->toTreeTable()
|
||||
->withDialogWidth('40%')
|
||||
->render();
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return Factory::create('model');
|
||||
}
|
||||
|
||||
|
||||
}
|
21
catch/cms/tables/ModelUsedFields.php
Normal file
21
catch/cms/tables/ModelUsedFields.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
use catcher\CatchTable;
|
||||
use catchAdmin\cms\tables\forms\Factory;
|
||||
|
||||
class ModelUsedFields extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return Factory::create('ModelUsedFields');
|
||||
}
|
||||
|
||||
}
|
45
catch/cms/tables/SiteLink.php
Normal file
45
catch/cms/tables/SiteLink.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
use catcher\CatchTable;
|
||||
use catchAdmin\cms\tables\forms\Factory;
|
||||
use catcher\library\table\Actions;
|
||||
use catcher\library\table\HeaderItem;
|
||||
use catcher\library\table\Search;
|
||||
|
||||
class SiteLink extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return $this->getTable('SiteLink')
|
||||
->header([
|
||||
HeaderItem::label('标题')->prop('title'),
|
||||
HeaderItem::label('地址')->prop('link_to')->width(400)->withUrlComponent(),
|
||||
HeaderItem::label('图标')->prop('icon')->width(120)->withPreviewComponent(),
|
||||
HeaderItem::label('展示')->prop('is_show')->width(120)->withSwitchComponent(),
|
||||
HeaderItem::label('权重')->prop('weight')->width(120)->withEditNumberComponent(),
|
||||
HeaderItem::label('操作')->actions([
|
||||
Actions::update(),
|
||||
Actions::delete()
|
||||
])
|
||||
])
|
||||
->withActions([
|
||||
Actions::create()
|
||||
])
|
||||
->withSearch([
|
||||
Search::label('网站标题')->input('title', '请输入网站标题')
|
||||
])
|
||||
->withBind()
|
||||
->withDialogWidth('40%')
|
||||
->withApiRoute('cms/site/links')
|
||||
->render();
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return Factory::create('SiteLink');
|
||||
}
|
||||
|
||||
}
|
45
catch/cms/tables/Tags.php
Normal file
45
catch/cms/tables/Tags.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
use catcher\CatchTable;
|
||||
use catchAdmin\cms\tables\forms\Factory;
|
||||
use catcher\library\table\Actions;
|
||||
use catcher\library\table\HeaderItem;
|
||||
use catcher\library\table\Search;
|
||||
|
||||
class Tags extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return $this->getTable('tags')
|
||||
->header([
|
||||
HeaderItem::label('编号')->prop('id'),
|
||||
|
||||
HeaderItem::label('名称')->prop('name'),
|
||||
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
|
||||
HeaderItem::label('操作')->actions([
|
||||
Actions::update(),
|
||||
Actions::delete()
|
||||
])
|
||||
])
|
||||
->withBind()
|
||||
->withSearch([
|
||||
Search::label('名称')->name('请输入标签名称')
|
||||
])
|
||||
->withApiRoute('cms/tags')
|
||||
->withActions([
|
||||
Actions::create()
|
||||
])
|
||||
->render();
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return Factory::create('tags');
|
||||
}
|
||||
|
||||
}
|
21
catch/cms/tables/UsedAt.php
Normal file
21
catch/cms/tables/UsedAt.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables;
|
||||
|
||||
use catcher\CatchTable;
|
||||
use catchAdmin\cms\tables\forms\Factory;
|
||||
|
||||
class UsedAt extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return Factory::create('UsedAt');
|
||||
}
|
||||
|
||||
}
|
71
catch/cms/tables/forms/Articles.php
Normal file
71
catch/cms/tables/forms/Articles.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catchAdmin\cms\model\Tags;
|
||||
use catcher\library\form\Form;
|
||||
use catchAdmin\cms\model\Articles as Article;
|
||||
use catchAdmin\cms\model\Category;
|
||||
|
||||
class Articles extends Form
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement fields() method.
|
||||
return [
|
||||
self::input('title', '标题')->required()->maxlength(100)->col(12),
|
||||
|
||||
self::cascader('category_id', '选择分类')
|
||||
->options(
|
||||
Category::field(['id', 'name', 'parent_id'])->select()->toTree()
|
||||
)
|
||||
->col(12)
|
||||
->props(self::props('name', 'id', [
|
||||
'checkStrictly' => true
|
||||
]))
|
||||
->filterable(true)
|
||||
->clearable(true)
|
||||
->style(['width' => '100%'])
|
||||
->required()->col(8),
|
||||
|
||||
self::input('keywords', '关键字')->col(12),
|
||||
|
||||
self::image('封面', 'cover')->col(12),
|
||||
|
||||
self::textarea('description', '摘要')->col(12),
|
||||
|
||||
self::images('组图', 'images')->col(12),
|
||||
|
||||
self::selectMultiple('tags', '标签')
|
||||
->options(Tags::field(['name as value', 'name as label'])->select()->toArray())
|
||||
->clearable(true)
|
||||
->allowCreate(true)
|
||||
->filterable(true)
|
||||
->style(['width' => '100%'])
|
||||
->col(12),
|
||||
|
||||
self::input('url', '自定义URL')->col(8),
|
||||
|
||||
self::editor('content', '内容')->required(),
|
||||
|
||||
self::radio('is_top', '置顶', Article::UN_TOP)->options(
|
||||
self::options()->add('是', Article::TOP)
|
||||
->add('否', Article::UN_TOP)->render()
|
||||
),
|
||||
|
||||
self::radio('is_recommend', '推荐', Article::UN_RECOMMEND)->options(
|
||||
self::options()->add('是', Article::RECOMMEND)
|
||||
->add('否', Article::UN_RECOMMEND)->render()
|
||||
),
|
||||
|
||||
self::radio('status', '展示', Article::ENABLE)->options(
|
||||
self::options()->add('是', Article::ENABLE)
|
||||
->add('否', Article::DISABLE)->render()
|
||||
),
|
||||
|
||||
self::radio('is_can_comment', '允许评论', Article::UN_CAN_COMMENT)->options(
|
||||
self::options()->add('是', Article::CAN_COMMENT)
|
||||
->add('否', Article::UN_CAN_COMMENT)->render()
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
22
catch/cms/tables/forms/BaseForm.php
Normal file
22
catch/cms/tables/forms/BaseForm.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catchAdmin\cms\model\Category as CategoryModel;
|
||||
use catchAdmin\cms\support\DynamicFormFields;
|
||||
use catcher\library\form\Form;
|
||||
|
||||
abstract class BaseForm extends Form
|
||||
{
|
||||
protected $table = null;
|
||||
|
||||
public function create(): array
|
||||
{
|
||||
$fields = parent::create(); // TODO: Change the autogenerated stub
|
||||
|
||||
if ($this->table) {
|
||||
return array_merge($fields, (new DynamicFormFields())->build($this->table));
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
73
catch/cms/tables/forms/Category.php
Normal file
73
catch/cms/tables/forms/Category.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catchAdmin\cms\model\Category as CategoryModel;
|
||||
use catcher\library\form\Form;
|
||||
|
||||
class Category extends BaseForm
|
||||
{
|
||||
protected $table = 'cms_category';
|
||||
|
||||
/**
|
||||
* create form
|
||||
*
|
||||
* @time 2021年03月02日
|
||||
* @return array
|
||||
*/
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement create() method.
|
||||
return [
|
||||
Form::input('name', '分类名称')->required(),
|
||||
Form::cascader('parent_id', '父级栏目')
|
||||
->options(CategoryModel::field(['id', 'name', 'parent_id'])->select()->toTree())->props([
|
||||
'props' => [
|
||||
'value' => 'id',
|
||||
'label' => 'name',
|
||||
'checkStrictly' => true
|
||||
]
|
||||
])->showAllLevels(false)->style(['width' => '100%']),
|
||||
|
||||
Form::input('title', 'seo标题'),
|
||||
Form::input('keywords', 'seo关键词'),
|
||||
Form::textarea('description', 'seo描述'),
|
||||
Form::input('url', '自定义URL'),
|
||||
Form::select('type', '页面类型', 1)->options([
|
||||
['value' => 1, 'label' => '列表模式'],
|
||||
['value' => 2, 'label' => '单页模式'],
|
||||
['value' => 3, 'label' => '封面模式'],
|
||||
]),
|
||||
|
||||
Form::radio('status', '状态', 1)->options(
|
||||
self::options()->add('启用', 1)
|
||||
->add('禁用', 2)->render()
|
||||
),
|
||||
|
||||
Form::radio('is_can_comment', '评论', 2)->options(
|
||||
self::options()->add('可以', 1)
|
||||
->add('不可以', 2)->render()
|
||||
),
|
||||
|
||||
Form::radio('is_can_contribute', '投稿', 2)->options(
|
||||
self::options()->add('可以', 1)
|
||||
->add('不可以', 2)->render()
|
||||
),
|
||||
|
||||
Form::number('weight', '权重', 1),
|
||||
|
||||
Form::number('limit', '每页数量', 10),
|
||||
];
|
||||
}
|
||||
}
|
12
catch/cms/tables/forms/Factory.php
Normal file
12
catch/cms/tables/forms/Factory.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catcher\library\form\FormFactory;
|
||||
|
||||
class Factory extends FormFactory
|
||||
{
|
||||
public static function from(): string
|
||||
{
|
||||
return __NAMESPACE__;
|
||||
}
|
||||
}
|
128
catch/cms/tables/forms/Field.php
Normal file
128
catch/cms/tables/forms/Field.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
use catcher\library\form\Form;
|
||||
|
||||
class Field extends Form
|
||||
{
|
||||
/**
|
||||
* create form
|
||||
*
|
||||
* @time 2021年03月02日
|
||||
* @return array
|
||||
*/
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement create() method.
|
||||
return [
|
||||
// 字段名称
|
||||
Form::input('name', '字段名称')->required()
|
||||
->appendValidate(
|
||||
Form::validatePattern('^[a-z]{1,30}_?[a-z]{1,30}?')->message('字段名称只支持小写字母,_组合')
|
||||
)
|
||||
->placeholder('由英文和下划线组成')
|
||||
->clearable(true),
|
||||
// 字段释义
|
||||
Form::input('title', 'label名称')->required()->placeholder('表单Label')->clearable(true),
|
||||
// 字段类型
|
||||
Form::select('type', '类型')
|
||||
->required()
|
||||
->options($this->types())
|
||||
->style(['width' => '100%'])
|
||||
->appendControl('string', [Form::number('length', '长度', 1)->max(1000)->min(1)])
|
||||
->appendControl('int', [Form::number('length', '长度', 1)->max(11)->min(1)])
|
||||
->appendControl('select', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')])
|
||||
->appendControl('radio', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')])
|
||||
->appendControl('checkbox', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')])
|
||||
->clearable(true),
|
||||
// 默认值
|
||||
Form::input('default_value', '默认值'),
|
||||
// 加索引
|
||||
Form::radio('is_index', '加索引', 2)->options(
|
||||
self::options()->add('是', 1)
|
||||
->add('否', 2)->render()
|
||||
),
|
||||
// 值唯一
|
||||
Form::radio('is_unique', '值唯一', 2)->options(
|
||||
self::options()->add('是', 1)
|
||||
->add('否', 2)->render()
|
||||
),
|
||||
// 表单验证规则
|
||||
Form::selectMultiple('rules', '验证规则')
|
||||
->options($this->rules()),
|
||||
// 正则验证
|
||||
Form::input('pattern', '正则验证')->placeholder('格式如下(正则|提示信息)'),
|
||||
// 排序
|
||||
Form::number('sort', '排序', 1)->max(10000)->min(1),
|
||||
// 字段是否在表单中显示
|
||||
Form::radio('status', '状态', 1)->options(
|
||||
self::options()->add('正常', 1)
|
||||
->add('隐藏', 2)->render()
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单类型
|
||||
*
|
||||
* @time 2021年03月06日
|
||||
* @return \string[][]
|
||||
*/
|
||||
protected function types(): array
|
||||
{
|
||||
return [
|
||||
['value' => 'string', 'label' => '字符串'],
|
||||
['value' => 'int', 'label' => '整数'],
|
||||
['value' => 'float', 'label' => '小数'],
|
||||
['value' => 'textarea', 'label' => 'textarea文本'],
|
||||
['value' => 'text', 'label' => '编辑器(建议)'],
|
||||
['value' => 'longtext', 'label' => '编辑器(支持超大文本)'],
|
||||
['value' => 'date', 'label' => '日期型'],
|
||||
['value' => 'datetime', 'label' => '日期时间型'],
|
||||
['value' => 'image', 'label' => '图片上传'],
|
||||
['value' => 'images', 'label' => '多图上传'],
|
||||
['value' => 'file', 'label' => '文件上传'],
|
||||
['value' => 'files', 'label' => '多文件上传'],
|
||||
['value' => 'select', 'label' => '列表'],
|
||||
['value' => 'checkbox', 'label' => '复选框'],
|
||||
['value' => 'password', 'label' => '密码框'],
|
||||
['value' => 'color', 'label' => '颜色选项'],
|
||||
['value' => 'radio', 'label' => '单选'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
['value' => 'require', 'label' => '必填'],
|
||||
['value' => 'number', 'label' => '数字'],
|
||||
['value' => 'integer', 'label' => '整数'],
|
||||
['value' => 'float', 'label' => '浮点数'],
|
||||
['value' => 'email', 'label' => '邮箱'],
|
||||
['value' => 'date', 'label' => '日期'],
|
||||
['value' => 'alpha', 'label' => '纯字母'],
|
||||
['value' => 'alphaNum', 'label' => '纯字母和数字'],
|
||||
['value' => 'url', 'label' => 'url地址'],
|
||||
['value' => 'ip', 'label' => 'ip地址'],
|
||||
['value' => 'mobile', 'label' => '手机号'],
|
||||
['value' => 'idCard', 'label' => '身份证'],
|
||||
['value' => 'zip', 'label' => '邮政编码'],
|
||||
['value' => 'password', 'label' => '密码'],
|
||||
['value' => 'strong_password', 'label' => '强密码'],
|
||||
['value' => 'landLine', 'label' => '座机'],
|
||||
['value' => 'chinese_character', 'label' => '汉字']
|
||||
];
|
||||
}
|
||||
}
|
67
catch/cms/tables/forms/Model.php
Normal file
67
catch/cms/tables/forms/Model.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Catch-CMS Design On 2020
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
use catchAdmin\cms\support\Table;
|
||||
use catchAdmin\cms\support\TableColumn;
|
||||
use catcher\library\form\Form;
|
||||
use think\facade\Db;
|
||||
use think\helper\Str;
|
||||
|
||||
class Model extends Form
|
||||
{
|
||||
protected $table = 'cms_articles';
|
||||
|
||||
/**
|
||||
* create form
|
||||
*
|
||||
* @time 2021年03月02日
|
||||
* @return array
|
||||
*/
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement create() method.
|
||||
return [
|
||||
self::input('name', '模型名称')->required()->maxlength(100),
|
||||
self::input('alias', '模型别名')->required()->appendValidates([
|
||||
self::validateAlphaDash()
|
||||
]),
|
||||
self::select('table_name', '模型关联表')
|
||||
->options($this->getCMSTables())
|
||||
->style(['width' => '100%'])
|
||||
->required(),
|
||||
|
||||
self::textarea('description', '模型描述')->maxlength(255),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 Cms 表
|
||||
*
|
||||
* @time 2021年04月30日
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getCMSTables()
|
||||
{
|
||||
$options = self::options();
|
||||
|
||||
foreach (Db::getTables() as $table) {
|
||||
if (Str::contains($table, 'cms') && !Str::contains($table, 'relate')) {
|
||||
$options->add($table, $table);
|
||||
}
|
||||
}
|
||||
|
||||
return $options->render();
|
||||
}
|
||||
}
|
66
catch/cms/tables/forms/ModelUsedFields.php
Normal file
66
catch/cms/tables/forms/ModelUsedFields.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catchAdmin\cms\model\Models;
|
||||
use catcher\library\form\Form;
|
||||
use think\facade\Db;
|
||||
|
||||
class ModelUsedFields extends Form
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
$modelId = request()->param('model_id');
|
||||
|
||||
$model = Models::where('id', $modelId)->with('fields')->find();
|
||||
|
||||
$fields = $this->getModelFields($model->table_name);
|
||||
|
||||
$this->primaryKeyValue = $modelId;
|
||||
// TODO: Implement fields() method.
|
||||
return [
|
||||
self::select('used_at_list', '列表使用', $model->used_at_list ? explode(',', $model->used_at_list) : '')
|
||||
->multiple(true)
|
||||
->style(['width' => '100%'])
|
||||
->options($fields),
|
||||
|
||||
self::select('used_at_search', '搜索使用' , $model->used_at_search ? explode(',', $model->used_at_search) : '')
|
||||
->multiple(true)
|
||||
->style(['width' => '100%'])
|
||||
->options($fields),
|
||||
|
||||
self::select('used_at_detail', '详情使用', $model->used_at_detail ? explode(',', $model->used_at_detail) : '')
|
||||
->multiple(true)
|
||||
->style(['width' => '100%'])
|
||||
->options($fields),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型字段
|
||||
*
|
||||
* @time 2021年05月11日
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return int[]|string[]
|
||||
*/
|
||||
protected function getModelFields($tableName)
|
||||
{
|
||||
$fields = array_keys(Db::name($tableName)->getFields());
|
||||
|
||||
foreach ($fields as $k => $field) {
|
||||
if ($field === app(Models::class)->getDeleteAtField()) {
|
||||
unset($fields[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
$options = self::options();
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$options = $options->add($field, $field);
|
||||
}
|
||||
|
||||
|
||||
return $options->render();
|
||||
}
|
||||
}
|
30
catch/cms/tables/forms/SiteLink.php
Normal file
30
catch/cms/tables/forms/SiteLink.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catchAdmin\cms\model\BaseModel;
|
||||
|
||||
class SiteLink extends BaseForm
|
||||
{
|
||||
protected $table = 'cms_site_links';
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement fields() method.
|
||||
return [
|
||||
self::input('title', '网站标题')->required(),
|
||||
|
||||
self::input('link_to', '跳转地址')->required()->appendValidates([
|
||||
self::validateUrl()
|
||||
]),
|
||||
|
||||
self::image('网站图标', 'icon'),
|
||||
|
||||
self::radio('is_show', '展示', BaseModel::ENABLE)->options(
|
||||
self::options()->add('是', BaseModel::ENABLE)
|
||||
->add('否', BaseModel::DISABLE)->render()
|
||||
),
|
||||
|
||||
self::number('weight', '权重')->min(1)->max(10000)
|
||||
];
|
||||
}
|
||||
}
|
21
catch/cms/tables/forms/Tags.php
Normal file
21
catch/cms/tables/forms/Tags.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
class Tags extends BaseForm
|
||||
{
|
||||
protected $table = 'cms_tags';
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement fields() method.
|
||||
return [
|
||||
self::input('name', '名称')->required(),
|
||||
|
||||
self::input('title', 'seo 标题'),
|
||||
|
||||
self::input('keywords', 'seo 关键词'),
|
||||
|
||||
self::input('description', 'seo 描述'),
|
||||
];
|
||||
}
|
||||
}
|
15
catch/cms/tables/forms/UsedAt.php
Normal file
15
catch/cms/tables/forms/UsedAt.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\tables\forms;
|
||||
|
||||
use catcher\library\form\Form;
|
||||
|
||||
class UsedAt extends Form
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement fields() method.
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user