TestRefund.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. $chname = $refill_info['channel_name'];
  136. $provider = $this->getProvider($chname);
  137. [$status, $order_state, $charge_id] = $provider->query($refill_info);
  138. if($status) {
  139. Log::record("order_sn=$order_sn order_state=$order_state",Log::DEBUG);
  140. }
  141. else {
  142. Log::record("order_sn=$order_sn msg=$order_state",Log::DEBUG);
  143. }
  144. }
  145. }
  146. }
  147. private function getOrders()
  148. {
  149. return [
  150. '0054340738786801278285',
  151. '0072270738754986062471',
  152. '0073520738759742703583',
  153. '0075580738780047989128',
  154. '0079860738751884483673',
  155. '0222330738757938391994',
  156. '0224810738762683686978',
  157. '0229430738760052407447',
  158. '0051880738756076094755',
  159. '0274810738781583681751',
  160. '0347700738779630513391',
  161. ];
  162. }
  163. public function testOneOrder()
  164. {
  165. $provider = $this->getProvider('by_online');
  166. $order_sn = '5744450737576478180405';
  167. [$succ, $resp] = $provider->query(['order_sn' => $order_sn, 'official_sn' => '']);
  168. }
  169. private function check_order($cond)
  170. {
  171. $fsucc = fopen(BASE_DATA_PATH . "/log/succ.log",'a+');
  172. $fcancel = fopen(BASE_DATA_PATH . "/log/cancel.log",'a+');
  173. $ferr = fopen(BASE_DATA_PATH . "/log/nerr.log",'a+');
  174. fwrite($fsucc,"移动成功,我们系统失败\r\n");
  175. fwrite($fcancel,"移动失败,我们系统成功\r\n");
  176. fwrite($ferr,"网络错误,系统请求失败\r\n");
  177. $reader = new statistics\order_reader();
  178. $gen = $reader->refill_vr_reader($cond);
  179. $count = 0;
  180. foreach ($gen as $item)
  181. {
  182. $count += 1;
  183. $chname = $item['channel_name'];
  184. $provider = $this->getProvider($chname);
  185. [$status, $order_state, $charge_id] = $provider->query($item);
  186. if($status)
  187. {
  188. $db_state = intval($item['order_state']);
  189. if($order_state !== $db_state)
  190. {
  191. if($order_state == ORDER_STATE_SUCCESS) {
  192. fwrite($fsucc,"{$item['order_sn']} {$order_state} {$db_state}\r\n");
  193. }
  194. else {
  195. fwrite($fcancel,"{$item['order_sn']} {$order_state} {$db_state}\r\n");
  196. }
  197. }
  198. }
  199. else
  200. {
  201. fwrite($ferr,"{$item['order_sn']}\r\n");
  202. }
  203. }
  204. Log::record("all item is $count",Log::DEBUG);
  205. fclose($fsucc);
  206. fclose($fcancel);
  207. fclose($ferr);
  208. }
  209. //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
  210. public function testCheckZY()
  211. {
  212. $cond['refill_order.order_time'] = [['egt', strtotime('2023-06-06')], ['lt', strtotime('2023-06-07')], 'and'];
  213. $cond['vr_order.add_time'] = [['egt', strtotime('2023-06-06')], ['lt', strtotime('2023-06-08')], 'and'];
  214. $cond['inner_status'] = 0;
  215. $cond['vr_order.store_id'] = ['in',[33,45]];
  216. $this->check_order($cond);
  217. }
  218. //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
  219. public function testCheckYZ()
  220. {
  221. $cond['refill_order.order_time'] = [['egt', strtotime('2023-05-01')], ['lt', strtotime('2023-06-01')], 'and'];
  222. $cond['vr_order.add_time'] = [['egt', strtotime('2023-05-01')], ['lt', strtotime('2023-06-02')], 'and'];
  223. $cond['inner_status'] = 0;
  224. $cond['vr_order.store_id'] = ['in',[319,327]];
  225. $this->check_order($cond);
  226. }
  227. }