<?php
/**
 * 更新海关编码
 */
require_once('../config.php');
$flagFile = APPLICATION_PATH . '/../data/log/fixhs.lock';
if (@file_exists($flagFile)) {
    echo 'The running.'."\r\n";
    echo $flagFile."\r\n";
    //exit();
}
$link = fopen($flagFile, 'wb');
fclose($link);
define('RUNTIME', '[' . date('Y-m-d H:i:s') . '] ');
echo RUNTIME . "Startingsss!\n";

set_time_limit(50000);


function updetail($hscode,$hsArr){
    //print_r($hsArr);
    //编码新的信息
    foreach ($hsArr as $kh=>$vhs){
        $condition = array(
            'hs_code'=>$hscode,
            //'he_name'=>$vhs['name'],
            'he_sort'=>$vhs['index']
        );
        $hsRows = Service_HsElement::getByCondition($condition,"*");
        if(count($hsRows)==1){
            //存在了，更新吧
            $upRow = array(
                'he_code'=>$vhs['name'],
                'he_name'=>$vhs['name'],
                'he_update_time'=>date("Y-m-d H:i:s",time())
            );
            $hsRow = $hsRows[0];
            if($hsRow['he_name']!=$vhs['name']){
                $upRow['he_description'] = "2023编码要素更新:{$hsRow['he_name']}-->{$vhs['name']}";
            }
            $he_id = $hsRows[0]['he_id'];
            Service_HsElement::update($upRow,$he_id,'he_id');
        }elseif (count($hsRows)==0){
            //不存在，加入吧
            $addRow = array(
                'hs_code'=>$hscode,
                'he_code'=>$vhs['name'],
                'he_name'=>$vhs['name'],
                'he_sort'=>$vhs['index'],
                'he_add_time'=>date("Y-m-d H:i:s",time()),
                'he_description'=>"2023新增要素:{$vhs['name']}"
            );
            Service_HsElement::add($addRow);

        }else{
            //存在2个？异常了
            throw new Exception($hscode."申报序号:{$vhs['index']}->{$vhs['name']},存在多个");
            return false;
        }
    }
    return true;
}

//添加海关编码和申报要素
function addhs($row,$hsArr){
    $hscode = $row['hs10']; //10位海关编码
    $pinming = $row['pinming'];
    $hsRow = Service_Hscodes::getByField($hscode,'hs_code');
    $hs_category_code = substr($hscode,0,6);
    $zssl = $row['zzsl'];
    $jktj = $row['jktj'];
    $jylb = $row['jylb'];
    $is_license = 0;
    if(strstr($zssl,'AB')){
        $is_license = 1;
    }
    if(empty($hsRow)){
        //添加hs编码数据
        $hsAddRow = array(
            'p_name'=>$pinming,
            'hs_category_code'=>$hs_category_code,
            'hs_code'=>$hscode,
            'hs_code_description'=>'',
            'hs_code_status'=>1,
            'has_tax'=>1,
            'consumption_tax'=>0,
            'added_value_tax'=>$zssl,
            'is_positive'=>1,
            'is_license'=>$is_license,
            //'exempt_value',
            //'ref_level',
            'customs_supervision_type'=>$jktj,
            'ciq_type'=>$jylb
        );
        //print_r($hsAddRow);
        Service_Hscodes::add($hsAddRow);
    }

    //添加要素

    updetail($hscode,$hsArr);

    //处理hs_uom
    $hu = Service_HsUom::getByField($hscode,'hs_code');
    if(empty($hu)){
        $pu_code_law = $row['uom1'];
        $pu_code_second = '';
        if($row['uom2']!=''){
            $pu_code_second = $row['uom2'];
        }
        $huRow = array(
            'hs_code'=>$hscode,
            'pu_code_law'=>$pu_code_law,
            'pu_code_second'=>$pu_code_second,
            'hu_add_time'=>date("Y-m-d H:i:s",time()),
        );
        Service_HsUom::add($huRow);
    }
}

