// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\AcceptorModel; use App\Models\TaskModel; use App\Models\TradeModel; use App\Models\VideoModel; use App\Services\BaseService; use Illuminate\Support\Facades\DB; /** * 承兑商管理-服务类 * @author laravel开发员 * @since 2020/11/11 * @package App\Services\Common */ class VideosService extends BaseService { /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 */ public function __construct() { $this->model = new VideoModel(); } /** * 获取列表 * @param $params 参数 * @param int $pageSize 分页大小:默认 15 * @return array */ public function getDataList($params, $pageSize = 10, $field = []) { $where = ['a.mark' => 1]; $query = $this->model->with(['member']) ->from('videos as a') ->leftJoin('member as b','b.id','a.user_id') ->where($where) ->select($field ? $field : ['a.*']); if (isset($params['member']) && $params['member'] != '') { $query->where(function($query) use($params){ $kw = isset($params['member'])? trim($params['member']) : ''; if($kw){ $query->where('b.nickname','like',"%{$params['member']}%") ->orWhere('b.realname','like',"%{$params['member']}%") ->orWhere('b.username','like',"%{$params['member']}%") ->orWhere('b.id','like',"%{$params['member']}%"); } }); } if (isset($params['title']) && $params['title'] != '') { $query->where('a.title','like',"%{$params['title']}%"); } if (isset($params['visible_type']) && $params['visible_type']) { if(is_array($params['visible_type'])){ $query->whereIn('a.visible_type',$params['visible_type']); }else{ if($params['visible_type'] != ''){ $query->where('a.visible_type',$params['visible_type']); } } } if (isset($params['type']) && $params['type']) { if(is_array($params['type'])){ $query->whereIn('a.type',$params['type']); }else{ if($params['type'] != ''){ $query->where('a.type',$params['type']); } } } if (isset($params['is_comment']) && $params['is_comment']) { if(is_array($params['is_comment'])){ $query->whereIn('a.is_comment',$params['is_comment']); }else{ if($params['is_comment'] != ''){ $query->where('a.is_comment',$params['is_comment']); } } } if (isset($params['is_short']) && $params['is_short']) { if(is_array($params['is_short'])){ $query->whereIn('a.is_short',$params['is_short']); }else{ if($params['is_short'] != ''){ $query->where('a.is_short',$params['is_short']); } } } if (isset($params['status']) && $params['status']) { if(is_array($params['status'])){ $query->whereIn('a.status',$params['status']); }else{ if($params['status'] != ''){ $query->where('a.status',$params['status']); } } } $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list ? $list->toArray() : []; if ($list) { foreach ($list['data'] as &$item) { $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : $item['thumb']; $item['file_url'] = $item['file_url'] ? get_image_url($item['file_url']) : $item['file_url']; $item['music_url'] = $item['music_url'] ? get_image_url($item['music_url']) : $item['music_url']; $item['albums'] =$item['albums'] ? json_decode($item['albums'],true):$item['albums']; // if(!empty($item['albums'])){ // $item['albums'] = array_map("get_image_url",json_decode($item['albums'])); // } } } return [ 'pageSize' => $pageSize, 'total' => isset($list['total']) ? $list['total'] : 0, 'list' => isset($list['data']) ? $list['data'] : [] ]; } /** * 添加会编辑会员 * @return array * @since 2020/11/11 * @author laravel开发员 */ public function edit() { // 请求参数 $data = request()->all(); if(!empty($data['thumb'])){ $data['thumb'] = $data['thumb'] ? remove_image_url($data['thumb']) : $data['thumb']; } if(!empty($data['albums'])){ $data['albums'] = $data['albums'] && is_array($data['albums']) ? json_encode($data['albums']) : $data['albums']; } return parent::edit($data); // TODO: Change the autogenerated stub } }