TestRefillBalance.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'balance');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. require_once(BASE_ROOT_PATH . '/global.php');
  6. require_once(BASE_CORE_PATH . '/lrlz.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. require_once(BASE_HELPER_PATH . '/statistics/refill_balance.php');
  9. class TestRefillBalance extends TestCase
  10. {
  11. public static function setUpBeforeClass(): void
  12. {
  13. Base::run_util();
  14. }
  15. public function testStartWith()
  16. {
  17. $start_with = function ($haystack, $needle) {
  18. $length = strlen($needle);
  19. return (substr($haystack, 0, $length) === $needle);
  20. };
  21. $x = $start_with('SP2022061805243705987437332339','SP');
  22. }
  23. public function testAddBalance()
  24. {
  25. Log::short_name('testAddBalance');
  26. Log::record("xxx",Log::DEBUG);
  27. $refill_balance = new statistics\refill_balance();
  28. $refill_balance->add_balance('system', 0, 0, strtotime('2021-12-01'), 'order_time');
  29. }
  30. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillBalance::testInitBalance)( .*)?$/" --test-suffix TestRefillBalance.php /var/www/html/test
  31. public function testInitBalance()
  32. {
  33. $refill_balance = new statistics\refill_balance();
  34. $refill_balance->stat_all(strtotime('2022-05-24'));
  35. }
  36. public function testFirstDay()
  37. {
  38. $refill_time = function ($type, $cid, $start)
  39. {
  40. if ($start != 0) {
  41. return $start;
  42. }
  43. if ($type == 'system') {
  44. $mod_refill = Model('refill_order');
  45. $item = $mod_refill->table('refill_order')->field('order_id,order_time')->order('order_id asc')->find();
  46. } elseif ($type == 'merchant') {
  47. $mod_refill = Model('refill_order');
  48. $item = $mod_refill->table('refill_order')->field('order_id,order_time')->where(['mchid' => $cid])->order('order_id asc')->find();
  49. } else {
  50. $mod_refill = Model('vr_order');
  51. $item = $mod_refill->table('vr_order')->field('order_id,add_time')->where(['store_id' => $cid])->order('order_id asc')->find();
  52. }
  53. $time = $item['order_time'] ?? 0;
  54. return $time;
  55. };
  56. $order_start = $refill_time('system', 0, 0);
  57. $order_start = $refill_time('merchant', 1092, 0);
  58. $order_start = $refill_time('provider', 49, 0);
  59. }
  60. public function testMerchantPaytime()
  61. {
  62. $refill_time = function ($type, $cid, $start)
  63. {
  64. if ($start != 0) {
  65. return $start;
  66. }
  67. $mod_pay = Model();
  68. if ($type == 'system')
  69. {
  70. $item = $mod_pay->table('refill_evidence')
  71. ->field('min(add_time) as add_time')
  72. ->find();
  73. } elseif ($type == 'merchant') {
  74. $item = $mod_pay->table('refill_evidence')
  75. ->field('min(add_time) as add_time')
  76. ->where(['mchid' => $cid])
  77. ->find();
  78. }
  79. $time = $item['add_time'] ?? time();
  80. Log::record(date('Y-m-d', $time),Log::DEBUG);
  81. return $time;
  82. };
  83. $order_start = $refill_time('system', 0, 0);
  84. $order_start = $refill_time('merchant', 1092, 0);
  85. }
  86. public function testProviderPaytime()
  87. {
  88. $refill_time = function ($type, $cid, $start)
  89. {
  90. if ($start != 0) {
  91. return $start;
  92. }
  93. $mod_pay = Model();
  94. if ($type == 'system')
  95. {
  96. $item = $mod_pay->table('provider_amount')
  97. ->field('min(add_time) as add_time')
  98. ->find();
  99. } elseif ($type == 'merchant') {
  100. $item = $mod_pay->table('provider_amount')
  101. ->field('min(add_time) as add_time')
  102. ->where(['provider_id' => $cid])
  103. ->find();
  104. }
  105. $time = $item['add_time'] ?? time();
  106. Log::record(date('Y-m-d', $time),Log::DEBUG);
  107. return $time;
  108. };
  109. $order_start = $refill_time('system', 0, 0);
  110. $order_start = $refill_time('provider', 49, 0);
  111. }
  112. public function testBalanceConfig()
  113. {
  114. $x = wcache('balance-cfg', ['a' => 1,'b' => 2], 'refill-');
  115. $y = rcache('balance-cfg','refill-','a,b');
  116. $x = wcache('balance-cfg', ['adc' => serialize(['a' => 1,'b' => 2])], 'refill-');
  117. $y = rcache('balance-cfg','refill-','adc');
  118. $z = unserialize($y) ?? [];
  119. }
  120. }