where("status", 1)->get(); foreach($list as $item) { try{ $delivery_message = json_decode($item["delivery_message"],true); $commodity_id = $item["id"]; $count = Card::query()->where("commodity_id", (int)$commodity_id)->where("status", 0)->count(); if($count < $num) { for($i = 0; $i < $num; $i++) { $cardObj = new \App\Model\Card(); $cardObj->commodity_id = $commodity_id; $cardObj->owner = 0; $cardObj->secret = json_encode($delivery_message,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $cardObj->create_time = Date::current(); $cardObj->save(); } } }catch(\Exception $e){ } } return "ok"; } }