function uphs($row){
    try {
        $db = Common_Common::getAdapter();
        $db->beginTransaction();
        //10位海关编码
        $hscode = $row['hs10']; //10位海关编码
        //规格型号
        $guige = $row['guige'];
        $id = $row['id'];

        //按|切割
        $guigeArr = explode("|",$guige);
        $error = [];
        if(!empty($guigeArr)){
            $hsArr = [];
            foreach ($guigeArr as $k=>$ge){
                $geArr = explode(":",$ge);
                $index = $geArr[0];
                $hsname = $geArr[1];
                if(count($geArr)!=2){
                    $error[] = "申报要素{$ge}不对";
                }
                $hsArr[] = array(
                    'index'=>$index,
                    'name'=>$hsname
                );
            }
        }else{
            $error[] = "数据无效,不含|";
        }

        //查看是否商品有备案了
        $products = Service_Product::getByField($hscode,"hs_code");
        if(empty($products)){
            //没有商品编码备案直接更新了
            $hsCondition = array(
                'hs_code'=>$hscode
            );
            $hsElement = Service_HsElement::getByCondition($hsCondition,"*");
            if(empty($hsElement)){
                //不存在
                //$error[] = "申报要素不存在";
                addhs($row,$hsArr);

            }else{
                updetail($hscode,$hsArr);
            }
        }else{
            $hsCondition = array(
                'hs_code'=>$hscode
            );
            $hsElement = Service_HsElement::getByCondition($hsCondition,"*");
            if(empty($hsElement)){
                //不存在
                //$error[] = "申报要素不存在";
                addhs($row,$hsArr);
            }else{
                updetail($hscode,$hsArr);
            }
        }
        if(!empty($error)){
            throw new Exception(implode("|",$error));
        }
        $sql = "update hs_2023up set dealstatus='1',message='success' where id='$id';";
        $db->query($sql);
        echo $sql;
        //$db->rollBack();
        $db->commit();
    }catch (Exception $e){
        $r = $e->getMessage();
        $db->rollBack();
        echo $r;
        $sql = "update hs_2023up set message='{$r}' where id='$id';";
        echo $sql;
        $db->query($sql);
    }
}

//2023校验后添加海关编码
function addhs2023($row){
    try {
        $db = Common_Common::getAdapter();
        $db->beginTransaction();

        $hs_code = $row['hs_code'];
        $hs_name = $row['hs_name'];
        $first_uom = $row['first_uom'];
        $second_uom = $row['second_uom'];
        $sbys = $row['sbys'];

        $first_uom_code = '';
        $second_uom_code = '';

        $uom1_msg = ""; //法一消息
        $uom2_msg = ""; //法二消息
        $hs_name_msg = ""; //海关名称
        $hselement_msg = ""; //申报要素名称校验消息


        $error=[];
        $firuomRow = Service_ProductUom::getByField($first_uom,'pu_name');
        if(!empty($firuomRow)){
            $first_uom_code = $firuomRow['pu_code'];
        }else{
            $error[] = "法定第一单位代码不存在-->".$first_uom;
            $uom1_msg = "法定第一单位代码不存在-->".$first_uom;
        }
        if($second_uom=='无'){
            $second_uom_code = "";
        }else{
            $secondRow = Service_ProductUom::getByField($second_uom,'pu_name');
            if(!empty($secondRow)){
                $second_uom_code = $secondRow['pu_code'];
            }else{
                $error[] = "法定第二单位代码不存在-->".$second_uom;
                $uom2_msg = "法定第二单位代码不存在-->".$second_uom;
            }
        }

        $sbysArr = explode(";",$sbys);
        if(count($sbysArr)>1){
            $hsArr = [];
            foreach ($sbysArr as $k=>$ge){
                $geArr = explode(":",$ge);
                $index = $geArr[0]-1;
                $hsname = $geArr[1];
                if(count($geArr)!=2){
                    $error[] = "申报要素{$ge}不对";
                    $hselement_msg.="申报要素{$ge}不对|";
                }
                $hsArr[] = array(
                    'index'=>$index,
                    'name'=>$hsname
                );
            }
        }
        if(!empty($error)){
            throw new Exception(implode("|",$error));
        }

        if($row['is_check']=='2'){
            //添加海关编码，申报要素，申报单位
            $hsRow = Service_Hscodes::getByField($hs_code,'hs_code');
            if(empty($hsRow)){
                $hsRowAdd = array(
                    'p_name'=>$hs_name,
                    'hs_category_code'=>substr($hs_code,0,6),
                    'hs_code'=>$hs_code,
                    'hs_code_description'=>'2023新增海关编码',
                    'hs_code_status'=>'1',
                );
                Service_Hscodes::add($hsRowAdd);
            }
            //处理法一法二单位
            $hsUom = Service_HsUom::getByField($hs_code,'hs_code');
            if(empty($hsUom)){
                $hsUomAdd = array(
                    'hs_code'=>$hs_code,
                    'pu_code_law'=>$first_uom_code,
                    'pu_code_second'=>$second_uom_code,
                    'hu_add_time'=>date("Y-m-d H:i:s",time()),
                    'hu_status'=>1,
                );
                Service_HsUom::add($hsUomAdd);
            }
            if(!updetail($hs_code,$hsArr)){
                throw new Exception("海关编码申报要素处理失败:".$hs_code);
            }
        }

        $db->update("hs_2023up",['deal_msg'=>'add success'],"id={$row['id']}");

        echo "aaabbb";


        //$db->rollBack();
        $db->commit();
    } catch (Exception $e){
        $db->rollBack();
        echo $row['id'].$e->getMessage()."\r\n";
        $r = $e->getMessage();

        $sql = "update hs_2023up set deal_msg='{$r}' where id={$row['id']};";
        //echo $sql;
        $db->query($sql);
    }
}



