|
@@ -0,0 +1,57 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\data\controller\api;
|
|
|
+
|
|
|
+use app\data\model\DataNotice;
|
|
|
+use hg\apidoc\annotation\Param;
|
|
|
+use hg\apidoc\annotation\Returned;
|
|
|
+use hg\apidoc\annotation\Title;
|
|
|
+use think\db\Query;
|
|
|
+use think\Request;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 公告
|
|
|
+ * Class Notice
|
|
|
+ * @package app\data\controller\api
|
|
|
+ */
|
|
|
+class Notice extends Auth
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @Title("列表")
|
|
|
+ *@Param("page",desc="第几页")
|
|
|
+ *@Param("limit",desc="每页几条")
|
|
|
+ *@Returned("title",desc="标题")
|
|
|
+ *@Returned("summary",desc="概要")
|
|
|
+ *@Returned("content",desc="内容")
|
|
|
+ *@Returned("title",desc="标题")
|
|
|
+ *@Returned("create_time",desc="时间")
|
|
|
+ *@Returned("is_read",desc="是否已读")
|
|
|
+ */
|
|
|
+ public function index(Request $request,DataNotice $notice){
|
|
|
+ $records=$notice
|
|
|
+ ->with([
|
|
|
+ 'reads'=>function(Query $query){
|
|
|
+ $query->where('uuid',$this->uuid);
|
|
|
+ }
|
|
|
+ ])
|
|
|
+ ->withoutField('content')
|
|
|
+ ->order('id','desc')
|
|
|
+ ->paginate($request['limit']?:15);
|
|
|
+ foreach ($records as &$record){
|
|
|
+ $record['is_read']=!$record['reads']->isEmpty();
|
|
|
+ $record->hidden(['reads'],true);
|
|
|
+ }
|
|
|
+ $this->success('',$records);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ *@Title("详情")
|
|
|
+ *@Param("id",desc="id")
|
|
|
+ */
|
|
|
+ public function show(Request $request,DataNotice $notice){
|
|
|
+ $notice=$notice->where('id',$request['id'])->findOrFail();
|
|
|
+ $notice->reads()->save([
|
|
|
+ 'uuid'=>$this->uuid,
|
|
|
+ ]);
|
|
|
+ $this->success('',$notice);
|
|
|
+ }
|
|
|
+}
|