@@ -101,7 +101,7 @@ protected function checkFilesAndHandleParams($generatorItem,$params,$currentApps
101
101
];
102
102
103
103
// 验证模板是否存在
104
- $ templatePath = App::getRootPath () . $ template ;
104
+ $ templatePath =Utils:: formatPath ( App::getRootPath () . $ template, " / " ) ;
105
105
if (is_readable ($ templatePath ) == false ) {
106
106
throw new ErrorException ("template not found " , 412 , [
107
107
'template ' => $ template
@@ -130,6 +130,7 @@ protected function checkFilesAndHandleParams($generatorItem,$params,$currentApps
130
130
$ createFiles [] = [
131
131
'fileFullPath ' => $ fileFullPath ,
132
132
'template ' => $ template ,
133
+ 'templatePath ' =>$ templatePath ,
133
134
'type ' => $ type
134
135
];
135
136
@@ -166,7 +167,7 @@ protected function checkModels($generatorItem,$tplParams){
166
167
$ path = $ tableConfig ['items ' ][$ k ]['path ' ];
167
168
168
169
// 验证模板是否存在
169
- $ templatePath = App::getRootPath () . $ template ;
170
+ $ templatePath = Utils:: formatPath ( App::getRootPath () . $ template, " / " ) ;
170
171
if (is_readable ($ templatePath ) == false ) {
171
172
throw new ErrorException ("template not found " , 412 , [
172
173
'template ' => $ template
@@ -223,7 +224,7 @@ protected function createFiles($createFiles,$tplParams){
223
224
224
225
if (!empty ($ createFiles ) && count ($ createFiles )>0 ){
225
226
foreach ($ createFiles as $ fileItem ) {
226
- $ html = (new ParseTemplate ())->compile ($ fileItem ['template ' ],$ tplParams );
227
+ $ html = (new ParseTemplate ())->compile ($ fileItem ['templatePath ' ],$ tplParams );
227
228
if ($ fileItem ['type ' ] === "file " ){
228
229
// 路径为文件,则添加到该文件
229
230
$ pathFileContent = Utils::getFileContent ($ fileItem ['fileFullPath ' ]);
@@ -248,7 +249,7 @@ protected function createModels($createModels,$tplParams){
248
249
$ table = $ item ['table ' ];
249
250
if (!empty ($ table ['model_name ' ])){
250
251
$ tplParams ['tables ' ][$ k ]['class_name ' ] =$ table ['model_name ' ];
251
- $ html = (new ParseTemplate ())->compile ($ item ['template ' ],$ tplParams );
252
+ $ html = (new ParseTemplate ())->compile ($ item ['templatePath ' ],$ tplParams );
252
253
Utils::createFile ($ item ['fileFullPath ' ],$ html );
253
254
}
254
255
if ($ table ['table_name ' ]){
@@ -307,21 +308,27 @@ protected function createTable($table){
307
308
308
309
$ tp_version = \think \facade \App::version ();
309
310
if (substr ($ tp_version , 0 , 2 ) == '5. ' ){
310
- Db5::query ($ sql );
311
+ Db5::startTrans ();
312
+ try {
313
+ Db5::query ($ sql );
314
+ Db5::commit ();
315
+ return true ;
316
+ } catch (\Exception $ e ) {
317
+ Db5rollback ();
318
+ return $ e ->getMessage ();
319
+ }
311
320
}else {
312
- Db::query ($ sql );
321
+ Db::startTrans ();
322
+ try {
323
+ Db::query ($ sql );
324
+ Db::commit ();
325
+ return true ;
326
+ } catch (\Exception $ e ) {
327
+ Db::rollback ();
328
+ return $ e ->getMessage ();
329
+ }
313
330
}
314
- return true ;
315
- //
316
- // Db::startTrans();
317
- // try {
318
- // Db::query($sql);
319
- // Db::commit();
320
- // return true;
321
- // } catch (\Exception $e) {
322
- // Db::rollback();
323
- // return $e->getMessage();
324
- // }
331
+
325
332
326
333
}
327
334
}
0 commit comments