/**
 * @todo 检查海关编码(先校验法一，法二，申报要素是否一样。
 * 法一 法二 申报要素完全一样，那么就不需要更改了。
 * 在查商品)
 *
 * 1）法一 法二不一样情况下（申报要素一样）
 * 再看是否商品备案（
 * 1-1）有商品备案，无账册直接去商品备案更改。）
 * 1-2）有商品备案，有账册 不能改要去海关改账册底账，再改系统的。
 * 1-3）无商品备案（更改法一 法二数据，写日志）
 *
 * 2）法一 法二不一样情况下（申报要素也不一样）
 * 1-1）有商品备案，无账册直接去商品备案更改。）
 * 1-2）有商品备案，有账册 不能改要去海关改账册底账，再改系统的。
 * 1-3）无商品备案（更改法一 法二数据，更改申报要素表，写日志）
 *
 * 3）查旧的海关编码表，有 新的没有，可能是废弃的。（ 已经导出不考虑了
 * select * from hs_codes as hs1
left join hs_2023up as hs2
on hs1.hs_code=hs2.hs_code
having hs2.id is null）
 *
 */
function checkhs($row){
    try{
        $db = Common_Common::getAdapter();
        $db->beginTransaction();

        $hs_code = $row['hs_code'];
        $hs_name = $row['hs_name'];
        $first_uom = $row['first_uom'];
        $second_uom = $row['second_uom'];
        $sbys = $row['sbys'];

        $first_uom_code = '';
        $second_uom_code = '';

        $uom1_msg = ""; //法一消息
        $uom2_msg = ""; //法二消息
        $hs_name_msg = ""; //海关名称
        $hselement_msg = ""; //申报要素名称校验消息


        $error=[];
        $firuomRow = Service_ProductUom::getByField($first_uom,'pu_name');
        if(!empty($firuomRow)){
            $first_uom_code = $firuomRow['pu_code'];
        }else{
            $error[] = "法定第一单位代码不存在-->".$first_uom;
            $uom1_msg = "法定第一单位代码不存在-->".$first_uom;
        }
        if($second_uom=='无'){
            $second_uom_code = "";
        }else{
            $secondRow = Service_ProductUom::getByField($second_uom,'pu_name');
            if(!empty($secondRow)){
                $second_uom_code = $secondRow['pu_code'];
            }else{
                $error[] = "法定第二单位代码不存在-->".$second_uom;
                $uom2_msg = "法定第二单位代码不存在-->".$second_uom;
            }
        }

        $sbysArr = explode(";",$sbys);
        if(count($sbysArr)>1){
            $hsArr = [];
            foreach ($sbysArr as $k=>$ge){
                $geArr = explode(":",$ge);
                $index = $geArr[0]-1;
                $hsname = $geArr[1];
                if(count($geArr)!=2){
                    $error[] = "申报要素{$ge}不对";
                    $hselement_msg.="申报要素{$ge}不对|";
                }
                $hsArr[] = array(
                    'index'=>$index,
                    'name'=>$hsname
                );
            }
        }

        $upRow = [];

        if(!empty($error)){
            $upRow['is_check'] = '1';
            $upRow['check_msg'] = implode("|",$error);
        }else{
            //检查这个编码以前海关编码表是否存在，不存在就检查直接通过表示可以直接添加
            $oldHsRow = Service_Hscodes::getByField($hs_code,'hs_code');
            if(empty($oldHsRow)){
                $upRow['is_check'] = '2';
                $upRow['check_msg'] = "旧编码表不存在";
            }else{
                //旧编码表存在，看是否有更新，包含法定第一单位，法定第二单位，申报要素是否更新。

                //旧的申报单位
                $oldpuRow = Service_HsUom::getByField($hs_code,'hs_code');
                $samefayifaer = false;
                //var_dump($oldpuRow['pu_code_law']==$first_uom_code);
                //var_dump($oldpuRow['pu_code_law'],$first_uom_code);
                if( ($oldpuRow['pu_code_law']==$first_uom_code) ){
                    //法一和法二一样
                    $samefayifaer = true;
                    $upRow['uom1_msg'] = "1";
                }else{
                    //法一法二不一样
                    $error[] = "法一单位不一致{$oldpuRow['pu_code_law']}-->{$first_uom_code}";
                    $upRow['uom1_msg'] = "法一单位不一致{$oldpuRow['pu_code_law']}-->{$first_uom_code}";
                }
                if( ($oldpuRow['pu_code_second']==$second_uom_code)){
                    //法一和法二一样
                    $samefayifaer = true;
                    $upRow['uom2_msg'] = "1";
                }else{
                    //法一法二不一样
                    $error[] = "法二单位不一致{$oldpuRow['pu_code_second']}-->{$second_uom_code}";
                    $upRow['uom2_msg'] = "法二单位不一致{$oldpuRow['pu_code_second']}-->{$second_uom_code}";
                }
                if($samefayifaer){

                }
                if($oldHsRow['p_name']!=$hs_name){
                    $upRow['hs_name_msg'] = "旧编码名称和新编码名称不一致{$oldHsRow['p_name']}-->{$hs_name}";
                }else{
                    $upRow['hs_name_msg'] = "1";
                }

                //旧的申报要素
                $hsCondition = array(
                    'hs_code'=>$hs_code
                );
                $hselements =  Service_HsElement::getByCondition($hsCondition,"*",0,0,'he_sort asc');
                /*print_r($hselements);
                print_r($hsArr);*/
                $hsError = [];
                if(!empty($hselements)){
                    if(count($hselements)!=count($hsArr)){
                        $hsError[] = "旧申报要素和新申报要素数量不一致";
                    }else{
                        foreach ($hselements as $khs=>$vhs){
                            if($vhs['he_name']!=$hsArr[$khs]['name']){
                                $indexhs = $khs+1;
                                $hsError[] = "旧编码第{$indexhs}和新编码不一致{$vhs['he_name']}-->{$hsArr[$khs]['name']}";
                            }
                        }
                    }
                    if(!empty($hsError)){
                        $upRow['hselement_msg'] = implode("|",$hsError);
                    }else{
                        $upRow['hselement_msg'] = "2"; //无需更新
                    }
                }else{
                    //申报要素不存在
                    $upRow['hselement_msg'] = "1";//要添加
                }

                if(!isset($upRow['is_check'])){
                    $upRow['is_check'] = '8';
                }
                //print_r($upRow);
                echo $row['id']."\r\n";



                //检查是否存在备案的商品
                //Service_Product::getByCondition(['hs_code'=>$hs_code],"*");
            }
        }
        if(!empty($upRow)){
            $db->update('hs_2023up',$upRow,"id={$row['id']}");
        }
        //$db->rollBack();
        $db->commit();
    }catch (Exception $e){
        $db->rollBack();
        echo $row['id'].$e->getMessage()."\r\n";
    }
}

