FilmRepository.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/8
  6. */
  7. namespace app\common\repositories\movie;
  8. use app\common\dao\movie\order\MovieOrderDao;
  9. use app\common\model\movie\film\Film;
  10. use app\common\repositories\BaseRepository;
  11. /**
  12. * Class FilmRepository
  13. * @package app\common\repositories\movie
  14. * @author xaboy
  15. * @mixin MovieOrderDao
  16. */
  17. class FilmRepository extends BaseRepository
  18. {
  19. protected $dao;
  20. /**
  21. * ProductRepository constructor.
  22. * @param Film $dao
  23. */
  24. public function __construct(Film $dao)
  25. {
  26. $this->dao = $dao;
  27. }
  28. /**
  29. * @param $page
  30. * @param $limit
  31. * @param $type
  32. * @param $with
  33. * @return array
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function getFilm($page, $limit, $type = 0, $with = [])
  39. {
  40. $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
  41. $time = strtotime(date('Y-m-d'));
  42. if (empty($type)) {
  43. $where = [['publish_date', '<=', $time]];
  44. } else {
  45. $where = [['publish_date', '>', $time]];
  46. }
  47. $result = $this->dao->where($where)->when($with, function ($query) use ($with) {
  48. $query->with($with);
  49. })->when($page && $limit, function ($query) use ($page, $limit) {
  50. $query->page($page, $limit);
  51. })->field([$field])->order('publish_date acs')->select()->toArray();
  52. foreach ($result as $key => $value) {
  53. $result[$key]['publish_date'] = date('Y-m-d', $value['publish_date']);
  54. $result[$key]['director'] = json_decode($value['director'], true);
  55. $result[$key]['actors'] = json_decode($value['actors'], true);
  56. $result[$key]['actors_name'] = !empty($result[$key]['actors']) ? implode(',', array_column($result[$key]['actors'], 'sc_name')) : '';
  57. $result[$key]['director_name'] = !empty($result[$key]['director']) ? implode(',', array_column($result[$key]['director'], 'sc_name')) : '';
  58. }
  59. return $result;
  60. }
  61. /**
  62. * 经纬度排序计算
  63. * @param string $latitude
  64. * @param string $longitude
  65. * @return string
  66. */
  67. private function distance(string $latitude, string $longitude)
  68. {
  69. return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2)
  70. + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance";
  71. }
  72. }