<?php
class Goods_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }
    
    public function get_goods_attr()
    {  
        $fields = $this->db->field_data('goods');
         return $fields;
    }    

    public function get_goods_type()
    {
        $this->db->order_by ( 'type_id', "asc" );
        $query = $this->db->get('type');
         return $query->result ();
    }   
    
    public function get_goods($_offset=null,$_num=null){
        $this->db->order_by ( 'goods_id', "asc" );
        if(isset($_offset) and isset($_num)){
            $this->db->limit($_num,$_offset);
        }
        $query = $this->db->get('goods');
         return $query->result ();
    }
    
    public function get_goods_code($_code){
        $query = $this->db->get_where('goods', array('goods_code' => $_code));
        return $query->row_array();
    }
    
    public function get_one_goods($_id){
        $query = $this->db->get_where('goods', array('goods_id' => $_id));
        return $query->row_array();
    }
    
    public function update_goods($_id,$_data){
        $this->db->where('goods_id',$_id);
        $this->db->update("goods",$_data);
        return $this->db->affected_rows();
    }
    public function add_goods($_data){
        $this->db->insert("goods",$_data);
        return $this->db->affected_rows();        
    }    
}

