<?php
declare(strict_types=1);$_SERVER['HTTP_HOST']='owned-weight.invalid';require __DIR__.'/app.php';require __DIR__.'/data.php';$app=coreApp('PREPARE');ck(file_exists($runtime.'/preflight-state.json')&&file_exists($runtime.'/preflight-ready.json')&&!file_exists($runtime.'/prepare-attempt.json'),'Complete read-only preflight and prepare once');saveOnce('prepare-attempt.json',['at'=>date('c'),'cap_INSERT'=>2]);$p=nativePdo('AI');$marker='CDXWGT11_'.$lane.'_U1';$user=['store_id'=>10001,'nick_name'=>$marker,'mobile'=>'00000009992','gender'=>1,'avatar_id'=>0,'platform'=>'api','business'=>'zhct','channel'=>'10000','is_delete'=>0,'balance'=>'0.00','gift_balance'=>'0.00','pay_money'=>'0.00'];$p->beginTransaction();event('prepare-native.jsonl',['operation'=>'begin','success'=>true]);
try{foreach(['user','staff'] as $t){$v=$t==='user'?$user:['user_id'=>$uid,'store_id'=>10001,'name'=>$marker,'phone'=>'00000009992','gender'=>1,'birthday'=>'2000-01-01','height'=>'180.25','weight'=>'70.00','is_delete'=>0,'create_by'=>'CDXWGT11'];$sql='INSERT INTO yoshop_'.$t.' ('.implode(',',array_keys($v)).') VALUES ('.implode(',',array_fill(0,count($v),'?')).')';consumeSQL('prepare.INSERT');$s=$p->prepare($sql);$b=[];foreach(array_values($v) as $i=>$x){$type=is_int($x)?1:2;$s->bindValue($i+1,$x,$type);$b[]=['position'=>$i+1,'value'=>$x,'php_type'=>gettype($x),'pdo_type'=>$type];}$ok=$s->execute();event('prepare-native.jsonl',['queryString'=>$sql,'bindValue'=>$b,'success'=>$ok,'affected'=>$s->rowCount()]);ck($ok&&$s->rowCount()===1,'Exact prepare affected1');$id=$p->lastInsertId();ck(ctype_digit((string)$id)&&(int)$id>0,'Genuine generated identity');if($t==='user')$uid=(int)$id;else $sid=(int)$id;}$p->commit();event('prepare-native.jsonl',['operation'=>'commit','success'=>true]);saveOnce('owned-actor.json',['user_id'=>$uid,'staff_id'=>$sid,'store_id'=>10001,'marker'=>$marker]);$rows=ownRows();foreach($rows as $t=>$r)ck(count($r)===(in_array($t,['user','staff'],true)?1:0),'Exact fresh owned rows '.$t);saveOnce('prepared-owned-rows.json',['rows'=>$rows,'decimal_text'=>decimals()]);echo json_encode(['lane'=>$lane,'prepare_INSERT'=>2,'actor'=>$uid,'staff'=>$sid,'HTTP'=>0]),"\n";}catch(Throwable $e){if($p->inTransaction())$p->rollBack();saveOnce('prepare-error.json',['class'=>get_class($e),'message'=>$e->getMessage(),'committed'=>!$p->inTransaction()]);throw $e;}
