input('name','');//获取搜索名称 $phone = request()->input('phone','');//获取搜索手机号 $start = request()->input('start','');//获取开始时间 $end = request()->input('end','');//获取结束时间 //查询数据条件 $where = [['is_del',0]]; if ($name) $where[] = ['name', 'like', "%$name%"]; if ($phone) $where[] = ['phone', 'like', "%$phone%"]; if ($start) $where[] = ['created_at', '>=', $start]; if ($end) $where[] = ['created_at', '<=', $end]; //获取数据 $list = Message::where($where) ->orderBy('id','desc') ->select(['id','name','phone','created_at']) ->paginate(10); return $this->apiResponseSuccess('获取信息成功', [ 'list' => $list->items(), 'total' => $list->total(), 'limit' => 10 ]); } /** * 获取记录详情 * @return \Illuminate\Http\JsonResponse */ function getInfo() { $id = request()->input('id', '');//获取需要查询的记录id if (empty($id)) return $this->apiResponseError('缺少必要参数'); //查询数据 $where = [['id', $id], ['is_del',0]]; $info = Message::where($where)->select(['id', 'name', 'phone', 'content', 'created_at'])->first(); if (empty($info)) return $this->apiResponseError('没有找到该记录'); return $this->apiResponseSuccess('获取成功', $info); } /** * 删除(批量)记录 * @return \Illuminate\Http\JsonResponse */ function destroys(){ $ids = request()->input('ids','');//获取需要删除的id if(empty($ids)) return $this->apiResponseError('缺少必要参数'); //数据条件 if(!is_array($ids)) return $this->apiResponseError('数据格式错误'); $res = Message::whereIn('id',$ids)->update(['is_del' => 1]); if ($res) { return $this->apiResponseSuccess('删除成功'); } else { return $this->apiResponseError('删除失败'); } } }