diff --git a/server/app/admin/controller/content/Demand.php b/server/app/admin/controller/content/Demand.php new file mode 100644 index 00000000..9c3412ff --- /dev/null +++ b/server/app/admin/controller/content/Demand.php @@ -0,0 +1,145 @@ +request->isAjax()) { + try { + $page = input('page/d', 1); + $limit = input('limit/d', 10); + + $keyword = input('keyword/s'); + + $page = $page ?: 1; + $limit = $limit ?: 10; + $where = []; + + $order = [ + 'id' => 'desc' + ]; + + if (!empty($keyword)) { + $where[] = ['name', 'like', '%'.trim($keyword).'%']; + } + + $count = thisModel::where($where)->count(); + + $list = thisModel::withCount(['reports'])->field(['id', 'name', 'create_time']) + ->where($where) + ->order($order) + ->page($page,$limit) + ->select() + ->toArray(); + + $data = [ + 'lists' => $list, + 'page_no' => $page, + 'page_size' => $limit, + 'count' => $count, + ]; + return JsonServer::success('获取成功', $data); + } catch (\Exception $e) { + return JsonServer::error('获取失败'); + } + } + + return view(); + } + + /** + * @NOTES: 添加 + * @author: 张无忌 + */ + public function add() + { + if ($this->request->isAjax()) { + $input = input('post.'); + + $rule = [ + 'name|需求名称' => 'require|min:2', + 'content|介绍' => 'require', + ]; + + $validate = Validate::rule($rule); + if (!$validate->check($input)) { + return JsonServer::error($validate->getError()); + } + + thisModel::create([ + 'name' => $input['name'], + 'content' => $input['content'], + 'create_time' => time(), + ]); + + return JsonServer::success('添加成功'); + } + + + return view(); + } + + /** + * @NOTES: 编辑 + * @author: 张无忌 + */ + public function edit() + { + $id = input('id'); + $item = thisModel::where('id', $id)->find(); + if ($this->request->isAjax()) { + $input = input('post.'); + + $rule = [ + 'name|需求名称' => 'require|min:2', + 'content|介绍' => 'require', + ]; + + $validate = Validate::rule($rule); + if (!$validate->check($input)) { + return JsonServer::error($validate->getError()); + } + + $item->save([ + 'name' => $input['name'], + 'content' => $input['content'], + ]); + + return JsonServer::success('编辑成功'); + } + + return view('', [ + 'detail' => $item, + ]); + } + + /** + * @NOTES: 删除 + * @author: 张无忌 + */ + public function del() + { + if ($this->request->isAjax()) { + thisModel::where('id', input('id/d'))->delete(); + return JsonServer::success('删除成功'); + } + + return JsonServer::error('异常'); + } +} \ No newline at end of file diff --git a/server/app/admin/controller/content/DemandReport.php b/server/app/admin/controller/content/DemandReport.php new file mode 100644 index 00000000..f4696ece --- /dev/null +++ b/server/app/admin/controller/content/DemandReport.php @@ -0,0 +1,107 @@ +request->isAjax()) { + try { + $page = input('page/d', 1); + $limit = input('limit/d', 10); + + $keyword = input('keyword/s'); + $status = input('status'); + + $page = $page ?: 1; + $limit = $limit ?: 10; + $where = []; + + $order = [ + 'id' => 'desc' + ]; + + $where[] = ['demand_id', '=', $demandId]; + + if (!empty($keyword)) { + $where[] = ['name|phone|company|price', 'like', '%'.trim($keyword).'%']; + } + + if (isset($status) && $status != '') { + $where[] = ['status', '=', $status]; + } + + $count = thisModel::where($where)->count(); + + $list = thisModel::where($where) + ->order($order) + ->page($page,$limit) + ->select() + ->toArray(); + + $data = [ + 'lists' => $list, + 'page_no' => $page, + 'page_size' => $limit, + 'count' => $count, + ]; + return JsonServer::success('获取成功', $data); + } catch (\Exception $e) { + return JsonServer::error('获取失败'); + } + } + + return view('', ['demandId' => $demandId]); + } + + /** + * @NOTES: 编辑 + * @author: 张无忌 + */ + public function edit() + { + $id = input('id'); + $item = thisModel::where('id', $id)->find(); + if ($this->request->isAjax()) { + $input = input('post.'); + + $item->save([ + 'remarks' => $input['remarks'], + 'status' => $input['status'], + ]); + + return JsonServer::success('编辑成功'); + } + + return view('', [ + 'detail' => $item, + ]); + } + + /** + * @NOTES: 删除 + * @author: 张无忌 + */ + public function del() + { + if ($this->request->isAjax()) { + thisModel::where('id', input('id/d'))->delete(); + return JsonServer::success('删除成功'); + } + + return JsonServer::error('异常'); + } +} \ No newline at end of file diff --git a/server/app/admin/view/content/demand/add.html b/server/app/admin/view/content/demand/add.html new file mode 100644 index 00000000..33a1c0f7 --- /dev/null +++ b/server/app/admin/view/content/demand/add.html @@ -0,0 +1,57 @@ +{layout name="layout2" /} + + +