xieruidong 2 years ago
parent
commit
5bbfa37cc7

+ 3 - 0
app/admin/controller/Notice.php

@@ -44,6 +44,9 @@ class Notice extends Controller
         if($this->request->isPost()){
             $this->_vali([
                 'title.max:50'=>'标题过长',
+                'summary.require'=>'概要必须',
+                'summary.max:250'=>'概要最长250',
+                'content.require'=>'内容必须',
             ]);
         }
     }

+ 8 - 3
app/admin/view/notice/form.html

@@ -5,12 +5,18 @@
     <div class="layui-card-body">
         <label class="layui-form-item relative block">
             <span class="help-label"><b>标题</b>Notice Title</span>
-            <input class="layui-input" name="title" placeholder="请输入新闻标题" required value='{$vo.title|default=""}'>
+            <input class="layui-input" name="title" placeholder="请输入标题" required value='{$vo.title|default=""}'>
         </label>
         <div class="layui-form-item label-required-prev">
+            <span class="help-label"><b>概要</b>Notice summary</span>
+            <div class="relative block">
+                <textarea class="layui-textarea" name="summary" placeholder="请输入概要">{$vo.summary|default=''}</textarea>
+            </div>
+        </div>
+        <div class="layui-form-item label-required-prev">
             <span class="help-label"><b>内容</b>Notice Content</span>
             <div class="relative block">
-                <textarea class="layui-hide" name="content" placeholder="请输入新闻内容">{$vo.content|default=''}</textarea>
+                <textarea class="layui-hide" name="content" placeholder="请输入内容">{$vo.content|default=''}</textarea>
             </div>
         </div>
 
@@ -26,7 +32,6 @@
 </form>
 
 <script>
-    $('input[name="images"]').uploadMultipleImage();
     require(['ckeditor'], function () {
         window.createEditor('[name=content]', {height: 350})
     });

+ 57 - 0
app/data/controller/api/Notice.php

@@ -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);
+    }
+}

+ 1 - 1
app/data/model/DataNotice.php

@@ -13,7 +13,7 @@ class DataNotice extends Model
     public function readUser(){
         return $this->belongsToMany(DataUser::class,DataNoticeRead::class,'notice_id','uuid');
     }
-    public function read(){
+    public function reads(){
         return $this->hasMany(DataNoticeRead::class,'notice_id');
     }
     public static function onAfterDelete(self $model): void

+ 1 - 0
config/apidoc.php

@@ -50,6 +50,7 @@ return [
                     \app\data\controller\api\auth\UserPurchase::class,
                     \app\data\controller\api\ShipYard::class,
                     \app\data\controller\api\Data::class,
+                    \app\data\controller\api\Notice::class,