* @version : HUOSDK 8.0 */ namespace console\index\controller; use huo\model\order\OrderModel; use huolib\constant\OrderConst; use huolib\tool\Time; use huoOrderRepeat\controller\OrderRepeat; use think\console\Command; use think\console\Input; use think\console\input\Option; use think\console\Output; class RepeatOrder extends Command { protected function configure() { $this->setName('repeat_order')->setDescription('所有掉单补单'); $this->addOption('date', 'd', Option::VALUE_REQUIRED, 'choose date to do', ''); } protected function execute(Input $input, Output $output) { $_date = $input->getOption('date'); $_log_date = date('Y-m-d H:i:s'); \think\Log::write("ETL RepeatOrder at $_log_date and date = $_date", 'etl', true); $this->repeatByDate($_date); exit; } /** * 执行每日补单操作 * * @param $date */ private function repeatByDate($date) { $_map = [ 'cp_status' => ['neq', OrderConst::CP_STATUS_SUC], 'status' => OrderConst::PAY_STATUS_SUC, ]; if (!empty($date)) { list($_start_time, $_end_time) = Time::day($date); $_map['create_time'] = ['between', [$_start_time, $_end_time]]; } $_order_repeat = new OrderRepeat(); $_order_model = new OrderModel(); $_field = ['id', 'order_id']; $_order_model->where($_map)->field($_field)->chunk( 10, function ($_orders) use ($_order_repeat) { foreach ($_orders as $_order) { if (is_object($_order)) { $_order = $_order->toArray(); } if (!empty($_order['order_id'])) { $_order_repeat->cpNotifyQueue($_order['order_id'], 1); } } } ); } }