function checkproductbill($row){
    try{
        $db = Common_Common::getAdapter();
        $db->beginTransaction();

        $hs_code = $row['hs_code'];
        $products = Service_Product::getByCondition(['hs_code'=>$hs_code],"*");

        $upRow = [];
        if(!empty($products)){
            $product_msg = "";
            foreach ($products as $k=>$p){
                $product_msg.="客户-->{$p['customer_code']},sku-->{$p['product_sku']}|";
            }
            $upRow['product_msg'] = $product_msg;
        }else{
            $upRow['product_msg'] = '1';
        }

        $books = Service_BillBook::getByCondition(['hs_code'=>$hs_code],"*");
        if(!empty($books)){
            $bill_msg = "";
            foreach ($books as $k=>$book){
                $bill_msg.="账册id:{$book['id']}|";
            }
            $upRow['bill_msg'] = $bill_msg;
        }else{
            $upRow['bill_msg'] = '1'; //无账册
        }

        print_r($upRow);
        if(!empty($upRow)){
            $db->update('hs_2023up',$upRow,"id={$row['id']}");
        }



        //查看有无账册



        //$db->rollBack();
        $db->commit();
    }catch (Exception $e){
        $db->rollBack();
        echo $row['id'].$e->getMessage()."\r\n";
    }
}

