<?php
/**
 * Class Shipment_CustomController
 * 清关数据处理
 */
class Default_CustomController extends Ec_Controller_DefaultAction
{
    public function preDispatch()
    {
        $this->tplDirectory = "default/views/template/";
    }
    /**
     * Note:
     * User: Yao
     * Date: 2018/12/20
     * Time: 11:23
     */
    public function listAction()
    {
        error_reporting(E_ALL);
        $tableName = $this->_request->getParam('t');
        if(empty($tableName)){
            throw new Exception('表名参数错误');
        }
        $table = Service_Bank::getModelInstance()->getAdapter();
        $talbeSql = "select * from information_schema.COLUMNS where TABLE_NAME='{$tableName}' and TABLE_SCHEMA='chukou_wms'";
        $tableInfo = $table->fetchAll($talbeSql);
        if(empty($tableInfo)){
            throw new Exception('表不存在');
        }
        $serviceName = implode('',array_map('ucfirst',explode('_',$tableName)));
         // $path = 'D:/qyoms/application';
         // $path ='D:/exportblwms/trunk/application';
        // $path = 'D:/exportblwms/trunk/application';
        // $path="D:/exportbloms/application";
        // $path = "D:/qywms/application";
        // $path ="D:/kjqinguan/application";
        $path ='E:/www/zhwms/branches/application/';
        // $path = 'D:/jcsys/trunk/application';
        // $path ='D:/hspipei/trunk/application';
        $service = $path.'/models/Service/'.$serviceName.'.php';
        $table = $path.'/models/Table/'.$serviceName.'.php';
        $dbTable = $path.'/models/DbTable/'.$serviceName.'.php';
        $column = array();
        $primaryKey ='';
        foreach($tableInfo as $row){
            if(!($primaryKey)){
                $primaryKey = $row['COLUMN_NAME'];
            }
            $column[]= $row['COLUMN_NAME'];
            $columnNote[]=$row['COLUMN_COMMENT'];
        }
        foreach ($column as $col){
            echo "'".$col."'=>'',";
            echo "<br/>";
        }
        die();
        $this->view->table= $serviceName;
        $this->view->realTable= $tableName;
        $this->view->column=$column;
        $this->view->primaryKey= $primaryKey;
        $this->view->colunmNote =array_chunk($columnNote,2);
        $content = $this->view->render($this->tplDirectory.'service.tpl');
        $tableContent = $this->view->render($this->tplDirectory.'table.tpl');
        $dbContent = $this->view->render($this->tplDirectory.'dbtable.tpl');
//        $content = $this->view->render($this->tplDirectory.'tableForm.tpl');
//        file_put_contents('formTable.html',$content);
//        echo $content;
        file_put_contents($service,$content);
        file_put_contents($table,$tableContent);
        file_put_contents($dbTable,$dbContent);
    }

}
