Procházet zdrojové kódy

获取影片场次日期返回时间戳

family před 1 rokem
rodič
revize
c83e404a72

+ 110 - 0
app/command/MovieOrderCommand.php

@@ -0,0 +1,110 @@
1
+<?php
2
+
3
+namespace app\command;
4
+
5
+use app\common\repositories\movie\MovieRepository;
6
+use crmeb\services\ApiResponseService;
7
+use think\console\Command;
8
+use think\console\Input;
9
+use think\console\Output;
10
+use think\facade\Db;
11
+
12
+class MovieOrderCommand extends Command
13
+{
14
+    protected function configure()
15
+    {
16
+        // 指令配置
17
+        $this->setName('movie-order')->setDescription('电影-订单');
18
+    }
19
+
20
+    protected function execute(Input $input, Output $output)
21
+    {
22
+        $this->doMovieOrder();
23
+    }
24
+
25
+    /**
26
+     * 电影-订单
27
+     * @return void
28
+     * @throws \think\db\exception\DataNotFoundException
29
+     * @throws \think\db\exception\DbException
30
+     * @throws \think\db\exception\ModelNotFoundException
31
+     */
32
+    private function doMovieOrder()
33
+    {
34
+        $page = 1;
35
+        $limit = 100;
36
+
37
+        /** @var MovieRepository $movieOrderRepository */
38
+        $movieOrderRepository = app()->make(MovieRepository::class);
39
+        $filmLists = $movieOrderRepository->getOrderListAll($page, $limit);
40
+
41
+        if (isset($filmLists['code']) && ($filmLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
42
+            $this->createMovieFilm($filmLists['data']['list']);
43
+
44
+            $data = $filmLists['data'];
45
+            $totalPages = $data['paging']['pages'] ?? 0;
46
+            for ($index = ($page + 1); $index <= $totalPages; $index++) {
47
+                $filmLists = $movieRepository->getFilm($index, $limit);
48
+                if (isset($filmLists['code']) && ($filmLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
49
+                    $this->createMovieFilm($filmLists['data']['list']);
50
+                }
51
+            }
52
+        }
53
+    }
54
+
55
+    /**
56
+     * 电影-获取影片列表
57
+     *
58
+     * @param $list
59
+     * @return void
60
+     * @throws \think\db\exception\DataNotFoundException
61
+     * @throws \think\db\exception\DbException
62
+     * @throws \think\db\exception\ModelNotFoundException
63
+     */
64
+    private function createMovieFilm($list)
65
+    {
66
+        $film_signList = array_column($list, 'film_sign');
67
+
68
+        $localFilm_nameLists = Db::name('movie_film')->whereIn('film_sign', $film_signList)->field('id,film_sign,film_name,publish_date')->select();
69
+        $localFilm_nameLists = !empty($localFilm_nameLists) ? array_reduce($localFilm_nameLists->toArray(), function ($carry, $item) {
70
+            $carry[$item['film_sign']] = [
71
+                'id' => $item['id'], 'film_sign' => $item['film_sign'], 'film_name' => $item['film_name'], 'publish_date' => $item['publish_date']
72
+            ];
73
+            return $carry;
74
+        }, []) : [];
75
+        $time = strtotime(date('Y-m-d'));
76
+
77
+        foreach ($list as $key => $value) {
78
+            $publish_date = strtotime($value['publish_date']);
79
+            $params = [
80
+                'film_sign' => $value['film_sign'],
81
+                'film_name' => $value['film_name'],
82
+                'publish_date' => $publish_date,
83
+                'language' => trim($value['language']),
84
+                'type' => $value['type'],
85
+                'duration' => $value['duration'],
86
+                'version' => $value['version'],
87
+                'grade' => $value['grade'],
88
+                'hots' => $value['hots'],
89
+                'cover_img' => $value['cover_img'],
90
+                'video' => $value['video'],
91
+                'detail_img' => json_encode($value['detail_img'], JSON_FORCE_OBJECT),
92
+                'director' => json_encode($value['director'], JSON_FORCE_OBJECT),
93
+                'actors' => json_encode($value['actors'], JSON_FORCE_OBJECT),
94
+                'intro' => $value['intro'],
95
+                'is_show' => intval(($publish_date <= $time))
96
+            ];
97
+            if (!isset($localFilm_nameLists[$value['film_sign']])) {
98
+                $params['create_time'] = time();
99
+                Db::name('movie_film')->insert($params);
100
+            } else {
101
+                $localFilm_name = $localFilm_nameLists[$value['film_sign']];
102
+                if (md5($value['film_sign'] . $value['film_name'] . $value['publish_date'])
103
+                    != md5($localFilm_name['film_sign'] . $localFilm_name['film_name'] . $localFilm_name['publish_date'])) {
104
+                    $params['update_time'] = time();
105
+                    Db::name('movie_film')->where('id', $localFilm_name['id'])->update($params);
106
+                }
107
+            }
108
+        }
109
+    }
110
+}

+ 8 - 1
app/common/repositories/movie/CinemaSchedRepository.php

@@ -128,7 +128,14 @@ class CinemaSchedRepository extends BaseRepository
128 128
         $cinema_sched = $movieRepository->getCinemaSched($film_sign, $cinema_sign);
129 129
 
130 130
         // 排片日期
131
-        $show_date = array_keys($cinema_sched);
131
+        $show_date = [];
132
+        $show_date_tmp = array_keys($cinema_sched);
133
+        foreach ($show_date_tmp as $sdKey => $sdValue) {
134
+            $show_date[$sdKey] = [
135
+                'date_timestamp' => strtotime(date('Y') . '-' . $sdValue),
136
+                'date' => $sdValue,
137
+            ];
138
+        }
132 139
         // 场次列表
133 140
         foreach ($cinema_sched as $date => &$cinema_schedValue) {
134 141
             foreach ($cinema_schedValue as $key => $value) {

+ 46 - 0
app/common/repositories/movie/MovieRepository.php

@@ -688,4 +688,50 @@ class MovieRepository extends BaseRepository
688 688
 
689 689
         return compact('movie_order', 'count');
690 690
     }
691
+
692
+    /**
693
+     * 订单列表
694
+     *
695
+     * @param $userinfo
696
+     * @param $page
697
+     * @param $limit
698
+     * @param $type
699
+     * @return array
700
+     * @throws \think\db\exception\DataNotFoundException
701
+     * @throws \think\db\exception\DbException
702
+     * @throws \think\db\exception\ModelNotFoundException
703
+     */
704
+    public function getOrderListAll($userinfo, $page, $limit, $type = -1)
705
+    {
706
+        $where['uid'] = $userinfo['uid'];
707
+        switch ($type) {
708
+            case 0:
709
+                $where['status'] = [0];
710
+                break;
711
+            case 1:
712
+            case 4:
713
+                $where['status'] = [1, 4];
714
+                break;
715
+            case 2:
716
+            case 3:
717
+                $where['status'] = [2, 3];
718
+                break;
719
+            default:
720
+                break;
721
+        }
722
+
723
+        $field = 'order_sn,order_price,city_name,area_name,cinema_name,address,hall_name,film_sign,film_name,show_date,show_time,sched_seat,number,status,create_time';
724
+        $movie_order = $this->dao->search($where)
725
+            ->when($page && $limit, function ($query) use ($page, $limit) {
726
+                $query->page($page, $limit);
727
+            })->order('order_id desc')->field([$field])->select()->toArray();
728
+        foreach ($movie_order as $key => $value) {
729
+            $movie_order[$key]['sched_seat'] = json_decode($value['sched_seat'], true);
730
+            $movie_order[$key]['cover_img'] = Db::name('movie_film')->where('film_sign', $value['film_sign'])->value('cover_img');
731
+        }
732
+
733
+        $count = $this->dao->search($where)->count();
734
+
735
+        return compact('movie_order', 'count');
736
+    }
691 737
 }