VideoController.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. <?php
  2. /**
  3. * 视频相关
  4. * @author x.b
  5. *
  6. */
  7. declare(strict_types=1);
  8. namespace Modules\Manage\Controllers;
  9. use App\Jobs\ClearAllLastestPagesCacheJob;
  10. use App\Jobs\HomeVideoInitJob;
  11. use App\Jobs\SendMessageToUserJob;
  12. use App\Jobs\VideoAutoCommentJob;
  13. use App\Model\TypeVideoModel;
  14. use App\Model\UserBuyVideoModel;
  15. use App\Model\UserModel;
  16. use App\Model\VideoModel as Model;
  17. use App\Model\VideoModel;
  18. use App\Model\VideoPerfectModel;
  19. use App\Repositories\CreatorRepository;
  20. use App\Repositories\Service\CommonService;
  21. use App\Repositories\Service\QueueService;
  22. use App\Repositories\VideoRepository;
  23. use Carbon\Carbon;
  24. use Hyperf\DbConnection\Db;
  25. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  26. use Modules\Api\Services\VideoService;
  27. use App\Model\TypeModel;
  28. use App\Constants\CommonConstant;
  29. class VideoController extends BaseController
  30. {
  31. /**
  32. * 视频列表
  33. * @param ValidatorFactoryInterface $validatorFactory
  34. * @return mixed
  35. * @example param_json_data string:
  36. * {"handshake":"","data":{"page":1,"page_size":5,"order":"id","order_sort":"desc","search":{"is_home":"","type_id":"53","title":"","video_id":"","user_id":"","status":"","check":"","stime":"","otime":""}}}
  37. */
  38. public function list(ValidatorFactoryInterface $validatorFactory)
  39. {
  40. $inputData = $this->getJsonData();
  41. $rules = [
  42. 'page' => 'required|int',
  43. 'page_size' => 'required|int',
  44. ];
  45. $validator = $validatorFactory->make($inputData, $rules);
  46. if ($validator->fails()) {
  47. return json_fail($validator->errors()->first());
  48. }
  49. $page = $inputData['page'];
  50. $page_size = intval($inputData['page_size']);
  51. if ($page_size <= 0) {
  52. $page_size = 12;
  53. }
  54. if ($page_size > 100) {
  55. $page_size = CommonConstant::PAGE_SIZE;
  56. }
  57. $select = [
  58. 'video.*',
  59. Db::raw("(select user.nick from user where user.code=video.uid) AS user_nick"),
  60. ];
  61. $model = Model::query();
  62. $order_key = isset($inputData['order']) ? $inputData['order'] : 'id';
  63. $order_value = isset($inputData['order_sort']) ? $inputData['order_sort'] : 'desc';
  64. if (!$order_key) {
  65. $order_key = 'id'; //不要信任前端,他可能会传个空字符串过来!
  66. }
  67. if (!$order_value) {
  68. $order_value = 'desc';
  69. }
  70. // "type_id":"视频分类ID", "title":"视频名字", "video_id":"视频ID", "user_id":"用户ID", "status":"上架状态", "check":"审核状态","stime":"视频的上传开始时间", "otime":"视频的上传结束时间", "is_home":"是否为首页视频( 0-不是 1-是 ''-不过滤)"
  71. // 备注: mu字段没包含.m3u8就是没转码
  72. $search = isset($inputData['search']) ? $inputData['search'] : array();
  73. if ($search) {
  74. foreach ($search as $k => $v) {
  75. if (!strlen((string)$v)) {
  76. continue;
  77. }
  78. switch ($k) {
  79. case "is_home":
  80. $is_home_ids = VideoPerfectModel::query()->pluck('video_id');
  81. if ($v=='1') {
  82. $model->whereIn('id', $is_home_ids);
  83. } else {
  84. $model->whereNotIn('id', $is_home_ids);
  85. }
  86. break;
  87. case "type_id":
  88. $model->where('tv.'.$k, $v);
  89. $model->leftJoin('type_video as tv', 'video.id', '=', 'tv.video_id');
  90. break;
  91. case "category_alias_name":
  92. $model->whereHas('perfect', function ($q1) use ($v) {
  93. $q1->where('category_alias_name', $v);
  94. });
  95. break;
  96. case "title":
  97. $model->where('video.'.$k, 'like', '%' . $v . '%');
  98. break;
  99. case "user_id":
  100. $model->where('video.uid', $v);
  101. break;
  102. case "video_id":
  103. $model->where('video.id', $v);
  104. break;
  105. case "stime":
  106. $model->where('video.created_at', '>=', Carbon::parse($v)->startOfDay()->toDateTimeString());
  107. break;
  108. case "otime":
  109. $model->where('video.created_at', '<=', Carbon::parse($v)->endOfDay()->toDateTimeString());
  110. break;
  111. case "online_otime":
  112. $model->where('video.online_at', '>=', Carbon::parse($v)->startOfDay()->toDateTimeString());
  113. break;
  114. case "online_stime":
  115. $model->where('video.online_at', '<=', Carbon::parse($v)->endOfDay()->toDateTimeString());
  116. break;
  117. case "player_type":
  118. $model->where('video.player_type', $v);
  119. break;
  120. default:
  121. $model->where('video.'.$k, $v);
  122. }
  123. }
  124. }
  125. $creatorRepo = make(CreatorRepository::class);
  126. $result = $model->select($select)
  127. ->with(['category:type.id as type_id,type.title', 'perfect:id,video_id,category_alias_name'])
  128. // ->withCount('perfect')
  129. ->orderBy((string)$order_key, (string)$order_value)
  130. ->paginate($page_size, ['*'], 'page', $page);
  131. $result = $result->toArray();
  132. if (!empty($result['data'])) {
  133. foreach ($result['data'] as &$v) {
  134. if ($v['pay_type'] == 2) {
  135. // 金币视频, 才走sql
  136. $v['buy_video_count'] = $creatorRepo->countVideoBuyer($v['id']);
  137. } else {
  138. $v['buy_video_count'] = 0;
  139. }
  140. }
  141. }
  142. //处理图片/视频路径
  143. // foreach ($result as $v) {
  144. // if (!$v->from) {
  145. // $v->cover = make(CommonService::class)->getImageUrl((string)$v->cover, true);
  146. // $v->smu = make(VideoService::class)->getPlayUrl((string)$v->from, (string)$v->smu);
  147. // $v->mu = make(VideoService::class)->getPlayUrl((string)$v->from, (string)$v->mu);
  148. // }
  149. // }
  150. return json_success($result);
  151. }
  152. /**
  153. * 删除 (假删)
  154. * @param ValidatorFactoryInterface $validatorFactory
  155. * @return mixed
  156. * @example param_json_data string: {"handshake":"","data":{"id":8}}
  157. */
  158. public function delete(ValidatorFactoryInterface $validatorFactory)
  159. {
  160. $inputData = $this->getJsonData();
  161. $rules = [
  162. 'id' => 'required|int',
  163. ];
  164. $validator = $validatorFactory->make($inputData, $rules);
  165. if ($validator->fails()) {
  166. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  167. return json_fail($validator->errors()->first());
  168. }
  169. $info = Model::query()
  170. ->where('id', $inputData['id'])
  171. ->first();
  172. if (!$info) {
  173. return json_fail('视频信息不存在');
  174. }
  175. $result = Model::query()
  176. ->where('id', $inputData['id'])
  177. ->delete();
  178. if (!$result) {
  179. return json_fail('删除失败');
  180. }
  181. // 清理最新视频分页缓存.
  182. dispatch_job(new ClearAllLastestPagesCacheJob());
  183. // 创建管理员日志
  184. $olditem = clone $info;
  185. $logSubject = "删除视频";
  186. $logSvalue = $olditem->id;
  187. $logDbData = [
  188. 'after_items' => [
  189. ],
  190. 'before_items' => [
  191. $olditem->toArray(),
  192. ],
  193. ];
  194. $this->log($logSubject, $logSvalue, $logDbData);
  195. return json_success($result);
  196. }
  197. /**
  198. * 删除-批量 (假删)
  199. * @param ValidatorFactoryInterface $validatorFactory
  200. * @return mixed
  201. * @example param_json_data string: {"handshake":"","data":{"ids":"1,2,4"}}
  202. */
  203. public function deleteList(ValidatorFactoryInterface $validatorFactory)
  204. {
  205. $inputData = $this->getJsonData();
  206. $rules = [
  207. 'ids' => 'required|string',
  208. ];
  209. $validator = $validatorFactory->make($inputData, $rules);
  210. if ($validator->fails()) {
  211. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  212. return json_fail($validator->errors()->first());
  213. }
  214. $ids = $inputData['ids'];
  215. $_ids = explode(',', $ids);
  216. $ids_list = [];
  217. foreach ($_ids as $kk => $vv) {
  218. if (!$vv) {
  219. continue;
  220. }
  221. $ids_list[] = $vv;
  222. }
  223. if (!$ids_list) {
  224. return json_fail("操作失败,没有满足的视频ID");
  225. }
  226. $result = Model::query()
  227. ->whereIn('id', $ids_list)
  228. ->delete();
  229. if (!$result) {
  230. return json_fail('删除失败');
  231. }
  232. // 清理最新视频分页缓存.
  233. dispatch_job(new ClearAllLastestPagesCacheJob());
  234. // 创建管理员日志
  235. $logSubject = "批量删除视频,ids为:{$ids}";
  236. $logSvalue = '';
  237. $logDbData = [
  238. 'after_items' => [],
  239. 'before_items' => [
  240. $ids_list
  241. ],
  242. ];
  243. return json_success($result);
  244. }
  245. /**
  246. * 回收站-列表 (强制过滤删除的视频)
  247. * @param ValidatorFactoryInterface $validatorFactory
  248. * @return mixed
  249. * @example param_json_data string:
  250. * {"handshake":"","data":{"page":1,"page_size":5,"order":"id","order_sort":"desc","search":{"type_id":"","title":"","video_id":"","user_id":"","status":"","check":"","stime":"","otime":""}}}
  251. */
  252. public function deleteHistoryList(ValidatorFactoryInterface $validatorFactory)
  253. {
  254. $inputData = $this->getJsonData();
  255. $rules = [
  256. 'page' => 'required|int',
  257. 'page_size' => 'required|int',
  258. ];
  259. $validator = $validatorFactory->make($inputData, $rules);
  260. if ($validator->fails()) {
  261. return json_fail($validator->errors()->first());
  262. }
  263. $page = $inputData['page'];
  264. $page_size = $inputData['page_size'];
  265. $select = [
  266. 'video.*',
  267. Db::raw("(select user.nick from user where user.code=video.uid) AS user_nick"),
  268. ];
  269. //$model = Model::query(); //这样写法,是查询出deleted_at无值的数据
  270. $model = Model::query()->onlyTrashed(); //注意:这样写,因需要查询出deleted_at有值的数据,
  271. $order_key = isset($inputData['order']) ? $inputData['order'] : 'id';
  272. $order_value = isset($inputData['order_sort']) ? $inputData['order_sort'] : 'desc';
  273. if (!$order_key) {
  274. $order_key = 'id'; //不要信任前端,他可能会传个空字符串过来!
  275. }
  276. if (!$order_value) {
  277. $order_value = 'desc';
  278. }
  279. // "type_id":"视频分类ID", "title":"视频名字", "video_id":"视频ID", "user_id":"用户ID", "status":"上架状态", "check":"审核状态","stime":"视频的上传开始时间", "otime":"视频的上传结束时间"
  280. // 备注: mu字段没包含.m3u8就是没转码
  281. $search = isset($inputData['search']) ? $inputData['search'] : array();
  282. if ($search) {
  283. foreach ($search as $k => $v) {
  284. if (!strlen((string)$v)) {
  285. continue;
  286. }
  287. switch ($k) {
  288. case "type_id":
  289. $model->where('tv.'.$k, $v);
  290. $model->leftJoin('type_video as tv', 'video.id', '=', 'tv.video_id');
  291. break;
  292. case "title":
  293. $model->where('video.'.$k, 'like', $v . '%');
  294. break;
  295. case "user_id":
  296. $model->where('video.uid', $v);
  297. break;
  298. case "video_id":
  299. $model->where('video.id', $v);
  300. break;
  301. case "stime":
  302. $model->where('video.created_at', '>=', $v);
  303. break;
  304. case "otime":
  305. $model->where('video.created_at', '<=', Carbon::parse($v)->endOfDay()->toDateTimeString());
  306. break;
  307. default:
  308. $model->where('video.'.$k, $v);
  309. }
  310. }
  311. }
  312. $result = $model->select($select)
  313. ->with(['category:type.id as type_id,type.title'])
  314. ->orderBy((string)$order_key, (string)$order_value)
  315. ->paginate($page_size, ['*'], 'page', $page);
  316. //处理图片/视频路径
  317. // foreach ($result as $v) {
  318. // if (!$v->from) {
  319. // $v->cover = make(CommonService::class)->getImageUrl((string)$v->cover, true);
  320. // $v->smu = make(VideoService::class)->getPlayUrl((string)$v->from, (string)$v->smu);
  321. // $v->mu = make(VideoService::class)->getPlayUrl((string)$v->from, (string)$v->mu);
  322. // }
  323. // }
  324. return json_success($result);
  325. }
  326. /**
  327. * 回收站-恢复(即取消删除)
  328. * @param ValidatorFactoryInterface $validatorFactory
  329. * @return mixed
  330. * @example param_json_data string: {"handshake":"","data":{"id":2}}
  331. */
  332. public function reset(ValidatorFactoryInterface $validatorFactory)
  333. {
  334. $inputData = $this->getJsonData();
  335. $rules = [
  336. 'id' => 'required|int',
  337. ];
  338. $validator = $validatorFactory->make($inputData, $rules);
  339. if ($validator->fails()) {
  340. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  341. return json_fail($validator->errors()->first());
  342. }
  343. $info = Db::table('video')
  344. ->where('id', $inputData['id'])
  345. ->first();
  346. if (!$info) {
  347. return json_fail('视频信息不存在');
  348. }
  349. $data = [
  350. 'deleted_at' => null,
  351. ];
  352. $result = Db::table('video')
  353. ->where('id', $inputData['id'])
  354. ->update($data);
  355. /*
  356. $result = Model::query()
  357. ->where('id', $inputData['id'])
  358. ->restore(); // 这个写法可以设置为null, 框架提供的方法
  359. */
  360. if (!$result) {
  361. return json_fail('恢复失败');
  362. }
  363. // 创建管理员日志
  364. $olditem = clone $info;
  365. $olditem = json_decode(json_encode($olditem), true);
  366. $newitem = Model::query()
  367. ->where('id', $inputData['id'])
  368. ->first();
  369. $logSubject = "恢复视频,将已删除的视频ID:{$inputData['id']},进行恢复状态";
  370. $logSvalue = $inputData['id'];
  371. $logDbData = [
  372. 'after_items' => [
  373. $newitem->toArray(),
  374. ],
  375. 'before_items' => [
  376. //$olditem->toArray(),
  377. $olditem
  378. ],
  379. ];
  380. $this->log($logSubject, $logSvalue, $logDbData);
  381. // 清理最新视频分页缓存.
  382. dispatch_job(new ClearAllLastestPagesCacheJob());
  383. return json_success($result);
  384. }
  385. /**
  386. * 首页视频管理-列表
  387. * @param ValidatorFactoryInterface $validatorFactory
  388. * @return mixed
  389. * @example param_json_data string:
  390. * {"handshake":"","data":{"page":1,"page_size":5,"order":"id","order_sort":"desc","search":{"title":"","video_id":"","user_id":"","stime":"","otime":""}}}
  391. */
  392. public function indexList(ValidatorFactoryInterface $validatorFactory)
  393. {
  394. $inputData = $this->getJsonData();
  395. $rules = [
  396. 'page' => 'required|int',
  397. 'page_size' => 'required|int',
  398. ];
  399. $validator = $validatorFactory->make($inputData, $rules);
  400. if ($validator->fails()) {
  401. return json_fail($validator->errors()->first());
  402. }
  403. $page = $inputData['page'];
  404. $page_size = $inputData['page_size'];
  405. $order_key = $inputData['order'] ?? "";
  406. $order_value = $inputData['order_sort'] ?? 'desc';
  407. switch ($order_key) {
  408. case "like":
  409. $order_key = 'video.like'; //点赞量
  410. break;
  411. default:
  412. $order_key = 'video_perfect.id'; //不要信任前端,他可能会传个空字符串过来!
  413. }
  414. switch ($order_value) {
  415. case "asc":
  416. $order_value = 'asc';
  417. break;
  418. default:
  419. $order_value = 'desc';
  420. }
  421. $model = VideoPerfectModel::query();
  422. // "title":"视频名字", "video_id":"视频ID", "user_id":"用户ID", "stime":"首页视频添加-开始时间", "otime":"首页视频添加-结束时间"
  423. $search = isset($inputData['search']) ? $inputData['search'] : array();
  424. if ($search) {
  425. foreach ($search as $k => $v) {
  426. if (!strlen((string)$v)) {
  427. continue;
  428. }
  429. switch ($k) {
  430. case "title":
  431. $model->where('video.'.$k, 'like', "{$v}%");
  432. break;
  433. case "video_id":
  434. $model->where('video_perfect.'.$k, $v);
  435. break;
  436. case "user_id":
  437. $model->where('video.uid', $v);
  438. break;
  439. case "stime":
  440. $model->where('video_perfect.created_at', '>=', $v);
  441. break;
  442. case "otime":
  443. $model->where('video_perfect.created_at', '<=', Carbon::parse($v)->endOfDay()->toDateTimeString());
  444. break;
  445. default:
  446. }
  447. }
  448. }
  449. $select = [
  450. 'video_perfect.id as video_perfect_id', 'video_perfect.created_at as video_perfect_created_at', 'video_perfect.video_id',
  451. 'video.*',
  452. Db::raw("(select user.nick from user where user.code=video.uid) AS user_nick"),
  453. ];
  454. $result = $model->select($select)
  455. ->join('video', 'video.id', '=', 'video_perfect.video_id')
  456. ->with(['category:type.id as type_id,type.title'])
  457. ->orderBy((string)$order_key, (string)$order_value)
  458. ->paginate($page_size, ['*'], 'page', $page);
  459. //处理图片/视频路径
  460. // foreach ($result as $v) {
  461. // if (!$v->from) {
  462. // $v->cover = make(CommonService::class)->getImageUrl((string)$v->cover, true);
  463. // $v->smu = make(VideoService::class)->getPlayUrl((string)$v->from, (string)$v->smu);
  464. // $v->mu = make(VideoService::class)->getPlayUrl((string)$v->from, (string)$v->mu);
  465. // }
  466. // }
  467. return json_success($result);
  468. }
  469. /**
  470. * 首页视频管理-删除[真删]
  471. * @param ValidatorFactoryInterface $validatorFactory
  472. * @return mixed
  473. * @example param_json_data string: {"handshake":"","data":{"video_id":"11"}}
  474. */
  475. public function indexDelete(ValidatorFactoryInterface $validatorFactory)
  476. {
  477. $inputData = $this->getJsonData();
  478. $rules = [
  479. 'video_id' => 'required|string',
  480. ];
  481. $validator = $validatorFactory->make($inputData, $rules);
  482. if ($validator->fails()) {
  483. return json_fail($validator->errors()->first());
  484. }
  485. $video_id = $inputData['video_id'];
  486. $info = VideoPerfectModel::query()
  487. ->where('video_id', $video_id)
  488. ->first();
  489. if (!$info) {
  490. return json_fail("此视频已从首页视频中删除,请勿重复操作");
  491. }
  492. $result = VideoPerfectModel::query()
  493. ->where('video_id', $video_id)
  494. ->delete();
  495. if (!$result) {
  496. return json_fail("操作失败");
  497. }
  498. // 创建管理员日志
  499. $old_items = clone $info;
  500. $logSubject = "删除首页视频,id为:{$video_id}";
  501. $logSvalue = $video_id;
  502. $logDbData = [
  503. 'after_items' => [],
  504. 'before_items' => [
  505. $old_items->toArray(),
  506. ],
  507. ];
  508. $this->log($logSubject, $logSvalue, $logDbData);
  509. // 清理最新视频分页缓存.
  510. dispatch_job(new ClearAllLastestPagesCacheJob());
  511. return json_success('', '操作成功');
  512. }
  513. /**
  514. * 首页视频管理-批量删除[真删]
  515. * @param ValidatorFactoryInterface $validatorFactory
  516. * @return mixed
  517. * @example param_json_data string: {"handshake":"","data":{"ids":"1,3,4"}}
  518. */
  519. public function indexDeleteMore(ValidatorFactoryInterface $validatorFactory)
  520. {
  521. $inputData = $this->getJsonData();
  522. $rules = [
  523. 'ids' => 'required|string',
  524. ];
  525. $validator = $validatorFactory->make($inputData, $rules);
  526. if ($validator->fails()) {
  527. return json_fail($validator->errors()->first());
  528. }
  529. $ids = $inputData['ids'];
  530. $_ids = explode(',', $ids);
  531. $ids_list = [];
  532. foreach ($_ids as $kk => $vv) {
  533. if (!$vv) {
  534. continue;
  535. }
  536. $ids_list[] = $vv;
  537. }
  538. if (!$ids_list) {
  539. return json_fail("操作失败,没有满足的视频ID");
  540. }
  541. $result = VideoPerfectModel::query()
  542. ->whereIn('video_id', $ids_list)
  543. ->delete();
  544. if (!$result) {
  545. return json_fail("操作失败");
  546. }
  547. // 创建管理员日志
  548. $logSubject = "批量删除首页视频,ids为:{$ids}";
  549. $logSvalue = '';
  550. $logDbData = [
  551. 'after_items' => [],
  552. 'before_items' => [
  553. $ids_list
  554. ],
  555. ];
  556. $this->log($logSubject, $logSvalue, $logDbData);
  557. // 清理最新视频分页缓存.
  558. dispatch_job(new ClearAllLastestPagesCacheJob());
  559. return json_success('', '操作成功');
  560. }
  561. /**
  562. * 首页视频管理-批量添加
  563. * @param ValidatorFactoryInterface $validatorFactory
  564. * @return mixed
  565. * @example param_json_data string: {"handshake":"","data":{"ids":"1,2,3,4"}}
  566. */
  567. public function indexAdds(ValidatorFactoryInterface $validatorFactory)
  568. {
  569. $inputData = $this->getJsonData();
  570. $rules = [
  571. 'ids' => 'required|string',
  572. ];
  573. $validator = $validatorFactory->make($inputData, $rules);
  574. if ($validator->fails()) {
  575. return json_fail($validator->errors()->first());
  576. }
  577. $ids = $inputData['ids'];
  578. $_ids = explode(',', $ids);
  579. $check = VideoPerfectModel::query()
  580. ->whereIn('video_id', $_ids)
  581. ->get();
  582. $_ids_db = [];
  583. if ($check) { //过滤已添加的视频id
  584. foreach ($check as $k) {
  585. $_ids_db[] = $k->video_id;
  586. }
  587. }
  588. $data = [];
  589. foreach ($_ids as $kk => $vv) {
  590. if (!$vv) {
  591. continue;
  592. }
  593. if (in_array($vv, $_ids_db)) {
  594. continue;
  595. }
  596. $data[] = array(
  597. 'video_id' => $vv,
  598. 'created_at' => Carbon::now()->toDateTimeString(),
  599. 'updated_at' => Carbon::now()->toDateTimeString(),
  600. );
  601. }
  602. if (!$data) {
  603. return json_fail("这些视频已处理,请勿重复操作");
  604. }
  605. $result = VideoPerfectModel::query()
  606. ->insert($data);
  607. if (!$result) {
  608. return json_fail("操作失败");
  609. }
  610. // 创建管理员日志
  611. $logSubject = "批量追加首页视频";
  612. $logSvalue = '';
  613. $logDbData = [
  614. 'after_items' => [
  615. $data
  616. ],
  617. 'before_items' => [],
  618. ];
  619. $this->log($logSubject, $logSvalue, $logDbData);
  620. // 清理最新视频分页缓存.
  621. dispatch_job(new ClearAllLastestPagesCacheJob());
  622. return json_success('', '操作成功');
  623. }
  624. /**
  625. * 审核
  626. * @author x.b
  627. * @param ValidatorFactoryInterface $validatorFactory
  628. * @return mixed
  629. * @example param_json_data string: {"handshake":"","data":{"video_id":7,"check":1}}
  630. */
  631. public function check(ValidatorFactoryInterface $validatorFactory)
  632. {
  633. $inputData = $this->getJsonData();
  634. $rules = [
  635. 'video_id' => 'required|int',
  636. 'check' => 'required|in:1,2',
  637. ];
  638. $validator = $validatorFactory->make($inputData, $rules);
  639. if ($validator->fails()) {
  640. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  641. return json_fail($validator->errors()->first());
  642. }
  643. $data = [
  644. 'id' => $inputData['video_id'],
  645. 'check' => $inputData['check'],
  646. ];
  647. $data = action_data($data);
  648. $oldItem = VideoModel::query()
  649. ->where('id', $inputData['video_id'])
  650. ->first();
  651. if (!$oldItem) {
  652. return json_fail('视频不存在');
  653. }
  654. if ($inputData['check'] == 1 && strpos($oldItem->mu, '.mp4')) {
  655. //状态改为转码中
  656. $data['status'] = 2;
  657. //转码
  658. make(QueueService::class)->addShiftVideoJob(
  659. [
  660. 'path' => $oldItem->mu,
  661. 'table' => 'video',
  662. 'id' => $oldItem->id,
  663. 'update' => 'mu',
  664. ]
  665. );
  666. }
  667. $result = VideoModel::query()
  668. ->where('id', $inputData['video_id'])
  669. ->update($data);
  670. $newitem = VideoModel::query()
  671. ->where('id', $inputData['video_id'])
  672. ->first();
  673. // 创建管理员日志
  674. $logSubject = "审核视频";
  675. $logSvalue = $inputData['video_id'];
  676. $logDbData = [
  677. 'after_items' => [
  678. $newitem->toArray(),
  679. ],
  680. 'before_items' => [
  681. $oldItem->toArray(),
  682. ],
  683. ];
  684. $this->log($logSubject, $logSvalue, $logDbData);
  685. return json_success($result);
  686. }
  687. /**
  688. * 编辑(标示上架/下架)
  689. * @author x.b
  690. * @param ValidatorFactoryInterface $validatorFactory
  691. * @param string no $video_id 视频ID(内调此接口使用) - 非必传
  692. * @param string no $status 状态0-下架 1-上架(内调此接口使用)- 非必传
  693. * @return mixed 若是 内调时,返回bool
  694. * @example param_json_data string: {"handshake":"","data":{"video_id":7,"status":1}}
  695. */
  696. public function update(ValidatorFactoryInterface $validatorFactory, $video_id = '', $status = '')
  697. {
  698. $inputData = $this->getJsonData();
  699. $rules = [
  700. 'video_id' => 'required|int',
  701. 'status' => 'required|in:1,2',
  702. ];
  703. if (!$video_id) {
  704. $validator = $validatorFactory->make($inputData, $rules);
  705. if ($validator->fails()) {
  706. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  707. return json_fail($validator->errors()->first());
  708. }
  709. $is_self = 0; //是否为内调 0-不是 1-是
  710. } else {
  711. $inputData['video_id'] = $video_id;
  712. $inputData['status'] = $status;
  713. $is_self = 1;
  714. }
  715. $oldItem = VideoModel::query()
  716. ->where('id', $inputData['video_id'])
  717. ->first();
  718. if (!$oldItem) {
  719. return $is_self ? false : json_fail('视频不存在');
  720. }
  721. // if ($inputData['status'] == 1
  722. // &&
  723. // (
  724. // !strpos($oldItem->mu, '.m3u8')
  725. // ||
  726. // !strpos($oldItem->smu, '.m3u8')
  727. // )
  728. // ) {
  729. // return $is_self ? false : json_fail('视频还未转码');
  730. // }
  731. $data = [
  732. 'status' => $inputData['status'],
  733. 'online_at' => date('Y-m-d H:i:s'), // 无论上架/下架 都有更新此字段 -老徐
  734. ];
  735. $result = VideoModel::query()
  736. ->where('id', $inputData['video_id'])
  737. ->update($data);
  738. // 同步沉余更新视频分类数据表
  739. $data2 = [
  740. 'status' => $inputData['status'],
  741. ];
  742. $result = TypeVideoModel::query()
  743. ->where('video_id', $inputData['video_id'])
  744. ->update($data2);
  745. $newitem = VideoModel::query()
  746. ->where('id', $inputData['video_id'])
  747. ->first();
  748. // 创建管理员日志
  749. $logSubject = "上下架视频";
  750. $logSvalue = $inputData['video_id'];
  751. $logDbData = [
  752. 'after_items' => [
  753. $newitem->toArray(),
  754. ],
  755. 'before_items' => [
  756. $oldItem->toArray(),
  757. ],
  758. ];
  759. $this->log($logSubject, $logSvalue, $logDbData);
  760. if ($oldItem->status != $newitem->status) {
  761. // 清理最新视频分页缓存.
  762. dispatch_job(new ClearAllLastestPagesCacheJob());
  763. }
  764. return $is_self ? true : json_success($result);
  765. }
  766. /**
  767. * 批量上架 ( 特殊处理: 内调 依次 上架 接口)
  768. * @param ValidatorFactoryInterface $validatorFactory
  769. * @return mixed
  770. * @example param_json_data string: {"handshake":"","data":{"ids":"8,9,10"}}
  771. */
  772. public function setStatusUp(ValidatorFactoryInterface $validatorFactory)
  773. {
  774. $inputData = $this->getJsonData();
  775. $rules = [
  776. 'ids' => 'required|string',
  777. ];
  778. $validator = $validatorFactory->make($inputData, $rules);
  779. if ($validator->fails()) {
  780. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  781. return json_fail($validator->errors()->first());
  782. }
  783. $ids = $inputData['ids'];
  784. $_ids = explode(',', $ids);
  785. $ids_list = [];
  786. foreach ($_ids as $kk => $vv) {
  787. if (!$vv) {
  788. continue;
  789. }
  790. $ids_list[] = $vv;
  791. }
  792. if (!$ids_list) {
  793. return json_fail("操作失败,没有满足的视频ID");
  794. }
  795. $error_msg = "";
  796. foreach ($ids_list as $v) {
  797. $r = self::update($validatorFactory, $v, 1);
  798. if ($r===false) {
  799. $error_msg .= ' '.$v;
  800. }
  801. }
  802. if ($error_msg) {
  803. return json_fail('', '操作失败,以下视频ID处理失败:'.$error_msg);
  804. } else {
  805. // 清理最新视频分页缓存.
  806. dispatch_job(new ClearAllLastestPagesCacheJob());
  807. return json_success('', '全部处理成功');
  808. }
  809. }
  810. /**
  811. * 批量下架
  812. * @param ValidatorFactoryInterface $validatorFactory
  813. * @return mixed
  814. * @example param_json_data string: {"handshake":"","data":{"ids":"8,9,10"}}
  815. */
  816. public function setStatusDown(ValidatorFactoryInterface $validatorFactory)
  817. {
  818. $inputData = $this->getJsonData();
  819. $rules = [
  820. 'ids' => 'required|string',
  821. ];
  822. $validator = $validatorFactory->make($inputData, $rules);
  823. if ($validator->fails()) {
  824. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  825. return json_fail($validator->errors()->first());
  826. }
  827. $ids = $inputData['ids'];
  828. $_ids = explode(',', $ids);
  829. $ids_list = [];
  830. foreach ($_ids as $kk => $vv) {
  831. if (!$vv) {
  832. continue;
  833. }
  834. $ids_list[] = $vv;
  835. }
  836. if (!$ids_list) {
  837. return json_fail("操作失败,没有满足的视频ID");
  838. }
  839. $data = [
  840. 'status' => 2, //2-下架 1-上架
  841. 'online_at' => Carbon::now()->toDateTimeString(),
  842. ];
  843. $result = VideoModel::query()
  844. ->whereIn('id', $ids_list)
  845. ->update($data);
  846. // 同步沉余更新视频分类数据表
  847. $data2 = [
  848. 'status' => 0,
  849. ];
  850. $result = TypeVideoModel::query()
  851. ->whereIn('video_id', $ids_list)
  852. ->update($data2);
  853. // 创建管理员日志
  854. $logSubject = "批量下架视频,ids为:{$ids}";
  855. $logSvalue = '';
  856. $logDbData = [
  857. 'after_items' => [],
  858. 'before_items' => [
  859. $ids_list
  860. ],
  861. ];
  862. $this->log($logSubject, $logSvalue, $logDbData);
  863. // 清理最新视频分页缓存.
  864. dispatch_job(new ClearAllLastestPagesCacheJob());
  865. return json_success($result);
  866. }
  867. /**
  868. * 添加/修改视频
  869. * @author x.b
  870. * @param ValidatorFactoryInterface $validatorFactory
  871. * @return mixed
  872. * @example param_json_data string: {"handshake":"","data":{"video_id":7,"title":1,"cover":'',"mu":'','like':1,"type_ids":'1,3,4',"coins":"10"}}
  873. */
  874. public function save(ValidatorFactoryInterface $validatorFactory)
  875. {
  876. $inputData = $this->getJsonData();
  877. if (isset($inputData['video_id'])) {
  878. $rules = [
  879. 'video_id' => 'int',
  880. 'title' => 'string',
  881. 'cover' => 'string',
  882. 'mu' => 'string',
  883. // 'like' => 'int',
  884. 'type_ids' => 'string',
  885. 'recommend_level' => 'int',
  886. 'pay_type' => 'required|int',
  887. ];
  888. } else {
  889. $rules = [
  890. 'video_id' => 'int',
  891. 'title' => 'required|string',
  892. 'cover' => 'required|string',
  893. 'mu' => 'required|string',
  894. // 'like' => 'int',
  895. 'type_ids' => 'string',
  896. 'recommend_level' => 'int',
  897. 'pay_type' => 'required|int',
  898. ];
  899. }
  900. $validator = $validatorFactory->make($inputData, $rules);
  901. if ($validator->fails()) {
  902. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  903. return json_fail($validator->errors()->first());
  904. }
  905. if (!$inputData['video_id']) {
  906. if (!$inputData['mu']) {
  907. return json_fail('请上传视频');
  908. }
  909. }
  910. $coins = intval(data_get($inputData, 'coins', 0));
  911. $payType = intval(data_get($inputData, 'pay_type', 1));
  912. if ($coins < 0) {
  913. return json_fail('请填写金币');
  914. }
  915. $data = [
  916. 'title' => $inputData['title'] ?? '',
  917. 'cover' => $inputData['cover'] ?? '',
  918. 'mu' => $inputData['mu'] ?? '',
  919. // 'like' => $inputData['like'],
  920. 'pay_type' => $payType,
  921. 'coins' => $coins, //金币
  922. 'uid' => $inputData['uid'] ?? '', //视频表uid 即用户邀请码 (微啪-非必传,官方视频绑定为 DFZUAR ),抖音-约会版 必传字段
  923. 'recommend_level' => isset($inputData['recommend_level']) ? intval($inputData['recommend_level']) : 0,
  924. ];
  925. /*if ($data['uid']) {
  926. $check = UserModel::query()
  927. ->select(['id'])
  928. ->where('code', $data['uid'])
  929. ->first();
  930. if (!$check) {
  931. return json_fail('请填写正确的用户邀请码');
  932. }
  933. }*/
  934. $newStrTags = '';
  935. $newArrTags = [];
  936. $create = action_data($data);
  937. if ($inputData['video_id']) {
  938. $oldItem = Model::query()
  939. ->where('id', $inputData['video_id'])
  940. ->first();
  941. if (!$oldItem) {
  942. return json_fail('视频不存在');
  943. }
  944. //判断分类
  945. if ($inputData['type_ids']) {
  946. $ids = explode(',', $inputData['type_ids']);
  947. foreach ($ids as $k => $id) {
  948. $typeObj = TypeModel::query()->where(['id' => $id])->first();
  949. if (!empty($typeObj)) {
  950. $newArrTags[] = $typeObj->title;
  951. }
  952. $type[$k] = [
  953. 'type_id' => $id,
  954. 'video_id' => $inputData['video_id'],
  955. ];
  956. }
  957. }
  958. if (isset($type)) {
  959. TypeVideoModel::query()->where('video_id', $inputData['video_id'])
  960. ->delete();
  961. TypeVideoModel::query()->insert($type);
  962. }
  963. if (!empty($newArrTags)) {
  964. $newStrTags = implode(',', $newArrTags);
  965. $create['tags'] = $newStrTags;
  966. } else {
  967. $create['tags'] = '';
  968. }
  969. $result = Model::query()
  970. ->where('id', $inputData['video_id'])
  971. ->update($create);
  972. $newitem = Model::query()
  973. ->where('id', $inputData['video_id'])
  974. ->first();
  975. // 创建管理员日志
  976. $logSubject = "修改视频";
  977. $logSvalue = $inputData['video_id'];
  978. $logDbData = [
  979. 'after_items' => [
  980. $newitem->toArray(),
  981. ],
  982. 'before_items' => [
  983. $oldItem->toArray(),
  984. ],
  985. ];
  986. $this->log($logSubject, $logSvalue, $logDbData);
  987. if ($oldItem->status != $newitem->status) {
  988. // 清理最新视频分页缓存.
  989. dispatch_job(new ClearAllLastestPagesCacheJob());
  990. }
  991. } else {
  992. if ($inputData['type_ids']) {
  993. $ids = explode(',', $inputData['type_ids']);
  994. foreach ($ids as $k => $id) {
  995. $typeObj = TypeModel::query()->where(['id' => $id])->first();
  996. if (!empty($typeObj)) {
  997. $newArrTags[] = $typeObj->title;
  998. }
  999. $type[$k] = [
  1000. 'type_id' => $id,
  1001. 'video_id' => $inputData['video_id'],
  1002. ];
  1003. }
  1004. }
  1005. if (!empty($newArrTags)) {
  1006. $newStrTags = implode(',', $newArrTags);
  1007. $create['tags'] = $newStrTags;
  1008. } else {
  1009. $create['tags'] = '';
  1010. }
  1011. $result = Model::query()->create($create);
  1012. if (!$result) {
  1013. return json_fail('创建失败');
  1014. }
  1015. if (isset($type)) {
  1016. TypeVideoModel::query()->insert($type);
  1017. }
  1018. // 创建管理员日志
  1019. $logSubject = "添加视频";
  1020. $logSvalue = $result->id;
  1021. $logDbData = [
  1022. 'after_items' => [
  1023. $result->toArray(),
  1024. ],
  1025. 'before_items' => [],
  1026. ];
  1027. $this->log($logSubject, $logSvalue, $logDbData);
  1028. // 清理最新视频分页缓存.
  1029. dispatch_job(new ClearAllLastestPagesCacheJob());
  1030. }
  1031. return json_success($result);
  1032. }
  1033. /**
  1034. * 首页视频发布
  1035. * @author x.b
  1036. * @return mixed
  1037. */
  1038. public function home()
  1039. {
  1040. $video_ids = VideoPerfectModel::query()->pluck('video_id')->all();
  1041. $count = count($video_ids) / 5;//总条数
  1042. if ($count < 20) {
  1043. return json_fail('视频至少添加100个,当前' . count($video_ids) . '个');
  1044. }
  1045. $result = make(QueueService::class)->addHomeVideoJob(['video_ids' => $video_ids]);
  1046. // 创建管理员日志
  1047. $logSubject = "发布首页视频";
  1048. $logSvalue = 0;
  1049. $logDbData = [
  1050. 'after_items' => [
  1051. [],
  1052. ],
  1053. 'before_items' => [
  1054. $video_ids
  1055. ],
  1056. ];
  1057. $this->log($logSubject, $logSvalue, $logDbData);
  1058. return json_success($result);
  1059. }
  1060. /**
  1061. * 首页视频桶缓存初始化.
  1062. * @return mixed
  1063. */
  1064. public function homeInit()
  1065. {
  1066. dispatch_job(new HomeVideoInitJob());
  1067. $logSubject = "首页视频桶缓存初始化";
  1068. $logSvalue = 0;
  1069. $logDbData = [
  1070. 'after_items' => [
  1071. [],
  1072. ],
  1073. 'before_items' => [
  1074. ],
  1075. ];
  1076. $this->log($logSubject, $logSvalue, $logDbData);
  1077. return json_success(['result' => 'success']);
  1078. }
  1079. /**
  1080. * 硬删除,用于回收站内.
  1081. * @return mixed
  1082. */
  1083. public function hardDelete()
  1084. {
  1085. $validatorFactory = make(ValidatorFactoryInterface::class);
  1086. $inputData = $this->getJsonData();
  1087. $rules = [
  1088. 'ids' => 'required|array',
  1089. ];
  1090. $validator = $validatorFactory->make($inputData, $rules);
  1091. if ($validator->fails()) {
  1092. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  1093. return json_fail($validator->errors()->first());
  1094. }
  1095. $ids = data_get($inputData, 'ids', []);
  1096. $ids = array_filter($ids);
  1097. $ids = array_unique($ids);
  1098. if (empty($ids)) {
  1099. return json_fail('请选择视频');
  1100. }
  1101. $newIds = [];
  1102. $items = VideoModel::query()->withTrashed()->whereIn('id', $ids)->get(['id', 'deleted_at']);
  1103. if ($items->isNotEmpty()) {
  1104. foreach ($items as $v) {
  1105. if (is_null($v->deleted_at)) {
  1106. return json_fail($v->id . ', 非回收站视频,不能完整执行硬删除操作');
  1107. break;
  1108. } else {
  1109. $newIds[] = $v->id;
  1110. }
  1111. }
  1112. }
  1113. if (!empty($newIds)) {
  1114. $videoRepo = make(VideoRepository::class);
  1115. $videoRepo->hardDelete($newIds);
  1116. } else {
  1117. return json_fail('视频选择有误');
  1118. }
  1119. return json_success(['result' => 'success']);
  1120. }
  1121. /**
  1122. * 审核
  1123. * @return mixed
  1124. */
  1125. public function changeCheck()
  1126. {
  1127. $validatorFactory = make(ValidatorFactoryInterface::class);
  1128. $inputData = $this->getJsonData();
  1129. $rules = [
  1130. 'id' => 'required|int',
  1131. 'target_check' => 'required|int',
  1132. 'reject_reason' => 'nullable', // 拒绝原因.
  1133. ];
  1134. $validator = $validatorFactory->make($inputData, $rules);
  1135. if ($validator->fails()) {
  1136. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  1137. return json_fail($validator->errors()->first());
  1138. }
  1139. $videoRepo = make(VideoRepository::class);
  1140. $targetCheck = intval(data_get($inputData, 'target_check', 0));
  1141. $obj = $videoRepo->find($inputData['id'], ['id', 'title', 'status', 'type', 'check', 'reject_reason', 'updated_at', 'created_at', 'uid', 'online_at']);
  1142. if (empty($obj)) {
  1143. return json_fail('对象不存在');
  1144. }
  1145. $rejectReason = data_get($inputData, 'reject_reason', '');
  1146. if ($obj->check == $targetCheck) {
  1147. return json_fail('前后状态无变化');
  1148. }
  1149. $creatorRepo = make(CreatorRepository::class);
  1150. $creatorObj = $creatorRepo->detail($obj->uid);
  1151. $videoTitle = mb_substr($obj->title, 0, 30);
  1152. $msgSubjct = '恭喜您,视频【'. $videoTitle .'】审核通过.';
  1153. $msgContent = '您可以分享本APP给微信、qq群里的朋友,收益越大.';
  1154. $obj->reject_reason = '';
  1155. if ($targetCheck == 2) {
  1156. $obj->reject_reason = $rejectReason;
  1157. $obj->status = 2;
  1158. $msgSubjct = '视频【'. $videoTitle .'】未通过审核';
  1159. $msgContent = '拒绝原因:' . $rejectReason . ', 若有异议,请联系客服!';
  1160. } elseif ($targetCheck == 1) {
  1161. $obj->status = 1; //审核通过就直接上架.
  1162. $obj->online_at = Carbon::now()->toDateTimeString(); // 上架时间
  1163. $jobParams = [
  1164. 'video_id' => $obj->id,
  1165. 'type' => $obj->type,
  1166. 'status' => 1,
  1167. 'check' => $targetCheck,
  1168. ];
  1169. // 异步自动增加评论和点赞
  1170. dispatch_job(new VideoAutoCommentJob($jobParams));
  1171. }
  1172. $obj->check = $targetCheck;
  1173. $saveStatus = $obj->save();
  1174. if ($saveStatus && !empty($creatorObj)) {
  1175. $jobParams = [
  1176. 'from_type' => 'sys',
  1177. 'receive_uid' => $obj->uid,
  1178. 'subject' => $msgSubjct,
  1179. 'content' => $msgContent,
  1180. ];
  1181. // 异步发送通知站内消息
  1182. dispatch_job(new SendMessageToUserJob($jobParams));
  1183. $creatorRepo->checkUpgrade0to1($creatorObj);
  1184. }
  1185. return json_success(['result' => 'success']);
  1186. }
  1187. /**
  1188. * 批量审核
  1189. * @return mixed
  1190. */
  1191. public function batchChangeCheck()
  1192. {
  1193. $validatorFactory = make(ValidatorFactoryInterface::class);
  1194. $inputData = $this->getJsonData();
  1195. $rules = [
  1196. 'ids' => 'required',
  1197. 'target_check' => 'required|int',
  1198. ];
  1199. $validator = $validatorFactory->make($inputData, $rules);
  1200. if ($validator->fails()) {
  1201. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  1202. return json_fail($validator->errors()->first());
  1203. }
  1204. $videoRepo = make(VideoRepository::class);
  1205. $targetCheck = intval(data_get($inputData, 'target_check', 0));
  1206. $arrIds = [];
  1207. if (is_string($inputData['ids'])) {
  1208. $arrIds = explode(',', $inputData['ids']);
  1209. } else {
  1210. $arrIds = $inputData['ids'];
  1211. }
  1212. $rejectReason = '您上传的视频不符合要求';
  1213. if (!empty($arrIds)) {
  1214. $creatorRepo = make(CreatorRepository::class);
  1215. foreach ($arrIds as $id) {
  1216. $obj = $videoRepo->find($id, ['id', 'title', 'status', 'type', 'check', 'reject_reason', 'updated_at', 'created_at', 'uid', 'online_at']);
  1217. if (empty($obj)) {
  1218. continue;
  1219. }
  1220. if ($obj->check == $targetCheck) {
  1221. continue;
  1222. }
  1223. if ($obj->status == 2 && $obj->check == 0) {
  1224. // 未审核的条件
  1225. $creatorObj = $creatorRepo->detail($obj->uid);
  1226. $videoTitle = mb_substr($obj->title, 0, 30);
  1227. $msgSubjct = '恭喜您,视频【'. $videoTitle .'】审核通过.';
  1228. $msgContent = '您可以分享本APP给微信、qq群里的朋友,收益越大.';
  1229. $obj->reject_reason = '';
  1230. if ($targetCheck == 2) {
  1231. $obj->reject_reason = $rejectReason;
  1232. $obj->status = 2;
  1233. $msgSubjct = '视频【'. $videoTitle .'】未通过审核';
  1234. $msgContent = '拒绝原因:' . $rejectReason . ', 若有异议,请联系客服!';
  1235. } elseif ($targetCheck == 1) {
  1236. $obj->status = 1; //审核通过就直接上架.
  1237. $obj->online_at = Carbon::now()->toDateTimeString(); // 上架时间
  1238. $jobParams = [
  1239. 'video_id' => $obj->id,
  1240. 'type' => $obj->type,
  1241. 'status' => 1,
  1242. 'check' => $targetCheck,
  1243. ];
  1244. // 异步自动增加评论和点赞
  1245. dispatch_job(new VideoAutoCommentJob($jobParams));
  1246. }
  1247. $obj->check = $targetCheck;
  1248. $saveStatus = $obj->save();
  1249. if ($saveStatus && !empty($creatorObj)) {
  1250. $jobParams = [
  1251. 'from_type' => 'sys',
  1252. 'receive_uid' => $obj->uid,
  1253. 'subject' => $msgSubjct,
  1254. 'content' => $msgContent,
  1255. ];
  1256. // 异步发送通知站内消息
  1257. dispatch_job(new SendMessageToUserJob($jobParams));
  1258. $creatorRepo->checkUpgrade0to1($creatorObj);
  1259. }
  1260. }
  1261. }
  1262. }
  1263. return json_success(['result' => 'success']);
  1264. }
  1265. }