<?php
declare(strict_types=1);$_SERVER['HTTP_HOST']='core.scan-pay.invalid';$_SERVER['HTTP_PLATFORM']='POC';$_SERVER['REQUEST_METHOD']='GET';$_SERVER['REQUEST_URI']='/api/PrepayOrder/scan';$_SERVER['SCRIPT_NAME']='/index.php';require __DIR__.'/app.php';ck(!file_exists($runtime.'/guard.json')&&!file_exists($runtime.'/guard-fresh-attempt.json'),'Original guard once');saveOnce('guard-fresh-attempt.json',['lane'=>$lane,'at'=>date('c')]);
try{$app=coreApp('GUARD_FRESH');require_once $root.'/app/api/common.php';ck(hash_file('sha256',$root.'/app/api/common.php')===json_decode(file_get_contents(__DIR__.'/source-frozen-sha.json'),true)['files']['app/api/common.php'],'Original API common pin');$ids=CoreGate::$ids;$before=ownSnapshot();$old=oldProtection();$tokens=[];foreach(['U1'=>'AI_U1','U2'=>'AI_U2'] as $name=>$entry){$token='CDXCORE11S1_'.$lane.'_'.$name.'_'.bin2hex(random_bytes(24));ck(\think\facade\Cache::set($token,['user'=>['user_id'=>$ids[$entry]],'password_version'=>0,'login_type'=>'thirdparty'],300),'Original own FileCache token');$u=\app\api\model\User::getUserByToken($token);ck($u&&(int)$u['user_id']===$ids[$entry]&&(int)$u['store_id']===2147001111,'Original API User token/profile tenant');$tokens[$name]=$token;}
$controller=new \app\api\controller\PrepayOrder($app);$g=new \app\common\service\onecard\UserGuard();$guardAi=$g->isOneCardUserByAiUserId($ids['AI_U1']);$guardZhct=$g->isOneCardUserByZhctIdentity($ids['STORE_U1'],$before['STORE_S1'][0]['uuid']);ck($guardAi===false&&$guardZhct===false,'Original actual OneCard UserGuard false');ck($before['one_card_account_map']===[]&&$before['staff_department']===[]&&$before['user_subsidy']===[]&&$before['user_gift_log']===[],'New identity map/department/subsidy/gift rows0');$balances=(new \app\common\service\account\AccountSettlementService())->getAvailableBalance($ids['AI_U1'],date('Y-m-d H:i:s'));$calc=(new \app\common\service\meal\MarketingStrategyCalculator())->applyByAiUserId($ids['AI_U1'],'0.01',date('Y-m-d H:i:s'),$ids['STORE_R1'],4,$ids['STORE_U1'],1);$limit=(new \app\common\service\consumeLimit\ConsumeLimitEvaluator())->assertAllowed($ids['AI_U1'],$ids['STORE_R1'],1,date('Y-m-d H:i:s'),'direct_pay','0.01');ck($limit['allowed']===true&&$limit['restricted_account_types']===[],'Original consume-limit no-match');ck($calc['marketing_strategy_id']===0&&$calc['pay_price']==='0.01','Original marketing no-match');$cast=getenv('POC_DIALECT')==='dm'?'VARCHAR(40)':'CHAR';$cash=readNative('AI','SELECT CAST(balance AS '.$cast.') balance_text,CAST(gift_balance AS '.$cast.') gift_text,CAST(pay_money AS '.$cast.') pay_text FROM yoshop_user WHERE user_id=?',[$ids['AI_U1']]);require_once __DIR__.'/decimal-oracle.php';ck(dec102text($cash[0]['balance_text'])==='1.00'&&dec102text($cash[0]['gift_text'])==='0.00'&&dec102text($cash[0]['pay_text'])==='0.00','Server exact money lease before HTTP');$order=readNative('ZHCT','SELECT config_value FROM ydy_config WHERE config_key=? AND restaurant_id=? AND status=1',['account_deduction_order',1],true);$sequence=json_decode($order[0]['config_value']??'',true);ck($sequence===['gift','subsidy','cash'],'Actual deduction order unchanged');ck($old===oldProtection()&&$before===ownSnapshot(),'No original guard mutations');saveOnce('tokens.json',$tokens);saveOnce('guard.json',['lane'=>$lane,'original_Auth_U1_U2'=>true,'original_API_Controller_store_check'=>true,'Guard_AI'=>$guardAi,'Guard_StoreIdentity'=>$guardZhct,'balances'=>$balances,'marketing'=>$calc,'consume_limit'=>$limit,'deduction_order'=>$sequence,'own_fullrows'=>$before,'old_protection'=>$old,'redis_branch'=>'Original FileCache fallback only; ownworker redis.hostname empty','created_at'=>date('c'),'business_DML'=>0,'HTTP'=>0]);echo json_encode(['lane'=>$lane,'original_auth2'=>true,'original_guard_false'=>true,'fullrow_leases'=>7,'department_map_subsidy_gift0'=>true,'cash'=>'1.00','HTTP'=>0,'DML'=>0]),"\n";}catch(Throwable $e){saveOnce('guard-fresh-failed.json',['class'=>get_class($e),'message'=>$e->getMessage(),'file'=>$e->getFile(),'line'=>$e->getLine()]);throw $e;}
