123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2016/10/11
- * Time: 下午8:56
- */
- use PHPUnit\Framework\TestCase;
- define('APP_ID', 'test');
- 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_ROOT_PATH . '/helper/order_helper.php');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_CORE_PATH . '/framework/function/http.php');
- require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
- class TestRefund extends TestCase
- {
- public static function setUpBeforeClass() : void
- {
- Base::run_util();
- }
- public function testRefundOrder()
- {
- $helper = new refund_helper(36490);
- $helper->refund('8000000000638201',$err);
- }
- public function testOrderHelper()
- {
- $helper = new refund_helper(36490);
- $helper->refund('8000000000638201',$err);
- }
- public function testReturnInfo()
- {
- $helper = new refund_helper(36490);
- $helper->return_info('8000000000651001',10100,$err);
- }
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefund::testByOnline)( .*)?$/" --test-suffix TestRefund.php /var/www/html/test
- public function testByOnline()
- {
- $getProvider = function ($name, $type = 'RefillPhone')
- {
- $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
- if (!file_exists($file)) {
- Log::record("provider api file=$file not exist.", Log::DEBUG);
- return false;
- } else {
- require_once($file);
- Log::record("file={$file} load success.", Log::DEBUG);
- }
- $class_name = "refill\\{$name}\\{$type}";
- if (class_exists($class_name, false)) {
- $caller = new $class_name([]);
- return $caller;
- }
- else {
- $error = "Base Error: class {$class_name} isn't exists!";
- Log::record($error, Log::ERR);
- return false;
- }
- };
- $snmaker = function ()
- {
- return mt_rand(1000, 9999)
- . sprintf('%010d', time())
- . sprintf('%06d', (float)microtime() * 1000000);
- };
- $provider = $getProvider('by_online');
- $order_sn = $snmaker();
- Log::record("order_sn=$order_sn",Log::DEBUG);
- $file = fopen(BASE_DATA_PATH . "/log/{$order_sn}.log",'a+');
- // [$succ_add, $msg, $nerr] = $provider->add(18810246909, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
- [$succ_add, $msg, $nerr] = $provider->add(13911129867, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
- // [$succ_add, $msg, $nerr] = $provider->add(13925782928, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
- // [$succ_add, $msg, $nerr] = $provider->add(15120035568, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
- // [$succ_add, $msg, $nerr] = $provider->add(17801048874, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
- // [$succ_add, $msg, $nerr] = $provider->add(15951343795, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
- // [$succ_add, $msg, $nerr] = $provider->add(15064807655, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
- $last_tag = '';
- $count = 0;
- $commit_time = time();
- while ($succ_add)
- {
- [$succ,$resp] = $provider->query(['order_sn' => $order_sn,'official_sn' => $nerr,'commit_time' => $commit_time]);
- if($succ)
- {
- $tag = md5($resp);
- if($tag != $last_tag) {
- fwrite($file,"md5=$tag\r\n");
- fwrite($file,$resp);
- fwrite($file,"\r\n");
- fflush($file);
- $last_tag = $tag;
- } else {
- fwrite($file,"count=$count\r\n");
- fflush($file);
- $count += 1;
- }
- }
- sleep(1);
- }
- fclose($file);
- }
- private function getProvider($name, $type = 'RefillPhone')
- {
- $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
- if (!file_exists($file)) {
- Log::record("provider api file=$file not exist.", Log::DEBUG);
- return false;
- } else {
- require_once($file);
- Log::record("file={$file} load success.", Log::DEBUG);
- }
- $class_name = "refill\\{$name}\\{$type}";
- if (class_exists($class_name, false)) {
- $caller = new $class_name([]);
- return $caller;
- }
- else {
- $error = "Base Error: class {$class_name} isn't exists!";
- Log::record($error, Log::ERR);
- return false;
- }
- }
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefund::testByQuery)( .*)?$/" --test-suffix TestRefund.php /var/www/html/test
- public function testByQuery()
- {
- $orders = $this->getOrders();
- $mod_refill = Model('refill_order');
- foreach ($orders as $order_sn)
- {
- $refill_info = $mod_refill->getOrderInfo(['order_sn' => $order_sn]);
- if(!empty($refill_info)) {
- $chname = $refill_info['channel_name'];
- $provider = $this->getProvider($chname);
- [$status, $order_state, $charge_id] = $provider->query($refill_info);
- if($status) {
- Log::record("order_sn=$order_sn order_state=$order_state",Log::DEBUG);
- }
- else {
- Log::record("order_sn=$order_sn msg=$order_state",Log::DEBUG);
- }
- }
- }
- }
- private function getOrders()
- {
- return [
- '0054340738786801278285',
- '0072270738754986062471',
- '0073520738759742703583',
- '0075580738780047989128',
- '0079860738751884483673',
- '0222330738757938391994',
- '0224810738762683686978',
- '0229430738760052407447',
- '0051880738756076094755',
- '0274810738781583681751',
- '0347700738779630513391',
- ];
- }
- public function testOneOrder()
- {
- $provider = $this->getProvider('by_online');
- $order_sn = '5744450737576478180405';
- [$succ, $resp] = $provider->query(['order_sn' => $order_sn, 'official_sn' => '']);
- }
- private function check_order($cond)
- {
- $fsucc = fopen(BASE_DATA_PATH . "/log/succ.log",'a+');
- $fcancel = fopen(BASE_DATA_PATH . "/log/cancel.log",'a+');
- $ferr = fopen(BASE_DATA_PATH . "/log/nerr.log",'a+');
- fwrite($fsucc,"移动成功,我们系统失败\r\n");
- fwrite($fcancel,"移动失败,我们系统成功\r\n");
- fwrite($ferr,"网络错误,系统请求失败\r\n");
- $reader = new statistics\order_reader();
- $gen = $reader->refill_vr_reader($cond);
- $count = 0;
- foreach ($gen as $item)
- {
- $count += 1;
- $chname = $item['channel_name'];
- $provider = $this->getProvider($chname);
- [$status, $order_state, $charge_id] = $provider->query($item);
- if($status)
- {
- $db_state = intval($item['order_state']);
- if($order_state !== $db_state)
- {
- if($order_state == ORDER_STATE_SUCCESS) {
- fwrite($fsucc,"{$item['order_sn']} {$order_state} {$db_state}\r\n");
- }
- else {
- fwrite($fcancel,"{$item['order_sn']} {$order_state} {$db_state}\r\n");
- }
- }
- }
- else
- {
- fwrite($ferr,"{$item['order_sn']}\r\n");
- }
- }
- Log::record("all item is $count",Log::DEBUG);
-
- fclose($fsucc);
- fclose($fcancel);
- fclose($ferr);
- }
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefund::testCheckZY)( .*)?$/" --test-suffix TestRefund.php /var/www/html/test
- public function testCheckZY()
- {
- $cond['refill_order.order_time'] = [['egt', strtotime('2023-06-06')], ['lt', strtotime('2023-06-07')], 'and'];
- $cond['vr_order.add_time'] = [['egt', strtotime('2023-06-06')], ['lt', strtotime('2023-06-08')], 'and'];
- $cond['inner_status'] = 0;
- $cond['vr_order.store_id'] = ['in',[33,45]];
- $this->check_order($cond);
- }
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefund::testCheckYZ)( .*)?$/" --test-suffix TestRefund.php /var/www/html/test
- public function testCheckYZ()
- {
- $cond['refill_order.order_time'] = [['egt', strtotime('2023-05-01')], ['lt', strtotime('2023-06-01')], 'and'];
- $cond['vr_order.add_time'] = [['egt', strtotime('2023-05-01')], ['lt', strtotime('2023-06-02')], 'and'];
- $cond['inner_status'] = 0;
- $cond['vr_order.store_id'] = ['in',[319,327]];
- $this->check_order($cond);
- }
- }
|