ArticleService.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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\ActionLogModel;
  13. use App\Models\ArticleModel;
  14. use App\Services\BaseService;
  15. /**
  16. * 文章管理-服务类
  17. * @author laravel开发员
  18. * @since 2020/11/11
  19. * Class ArticleService
  20. * @package App\Services\Common
  21. */
  22. class ArticleService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author laravel开发员
  27. * @since 2020/11/11
  28. * ArticleService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new ArticleModel();
  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. $showType = isset($params['show_type'])? $params['show_type'] : 0;
  56. if($status>0){
  57. $where['a.status'] = $status;
  58. }
  59. if($showType==1){
  60. $type = [1,2,3,4,5,6,7,8];
  61. }else if($showType == 2){
  62. $type = [9,10,11,99];
  63. }
  64. $list = $this->model->from('article as a')
  65. ->where($where)
  66. ->where(function($query) use($type){
  67. if($type && is_array($type)){
  68. $query->whereIn('a.type',$type);
  69. }else if($type){
  70. $query->where('a.type',$type);
  71. }
  72. })
  73. ->where(function ($query) use($params){
  74. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  75. if($keyword){
  76. $query->where('a.title','like',"%{$keyword}%")->orWhere('a.tags','like',"%{$keyword}%");
  77. }
  78. })
  79. ->select(['a.*'])
  80. ->orderBy('a.create_time','desc')
  81. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  82. $list = $list? $list->toArray() :[];
  83. if($list){
  84. $typrArr = ['','普通文章','诚意金说明','关于我们','司机等级升级说明','用户注册协议','隐私政策','申请司机说明','邀请有奖活动规则','常见问题','账号登录','商家合作'];
  85. foreach($list['data'] as &$item){
  86. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  87. $item['cover'] = $item['cover']? get_image_url($item['cover']) : '';
  88. $item['content'] = $item['content']? get_format_content($item['content']) : '';
  89. $item['type_name'] = isset($typrArr[$item['type']])? $typrArr[$item['type']] : '其他';
  90. }
  91. }
  92. return [
  93. 'pageSize'=> $pageSize,
  94. 'total'=>isset($list['total'])? $list['total'] : 0,
  95. 'list'=> isset($list['data'])? $list['data'] : []
  96. ];
  97. }
  98. /**
  99. * 添加或编辑
  100. * @return array
  101. * @since 2020/11/11
  102. * @author laravel开发员
  103. */
  104. public function edit()
  105. {
  106. $data = request()->all();
  107. $content = isset($data['content'])? $data['content'] : '';
  108. if($content){
  109. $data['content'] = set_format_content($content);
  110. }
  111. // 设置日志标题
  112. ActionLogModel::setTitle("发布文章或客服咨询信息");
  113. ActionLogModel::record();
  114. return parent::edit($data); // TODO: Change the autogenerated stub
  115. }
  116. }