setName('xQueue:Book'); // $this->setDescription('导入章节内容'); $this->setName('xQueue:KamiOrderFinish')->setDescription('[ 订单列表 ] 卡密完成订单迁移'); } /** * @param Input $input * @param Output $output * @throws \think\admin\Exception */ protected function execute(Input $input, Output $output) { ini_set('memory_limit', '1024M'); $day = input('day'); // var_dump($day);die; MerchantService::instance()->init($day); /* if (!$day) { $day = date('Y-m-d', strtotime('-1 day')); } */ $page = 1; $this->finishOne($day, $page); while ($this->finishOne($day, $page)) { $page++; } $this->setQueueSuccess("完成 {$page} 页订单迁移!"); } public function finishOne($day, $page) { $orderService = Kami91OrderService::instance(); $orderHistoryService = KamiOrderHistoryService::instance(); $data = $this->getFinishData($day, $page, $orderService); //??// list($count, $total) = [0, $data->count()]; if(!$total){ return false; } return $data->chunk(100, function (Collection $data) use (&$count, $total, $orderService, $orderHistoryService) { // var_dump($orderlist);die; foreach ($data->toArray() as $vo) { if ($vo) { # 先插入一条历史数据 $id = $vo['id']; unset($vo['id']); $state = $orderHistoryService->up($vo); if ($state) { $orderService->del($id); $count++; $this->setQueueProgress("迁移订单 {$vo['order_id']} ", $count / $total * 100); } }else{ return false; } } return true; }); } public function getFinishData($day, $page, $orderService) { if (!$day) { $start = date('Y-m-d', strtotime('-360 day')); $day = date('Y-m-d', strtotime('-1 day')); } else { $start = $day; } $begin = $start . ' 00:00:00'; $after = $day . ' 23:59:59'; $time = [$begin, $after]; $db = $orderService->db()->whereRaw('status in(2,3) '); $db = $db->whereBetween('create_at', $time)->order('id asc'); if ($page) { $limit = 1000; $page = $page - 1; $page = $page * $limit; $db->limit($page, $limit); } return $db; } }