EnshrineNoticeService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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($userId){
  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. $dataList = $this->model::from('enshrine_notices as a')
  46. ->leftJoin('member as m','m.id','=','a.user_id')
  47. ->where(['a.type'=> $type,'a.is_hide'=> $isHide,'a.mark'=>1,'a.user_id'=> $userId,'a.status'=> 1])
  48. ->select(['a.*','m.avatar','m.nickname'])
  49. ->orderBy('a.create_time', 'desc')
  50. ->paginate($pageSize);
  51. $dataList = $dataList ? $dataList->toArray() : [];
  52. if ($dataList) {
  53. foreach ($dataList['data'] as &$item) {
  54. $item['avatar'] = $item['avatar']? get_image_url($item['avatar']) : '';
  55. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
  56. $item['time'] = $item['create_time']? format_time(strtotime($item['create_time'])) : '';
  57. $item['description'] = $item['description']? str_replace("\n",'<br>', $item['description']) : '';
  58. }
  59. unset($item);
  60. }
  61. return [
  62. 'code' => 0,
  63. 'success'=> true,
  64. 'msg' => '操作成功',
  65. 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
  66. 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
  67. ];
  68. }
  69. /**
  70. * 发布记录
  71. * @param $userId
  72. */
  73. public function publish($userId){
  74. $params = request()->all();
  75. $realname = isset($params['realname'])? $params['realname'] : '';
  76. $description = isset($params['description'])? $params['description'] : '';
  77. $type = isset($params['type'])? $params['type'] : 1;
  78. $memberInfo = MemberModel::where(['id'=> $userId,'mark'=> 1,'status'=> 1])
  79. ->select(['id','nickname'])
  80. ->first();
  81. if(!$memberInfo){
  82. return message('您的账号不可操作或已冻结,请联系客服', false);
  83. }
  84. $data = [
  85. 'user_id'=> $userId,
  86. 'type'=> $type,
  87. 'realname'=> $realname,
  88. 'description'=> $description,
  89. 'is_hide'=> isset($params['is_hide'])? $params['is_hide'] : 2,
  90. 'update_time'=> time(),
  91. 'create_time'=> time(),
  92. 'status'=> 1,
  93. ];
  94. if($this->model::insertGetId($data)){
  95. return message('发布成功', true);
  96. }else{
  97. return message('发布失败', false);
  98. }
  99. }
  100. /**
  101. * 删除记录
  102. * @param $userId
  103. * @return array
  104. */
  105. public function del($userId){
  106. $id = request()->get('id', 0);
  107. if($id<=0){
  108. return message('参数错误');
  109. }
  110. $info = $this->model::where(['id'=> $id, 'user_id'=> $userId,'mark'=> 1,'status'=> 1])
  111. ->select(['id','user_id','realname'])
  112. ->first();
  113. if(!$info){
  114. return message('记录不存在或已处理', false);
  115. }
  116. if($this->model::where(['id'=> $id, 'user_id'=> $userId,'mark'=> 1,'status'=> 1])->delete()){
  117. return message('删除成功', true);
  118. }else{
  119. return message('删除失败', false);
  120. }
  121. }
  122. }