function execheck(){
    $sql = "select * from hs_2023up where 1 and is_check='-1';";
    echo $sql;
    //exit;
    $db = Common_Common::getAdapter();
    $rows = $db->fetchAll($sql);
    echo "<pre>";
    echo "rows";
    //print_r($rows);
    //exit;
    if(!empty($rows)){
        foreach ($rows as $k=>$row){
            checkhs($row);
            //exit;
        }
    }
}
/**
 * is_check 为2表示不存在编码可以直接假如，
 * is_check 为8表示经过法一，法二以及海关编码校验
 *
 */
function checkproductandbill(){
    $sql = "SELECT * FROM `hs_2023up` where ( (uom1_msg!='1') or (uom2_msg!='1') or (hselement_msg!='2')) ;";
    echo $sql;
    //exit;
    $db = Common_Common::getAdapter();
    $rows = $db->fetchAll($sql);
    echo "<pre>";
    echo "rows";
    //print_r($rows);
    //exit;
    if(!empty($rows)){
        foreach ($rows as $k=>$row){
            checkproductbill($row);
            //exit;
        }
    }
}

//execheck();
//checkproductandbill();

//更新uom
function upHsuom($row){
    try {
        $db = Common_Common::getAdapter();
        $db->beginTransaction();

        $hs_code = $row['hs_code'];
        $hs_name = $row['hs_name'];
        $first_uom = $row['first_uom'];
        $second_uom = $row['second_uom'];
        $sbys = $row['sbys'];

        $first_uom_code = '';
        $second_uom_code = '';

        $uom1_msg = ""; //法一消息
        $uom2_msg = ""; //法二消息
        $hs_name_msg = ""; //海关名称
        $hselement_msg = ""; //申报要素名称校验消息


        $error=[];
        $firuomRow = Service_ProductUom::getByField($first_uom,'pu_name');
        if(!empty($firuomRow)){
            $first_uom_code = $firuomRow['pu_code'];
        }
        if($second_uom=='无'){
            $second_uom_code = "";
        }else {
            $secondRow = Service_ProductUom::getByField($second_uom, 'pu_name');
            if(!empty($secondRow)){
                $second_uom_code = $secondRow['pu_code'];
            }
        }
        //没有商品备案
        if($row['product_msg']=='1'){
            $uomRow = array(
                'pu_code_law'=>$first_uom_code,
                'pu_code_second'=>$second_uom_code,
                'hu_update_time'=>date("Y-m-d H:i:s",time())
            );
            if(!Service_HsUom::update($uomRow,$hs_code,'hs_code')){
                throw new Exception("更新编码法一法二失败".$hs_code);
            }else{
                $db->update("hs_2023up",['deal_msg'=>'uomsuccess'],"id={$row['id']}");
            }
        }else{
            //有商品备案
            if($row['bill_msg']=='1'){
                //无账册情况下直接改

            }else{

            }
            $db->update("hs_2023up",['deal_msg'=>'uomfaise,有商品备案请打回草稿重新备案'],"id={$row['id']}");
        }
        //print_r($row);
        //$db->rollBack();
        //echo "0000";

        $db->commit();
    }catch (Exception $e){
        $r = $e->getMessage();
        $db->rollBack();
        echo $r;
        $sql = "update hs_2023up set deal_msg='{$r}' where id={$row['id']};";
        //echo $sql;
        $db->query($sql);
    }
}

