@@ -60,7 +60,7 @@ class Crud extends Backend
6060 */
6161 protected array $ dtStringToArray = ['checkbox ' , 'selects ' , 'remoteSelects ' , 'city ' , 'images ' , 'files ' ];
6262
63- protected array $ noNeedPermission = ['logStart ' , 'getFileData ' , 'parseFieldData ' , 'generateCheck ' ];
63+ protected array $ noNeedPermission = ['logStart ' , 'getFileData ' , 'parseFieldData ' , 'generateCheck ' , ' uploadCompleted ' ];
6464
6565 public function initialize (): void
6666 {
@@ -294,7 +294,9 @@ public function generate(): void
294294 $ this ->error ($ e ->getMessage ());
295295 }
296296
297- $ this ->success ();
297+ $ this ->success ('' , [
298+ 'crudLog ' => CrudLog::find ($ crudLogId ),
299+ ]);
298300 }
299301
300302 /**
@@ -304,8 +306,41 @@ public function generate(): void
304306 public function logStart (): void
305307 {
306308 $ id = $ this ->request ->post ('id ' );
307- $ info = CrudLog::find ($ id )->toArray ();
308- if (!$ info ) {
309+ $ type = $ this ->request ->post ('type ' , '' );
310+
311+ if ($ type == 'Cloud history ' ) {
312+ // 云端 历史记录
313+ $ client = get_ba_client ();
314+ $ response = $ client ->request ('GET ' , '/api/v6.Crud/info ' , [
315+ 'query ' => [
316+ 'id ' => $ id ,
317+ 'server ' => 1 ,
318+ 'ba-user-token ' => $ this ->request ->post ('token ' , '' ),
319+ ]
320+ ]);
321+ $ body = $ response ->getBody ();
322+ $ statusCode = $ response ->getStatusCode ();
323+ $ content = $ body ->getContents ();
324+ if ($ content == '' || stripos ($ content , '<title>系统发生错误</title> ' ) !== false || $ statusCode != 200 ) {
325+ $ this ->error (__ ('Failed to load cloud data ' ));
326+ }
327+ $ json = json_decode ($ content , true );
328+ if (json_last_error () != JSON_ERROR_NONE ) {
329+ $ this ->error (__ ('Failed to load cloud data ' ));
330+ }
331+ if (is_array ($ json )) {
332+ if ($ json ['code ' ] != 1 ) {
333+ $ this ->error ($ json ['msg ' ]);
334+ }
335+
336+ $ info = $ json ['data ' ]['info ' ];
337+ }
338+ } else {
339+ // 本地记录
340+ $ info = CrudLog::find ($ id )->toArray ();
341+ }
342+
343+ if (!isset ($ info ) || !$ info ) {
309344 $ this ->error (__ ('Record not found ' ));
310345 }
311346
@@ -328,6 +363,7 @@ public function logStart(): void
328363 $ this ->success ('' , [
329364 'table ' => $ info ['table ' ],
330365 'fields ' => $ info ['fields ' ],
366+ 'sync ' => $ info ['sync ' ],
331367 ]);
332368 }
333369
@@ -548,6 +584,38 @@ public function generateCheck(): void
548584 $ this ->success ();
549585 }
550586
587+ /**
588+ * CRUD 设计记录上传成功标记
589+ * @throws Throwable
590+ */
591+ public function uploadCompleted (): void
592+ {
593+ $ syncIds = $ this ->request ->post ('syncIds/a ' , []);
594+ $ cancelSync = $ this ->request ->post ('cancelSync/b ' , false );
595+ $ crudLogModel = new CrudLog ();
596+
597+ if ($ cancelSync ) {
598+ $ logData = $ crudLogModel ->where ('id ' , 'in ' , array_keys ($ syncIds ))->select ();
599+ foreach ($ logData as $ logDatum ) {
600+ if ($ logDatum ->sync == $ syncIds [$ logDatum ->id ]) {
601+ $ logDatum ->sync = 0 ;
602+ $ logDatum ->save ();
603+ }
604+ }
605+ $ this ->success ();
606+ }
607+
608+ $ saveData = [];
609+ foreach ($ syncIds as $ key => $ syncId ) {
610+ $ saveData [] = [
611+ 'id ' => $ key ,
612+ 'sync ' => $ syncId ,
613+ ];
614+ }
615+ $ crudLogModel ->saveAll ($ saveData );
616+ $ this ->success ();
617+ }
618+
551619 /**
552620 * 关联表数据解析
553621 * @param $field
0 commit comments