<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';
$meta=json_decode(file_get_contents(__DIR__.'/structure-'.$lane.'.json'),true);$rows=[];
foreach($pks as $t=>$pk){$g=$meta['tables'][$t];$check($g['foreign_keys']===0&&$g['triggers']===0&&$g['own_collision']===0,'Metadata gate '.$t);$check($read('SELECT COUNT(*) n FROM yoshop_'.$t.' WHERE store_id IN (2147001111,2147001112)')[0]['n']==0,'Live collision '.$t);if($dm){$ddl=$read("SELECT DBMS_METADATA.GET_DDL('TABLE',?,'AIZHCT_APP') ddl FROM DUAL",[strtoupper('yoshop_'.$t)])[0]['ddl'];$persist('ddl-'.$t.'.json',['ddl'=>$ddl]);$check(preg_match('/"'.strtoupper($pk).'"[^,\n]*(?:IDENTITY\s*\(|AUTO_INCREMENT\b)/i',$ddl)===1,'DM generated PK '.$t);$rows[$t]=['pk'=>$pk,'identity'=>true,'ddl_sha256'=>hash('sha256',$ddl)];}else{$auto=array_column(array_filter($g['columns'],static function($c){return $c['extra']==='auto_increment';}),'column_name');$check($auto===[$pk],'MySQL generated PK '.$t);$rows[$t]=['pk'=>$pk,'identity'=>true];}}
$templates=[];foreach($tenants as $module=>$tenant){foreach($pks as $t=>$pk){$r=[];foreach($meta['tables'][$t]['columns'] as $col){$k=$col['column_name'];if($k===$pk)continue;$type=strtolower($col['data_type']);if(preg_match('/int|number|decimal|double|float|numeric|bit/',$type))$r[$k]=0;elseif(preg_match('/date|timestamp/',$type))$r[$k]='2026-10-11 08:00:00';else $r[$k]='';}$r['store_id']=$tenant;foreach(['create_time','update_time'] as $k)if(array_key_exists($k,$r))$r[$k]=1800000000;$templates[$module][$t]=$r;}
$templates[$module]['user']=array_replace($templates[$module]['user'],['nick_name'=>$marker.'_'.$module,'is_delete'=>1,'platform'=>'H5','business'=>'aizhct']);
$templates[$module]['upload_file']=array_replace($templates[$module]['upload_file'],['storage'=>'local','domain'=>'http://comment-metadata.invalid','file_type'=>10,'file_name'=>$marker.'_'.$module,'file_path'=>$marker.'/'.$module.'.png','file_ext'=>'png','is_delete'=>0]);
$templates[$module]['goods']=array_replace($templates[$module]['goods'],['goods_name'=>'隐藏评价专用 '.$marker.'_'.$module,'goods_no'=>$marker.'_'.$module,'status'=>20,'is_delete'=>1,'goods_type'=>10,'spec_type'=>10,'content'=>'[]','points_discount_config'=>'{}','alone_grade_equity'=>'{}','delivery_type'=>'[]']);
$templates[$module]['order']=array_replace($templates[$module]['order'],['order_no'=>$marker.'_'.$module,'order_type'=>10,'order_status'=>20,'pay_status'=>10,'is_delete'=>1,'platform'=>'H5','order_source_data'=>'{}','buyer_remark'=>'评价链隔离 '.$marker]);
$templates[$module]['order_goods']=array_replace($templates[$module]['order_goods'],['goods_type'=>10,'goods_name'=>'隐藏评价专用 '.$marker.'_'.$module,'goods_no'=>$marker.'_'.$module,'goods_props'=>'[]','content'=>'[]']);
$templates[$module]['comment']['content']='评价 中文 单引号\' 反斜杠\\ '.$marker.'_'.$module;$templates[$module]['comment']['is_delete']=0;$templates[$module]['comment']['status']=0;
}
$persist('fixture-values.json',['marker'=>$marker,'generated_primary_keys'=>true,'templates'=>$templates,'comment_rows'=>[['score'=>10,'sort'=>20,'create_time'=>1800000001,'is_picture'=>1],['score'=>20,'sort'=>10,'create_time'=>1800000002,'is_picture'=>0],['score'=>30,'sort'=>10,'create_time'=>1800000003,'is_picture'=>0]],'relationships'=>'user/avatar=file; order/user; order_goods/user/order/goods/image=file; comment/user/order/order_goods/goods; comment_image/comment[0]/image=file']);
$app=commentApp($root,$runtime);$hashes=[];foreach(['app/store/controller/goods/Comment.php','app/terminal/controller/goods/Comment.php','app/store/model/Comment.php','app/terminal/model/Comment.php','app/common/model/Comment.php','app/store/model/CommentImage.php','app/terminal/model/CommentImage.php','app/common/model/CommentImage.php','app/common/model/UploadFile.php','app/common/model/OrderGoods.php','app/common/model/User.php','cores/BaseModel.php','app/common/database/DmBuilder.php'] as $f){$cl=str_replace('/','\\',substr($f,0,-4));$actual=(new ReflectionClass($cl))->getFileName();$check(realpath($actual)===realpath($root.'/'.$f),'Actual source root '.$f);$hashes[$f]=hash_file('sha256',$actual);}
$out=['lane'=>$lane,'business_dml'=>0,'identity'=>$rows,'hashes'=>$hashes,'fixture_sha256'=>hash_file('sha256',$runtime.'/fixture-values.json'),'protect'=>$protect()];$persist('preflight.json',$out);echo json_encode($out),"\n";
