VideosService.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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\TaskModel;
  14. use App\Models\TradeModel;
  15. use App\Models\VideoModel;
  16. use App\Services\BaseService;
  17. use Illuminate\Support\Facades\DB;
  18. /**
  19. * 承兑商管理-服务类
  20. * @author laravel开发员
  21. * @since 2020/11/11
  22. * @package App\Services\Common
  23. */
  24. class VideosService extends BaseService
  25. {
  26. /**
  27. * 构造函数
  28. * @author laravel开发员
  29. * @since 2020/11/11
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new VideoModel();
  34. }
  35. /**
  36. * 获取列表
  37. * @param $params 参数
  38. * @param int $pageSize 分页大小:默认 15
  39. * @return array
  40. */
  41. public function getDataList($params, $pageSize = 10, $field = [])
  42. {
  43. $where = ['a.mark' => 1];
  44. $query = $this->model->with(['member'])
  45. ->from('videos as a')
  46. ->leftJoin('member as b','b.id','a.user_id')
  47. ->where($where)
  48. ->select($field ? $field : ['a.*']);
  49. if (isset($params['member']) && $params['member'] != '') {
  50. $query->where(function($query) use($params){
  51. $kw = isset($params['member'])? trim($params['member']) : '';
  52. if($kw){
  53. $query->where('b.nickname','like',"%{$params['member']}%")
  54. ->orWhere('b.realname','like',"%{$params['member']}%")
  55. ->orWhere('b.username','like',"%{$params['member']}%")
  56. ->orWhere('b.id','like',"%{$params['member']}%");
  57. }
  58. });
  59. }
  60. if (isset($params['title']) && $params['title'] != '') {
  61. $query->where('a.title','like',"%{$params['title']}%");
  62. }
  63. if (isset($params['visible_type']) && $params['visible_type']) {
  64. if(is_array($params['visible_type'])){
  65. $query->whereIn('a.visible_type',$params['visible_type']);
  66. }else{
  67. if($params['visible_type'] != ''){
  68. $query->where('a.visible_type',$params['visible_type']);
  69. }
  70. }
  71. }
  72. if (isset($params['type']) && $params['type']) {
  73. if(is_array($params['type'])){
  74. $query->whereIn('a.type',$params['type']);
  75. }else{
  76. if($params['type'] != ''){
  77. $query->where('a.type',$params['type']);
  78. }
  79. }
  80. }
  81. if (isset($params['is_comment']) && $params['is_comment']) {
  82. if(is_array($params['is_comment'])){
  83. $query->whereIn('a.is_comment',$params['is_comment']);
  84. }else{
  85. if($params['is_comment'] != ''){
  86. $query->where('a.is_comment',$params['is_comment']);
  87. }
  88. }
  89. }
  90. if (isset($params['is_short']) && $params['is_short']) {
  91. if(is_array($params['is_short'])){
  92. $query->whereIn('a.is_short',$params['is_short']);
  93. }else{
  94. if($params['is_short'] != ''){
  95. $query->where('a.is_short',$params['is_short']);
  96. }
  97. }
  98. }
  99. if (isset($params['status']) && $params['status']) {
  100. if(is_array($params['status'])){
  101. $query->whereIn('a.status',$params['status']);
  102. }else{
  103. if($params['status'] != ''){
  104. $query->where('a.status',$params['status']);
  105. }
  106. }
  107. }
  108. $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
  109. $list = $list ? $list->toArray() : [];
  110. if ($list) {
  111. foreach ($list['data'] as &$item) {
  112. $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : $item['thumb'];
  113. $item['file_url'] = $item['file_url'] ? get_image_url($item['file_url']) : $item['file_url'];
  114. $item['music_url'] = $item['music_url'] ? get_image_url($item['music_url']) : $item['music_url'];
  115. $item['albums'] =$item['albums'] ? json_decode($item['albums'],true):$item['albums'];
  116. // if(!empty($item['albums'])){
  117. // $item['albums'] = array_map("get_image_url",json_decode($item['albums']));
  118. // }
  119. }
  120. }
  121. return [
  122. 'pageSize' => $pageSize,
  123. 'total' => isset($list['total']) ? $list['total'] : 0,
  124. 'list' => isset($list['data']) ? $list['data'] : []
  125. ];
  126. }
  127. /**
  128. * 添加会编辑会员
  129. * @return array
  130. * @since 2020/11/11
  131. * @author laravel开发员
  132. */
  133. public function edit()
  134. {
  135. // 请求参数
  136. $data = request()->all();
  137. if(!empty($data['thumb'])){
  138. $data['thumb'] = $data['thumb'] ? remove_image_url($data['thumb']) : $data['thumb'];
  139. }
  140. if(!empty($data['albums'])){
  141. $data['albums'] = $data['albums'] && is_array($data['albums']) ? json_encode($data['albums']) : $data['albums'];
  142. }
  143. return parent::edit($data); // TODO: Change the autogenerated stub
  144. }
  145. }