self::getUinqueId(4,$ids), "user_id" => $user_id, "party_id" => $party_id, "name" => $party_name."的公会", "image" => "/assets/img/guild_image.jpeg", "desc" => "请编辑公会简介内容!", "notice" => "请编辑公会公告内容!", "createtime" => time() ]; $guild_id = self::insertGetId($data); // 添加工会长 $data = [ "guild_id" => $guild_id, "user_id" => $user_id, "role" => 2, "sign_type" => 3, "status" => 1, "sign_time" => 2147483647, "createtime" => time() ]; $res2 = \app\common\model\GuildMember::insert($data); // 更新用户公会ID $res3 = \app\common\model\User::update(["guild_id"=>$guild_id],["id"=>$user_id]); if($guild_id && $res2 && $res3) { Db::commit(); } }catch (ValidateException $e) { Db::rollback(); } catch (PDOException $e) { Db::rollback(); } catch (Exception $e) { Db::rollback(); } } /** * 生成不重复的随机数字 */ public static function getUinqueId($length = 4,$ids = []) { $newid = Random::build("nozero",$length); if(in_array($newid,$ids)) { self::getUinqueId(4,$ids); } return $newid; } }