<?php
class Service_OrderProduct
{
    /**
     * @var null
     */
    public static $_modelClass = null;

    /**
     * @return Table_OrderProduct|null
     */
    public static function getModelInstance()
    {
        if (is_null(self::$_modelClass)) {
            self::$_modelClass = new Table_OrderProduct();
        }
        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 = "op_id")
    {
        $model = self::getModelInstance();
        return $model->update($row, $value, $field);
    }

    /**
     * @param $value
     * @param string $field
     * @return mixed
     */
    public static function delete($value, $field = "op_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 = 'op_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 = "",$lock='')
    {
        $model = self::getModelInstance();
        return $model->getByCondition($condition, $type, $pageSize, $page, $order,$lock);
    }

    /**
     * @param $val
     * @return array
     */
    public static function validator($val)
    {
        $validateArr = $error = array();
        
        return  Common_Validator::formValidator($validateArr);
    }

    public static function getGoodsId($receiving_code){
        $model = self::getModelInstance();
        return $model->getGoodsId($receiving_code);
    }

    public static function getJoinProductByCondition($condition){
        $model = self::getModelInstance();
        return $model->getJoinProductByCondition($condition);
    }

    public static function calNetWeightByCondition($condition){
        $model = self::getModelInstance();
        return $model->calNetWeightByCondition($condition);
    }


    /**
     * @param array $params
     * @return array
     */
    public  function getFields()
    {
        $row = array(
        
              'E0'=>'op_id',
              'E1'=>'order_id',
              'E2'=>'order_code',
              'E3'=>'product_id',
              'E4'=>'product_barcode',
              'E5'=>'op_quantity',
              'E6'=>'op_category',
              'E7'=>'op_ref_tnx',
              'E8'=>'op_ref_item_id',
              'E9'=>'op_ref_buyer_id',
              'E10'=>'op_ref_paydate',
              'E11'=>'op_add_time',
              'E12'=>'op_update_time',
        );
        return $row;
    }

}