<?php
/**
 * Created by JetBrains PhpStorm.
 * User: user
 * Date: 15-11-25
 * Time: 上午10:53
 * To change this template use File | Settings | File Templates.
 */
class Service_Remote extends Common_Service
{
    /**
     * @var null
     */
    public static $_modelClass = null;

    public static function getModelInstance(){
        if (is_null(self::$_modelClass)) {
            self::$_modelClass = new Table_Remote();
        }
        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 = "r_id"){
        $model = self::getModelInstance();
        return $model->update($row, $value, $field);
    }

    /**
     * @param $value
     * @param string $field
     * @return mixed
     */
    public static function delete($value, $field = "r_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 = 'r_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);
    }

    /**
     * @param array $params
     * @return array
     */
    public  function getFields()
    {
        $row = array(
            'E0'=>'r_id',
            'E1'=>'city_name',
            'E2'=>'country_id',
            'E3'=>'country_name_en',
            'E4'=>'postcode_no',
            'E5'=>'postcode_no_end',
            'E6'=>'sm_id',
            'E8'=>'sm_code',
            'E7'=>'warehouse_id',
        );
        return $row;
    }
}
