Просмотр исходного кода

wesmiler 报恩寺项目提交

wesmiler 4 лет назад
Родитель
Сommit
12844d5be4

+ 2 - 2
app/Http/Controllers/Api/v1/ArticleController.php

@@ -64,8 +64,8 @@ class ArticleController extends BaseController
      * @param ArticleValidator $validate
      * @return array
      */
-    public function books(Request $request, ArticleValidator $validate){
-        $params = $validate->check($request->all(),'books');
+    public function books(Request $request, ArticleValidator $validator){
+        $params = $validator->check($request->all(),'books');
         if(!is_array($params)){
             return message($params, false);
         }

+ 31 - 0
app/Http/Controllers/Api/v1/EnshrineController.php

@@ -3,6 +3,8 @@
 namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\BaseController;
+use App\Http\Validator\EnshrineNoticeValidator;
+use App\Services\EnshrineNoticeService;
 use App\Services\EnshrineService;
 use Illuminate\Http\Request;
 
@@ -26,6 +28,7 @@ class EnshrineController extends BaseController
         parent::__construct();
 
         $this->service = new EnshrineService();
+        $this->noticeService = new EnshrineNoticeService();
     }
 
 
@@ -94,4 +97,32 @@ class EnshrineController extends BaseController
     public function buy(){
         return $this->service->buy($this->userId);
     }
+
+    /**
+     * 发布忏悔/回向记录
+     * @return mixed
+     */
+    public function noticePublish(Request $request, EnshrineNoticeValidator $validator){
+        $params = $validator->check($request->all(),'publish');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+        return $this->noticeService->publish($this->userId);
+    }
+
+    /**
+     * 忏悔回向记录
+     * @return mixed
+     */
+    public function noticeList(){
+        return $this->noticeService->getDataList($this->userId);
+    }
+
+    /**
+     * 忏悔回向记录删除
+     * @return mixed
+     */
+    public function noticeDel(){
+        return $this->noticeService->del($this->userId);
+    }
 }

+ 46 - 0
app/Http/Validator/EnshrineNoticeValidator.php

@@ -0,0 +1,46 @@
+<?php
+namespace App\Http\Validator;
+class EnshrineNoticeValidator extends BaseValidator
+{
+    // 当前模型所有验证规则
+    public static $rules = [
+        'id' => 'required',
+        'realname' => 'required|string|min:2|max:20',
+        'description' => 'required|string|min:2|max:150',
+
+    ];
+
+    // 当前模型所有错误提示信息
+    public static $msgs = [
+        'required' => ':attribute不能为空',
+        'string' => ':attribute必须是字符串',
+        'min' => ':attribute长度不能小于:min位',
+        'max' => ':attribute长度不能大于:max位',
+        'exists' => ':attribute不存在',
+        'rule' => ':attribute格式不正确',
+    ];
+
+    // 当前模型所有验证字段
+    public static $fields = [
+        'id' => 'ID',
+        'realname' => '姓名',
+        'description' => '内容',
+    ];
+
+    // 当前模型所有验证场景
+    public static $scenes = [
+        'info'=> ['id'],
+        'publish'=> ['id','realname','description'],
+    ];
+
+    /**
+     * 验证
+     * @param $request
+     * @param string $scene
+     * @return int|mixed
+     */
+    public static function check($request, $scene=''){
+        $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
+        return $validator->checkParams($request, $scene);
+    }
+}

+ 40 - 0
app/Models/EnshrineNoticeModel.php

@@ -0,0 +1,40 @@
+<?php
+// +----------------------------------------------------------------------
+// | Laravel框架 [ Laravel ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 Laravel研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: wesmiler <12345678@qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 忏悔/回向管理-模型
+ * @author wesmiler
+ * @since 2020/11/11
+ * Class EnshrineNoticeModel
+ * @package App\Models
+ */
+class EnshrineNoticeModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'enshrine_notices';
+
+    /**
+     * 获取信息
+     * @param int $id
+     * @return array|string
+     * @author wesmiler
+     * @since 2020/11/11
+     */
+    public function getInfo($id)
+    {
+        $info = parent::getInfo($id); // TODO: Change the autogenerated stub
+
+        return $info;
+    }
+
+}

+ 109 - 0
app/Services/EnshrineNoticeService.php

