AdminKlUpdateTest.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2019/9/18
  6. * Time: 下午7:52
  7. */
  8. use app\common\library\Ip;
  9. use app\common\library\Redis;
  10. use app\main\constants\CacheConstants;
  11. use app\main\constants\KlConstants;
  12. use app\main\model\object\OrderObject;
  13. use app\main\service\AdminKlUpdateService;
  14. use app\main\service\OrderService;
  15. use app\main\service\UserService;
  16. use app\main\model\object\UserObject;
  17. class AdminKlUpdateTest extends TestInit
  18. {
  19. public $user_id = 60007;
  20. public function setUp()
  21. {
  22. \think\Request::instance()->module('admin');
  23. $user = \app\main\service\UserService::instance()->getUserModel()->getUserInfo($this->user_id);
  24. AdminKlUpdateService::instance()->setUser((new \app\main\model\object\UserObject())->bind($user));
  25. $_SERVER['HTTP_X_FORWARDED_FOR'] = '112.90.77.178';
  26. Ip::ip();
  27. }
  28. public function testCheckScreenCity()
  29. {
  30. $data = Redis::instance()->sMembers("ALIC:1734");
  31. var_dump($data);
  32. exit;
  33. $city = '深圳市';
  34. $new = false;
  35. $pay = false;
  36. $op = 'and';
  37. var_dump(IP::city());
  38. $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
  39. $this->assertTrue($data);
  40. }
  41. public function testCheckScreenNew()
  42. {
  43. $city = false;
  44. $new = '>1';
  45. $pay = false;
  46. $op = 'and';
  47. $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
  48. $this->assertFalse($data);
  49. $cacheNew = CacheConstants::getNewUserCacheKey(AdminKlUpdateService::instance()->getUser()->channel_id);
  50. Redis::instance()->set($cacheNew, 2);
  51. $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
  52. $this->assertTrue($data);
  53. }
  54. public function testCheckScreenPay()
  55. {
  56. $city = false;
  57. $new = false;
  58. $pay = '>1';
  59. $op = 'and';
  60. $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
  61. $this->assertFalse($data);
  62. $cacheNew = CacheConstants::getPayUserLimitCacheKey(AdminKlUpdateService::instance()->getUser()->channel_id);
  63. Redis::instance()->set($cacheNew, 2);
  64. $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
  65. $this->assertTrue($data);
  66. }
  67. public function testCheckScreen()
  68. {
  69. $city = '深圳市';
  70. $new = '<1';
  71. $pay = '=1';
  72. $op = 'and';
  73. $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
  74. $this->assertFalse($data);
  75. }
  76. public function testCheckFilterUserPayTime()
  77. {
  78. $order = app\main\service\OrderService::instance()->getOrderModel()
  79. ->where('user_id', $this->user_id)
  80. ->where('state', \app\main\constants\OrderContents::ORDER_STATE_PAID)
  81. ->order('finishtime', 'desc')
  82. ->find();
  83. if ($order) {
  84. OrderService::instance()->getOrderModel()
  85. ->update(['finishtime' => time()], ['id' => $order['id']]);
  86. $pay_time_span = 1;
  87. $pay_type = false;
  88. $read_chapter_count = false;
  89. $shubi_left = false;
  90. $order_count = false;
  91. $op = 'and';
  92. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  93. $this->assertTrue($data);
  94. OrderService::instance()->getOrderModel()
  95. ->update(['finishtime' => time() - $pay_time_span * 3600], ['id' => $order['id']]);
  96. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  97. $this->assertFalse($data);
  98. }
  99. }
  100. public function testCheckFilterUserPayType()
  101. {
  102. $order = new OrderObject();
  103. $order->bind(['book_id'=>1]);
  104. AdminKlUpdateService::instance()->setOrder($order);
  105. $pay_time_span = false;
  106. $pay_type = 'Z';
  107. $read_chapter_count = false;
  108. $shubi_left = false;
  109. $order_count = false;
  110. $op = 'and';
  111. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  112. $this->assertTrue($data);
  113. $order->bind(['activity_id'=>1]);
  114. AdminKlUpdateService::instance()->setOrder($order);
  115. $pay_type = 'activity';
  116. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  117. $this->assertTrue($data);
  118. }
  119. public function testCheckFilterUserChapter()
  120. {
  121. $pay_time_span = false;
  122. $pay_type = false;
  123. $read_chapter_count = '>5';
  124. $shubi_left = false;
  125. $order_count = false;
  126. $op = 'and';
  127. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  128. $this->assertTrue($data);
  129. $read_chapter_count = '>100';
  130. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  131. $this->assertFalse($data);
  132. }
  133. public function testCheckFilterUserShubi()
  134. {
  135. UserService::instance()->getUserModel()->setConnect($this->user_id)->update(
  136. ['kandian' => 101], ['id' => $this->user_id]
  137. );
  138. $user = UserService::instance()->getUserModel()->getUserInfo($this->user_id, true);
  139. AdminKlUpdateService::instance()->setUser((new UserObject())->bind($user));
  140. $pay_time_span = false;
  141. $pay_type = false;
  142. $read_chapter_count = false;
  143. $shubi_left = '>100';
  144. $order_count = false;
  145. $op = 'and';
  146. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  147. $this->assertTrue($data);
  148. }
  149. public function testCheckFilterUserOrderCount()
  150. {
  151. $pay_time_span = false;
  152. $pay_type = false;
  153. $read_chapter_count = false;
  154. $shubi_left = false;
  155. $order_count = '>10';
  156. $op = 'and';
  157. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  158. $this->assertTrue($data);
  159. $order_count = '>100';
  160. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  161. $this->assertFalse($data);
  162. }
  163. public function testCheckFilterUser()
  164. {
  165. $order = new OrderObject();
  166. $order->bind(['day'=>1]);
  167. AdminKlUpdateService::instance()->setOrder($order);
  168. $pay_time_span = 1;
  169. $pay_type = 'vip';
  170. $read_chapter_count = '>2';
  171. $shubi_left = '>10';
  172. $order_count = '>10';
  173. $op = 'and';
  174. $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
  175. $this->assertFalse($data);
  176. }
  177. public function testCheckRegister()
  178. {
  179. $time = '>1';
  180. $data = AdminKlUpdateService::instance()->checkFilterOrderAndRegister($time)->data;
  181. $this->assertTrue($data);
  182. }
  183. public function testOrderKlDouble()
  184. {
  185. $double_pay = 40;
  186. $new = false;
  187. $old = false;
  188. $data = AdminKlUpdateService::instance()->checkOrderKL($double_pay, $new, $old)->data;
  189. }
  190. public function testOrderKlNew()
  191. {
  192. $double_pay = false;
  193. $new = 40;
  194. $old = false;
  195. $data = AdminKlUpdateService::instance()->checkOrderKL($double_pay, $new, $old)->data;
  196. }
  197. public function testOrderKlOld()
  198. {
  199. $double_pay = false;
  200. $new = false;
  201. $old = 40;
  202. $data = AdminKlUpdateService::instance()->checkOrderKL($double_pay, $new, $old)->data;
  203. }
  204. public function testKlEq()
  205. {
  206. $rule_id = 12;
  207. $redisKey = KlConstants::REDIS_KEY_PREFIX.$rule_id;
  208. Redis::instance()->del($redisKey);
  209. $data = \app\main\service\KlService::instance()->getRuleConfig($rule_id);
  210. var_dump($data);
  211. }
  212. }