VideoLogic.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\admin\logic;
  3. use app\model\CommonModel;
  4. use app\model\VideoModel;
  5. use think\exception\ValidateException;
  6. use think\response\Json;
  7. class VideoLogic extends BaseLogic
  8. {
  9. //获取视频列表
  10. public static function List(array $data = []): Json
  11. {
  12. $db = VideoModel::where('is_del', CommonModel::$del_normal);
  13. if ($data['status'] != '') $db->where('status', $data['status']);
  14. if ($data['video_sn'] !== '') $db->whereLike('video_sn', '%' . $data['video_sn'] . '%');
  15. if ($data['video_name']) $db->whereLike('video_name', '%' . $data['video_name'] . '%');
  16. if ($data['video_url'] != '') $db->whereLike('video_url', '%' . $data['video_url'] . '%');
  17. $count = $db->count('id');
  18. $video = $db
  19. ->field('id,video_name,remark,status,addtime')
  20. ->page($data['page'], $data['size'])
  21. ->order('addtime desc')
  22. ->select()
  23. ->toArray();
  24. return json_show(CommonModel::$success, '获取成功', ['list' => $video, 'count' => $count]);
  25. }
  26. //添加视频
  27. public static function Add(array $data = []): Json
  28. {
  29. $rs = VideoModel::field('id')
  30. ->where(['is_del' => CommonModel::$del_normal, 'video_name' => $data['video_name']])
  31. ->findOrEmpty()
  32. ->isEmpty();
  33. if (!$rs) throw new ValidateException('该视频名称已存在');
  34. $video_sn = make_no("FC");
  35. $data = array_merge($data, [
  36. "video_sn" => $video_sn,
  37. "is_del" => CommonModel::$del_normal,
  38. "status" => CommonModel::$status_normal,
  39. "addtime" => date("Y-m-d H:i:s"),
  40. "updatetime" => date("Y-m-d H:i:s"),
  41. ]);
  42. // write_log("视频{$video}新建成功", $this->userinfo, "account", "add");
  43. $res = VideoModel::create($data)->save();
  44. return $res ? json_show(CommonModel::$success, '视频新建成功') : json_show(CommonModel::$error_param, '视频新建失败');
  45. }
  46. //读取视频详情
  47. public static function Read(int $id = 0): Json
  48. {
  49. $rs = VideoModel::field(true)
  50. ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
  51. ->findOrEmpty()
  52. ->toArray();
  53. return json_show(CommonModel::$success, '获取视频详情成功', $rs);
  54. }
  55. //编辑视频
  56. public static function Edit(array $data = []): Json
  57. {
  58. $rs = VideoModel::field('id,video_name')
  59. ->where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
  60. ->findOrEmpty();
  61. if ($rs->isEmpty()) throw new ValidateException('该视频不存在');
  62. //修改了视频名称,检查视频名称是否重复
  63. if ($rs->video_name != $data['video_name']) {
  64. $temp = VideoModel::field('id')
  65. ->where(['is_del' => CommonModel::$del_normal, 'video_name' => $data['video_name']])
  66. ->findOrEmpty()
  67. ->isEmpty();
  68. if (!$temp) throw new ValidateException('该视频名称重复');
  69. }
  70. $data = array_merge($data, [
  71. "updatetime" => date("Y-m-d H:i:s"),
  72. ]);
  73. // write_log("视频{$video}新建成功", $this->userinfo, "account", "add");
  74. $res = VideoModel::where(['id' => $data['id']])->save($data);
  75. return $res ? json_show(CommonModel::$success, '视频内容编辑成功') : json_show(CommonModel::$error_param, '视频内容编辑失败');
  76. }
  77. //视频启禁用
  78. public static function Change(array $data = []): Json
  79. {
  80. $where = [
  81. ['id', '=', $data['id']],
  82. ['is_del', '=', CommonModel::$del_normal],
  83. ['status', '<>', $data['status']],
  84. ];
  85. $rs = VideoModel::field('id,status')
  86. ->where($where)
  87. ->findOrEmpty()
  88. ->isEmpty();
  89. if ($rs) throw new ValidateException('该视频不存在或重复操作');
  90. // write_log("视频{$video}新建成功", $this->userinfo, "account", "add");
  91. $res = VideoModel::where($where)->save($data);
  92. return $res ? json_show(CommonModel::$success, '更新成功') : json_show(CommonModel::$error_param, '更新失败');
  93. }
  94. //删除视频
  95. public static function Delete(int $id = 0): Json
  96. {
  97. $rs = VideoModel::where(['id' => $id, 'is_del' => CommonModel::$del_normal])
  98. ->save(['is_del' => CommonModel::$del_deleted]);
  99. return $rs ? json_show(CommonModel::$success, '视频删除成功') : json_show(CommonModel::$error_param, '视频不存在或重复删除');
  100. }
  101. }