|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+/**
|
|
|
3
|
+ * @package merchant
|
|
|
4
|
+ * @Author: Qinii
|
|
|
5
|
+ * @Date: 2020/5/8
|
|
|
6
|
+ */
|
|
|
7
|
+
|
|
|
8
|
+namespace app\common\repositories\movie;
|
|
|
9
|
+
|
|
|
10
|
+use app\common\model\movie\cinema\CinemaSched;
|
|
|
11
|
+use app\common\repositories\BaseRepository;
|
|
|
12
|
+use think\facade\Db;
|
|
|
13
|
+
|
|
|
14
|
+/**
|
|
|
15
|
+ * Class CinemaSchedRepository
|
|
|
16
|
+ * @package app\common\repositories\movie
|
|
|
17
|
+ * @author xaboy
|
|
|
18
|
+ * @mixin CinemaSched
|
|
|
19
|
+ */
|
|
|
20
|
+class CinemaSchedRepository extends BaseRepository
|
|
|
21
|
+{
|
|
|
22
|
+ protected $dao;
|
|
|
23
|
+
|
|
|
24
|
+ /**
|
|
|
25
|
+ * ProductRepository constructor.
|
|
|
26
|
+ * @param CinemaSched $dao
|
|
|
27
|
+ */
|
|
|
28
|
+ public function __construct(CinemaSched $dao)
|
|
|
29
|
+ {
|
|
|
30
|
+ $this->dao = $dao;
|
|
|
31
|
+ }
|
|
|
32
|
+
|
|
|
33
|
+ /**
|
|
|
34
|
+ * @param $film_sign
|
|
|
35
|
+ * @return array
|
|
|
36
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
37
|
+ * @throws \think\db\exception\DbException
|
|
|
38
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
39
|
+ */
|
|
|
40
|
+ public function getFilmSchedDate($film_sign)
|
|
|
41
|
+ {
|
|
|
42
|
+ $field = 'show_date';
|
|
|
43
|
+ $where = ['film_sign' => $film_sign];
|
|
|
44
|
+
|
|
|
45
|
+ $show_date = $this->dao->search(null, $where)->field([$field])->order('show_date asc')->group('show_date')->select()->toArray();
|
|
|
46
|
+ foreach ($show_date as $key => $value) {
|
|
|
47
|
+ $show_date[$key]['date'] = date('m-d', $value['show_date']);
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+ return compact('show_date');
|
|
|
51
|
+ }
|
|
|
52
|
+
|
|
|
53
|
+ /**
|
|
|
54
|
+ * @param $page
|
|
|
55
|
+ * @param $limit
|
|
|
56
|
+ * @param $longitude
|
|
|
57
|
+ * @param $latitude
|
|
|
58
|
+ * @param $show_date
|
|
|
59
|
+ * @param $with
|
|
|
60
|
+ * @param $order
|
|
|
61
|
+ * @return array
|
|
|
62
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
63
|
+ * @throws \think\db\exception\DbException
|
|
|
64
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
65
|
+ */
|
|
|
66
|
+ public function getFilmSched($page, $limit, $film_sign, $longitude, $latitude, $show_date, $with = [], $order = 1)
|
|
|
67
|
+ {
|
|
|
68
|
+ $field = 'cinema_sign,cinema_name,address,cost_price,longitude,latitude';
|
|
|
69
|
+ $where = ['film_sign' => $film_sign, 'show_date' => $show_date];
|
|
|
70
|
+
|
|
|
71
|
+ $cinema_sched = $this->dao->search(null, $where)->when($with, function ($query) use ($with) {
|
|
|
72
|
+ $query->with($with);
|
|
|
73
|
+ })->when($latitude && $longitude, function ($query) use ($field, $longitude, $latitude) {
|
|
|
74
|
+ $query->field([$field, $this->distance($latitude, $longitude)]);
|
|
|
75
|
+ })->when($page && $limit, function ($query) use ($page, $limit) {
|
|
|
76
|
+ $query->page($page, $limit);
|
|
|
77
|
+ })->when(!is_null($order), function ($query) use ($order) {
|
|
|
78
|
+ if ($order == 1) {//距离最近
|
|
|
79
|
+ $query->order('distance asc');
|
|
|
80
|
+ } else {//播放日期
|
|
|
81
|
+ $query->order('show_date desc');
|
|
|
82
|
+ }
|
|
|
83
|
+ })->field([$field])->select()->toArray();
|
|
|
84
|
+ foreach ($cinema_sched as $key => $value) {
|
|
|
85
|
+ $cinema_sched[$key]['distance'] = isset($value['distance']) ? round($value['distance'] / 1000, 2) : 0.00;
|
|
|
86
|
+ }
|
|
|
87
|
+
|
|
|
88
|
+ $count = $this->dao->search(null, $where)->when($with, function ($query) use ($with) {
|
|
|
89
|
+ $query->with($with);
|
|
|
90
|
+ })->when($latitude && $longitude, function ($query) use ($field, $longitude, $latitude) {
|
|
|
91
|
+ $query->field([$field, $this->distance($latitude, $longitude)]);
|
|
|
92
|
+ })->count();
|
|
|
93
|
+
|
|
|
94
|
+ return compact('cinema_sched', 'count');
|
|
|
95
|
+ }
|
|
|
96
|
+
|
|
|
97
|
+ /**
|
|
|
98
|
+ * @param $page
|
|
|
99
|
+ * @param $limit
|
|
|
100
|
+ * @param $cinema_sign
|
|
|
101
|
+ * @param $film_sign
|
|
|
102
|
+ * @param $show_date
|
|
|
103
|
+ * @return array
|
|
|
104
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
105
|
+ * @throws \think\db\exception\DbException
|
|
|
106
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
107
|
+ */
|
|
|
108
|
+ public function getCinemaFilmSched($page, $limit, $cinema_sign, $film_sign, $show_date)
|
|
|
109
|
+ {
|
|
|
110
|
+ $field = 'relation_id,sched_sign,film_sign,film_name,show_date,show_time,cinema_sign,cinema_name,hall_sign,hall_name,cost_price';
|
|
|
111
|
+ $where = ['cinema_sign' => $cinema_sign, 'film_sign' => $film_sign, 'show_date' => $show_date];
|
|
|
112
|
+
|
|
|
113
|
+ $cinema_sched = $this->dao->search(null, $where)
|
|
|
114
|
+ ->when($page && $limit, function ($query) use ($page, $limit) {
|
|
|
115
|
+ $query->page($page, $limit);
|
|
|
116
|
+ })->order('show_time asc')->field([$field])->select()->toArray();
|
|
|
117
|
+ foreach ($cinema_sched as $key => $value) {
|
|
|
118
|
+ $pcYanglaojinGongxian = MovieRepository::getPvYanglaojinScore($value['cost_price']);
|
|
|
119
|
+
|
|
|
120
|
+ $cinema_sched[$key]['cost_price'] = $pcYanglaojinGongxian['cost_price'];
|
|
|
121
|
+ $cinema_sched[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin'];
|
|
|
122
|
+ $cinema_sched[$key]['pv'] = $pcYanglaojinGongxian['pv'];
|
|
|
123
|
+ $cinema_sched[$key]['score'] = $pcYanglaojinGongxian['score'];
|
|
|
124
|
+ $cinema_sched[$key]['gongxian'] = $pcYanglaojinGongxian['gongxian'];
|
|
|
125
|
+ $cinema_sched[$key]['distance'] = isset($value['distance']) ? round($value['distance'] / 1000, 2) : 0.00;
|
|
|
126
|
+ }
|
|
|
127
|
+
|
|
|
128
|
+ $count = $this->dao->search(null, $where)->count();
|
|
|
129
|
+
|
|
|
130
|
+ return compact('cinema_sched', 'count');
|
|
|
131
|
+ }
|
|
|
132
|
+
|
|
|
133
|
+ /**
|
|
|
134
|
+ * 经纬度排序计算
|
|
|
135
|
+ * @param string $latitude
|
|
|
136
|
+ * @param string $longitude
|
|
|
137
|
+ * @return string
|
|
|
138
|
+ */
|
|
|
139
|
+ private function distance(string $latitude, string $longitude)
|
|
|
140
|
+ {
|
|
|
141
|
+ return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2)
|
|
|
142
|
+ + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance";
|
|
|
143
|
+ }
|
|
|
144
|
+}
|