ArticleConsultRecordService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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\ArticleConsultRecordsModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 行业咨询记录管理-服务类
  16. * @author laravel开发员
  17. * @since 2020/11/11
  18. * @package App\Services\Common
  19. */
  20. class ArticleConsultRecordService extends BaseService
  21. {
  22. public static $instance = null;
  23. /**
  24. * 构造函数
  25. * @author laravel开发员
  26. * @since 2020/11/11
  27. */
  28. public function __construct()
  29. {
  30. $this->model = new ArticleConsultRecordsModel();
  31. }
  32. /**
  33. * 静态入口
  34. */
  35. public static function make()
  36. {
  37. if (!self::$instance) {
  38. self::$instance = new static();
  39. }
  40. return self::$instance;
  41. }
  42. /**
  43. * 列表(兼容旧方法)
  44. * @param $params
  45. * @param int $pageSize
  46. * @return array
  47. */
  48. public function getDataList($params, $pageSize = 15)
  49. {
  50. $where = ['a.mark' => 1];
  51. $status = isset($params['status']) ? $params['status'] : 0;
  52. if ($status > 0) {
  53. $where['a.status'] = $status;
  54. }
  55. $userId = isset($params['user_id']) ? $params['user_id'] : 0;
  56. if ($userId > 0) {
  57. $where['a.user_id'] = $userId;
  58. }
  59. $sourceId = isset($params['source_id']) ? $params['source_id'] : 0;
  60. if ($sourceId > 0) {
  61. $where['a.source_id'] = $sourceId;
  62. }
  63. $query = $this->model->with(['member','article'])->from('article_consult_records as a')
  64. ->leftJoin('member as b','b.id','=','a.user_id')
  65. ->where($where)
  66. ->where(function ($query) use ($params) {
  67. $keyword = isset($params['keyword']) ? $params['keyword'] : '';
  68. if ($keyword) {
  69. $query->where('a.realname', 'like', "%{$keyword}%")
  70. ->orWhere('a.mobile', 'like', "%{$keyword}%");
  71. }
  72. })
  73. ->where(function ($query) use ($params) {
  74. $date =isset($params['date'])?$params['date']:[];
  75. $start = $date[0] ?? '';
  76. $end = $date[1] ?? '';
  77. if ($start) {
  78. $query->where('a.create_time', '>=', strtotime($start));
  79. }
  80. if ($end && $start < $end) {
  81. $query->where('a.create_time', '<=', strtotime($end));
  82. }else if ($end && $start == $end) {
  83. $query->where('a.create_time', '<', strtotime($end)+86400);
  84. }
  85. })
  86. ->select(['a.*']);
  87. $query->orderBy('a.id', 'desc');
  88. $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
  89. $list = $list ? $list->toArray() : [];
  90. if ($list) {
  91. foreach ($list['data'] as &$item) {
  92. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
  93. }
  94. }
  95. return [
  96. 'msg' => '操作成功',
  97. 'code' => 0,
  98. 'data' => isset($list['data']) ? $list['data'] : [],
  99. 'count' => isset($list['total']) ? $list['total'] : 0,
  100. ];
  101. }
  102. /**
  103. * 删除
  104. * @return array
  105. */
  106. public function delete()
  107. {
  108. $this->model->where(['mark'=>0])->where('update_time','<', time() - 600)->delete();
  109. return parent::delete(); // TODO: Change the autogenerated stub
  110. }
  111. /**
  112. * 处理状态
  113. * @param int $adminId
  114. * @return array
  115. */
  116. public function status($adminId=0)
  117. {
  118. $data = request()->all();
  119. if (!$data['id']) {
  120. return message('记录ID不能为空', false);
  121. }
  122. if (!$data['status']) {
  123. return message('记录状态不能为空', false);
  124. }
  125. $error = '';
  126. $item = [
  127. 'id' => $data['id'],
  128. 'status' => $data['status']
  129. ];
  130. if($adminId){
  131. $item['admin_id'] = $data['admin_id'];
  132. }
  133. $rowId = $this->model->edit($item, $error);
  134. if (!$rowId) {
  135. return message($error, false);
  136. }
  137. return message();
  138. }
  139. }