<?php
function typeDevices($type){return $type===2?['strength']:($type===3?['elliptical','bicycle']:['treadmill']);}
function fastSnapshot(){global $runtime;$s=json_decode(file_get_contents($runtime.'/fast-scope.json'),true);$uid=actor()['user_id'];$devices=$s['devices'];$q=implode(',',array_fill(0,count($devices),'?'));$own=readNative('ZHCT','SELECT * FROM ydy_measurement_session WHERE ai_user_id=? AND vendor=? AND is_valid=1 AND device_type IN ('.$q.') ORDER BY start_time DESC',array_merge([$uid,'yingjiduo'],$devices));$global=readNative('ZHCT','SELECT * FROM ydy_measurement_session WHERE vendor=? AND is_valid=1 AND device_type IN ('.$q.') AND ((start_time>=? AND start_time<=?) OR (start_time>=? AND start_time<=?)) ORDER BY session_id',array_merge(['yingjiduo'],$devices,['2026-01-01 00:00:00','2026-12-31 23:59:59',$s['day'].' 00:00:00',$s['day'].' 23:59:59']));$map=[];foreach(array_merge($own,$global) as $r)$map[$r['session_id']]=$r;$ids=array_keys($map);$health=$ids?readNative('ZHCT','SELECT * FROM ydy_health_record WHERE session_id IN ('.implode(',',array_fill(0,count($ids),'?')).') ORDER BY record_id',$ids):[];$users=array_values(array_unique(array_column($global,'ai_user_id')));$staff=$users?readNative('ZHCT','SELECT id,ai_user_id,name FROM ydy_staff WHERE ai_user_id IN ('.implode(',',array_fill(0,count($users),'?')).') ORDER BY id',$users):[];$staffMax=$users?readNative('ZHCT','SELECT ai_user_id,MAX(name) nickname,COUNT(*) staff_rows FROM ydy_staff WHERE ai_user_id IN ('.implode(',',array_fill(0,count($users),'?')).') GROUP BY ai_user_id',$users):[];$sign=[];$address=[];$files=[];if($s['sign_id']>0){$sign=readNative('AI','SELECT * FROM yoshop_sign_action WHERE id=? AND store_id=?',[$s['sign_id'],10001]);$address=readNative('AI','SELECT * FROM yoshop_sign_address WHERE action_id=? AND is_delete=0',[$s['sign_id']]);$fids=array_values(array_filter(array_unique([$sign[0]['cover_img_id'],$sign[0]['rule_img_id']])));if($fids)$files=readNative('AI','SELECT * FROM yoshop_upload_file WHERE file_id IN ('.implode(',',array_fill(0,count($fids),'?')).') AND store_id=? AND is_delete=0 AND is_recycle=0 ORDER BY file_id DESC',array_merge($fids,[10001]));}return ['own_sessions'=>$own,'global_sessions'=>$global,'health'=>$health,'rank_staff_names'=>$staff,'rank_staff_max'=>$staffMax,'sign'=>$sign,'address'=>$address,'files'=>$files];}
function fastProtection(){global $runtime;$old=readNative('AI','SELECT * FROM yoshop_user WHERE user_id=? AND store_id=?',[actor()['user_id'],10001]);$staff=readNative('AI','SELECT * FROM yoshop_staff WHERE user_id=? AND store_id=?',[actor()['user_id'],10001]);$new=json_decode(file_get_contents($runtime.'/AI-baseline.json'),true);$uid=$new['user'][0]['user_id'];$newRows=[];foreach(['user'=>'user_id','staff'=>'id','user_weight'=>'id','user_weight_status'=>'id','user_course'=>'id','user_score'=>'id','user_score_log'=>'id','user_bind'=>'bind_id','user_health_metric_record'=>'id'] as $t=>$pk)$newRows[$t]=readNative('AI','SELECT * FROM yoshop_'.$t.' WHERE user_id=? ORDER BY '.$pk,[$uid]);ck($newRows===$new,'Prior ownnew9 exact');$related=['user_disease'=>readNative('AI','SELECT * FROM yoshop_user_disease WHERE user_id=? ORDER BY id',[$uid]),'habit'=>readNative('AI','SELECT * FROM yoshop_habit WHERE staff_id=? ORDER BY id',[$new['staff'][0]['id']]),'user_other_info'=>readNative('AI','SELECT * FROM yoshop_user_other_info WHERE user_id=? ORDER BY id',[$uid])];ck($related===json_decode(file_get_contents($runtime.'/disease-baseline.json'),true),'Prior Disease/Habit/OtherInfo exact');return ['actor'=>$old,'actor_staff'=>$staff,'prior_new9'=>$newRows,'prior_related'=>$related,'funds'=>funds(),'scope'=>'Only related rank staff names, not globalStoreStaff/Prepay raw unchanged claim'];}
