EnshrineNoticeService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Laravel框架 [ Laravel ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 Laravel研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: wesmiler <12345678@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services;
  12. use App\Models\DictModel;
  13. use App\Models\EnshrineNoticeModel;
  14. /**
  15. * 忏悔/回向记录-服务类
  16. * @author wesmiler
  17. * @since 2020/11/11
  18. * Class EnshrineNoticeService
  19. * @package App\Services
  20. */
  21. class EnshrineNoticeService extends BaseService
  22. {
  23. /**
  24. * 构造函数
  25. * @author wesmiler
  26. * @since 2020/11/11
  27. * EnshrineNoticeService constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new EnshrineNoticeModel();
  32. }
  33. /**
  34. * 获取忏悔/回向记录
  35. * @param $userId
  36. * @return array
  37. */
  38. public function getDataList($userId){
  39. $params = request()->all();
  40. $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
  41. $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
  42. $type = isset($params['type'])? $params['type'] : 1;
  43. $isHide = isset($params['is_hide'])? $params['is_hide'] : 1;
  44. $dataList = $this->model::from('enshrine_notices a')
  45. ->where(['a.type'=> $type,'a.is_hide'=> $isHide,'a.mark'=>1,'a.user_id'=> $userId,'a.status'=> 1])
  46. ->select(['a.*'])
  47. ->orderBy('a.create_time', 'desc')
  48. ->paginate($pageSize);
  49. $dataList = $dataList ? $dataList->toArray() : [];
  50. if ($dataList) {
  51. foreach ($dataList['data'] as &$item) {
  52. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
  53. $item['description'] = $item['description']? str_replace("\n",'<br>', $item['description']) : '';
  54. }
  55. unset($item);
  56. }
  57. return [
  58. 'code' => 0,
  59. 'success'=> true,
  60. 'msg' => '操作成功',
  61. 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
  62. 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
  63. ];
  64. }
  65. /**
  66. * 发布记录
  67. * @param $userId
  68. */
  69. public function publish($userId){
  70. $params = request()->all();
  71. $realname = isset($params['realname'])? $params['realname'] : '';
  72. $description = isset($params['description'])? $params['description'] : '';
  73. }
  74. /**
  75. * 删除记录
  76. * @param $userId
  77. * @return array
  78. */
  79. public function del($userId){
  80. $id = request()->get('id', 0);
  81. if($id<=0){
  82. return message('参数错误');
  83. }
  84. $info = $this->model::where(['id'=> $id, 'user_id'=> $userId,'mark'=> 1,'status'=> 1])
  85. ->select(['id','user_id','real_name'])
  86. ->first();
  87. if(!$info){
  88. return message('记录不存在或已处理', false);
  89. }
  90. if($this->model::where(['id'=> $id, 'user_id'=> $userId,'mark'=> 1,'status'=> 1])->delete()){
  91. return message('删除成功', true);
  92. }else{
  93. return message('删除失败', false);
  94. }
  95. }
  96. }