Staff.php(controller) <?php namespace app\index\controller; use think\Controller; use app\index\model\Staff as StaffModel; class Staff extends Controller { //模型闭包查询 public function query() { $staff = StaffModel::get(function($query){ $query->where('sex',0)->where('salary','<',4000)->order('salary','desc'); }); echo '性别为男,工资小于4000的员工信息:<br>'; dump($staff); $age = $this->request->param('age') ?: 40; $salary = $this->request->param('salary') ?: 5000; $staffs = StaffModel::all(function($query) use ($age, $salary){ $query->where('age','<=',$age)->where('salary','>',$salary); }); foreach ($staffs as $staff) { echo '姓名:'.$staff->name.'<br>'; echo '年龄:'.$staff->age.'<br>'; echo '工资:'.$staff->salary.'<hr>'; } } //模型软删除 public function softDelete() { StaffModel::destroy(1); $res = StaffModel::all(); dump($res); } } Staff.php(model) <?php namespace app\index\model; use think\Model; use think\model\concern\SoftDelete; class Staff extends Model { use SoftDelete; protected $table = 'staff'; protected $pk = 'staff_id'; protected $deleteTime = 'delete_time'; protected $defaultSoftDelete = 0; }