bonus_helperTest.php 4.8 KB

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