slotresult.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <?php
  2. defined( 'IN_WEB') or die( 'Include Error!');
  3. /**
  4. * 老虎机概率规则
  5. */
  6. class ModelSlotresult{
  7. //修正需消耗总体力配置表
  8. public $betSpinsRule=[
  9. 1=>50,
  10. 2=>50,
  11. 3=>50,
  12. 5=>50,
  13. 10=>100,
  14. 20=>200,
  15. 40=>400,
  16. 80=>800,
  17. 100=>1000,
  18. 200=>2000,
  19. ];
  20. //默认转老虎机体力消耗结构[1=>"打",2=>"偷",3=>"体力",4=>"盾牌",5=>"1金币",6=>"2金币",7=>"3金币",8=>"1金币袋",9=>"2金币袋",10=>"3金币袋",11=>"空",12=>"1收集物",13=>"2收集物",14=>"3收集物",15=>"小玩法1",16=>"小玩法2",17=>"小玩法3",18=>"偷1",19=>"偷2",20=>"打1",21=>"打2",22=>"1体力瓶",23=>"2体力瓶"]
  21. public $defaultLostSpinsArr=[1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0,8=>0,9=>0,10=>0,11=>0,12=>0,13=>0,14=>0,15=>0,16=>0,17=>0,18=>0,19=>0,20=>0,21=>0,22=>0,23=>0];
  22. //默认转老虎机体力消耗对权重修正系数配置
  23. public $defaultSpinsLostCfg = [
  24. -5 =>[1=>5, 2=>5, 3=>5, 4=>5, 5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>5, 13=>5, 14=>5,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  25. -4 =>[1=>3, 2=>3, 3=>3, 4=>3, 5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>3, 13=>3, 14=>3,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  26. -3 =>[1=>2.5,2=>2.5,3=>2.5,4=>2.5,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>2.5,13=>2.5,14=>2.5,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  27. -2 =>[1=>2, 2=>2, 3=>2, 4=>2, 5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>2, 13=>2, 14=>2,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  28. -1 =>[1=>1.5,2=>1.5,3=>1.5,4=>1.5,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>1.5,13=>1.5,14=>1.5,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  29. 0 =>[1=>1, 2=>1, 3=>1, 4=>1, 5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>1, 13=>1, 14=>1,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  30. 1 =>[1=>0.9,2=>0.9,3=>0.9,4=>0.9,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.9,13=>0.9,14=>0.9,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  31. 2 =>[1=>0.8,2=>0.8,3=>0.8,4=>0.8,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.8,13=>0.8,14=>0.8,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  32. 3 =>[1=>0.7,2=>0.7,3=>0.7,4=>0.7,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.7,13=>0.7,14=>0.7,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  33. 4 =>[1=>0.6,2=>0.6,3=>0.6,4=>0.6,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.6,13=>0.6,14=>0.6,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  34. 5 =>[1=>0.5,2=>0.5,3=>0.5,4=>0.5,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.5,13=>0.5,14=>0.5,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  35. ];
  36. //默认每6小时转老虎机体力消耗对权重修正系数配置
  37. public $defaultSpinsLostDayCfg = [
  38. 100 =>[1=>1,2=>1,3=>1.5,4=>1.5,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>1.5,13=>1.5,14=>1.5,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  39. 200 =>[1=>1,2=>1.5,3=>1,4=>1,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>1,13=>1,14=>1,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  40. 500 =>[1=>1,2=>1,3=>0.8,4=>0.8,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.8,13=>0.8,14=>0.8,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  41. 1000 =>[1=>1,2=>1,3=>0.5,4=>0.5,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.5,13=>0.5,14=>0.5,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  42. 2000 =>[1=>1,2=>1,3=>0.3,4=>0.3,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.3,13=>0.3,14=>0.3,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  43. 5000 =>[1=>1,2=>1,3=>0.2,4=>0.2,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.2,13=>0.2,14=>0.2,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  44. ];
  45. //默认每6小时转老虎机次数对权重修正系数配置
  46. public $defaultSlotLimitDayCfg = [
  47. 10 =>[1=>1,2=>2,3=>1,4=>1,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>2,13=>2,14=>2,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  48. 20 =>[1=>2,2=>1,3=>2,4=>2,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>1.5,13=>1.5,14=>1.5,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  49. 40 =>[1=>1,2=>1,3=>1.5,4=>1.5,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>1,13=>1,14=>1,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  50. 60 =>[1=>1,2=>1,3=>1,4=>1,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>1,13=>1,14=>1,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  51. 80 =>[1=>1,2=>1,3=>0.5,4=>0.5,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.5,13=>0.5,14=>0.5,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  52. 100=>[1=>1,2=>1,3=>0.2,4=>0.2,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>0.2,13=>0.2,14=>0.2,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1],
  53. ];
  54. /**
  55. * Notes:等级获取旋转权重配置
  56. * User: wsc
  57. * Time: 2021/2/25 10:27
  58. * @param $lv
  59. * @return mixed
  60. */
  61. public function getWeightByLv($lv){
  62. $ret = oo::commonOprRedis('common')->hGet(okeys::slotWeightCfg(),$lv);
  63. if(!empty($ret)){
  64. return json_decode($ret,true);
  65. }
  66. //查询数据库概率
  67. $tb = otable::slotWeightCfg();
  68. $sql = "select * from {$tb} where levelId={$lv} limit 1";
  69. $conf = oo::commonOprDb('config')->getOne($sql, MYSQLI_ASSOC);
  70. oo::commonOprRedis('config')->hSet(okeys::slotWeightCfg(),$lv,$conf['slotpro']);
  71. $ret = json_decode($conf['slotpro'],true);
  72. return $ret;
  73. }
  74. /**
  75. * Notes:设置旋转结果体力消耗
  76. * User: wsc
  77. * Time: 2021/2/25 9:53
  78. * @param $uid
  79. * @param $id
  80. * @param $num int|float 变化值
  81. * @return int
  82. */
  83. public function changeResSpinsLost($uid,$id,$num){
  84. $key = okeys::userSlotResSpinsLost($uid);
  85. if(oo::commonOprRedis('common')->setnx(okeys::clearSlotResSpinsLostLock($uid),1)){
  86. oo::commonOprRedis('common')->delete($key);
  87. oo::commonOprRedis('common')->expire(okeys::clearSlotResSpinsLostLock($uid),7*86400);
  88. }
  89. $num = floor($num);
  90. $afterNum = oo::commonOprRedis('common')->hIncrBy($key,$id,$num);
  91. oo::commonOprRedis('common')->expire($key,7*86400);//临时策略,每次设置缓存7天
  92. return $afterNum;
  93. }
  94. /**
  95. * Notes:通过活动类型获取所有类型旋转结果体力累计消耗
  96. * User: wsc
  97. * Time: 2021/2/25 10:12
  98. * @param $uid
  99. * @param int $type 当前活动类型
  100. * @return int
  101. */
  102. public function getSumResSpinsLost($uid,$type=0){
  103. $sumSpins=0;
  104. $spinArr = oo::commonOprRedis('common')->hGetAll(okeys::userSlotResSpinsLost($uid));
  105. foreach ($spinArr as $k=>$v){
  106. if($k<12){
  107. $sumSpins +=intval($v);
  108. }
  109. }
  110. if($type==1){//只有收集物品3
  111. $sumSpins +=intval($spinArr[14]);
  112. }
  113. if($type==2){//有收集物品1,2,3
  114. $sumSpins +=intval($spinArr[12]+$spinArr[13]+$spinArr[14]);
  115. }
  116. if($type==3){//小玩法收集物1,2,3
  117. $sumSpins +=intval($spinArr[15]+$spinArr[16]+$spinArr[17]);
  118. }
  119. if($type==4){//1个打 ,2个打
  120. $sumSpins +=intval($spinArr[18]+$spinArr[19]);
  121. }
  122. if($type==5){//1个偷,2个偷
  123. $sumSpins +=intval($spinArr[20]+$spinArr[21]);
  124. }
  125. if($type==10){//1个体力瓶,2个体力瓶
  126. $sumSpins +=intval($spinArr[22]+$spinArr[23]);
  127. }
  128. return $sumSpins;
  129. }
  130. public function getSumResWeight($lv,$type=0){
  131. $sumWeight=0;
  132. $slotWeightCfg = $this->getWeightByLv($lv);
  133. $slotWeightCfg = array_column($slotWeightCfg,'v','id');
  134. foreach ($slotWeightCfg as $k=>$v){
  135. if($k<12){
  136. $sumWeight +=intval($v);
  137. }
  138. }
  139. if($type==1){//只有收集物品3
  140. $sumWeight +=intval($slotWeightCfg[14]);
  141. }
  142. if($type==2){//有收集物品1,2,3
  143. $sumWeight +=intval($slotWeightCfg[12]+$slotWeightCfg[13]+$slotWeightCfg[14]);
  144. }
  145. if($type==3){//小玩法收集物1,2,3,
  146. $sumWeight +=intval($slotWeightCfg[15]+$slotWeightCfg[16]+$slotWeightCfg[17]);
  147. }
  148. if($type==4){//1个偷,2个偷
  149. $sumWeight +=intval($slotWeightCfg[18]+$slotWeightCfg[19]);
  150. }
  151. if($type==5){//1个打 ,2个打
  152. $sumWeight +=intval($slotWeightCfg[20]+$slotWeightCfg[21]);
  153. }
  154. if($type==10){//1个体力瓶,2个体力瓶
  155. $sumWeight +=intval($slotWeightCfg[22]+$slotWeightCfg[23]);
  156. }
  157. return $sumWeight;
  158. }
  159. /**
  160. * Notes:减少所有类型旋转结果体力累计消耗
  161. * User: wsc
  162. * Time: 2021/2/25 10:46
  163. * @param $uid
  164. * @param $lv int 用户等级
  165. * @param int $type 当前活动类型
  166. * @param $bet int 当前旋转倍率
  167. * @return bool
  168. */
  169. public function delResSpinsLost($uid,$lv,$bet,$type=0){
  170. if(!$uid||!$lv||!$bet) return false;
  171. $betSpinsRule = funs::getArrFromJsonArr(oo::commonOprRedis('config')->hGetAll(okeys::slotCoefficientCfg('betSpinsRule')));
  172. $betSpinsRule = $betSpinsRule?$betSpinsRule:$this->betSpinsRule;
  173. $sumSpins = $this->getSumResSpinsLost($uid,$type);
  174. $ruleSpins = intval($betSpinsRule[$bet])>0?intval($betSpinsRule[$bet]):1000;
  175. if($sumSpins>$ruleSpins){//每次转动老虎机之后,若玩家所有类型的消耗总体力大于刚刚使用的倍率所对应的“修正需消耗总体力”
  176. $slotWeightCfg = $this->getWeightByLv($lv);
  177. $slotWeightCfg = array_column($slotWeightCfg,'v','id');
  178. $sumWeight = $this->getSumResWeight($lv,$type);
  179. foreach ($this->defaultLostSpinsArr as $k=>$v){
  180. if($k<12){
  181. $this->changeResSpinsLost($uid,$k,-abs($ruleSpins*$slotWeightCfg[$k]/$sumWeight));
  182. }else{
  183. if($type==1&&$k==14){//常规收集
  184. $this->changeResSpinsLost($uid,$k,-abs($ruleSpins*$slotWeightCfg[$k]/$sumWeight));
  185. }else if($type==2&&in_array($k,[12,13,14])){//特殊收集,特殊收集偷,特殊收集打
  186. $this->changeResSpinsLost($uid,$k,-abs($ruleSpins*$slotWeightCfg[$k]/$sumWeight));
  187. }else if($type==3&&in_array($k,[15,16,17])){//小玩法收集
  188. $this->changeResSpinsLost($uid,$k,-abs($ruleSpins*$slotWeightCfg[$k]/$sumWeight));
  189. }else if($type==4&&in_array($k,[18,19,2])){//偷收集
  190. $this->changeResSpinsLost($uid,$k,-abs($ruleSpins*$slotWeightCfg[$k]/$sumWeight));
  191. }else if($type==5&&in_array($k,[20,21,1])){//打收集
  192. $this->changeResSpinsLost($uid,$k,-abs($ruleSpins*$slotWeightCfg[$k]/$sumWeight));
  193. }
  194. }
  195. }
  196. }
  197. return true;
  198. }
  199. /**
  200. * Notes:活动进度领奖修正对应旋转结果体力累计消耗调整
  201. * User: wsc
  202. * Time: 2021/2/25 12:23
  203. * @param $uid
  204. * @param $lv
  205. * @param $spins
  206. * @param $type int 0偷,打活动 1常规收集 2特殊收集,特殊收集打,特殊收集偷
  207. * @return bool
  208. */
  209. public function activityAddResSpinsLost($uid,$lv,$spins,$gid=0){
  210. if(!$spins) return false;
  211. // $id= intval(oo::commonOprRedis('common')->get(okeys::userLastSlotId($uid)));//最后一次转到的结果id
  212. // if($id){
  213. $slotWeightCfg = $this->getWeightByLv($lv);
  214. $slotWeightCfg = array_column($slotWeightCfg,'v','id');
  215. $sumWeight=0;
  216. if($gid==1){//普通收集(打,偷,收集物3)
  217. $changeIds =[1,2,14];
  218. }else if($gid==2){//特殊收集(收集物1+收集物2+收集物3)
  219. $changeIds=[12,13,14];
  220. }else if($gid==3){//特殊收集偷(偷+收集物1+收集物2+收集物3)
  221. $changeIds=[2,12,13,14];
  222. }else if($gid==4){//特殊收集打(打+收集物1+收集物2+收集物3)
  223. $changeIds=[1,12,13,14];
  224. }else if($gid==5){//偷
  225. $changeIds=[2];
  226. }else if($gid==6){//打
  227. $changeIds=[1];
  228. }else if($gid==8){//偷收集(偷3,偷1+偷2)
  229. $changeIds=[2,18,19];
  230. }else if($gid==9){//打收集(打3+打1+打2)
  231. $changeIds=[1,20,21];
  232. }else{
  233. $changeIds = [];
  234. }
  235. if(!empty($changeIds)){
  236. foreach ($changeIds as $k=>$v){
  237. $sumWeight +=$slotWeightCfg[$v];
  238. }
  239. if($sumWeight>0){
  240. foreach ($changeIds as $k=>$id){
  241. $this->changeResSpinsLost($uid,$id,$spins*$slotWeightCfg[$id]/$sumWeight);
  242. }
  243. }
  244. }
  245. // }
  246. return true;
  247. }
  248. /**
  249. * Notes:添加老虎机累计次数及体力消耗记录(6小时内)
  250. * User: wsc
  251. * Time: 2021/2/25 11:45
  252. * @param $uid
  253. * @param int $num
  254. * @return array
  255. */
  256. public function addSlotExpendLog($uid,$num=1){
  257. $key = okeys::userSlotDayLog($uid);
  258. $resNum1 = oo::commonOprRedis('common')->hIncrBy($key,1,1);//累计次数
  259. $resNum2 = oo::commonOprRedis('common')->hIncrBy($key,2,$num);//累计消耗体力数
  260. if($resNum1==1){
  261. oo::commonOprRedis('common')->expire($key,6*3600);//12小时重新刷新
  262. }
  263. return [$resNum1,$resNum2];
  264. }
  265. /**
  266. * Notes:获取各类型权重调整系数配置
  267. * User: wsc
  268. * Time: 2021/2/25 16:41
  269. * @return array
  270. */
  271. public function getConfig(){
  272. $cfg =[];
  273. $cfg['spinsLost'] =funs::getArrFromJsonArr(oo::commonOprRedis('config')->hGetAll(okeys::slotCoefficientCfg('spinsLost')));
  274. ksort($cfg['spinsLost']);
  275. $cfg['spinsLostDay'] =funs::getArrFromJsonArr(oo::commonOprRedis('config')->hGetAll(okeys::slotCoefficientCfg('spinsLostDay')));
  276. ksort($cfg['spinsLostDay']);
  277. $cfg['slotLimitDay'] =funs::getArrFromJsonArr(oo::commonOprRedis('config')->hGetAll(okeys::slotCoefficientCfg('slotLimitDay')));
  278. ksort($cfg['slotLimitDay']);
  279. if(!$cfg['spinsLost']){
  280. $cfg['spinsLost'] = $this->defaultSpinsLostCfg;
  281. }
  282. if(!$cfg['spinsLostDay']){
  283. $cfg['spinsLostDay'] = $this->defaultSpinsLostDayCfg;
  284. }
  285. if(!$cfg['slotLimitDay']){
  286. $cfg['slotLimitDay'] = $this->defaultSlotLimitDayCfg;
  287. }
  288. return $cfg;
  289. }
  290. public function getThisSlotWeight($uid,$lv,$bet,$actChildType,$changeType=0,$otherData = []){
  291. $slotWeightCfg = $this->getWeightByLv($lv);
  292. $lastSlotWeight = $slotWeightCfg = array_column($slotWeightCfg,'v','id');
  293. $cfg = $this->getConfig();
  294. $coefCfg_1 = $coefCfg_2 = $coefCfg_3 =[1=>1,2=>1,3=>1,4=>1,5=>1,6=>1,7=>1,8=>1,9=>1,10=>1,11=>1,12=>1,13=>1,14=>1,15=>1,16=>1,17=>1,18=>1,19=>1,20=>1,21=>1,22=>1,23=>1];
  295. $slotResSpinsLost =oo::commonOprRedis('common')->hGetAll(okeys::userSlotResSpinsLost($uid));
  296. // ksort($cfg['slotLimitDay']);
  297. // foreach ($cfg['slotLimitDay'] as $k=>$v){
  298. // if($slotLimitDay<=$k){
  299. // $coefCfg_1 = $v;
  300. // $have_a =1;
  301. // break;
  302. // }
  303. // }
  304. // if(!isset($have_a)){
  305. // $coefCfg_1=end($cfg['slotLimitDay']);
  306. // }
  307. // ksort($cfg['spinsLostDay']);
  308. // if(!isset($have_b)){
  309. // $coefCfg_2=end($cfg['spinsLostDay']);
  310. // }
  311. //老虎机体力返比控制
  312. $returnRate = 1;
  313. // if(!IS_DEBUF)$otherData=[];//wsc-2021.10.09-临时关闭修正 - 2021-10-18 测试环境开启修正
  314. if(!empty($otherData)){
  315. $config = oo::commonOprModel('config')->getConfigByUserGroup($otherData['groupId']);
  316. //[ * 1、累计预设消耗体力 sumExpectSpins, 2、累计预设分数 sumExpectGrade]
  317. $getCollectSumNum = oo::commonOprModel('config')->getCollectSumNum($otherData['aid'], 'all', $otherData['rid'], $otherData['stage'], $otherData['groupId']);
  318. $getCollectActSpins = intval(oo::commonOprRedis('activity')->hGet(okeys::getCollectActSpins($otherData['aid']),$uid));//累计消耗体力
  319. $getCollectActAdd = intval(oo::commonOprRedis('activity')->hGet(okeys::getCollectActAdd($otherData['aid']),$uid));//累计获取
  320. $a = empty($getCollectSumNum['sumExpectSpins']) ? 0 : $getCollectActSpins / $getCollectSumNum['sumExpectSpins'];
  321. $b = empty($getCollectSumNum['sumExpectGrade']) ? 0 : $getCollectActAdd / $getCollectSumNum['sumExpectGrade'];
  322. $getCollectSumNum['currentSpins'] = $getCollectActSpins;
  323. $getCollectSumNum['currentGrade'] = $getCollectActAdd;
  324. $getCollectSumNum['a'] = $a;
  325. $getCollectSumNum['b'] = $b;
  326. $bArr = [];
  327. if(!empty($config['config'] ) && is_array($config['config'])){
  328. krsort($config['config']);
  329. foreach ($config['config'] as $ak => $values){
  330. $bArr = $values;
  331. if($a >= $ak)break;
  332. }
  333. $bMap = [1=>"0", 2=>"0.1", 3=>"0.2", 4=>"0.3", 5=>"0.4", 6=>"0.5", 7=>"0.6", 8=>"0.7", 9=>"0.8", 10=>"0.9", 11=>"1.0"];
  334. $bk = 1;
  335. for($k = 11; $k > 0; $k--){
  336. $v = $bMap[$k];
  337. $bk = $k;
  338. if($b >= $v)break;
  339. }
  340. if(isset($bArr[$bk]))$returnRate = $bArr[$bk];
  341. }
  342. $log = [
  343. 'spinsReturn' => [
  344. 'uid' => $uid,
  345. 'stage' => $otherData['stage'],
  346. 'getGradeExcept' => $getCollectSumNum['sumExpectGrade'],
  347. 'spendSpinsExpect' => $getCollectSumNum['sumExpectSpins'],
  348. 'getGradeTotal' => $getCollectActAdd,
  349. 'spendSpinsTotal' => $getCollectActSpins,
  350. 'A' => $a,
  351. 'B' => $b,
  352. 'modifyRate' => $returnRate,
  353. ]
  354. ];
  355. if(IS_DEBUF && time() < strtotime('2021-10-19'))oo::logs()->debug3($log,'returnRate.log');
  356. #收集活动卡点,触发条件:当前收集层的奖励为体力;当前收集层数大于10;
  357. $reward = oo::commonOprModel('activitynew')->getActReward($otherData['aid']);
  358. $hasSpins = false;
  359. $rid = max(intval($otherData['rid']), 1);
  360. if(!empty($reward['extra_reward']) && $reward['type'] == 'super_collect'){
  361. $stagePrizes = $reward['extra_reward'][$rid]['list'][$otherData['stage']]['prize'] ?? [];
  362. foreach ($stagePrizes as $item){#奖励中是否包含体力
  363. if(!empty($item['type']) && $item['type'] == 15){
  364. $hasSpins = true;
  365. break;
  366. }
  367. }
  368. }
  369. #当前层大于10 且有体力奖励
  370. $freezePointRate = 1;
  371. $freezePointMinStage = intval(oo::commonOprRedis('config')->get(okeys::slotFreezePointMinStage()));
  372. if($otherData['stage'] > $freezePointMinStage && $hasSpins){
  373. #取上一层的累计值
  374. $getCollectSumNumPreStage = oo::commonOprModel('config')->getCollectSumNum($otherData['aid'], 'all', $otherData['rid'], $otherData['stage'] - 1, $otherData['groupId']);
  375. #当前层总分 = 当前层累积预设分数 - 上一层累积预设分数
  376. $currentStageGrade = $getCollectSumNum['sumExpectGrade'] - $getCollectSumNumPreStage['sumExpectGrade'];
  377. #当前层预设体力 = 当前层累积预设体力 - 上一层累积预设体力
  378. $currentStageSpins = $getCollectSumNum['sumExpectSpins'] - $getCollectSumNumPreStage['sumExpectSpins'];
  379. #当前层获得分数 = 当累积获取 - 上层累积预设分数
  380. $currentGrade = $getCollectActAdd - $getCollectSumNumPreStage['sumExpectGrade'];
  381. #收集活动卡点修正
  382. #A =(当前层总分-当前层获得分数)/ 当前层总分
  383. $a = empty($currentStageGrade) ? 0 : ($currentStageGrade - $currentGrade ) / $currentStageGrade;
  384. #B =( 剩余体力 / 当前收集层预设体力
  385. $b = empty($currentStageSpins) ? 0 : $otherData['leftSpins'] / $currentStageSpins;
  386. #根据用户组获取收集卡点配置
  387. $config = oo::commonOprModel('config')->getFreezePointConfigByUserGroup($otherData['groupId']);
  388. if(time() < strtotime('2021-10-14'))oo::logs()->debug3($config,'returnRate.log');
  389. #根据 A、B 获取具体的修正值
  390. if(!empty($config['config'] ) && is_array($config['config'])){
  391. ksort($config['config']);
  392. foreach ($config['config'] as $ak => $values){
  393. $bArr = $values;
  394. if($a <= $ak)break;
  395. }
  396. $bMap = [
  397. 1=>"0",
  398. 2=>"0.1",
  399. 3=>"0.2",
  400. 4=>"0.3",
  401. 5=>"0.4",
  402. 6=>"0.5",
  403. 7=>"0.6",
  404. 8=>"0.7",
  405. 9=>"0.8",
  406. 10=>"0.9",
  407. 11=>"1",
  408. 12=>"1.1",
  409. 13=>"1.2",
  410. 14=>"1.3",
  411. 15=>"1.4",
  412. 16=>"1.5",
  413. ];
  414. $bk = 1;
  415. foreach ($bMap as $k => $v){
  416. $bk = $k;
  417. if($b <= $v)break;
  418. }
  419. #将修正值乘上体力返比修正值
  420. if(isset($bArr[$bk]))$freezePointRate *= $bArr[$bk];
  421. }
  422. }
  423. $returnRate *= $freezePointRate;
  424. $log = [
  425. 'collectFreeze' => [
  426. 'uid' => $uid,
  427. 'minStageCfg' => $freezePointMinStage,
  428. 'currentStage' => $otherData['stage'],
  429. 'minStageCfg' => $freezePointMinStage,
  430. 'hasSpins' => $hasSpins ? 1 : 0,
  431. 'currentStageGradeTotal' => $currentStageGrade,
  432. 'currentStageGrade' => $currentGrade,
  433. 'currentStageSpinsTotal' => $currentStageSpins,
  434. 'leftSpins' => $otherData['leftSpins'],
  435. 'A' => $a,
  436. 'B' => $b,
  437. 'modifyRate' => $freezePointRate,
  438. ]
  439. ];
  440. if(IS_DEBUF && time() < strtotime('2021-10-19'))oo::logs()->debug3($log,'returnRate.log');
  441. }
  442. foreach ($slotResSpinsLost as $key=>$val){
  443. $spins_bet = $val/$bet;
  444. $have=0;
  445. foreach ($cfg['spinsLost'] as $k=>$v){
  446. if($spins_bet<=$k){
  447. $coefCfg_3[$key] = $v[$key];
  448. $have =1;
  449. break;
  450. }
  451. }
  452. if(!$have){//大于所有值时
  453. $coefCfg_3[$key] = end($cfg['spinsLost'])[$key];
  454. }
  455. }
  456. foreach ($this->defaultLostSpinsArr as $k=>$v){
  457. //防止异常-处理
  458. $coefCfg_1[$k]=$coefCfg_1[$k]?$coefCfg_1[$k]:1;
  459. $coefCfg_2[$k]=$coefCfg_2[$k]?$coefCfg_2[$k]:1;
  460. $coefCfg_3[$k]=$coefCfg_3[$k]?$coefCfg_3[$k]:1;
  461. //权重从新计算
  462. $lastSlotWeight[$k] = intval($coefCfg_1[$k]*$coefCfg_2[$k]*$coefCfg_3[$k]*intval($slotWeightCfg[$k]));
  463. }
  464. $slotWeightBf= $lastSlotWeight;
  465. unset($lastSlotWeight[12],$lastSlotWeight[13],$lastSlotWeight[14],$lastSlotWeight[15],$lastSlotWeight[16],$lastSlotWeight[17],$lastSlotWeight[18],$lastSlotWeight[19],$lastSlotWeight[20],$lastSlotWeight[21],$lastSlotWeight[22],$lastSlotWeight[23]);
  466. //收集活动过滤权重
  467. if($actChildType==1){//普通收集
  468. $lastSlotWeight[14] = $slotWeightBf[14] * $returnRate;
  469. }
  470. if($actChildType==2){//特殊收集,特殊收集偷,特殊收集打 (收集物1,2,3)
  471. $lastSlotWeight[12] = $slotWeightBf[12] * $returnRate;
  472. $lastSlotWeight[13] = $slotWeightBf[13] * $returnRate;
  473. $lastSlotWeight[14] = $slotWeightBf[14] * $returnRate;
  474. }
  475. if($actChildType==4){//偷收集
  476. $lastSlotWeight[18] = $slotWeightBf[18] * $returnRate;
  477. $lastSlotWeight[19] = $slotWeightBf[19] * $returnRate;
  478. }
  479. if($actChildType==5){//打收集
  480. $lastSlotWeight[20] = $slotWeightBf[20] * $returnRate;
  481. $lastSlotWeight[21] = $slotWeightBf[21] * $returnRate;
  482. }
  483. switch($changeType){
  484. case 1: //小玩法收集活动
  485. $lastSlotWeight[15] = $slotWeightBf[15];
  486. $lastSlotWeight[16] = $slotWeightBf[16];
  487. $lastSlotWeight[17] = $slotWeightBf[17];
  488. break;
  489. case 2: //体力存钱罐
  490. $lastSlotWeight[22] = $slotWeightBf[22];
  491. $lastSlotWeight[23] = $slotWeightBf[23];
  492. break;
  493. case 3: //小玩法和体力存钱罐同开
  494. $lastSlotWeight[15] = $slotWeightBf[15];
  495. $lastSlotWeight[16] = $slotWeightBf[16];
  496. $lastSlotWeight[17] = $slotWeightBf[17];
  497. $lastSlotWeight[22] = $slotWeightBf[22];
  498. $lastSlotWeight[23] = $slotWeightBf[23];
  499. break;
  500. }
  501. //收集活动体力返比
  502. if($returnRate != 1){
  503. if($otherData['actGroupId'] == 1 || $otherData['actGroupId'] == 7){
  504. $lastSlotWeight[1] *= $returnRate;//打
  505. $lastSlotWeight[2] *= $returnRate;//偷
  506. }else if($otherData['actGroupId'] == 3 || $otherData['actGroupId'] == 5 || $otherData['actGroupId'] == 8){
  507. $lastSlotWeight[2] *= $returnRate;//偷
  508. }else if($otherData['actGroupId'] == 4 || $otherData['actGroupId'] == 6 || $otherData['actGroupId'] == 9){
  509. $lastSlotWeight[1] *= $returnRate;//打
  510. }
  511. }
  512. return $lastSlotWeight;
  513. }
  514. public function getSlotResult($uid,$lv,$bet,$actChildType,$change=0,$n=0,$otherData = []){
  515. if($n){
  516. $ret['rid'] =$n;
  517. }else{
  518. $weight = $this->getThisSlotWeight($uid,$lv,$bet,$actChildType,$change,$otherData);
  519. $ret['rid'] = funs::get_randByProb($weight);
  520. }
  521. $slotWeightCfg = $this->getWeightByLv($lv);
  522. $lastSlotWeight = array_column($slotWeightCfg,null,'id');
  523. $ret['type'] = (int)$lastSlotWeight[$ret['rid']]['type'];
  524. $ret['prize'] = $lastSlotWeight[$ret['rid']];
  525. return $ret;
  526. }
  527. }