TestExportOrder.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. use statistics\stat_refill;
  4. define('APP_ID', 'test');
  5. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  6. require_once(BASE_ROOT_PATH . '/global.php');
  7. require_once(BASE_CORE_PATH . '/lrlz.php');
  8. require_once(BASE_ROOT_PATH . '/fooder.php');
  9. class TestExportOrder extends TestCase
  10. {
  11. public static function setUpBeforeClass() : void
  12. {
  13. Base::run_util();
  14. }
  15. public function testXingzhiyu()
  16. {
  17. $end_time = strtotime("2021-06-15");
  18. $this->exoprt(10132,null,$end_time);
  19. }
  20. public function exoprt($mchid,$start_time = null,$end_time = null)
  21. {
  22. $cond['mchid'] = $mchid;
  23. $cond['vr_order.order_state'] = 40;
  24. if(!is_null($start_time) && !is_null($end_time)) {
  25. $cond["refill_order.notify_time&refill_order.notify_time"] = ['_multi' => true, ['egt', $start_time], ['lt', $end_time]];
  26. }
  27. elseif(!is_null($start_time)) {
  28. $cond["refill_order.notify_time"] = ['egt', $start_time];
  29. }
  30. elseif(!is_null($end_time)) {
  31. $cond["refill_order.notify_time"] = ['lt', $end_time];
  32. }
  33. $path = BASE_DATA_PATH . "/log/{$mchid}.csv";
  34. $fp = fopen($path, 'w');
  35. fputcsv($fp,['序号','商户订单号','卡号','面额','流水号',"下单时间","回调时间"]);
  36. $count = 1000;
  37. $i = 0;
  38. $index = 0;
  39. while (true)
  40. {
  41. $start = $i * $count;
  42. $items = Model('')->table('refill_order,vr_order')
  43. ->field('mch_order,refill_order.card_no,refill_amount,mch_amount,official_sn,from_unixtime(order_time) as sorder_time,from_unixtime(notify_time) as snotify_time')
  44. ->join('inner')
  45. ->on('refill_order.order_id=vr_order.order_id')
  46. ->where($cond)
  47. ->limit("{$start},{$count}")
  48. ->select();
  49. if(empty($items)) {
  50. break;
  51. }
  52. $i++;
  53. foreach ($items as $item)
  54. {
  55. $index++;
  56. $data = [$index,$item['mch_order'],$item['card_no'],$item['refill_amount'],$item['mch_amount'],$item['official_sn'],$item['sorder_time'],$item['snotify_time']];
  57. fputcsv($fp,$data);
  58. }
  59. }
  60. fclose($fp);
  61. }
  62. }
  63. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestExportOrder::testXingzhiyu)( .*)?$/" --test-suffix TestExportOrder.php /var/www/html/test