table)->where($_where)->count(); $page = $this->request->param('page', 1); $pagesize = $this->request->param('pagesize', 10); $pages = ceil($count / $pagesize); //总页数 $_result = Db::name($this->table)->where($_where)->page($page, $pagesize)->order('id', "DESC")->select(); $_data['list'] = $_result; $_data['pages'] = $pages; self::formatData($_data['list']); return send_http_status(200, $_data); } /** * 合同详情 */ public function view($id = '') { if (!$id) { return; } //获取房源详情 $_data = Db::name($this->table)->where('user_id', USER_ID)->find($id); if ($_data) { $_data['create_time'] = date('Y-m-d', $_data['create_time']); $_data['contract_starttime'] = date('Y-m-d', $_data['contract_starttime']); $_data['contract_endtime'] = date('Y-m-d', $_data['contract_endtime']); return send_http_status(200, $_data); } } /** * 删除合同信息 * @param string $id 合同id * @return \type * @throws \think\Exception * @throws \think\exception\PDOException */ public function del($id = '') { if ((!$id || !is_numeric($id))) { return send_http_status(51003); } $affected = Db::name($this->table)->where('id', $id)->where('user_id', USER_ID)->update(['is_del' => 1]); if ($affected) { return send_http_status(200); } return send_http_status(413); } static private function formatData(&$data) { if (!$data) { return; } array_walk($data, function (&$v, &$k) { !empty($v['create_time']) ? $v['create_time'] = date('Y-m-d', $v['create_time']) : $v['create_time'] = ''; !empty($v['update_time']) ? $v['update_time'] = date('Y-m-d', $v['update_time']) : $v['update_time'] = ''; }); } }