//更新申报要素
function upHselement($row){
    try {
        $db = Common_Common::getAdapter();
        $db->beginTransaction();

        $hs_code = $row['hs_code'];
        $hs_name = $row['hs_name'];
        $first_uom = $row['first_uom'];
        $second_uom = $row['second_uom'];
        $sbys = $row['sbys'];

        $error = [];

        $updateRow = [];

        $sbysArr = explode(";",$sbys);
        if(count($sbysArr)>1){
            $hsArr = [];
            foreach ($sbysArr as $k=>$ge){
                $geArr = explode(":",$ge);
                $index = $geArr[0]-1;
                $hsname = $geArr[1];
                if(count($geArr)!=2){
                    $error[] = "申报要素{$ge}不对";
                    $hselement_msg.="申报要素{$ge}不对|";
                }
                $hsArr[] = array(
                    'index'=>$index,
                    'name'=>$hsname
                );
            }
        }
        if (empty($error)){
            //没有备案商品
            if($row['product_msg']=='1'){
                //申报要素不一样，删除重建
                if($row['hselement_msg']!='2'){
                    //删除重建
                    if(!Service_HsElement::delete($hs_code,"hs_code")){
                        throw new Exception("删除编码申报要素错误：".$hs_code);
                    }else{
                        if(!updetail($hs_code,$hsArr)){
                            throw new Exception("添加编码申报要素错误：".$hs_code);
                        }else{
                            $updateRow['deal_msg'] = "success";
                        }
                    }
                }
            }else{
                //有备案商品
                $updateRow['deal_msg'] = "需人工核查";
            }
        }
        if(!empty($updateRow)){
            $db->update("hs_2023up",$updateRow,"id={$row['id']}");
            $db->commit();
        }else{
            throw new Exception("未发现更新".$hs_code);
        }

        print_r($updateRow);
        //SELECT * FROM `hs_2023up` where ( (uom1_msg='1') and (uom2_msg='1') )  and hselement_msg!='2' and deal_msg is null
        //$db->rollBack();

        echo "999";

    }catch (Exception $e){
        $r = $e->getMessage();
        $db->rollBack();

        $sql = "update hs_2023up set deal_msg='{$r}' where id={$row['id']};";
        //echo $sql;
        $db->query($sql);
    }
}

function fixhscode1(){
    //SELECT * FROM `hs_2023up` where ( (uom1_msg!='1') or (uom2_msg!='1') or (hselement_msg!='2')) and product_msg!='1'
    //1）法一 法二不一样情况下（申报要素一样） 1-3）无商品备案（更改法一 法二数据，写日志）
    $sqlsamefayifaer = "SELECT * FROM `hs_2023up` where ( (uom1_msg!='1') or (uom2_msg!='1') ) and  product_msg='1' and hselement_msg='2' and deal_msg is null";
    $db = Common_Common::getAdapter();
    $rows = $db->fetchAll($sqlsamefayifaer);
    if(!empty($rows)){
        foreach ($rows as $k=>$row){
            //upHsuom($row);
        }
    }

    //法一 法二不一样情况下（申报要素也不一样）
    $sqlsamefayifaer_elementnoteq = "SELECT * FROM `hs_2023up` where ( (uom1_msg!='1') or (uom2_msg!='1') ) and  product_msg='1' and hselement_msg!='2' and deal_msg is null";
    $rows = $db->fetchAll($sqlsamefayifaer_elementnoteq);
    //echo count($rows);
    if(!empty($rows)){
        foreach ($rows as $k=>$row){
           /* upHsuom($row); //更新法一
            upHselement($row);//更新申报要素*/
        }
    }
    //法一法二一样，申报要素不一样。
    $sqlelementNoteq = "SELECT * FROM `hs_2023up` where ( (uom1_msg='1') and (uom2_msg='1') )  and hselement_msg!='2' and deal_msg is null";
    $rows = $db->fetchAll($sqlelementNoteq);
    echo count($rows);
    //exit;
    if(!empty($rows)){
        foreach ($rows as $k=>$row){
            print_r($row);
            upHselement($row); //更新申报要素
            //exit;
        }
    }
    exit;
    //旧编码不存在的，直接增加
    $sqlhsnotexist = "SELECT * FROM `hs_2023up` where 1  and is_check='2' and  deal_msg is null;";
    $rows = $db->fetchAll($sqlhsnotexist);
    if(!empty($rows)){
        foreach ($rows as $k=>$row){
            //print_r($row);
            //upHsuom($row); //更新法一
            addhs2023($row);
            //exit;
        }
    }
}

fixhscode1();




