TestRefillBalance.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 testAddBalance()
  16. {
  17. Log::short_name('testAddBalance');
  18. Log::record("xxx",Log::DEBUG);
  19. $refill_balance = new statistics\refill_balance();
  20. $refill_balance->add_balance('system', 0, 0, strtotime('2021-12-01'), 'order_time');
  21. }
  22. //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
  23. public function testInitBalance()
  24. {
  25. $refill_balance = new statistics\refill_balance();
  26. $refill_balance->stat_all(strtotime('2022-05-24'));
  27. }
  28. public function testFirstDay()
  29. {
  30. $refill_time = function ($type, $cid, $start)
  31. {
  32. if ($start != 0) {
  33. return $start;
  34. }
  35. if ($type == 'system') {
  36. $mod_refill = Model('refill_order');
  37. $item = $mod_refill->table('refill_order')->field('order_id,order_time')->order('order_id asc')->find();
  38. } elseif ($type == 'merchant') {
  39. $mod_refill = Model('refill_order');
  40. $item = $mod_refill->table('refill_order')->field('order_id,order_time')->where(['mchid' => $cid])->order('order_id asc')->find();
  41. } else {
  42. $mod_refill = Model('vr_order');
  43. $item = $mod_refill->table('vr_order')->field('order_id,add_time')->where(['store_id' => $cid])->order('order_id asc')->find();
  44. }
  45. $time = $item['order_time'] ?? 0;
  46. return $time;
  47. };
  48. $order_start = $refill_time('system', 0, 0);
  49. $order_start = $refill_time('merchant', 1092, 0);
  50. $order_start = $refill_time('provider', 49, 0);
  51. }
  52. public function testMerchantPaytime()
  53. {
  54. $refill_time = function ($type, $cid, $start)
  55. {
  56. if ($start != 0) {
  57. return $start;
  58. }
  59. $mod_pay = Model();
  60. if ($type == 'system')
  61. {
  62. $item = $mod_pay->table('refill_evidence')
  63. ->field('min(add_time) as add_time')
  64. ->find();
  65. } elseif ($type == 'merchant') {
  66. $item = $mod_pay->table('refill_evidence')
  67. ->field('min(add_time) as add_time')
  68. ->where(['mchid' => $cid])
  69. ->find();
  70. }
  71. $time = $item['add_time'] ?? time();
  72. Log::record(date('Y-m-d', $time),Log::DEBUG);
  73. return $time;
  74. };
  75. $order_start = $refill_time('system', 0, 0);
  76. $order_start = $refill_time('merchant', 1092, 0);
  77. }
  78. public function testProviderPaytime()
  79. {
  80. $refill_time = function ($type, $cid, $start)
  81. {
  82. if ($start != 0) {
  83. return $start;
  84. }
  85. $mod_pay = Model();
  86. if ($type == 'system')
  87. {
  88. $item = $mod_pay->table('provider_amount')
  89. ->field('min(add_time) as add_time')
  90. ->find();
  91. } elseif ($type == 'merchant') {
  92. $item = $mod_pay->table('provider_amount')
  93. ->field('min(add_time) as add_time')
  94. ->where(['provider_id' => $cid])
  95. ->find();
  96. }
  97. $time = $item['add_time'] ?? time();
  98. Log::record(date('Y-m-d', $time),Log::DEBUG);
  99. return $time;
  100. };
  101. $order_start = $refill_time('system', 0, 0);
  102. $order_start = $refill_time('provider', 49, 0);
  103. }
  104. public function testBalanceConfig()
  105. {
  106. $x = wcache('balance-cfg', ['a' => 1,'b' => 2], 'refill-');
  107. $y = rcache('balance-cfg','refill-','a,b');
  108. $x = wcache('balance-cfg', ['adc' => serialize(['a' => 1,'b' => 2])], 'refill-');
  109. $y = rcache('balance-cfg','refill-','adc');
  110. $z = unserialize($y) ?? [];
  111. }
  112. }