ComplaintService.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\ComplaintModel;
  13. use App\Services\BaseService;
  14. use App\Services\RedisService;
  15. /**
  16. * 投诉建议管理-服务类
  17. * @author laravel开发员
  18. * @since 2020/11/11
  19. * Class ComplaintService
  20. * @package App\Services\Common
  21. */
  22. class ComplaintService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author laravel开发员
  27. * @since 2020/11/11
  28. * ComplaintService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new ComplaintModel();
  33. }
  34. /**
  35. * 静态入口
  36. * @return static|null
  37. */
  38. public static function make()
  39. {
  40. if (!self::$instance) {
  41. self::$instance = (new static());
  42. }
  43. return self::$instance;
  44. }
  45. /**
  46. * @param $params
  47. * @param int $pageSize
  48. * @return array
  49. */
  50. public function getDataList($params, $pageSize = 15)
  51. {
  52. $where = ['a.mark' => 1];
  53. $status = isset($params['status'])? $params['status'] : 0;
  54. $type = isset($params['type'])? $params['type'] : 0;
  55. $userType = isset($params['user_type'])? $params['user_type'] : 0;
  56. if($status>0){
  57. $where['a.status'] = $status;
  58. }
  59. if($type>0){
  60. $where['a.type'] = $type;
  61. }
  62. if($userType>0){
  63. $where['a.user_type'] = $userType;
  64. }
  65. $list = $this->model->from('complaint as a')
  66. ->leftJoin('member as b', 'b.id','=','a.user_id')
  67. ->where($where)
  68. ->where(function ($query) use($params){
  69. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  70. if($keyword){
  71. $query->where('a.content','like',"%{$keyword}%");
  72. }
  73. })
  74. ->select(['a.*'])
  75. ->orderBy('a.create_time','desc')
  76. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  77. $list = $list? $list->toArray() :[];
  78. if($list){
  79. foreach($list['data'] as &$item){
  80. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  81. }
  82. }
  83. return [
  84. 'pageSize'=> $pageSize,
  85. 'total'=>isset($list['total'])? $list['total'] : 0,
  86. 'list'=> isset($list['data'])? $list['data'] : []
  87. ];
  88. }
  89. /**
  90. * 获取文章详情
  91. * @param $id
  92. * @return array|mixed
  93. */
  94. public function getInfo($id)
  95. {
  96. $cacheKey = "caches:aomplaint:info_{$id}";
  97. $info = RedisService::get($cacheKey);
  98. if($info){
  99. return $info;
  100. }
  101. $info = $this->model->where(['id'=> $id,'mark'=>1])
  102. ->select(['id','title','albums','user_id','type','content'])
  103. ->first();
  104. $info = $info? $info->toArray() : [];
  105. if($info){
  106. $info['albums'] = $info['albums']? get_images_preview($info['albums']) : [];
  107. $info['content'] = htmlspecialchars_decode($info['content']);
  108. RedisService::set($cacheKey, $info, rand(5,10));
  109. }
  110. return $info;
  111. }
  112. /**
  113. * 提交内容
  114. * @param $userId
  115. * @param $params
  116. * @return mixed
  117. */
  118. public function submit($userId, $params)
  119. {
  120. $albums = isset($params['albums'])? get_format_images($params['albums'],'') : '';
  121. $data = [
  122. 'user_id'=> $userId,
  123. 'title'=> isset($params['title'])? trim($params['title']) : '',
  124. 'user_type'=> isset($params['user_type']) && $params['user_type']? intval($params['user_type']) : 1,
  125. 'mobile'=> isset($params['mobile'])? trim($params['mobile']) : '',
  126. 'content'=> isset($params['content'])? trim($params['content']) : '',
  127. 'type'=> isset($params['type'])? intval($params['type']) : 1,
  128. 'albums'=> $albums,
  129. 'create_time'=> time(),
  130. 'update_time'=> time(),
  131. 'status'=> 1,
  132. 'mark'=> 1,
  133. ];
  134. return $this->model->insertGetId($data);
  135. }
  136. }