<?php
class Service_OutboundBag extends Common_Service
{
    /**
     * @var null
     */
    public static $_modelClass = null;

    /**
     * @return Table_OutboundBag|null
     */
    public static function getModelInstance()
    {
        if (is_null(self::$_modelClass)) {
            self::$_modelClass = new Table_OutboundBag();
        }
        return self::$_modelClass;
    }
    
    /**
     * 创建包袋
     * @author solar
     * @param string $ob_no 包袋号
     * @param string $sm_code 运输方式code
     * @return boolean
     */
    public static function create($ob_no, $sm_code,$ob_trade_mode="") {
    	$row['ob_no'] = $ob_no;
    	$row['warehouse_id'] = Service_User::getUserWarehouseId();
    	$row['ob_status'] = 0;
    	$row['sm_code'] = $sm_code;
    	$row['creater_id'] = Service_User::getUserId();
    	$row['ob_add_time'] = date('Y-m-d H:i:s');
        $row['ob_trade_mode'] = $ob_trade_mode;
    	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 = "ob_id")
    {
        $model = self::getModelInstance();
        return $model->update($row, $value, $field);
    }

    /**
     * @param $value
     * @param string $field
     * @return mixed
     */
    public static function delete($value, $field = "ob_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 = 'ob_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 getLeftJoinUserByCondition($condition = array(), $type = '*', $pageSize = 0, $page = 1, $order = "")
    {
        $model = self::getModelInstance();
        return $model->getLeftJoinUserByCondition($condition, $type, $pageSize, $page, $order);
    }

    public static function getJoinOrderByCondition($condition = array(),$type='*',$pageSize=0,$page=1,$order=""){
        $model = self::getModelInstance();
        return $model->getJoinOrderByCondition($condition,$type,$pageSize,$page,$order);
    }

    public static function getExportFileJoinByCondition($condition = array(),$type='*',$pageSize=0,$page=1,$order=""){
        $model = self::getModelInstance();
        return $model->getExportFileJoinByCondition($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' => 'ob_id',
            'E1' => 'ob_no',
            'E2' => 'warehouse_id',
            'E3' => 'ob_status',
            'E4' => 'sm_code',
            'E5' => 'ob_weight',
            'E6' => 'creater_id',
            'E7' => 'ob_add_time',
            'E8' => 'ob_update_time',
            'E20' => 'order_code',
            'E21' => 'reference_no',
            'E22' => 'ob_trade_mode',
            'E23' => 'ob_num',
        );
        return $row;
    }

}