<?php
class Service_OrderLog extends Common_Service
{
    /**
     * @var null
     */
    public static $_modelClass = null;

    /**
     * @return Table_OrderLog|null
     */
    public static function getModelInstance()
    {
        if (is_null(self::$_modelClass)) {
            self::$_modelClass = new Table_OrderLog();
        }
        return self::$_modelClass;
    }
    
    /**
     * 订单日志
     * @author solar
     * @param int $order_id
     * @param string $order_code
     * @param int $ol_type 变更类型,0状态;1内容
     * @param int $status_from
     * @param int $status_to
     * @param string $comments
     */
    public static function log($order_id, $order_code, $status_from, $status_to, $ol_type, $comments) {
    	$row['order_id'] = $order_id;
    	$row['order_code'] = $order_code;
    	$row['ol_type'] = $ol_type;
    	$row['order_status_from'] = $status_from;
    	$row['order_status_to'] = $status_to;
    	$row['ol_add_time'] = date('Y-m-d H:i:s');
    	$row['user_id'] = Service_User::getUserId();
    	$row['ol_ip'] = Common_Common::getIP();
    	$row['ol_comments'] = $comments;
    	return self::add($row);
    }

    /**
     * @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 = "ol_id")
    {
        $model = self::getModelInstance();
        return $model->update($row, $value, $field);
    }

    /**
     * @param $value
     * @param string $field
     * @return mixed
     */
    public static function delete($value, $field = "ol_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 = 'ol_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 $val
     * @return array
     */
    public static function validator($val)
    {
        $validateArr = $error = array();
        
        return  Common_Validator::formValidator($validateArr);
    }


    /**
     * @param array $params
     * @return array
     */
    public  function getFields()
    {
        $row = array(
        
              'E0'=>'ol_id',
              'E1'=>'order_id',
              'E2'=>'order_code',
              'E3'=>'ol_type',
              'E4'=>'order_status_from',
              'E5'=>'order_status_to',
              'E6'=>'ol_add_time',
              'E7'=>'user_id',
              'E8'=>'ol_ip',
              'E9'=>'ol_comments',
        );
        return $row;
    }

}