EnshrineNoticeService.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. use App\Models\MemberModel;
  15. /**
  16. * 忏悔/回向记录-服务类
  17. * @author wesmiler
  18. * @since 2020/11/11
  19. * Class EnshrineNoticeService
  20. * @package App\Services
  21. */
  22. class EnshrineNoticeService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author wesmiler
  27. * @since 2020/11/11
  28. * EnshrineNoticeService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new EnshrineNoticeModel();
  33. }
  34. /**
  35. * 获取忏悔/回向记录
  36. * @param $userId
  37. * @return array
  38. */
  39. public function getDataList(){
  40. $params = request()->all();
  41. $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
  42. $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
  43. $type = isset($params['type'])? $params['type'] : 1;
  44. $isHide = isset($params['is_hide'])? $params['is_hide'] : 1;
  45. $userId = isset($params['user_id'])? $params['user_id'] : 0;
  46. $where = ['a.type'=> $type,'a.is_hide'=> $isHide,'a.mark'=>1,'a.status'=> 1];
  47. if($userId){
  48. $where['a.user_id'] = $userId;
  49. }
  50. $dataList = $this->model::from('enshrine_notices as a')
  51. ->leftJoin('member as m','m.id','=','a.user_id')
  52. ->where($where)
  53. ->select(['a.*','m.avatar','m.nickname'])
  54. ->orderBy('a.create_time', 'desc')
  55. ->paginate($pageSize);
  56. $dataList = $dataList ? $dataList->toArray() : [];
  57. if ($dataList) {
  58. foreach ($dataList['data'] as &$item) {
  59. $item['avatar'] = $item['avatar']? get_image_url($item['avatar']) : '';
  60. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
  61. $item['time'] = $item['create_time']? format_time(strtotime($item['create_time'])) : '';
  62. $item['description'] = $item['description']? str_replace("\n",'<br>', $item['description']) : '';
  63. }
  64. unset($item);
  65. }
  66. return [
  67. 'code' => 0,
  68. 'success'=> true,
  69. 'msg' => '操作成功',
  70. 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
  71. 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
  72. ];
  73. }
  74. /**
  75. * 发布记录
  76. * @param $userId
  77. */
  78. public function publish($userId){
  79. $params = request()->all();
  80. $realname = isset($params['realname'])? $params['realname'] : '';
  81. $description = isset($params['description'])? $params['description'] : '';
  82. $type = isset($params['type'])? $params['type'] : 1;
  83. $memberInfo = MemberModel::where(['id'=> $userId,'mark'=> 1,'status'=> 1])
  84. ->select(['id','nickname'])
  85. ->first();
  86. if(!$memberInfo){
  87. return message('您的账号不可操作或已冻结,请联系客服', false);
  88. }
  89. $data = [
  90. 'user_id'=> $userId,
  91. 'type'=> $type,
  92. 'realname'=> $realname,
  93. 'description'=> $description,
  94. 'is_hide'=> isset($params['is_hide'])? $params['is_hide'] : 2,
  95. 'update_time'=> time(),
  96. 'create_time'=> time(),
  97. 'status'=> 1,
  98. ];
  99. if($this->model::insertGetId($data)){
  100. return message('发布成功', true);
  101. }else{
  102. return message('发布失败', false);
  103. }
  104. }
  105. /**
  106. * 删除记录
  107. * @param $userId
  108. * @return array
  109. */
  110. public function del($userId){
  111. $id = request()->get('id', 0);
  112. if($id<=0){
  113. return message('参数错误');
  114. }
  115. $info = $this->model::where(['id'=> $id, 'user_id'=> $userId,'mark'=> 1,'status'=> 1])
  116. ->select(['id','user_id','realname'])
  117. ->first();
  118. if(!$info){
  119. return message('记录不存在或已处理', false);
  120. }
  121. if($this->model::where(['id'=> $id, 'user_id'=> $userId,'mark'=> 1,'status'=> 1])->delete()){
  122. return message('删除成功', true);
  123. }else{
  124. return message('删除失败', false);
  125. }
  126. }
  127. }