TestRefund.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2016/10/11
  6. * Time: 下午8:56
  7. */
  8. use PHPUnit\Framework\TestCase;
  9. define('APP_ID', 'test');
  10. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  11. require_once(BASE_ROOT_PATH . '/global.php');
  12. require_once(BASE_CORE_PATH . '/lrlz.php');
  13. require_once(BASE_ROOT_PATH . '/fooder.php');
  14. require_once(BASE_ROOT_PATH . '/helper/order_helper.php');
  15. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  16. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  17. require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
  18. class TestRefund extends TestCase
  19. {
  20. public static function setUpBeforeClass() : void
  21. {
  22. Base::run_util();
  23. }
  24. public function testRefundOrder()
  25. {
  26. $helper = new refund_helper(36490);
  27. $helper->refund('8000000000638201',$err);
  28. }
  29. public function testOrderHelper()
  30. {
  31. $helper = new refund_helper(36490);
  32. $helper->refund('8000000000638201',$err);
  33. }
  34. public function testReturnInfo()
  35. {
  36. $helper = new refund_helper(36490);
  37. $helper->return_info('8000000000651001',10100,$err);
  38. }
  39. //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
  40. public function testByOnline()
  41. {
  42. $getProvider = function ($name, $type = 'RefillPhone')
  43. {
  44. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  45. if (!file_exists($file)) {
  46. Log::record("provider api file=$file not exist.", Log::DEBUG);
  47. return false;
  48. } else {
  49. require_once($file);
  50. Log::record("file={$file} load success.", Log::DEBUG);
  51. }
  52. $class_name = "refill\\{$name}\\{$type}";
  53. if (class_exists($class_name, false)) {
  54. $caller = new $class_name([]);
  55. return $caller;
  56. }
  57. else {
  58. $error = "Base Error: class {$class_name} isn't exists!";
  59. Log::record($error, Log::ERR);
  60. return false;
  61. }
  62. };
  63. $snmaker = function ()
  64. {
  65. return mt_rand(1000, 9999)
  66. . sprintf('%010d', time())
  67. . sprintf('%06d', (float)microtime() * 1000000);
  68. };
  69. $provider = $getProvider('by_online');
  70. $order_sn = $snmaker();
  71. Log::record("order_sn=$order_sn",Log::DEBUG);
  72. $file = fopen(BASE_DATA_PATH . "/log/{$order_sn}.log",'a+');
  73. // [$succ_add, $msg, $nerr] = $provider->add(18810246909, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
  74. [$succ_add, $msg, $nerr] = $provider->add(13911129867, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
  75. // [$succ_add, $msg, $nerr] = $provider->add(13925782928, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
  76. // [$succ_add, $msg, $nerr] = $provider->add(15120035568, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
  77. // [$succ_add, $msg, $nerr] = $provider->add(17801048874, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
  78. // [$succ_add, $msg, $nerr] = $provider->add(15951343795, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
  79. // [$succ_add, $msg, $nerr] = $provider->add(15064807655, 4, 1, ['regin_no' => 1, 'order_sn' => $order_sn]);
  80. $last_tag = '';
  81. $count = 0;
  82. $commit_time = time();
  83. while ($succ_add)
  84. {
  85. [$succ,$resp] = $provider->query(['order_sn' => $order_sn,'official_sn' => $nerr,'commit_time' => $commit_time]);
  86. if($succ)
  87. {
  88. $tag = md5($resp);
  89. if($tag != $last_tag) {
  90. fwrite($file,"md5=$tag\r\n");
  91. fwrite($file,$resp);
  92. fwrite($file,"\r\n");
  93. fflush($file);
  94. $last_tag = $tag;
  95. } else {
  96. fwrite($file,"count=$count\r\n");
  97. fflush($file);
  98. $count += 1;
  99. }
  100. }
  101. sleep(1);
  102. }
  103. fclose($file);
  104. }
  105. private function getProvider($name, $type = 'RefillPhone')
  106. {
  107. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  108. if (!file_exists($file)) {
  109. Log::record("provider api file=$file not exist.", Log::DEBUG);
  110. return false;
  111. } else {
  112. require_once($file);
  113. Log::record("file={$file} load success.", Log::DEBUG);
  114. }
  115. $class_name = "refill\\{$name}\\{$type}";
  116. if (class_exists($class_name, false)) {
  117. $caller = new $class_name([]);
  118. return $caller;
  119. }
  120. else {
  121. $error = "Base Error: class {$class_name} isn't exists!";
  122. Log::record($error, Log::ERR);
  123. return false;
  124. }
  125. }
  126. //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
  127. public function testByQuery()
  128. {
  129. $orders = $this->getOrders();
  130. $mod_refill = Model('refill_order');
  131. foreach ($orders as $order_sn)
  132. {
  133. $refill_info = $mod_refill->getOrderInfo(['order_sn' => $order_sn]);
  134. if(!empty($refill_info))
  135. {
  136. $chname = $refill_info['channel_name'];
  137. $provider = $this->getProvider($chname);
  138. [$status, $order_state, $charge_id] = $provider->query($refill_info);
  139. if($status) {
  140. Log::record("order_sn=$order_sn order_state=$order_state",Log::DEBUG);
  141. }
  142. else {
  143. Log::record("order_sn=$order_sn msg=$order_state",Log::DEBUG);
  144. }
  145. }
  146. else {
  147. Log::record("order_sn=$order_sn empty",Log::DEBUG);
  148. }
  149. }
  150. }
  151. private function getOrders()
  152. {
  153. return [
  154. '7749990739497208755104',
  155. '4241640739497214477247',
  156. '3409590739497235409931',
  157. '3441260739497239066452',
  158. '1434360739497573663949',
  159. '3359180739497588027168',
  160. '33841685199232623212',
  161. '28471685199597405220',
  162. '57171685202698387113',
  163. '89491685204072019563',
  164. '54821685230140381770',
  165. '94021685232830341599',
  166. '3141710739497207880429',
  167. '1343340739497214781295',
  168. '5905900739497214862174',
  169. '1955480739497240001384',
  170. '2344270739497387804732',
  171. '5649180739497388386881',
  172. '7799780739497388683087',
  173. '9389810739497404696612',
  174. '6035530739497543907708',
  175. '2069310739497546200263',
  176. '2986790739497573078875',
  177. '2996950739497573184793',
  178. '5746870739323892570502',
  179. '7776210739324342537968',
  180. '1651790739324578300572',
  181. '2089700739324697035601',
  182. '1046530739324701858673',
  183. '3588350739324790951598',
  184. '02031910738486333430245',
  185. '42041685144164497475',
  186. '13731685144277889026',
  187. '89841685144485116642',
  188. '86911685176628006840',
  189. '75071685198614860230',
  190. '75811685201242132173',
  191. '55051685203269595963',
  192. '19821685205286104990',
  193. '9704550739323836502970',
  194. '8853970739324578150798',
  195. '8266910739324696844607',
  196. '1909980739324696852263',
  197. '4242700739497207277597',
  198. '7315300739497207416673',
  199. '6027840739497213695911',
  200. '6664270739497214380016',
  201. '3697580739497224283328',
  202. '1527960739497224461069',
  203. '5845540739497224677983',
  204. '9158010739497239807777',
  205. '0725700739497405115820',
  206. '5647410739497407395639',
  207. '8484290739497572819121',
  208. '7522330739497578980959',
  209. '3148900739497588515397',
  210. '44641685144571093667',
  211. '11331685200447945941',
  212. '83701685230393513621',
  213. '0999230739324323447175',
  214. '2099360739324342437099',
  215. '1345740739324456585903',
  216. '3436600739324517966370',
  217. '7931230739324697254624',
  218. '8439720739324795372416'
  219. ];
  220. }
  221. public function testOneOrder()
  222. {
  223. $provider = $this->getProvider('by_online');
  224. $params = [
  225. '8013920739815620475078' => '1123061172453041',
  226. '0375610739886119616188' => '1123061272466229',
  227. ];
  228. foreach ($params as $order_sn => $official_sn)
  229. {
  230. [$succ, $resp] = $provider->query(['order_sn' => $order_sn, 'official_sn' => $official_sn]);
  231. }
  232. }
  233. private function check_order($cond)
  234. {
  235. $fsucc = fopen(BASE_DATA_PATH . "/log/succ.log",'a+');
  236. $fcancel = fopen(BASE_DATA_PATH . "/log/cancel.log",'a+');
  237. $ferr = fopen(BASE_DATA_PATH . "/log/nerr.log",'a+');
  238. fwrite($fsucc,"移动成功,我们系统失败\r\n");
  239. fwrite($fcancel,"移动失败,我们系统成功\r\n");
  240. fwrite($ferr,"网络错误,系统请求失败\r\n");
  241. $reader = new statistics\order_reader();
  242. $gen = $reader->refill_vr_reader($cond);
  243. $count = 0;
  244. foreach ($gen as $item)
  245. {
  246. Log::record("order_sn={$item['order_sn']}", Log::DEBUG);
  247. $count += 1;
  248. $chname = $item['channel_name'];
  249. $provider = $this->getProvider($chname);
  250. [$status, $order_state, $charge_id] = $provider->query($item);
  251. if($status)
  252. {
  253. $db_state = intval($item['order_state']);
  254. if($order_state !== $db_state)
  255. {
  256. if ($order_state == ORDER_STATE_SUCCESS) {
  257. fwrite($fsucc, "{$item['order_sn']} {$order_state} {$db_state}\r\n");
  258. } else {
  259. fwrite($fcancel, "{$item['order_sn']} {$order_state} {$db_state}\r\n");
  260. }
  261. }
  262. }
  263. else {
  264. fwrite($ferr, "{$item['order_sn']}\r\n");
  265. }
  266. }
  267. Log::record("all item is $count",Log::DEBUG);
  268. fclose($fsucc);
  269. fclose($fcancel);
  270. fclose($ferr);
  271. }
  272. //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
  273. public function testCheckZY()
  274. {
  275. $cond['refill_order.order_time'] = [['egt', strtotime('2023-06-01')], ['lt', strtotime('2023-06-09')], 'and'];
  276. $cond['vr_order.add_time'] = [['egt', strtotime('2023-06-01')], ['lt', strtotime('2023-06-09')], 'and'];
  277. $cond['inner_status'] = 0;
  278. $cond['vr_order.order_state'] = 0;
  279. $cond['vr_order.store_id'] = ['in',[33,45]];
  280. $this->check_order($cond);
  281. }
  282. //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
  283. public function testCheckYZ()
  284. {
  285. $cond['refill_order.order_time'] = [['egt', strtotime('2023-05-01')], ['lt', strtotime('2023-06-01')], 'and'];
  286. $cond['vr_order.add_time'] = [['egt', strtotime('2023-05-01')], ['lt', strtotime('2023-06-02')], 'and'];
  287. $cond['inner_status'] = 0;
  288. $cond['vr_order.store_id'] = ['in',[319,327]];
  289. $this->check_order($cond);
  290. }
  291. }