| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- /**
- * @package merchant
- * @Author: Qinii
- * @Date: 2020/5/8
- */
- namespace app\common\repositories\movie;
- use app\common\dao\movie\order\MovieOrderDao;
- use app\common\model\movie\film\Film;
- use app\common\repositories\BaseRepository;
- /**
- * Class FilmRepository
- * @package app\common\repositories\movie
- * @author xaboy
- * @mixin MovieOrderDao
- */
- class FilmRepository extends BaseRepository
- {
- protected $dao;
- /**
- * ProductRepository constructor.
- * @param Film $dao
- */
- public function __construct(Film $dao)
- {
- $this->dao = $dao;
- }
- /**
- * @param $page
- * @param $limit
- * @param $type
- * @param $with
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getFilm($page, $limit, $type = 0, $with = [])
- {
- $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
- $time = strtotime(date('Y-m-d'));
- if (empty($type)) {
- $where = [['publish_date', '<=', $time]];
- } else {
- $where = [['publish_date', '>', $time]];
- }
- $result = $this->dao->where($where)->when($with, function ($query) use ($with) {
- $query->with($with);
- })->when($page && $limit, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })->field([$field])->order('publish_date acs')->select()->toArray();
- foreach ($result as $key => $value) {
- $result[$key]['publish_date'] = date('Y-m-d', $value['publish_date']);
- $result[$key]['director'] = json_decode($value['director'], true);
- $result[$key]['actors'] = json_decode($value['actors'], true);
- $result[$key]['actors_name'] = !empty($result[$key]['actors']) ? implode(',', array_column($result[$key]['actors'], 'sc_name')) : '';
- $result[$key]['director_name'] = !empty($result[$key]['director']) ? implode(',', array_column($result[$key]['director'], 'sc_name')) : '';
- }
- return $result;
- }
- /**
- * 经纬度排序计算
- * @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";
- }
- }
|