bonus_helperTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/6/21
  6. * Time: 下午8:28
  7. */
  8. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  9. require_once(BASE_ROOT_PATH . '/fooder.php');
  10. require_once(BASE_ROOT_PATH . '/helper/bonus_helper.php');
  11. require_once(BASE_ROOT_PATH . '/helper/bonus/witholder.php');
  12. require_once(BASE_ROOT_PATH . '/helper/notify_helper.php');
  13. class bonus_helperTest extends PHPUnit_Framework_TestCase
  14. {
  15. public static function setUpBeforeClass()
  16. {
  17. Base::run_util();
  18. }
  19. public function testScaler()
  20. {
  21. //$scaler = new \bonus\scaler([10 => 10,100 => 100,50 => 50, 30 => 30]);
  22. //$scaler = new \bonus\scaler([10 => 10,50 => 50, 20 => 60,100 => 100]);
  23. $scaler = new \bonus\scaler([30 => 0.62,100 => 1.26]);
  24. $ret = $scaler->calc();
  25. }
  26. public function testModel()
  27. {
  28. $item = Model('user_bonus')->field('*')->where(array('type_id' => 105,'bonus_id' => 2491))->select();
  29. bonus_helper::shake($item[0]['type_id'],$item[0]['bonus_id'],$item[0]['bonus_value'],3,bonus_helper::direct_dec());
  30. }
  31. public function testMemBonus()
  32. {
  33. $x = false;
  34. if($x) {
  35. $user_bonus = 0;
  36. }
  37. $bonus_val = $user_bonus->bonus_value();
  38. $mem_bonus = new \bonus\witholder(36490);
  39. $mem_bonus->withold(7.30);
  40. }
  41. public function testExpire()
  42. {
  43. notify_helper::bonus_expired();
  44. }
  45. public function testPush()
  46. {
  47. $url = 'http://a.lrlz.com/mobile/index.php?act=rank_list&op=index&client_type=wap&list_sn=%3Cddc6ff0cd400941d3ae0f8b0889d54a1%3E&from=timeline&isappinstalled=0';
  48. $url = urldecode($url);
  49. }
  50. public function testTime()
  51. {
  52. $send_date = new DateTime();
  53. $send_date->setTimestamp(1478313092);
  54. $usable_date = new DateTime();
  55. $usable_date->setTimestamp(1480905244);
  56. }
  57. public function testReset()
  58. {
  59. $mod_member = Model('member');
  60. $items = $mod_member->field('available_predeposit,available_bonus,member_id')->where(array('member_id' => array('gt',0)))->limit(false)->select();
  61. foreach($items as $item)
  62. {
  63. $bonus = [];
  64. $bonus[30] = intval(doubleval($item['available_predeposit']) * 100 + 0.5) / 100;
  65. $strbonus = serialize($bonus);
  66. $member_id = intval($item['member_id']);
  67. $ret = Model()->table('member')->where(array('member_id' => $member_id))->update(array('available_bonus' => $strbonus));
  68. if($ret == false) {
  69. $ret = true;
  70. }
  71. }
  72. }
  73. public function testKeysort()
  74. {
  75. $x = RESOURCE_SITE_URL;
  76. $data = array(10 => 3018.25,90 => 5623,30 => 5566);
  77. ksort($data);
  78. $xdata = $data;
  79. krsort($data);
  80. //arsort($data);
  81. // $xxxx = array_reverse($xdata,true);
  82. $xxxx = [];
  83. foreach ($data as $key => $val) {
  84. $xxxx[$key] = $val;
  85. }
  86. }
  87. public function testRegex()
  88. {
  89. $src = '30|1980|165#60|10|20#50|10|5';
  90. $params = explode('#', urldecode($src));
  91. $result = [];
  92. foreach ($params as $val)
  93. {
  94. if(preg_match_all('/^(\d{1,2})\|(\d{1,4})\|(\d{1,6})$/', $val, $match)) {
  95. $item['rate'] = intval($match[1]);
  96. $item['amount'] = intval($match[2]);
  97. $item['num'] = intval($match[3]);
  98. $result[] = $item;
  99. }
  100. }
  101. //$regxp = '/([0-9^|#]*|[0-9^|#]*|[0-9^|#]*)[#]?/i';
  102. // $regxp = '/(([0-9]*){3}[#]?/i';
  103. $regxp = '/(([0-9]*)|([0-9]*)|([0-9]*)[^#]){1}[#]?/i';
  104. $val = preg_match_all($regxp,$src,$match);
  105. }
  106. public function testMicro()
  107. {
  108. microtime();
  109. }
  110. public function testRefundBonus()
  111. {
  112. account_helper::bonus_refund('700532450973112490',36490);
  113. }
  114. public function testBonusShare()
  115. {
  116. $mod_share = Model('bonus_share');
  117. $items = $mod_share->getAll();
  118. }
  119. // private function make_sn($count)
  120. // {
  121. // return mt_rand(10000,99999)
  122. // . sprintf('%04d',(time() - 946656000)/1000000)
  123. // . sprintf('%06d', (float) microtime() * 1000000)
  124. // . sprintf('%03d', $count++);
  125. // }
  126. private function make_sn()
  127. {
  128. return mt_rand(10,99)
  129. . sprintf('%010d',time())
  130. . sprintf('%06d', (float) microtime() * 1000000);
  131. }
  132. public function testMakeSn()
  133. {
  134. // $t = (float) microtime();
  135. // $x = sprintf('%03d', (float) microtime() * 1000);
  136. $sns = [];
  137. for ($index = 0; $index < 100000; $index++) {
  138. $sns[] = $this->make_sn();
  139. }
  140. $sns = array_unique($sns);
  141. $count = count($sns);
  142. // $txxx = [];
  143. // for ($index = 0; $index < 1000; $index++) {
  144. // $x1 = (float) microtime();
  145. // $txxx[] = intval($x1 * 1000000);
  146. // }
  147. // $txxx = array_unique($txxx);
  148. // $XYYY = count($txxx);
  149. }
  150. public function testAndroidUrl()
  151. {
  152. $url = BASE_SITE_URL . '/data/upload/package/xmmz_release.apk';
  153. echo $url;
  154. }
  155. public static function tearDownAfterClass()
  156. {
  157. }
  158. }