TestMemberCard.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php declare(strict_types=1);
  2. use PHPUnit\Framework\TestCase;
  3. /**
  4. * Created by PhpStorm.
  5. * User: stanley-king
  6. * Date: 16/6/27
  7. * Time: 下午10:27
  8. */
  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_HELPER_PATH . '/mcard/mcard.php');
  15. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  16. require_once(BASE_HELPER_PATH . '/util_helper.php');
  17. require_once(BASE_HELPER_PATH . '/order_helper.php');
  18. require_once(BASE_HELPER_PATH . '/bonus_helper.php');
  19. require_once(BASE_HELPER_PATH . '/vrorder_helper.php');
  20. use mcard;
  21. class TestMemberCard extends TestCase
  22. {
  23. private $member_id = 36490;
  24. public static function setUpBeforeClass(): void
  25. {
  26. Base::run_util();
  27. }
  28. public function testGetOils()
  29. {
  30. $ret = mcard\getTopcardInfo('oil',36490);
  31. }
  32. public function testAddMemberCard()
  33. {
  34. $usercards = new mcard\user_mcards($this->member_id);
  35. $usercards->addCard(['card_type' => mcard\BothType, 'total_amount' => 10000, 'discount' => 0.05, 'package_type' => 'year']);
  36. }
  37. public function testDeduct()
  38. {
  39. $usercards = new mcard\user_mcards(36490);
  40. $amounts = [3000, 5000, 200, 100, 200, 2000, 1000];
  41. foreach ($amounts as $amount) {
  42. if ($usercards->enough($amount)) {
  43. $usercards->deduct($amount);
  44. Log::record("Consume {$amount}.");
  45. } else {
  46. Log::record("Not enough money {$amount}.");
  47. }
  48. }
  49. }
  50. public function testAddTopCard()
  51. {
  52. $cards = new mtopcard\user_topcards($this->member_id);
  53. $cards->addCard('1000111100020445281', mtopcard\PetroChinaCard);
  54. $cards->addMoney(0, 1000);
  55. $cards->addMoney(0, 1000);
  56. $cards->addMoney(0, 1000);
  57. $ret = $cards->cards_format();
  58. }
  59. public function testAddCardKeys()
  60. {
  61. $params = [
  62. ['card_type' => mtopcard\OilCardPaper, 'amount' => 100],
  63. ['card_type' => mtopcard\OilCardPaper, 'amount' => 200],
  64. ['card_type' => mtopcard\OilCardPaper, 'amount' => 500],
  65. ['card_type' => mtopcard\OilCardPaper, 'amount' => 1000],
  66. ['card_type' => mtopcard\PhoneCardPaper, 'amount' => 100],
  67. ];
  68. $car_no = '1900000000000000';
  69. $count = 10;
  70. $mod_card = Model('card_key');
  71. foreach ($params as $item)
  72. {
  73. for($i= 0; $i < $count; $i++) {
  74. $mod_card->addCard(['card_no' => $car_no,'card_key' => 'm8i094k4t8n8','card_type' => $item['card_type'],'amount' => $item['amount']]);
  75. $car_no += 1;
  76. }
  77. }
  78. }
  79. public function testAddCardKeysLocal()
  80. {
  81. $params = [
  82. ['card_type' => mtopcard\OilCardPaper, 'amount' => 100],
  83. ['card_type' => mtopcard\OilCardPaper, 'amount' => 200],
  84. ['card_type' => mtopcard\PhoneCardPaper, 'amount' => 100],
  85. ['card_type' => mtopcard\PhoneCardPaper, 'amount' => 200]
  86. ];
  87. $car_no = '1900000000000000';
  88. $count = 10;
  89. $mod_card = Model('card_key');
  90. foreach ($params as $item)
  91. {
  92. for($i= 0; $i < $count; $i++) {
  93. $mod_card->addCard(['card_no' => $car_no,'card_key' => 'm8i094k4t8n8','card_type' => $item['card_type'],'amount' => $item['amount']]);
  94. $car_no += 1;
  95. }
  96. }
  97. }
  98. public function testReserve()
  99. {
  100. $amount = 1000;
  101. $card = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper,1000,35268,'xxxyyyzzzkkkdj',mtopcard\PetroChinaCard);
  102. mtopcard\cards_helper::assign(1,'xiongmao');
  103. mtopcard\cards_helper::reserve(mtopcard\OilCardPaper,1000,35268,'xxxyyyzzzkkkdj',mtopcard\PetroChinaCard);
  104. mtopcard\cards_helper::reuse(4);
  105. }
  106. public function testOnVrOrderSuccess()
  107. {
  108. $logic = Logic('queue');
  109. $logic->OnVrOrderSuccess(['order_sn' => '920648515867397620']);
  110. }
  111. public function testOnVrOrderCancel()
  112. {
  113. $logic = Logic('queue');
  114. $logic->OnVrOrderCancel(['order_sn' => '510649439049587625']);
  115. }
  116. public function testVOrderPaidSuccess()
  117. {
  118. $logic = Logic('queue');
  119. $logic->OnVrOrderPaidSuccess(['order_sn' => '530649437595131625']);
  120. }
  121. //测试购买会员,成功支付,改变用户会员属性,修改状态.
  122. public function testPaidVOrderSuccess()
  123. {
  124. $order_sn = '530649437595131625';
  125. $trade_no = '730510765598547599';
  126. $payer = new pay_helper($order_sn);
  127. $payer->update_order($trade_no,'wxpay');
  128. }
  129. public function testOnVrOrderComplete()
  130. {
  131. $order_sn = '260649436354923625';
  132. $logic = Logic('queue');
  133. $logic->OnVrOrderComplete(['order_sn' => $order_sn]);
  134. }
  135. //测试购买会员
  136. public function testMcardOrderSucess()
  137. {
  138. $logic = Logic('queue');
  139. $logic->OnMCardPaidSuccess(['order_sn' => '580648112029501620']);
  140. }
  141. public function testExtraInfo()
  142. {
  143. $order_sn = '920648515867397620';
  144. $model_order = Model('vr_order');
  145. $order = $model_order->getOrderInfo(['order_sn' => $order_sn]);
  146. vrorder_helper::extend_order_info($order);
  147. }
  148. public function testStrict()
  149. {
  150. }
  151. }