123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <?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);
- }
- }
- else {
- Log::record("order_sn=$order_sn empty",Log::DEBUG);
- }
- }
- }
- private function getOrders()
- {
- return [
- '7749990739497208755104',
- '4241640739497214477247',
- '3409590739497235409931',
- '3441260739497239066452',
- '1434360739497573663949',
- '3359180739497588027168',
- '33841685199232623212',
- '28471685199597405220',
- '57171685202698387113',
- '89491685204072019563',
- '54821685230140381770',
- '94021685232830341599',
- '3141710739497207880429',
- '1343340739497214781295',
- '5905900739497214862174',
- '1955480739497240001384',
- '2344270739497387804732',
- '5649180739497388386881',
- '7799780739497388683087',
- '9389810739497404696612',
- '6035530739497543907708',
- '2069310739497546200263',
- '2986790739497573078875',
- '2996950739497573184793',
- '5746870739323892570502',
- '7776210739324342537968',
- '1651790739324578300572',
- '2089700739324697035601',
- '1046530739324701858673',
- '3588350739324790951598',
- '02031910738486333430245',
- '42041685144164497475',
- '13731685144277889026',
- '89841685144485116642',
- '86911685176628006840',
- '75071685198614860230',
- '75811685201242132173',
- '55051685203269595963',
- '19821685205286104990',
- '9704550739323836502970',
- '8853970739324578150798',
- '8266910739324696844607',
- '1909980739324696852263',
- '4242700739497207277597',
- '7315300739497207416673',
- '6027840739497213695911',
- '6664270739497214380016',
- '3697580739497224283328',
- '1527960739497224461069',
- '5845540739497224677983',
- '9158010739497239807777',
- '0725700739497405115820',
- '5647410739497407395639',
- '8484290739497572819121',
- '7522330739497578980959',
- '3148900739497588515397',
- '44641685144571093667',
- '11331685200447945941',
- '83701685230393513621',
- '0999230739324323447175',
- '2099360739324342437099',
- '1345740739324456585903',
- '3436600739324517966370',
- '7931230739324697254624',
- '8439720739324795372416'
- ];
- }
- public function testOneOrder()
- {
- $provider = $this->getProvider('by_online');
- $params = [
- '8013920739815620475078' => '1123061172453041',
- '0375610739886119616188' => '1123061272466229',
- ];
- foreach ($params as $order_sn => $official_sn)
- {
- [$succ, $resp] = $provider->query(['order_sn' => $order_sn, 'official_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)
- {
- Log::record("order_sn={$item['order_sn']}", Log::DEBUG);
- $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-01')], ['lt', strtotime('2023-06-09')], 'and'];
- $cond['vr_order.add_time'] = [['egt', strtotime('2023-06-01')], ['lt', strtotime('2023-06-09')], 'and'];
- $cond['inner_status'] = 0;
- $cond['vr_order.order_state'] = 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);
- }
- }
|