mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-29 14:01:07 +00:00
增加多语言翻译
This commit is contained in:
parent
d338e54375
commit
54b55fdcce
@ -98,12 +98,12 @@ class SystemCrud extends AuthController
|
||||
$data['fromField'] = $fromField;
|
||||
$data['columnField'] = $columnField;
|
||||
if (!$data['tableName']) {
|
||||
return app('json')->fail('缺少表名');
|
||||
return app('json')->fail(500045);
|
||||
}
|
||||
|
||||
$this->services->createCrud($data);
|
||||
|
||||
return app('json')->success('创建成功');
|
||||
return app('json')->success(500046);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,11 +121,11 @@ class SystemCrud extends AuthController
|
||||
], true);
|
||||
|
||||
if (!$tableName) {
|
||||
return app('json')->fail('缺少表名');
|
||||
return app('json')->fail(500045);
|
||||
}
|
||||
|
||||
if (in_array($tableName, SystemCrudServices::NOT_CRUD_TABANAME)) {
|
||||
return app('json')->fail('不能生成系统自带数据表');
|
||||
return app('json')->fail(500044);
|
||||
}
|
||||
|
||||
$routeName = 'crud/' . Str::snake($tableName);
|
||||
@ -176,12 +176,12 @@ class SystemCrud extends AuthController
|
||||
public function read($id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
return app('json')->fail(500035);
|
||||
}
|
||||
|
||||
$info = $this->services->get($id);
|
||||
if (!$info) {
|
||||
return app('json')->fail('查看的生成的文件不存在');
|
||||
return app('json')->fail(500043);
|
||||
}
|
||||
|
||||
$routeName = 'crud/' . Str::snake($info->table_name);
|
||||
@ -256,12 +256,12 @@ class SystemCrud extends AuthController
|
||||
public function delete(SystemMenusServices $services, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
return app('json')->fail(500035);
|
||||
}
|
||||
|
||||
$info = $this->services->get($id);
|
||||
if (!$info) {
|
||||
return app('json')->fail('删除的数据不存在');
|
||||
return app('json')->fail(500042);
|
||||
}
|
||||
|
||||
$services->transaction(function () use ($services, $info) {
|
||||
@ -283,12 +283,12 @@ class SystemCrud extends AuthController
|
||||
unlink($item);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return app('json')->success('删除生成的菜单和信息成功,删除文件出错,详细错误:' . $e->getMessage());
|
||||
return app('json')->success(500041, [], ['message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return app('json')->success('删除成功');
|
||||
return app('json')->success(100002);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,12 +302,12 @@ class SystemCrud extends AuthController
|
||||
public function download($id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
return app('json')->fail(500035);
|
||||
}
|
||||
|
||||
$info = $this->services->get($id);
|
||||
if (!$info) {
|
||||
return app('json')->fail('下载的文件不存在');
|
||||
return app('json')->fail(500039);
|
||||
}
|
||||
$zipPath = app()->getRootPath() . 'backup' . DS . Str::camel($info->table_name);
|
||||
$zipName = app()->getRootPath() . 'backup' . DS . Str::camel($info->table_name) . '.zip';
|
||||
@ -353,7 +353,7 @@ class SystemCrud extends AuthController
|
||||
], $makePath);
|
||||
|
||||
if (!extension_loaded('zip')) {
|
||||
return app('json')->fail('请安装zip扩展后在尝试下载');
|
||||
return app('json')->fail(500040);
|
||||
}
|
||||
|
||||
$fileService = new FileService();
|
||||
|
||||
@ -112,16 +112,16 @@ class SystemRoute extends AuthController
|
||||
]);
|
||||
|
||||
if (!$data['name']) {
|
||||
return app('json')->fail('请输入路由名称');
|
||||
return app('json')->fail(500031);
|
||||
}
|
||||
if (!$data['path']) {
|
||||
return app('json')->fail('请输入路由路径');
|
||||
return app('json')->fail(500032);
|
||||
}
|
||||
if (!$data['method']) {
|
||||
return app('json')->fail('请选择路由请求方式');
|
||||
return app('json')->fail(500033);
|
||||
}
|
||||
if (!$data['app_name']) {
|
||||
return app('json')->fail('缺少应用名参数');
|
||||
return app('json')->fail(500034);
|
||||
}
|
||||
if ($id) {
|
||||
$this->services->update($id, $data);
|
||||
@ -130,7 +130,7 @@ class SystemRoute extends AuthController
|
||||
$this->services->save($data);
|
||||
}
|
||||
|
||||
return app('json')->success($id ? '修改成功' : '添加成功');
|
||||
return app('json')->success($id ? 100001 : 100021);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,12 +155,12 @@ class SystemRoute extends AuthController
|
||||
public function delete($id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
return app('json')->fail(500035);
|
||||
}
|
||||
|
||||
$this->services->destroy($id);
|
||||
|
||||
return app('json')->success('删除成功');
|
||||
return app('json')->success(100002);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ class SystemRouteCate extends AuthController
|
||||
]);
|
||||
|
||||
if (!$data['name']) {
|
||||
return app('json')->fail('缺少分类名称');
|
||||
return app('json')->fail(500037);
|
||||
}
|
||||
|
||||
$data['add_time'] = time();
|
||||
@ -88,7 +88,7 @@ class SystemRouteCate extends AuthController
|
||||
$this->services->save($data);
|
||||
|
||||
|
||||
return app('json')->success('保存成功');
|
||||
return app('json')->success(100000);
|
||||
|
||||
}
|
||||
|
||||
@ -122,13 +122,13 @@ class SystemRouteCate extends AuthController
|
||||
]);
|
||||
|
||||
if (!$data['name']) {
|
||||
return app('json')->fail('缺少分类名称');
|
||||
return app('json')->fail(500037);
|
||||
}
|
||||
|
||||
$data['pid'] = $data['path'][count($data['path']) - 1] ?? 0;
|
||||
$this->services->update($id, $data);
|
||||
|
||||
return app('json')->success('修改成功');
|
||||
return app('json')->success(100001);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,15 +142,15 @@ class SystemRouteCate extends AuthController
|
||||
public function delete(SystemRouteServices $service, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
return app('json')->fail(500035);
|
||||
}
|
||||
|
||||
if ($service->count(['cate_id' => $id])) {
|
||||
return app('json')->fail('请先删除分类下的接口');
|
||||
return app('json')->fail(500038);
|
||||
}
|
||||
|
||||
$this->services->delete($id);
|
||||
|
||||
return app('json')->success('删除成功');
|
||||
return app('json')->success(100002);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ namespace app\services\system;
|
||||
|
||||
use app\dao\system\SystemCrudDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\crud\Controller;
|
||||
use crmeb\services\crud\Dao;
|
||||
use crmeb\services\crud\Make;
|
||||
@ -27,11 +28,8 @@ use crmeb\services\crud\ViewApi;
|
||||
use crmeb\services\crud\ViewPages;
|
||||
use crmeb\services\crud\ViewRouter;
|
||||
use Phinx\Db\Adapter\AdapterFactory;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\helper\Str;
|
||||
use think\migration\Migrator;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
use think\migration\db\Table;
|
||||
|
||||
/**
|
||||
@ -140,7 +138,7 @@ class SystemCrudServices extends BaseServices
|
||||
{
|
||||
|
||||
if (!in_array($type, $this->getTabelRule()['types'])) {
|
||||
throw new ValidateException('类型不在支持范围');
|
||||
throw new AdminException(500047);
|
||||
}
|
||||
|
||||
return $this->getTabelRule()['rule'][$type] ?? $type;
|
||||
@ -234,7 +232,7 @@ class SystemCrudServices extends BaseServices
|
||||
$filePath = $this->valueReplace($data['filePath']);
|
||||
|
||||
if ($this->dao->value(['table_name' => $tableName])) {
|
||||
throw new ValidateException('此表已经生成请在列表中查看');
|
||||
throw new AdminException(500048);
|
||||
}
|
||||
|
||||
$data['softDelete'] = false;
|
||||
@ -247,13 +245,13 @@ class SystemCrudServices extends BaseServices
|
||||
}
|
||||
|
||||
if (in_array($tableName, self::NOT_CRUD_TABANAME)) {
|
||||
throw new ValidateException('不能生成系统自带数据表');
|
||||
throw new AdminException(500044);
|
||||
}
|
||||
|
||||
//读取表结构
|
||||
$column = $this->getColumnNamesList($tableName);
|
||||
if (!$column) {
|
||||
throw new ValidateException('请先创建' . $tableName . '表');
|
||||
throw new AdminException(500049, ['_name' => $tableName]);
|
||||
}
|
||||
|
||||
$tableInfo = $this->getTableInfo($tableName);
|
||||
|
||||
@ -65,7 +65,7 @@ class SystemRouteServices extends BaseServices
|
||||
{
|
||||
$routeInfo = $this->dao->get($id);
|
||||
if (!$routeInfo) {
|
||||
throw new ValidateException('修改的路由不存在');
|
||||
throw new ValidateException(500036);
|
||||
}
|
||||
|
||||
$routeInfo = $routeInfo->toArray();
|
||||
|
||||
@ -445,7 +445,7 @@ abstract class Make
|
||||
if ($this->isExistsMake) {
|
||||
unlink($pathname);
|
||||
} else {
|
||||
throw new CrudException($this->name . ':' . $pathname . ' already exists!');
|
||||
throw new CrudException(500052, ['filename' => $this->name . ':' . $pathname]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -454,13 +454,13 @@ abstract class Make
|
||||
mkdir(dirname($pathname), 0755, true);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
throw new CrudException('CRUD创建目录报错,无法创建:' . dirname($pathname));
|
||||
throw new CrudException(500050, ['pathname' => dirname($pathname)]);
|
||||
}
|
||||
|
||||
try {
|
||||
file_put_contents($pathname, $this->content);
|
||||
} catch (\Throwable $e) {
|
||||
throw new CrudException('CRUD生成文件报错,无法写入:' . $pathname);
|
||||
throw new CrudException(500051, ['pathname' => $pathname]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ class Route extends Make
|
||||
$routePath = $options['routePath'] ?? '';
|
||||
$menus = $options['menus'] ?? '';
|
||||
if (!$route) {
|
||||
throw new CrudException('缺少路由名称');
|
||||
throw new CrudException(500053);
|
||||
}
|
||||
if (!$action) {
|
||||
$action = ['index', 'create', 'save', 'edit', 'update', 'delete'];
|
||||
|
||||
@ -75,7 +75,7 @@ class ViewApi extends Make
|
||||
}
|
||||
$route = $options['route'] ?? '';
|
||||
if (!$route) {
|
||||
throw new CrudException('缺少路由名称');
|
||||
throw new CrudException(500053);
|
||||
}
|
||||
|
||||
$contentJs = '';
|
||||
|
||||
@ -75,7 +75,7 @@ class ViewRouter extends Make
|
||||
$route = $options['route'] ?? Str::snake($name);
|
||||
$pagePath = $options['pagePath'] ?? Str::camel($name);
|
||||
if (!$route) {
|
||||
throw new CrudException('缺少路由名称');
|
||||
throw new CrudException(500053);
|
||||
}
|
||||
|
||||
$this->value['menus'] = $menus;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user