Vod.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. namespace app\api\controller;
  3. use think\Controller;
  4. use think\Cache;
  5. use think\Db;
  6. use think\Request;
  7. use think\Validate;
  8. class Vod extends Base
  9. {
  10. use PublicApi;
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. $this->check_config();
  15. }
  16. public function index()
  17. {
  18. }
  19. /**
  20. * 获取视频列表
  21. *
  22. * @param Request $request
  23. * @return \think\response\Json
  24. */
  25. public function get_list(Request $request)
  26. {
  27. // 参数校验
  28. $param = $request->param();
  29. $validate = validate($request->controller());
  30. if (!$validate->scene($request->action())->check($param)) {
  31. return json([
  32. 'code' => 1001,
  33. 'msg' => '参数错误: ' . $validate->getError(),
  34. ]);
  35. }
  36. $offset = isset($param['offset']) ? (int)$param['offset'] : 0;
  37. $limit = isset($param['limit']) ? (int)$param['limit'] : 20;
  38. // 查询条件组装
  39. $where = [];
  40. if (isset($param['type_id'])) {
  41. $where['type_id'] = (int)$param['type_id'];
  42. }
  43. if (isset($param['id'])) {
  44. $where['vod_id'] = (int)$param['id'];
  45. }
  46. // if (isset($param['type_id_1'])) {
  47. // $where['type_id_1'] = (int)$param['type_id_1'];
  48. // }
  49. if (!empty($param['vod_letter'])) {
  50. $where['vod_letter'] = $param['vod_letter'];
  51. }
  52. if (isset($param['vod_tag']) && strlen($param['vod_tag']) > 0) {
  53. $where['vod_tag'] = ['like', '%' . $this->format_sql_string($param['vod_tag']) . '%'];
  54. }
  55. if (isset($param['vod_name']) && strlen($param['vod_name']) > 0) {
  56. $where['vod_name'] = ['like', '%' . $this->format_sql_string($param['vod_name']) . '%'];
  57. }
  58. if (isset($param['vod_blurb']) && strlen($param['vod_blurb']) > 0) {
  59. $where['vod_blurb'] = ['like', '%' . $this->format_sql_string($param['vod_blurb']) . '%'];
  60. }
  61. if (isset($param['vod_class']) && strlen($param['vod_class']) > 0) {
  62. $where['vod_class'] = ['like', '%' . $this->format_sql_string($param['vod_class']) . '%'];
  63. }
  64. if (isset($param['vod_area']) && strlen($param['vod_area']) > 0) {
  65. $where['vod_area'] = $this->format_sql_string($param['vod_area']);
  66. }
  67. if (isset($param['vod_year']) && strlen($param['vod_year']) > 0) {
  68. $where['vod_year'] = $this->format_sql_string($param['vod_year']);
  69. }
  70. // 数据获取
  71. $total = model('Vod')->getCountByCond($where);
  72. $list = [];
  73. if ($total > 0) {
  74. // 排序
  75. $order = "vod_time DESC";
  76. if (strlen($param['orderby']) > 0) {
  77. $order = 'vod_' . $param['orderby'] . " DESC";
  78. }
  79. $field = 'vod_id,vod_name,vod_actor,vod_hits,vod_hits_day,vod_hits_week,vod_hits_month,vod_time,vod_remarks,vod_score,vod_area,vod_year';
  80. // $list = model('Vod')->getListByCond($offset, $limit, $where, $order, $field, []);
  81. $list = model('Vod')->getListByCond($offset, $limit, $where, $order, $field);
  82. }
  83. // 返回
  84. return json([
  85. 'code' => 1,
  86. 'msg' => '获取成功',
  87. 'info' => [
  88. 'offset' => $offset,
  89. 'limit' => $limit,
  90. 'total' => $total,
  91. 'rows' => $list,
  92. ],
  93. ]);
  94. }
  95. /**
  96. * 视频详细信息
  97. *
  98. * @param Request $request
  99. * @return \think\response\Json
  100. * @throws \think\db\exception\DataNotFoundException
  101. * @throws \think\db\exception\ModelNotFoundException
  102. * @throws \think\exception\DbException
  103. */
  104. public function get_detail(Request $request)
  105. {
  106. $param = $request->param();
  107. $validate = validate($request->controller());
  108. if (!$validate->scene($request->action())->check($param)) {
  109. return json([
  110. 'code' => 1001,
  111. 'msg' => '参数错误: ' . $validate->getError(),
  112. ]);
  113. }
  114. $res = Db::table('mac_vod')->where(['vod_id' => $param['vod_id']])->select();
  115. // 返回
  116. return json([
  117. 'code' => 1,
  118. 'msg' => '获取成功',
  119. 'info' => $res
  120. ]);
  121. }
  122. /**
  123. * 获取视频的年份
  124. *
  125. * @return \think\response\Json
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. */
  130. public function get_year(Request $request)
  131. {
  132. $param = $request->param();
  133. $validate = validate($request->controller());
  134. if (!$validate->scene($request->action())->check($param)) {
  135. return json([
  136. 'code' => 1001,
  137. 'msg' => '参数错误: ' . $validate->getError(),
  138. ]);
  139. }
  140. $result = Db::table('mac_vod')->distinct(true)->field('vod_year')->where(['type_id_1' => $param['type_id_1']])->select();
  141. $return = [];
  142. foreach ($result as $index => $item) {
  143. if (!empty($item['vod_year'])){
  144. array_push($return,$item['vod_year']);
  145. }
  146. }
  147. // 返回
  148. return json([
  149. 'code' => 1,
  150. 'msg' => '获取成功',
  151. 'info' => [
  152. 'total' => count($return),
  153. 'rows' => $return,
  154. ],
  155. ]);
  156. }
  157. /**
  158. * 获取该视频类型名称
  159. *
  160. * @return \think\response\Json
  161. * @throws \think\db\exception\DataNotFoundException
  162. * @throws \think\db\exception\ModelNotFoundException
  163. * @throws \think\exception\DbException
  164. */
  165. public function get_class(Request $request)
  166. {
  167. $param = $request->param();
  168. $validate = validate($request->controller());
  169. if (!$validate->scene($request->action())->check($param)) {
  170. return json([
  171. 'code' => 1001,
  172. 'msg' => '参数错误: ' . $validate->getError(),
  173. ]);
  174. }
  175. $result = Db::table('mac_vod')->distinct(true)->field('vod_class')->where(['type_id_1' => $param['type_id_1']])->select();
  176. $return = [];
  177. foreach ($result as $index => $item) {
  178. if (!empty($item['vod_class'])){
  179. array_push($return,$item['vod_class']);
  180. }
  181. }
  182. // 返回
  183. return json([
  184. 'code' => 1,
  185. 'msg' => '获取成功',
  186. 'info' => [
  187. 'total' => count($return),
  188. 'rows' => $return,
  189. ],
  190. ]);
  191. }
  192. /**
  193. * 获取该视频类型的地区
  194. *
  195. * @return \think\response\Json
  196. * @throws \think\db\exception\DataNotFoundException
  197. * @throws \think\db\exception\ModelNotFoundException
  198. * @throws \think\exception\DbException
  199. */
  200. public function get_area(Request $request)
  201. {
  202. $param = $request->param();
  203. $validate = validate($request->controller());
  204. if (!$validate->scene($request->action())->check($param)) {
  205. return json([
  206. 'code' => 1001,
  207. 'msg' => '参数错误: ' . $validate->getError(),
  208. ]);
  209. }
  210. $result = Db::table('mac_vod')->distinct(true)->field('vod_area')->where(['type_id_1' => $param['type_id_1']])->select();
  211. $return = [];
  212. foreach ($result as $index => $item) {
  213. if (!empty($item['vod_area'])){
  214. array_push($return,$item['vod_area']);
  215. }
  216. }
  217. // 返回
  218. return json([
  219. 'code' => 1,
  220. 'msg' => '获取成功',
  221. 'info' => [
  222. 'total' => count($return),
  223. 'rows' => $return,
  224. ],
  225. ]);
  226. }
  227. }