GuildModel.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. namespace loyalsoft;
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8. /**
  9. * Description of GuildModel
  10. *
  11. * @author cyzhao
  12. */
  13. class GuildModel
  14. {
  15. /**
  16. * 公会的ID
  17. * @var int
  18. */
  19. public $guildId;
  20. /**
  21. * 公会名称
  22. * @var string
  23. */
  24. public $name;
  25. /**
  26. * 公会的等级
  27. * @var int
  28. */
  29. public $level = 1;
  30. /**
  31. * 奖杯积分
  32. * @var int
  33. */
  34. public $cupScore = 0;
  35. /**
  36. * 玩家申请加入公会列表
  37. * @var object
  38. */
  39. public $applylist;
  40. /**
  41. * 会长的OpenID
  42. * @var string
  43. */
  44. public $chairman_id = "";
  45. /**
  46. * 会长 name
  47. * @var string
  48. */
  49. public $chairman_name = "";
  50. /**
  51. * @var array 副会长集合
  52. */
  53. public $viceChairManArr = array();
  54. /**
  55. * @var array 干部
  56. */
  57. public $officerManArr = array();
  58. /**
  59. * 公会成员
  60. * @var array
  61. */
  62. public $members = array();
  63. /**
  64. * 公会的宗旨/公告
  65. * @var string
  66. */
  67. public $declare = "";
  68. /**
  69. * 创建时间戳
  70. * @var type
  71. */
  72. public $createts = 0;
  73. /**
  74. * 允许一键(快速)加入, 默认不开启
  75. * @var int
  76. */
  77. public $enableQuickIn = 0; //默认允许任何人加入; 1是需要申请;2不允许任何人加入公会
  78. /**
  79. * 徽章
  80. * @var int
  81. */
  82. public $guild_img = 0;
  83. /**
  84. * 加入公会所需条件
  85. * @var int
  86. */
  87. public $condition;
  88. /**
  89. * 弹劾 同意
  90. * @var type
  91. */
  92. public $accuse_agreed = array();
  93. /**
  94. * 弹劾 拒接
  95. * @var type
  96. */
  97. public $accuse_refuse = array();
  98. /**
  99. * 弹劾 时间
  100. * @var int
  101. */
  102. public $accuseTs = 0;
  103. /**
  104. * 弹劾 冷却时间
  105. * @var int
  106. */
  107. public $accuse_coolTime = 0;
  108. /**
  109. * 公会总贡献
  110. * @var int
  111. */
  112. public $allContribute = 0;
  113. /**
  114. * 公会公告编辑冷却时间
  115. * @var int
  116. */
  117. public $announcement_CoolingTs = 0;
  118. /**
  119. * 公会公告内容
  120. * @var type
  121. */
  122. public $announcement_content = array();
  123. /**
  124. * 公会礼包购买数量记录
  125. * @var type
  126. */
  127. public $giftnum_record;
  128. /**
  129. * 创建新公会
  130. * @param type $mem
  131. * @return GuildModel
  132. */
  133. public static function NewGuildInit($mem, $zoneid)
  134. {
  135. $guildid = self::CreateNewGuildID($mem, $zoneid);
  136. $guildInfo = new GuildModel();
  137. $guildInfo->guildId = $guildid;
  138. $guildInfo->createts = now();
  139. $guildInfo->members = array();
  140. $guildInfo->level = 1;
  141. $guildInfo->cupScore = 0;
  142. $guildInfo->applylist = ObjectInit();
  143. $guildInfo->condition = ObjectInit();
  144. $guildInfo->giftnum_record = ObjectInit();
  145. return $guildInfo;
  146. }
  147. static function CreateNewGuildID($mem, $zoneid)
  148. {
  149. $i = 0;
  150. while (true) {
  151. if ($mem->add(MemKey_Guild::constCreateGuildIDLock(), "V")) {
  152. $guildid = $mem->get(MemKey_Guild::constGetCurrentMaxGuildID($zoneid));
  153. if ($guildid == null) {
  154. $guildid = GUILDIDBASE;
  155. }
  156. $guildid += 1;
  157. $mem->set(MemKey_Guild::constGetCurrentMaxGuildID($zoneid), $guildid);
  158. $mem->delete(MemKey_Guild::constCreateGuildIDLock());
  159. return $guildid;
  160. } else {
  161. if ($i++ > 10)
  162. return 0;
  163. usleep(13); // 休息13微妙
  164. }
  165. }
  166. }
  167. }
  168. /**
  169. * 玩家请求加入公会的消息结构体
  170. */
  171. class UserApplyForGuildModel
  172. {
  173. public $uid;
  174. public $ts;
  175. public $approved = false;
  176. public $name;
  177. public $level;
  178. /**
  179. * 创建一条新的请求信息
  180. * @param type $oid
  181. * @return UserApplyForGuildModel Description
  182. */
  183. public static function CreateApplyInfo($uid, $name, $level)
  184. {
  185. $ret = new UserApplyForGuildModel();
  186. $ret->uid = $uid;
  187. $ret->ts = now();
  188. $ret->name = $name;
  189. $ret->level = $level;
  190. $ret->approved = false;
  191. return $ret;
  192. }
  193. }
  194. /**
  195. * 公会值日消息类型
  196. */
  197. class GuildJournalType
  198. {
  199. const Join = 1; //加入
  200. const requestDonate = 2; //请求捐献
  201. const Quit = 3; //退会
  202. const ChangeChairMan = 4; //改变会长
  203. const BuyGift = 5; //购买礼包
  204. }
  205. /**
  206. * 公会日志数据体
  207. */
  208. class GuildJournalModel
  209. {
  210. public $ts;
  211. public $uid;
  212. public $type;
  213. public $datas;
  214. public static function CreateJoin($uid, $name)
  215. {
  216. $journal = new GuildJournalModel();
  217. $journal->ts = now();
  218. $journal->type = GuildJournalType::Join;
  219. $journal->uid = $uid;
  220. $journal->datas = array();
  221. $journal->datas [] = $uid;
  222. $journal->datas [] = $name;
  223. return $journal;
  224. }
  225. public static function RequestDonate($uid, $name, $cardId, $cardCount)
  226. {
  227. $journal = new GuildJournalModel();
  228. $journal->ts = now();
  229. $journal->type = GuildJournalType::requestDonate;
  230. $journal->uid = $uid;
  231. $journal->datas = array();
  232. $journal->datas [] = $uid;
  233. $journal->datas [] = $name;
  234. $journal->datas [] = $cardId;
  235. $journal->datas [] = $cardCount;
  236. $journal->datas [] = 0; //现在已得到的捐献数量
  237. return $journal;
  238. }
  239. public static function CreateQuit($uid, $name)
  240. {
  241. $journal = new GuildJournalModel();
  242. $journal->ts = now();
  243. $journal->type = GuildJournalType::Quit;
  244. $journal->uid = $uid;
  245. $journal->datas = array();
  246. $journal->datas [] = $uid;
  247. $journal->datas [] = $name;
  248. return $journal;
  249. }
  250. public static function CreateChangeChairman($uid, $name, $transferedid, $transferedname)
  251. {
  252. $journal = new GuildJournalModel();
  253. $journal->ts = now();
  254. $journal->type = GuildJournalType::ChangeChairMan;
  255. $journal->uid = $uid;
  256. $journal->datas = array();
  257. $journal->datas [] = $uid;
  258. $journal->datas [] = $name;
  259. $journal->datas [] = $transferedid;
  260. $journal->datas [] = $transferedname;
  261. return $journal;
  262. }
  263. public static function BuyGift($uid, $name)
  264. {
  265. $journal = new GuildJournalModel();
  266. $journal->ts = now();
  267. $journal->type = GuildJournalType::BuyGift;
  268. $journal->uid = $uid;
  269. $journal->datas = array();
  270. $journal->datas [] = $uid;
  271. $journal->datas [] = $name;
  272. return $journal;
  273. }
  274. }
  275. class GuildAnnouncementModel extends Object_ext
  276. {
  277. public $ts;
  278. public $title;
  279. public $content;
  280. function __construct($tag, $ts, $title, $content)
  281. {
  282. if (1 == func_num_args() && $tag) { # 默认的Object初始化方法
  283. parent::__construct($tag);
  284. } else {
  285. $this->ts = $ts;
  286. $this->title = $title;
  287. $this->content = $content;
  288. }
  289. }
  290. }