where('level', '<>', 0)->get() as $user){ User::query()->whereId($user->id)->update(['level' => 0]); } // 获取商品列表,取新等级 $goodList = Goods::query()->where('level', '<>', 0)->whereType(2)->get(); // 取生效的套餐 $orderList = Order::query() ->whereIn('goods_id', $goodList->pluck('id')->toArray()) ->whereStatus(2) ->whereIsExpire(0) ->get(); foreach($orderList as $order){ $ret = User::query()->whereId($order->user_id)->update(['level' => $order->goods->level]); if($ret){ Log::info('用户: '.$order->user->id.', 按照订单'.$order->id.' 等级为'.$order->goods->level); }else{ Log::error('用户: '.$order->user->id.' 等级更新失败!'); } } Log::info('----------------------------【用户等级升级】结束----------------------------'); } }