<?php
require_once 'config.php';
$arr = [
    'SOC04260446161',
    'SOC04260448793',
    'SOC04260448798',
    'SOC04260451134',
    'SOC04260451698',
    'SOC04260454630',
    'SOC04260449276',
    'SOC04260455735',
    'SOC04260454945',
    'SOC04260455498',
    'SOC04260448922',
    'SOC04260473172',
    'SOC04260445348',
    'SOC04260462429',
    'SOC04260456442',
    'SOC04260455082',
    'SOC04260457590',
    'SOC04260458657',
    'SOC04260462497',
    'SOC04260455611',
    'SOC04260474195',
    'SOC04260455244',
    'SOC04260459100',
    'SOC04260462120',
    'SOC04260456951',
    'SOC04260448849',
    'SOC04260448666',
    'SOC04260474640',
    'SOC04260462388',
    'SOC04260454866',
    'SOC04260456563',
    'SOC04260455872',
    'SOC04260456945',
    'SOC04260468879',
    'SOC04260467981',
    'SOC04260459275',
    'SOC04260460665',
    'SOC04260453745',
    'SOC04260476700',
    'SOC04260465254',
    'SOC04260476526',
    'SOC04260476094',
    'SOC04260479292',
    'SOC04260475568',
    'SOC04260479436',
    'SOC04260480059',
    'SOC04260454398',
    'SOC04260448609',
    'SOC04260448614',
    'SOC04260479162',
    'SOC04260480735'
];

echo "<pre>";
echo "ddd";//exit;
function deal(){
    $return = [
        'state' => 0,
        'message' => 'fail',
        'inv_code' => [],
    ];
    $db = Common_Common::getAdapter();
    $db->beginTransaction();
    try {
        $codeArray = [
            'SOC04260446161',
            'SOC04260448793',
            'SOC04260448798',
            'SOC04260451134',
            'SOC04260451698',
            'SOC04260454630',
            'SOC04260449276',
            'SOC04260455735',
            'SOC04260454945',
            'SOC04260455498',
            'SOC04260448922',
            'SOC04260473172',
            'SOC04260445348',
            'SOC04260462429',
            'SOC04260456442',
            'SOC04260455082',
            'SOC04260457590',
            'SOC04260458657',
            'SOC04260462497',
            'SOC04260455611',
            'SOC04260474195',
            'SOC04260455244',
            'SOC04260459100',
            'SOC04260462120',
            'SOC04260456951',
            'SOC04260448849',
            'SOC04260448666',
            'SOC04260474640',
            'SOC04260462388',
            'SOC04260454866',
            'SOC04260456563',
            'SOC04260455872',
            'SOC04260456945',
            'SOC04260468879',
            'SOC04260467981',
            'SOC04260459275',
            'SOC04260460665',
            'SOC04260453745',
            'SOC04260476700',
            'SOC04260465254',
            'SOC04260476526',
            'SOC04260476094',
            'SOC04260479292',
            'SOC04260475568',
            'SOC04260479436',
            'SOC04260480059',
            'SOC04260454398',
            'SOC04260448609',
            'SOC04260448614',
            'SOC04260479162',
            'SOC04260480735'
        ];
        if (empty($codeList)) {
            //throw new Exception('单号为空');
        }
        $codeArray = array_filter($codeArray);
        $type = 3;
        if(empty($type)){
            throw new Exception('请选择类型');
        }
        print_r($codeArray);
        //exit;
        $etpsInfo = '2';
        if(empty($etpsInfo)){
            //throw new Exception('请选择经营企业信息');
        }
        $invConfig = new Api_Inv_Config();
        $headConfig = $invConfig->getInvHeadConfig($etpsInfo);

        if($type == 1){
            $invFestProcess = new Process_InvOrder();
        }elseif ($type ==3){
            $invFestProcess = new Process_InvReturnOrder();
        }else{
            $invFestProcess = new Process_InvExportOrder();
        }
        var_dump($invFestProcess);
        //exit;
        $invFestProcess->setHeadInfo($headConfig);
        $searchType = 'order_code';
        if ($searchType == 'sb_code') {
            $result = $invFestProcess->createMainifestBySbcode($codeArray);
        } elseif ($searchType == 'order_code') {
            $result = $invFestProcess->createMainifestByorderCode($codeArray);
        }else{
            //throw new Exception('不存在该类型');
        }
        var_dump($result);
        if($result['state'] != 1){
            //throw new Exception('创建汇单失败');
        }
        $return['success'] = $result['success'];
        $return['message'] = "创建成功：汇单号：" . $result['code'];
        $return['fail'] = array_diff($codeArray,$result['success']);
        $return['state'] = 1;
        //$db->commit();
        $db->rollBack();
    } catch (Exception $e) {
        echo $e;
        $return['message'] = $e->getMessage();
        $db->rollBack();
    }


    //die(Zend_Json::encode($return));
}
deal();