<?php

namespace app\common\model;

use think\Model;

class HeadNav extends Model
{
    public $page_info;

    /**
     * 获取单个导航栏内容
     */
    public function getOneHeadNav($condition, $field = '*')
    {
        return db('head_nav')->field($field)->where($condition)->find();
    }



    /**
     * 头部导航栏列表
     */
    public function getHeadNav($condition, $field = '*', $page = 0, $order = 'nav_sort', $limit = '')
    {
        if ($limit) {
            return db('head_nav')->where($condition)->field($field)->order($order)->page($page)->limit($limit)->select();
        } else {
            $res = db('head_nav')->where($condition)->field($field)->order($order)->paginate($page);
            $this->page_info = $res;
            return $res->items();
        }
    }
    /**
     * 新增导航栏
     */
    public function addHeadNav($param)
    {
        return db('head_nav')->insertGetId($param);
    }

    /**
     * 修改导航栏
     */
    public function editHeadNav($condition, $update)
    {
        return db('head_nav')->where($condition)->update($update);
    }

    /**
     * 删除导航栏
     * @param unknown $condition
     * @return boolean
     */
    public function delHeadNav($condition)
    {
        $headnav_array = $this->getHeadNav($condition, 'id');
        $id_array = array();
        foreach ($headnav_array as $value) {
            $id_array[] = $value['id'];
            // @unlink(BASE_UPLOAD_PATH . DS . ATTACH_PRODUCT . DS . $value['product_img']);
        }
        return db('head_nav')->where(array('id' => array('in', $id_array)))->delete();
    }



}

?>
