Topic.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 Topic 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['time_end']) && isset($param['time_start'])) {
  41. $where['topic_time'] = ['between', [(int)$param['time_start'], (int)$param['time_end']]];
  42. }elseif (isset($param['time_end'])) {
  43. $where['topic_time'] = ['<', (int)$param['time_end']];
  44. }elseif (isset($param['time_start'])) {
  45. $where['topic_time'] = ['>', (int)$param['time_start']];
  46. }
  47. // 数据获取
  48. $total = model('Topic')->getCountByCond($where);
  49. $list = [];
  50. if ($total > 0) {
  51. // 排序
  52. $order = "topic_time DESC";
  53. if (strlen($param['orderby']) > 0) {
  54. $order = 'topic_' . $param['orderby'] . " DESC";
  55. }
  56. $field = 'topic_id,topic_name,topic_en,topic_pic_slide,topic_content';
  57. $list = model('Topic')->getListByCond($offset, $limit, $where, $order, $field, []);
  58. }
  59. // 返回
  60. return json([
  61. 'code' => 1,
  62. 'msg' => '获取成功',
  63. 'info' => [
  64. 'offset' => $offset,
  65. 'limit' => $limit,
  66. 'total' => $total,
  67. 'rows' => $list,
  68. ],
  69. ]);
  70. }
  71. /**
  72. * 获取列表与推荐信息视频文章
  73. *
  74. * @param Request $request
  75. * @return \think\response\Json
  76. */
  77. public function get_detail(Request $request)
  78. {
  79. // 参数校验
  80. $param = $request->param();
  81. $validate = validate($request->controller());
  82. if (!$validate->scene($request->action())->check($param)) {
  83. return json([
  84. 'code' => 1001,
  85. 'msg' => '参数错误: ' . $validate->getError(),
  86. ]);
  87. }
  88. $result = Db::table('mac_topic')->where(['topic_id' => $param['topic_id']])->find();
  89. if ($result)
  90. {
  91. $topic_rel_vod = [];
  92. $topic_rel_art = [];
  93. if (!empty($result['topic_rel_vod']))
  94. {
  95. $topic_rel_vod_arr = explode(',',$result['topic_rel_vod']);
  96. foreach ($topic_rel_vod_arr as $index => $item) {
  97. $vod = Db::table('mac_vod')->where(['vod_id' => $item])->column('vod_id,vod_name,vod_en,vod_pic,vod_actor,vod_director,vod_blurb,vod_content,vod_play_url');
  98. if ($vod) {
  99. array_push($topic_rel_vod,$vod);
  100. }
  101. }
  102. $result['topic_rel_vod'] = $topic_rel_vod;
  103. }
  104. if (!empty($result['topic_rel_art']))
  105. {
  106. $topic_rel_art_arr = explode(',',$result['topic_rel_art']);
  107. foreach ($topic_rel_art_arr as $index => $item) {
  108. $vod = Db::table('mac_art')->where(['art_id' => $item])->column('art_id,type_id,art_name,art_sub,art_en,art_blurb,art_content');
  109. if ($vod) {
  110. array_push($topic_rel_art,$vod);
  111. }
  112. }
  113. $result['topic_rel_art'] = $topic_rel_art;
  114. }
  115. }
  116. // 返回
  117. return json([
  118. 'code' => 1,
  119. 'msg' => '获取成功',
  120. 'info' => $result,
  121. ]);
  122. }
  123. }