<?php
class Service_TrackingErrorLog extends Common_Service
{
    /**
     * @var null
     */
    public static $_modelClass = null;

    /**
     * @return Table_Orders|null
     */
    public static function getModelInstance()
    {
        if (is_null(self::$_modelClass)) {
            self::$_modelClass = new Table_TrackingErrorLog();
        }
        return self::$_modelClass;
    }

    /**
     * @param $row
     * @return mixed
     */
    public static function add($row)
    {
        $model = self::getModelInstance();
        $now=date('Y-m-d H:i:s');
        if(isset($row['order_code'])&&$row['order_code']!=''){
            $info=self::getByField($row['order_code'],'order_code');
            if(!empty($info)){
                $row['update_time']=$now;
                $row['count']=$info['count']+1;
                return self::update($row, $info['te_id'], 'te_id');
            }
        }
        $row['add_time'] =$now;
        $row['update_time']=$now;
        return $model->add($row);
    }


    /**
     * @param $row
     * @param $value
     * @param string $field
     * @return mixed
     */
    public static function update($row, $value, $field = "te_id")
    {
        $model = self::getModelInstance();
        return $model->update($row, $value, $field);
    }
    /**
     * @param $value
     * @param string $field
     * @return mixed
     */
    public static function delete($value, $field = "te_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 = 'te_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'=>'te_id',
              'E1'=>'order_code',
              'E2'=>'sm_code',
              'E3'=>'add_time',
              'E4'=>'content',
              'E5'=>'type',
              'E6'=>'count',
              'E7'=>'update_time',
        );
        return $row;
    }
    
}