<?php
class Service_ImportData extends Common_Service
{
    /**
     * @var null
     */
    public static $_modelClass = null;

    /**
     * @return Table_ImportData|null
     */
    public static function getModelInstance()
    {
        if (is_null(self::$_modelClass)) {
            self::$_modelClass = new Table_ImportData();
        }
        return self::$_modelClass;
    }

    /**
     * @param $row
     * @return mixed
     */
    public static function add($row)
    {
        $model = self::getModelInstance();
        return $model->add($row);
    }


    /**
     * @param $row
     * @param $value
     * @param string $field
     * @return mixed
     */
    public static function update($row, $value, $field = "id_id")
    {
        $model = self::getModelInstance();
        return $model->update($row, $value, $field);
    }

    /**
     * @param $value
     * @param string $field
     * @return mixed
     */
    public static function delete($value, $field = "id_id")
    {
        $model = self::getModelInstance();
        return $model->delete($value, $field);
    }

    /**
     * @param $value
     * @param string $field
     * @param string $colums
     * @return mixed
     */
    public static function getByField($value, $field = 'id_id', $colums = "*")
    {
        $model = self::getModelInstance();
        return $model->getByField($value, $field, $colums);
    }

    /**
     * @return mixed
     */
    public static function getAll()
    {
        $model = self::getModelInstance();
        return $model->getAll();
    }

    /**
     * @param array $condition
     * @param string $type
     * @param int $pageSize
     * @param int $page
     * @param string $order
     * @return mixed
     */
    public static function getByCondition($condition = array(), $type = '*', $pageSize = 0, $page = 1, $order = "")
    {
        $model = self::getModelInstance();
        return $model->getByCondition($condition, $type, $pageSize, $page, $order);
    }


    public static function getAllByCondition($condition = array(), $type = '*', $pageSize = 0, $page = 1, $order = "")
    {
        $model = self::getModelInstance();
        return $model->getAllByCondition($condition, $type, $pageSize, $page, $order);
    }

    public static function getGroupByCondition($condition = array(), $type = '*', $pageSize = 0, $page = 1, $order = "")
    {
        $model = self::getModelInstance();
        return $model->getGroupByCondition($condition, $type, $pageSize, $page, $order);
    }

    /**
     * @param $val
     * @return array
     */
    public static function validator($val)
    {
        $validateArr = $error = array();
        
        return  Common_Validator::formValidator($validateArr);
    }
    /**
     * @author william-fan
     * @todo 校验数据
     */
    public static function importCheckData($rows,$bilPayment){
        $check = false;
        //
        $fee_name = '';
        if(!empty($bilPayment) && $bilPayment['ft_code']!=''){
           $feeType =  Service_FeeType::getByField($bilPayment['ft_code'],'ft_code');
           $fee_name = $feeType['ft_name_cn'];
        }
        if(!empty($rows)){
            foreach($rows as $key=>$value){
                if($fee_name==$value['feeType']){
                    return true;
                }
            }
        }
        return $check;
    }

    /**
     * @param array $params
     * @return array
     */
    public  function getFields()
    {
        $row = array(
        
              'E0'=>'id_id',
              'E1'=>'id_code',
              'E2'=>'id_name',
              'E3'=>'id_reference_no',
              'E4'=>'id_reference_date',
              'E5'=>'id_status',
              'E6'=>'payer_code',
              'E7'=>'sm_code',
              'E8'=>'id_note',
              'E9'=>'id_creator_id',
              'E10'=>'id_finish_id',
              'E11'=>'id_add_time',
              'E12'=>'id_finish_time',
              'E13'=>'id_update_time',
        );
        return $row;
    }

}