ArticleService.php 3.7 KB

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