<?php

namespace app\common\model;

use think\Model;

class DevelopmentCase extends Model
{
    public $page_info;

    /**
     * 获取单个案例内容
     */
    public function getOneCase($condition, $field = '*')
    {
        return db('case')->field($field)->where($condition)->find();
    }



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

    /**
     * 修改案例
     */
    public function edit($condition, $update)
    {
        return db('case')->where($condition)->update($update);
    }

    /**
     * 删除案例
     * @param unknown $condition
     * @return boolean
     */
    public function deleteCase($condition)
    {
        $case_array = $this->getDevelopmentCase($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('case')->where(array('id' => array('in', $id_array)))->delete();
    }



}

?>
