<?php

namespace app\common\model;

use think\Model;

class OurTeam extends Model
{
    public $page_info;

    /**
     * 获取单个我们的团队信息
     */
    public function getOneOurteam($condition, $field = '*')
    {
        return db('our_team')->field($field)->where($condition)->find();
    }



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

    /**
     * 修改我们的团队信息
     */
    public function edit($condition, $update)
    {
        return db('our_team')->where($condition)->update($update);
    }

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



}

?>
