Actor.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. // 查询条件组装
  36. $where = [];
  37. if (isset($param['type_id'])) {
  38. $where['type_id'] = (int)$param['type_id'];
  39. }
  40. if (isset($param['sex'])) {
  41. $where['actor_sex'] = $param['sex'];
  42. }
  43. if (isset($param['area']) && strlen($param['area']) > 0) {
  44. $where['actor_area'] = ['like', '%' . $this->format_sql_string($param['area']) . '%'];
  45. }
  46. if (isset($param['letter']) && strlen($param['letter']) > 0) {
  47. $where['actor_letter'] = ['like', '%' . $this->format_sql_string($param['letter']) . '%'];
  48. }
  49. if (isset($param['level']) && strlen($param['level']) > 0) {
  50. $where['actor_level'] = ['like', '%' . $this->format_sql_string($param['level']) . '%'];
  51. }
  52. if (isset($param['name']) && strlen($param['name']) > 0) {
  53. $where['actor_name'] = ['like', '%' . $this->format_sql_string($param['name']) . '%'];
  54. }
  55. if (isset($param['blood']) && strlen($param['blood']) > 0) {
  56. $where['actor_blood'] = ['like', '%' . $this->format_sql_string($param['blood']) . '%'];
  57. }
  58. if (isset($param['starsign']) && strlen($param['starsign']) > 0) {
  59. $where['actor_starsign'] = ['like', '%' . $this->format_sql_string($param['starsign']) . '%'];
  60. }
  61. if (isset($param['time_end']) && isset($param['time_start'])) {
  62. $where['actor_time'] = ['between', [(int)$param['time_start'], (int)$param['time_end']]];
  63. } elseif (isset($param['time_end'])) {
  64. $where['actor_time'] = ['<', (int)$param['time_end']];
  65. } elseif (isset($param['time_start'])) {
  66. $where['actor_time'] = ['>', (int)$param['time_start']];
  67. }
  68. // 数据获取
  69. $total = model('Actor')->getCountByCond($where);
  70. $list = [];
  71. if ($total > 0) {
  72. // 排序
  73. $order = "actor_time DESC";
  74. if (strlen($param['orderby']) > 0) {
  75. $order = 'actor_' . $param['orderby'] . " DESC";
  76. }
  77. $field = 'actor_id,actor_name,actor_en,actor_alias,actor_sex,actor_hits_month,actor_hits_week,actor_hits_day,actor_time';
  78. $list = model('Actor')->getListByCond($offset, $limit, $where, $order, $field, []);
  79. }
  80. // 返回
  81. return json([
  82. 'code' => 1,
  83. 'msg' => '获取成功',
  84. 'info' => [
  85. 'offset' => $offset,
  86. 'limit' => $limit,
  87. 'total' => $total,
  88. 'rows' => $list,
  89. ],
  90. ]);
  91. }
  92. /**
  93. * 视频演员详情
  94. *
  95. * @param Request $request
  96. * @return \think\response\Json
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\ModelNotFoundException
  99. * @throws \think\exception\DbException
  100. */
  101. public function get_detail(Request $request)
  102. {
  103. $param = $request->param();
  104. $validate = validate($request->controller());
  105. if (!$validate->scene($request->action())->check($param)) {
  106. return json([
  107. 'code' => 1001,
  108. 'msg' => '参数错误: ' . $validate->getError(),
  109. ]);
  110. }
  111. $res = Db::table('mac_actor')->where(['actor_id' => $param['actor_id']])->select();
  112. // 返回
  113. return json([
  114. 'code' => 1,
  115. 'msg' => '获取成功',
  116. 'info' => $res
  117. ]);
  118. }
  119. }