dao = $dao; } /** * @param $film_sign * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getFilmSchedDate($film_sign) { $field = 'show_date'; $where = ['film_sign' => $film_sign]; $show_date = $this->dao->search(null, $where)->field([$field])->order('show_date asc')->group('show_date')->select()->toArray(); foreach ($show_date as $key => $value) { $show_date[$key]['date'] = date('m-d', $value['show_date']); } return $show_date; } /** * @param $page * @param $limit * @param $longitude * @param $latitude * @param $show_date * @param $with * @param $order * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getFilmSched($page, $limit, $film_sign, $longitude, $latitude, $show_date, $with = [], $order = 1) { $field = 'sched_sign,cinema_sign,cinema_name,address,show_date,price,longitude,latitude'; $where = ['film_sign' => $film_sign, 'show_date' => $show_date]; $cinema_sched = $this->dao->search(null, $where)->when($with, function ($query) use ($with) { $query->with($with); })->when($latitude && $longitude, function ($query) use ($field, $longitude, $latitude) { $query->field([$field, $this->distance($latitude, $longitude)]); })->when($page && $limit, function ($query) use ($page, $limit) { $query->page($page, $limit); })->when(!is_null($order), function ($query) use ($order) { if ($order == 1) {//距离最近 $query->order('distance asc'); } else {//播放日期 $query->order('show_date desc'); } })->field([$field])->select()->toArray(); foreach ($cinema_sched as $key => $value) { $cinema_sched[$key]['distance'] = isset($value['distance']) ? round($value['distance'] / 1000, 2) : 0.00; $cinema_sched[$key]['show_date'] = date('m-d', $value['show_date']); $pcYanglaojinGongxian = MovieRepository::getPvYanglaojinScore($value['price']); $cinema_sched[$key]['price'] = $pcYanglaojinGongxian['cost_price']; } $count = $this->dao->search(null, $where)->when($with, function ($query) use ($with) { $query->with($with); })->when($latitude && $longitude, function ($query) use ($field, $longitude, $latitude) { $query->field([$field, $this->distance($latitude, $longitude)]); })->count(); return compact('cinema_sched', 'count'); } /** * @param $page * @param $limit * @param $cinema_sign * @param $film_sign * @param $show_date * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getCinemaFilmSched($page, $limit, $cinema_sign, $film_sign, $show_date) { $field = 'relation_id,sched_sign,film_sign,film_name,show_date,show_time,cinema_sign,cinema_name,hall_sign,hall_name,price'; $where = ['cinema_sign' => $cinema_sign, 'film_sign' => $film_sign, 'show_date' => strtotime($show_date)]; $cinema_sched = $this->dao->search(null, $where) ->when($page && $limit, function ($query) use ($page, $limit) { $query->page($page, $limit); })->order('show_time asc')->field([$field])->select()->toArray(); foreach ($cinema_sched as $key => $value) { $pcYanglaojinGongxian = MovieRepository::getPvYanglaojinScore($value['price']); $cinema_sched[$key]['price'] = $pcYanglaojinGongxian['cost_price']; $cinema_sched[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin']; $cinema_sched[$key]['pv'] = $pcYanglaojinGongxian['pv']; $cinema_sched[$key]['score'] = $pcYanglaojinGongxian['score']; $cinema_sched[$key]['gongxian'] = $pcYanglaojinGongxian['gongxian']; } $count = $this->dao->search(null, $where)->count(); return compact('cinema_sched', 'count'); } /** * 经纬度排序计算 * @param string $latitude * @param string $longitude * @return string */ private function distance(string $latitude, string $longitude) { return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2) + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance"; } /** * 获取影片场次详情 * * @param $relation_id * @param $sched_sign * @return CinemaSched|array|\think\Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getCinemaSchedInfo($relation_id, $sched_sign) { return $this->dao->search(null, ['relation_id' => $relation_id, 'sched_sign' => $sched_sign])->find(); } }