123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Service\MediaService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class MediaController extends Controller
- {
- /**
- * 创建/编辑 素材组
- * */
- public function editGroup(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'name' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $groupId = $request->input('group_id');
- $groupName = $request->input('name');
- $sysGroupId = $request->input('sys_group_id');
- $adminId = $request->input('admin_id');
- # 创建/编辑 素材组
- list($groupId, $errno) = MediaService::editGroup($groupId, $groupName, $sysGroupId, $adminId);
- return self::returnValue(['group_id' => $groupId], $errno);
- }
- /**
- * 删除素材组
- * */
- public function delGroup(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'group_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $groupId = $request->input('group_id');
- $sysGroupId = $request->input('sys_group_id');
- $adminId = $request->input('admin_id');
- # 删除
- $errno = MediaService::delGroup($groupId, $sysGroupId, $adminId);
- return self::returnValue([], $errno);
- }
- /**
- * 素材组列表
- * */
- public function groupList(Request $request)
- {
- $keyword = $request->input('keyword');
- $sysGroupId = $request->input('sys_group_id');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- # 获取素材组列表
- list($list, $count) = MediaService::getGroupList($sysGroupId, $keyword, $page, $pageSize);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 批量新增/编辑素材到素材库
- * */
- public function editMedia(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'media_data' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $mediaData = $request->input('media_data');
- $sysGroupId = $request->input('sys_group_id');
- $adminId = $request->input('admin_id');
- # 批量保存素材
- $failList = [];
- $errno = MediaService::editMedia($mediaData, $sysGroupId, $adminId, $failList);
- if(!empty($failList)) return self::returnValue(['fail_list' => $failList], $errno);
- return self::returnValue([], $errno);
- }
- /**
- * 素材列表
- * */
- public function mediaList(Request $request)
- {
- $platformId = $request->input('platform_id');
- $groupId = $request->input('group_id');
- $keyword = $request->input('keyword');
- $sysGroupId = $request->input('sys_group_id');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- # 获取素材组列表
- list($list, $count) = MediaService::getMediaList($sysGroupId, $keyword, $platformId, $groupId, $page, $pageSize);
- return self::returnPageValue($list, $count, $pageSize, $page);
- }
- /**
- * 批量移动分组
- * */
- public function changeGroup(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'media_ids' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $mediaIds = $request->input('media_ids');
- $groupId = $request->input('group_id');
- $sysGroupId = $request->input('sys_group_id');
- $adminId = $request->input('admin_id');
- # 执行移动
- $errno = MediaService::changeGroup($mediaIds, $groupId, $sysGroupId, $adminId);
- return self::returnValue([], $errno);
- }
- /**
- * 批量删除素材
- * */
- public function delMedia(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'media_ids' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $mediaIds = $request->input('media_ids');
- $sysGroupId = $request->input('sys_group_id');
- $adminId = $request->input('admin_id');
- # 执行删除
- $errno = MediaService::delMedia($mediaIds, $sysGroupId, $adminId);
- return self::returnValue([], $errno);
- }
- /**
- * 素材库选择素材
- * */
- public function mediaSel(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'media_id' => 'required|integer',
- 'corpid' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $mediaId = $request->input('media_id');
- # 素材入material表
- $errno = 0;
- $data = MediaService::saveMaterial($mediaId, $corpid, $errno);
- return self::returnValue($data, $errno);
- }
- }
|