<?php

namespace app\common\model;

use think\Model;

class LeaderTeam extends Model
{
    public $page_info;

    /**
     * 获取单个领导团队信息
     */
    public function getOneleaderteam($condition, $field = '*')
    {
        return db('leader_team')->field($field)->where($condition)->find();
    }



    /**
     * 领导团队列表
     */
    public function getLeaderTeam($condition, $field = '*', $page = 0, $order = 'add_time', $limit = '')
    {
        if ($limit) {
            return db('leader_team')->where($condition)->field($field)->order($order,'add_time')->page($page)->limit($limit)->select();
        } else {
            $res = db('leader_team')->where($condition)->field($field)->order($order,'add_time')->paginate($page);
            $this->page_info = $res;
            return $res->items();
        }
    }
    /**
     * 新增领导团队
     */
    public function add($param)
    {
        return db('leader_team')->insertGetId($param);
    }

    /**
     * 修改领导团队信息
     */
    public function edit($condition, $update)
    {
        return db('leader_team')->where($condition)->update($update);
    }

    /**
     * 删除领导团队
     * @param unknown $condition
     * @return boolean
     */
    public function deleteLeaderTeam($condition)
    {
        $leaderteam_array = $this->getLeaderTeam($condition, 'id');
        $id_array = array();
        foreach ($leaderteam_array as $value) {
            $id_array[] = $value['id'];
            // @unlink(BASE_UPLOAD_PATH . DS . ATTACH_PRODUCT . DS . $value['product_img']);
        }
        return db('leader_team')->where(array('id' => array('in', $id_array)))->delete();
    }



}

?>
