企微短剧业务系统

MediaController.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Service\MediaService;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. class MediaController extends Controller
  7. {
  8. /**
  9. * 创建/编辑 素材组
  10. * */
  11. public function editGroup(Request $request)
  12. {
  13. $validator = \Validator::make($request->all(),[
  14. 'name' => 'required|string',
  15. ]);
  16. if ($validator->fails()) {
  17. return self::returnValue($validator->getMessageBag(), 1102);
  18. }
  19. $groupId = $request->input('group_id');
  20. $groupName = $request->input('name');
  21. $sysGroupId = $request->input('sys_group_id');
  22. $adminId = $request->input('admin_id');
  23. # 创建/编辑 素材组
  24. list($groupId, $errno) = MediaService::editGroup($groupId, $groupName, $sysGroupId, $adminId);
  25. return self::returnValue(['group_id' => $groupId], $errno);
  26. }
  27. /**
  28. * 删除素材组
  29. * */
  30. public function delGroup(Request $request)
  31. {
  32. $validator = \Validator::make($request->all(),[
  33. 'group_id' => 'required|integer',
  34. ]);
  35. if ($validator->fails()) {
  36. return self::returnValue($validator->getMessageBag(), 1102);
  37. }
  38. $groupId = $request->input('group_id');
  39. $sysGroupId = $request->input('sys_group_id');
  40. $adminId = $request->input('admin_id');
  41. # 删除
  42. $errno = MediaService::delGroup($groupId, $sysGroupId, $adminId);
  43. return self::returnValue([], $errno);
  44. }
  45. /**
  46. * 素材组列表
  47. * */
  48. public function groupList(Request $request)
  49. {
  50. $keyword = $request->input('keyword');
  51. $sysGroupId = $request->input('sys_group_id');
  52. $page = $request->input('page', 1);
  53. $pageSize = $request->input('page_size', 20);
  54. # 获取素材组列表
  55. list($list, $count) = MediaService::getGroupList($sysGroupId, $keyword, $page, $pageSize);
  56. return self::returnPageValue($list, $count, $pageSize, $page);
  57. }
  58. /**
  59. * 批量新增/编辑素材到素材库
  60. * */
  61. public function editMedia(Request $request)
  62. {
  63. $validator = \Validator::make($request->all(),[
  64. 'media_data' => 'required',
  65. ]);
  66. if ($validator->fails()) {
  67. return self::returnValue($validator->getMessageBag(), 1102);
  68. }
  69. $mediaData = $request->input('media_data');
  70. $sysGroupId = $request->input('sys_group_id');
  71. $adminId = $request->input('admin_id');
  72. # 批量保存素材
  73. $failList = [];
  74. $errno = MediaService::editMedia($mediaData, $sysGroupId, $adminId, $failList);
  75. if(!empty($failList)) return self::returnValue(['fail_list' => $failList], $errno);
  76. return self::returnValue([], $errno);
  77. }
  78. /**
  79. * 素材列表
  80. * */
  81. public function mediaList(Request $request)
  82. {
  83. $platformId = $request->input('platform_id');
  84. $groupId = $request->input('group_id');
  85. $keyword = $request->input('keyword');
  86. $sysGroupId = $request->input('sys_group_id');
  87. $page = $request->input('page', 1);
  88. $pageSize = $request->input('page_size', 20);
  89. # 获取素材组列表
  90. list($list, $count) = MediaService::getMediaList($sysGroupId, $keyword, $platformId, $groupId, $page, $pageSize);
  91. return self::returnPageValue($list, $count, $pageSize, $page);
  92. }
  93. /**
  94. * 批量移动分组
  95. * */
  96. public function changeGroup(Request $request)
  97. {
  98. $validator = \Validator::make($request->all(),[
  99. 'media_ids' => 'required',
  100. ]);
  101. if ($validator->fails()) {
  102. return self::returnValue($validator->getMessageBag(), 1102);
  103. }
  104. $mediaIds = $request->input('media_ids');
  105. $groupId = $request->input('group_id');
  106. $sysGroupId = $request->input('sys_group_id');
  107. $adminId = $request->input('admin_id');
  108. # 执行移动
  109. $errno = MediaService::changeGroup($mediaIds, $groupId, $sysGroupId, $adminId);
  110. return self::returnValue([], $errno);
  111. }
  112. /**
  113. * 批量删除素材
  114. * */
  115. public function delMedia(Request $request)
  116. {
  117. $validator = \Validator::make($request->all(),[
  118. 'media_ids' => 'required',
  119. ]);
  120. if ($validator->fails()) {
  121. return self::returnValue($validator->getMessageBag(), 1102);
  122. }
  123. $mediaIds = $request->input('media_ids');
  124. $sysGroupId = $request->input('sys_group_id');
  125. $adminId = $request->input('admin_id');
  126. # 执行删除
  127. $errno = MediaService::delMedia($mediaIds, $sysGroupId, $adminId);
  128. return self::returnValue([], $errno);
  129. }
  130. /**
  131. * 素材库选择素材
  132. * */
  133. public function mediaSel(Request $request)
  134. {
  135. $validator = \Validator::make($request->all(),[
  136. 'media_id' => 'required|integer',
  137. 'corpid' => 'required|string',
  138. ]);
  139. if ($validator->fails()) {
  140. return self::returnValue($validator->getMessageBag(), 1102);
  141. }
  142. $corpid = $request->input('corpid');
  143. $mediaId = $request->input('media_id');
  144. # 素材入material表
  145. $errno = 0;
  146. $data = MediaService::saveMaterial($mediaId, $corpid, $errno);
  147. return self::returnValue($data, $errno);
  148. }
  149. }