Sfoglia il codice sorgente

电影订单超时检查

family 1 anno fa
parent
commit
f31646d305

+ 11 - 71
app/command/MovieOrderCommand.php

@@ -14,7 +14,7 @@ class MovieOrderCommand extends Command
14 14
     protected function configure()
15 15
     {
16 16
         // 指令配置
17
-        $this->setName('movie-order')->setDescription('电影-订单');
17
+        $this->setName('movie_order')->setDescription('电影-订单');
18 18
     }
19 19
 
20 20
     protected function execute(Input $input, Output $output)
@@ -31,79 +31,19 @@ class MovieOrderCommand extends Command
31 31
      */
32 32
     private function doMovieOrder()
33 33
     {
34
-        $page = 1;
35
-        $limit = 100;
34
+        $tenMinute = 600; // 10分钟
35
+        $time = time();
36 36
 
37 37
         /** @var MovieRepository $movieOrderRepository */
38 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
-                }
39
+        $movieOrder = $movieOrderRepository->getOrderListAll([0]);
40
+
41
+        foreach ($movieOrder as $key => $order) {
42
+            $create_time = strtotime($order['create_time']) + $tenMinute;
43
+            // 下单时间 + 10分钟 < 当前时间:表示订单超时
44
+            if ($create_time < $time) {
45
+                $update = ['status' => 3, 'update_time' => time()];
46
+                Db::name('order_movie')->where(['order_id' => $order['order_id']])->update($update);
107 47
             }
108 48
         }
109 49
     }

+ 11 - 34
app/common/repositories/movie/MovieRepository.php

@@ -850,48 +850,25 @@ class MovieRepository extends BaseRepository
850 850
     }
851 851
 
852 852
     /**
853
-     * 订单列表
853
+     * 所有未支付订单列表
854 854
      *
855
-     * @param $userinfo
856
-     * @param $page
857
-     * @param $limit
858
-     * @param $type
855
+     * @param $status
856
+     * @param $paid
859 857
      * @return array
860 858
      * @throws \think\db\exception\DataNotFoundException
861 859
      * @throws \think\db\exception\DbException
862 860
      * @throws \think\db\exception\ModelNotFoundException
863 861
      */
864
-    public function getOrderListAll($userinfo, $page, $limit, $type = -1)
862
+    public function getOrderListAll($status = [], $paid = 0)
865 863
     {
866
-        $where['uid'] = $userinfo['uid'];
867
-        switch ($type) {
868
-            case 0:
869
-                $where['status'] = [0];
870
-                break;
871
-            case 1:
872
-            case 4:
873
-                $where['status'] = [1, 4];
874
-                break;
875
-            case 2:
876
-            case 3:
877
-                $where['status'] = [2, 3];
878
-                break;
879
-            default:
880
-                break;
881
-        }
882
-
883
-        $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';
884
-        $movie_order = $this->dao->search($where)
885
-            ->when($page && $limit, function ($query) use ($page, $limit) {
886
-                $query->page($page, $limit);
887
-            })->order('order_id desc')->field([$field])->select()->toArray();
888
-        foreach ($movie_order as $key => $value) {
889
-            $movie_order[$key]['sched_seat'] = json_decode($value['sched_seat'], true);
890
-            $movie_order[$key]['cover_img'] = Db::name('movie_film')->where('film_sign', $value['film_sign'])->value('cover_img');
891
-        }
864
+        $where = ['status' => $status, 'paid' => $paid];
892 865
 
893
-        $count = $this->dao->search($where)->count();
866
+        $field = 'order_id,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';
867
+        //        foreach ($movie_order as $key => $value) {
868
+//            $movie_order[$key]['sched_seat'] = json_decode($value['sched_seat'], true);
869
+//            $movie_order[$key]['cover_img'] = Db::name('movie_film')->where('film_sign', $value['film_sign'])->value('cover_img');
870
+//        }
894 871
 
895
-        return compact('movie_order', 'count');
872
+        return $this->dao->search($where)->order('create_time asc')->field([$field])->select()->toArray();
896 873
     }
897 874
 }

+ 1 - 0
config/console.php

@@ -29,5 +29,6 @@ return [
29 29
         'cinema_film_sched' => 'app\command\CinemaSchedCommand',
30 30
         'repair_pv_log' => 'app\command\repairPvLog',
31 31
         'gzcAddByBill' => 'app\command\GzcAddByBillCommand',
32
+        'movie_order' => 'app\command\MovieOrderCommand',
32 33
     ],
33 34
 ];