123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/11/9
- * Time: 下午5:19
- */
- 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/search/tcp_client.php');
- require_once(BASE_ROOT_PATH . '/helper/message/publisher.php');
- use PHPUnit\Framework\TestCase;
- class TestCommand extends TestCase
- {
- public static function setUpBeforeClass() : void
- {
- Base::run_util();
- }
- //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
- public function testExportCard()
- {
- $filename = BASE_DATA_PATH . "/log/cards.csv";
- $fcards = fopen($filename,'w+');
- $mod_member = Model('card_info');
- $start = 0;
- while (true)
- {
- $items = $mod_member->field('card_no,using_times')->where(['card_no' => ['gt', $start], 'card_type' => 4])->limit("0,1000")->select();
- if (empty($items)) {
- break;
- }
- foreach ($items as $item) {
- $card_no = $item['card_no'];
- $start = $card_no;
- $using_times = $item['using_times'] + 1;
- fputcsv($fcards, [$card_no,$using_times]);
- }
- }
- fclose($fcards);
- }
- public function testInit_reward()
- {
- $mod_member = Model('member');
- $i = 0;
- while (true)
- {
- $start = $i * 1000;
- $items = $mod_member->field('member_id')->order('member_id asc')->limit("{$start},1000")->select();
- if(empty($items)) {
- return;
- }
- $i++;
- foreach ($items as $item)
- {
- $user = intval($item['member_id']);
- if($user <= 0) continue;
- $val = $mod_member->field('count(*) inviter_count' )->where(['inviter_id' => $user])->select();
- $invitees = intval($val[0]['inviter_count']);
- if($invitees <= 0) continue;
- $ret = $mod_member->editMember(['member_id' => $user],['invitees' => $invitees,'reward_amount' => $invitees * 30]);
- if($ret == false) {
- Log::record("update member_id = {$user} invitees and reward",Log::ERR);
- }
- }
- }
- }
- public function testLowestPrice()
- {
- Log::record(__METHOD__ . " start",Log::DEBUG);
- $mod_goods = Model('goods');
- $path = BASE_DATA_PATH . '/mobile/lowest_price.txt';
- $file = fopen($path,'r');
- $i = 0;
- while (!feof($file))
- {
- $line = fgets($file);
- $line = trim($line);
- $datas = explode("\t",$line);
- if(count($datas) == 3) {
- $goods_id = intval($datas[0]);
- $goods_price = intval($datas[1] * 100 + 0.5) / 100;
- $lowest_price = intval($datas[2] * 100 + 0.5) / 100;
- $result = $mod_goods->editGoods(['goods_marketprice' => $goods_price,'goods_price' => $goods_price,'goods_lowest_price' => $lowest_price],['goods_id' => $goods_id]);
- if($result == false) {
- Log::record("update goods_id = {$goods_id}",Log::ERR);
- }
- }
- else {
- Log::record("update err line ={$i}",Log::ERR);
- }
- $i++;
- }
- fclose($file);
- Log::record(__METHOD__ . " end",Log::DEBUG);
- }
- //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
- public function testQueryRefund()
- {
- QueueClient::push("QueryRefund", ['order_id' => 8987841]);
- }
- //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
- public function testQueryAllRefund()
- {
- $mod = Model();
- $start = 0;
- $inter = 0;
- while (true)
- {
- $cond = ['inner_status' => 0,
- 'order_state' => ORDER_STATE_SUCCESS,
- 'vr_order.order_id' => ['gt', $start],
- 'store_id' => 33,
- 'order_time' => ['lt', strtotime("2023-05-24 18:00:00")]
- ];
- $items = $mod->table('refill_order,vr_order')
- ->field('refill_order.order_id')
- ->where($cond)
- ->join('inner')->on('refill_order.order_id=vr_order.order_id')
- ->limit("0,100")
- ->select();
- if(empty($items)) break;
- $inter += 1;
- foreach ($items as $item) {
- $order_id = intval($item['order_id']);
- $start = $order_id;
- QueueClient::async_push("QueryRefund", ['order_id' => $order_id],$inter);
- }
- }
- }
- }
|