<?php
require __DIR__.'/db.php';$fixture=json_decode(file_get_contents(__DIR__.'/private-fixture-lease.json'),true);
$source=static function()use($q,$p,$fixture,$check):array{$result=['own'=>[],'natural'=>[]];$ownFile=__DIR__.'/private-fixture-own.json';$known=is_file($ownFile)?json_decode(file_get_contents($ownFile),true):['member_weight'=>[],'member_weight_status'=>[]];foreach(['member_weight','member_weight_status']as $t){$rows=[];$last=0;for($page=0;$page<3;$page++){$sql='SELECT * FROM '.$p.$t.' WHERE ID>? ORDER BY ID';$part=$q($p==='ydy_'?$sql.' LIMIT 100':'SELECT * FROM ('.$sql.') WHERE ROWNUM<=100',[$last]);$rows=array_merge($rows,$part);if(count($part)<100)break;$last=(int)$part[count($part)-1]['id'];}$check(count($rows)<=200&&strlen(json_encode($rows))<=2097152,'Whole table source cap');$result['own'][$t]=array_values(array_filter($rows,static function($r)use($fixture){return $r['staff_uuid']===$fixture['staff']['uuid'];}));$ids=array_column($known[$t],'id');$result['natural'][$t]=array_values(array_filter($rows,static function($r)use($ids){return !in_array($r['id'],$ids,true);}));}
$result['staff']=$q('SELECT * FROM '.$p.'staff WHERE UUID=?',[$fixture['staff']['uuid']]);$result['user']=$q('SELECT * FROM '.$p.'user WHERE ID=?',[$fixture['user']['id']]);$result['actor']=$q('SELECT * FROM '.$p.'user WHERE ID=?',[$fixture['actor']['id']]);return $result;};
$guard=static function(array $s,bool $inserted=true)use($fixture,$check):void{foreach(['staff','user','actor']as $t)$check($s[$t]===[$fixture[$t]],'Full reference sentinel '.$t);foreach(['member_weight','member_weight_status']as $t){$check($s['natural'][$t]===$fixture['natural'][$t],'Exact own PK excluded natural '.$t);if($inserted){$own=json_decode(file_get_contents(__DIR__.'/private-fixture-own.json'),true);$check($s['own'][$t]===$own[$t],'Own fixture full source stable '.$t);}else $check($s['own'][$t]===[],'Scope0 before insert');}};
$expected=static function(array $s,string $method,int $page=1)use($lane):array{$rows=[];if($method==='show'){$status=$s['own']['member_weight_status'];usort($status,static function($a,$b){return strcmp($b['create_time'],$a['create_time']);});foreach(array_slice($status,($page-1)*10,10)as $r)$rows[]=['create_time'=>preg_replace('/\.0{1,6}$/','',$r['create_time']),'name'=>$s['user'][0]['name'],'status'=>$r['status'],'energy_value'=>(int)$r['energy_value']];}else{$weight=$s['own']['member_weight'];usort($weight,static function($a,$b){return strcmp($a['ymd'],$b['ymd']);});foreach($weight as $r)$rows[]=['weight'=>(float)$r['weight'],'pbf'=>$r['pbf'],'ymd'=>$r['ymd']];}return ['code'=>0,'message'=>'查询成功','data'=>['rows'=>$rows,'total'=>count($s['own']['member_weight_status'])]];};
