<?php
/**
 * 红包类型模型
 *

 */

defined('InShopNC') or exit('Access Invalid!');

class bonus_typeModel extends Model
{
    public function __construct()
    {
        parent::__construct('bonus_type');
    }

    public function getAll()
    {
        return $this->select();
    }

    public function get_one($condition,$field='*',$master = false)
    {
        return $this->where($condition)->field($field)->lock($master)->find();
    }
    public function get($condition,$field='*')
    {
        return $this->where($condition)->field($field)->order('type_id desc')->select();
    }

    public function getTypeCount($condition = array()) {
        return $this->table('bonus_type')->where($condition)->count();
    }

    public function getTypeList($condition = array(), $pagesize = '', $fields = '*', $order = '', $limit = '')
    {
        return $this->table('bonus_type')->where($condition)->field($fields)->order($order)->limit($limit)->page($pagesize)->select();
    }

    public function save($data, &$id)
    {
        if ($id > 0) {
            $this->where(array('type_id' => $id))->update($data);
        } else {
            $id = $this->insert($data);
        }
    }

    public function add($data) {
        return $this->insert($data);
    }
    public function edit($condition,$data) {
        $this->where($condition)->update($data);
    }
}
