setName('check:dispatch') ->setDescription($this->title); } protected function execute(Input $input, Output $output){ // 查询所有待派单,且未通知过的订单 $orders = Db::name('order') ->alias('o') ->join('order_dispatch_notify n', 'o.id = n.order_id','left') ->where('o.status', Order::STATUS_DISPATCHING) ->whereNull('n.id') // 没有记录就表示还没通知 ->where('o.create_time', '<=', now()->format('Y-m-d H:i:s')) ->field(['o.id','o.area_id','o.order_no']) ->select(); $log_insert = []; $now = now()->format('Y-m-d H:i:s'); foreach ($orders as $order){ $area_id = substr($order['area_id'], 0, 4); $res = Admin::where('area_ids', 'like', '%' . $area_id . '%') ->column('id'); $insert = []; foreach ($res as $re) { $insert [] = [ 'to_id' => $re, 'type' => 1, 'title' => '订单未派单超时通知', 'content' => '您有一条订单号为 ' . $order['order_no'] . ' 超过20分钟未派单,请及时派单!' ]; } $build = new Message(); $build->saveAll($insert); $log_insert [] = [ 'order_id' => $order['id'], 'notified_at' => $now, 'created_at' => $now, ]; } Db::name('order_dispatch_notify')->insertAll($log_insert); } }