public function index( $id, $type, $data ) { $name = ''; $list = ''; if ( $type == 1 ) { $name = 'store'; } else if ( $type == 2 ) { $name = 'rider'; } else if ( $type == 3 ) { $name = 'deposit'; } else if ( $type == 4 ) { $name = 'refund'; } $list = db( $name )->where( [ 'id'=>$id, 'type'=>1 ] )->count(); Db::startTrans(); $ultimately = true; try { if ( $list != 0 ) { $result = new Api(); $list[ 'userinfo_id' ] = getallheaders()[ 'Id' ]; $list[ 'addtime' ] = date( 'Y-m-d H:i:s' ); $list[ 'path' ] = $result->pathse; $content = db( $name )->where( [ 'id'=>$id, 'type'=>1 ] )->find(); $contentsMap = array_combine( array_keys( $data ), array_values( $data ) ); // 遍历content数组,只保留在contentsMap中存在的键值对 foreach ( $content as $key => $value ) { if ( isset( $contentsMap[ $key ] ) ) { // 如果键存在于contentsMap中,保留该键值对 continue; } // 如果键不存在于contentsMap中,从content数组中移除该键值对 unset( $content[ $key ] ); } // 提取 $contents 的键作为排序参考 $sortedKeys = array_keys($content); // 使用 uksort 对 $content 进行排序 uksort($data, function($a, $b) use ($sortedKeys) { return array_search($a, $sortedKeys) - array_search($b, $sortedKeys); }); $list[ 'content' ] = json_encode( $content ); $list[ 'contents' ] = json_encode( $data ); $list[ 'type' ] = 2; $list = db( $name )->where( [ 'id'=>$id, 'type'=>1 ] )->update( $data ); if ( $list ) { $resultss = $result->daiord( $list ); if ( !$resultss ) { DB::rollBack(); //错误 回滚事务 throw new \Exception( '' ); } Db::commit(); } else { DB::rollBack(); //错误 回滚事务 throw new \Exception( '' ); } } else { DB::rollBack(); //错误 回滚事务 throw new \Exception( '' ); } } catch ( \Exception $e ) { Db::rollback(); $ultimately = false; } if ( $ultimately )return true; if ( !$ultimately )return false; }