<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 18-4-11
 * Time: 下午4:37
 * To change this template use File | Settings | File Templates.
 */
class Service_AutopackInfo extends Common_Service
{
    /**
     * @var null
     */
    public static $_modelClass = null;

    public static function getModelInstance(){
        if(is_null(self::$_modelClass)){
            self::$_modelClass = new Table_AutopackInfo();
        }
        return self::$_modelClass;
    }

    public static function add($row){
        $model = self::getModelInstance();
        return $model->add($row);
    }

     public static function update($row, $value, $field = "api_id"){
         $model = self::getModelInstance();
         return $model->update($row, $value, $field);
     }

    public static function delete($value, $field = "api_id"){
        $model = self::getModelInstance();
        return $model->delete($value, $field);
    }

    public static function getByField($value, $field = 'api_id', $colums = "*"){
        $model = self::getModelInstance();
        return $model->getByField($value, $field, $colums);
    }

    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 getAll(){
        $model = self::getModelInstance();
        return $model->getAll();
    }

    public static function validator($val)
    {
        $validateArr = $error = array();

        $validateArr[] = array("name" =>EC::Lang('customerCode'), "value" =>$val["customer_code"], "regex" => array("require",));
        $validateArr[] = array("name" =>EC::Lang('smCode'), "value" =>$val["sm_code"], "regex" => array("require",));
        return  Common_Validator::formValidator($validateArr);
    }

    public  function getFields()
    {
        $row = array(

            'E0'=>'api_id',
            'E1'=>'customer_id',
            'E2'=>'customer_code',
            'E3'=>'sm_code',
        );
        return $row;
    }

}
