weaponlevelDeal.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. include_once __DIR__ . '/../../main.php';
  9. //taskDeal();
  10. textInterface();
  11. function taskDeal() {
  12. $db = daoInst();
  13. $zoneid = 1;
  14. $index = 0;
  15. $size = 20;
  16. $page = 0;
  17. $userUidArr = array();
  18. while (true) {
  19. $page = $index * $size;
  20. $sql = "select * from tab_rolename WHERE zoneid= $zoneid limit %d,%d";
  21. $queryStr = sprintf($sql, $page, $size);
  22. $result = $db->query($queryStr)->fetchAll();
  23. if(count($result) == 0){
  24. break;
  25. }
  26. foreach ($result as $arr) {
  27. foreach ($arr as $k=>$item) {
  28. if($k == "userID" && !in_array($item, $userUidArr)){
  29. $userUidArr[] = $item;
  30. }
  31. }
  32. }
  33. $index += 1;
  34. }
  35. startDeal($userUidArr);
  36. }
  37. /**
  38. * 测试接口 可以自己添加uid测试
  39. */
  40. function textInterface() {
  41. $userUidArr = array();
  42. //$userUidArr[] = "6347a46975d0a43de55f0cec";
  43. $userUidArr[] = "EA74E58DCEB076ACC2D824684499CDA2";
  44. startDeal($userUidArr);
  45. }
  46. /**
  47. * 开始处理玩家任务信息
  48. * @param type $userUidArr
  49. */
  50. function startDeal($userUidArr) {
  51. $mem = gMem();
  52. $weaponConf = GameConfig::weaponextra_level();
  53. foreach ($userUidArr as $userUid) {
  54. $userRedisKey = MemKey_User::Info_hash(1, $userUid);
  55. if(!$mem->exists($userRedisKey)){
  56. //$sFname = "savData/" ."noRedisExistUserUid.txt";
  57. $sFname = isOnline("otherData", "noRedisExistUserUid.txt");
  58. //$sFname = "../../../../../../ylsjTaskData/otherData/"."noRedisExistUserUid.txt";
  59. $fd = fopen($sFname, 'a');
  60. fwrite($fd, "\r\n" . $userRedisKey);
  61. fclose($fd);
  62. continue;
  63. }
  64. if(!$mem->hexists($userRedisKey,'privateState')){
  65. //$sFname = "savData/" ."noPrivateState.txt";
  66. //$sFname = "../../../../../../ylsjTaskData/otherData/"."noPrivateState.txt";
  67. $sFname = isOnline("otherData", "noPrivateState.txt");
  68. $fd = fopen($sFname, 'a');
  69. fwrite($fd, "\r\n" . $userRedisKey);
  70. fclose($fd);
  71. continue;
  72. }
  73. if(!$mem->hexists($userRedisKey,'store')){
  74. //$sFname = "savData/" ."noStore.txt";
  75. //$sFname = "../../../../../../ylsjTaskData/otherData/"."noStore.txt";
  76. $sFname = isOnline("otherData", "noStore.txt");
  77. $fd = fopen($sFname, 'a');
  78. fwrite($fd, "\r\n" . $userRedisKey);
  79. fclose($fd);
  80. continue;
  81. }
  82. $privateState = $mem->hget($userRedisKey, 'privateState');
  83. if(!StlUtil::dictHasProperty($privateState,'weapon_index')){
  84. $privateState->weapon_index = 0;
  85. }
  86. $startIndex = $privateState->weapon_index;
  87. if($startIndex > 0){
  88. continue;
  89. }
  90. $store = $mem->hget($userRedisKey, 'store');
  91. $equipment = $store->equipment;
  92. //处理前玩家数据保存
  93. taskSav_start($userRedisKey, $store, $privateState);
  94. $tempDic = new \stdClass();
  95. $index = 0;
  96. foreach ($equipment as $k => $item) {
  97. $typeId = $item->typeId;
  98. if(!StlUtil::dictHasProperty($weaponConf, $typeId)){
  99. $sFname = isOnline("otherData", "noConf.txt");
  100. $fd = fopen($sFname, 'a');
  101. fwrite($fd, "\r\n" . $typeId);
  102. fclose($fd);
  103. continue;
  104. }
  105. $lv = $item->level;
  106. $dic = $weaponConf->$typeId;
  107. $arr = (array)$dic;
  108. ksort($arr);
  109. foreach ($arr as $star => $val) {
  110. if($lv >= $val->starlimitLv){
  111. $item->starLevel = $val->starLv;
  112. }
  113. }
  114. $index += 1;
  115. $tempDic->$k = $item;
  116. $privateState->weapon_index = $index;
  117. }
  118. $store->equipment = $tempDic;
  119. taskSav_end($userRedisKey, $store, $privateState);
  120. //玩家数据回存
  121. gMem()->hset($userRedisKey, 'store', $store);
  122. gMem()->hset($userRedisKey, 'privateState', $privateState);
  123. }
  124. }
  125. /**
  126. * 保存数据地址 ----自己去方法里面设置 true或是false
  127. * @param type $g
  128. * @param type $name
  129. * @return string
  130. */
  131. function isOnline($g,$name) {
  132. $Online = false;
  133. $sFname = $name;
  134. if($Online){
  135. if($g == "start"){
  136. $sFname = "../../../../../../ylsjWeaponData/sav_start/".$name;
  137. } elseif ($g == "end") {
  138. $sFname = "../../../../../../ylsjWeaponData/sav_last/".$name;
  139. } else {
  140. $sFname = "../../../../../../ylsjWeaponData/otherData/".$name;
  141. }
  142. } else {
  143. $sFname = "savData/". $name;
  144. }
  145. return $sFname;
  146. }
  147. /**
  148. * 处理完后数据回存
  149. * @param type $userUid
  150. * @param type $store
  151. * @param type $privateState
  152. * @param type $hero
  153. */
  154. function taskSav_start($userUid,$store,$privateState) {
  155. $name = isOnline("start", $userUid."-pre.txt");
  156. $fd = fopen($name, 'a');
  157. fwrite($fd, json_encode($store)."\r\n");
  158. fwrite($fd, "\r\n" . json_encode($privateState)."\r\n");
  159. fclose($fd);
  160. }
  161. function taskSav_end($userUid,$store,$privateState) {
  162. //$name ="savData/". "$userUid"."-last.txt";
  163. //$name = "../../../../../../ylsjTaskData/sav_last/"."$userUid"."-last.txt";
  164. $name = isOnline("end", $userUid."-last.txt");
  165. $fd = fopen($name, 'a');
  166. fwrite($fd,"\r\n" . json_encode($store)."\r\n");
  167. fwrite($fd, "\r\n" . json_encode($privateState)."\r\n");
  168. fclose($fd);
  169. }