table('vr_order')->field('*')->order('order_id asc')->limit("{$start},{$count}")->select(); if(empty($items)) { break; } $i++; foreach ($items as $item) { try { if(empty($item['extra_info'])) { continue; } $extra_info = json_decode($item['extra_info'],true); if(empty($extra_info)) { continue; } $card_no = $extra_info['input']['card_no']; $card_type = mtopcard\topcard_type($extra_info['input']['card_type']); Log::record("{$card_no} {$card_type}",Log::DEBUG); if(empty($card_no)) continue; $vr_order->table('vr_order')->where(['order_id' => $item['order_id']])->update(['card_no' => $card_no]); } catch (Exception $ex) { Log::record($ex->getMessage(),Log::DEBUG); } } } } public function testLoadTopcards() { global $config; $spec_card = $config['vgoods_spec_card']; $vr_order = Model(); $topcard = Model('topcard'); $member_topcard = Model('member_topcard'); $count = 1000; $i = 0; $index = 0; while (true) { $start = $i * $count; $items = $vr_order->table('vr_order')->field('*')->order('order_id asc')->limit("{$start},{$count}")->select(); if(empty($items)) { break; } $i++; foreach ($items as $item) { try { $member_id = intval($item['buyer_id']); $add_time = intval($item['add_time']); $payment_time = intval($item['payment_time']); $goods_id = intval($item['goods_id']); $amount = $spec_card[$goods_id]; $order_state = intval($item['order_state']); if(empty($item['extra_info'])) { $index++; continue; } $extra_info = json_decode($item['extra_info'],true); if(empty($extra_info)) { $index++; continue; } $card_no = $extra_info['input']['card_no']; $card_type = mtopcard\topcard_type($extra_info['input']['card_type']); Log::record("{$index} {$card_no} {$card_type}",Log::DEBUG); $index++; if(empty($card_no)) continue; if(empty($topcard->get_card($card_no))) { $topcard->add($card_no,$card_type,$add_time); } if(in_array($order_state,[ORDER_STATE_PAY, ORDER_STATE_SEND, ORDER_STATE_SUCCESS]) && $amount > 0) { $ret = $topcard->add_money($card_no,$amount,$payment_time); if(!$ret) { Log::record("{$card_no} add money fail.",Log::DEBUG); } } } catch (Exception $ex) { Log::record($ex->getMessage(),Log::DEBUG); } } } } public function testDate() { $now = time(); $nine = strtotime(date('Y-m-d',$now)) + 9*3600; $twenty_first = strtotime(date('Y-m-d',$now)) + 21*3600; if($now > $nine || $now < $twenty_first) { $x = 0; } } public function testTime() { $this->month_range(time()); $x = strtotime(date('Y-m-d',time())); $y = strtotime('+1 day',$x); $x1 = date('Y-m-01',strtotime(date('Y-m-d'))); $x2 = date('Y-m-t',strtotime(date('Y-m-d'))); $x3 = date('Y-m-01',strtotime('-1 month')); $x4 = date('Y-m-t',strtotime('-1 month')); } private function month_range($time) { $x = strtotime(date('Y-m-d',$time)); $x = strtotime(date('Y-m-01',$x)); $y = strtotime('+1 month',$x); return [$x,$y]; } public function testGetOils() { $ret = mcard\getTopcardInfo('oil',36490); } public function testAddMemberCard() { $usercards = new mcard\user_mcards($this->member_id); $usercards->addCard(['card_type' => mcard\BothType, 'total_amount' => 10000, 'discount' => 0.05, 'package_type' => 'year']); } public function testDeduct() { $usercards = new mcard\user_mcards(36490); $amounts = [3000, 5000, 200, 100, 200, 2000, 1000]; foreach ($amounts as $amount) { if ($usercards->enough($amount)) { $usercards->deduct($amount); Log::record("Consume {$amount}."); } else { Log::record("Not enough money {$amount}."); } } } public function testAddTopCard() { $cards = new mtopcard\user_topcards($this->member_id); $cards->addCard('1000111100020445281', mtopcard\PetroChinaCard); $cards->addMoney(0, 1000); $cards->addMoney(0, 1000); $cards->addMoney(0, 1000); $ret = $cards->cards_format(); } public function testAddCardKeys() { $params = [ ['card_type' => mtopcard\OilCardPaper, 'amount' => 100], ['card_type' => mtopcard\OilCardPaper, 'amount' => 200], ['card_type' => mtopcard\OilCardPaper, 'amount' => 500], ['card_type' => mtopcard\OilCardPaper, 'amount' => 1000], ['card_type' => mtopcard\PhoneCardPaper, 'amount' => 100], ]; $car_no = '1900000000000000'; $count = 10; $mod_card = Model('card_key'); foreach ($params as $item) { for($i= 0; $i < $count; $i++) { $mod_card->addCard(['card_no' => $car_no,'card_key' => 'm8i094k4t8n8','card_type' => $item['card_type'],'amount' => $item['amount']]); $car_no += 1; } } } public function testAddCardKeysLocal() { $params = [ ['card_type' => mtopcard\OilCardPaper, 'amount' => 100], ['card_type' => mtopcard\OilCardPaper, 'amount' => 200], ['card_type' => mtopcard\PhoneCardPaper, 'amount' => 100], ['card_type' => mtopcard\PhoneCardPaper, 'amount' => 200] ]; $car_no = '1900000000000000'; $count = 10; $mod_card = Model('card_key'); foreach ($params as $item) { for($i= 0; $i < $count; $i++) { $mod_card->addCard(['card_no' => $car_no,'card_key' => 'm8i094k4t8n8','card_type' => $item['card_type'],'amount' => $item['amount']]); $car_no += 1; } } } public function testReserve() { $amount = 1000; $card = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper,1000,35268,'xxxyyyzzzkkkdj',mtopcard\PetroChinaCard); mtopcard\cards_helper::assign(1,'xiongmao'); mtopcard\cards_helper::reserve(mtopcard\OilCardPaper,1000,35268,'xxxyyyzzzkkkdj',mtopcard\PetroChinaCard); mtopcard\cards_helper::reuse(4); } public function testOnVrOrderSuccess() { $logic = Logic('queue'); $logic->OnVrOrderSuccess(['order_sn' => '920648515867397620']); } public function testOnVrOrderCancel() { $logic = Logic('queue'); $logic->OnVrOrderCancel(['order_sn' => '510649439049587625']); } public function testVOrderPaidSuccess() { $logic = Logic('queue'); $logic->OnVrOrderPaidSuccess(['order_sn' => '530649437595131625']); } //测试购买会员,成功支付,改变用户会员属性,修改状态. public function testPaidVOrderSuccess() { $order_sn = '530649437595131625'; $trade_no = '730510765598547599'; $payer = new pay_helper($order_sn); $payer->update_order($trade_no,'wxpay'); } public function testOnVrOrderComplete() { $order_sn = '260649436354923625'; $logic = Logic('queue'); $logic->OnVrOrderComplete(['order_sn' => $order_sn]); } //测试购买会员 public function testMcardOrderSucess() { $logic = Logic('queue'); $logic->OnMCardPaidSuccess(['order_sn' => '580648112029501620']); } public function testExtraInfo() { $order_sn = '920648515867397620'; $model_order = Model('vr_order'); $order = $model_order->getOrderInfo(['order_sn' => $order_sn]); vrorder_helper::extend_order_info($order); } public function testStrict() { } }