123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- use PHPUnit\Framework\TestCase;
- define('APP_ID', 'balance');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_HELPER_PATH . '/statistics/refill_balance.php');
- class TestRefillBalance extends TestCase
- {
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testStartWith()
- {
- $start_with = function ($haystack, $needle) {
- $length = strlen($needle);
- return (substr($haystack, 0, $length) === $needle);
- };
- $x = $start_with('SP2022061805243705987437332339','SP');
- }
- public function testAddBalance()
- {
- Log::short_name('testAddBalance');
- Log::record("xxx",Log::DEBUG);
- $refill_balance = new statistics\refill_balance();
- $refill_balance->add_balance('system', 0, 0, strtotime('2021-12-01'), 'order_time');
- }
- //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
- public function testInitBalance()
- {
- $refill_balance = new statistics\refill_balance();
- $refill_balance->stat_all(strtotime('2022-05-24'));
- }
- public function testFirstDay()
- {
- $refill_time = function ($type, $cid, $start)
- {
- if ($start != 0) {
- return $start;
- }
- if ($type == 'system') {
- $mod_refill = Model('refill_order');
- $item = $mod_refill->table('refill_order')->field('order_id,order_time')->order('order_id asc')->find();
- } elseif ($type == 'merchant') {
- $mod_refill = Model('refill_order');
- $item = $mod_refill->table('refill_order')->field('order_id,order_time')->where(['mchid' => $cid])->order('order_id asc')->find();
- } else {
- $mod_refill = Model('vr_order');
- $item = $mod_refill->table('vr_order')->field('order_id,add_time')->where(['store_id' => $cid])->order('order_id asc')->find();
- }
- $time = $item['order_time'] ?? 0;
- return $time;
- };
- $order_start = $refill_time('system', 0, 0);
- $order_start = $refill_time('merchant', 1092, 0);
- $order_start = $refill_time('provider', 49, 0);
- }
- public function testMerchantPaytime()
- {
- $refill_time = function ($type, $cid, $start)
- {
- if ($start != 0) {
- return $start;
- }
- $mod_pay = Model();
- if ($type == 'system')
- {
- $item = $mod_pay->table('refill_evidence')
- ->field('min(add_time) as add_time')
- ->find();
- } elseif ($type == 'merchant') {
- $item = $mod_pay->table('refill_evidence')
- ->field('min(add_time) as add_time')
- ->where(['mchid' => $cid])
- ->find();
- }
- $time = $item['add_time'] ?? time();
- Log::record(date('Y-m-d', $time),Log::DEBUG);
- return $time;
- };
- $order_start = $refill_time('system', 0, 0);
- $order_start = $refill_time('merchant', 1092, 0);
- }
- public function testProviderPaytime()
- {
- $refill_time = function ($type, $cid, $start)
- {
- if ($start != 0) {
- return $start;
- }
- $mod_pay = Model();
- if ($type == 'system')
- {
- $item = $mod_pay->table('provider_amount')
- ->field('min(add_time) as add_time')
- ->find();
- } elseif ($type == 'merchant') {
- $item = $mod_pay->table('provider_amount')
- ->field('min(add_time) as add_time')
- ->where(['provider_id' => $cid])
- ->find();
- }
- $time = $item['add_time'] ?? time();
- Log::record(date('Y-m-d', $time),Log::DEBUG);
- return $time;
- };
- $order_start = $refill_time('system', 0, 0);
- $order_start = $refill_time('provider', 49, 0);
- }
- public function testBalanceConfig()
- {
- $x = wcache('balance-cfg', ['a' => 1,'b' => 2], 'refill-');
- $y = rcache('balance-cfg','refill-','a,b');
- $x = wcache('balance-cfg', ['adc' => serialize(['a' => 1,'b' => 2])], 'refill-');
- $y = rcache('balance-cfg','refill-','adc');
- $z = unserialize($y) ?? [];
- }
- }
|