@@ -0,0 +1,109 @@
+<?php
+// +----------------------------------------------------------------------
+// | Laravel框架 [ Laravel ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 Laravel研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: wesmiler <12345678@qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services;
+
+use App\Models\DictModel;
+use App\Models\EnshrineNoticeModel;
+
+/**
+ * 忏悔/回向记录-服务类
+ * @author wesmiler
+ * @since 2020/11/11
+ * Class EnshrineNoticeService
+ * @package App\Services
+ */
+class EnshrineNoticeService extends BaseService
+{
+    /**
+     * 构造函数
+     * @author wesmiler
+     * @since 2020/11/11
+     * EnshrineNoticeService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new EnshrineNoticeModel();
+    }
+
+    /**
+     * 获取忏悔/回向记录
+     * @param $userId
+     * @return array
+     */
+    public function getDataList($userId){
+        $params = request()->all();
+        $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
+        $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
+        $type = isset($params['type'])? $params['type'] : 1;
+        $isHide = isset($params['is_hide'])? $params['is_hide'] : 1;
+
+        $dataList = $this->model::from('enshrine_notices a')
+            ->where(['a.type'=> $type,'a.is_hide','a.mark'=>1,'a.user_id'=> $userId,'a.status'=> 1])
+            ->select(['a.*'])
+            ->orderBy('a.create_time', 'desc')
+            ->paginate($pageSize);
+
+        $dataList = $dataList ? $dataList->toArray() : [];
+        if ($dataList) {
+            foreach ($dataList['data'] as &$item) {
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
+                $item['description'] = $item['description']? str_replace("\n",'<br>', $item['description']) : '';
+            }
+            unset($item);
+        }
+
+        return [
+            'code' => 0,
+            'success'=> true,
+            'msg' => '操作成功',
+            'count' => isset($dataList['total']) ? $dataList['total'] : 0,
+            'data' => isset($dataList['data']) ? $dataList['data'] : 0,
+        ];
+    }
+
+    /**
+     * 发布记录
+     * @param $userId
+     */
+    public function publish($userId){
+        $params = request()->all();
+        $realname = isset($params['realname'])? $params['realname'] : '';
+        $description = isset($params['description'])? $params['description'] : '';
+
+
+    }
+
+    /**
+     * 删除记录
+     * @param $userId
+     * @return array
+     */
+    public function del($userId){
+        $id = request()->get('id', 0);
+        if($id<=0){
+            return message('参数错误');
+        }
+
+        $info = $this->model::where(['id'=> $id, 'user_id'=> $userId,'mark'=> 1,'status'=> 1])
+            ->select(['id','user_id','real_name'])
+            ->first();
+        if(!$info){
+            return message('记录不存在或已处理', false);
+        }
+
+        if($this->model::where(['id'=> $id, 'user_id'=> $userId,'mark'=> 1,'status'=> 1])->delete()){
+            return message('删除成功', true);
+        }else{
+            return message('删除失败', false);
+        }
+    }
+}

+ 3 - 2
app/Services/EnshrineService.php

@@ -613,7 +613,7 @@ class EnshrineService extends BaseService
             return message('参数错误', false);
         }
 
-        $info = EnshrineActionModel::where(['id'=> $id,'user_id'=> $userId,'mark'=> 1,'status'=> 1])
+        $info = EnshrineActionModel::where(['id'=> $id,'user_id'=> $userId,'type'=> 3,'mark'=> 1,'status'=> 1])
             ->select(['id','user_id','status'])
             ->first();
         if(!$info){
@@ -628,7 +628,7 @@ class EnshrineService extends BaseService
         }
 
         if($type == 2){
-            if(EnshrineActionModel::where(['id'=> $id,'user_id'=> $userId,'mark'=> 1,'status'=> 1])->delete()){
+            if(EnshrineActionModel::where(['id'=> $id,'user_id'=> $userId,'type'=> 3,'mark'=> 1,'status'=> 1])->delete()){
                 return message('删除成功', true);
             }else{
                 return message('删除失败', false);
@@ -643,4 +643,5 @@ class EnshrineService extends BaseService
         }
 
     }
+
 }

+ 3 - 0
routes/api.php

@@ -162,4 +162,7 @@ Route::post('/enshrine/buy', [\App\Http\Controllers\Api\v1\EnshrineController::c
 Route::post('/enshrine/action', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'actionRecord']);
 Route::post('/enshrine/xinyuan', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'xinyuan']);
 Route::post('/enshrine/catchXuyuan', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'catchXuyuan']);
+Route::post('/enshrine/noticePublish', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'noticePublish']);
+Route::post('/enshrine/noticeList', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'noticeList']);
+Route::post('/enshrine/noticeDel', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'noticeDel']);