VideoGroupLogic.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\admin\logic;
  3. use app\model\CommonModel;
  4. use app\model\VideoGroupModel;
  5. use think\exception\ValidateException;
  6. use think\response\Json;
  7. class VideoGroupLogic extends BaseLogic
  8. {
  9. //获取视频分组列表
  10. public static function list(array $data = []): Json
  11. {
  12. $db = VideoGroupModel::alias('a')
  13. ->leftJoin('company b', 'b.id=a.company_id')
  14. ->leftJoin('card c', 'c.id=a.card_id')
  15. ->where('a.is_del', CommonModel::$del_normal);
  16. if ($data['status'] != '') $db->where('a.status', $data['status']);
  17. if ($data['company_title'] != '') $db->whereLike('b.title', '%' . $data['company_title'] . '%');
  18. if ($data['card_title'] != '') $db->whereLike('c.title', '%' . $data['card_title'] . '%');
  19. $count = $db->count('a.id');
  20. $list = $db->field('a.id,b.title company_title,c.title card_title,a.num,a.status,a.addtime,a.is_top')
  21. ->page($data['page'], $data['size'])
  22. ->order(['a.is_top' => 'desc', 'a.id' => 'desc'])
  23. ->select()
  24. ->toArray();
  25. return json_show(CommonModel::$success, '获取视频分组列表成功', ['count' => $count, 'list' => $list]);
  26. }
  27. //添加视频分组
  28. public static function add(array $data = []): Json
  29. {
  30. $rs = VideoGroupModel::field('id')
  31. ->where([
  32. 'is_del' => CommonModel::$del_normal,
  33. 'company_id' => $data['company_id'],
  34. 'card_id' => $data['card_id']
  35. ])
  36. ->findOrEmpty()
  37. ->isEmpty();
  38. if (!$rs) return json_show(CommonModel::$error_param, '该分组已存在');
  39. $res = VideoGroupModel::create(array_merge($data, [
  40. 'num' => 0,
  41. 'is_top' => CommonModel::$top_no,
  42. 'status' => CommonModel::$status_normal,
  43. 'is_del' => CommonModel::$del_normal,
  44. 'createrid' => self::$uid,
  45. 'creater' => self::$uname,
  46. 'addtime' => date('Y-m-d H:i:s'),
  47. 'updaterid' => self::$uid,
  48. 'updater' => self::$uname,
  49. 'updatetime' => date('Y-m-d H:i:s'),
  50. ]))->save();
  51. return $res ? json_show(CommonModel::$success, '添加视频分组成功') : json_show(CommonModel::$success, '添加视频分组失败');
  52. }
  53. //获取视频分组详情
  54. public static function read(int $id = 0): Json
  55. {
  56. $res = VideoGroupModel::field(true)
  57. ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
  58. ->findOrEmpty()
  59. ->toArray();
  60. if (empty($res)) throw new ValidateException('该视频分组为空');
  61. return json_show(CommonModel::$success, '获取视频分组详情成功', $res);
  62. }
  63. //编辑视频分组
  64. public static function edit(array $data = []): Json
  65. {
  66. $rs = VideoGroupModel::field('id,company_id,card_id')
  67. ->where([
  68. 'id' => $data['id'],
  69. 'is_del' => CommonModel::$del_normal,
  70. ])
  71. ->findOrEmpty();
  72. if ($rs->isEmpty()) return json_show(CommonModel::$error_param, '该视频分组不存在');
  73. if (($rs->company_id != $data['company_id']) || ($rs->card_id != $data['card_id'])) {
  74. $temp = VideoGroupModel::field('id')
  75. ->where([
  76. 'is_del' => CommonModel::$del_normal,
  77. 'company_id' => $data['company_id'],
  78. 'card_id' => $data['card_id']
  79. ])
  80. ->findOrEmpty()
  81. ->isEmpty();
  82. if (!$temp) return json_show(CommonModel::$error_param, '该视频分组已存在');
  83. }
  84. $res = VideoGroupModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
  85. ->save(array_merge($data, ['updatetime' => date('Y-m-d H:i:s'), 'updaterid' => self::$uid, 'updater' => self::$uid]));
  86. return $res ? json_show(CommonModel::$success, '编辑视频分组成功') : json_show(CommonModel::$error_param, '编辑视频分组失败');
  87. }
  88. //视频分组启禁用
  89. public static function status(array $data = []): Json
  90. {
  91. $res = VideoGroupModel::where('id', $data['id'])
  92. ->where('status', '<>', $data['status'])
  93. ->save([
  94. 'status' => $data['status'],
  95. 'updatetime' => date('Y-m-d H:i:s'),
  96. 'updaterid' => self::$uid,
  97. 'updater' => self::$uid
  98. ]);
  99. return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$success, '操作失败,该视频分组不存在或重复操作');
  100. }
  101. //删除视频分组
  102. public static function delete(array $ids = []): Json
  103. {
  104. $res = VideoGroupModel::whereIn('id', $ids)
  105. ->where('is_del', CommonModel::$del_normal)
  106. ->save([
  107. 'is_del' => CommonModel::$del_deleted,
  108. 'updatetime' => date('Y-m-d H:i:s'),
  109. 'updaterid' => self::$uid,
  110. 'updater' => self::$uid
  111. ]);
  112. return $res ? json_show(CommonModel::$success, '删除成功') : json_show(CommonModel::$error_param, '删除失败,该视频分组不存在');
  113. }
  114. //视频分组置顶
  115. public static function top(array $data = []): Json
  116. {
  117. $res = VideoGroupModel::where('id', $data['id'])
  118. ->where('is_top', '<>', $data['is_top'])
  119. ->save([
  120. 'is_top' => $data['is_top'],
  121. 'updatetime' => date('Y-m-d H:i:s'),
  122. 'updaterid' => self::$uid,
  123. 'updater' => self::$uid
  124. ]);
  125. return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$success, '操作失败,该视频分组不存在或重复操作');
  126. }
  127. }