<?php

namespace app\common\model;

use think\Model;

class DevelopmentServer extends Model
{
    public $page_info;

    /**
     * 获取单个开发服务内容
     */
    public function getOneServer($condition, $field = '*')
    {
        return db('development_server')->field($field)->where($condition)->find();
    }



    /**
     * 开发服务列表
     */
    public function getDevelopmentServer($condition, $field = '*', $page = 0, $order = 'sort', $limit = '')
    {
        if ($limit) {
            return db('development_server')->where($condition)->field($field)->order($order,'desc')->page($page)->limit($limit)->select();
        } else {
            $res = db('development_server')->where($condition)->field($field)->order($order,'desc')->paginate($page);
            $this->page_info = $res;
            return $res->items();
        }
    }
    /**
     * 新增开发服务
     */
    public function add($param)
    {
        return db('development_server')->insertGetId($param);
    }

    /**
     * 修改开发服务
     */
    public function edit($condition, $update)
    {
        return db('development_server')->where($condition)->update($update);
    }

    /**
     * 删除开发服务
     * @param unknown $condition
     * @return boolean
     */
    public function deleteServer($condition)
    {
        $case_array = $this->getDevelopmentServer($condition, 'id');
        $id_array = array();
        foreach ($case_array as $value) {
            $id_array[] = $value['id'];
            // @unlink(BASE_UPLOAD_PATH . DS . ATTACH_PRODUCT . DS . $value['product_img']);
        }
        return db('development_server')->where(array('id' => array('in', $id_array)))->delete();
    }



}

?>
