TestCommand.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/11/9
  6. * Time: 下午5:19
  7. */
  8. define('APP_ID', 'test');
  9. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  10. require_once(BASE_ROOT_PATH . '/global.php');
  11. require_once(BASE_CORE_PATH . '/lrlz.php');
  12. require_once(BASE_ROOT_PATH . '/fooder.php');
  13. require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
  14. require_once(BASE_ROOT_PATH . '/helper/message/publisher.php');
  15. use PHPUnit\Framework\TestCase;
  16. class TestCommand extends TestCase
  17. {
  18. public static function setUpBeforeClass() : void
  19. {
  20. Base::run_util();
  21. }
  22. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestCommand::testExportCard)( .*)?$/" --test-suffix TestCommand.php /var/www/html/test
  23. public function testExportCard()
  24. {
  25. $filename = BASE_DATA_PATH . "/log/cards.csv";
  26. $fcards = fopen($filename,'w+');
  27. $mod_member = Model('card_info');
  28. $start = 0;
  29. while (true)
  30. {
  31. $items = $mod_member->field('card_no,using_times')->where(['card_no' => ['gt', $start], 'card_type' => 4])->limit("0,1000")->select();
  32. if (empty($items)) {
  33. break;
  34. }
  35. foreach ($items as $item) {
  36. $card_no = $item['card_no'];
  37. $start = $card_no;
  38. $using_times = $item['using_times'] + 1;
  39. fputcsv($fcards, [$card_no,$using_times]);
  40. }
  41. }
  42. fclose($fcards);
  43. }
  44. public function testInit_reward()
  45. {
  46. $mod_member = Model('member');
  47. $i = 0;
  48. while (true)
  49. {
  50. $start = $i * 1000;
  51. $items = $mod_member->field('member_id')->order('member_id asc')->limit("{$start},1000")->select();
  52. if(empty($items)) {
  53. return;
  54. }
  55. $i++;
  56. foreach ($items as $item)
  57. {
  58. $user = intval($item['member_id']);
  59. if($user <= 0) continue;
  60. $val = $mod_member->field('count(*) inviter_count' )->where(['inviter_id' => $user])->select();
  61. $invitees = intval($val[0]['inviter_count']);
  62. if($invitees <= 0) continue;
  63. $ret = $mod_member->editMember(['member_id' => $user],['invitees' => $invitees,'reward_amount' => $invitees * 30]);
  64. if($ret == false) {
  65. Log::record("update member_id = {$user} invitees and reward",Log::ERR);
  66. }
  67. }
  68. }
  69. }
  70. public function testLowestPrice()
  71. {
  72. Log::record(__METHOD__ . " start",Log::DEBUG);
  73. $mod_goods = Model('goods');
  74. $path = BASE_DATA_PATH . '/mobile/lowest_price.txt';
  75. $file = fopen($path,'r');
  76. $i = 0;
  77. while (!feof($file))
  78. {
  79. $line = fgets($file);
  80. $line = trim($line);
  81. $datas = explode("\t",$line);
  82. if(count($datas) == 3) {
  83. $goods_id = intval($datas[0]);
  84. $goods_price = intval($datas[1] * 100 + 0.5) / 100;
  85. $lowest_price = intval($datas[2] * 100 + 0.5) / 100;
  86. $result = $mod_goods->editGoods(['goods_marketprice' => $goods_price,'goods_price' => $goods_price,'goods_lowest_price' => $lowest_price],['goods_id' => $goods_id]);
  87. if($result == false) {
  88. Log::record("update goods_id = {$goods_id}",Log::ERR);
  89. }
  90. }
  91. else {
  92. Log::record("update err line ={$i}",Log::ERR);
  93. }
  94. $i++;
  95. }
  96. fclose($file);
  97. Log::record(__METHOD__ . " end",Log::DEBUG);
  98. }
  99. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestCommand::testQueryRefund)( .*)?$/" --test-suffix TestCommand.php /var/www/html/test
  100. public function testQueryRefund()
  101. {
  102. QueueClient::push("QueryRefund", ['order_id' => 8987841]);
  103. }
  104. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestCommand::testQueryAllRefund)( .*)?$/" --test-suffix TestCommand.php /var/www/html/test
  105. public function testQueryAllRefund()
  106. {
  107. $mod = Model();
  108. $start = 0;
  109. $inter = 0;
  110. while (true)
  111. {
  112. $cond = ['inner_status' => 0,
  113. 'order_state' => ORDER_STATE_SUCCESS,
  114. 'vr_order.order_id' => ['gt', $start],
  115. 'store_id' => 33,
  116. 'order_time' => ['lt', strtotime("2023-05-24 18:00:00")]
  117. ];
  118. $items = $mod->table('refill_order,vr_order')
  119. ->field('refill_order.order_id')
  120. ->where($cond)
  121. ->join('inner')->on('refill_order.order_id=vr_order.order_id')
  122. ->limit("0,100")
  123. ->select();
  124. if(empty($items)) break;
  125. $inter += 1;
  126. foreach ($items as $item) {
  127. $order_id = intval($item['order_id']);
  128. $start = $order_id;
  129. QueueClient::async_push("QueryRefund", ['order_id' => $order_id],$inter);
  130. }
  131. }
  132. }
  133. }