| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /**
- * @package merchant
- * @Author: Qinii
- * @Date: 2020/5/8
- */
- namespace app\common\repositories\movie;
- use app\common\model\movie\cinema\CinemaSched;
- use app\common\repositories\BaseRepository;
- use think\facade\Db;
- /**
- * Class CinemaSchedRepository
- * @package app\common\repositories\movie
- * @author xaboy
- * @mixin CinemaSched
- */
- class CinemaSchedRepository extends BaseRepository
- {
- protected $dao;
- /**
- * ProductRepository constructor.
- * @param CinemaSched $dao
- */
- public function __construct(CinemaSched $dao)
- {
- $this->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,cost_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['cost_price']);
- $cinema_sched[$key]['cost_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,cost_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['cost_price']);
- $cinema_sched[$key]['cost_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";
- }
- }
|