ComplaintService.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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\Common;
  12. use App\Models\ComplaintModel;
  13. use App\Models\FreightPackageModel;
  14. use App\Models\TicketModel;
  15. use App\Services\BaseService;
  16. use App\Services\RedisService;
  17. /**
  18. * 意见反馈管理-服务类
  19. * @author laravel开发员
  20. * @since 2020/11/11
  21. * @package App\Services\Common
  22. */
  23. class ComplaintService extends BaseService
  24. {
  25. // 静态对象
  26. protected static $instance = null;
  27. /**
  28. * 构造函数
  29. * @author laravel开发员
  30. * @since 2020/11/11
  31. */
  32. public function __construct()
  33. {
  34. $this->model = new ComplaintModel();
  35. }
  36. /**
  37. * 静态入口
  38. */
  39. public static function make()
  40. {
  41. if (!self::$instance) {
  42. self::$instance = new static();
  43. }
  44. return self::$instance;
  45. }
  46. /**
  47. * 列表
  48. * @param $params
  49. * @param int $pageSize
  50. * @return array
  51. */
  52. public function getDataList($params, $pageSize = 15)
  53. {
  54. $where = ['a.mark' => 1];
  55. $list = $this->model->from('complaint as a')
  56. ->leftJoin('member as b','b.id','=','a.user_id')
  57. ->leftJoin('driver as c','c.id','=','a.user_id')
  58. ->where($where)
  59. ->where(function ($query) use($params){
  60. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  61. if($keyword){
  62. $query->where('a.title','like',"%{$keyword}%")->orWhere('a.content','like',"%{$keyword}%")->orWhere('a.mobile','like',"%{$keyword}%");
  63. }
  64. })
  65. ->where(function ($query) use($params){
  66. $status = isset($params['status'])? $params['status'] : 0;
  67. if($status>0 && is_array($status)){
  68. $query->whereIn('a.status', $status);
  69. }else if($status){
  70. $query->where('a.status', $status);
  71. }
  72. $type = isset($params['type'])? $params['type'] : 0;
  73. if($type>0){
  74. $query->where('a.type', $type);
  75. }
  76. $userType = isset($params['user_type'])? $params['user_type'] : 0;
  77. if($userType>0){
  78. $query->where('a.user_type', $userType);
  79. }
  80. })
  81. ->select(['a.*','b.nickname as username','c.realname as driver_name'])
  82. ->orderBy('a.create_time','desc')
  83. ->orderBy('a.id','desc')
  84. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  85. $list = $list? $list->toArray() :[];
  86. if($list){
  87. $typeArr = [1=>'功能BUG',2=>'产品优化',3=>'客服功能',4=>'规则制度',5=>'费用相关',99=>'其他'];
  88. foreach($list['data'] as &$item){
  89. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  90. $item['albums'] = $item['albums']? get_images_preview($item['albums']) : [];
  91. if($item['user_type'] == 2){
  92. $item['username'] = $item['driver_name']? $item['driver_name'] : '';
  93. }
  94. $item['type_name'] = isset($typeArr[$item['type']]) && $typeArr[$item['type']]? $typeArr[$item['type']] : '其他';
  95. }
  96. }
  97. return [
  98. 'pageSize'=> $pageSize,
  99. 'total'=>isset($list['total'])? $list['total'] : 0,
  100. 'list'=> isset($list['data'])? $list['data'] : []
  101. ];
  102. }
  103. /**
  104. * 编辑
  105. * @return array
  106. */
  107. public function edit()
  108. {
  109. $data = request()->post();
  110. if(isset($data['albums'])){
  111. $data['albums'] = $data['albums']? get_format_images($data['albums']) : '';
  112. }
  113. return parent::edit($data);
  114. }
  115. }