ArticleService.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\AcceptorModel;
  13. use App\Models\AccountLogModel;
  14. use App\Models\ActionLogModel;
  15. use App\Models\ArticleModel;
  16. use App\Models\GoodsCategoryModel;
  17. use App\Models\GoodsModel;
  18. use App\Models\TradeModel;
  19. use App\Services\BaseService;
  20. use App\Services\RedisService;
  21. use Illuminate\Support\Facades\DB;
  22. /**
  23. * 承兑商管理-服务类
  24. * @author laravel开发员
  25. * @since 2020/11/11
  26. * @package App\Services\Common
  27. */
  28. class ArticleService extends BaseService
  29. {
  30. /**
  31. * 构造函数
  32. * @author laravel开发员
  33. * @since 2020/11/11
  34. */
  35. public function __construct()
  36. {
  37. $this->model = new ArticleModel();
  38. }
  39. /**
  40. * 获取列表
  41. * @param $params 参数
  42. * @param int $pageSize 分页大小:默认 15
  43. * @return array
  44. */
  45. public function getDataList($params, $pageSize = 10, $field=[])
  46. {
  47. $where = ['a.mark' => 1];
  48. $query = $this->model->from('article as a')
  49. ->where($where)
  50. ->select($field ? $field : ['a.*']);
  51. if (isset($params['title']) && $params['title'] != '') {
  52. $query->where(function($query) use($params){
  53. $query->where('a.title','like',"%{$params['title']}%")
  54. ->orWhere('a.title_en','like',"%{$params['title']}%");
  55. });
  56. }
  57. if (isset($params['status'])) {
  58. if(is_array($params['status'])){
  59. $query->whereIn('a.status',$params['status']);
  60. }else{
  61. if($params['status'] != ''){
  62. $query->where('a.status',$params['status']);
  63. }
  64. }
  65. }
  66. if (isset($params['type'])) {
  67. if(is_array($params['type'])){
  68. $query->whereIn('a.type',$params['type']);
  69. }else{
  70. if($params['type'] != ''){
  71. $query->where('a.type',$params['type']);
  72. }
  73. }
  74. }
  75. $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
  76. $list = $list ? $list->toArray() : [];
  77. if ($list) {
  78. foreach ($list['data'] as &$item) {
  79. $item['cover'] = $item['cover'] ? get_image_url($item['cover']) : $item['cover'];
  80. $item['create_time'] = $item['create_time'] ? datetime(strtotime($item['create_time'])) : '';
  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. * @return array
  92. * @since 2020/11/11
  93. * @author laravel开发员
  94. */
  95. public function edit()
  96. {
  97. // 请求参数
  98. $data = request()->all();
  99. if(!empty($data['cover'])){
  100. $cover = trim($data['cover']);
  101. if (strpos($cover, "temp")) {
  102. $data['cover'] = save_image($cover, 'ad');
  103. } else {
  104. $data['cover'] = str_replace(IMG_URL, "", $data['cover']);
  105. }
  106. }
  107. ActionLogModel::setTitle("发布或编辑文章资讯");
  108. ActionLogModel::record();
  109. return parent::edit($data); // TODO: Change the autogenerated stub
  110. }
  111. }