Actor.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. namespace app\api\controller;
  3. use think\Db;
  4. use think\Request;
  5. class Actor extends Base
  6. {
  7. use PublicApi;
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. $this->check_config();
  12. }
  13. public function index()
  14. {
  15. }
  16. /**
  17. * 获取列表
  18. *
  19. * @param Request $request
  20. * @return \think\response\Json
  21. */
  22. public function get_list(Request $request)
  23. {
  24. // 参数校验
  25. $param = $request->param();
  26. $validate = validate($request->controller());
  27. if (!$validate->scene($request->action())->check($param)) {
  28. return json([
  29. 'code' => 1001,
  30. 'msg' => '参数错误: ' . $validate->getError(),
  31. ]);
  32. }
  33. $offset = isset($param['offset']) ? (int)$param['offset'] : 0;
  34. $limit = isset($param['limit']) ? (int)$param['limit'] : 20;
  35. // 查询条件组装(0/1 均展示:采集/默认入库常见 actor_status=0,仅 eq 1 会导致「库里有数据但接口为空」)
  36. $where = [];
  37. $where['actor_status'] = ['in', [0, 1]];
  38. if (isset($param['type_id']) && (int)$param['type_id'] > 0) {
  39. $where['type_id'] = (int)$param['type_id'];
  40. }
  41. if (isset($param['sex'])) {
  42. $where['actor_sex'] = $param['sex'];
  43. }
  44. if (isset($param['area']) && strlen($param['area']) > 0) {
  45. $where['actor_area'] = ['like', '%' . $this->format_sql_string($param['area']) . '%'];
  46. }
  47. if (isset($param['letter']) && strlen($param['letter']) > 0) {
  48. $where['actor_letter'] = ['like', '%' . $this->format_sql_string($param['letter']) . '%'];
  49. }
  50. if (isset($param['level']) && strlen($param['level']) > 0) {
  51. $where['actor_level'] = ['like', '%' . $this->format_sql_string($param['level']) . '%'];
  52. }
  53. if (isset($param['name']) && strlen($param['name']) > 0) {
  54. $where['actor_name'] = ['like', '%' . $this->format_sql_string($param['name']) . '%'];
  55. }
  56. if (isset($param['blood']) && strlen($param['blood']) > 0) {
  57. $where['actor_blood'] = ['like', '%' . $this->format_sql_string($param['blood']) . '%'];
  58. }
  59. if (isset($param['starsign']) && strlen($param['starsign']) > 0) {
  60. $where['actor_starsign'] = ['like', '%' . $this->format_sql_string($param['starsign']) . '%'];
  61. }
  62. if (isset($param['time_end']) && isset($param['time_start'])) {
  63. $where['actor_time'] = ['between', [(int)$param['time_start'], (int)$param['time_end']]];
  64. } elseif (isset($param['time_end'])) {
  65. $where['actor_time'] = ['<', (int)$param['time_end']];
  66. } elseif (isset($param['time_start'])) {
  67. $where['actor_time'] = ['>', (int)$param['time_start']];
  68. }
  69. // 数据获取
  70. $total = model('Actor')->getCountByCond($where);
  71. $list = [];
  72. if ($total > 0) {
  73. // 排序
  74. $order = "actor_time DESC";
  75. if (!empty($param['orderby'])) {
  76. $order = 'actor_' . $param['orderby'] . " DESC";
  77. }
  78. $field = 'actor_id,actor_name,actor_en,actor_alias,actor_sex,actor_pic,actor_remarks,actor_hits,actor_hits_month,actor_hits_week,actor_hits_day,actor_time,type_id';
  79. $list = model('Actor')->getListByCond($offset, $limit, $where, $order, $field, false);
  80. foreach ($list as &$row) {
  81. $row['actor_pic'] = mac_url_img($row['actor_pic'] ?? '');
  82. $row['actor_link'] = mac_url_actor_detail($row);
  83. }
  84. unset($row);
  85. }
  86. // 返回
  87. return json([
  88. 'code' => 1,
  89. 'msg' => '获取成功',
  90. 'info' => [
  91. 'offset' => $offset,
  92. 'limit' => $limit,
  93. 'total' => $total,
  94. 'rows' => $list,
  95. ],
  96. ]);
  97. }
  98. /**
  99. * 视频演员详情
  100. *
  101. * @param Request $request
  102. * @return \think\response\Json
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\ModelNotFoundException
  105. * @throws \think\exception\DbException
  106. */
  107. public function get_detail(Request $request)
  108. {
  109. $param = $request->param();
  110. $validate = validate($request->controller());
  111. if (!$validate->scene($request->action())->check($param)) {
  112. return json([
  113. 'code' => 1001,
  114. 'msg' => '参数错误: ' . $validate->getError(),
  115. ]);
  116. }
  117. $res = Db::table('mac_actor')
  118. ->where('actor_id', (int) $param['actor_id'])
  119. ->where('actor_status', 'in', [0, 1])
  120. ->find();
  121. if (empty($res)) {
  122. return json(['code' => 1001, 'msg' => '数据不存在']);
  123. }
  124. // 处理图片 URL
  125. $res['actor_pic'] = mac_url_img($res['actor_pic']);
  126. $res['actor_pic_thumb'] = mac_url_img($res['actor_pic_thumb'] ?? '');
  127. $res['actor_link'] = mac_url_actor_detail($res);
  128. // 返回
  129. return json([
  130. 'code' => 1,
  131. 'msg' => '获取成功',
  132. 'info' => $res
  133. ]);
  134. }
  135. /**
  136. * 获取推荐明星
  137. * 对应首页推荐明星区块
  138. *
  139. * @param Request $request
  140. * @return \think\response\Json
  141. *
  142. * 参数说明:
  143. * ids - 可选,指定明星ID,多个用逗号分隔
  144. * num - 可选,数量,默认8
  145. * by - 可选,排序字段,默认 time,可选: hits,hits_day,hits_week,hits_month,time
  146. */
  147. public function get_recommend(Request $request)
  148. {
  149. $param = $request->param();
  150. $ids = isset($param['ids']) ? trim($param['ids']) : '';
  151. $num = isset($param['num']) ? (int)$param['num'] : 8;
  152. $start = isset($param['start']) ? max(0, (int)$param['start']) : 0;
  153. $by = isset($param['by']) ? trim($param['by']) : 'time';
  154. $allowBy = ['hits', 'hits_day', 'hits_week', 'hits_month', 'time'];
  155. if (!in_array($by, $allowBy)) {
  156. $by = 'time';
  157. }
  158. $where = [];
  159. $where['actor_status'] = ['eq', 1];
  160. if (!empty($ids)) {
  161. $idArr = array_map('intval', explode(',', $ids));
  162. $where['actor_id'] = ['in', $idArr];
  163. }
  164. $list = Db::table('mac_actor')
  165. ->field('actor_id,actor_name,actor_pic,actor_sex,actor_area,actor_hits,actor_hits_month,actor_time')
  166. ->where($where)
  167. ->order('actor_' . $by . ' desc')
  168. ->limit($start, $num)
  169. ->select();
  170. foreach ($list as &$v) {
  171. $v['actor_pic'] = mac_url_img($v['actor_pic']);
  172. $v['actor_link'] = mac_url_actor_detail($v);
  173. }
  174. unset($v);
  175. return json([
  176. 'code' => 1,
  177. 'msg' => '获取成功',
  178. 'info' => [
  179. 'total' => count($list),
  180. 'rows' => $list,
  181. ],
  182. ]);
  183. }
  184. }