<?php
declare(strict_types=1);
define('RFJ_CONTEXT_ONLY',true);require __DIR__.'/preflight.php';
$missing=2147000000;if($q($store,'SELECT ID FROM '.$s.'meal_order_refund WHERE ID=?',[$missing])!==[])throw new RuntimeException('Synthetic missing ID unexpectedly exists');
$snapshot=static function()use($store,$ai,$q,$s,$a,$chosen):string{$data=['store_user'=>$q($store,'SELECT * FROM '.$s.'user WHERE ID=?',[(int)$chosen['store_user']['id']]),'store_orders'=>$q($store,'SELECT * FROM '.$s.'meal_order WHERE USER_ID=? ORDER BY ID',[(int)$chosen['store_user']['id']])];foreach(['user','user_balance_log','user_subsidy','user_subsidy_log','user_subsidy_used','user_gift_log','account_settlement'] as $table){$rows=$q($ai,'SELECT * FROM '.$a.$table.' WHERE USER_ID=?',[(int)$chosen['ai_user']['user_id']]);foreach($rows as &$row)ksort($row);unset($row);usort($rows,static function($x,$y){return strcmp(serialize($x),serialize($y));});$data['ai_'.$table]=$rows;}return hash('sha256',serialize($data));};
$before=$snapshot();$actor=$q($store,'SELECT ID,UUID FROM '.$s.'user WHERE ID=(SELECT MIN(ID) FROM '.$s.'user WHERE TYPE=0 AND IS_DELETE=0)')[0];require_once $root.'/application/base/Security.php';$token=\app\base\Security::encrypt(implode("\t",[(string)$actor['id'],(string)$actor['uuid'],'CDXRFJ10AUDIT','0','','','CDXRFJ10AUDIT']));
$raw=file_get_contents('http://127.0.0.1:'.($lane==='B'?18301:18302).'/p/mealOrder/refundReject',false,stream_context_create(['http'=>['method'=>'POST','header'=>'token: '.$token."\r\nContent-Type: application/x-www-form-urlencoded\r\n",'content'=>http_build_query(['refund_id'=>$missing]),'ignore_errors'=>true,'timeout'=>20]]));$body=json_decode($raw,true);preg_match('#^HTTP/\S+\s+(\d+)#',$http_response_header[0]??'',$m);$unchanged=$before===$snapshot();$ok=(int)($m[1]??0)===200&&$body===['code'=>'2','message'=>'退款订单不存在','data'=>[]]&&$unchanged;
echo json_encode(['lane'=>$lane,'scenario'=>'positive_missing_refund_db_join','method'=>'POST','path'=>'/p/mealOrder/refundReject','http_status'=>(int)($m[1]??0),'code'=>$body['code']??null,'code_type'=>gettype($body['code']??null),'data_type'=>gettype($body['data']??null),'positive_id_independently_absent'=>true,'full_raw_wire_sha256'=>hash('sha256',$raw),'both_business_databases_sources_unchanged'=>$unchanged,'source_before_sha256'=>$before,'database_writes'=>0,'all_passed'=>$ok]),"\n";exit($ok?0:2);
