123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2019/9/18
- * Time: 下午7:52
- */
- use app\common\library\Ip;
- use app\common\library\Redis;
- use app\main\constants\CacheConstants;
- use app\main\constants\KlConstants;
- use app\main\model\object\OrderObject;
- use app\main\service\AdminKlUpdateService;
- use app\main\service\OrderService;
- use app\main\service\UserService;
- use app\main\model\object\UserObject;
- class AdminKlUpdateTest extends TestInit
- {
- public $user_id = 60007;
- public function setUp()
- {
- \think\Request::instance()->module('admin');
- $user = \app\main\service\UserService::instance()->getUserModel()->getUserInfo($this->user_id);
- AdminKlUpdateService::instance()->setUser((new \app\main\model\object\UserObject())->bind($user));
- $_SERVER['HTTP_X_FORWARDED_FOR'] = '112.90.77.178';
- Ip::ip();
- }
- public function testCheckScreenCity()
- {
- $data = Redis::instance()->sMembers("ALIC:1734");
- var_dump($data);
- exit;
- $city = '深圳市';
- $new = false;
- $pay = false;
- $op = 'and';
- var_dump(IP::city());
- $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
- $this->assertTrue($data);
- }
- public function testCheckScreenNew()
- {
- $city = false;
- $new = '>1';
- $pay = false;
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
- $this->assertFalse($data);
- $cacheNew = CacheConstants::getNewUserCacheKey(AdminKlUpdateService::instance()->getUser()->channel_id);
- Redis::instance()->set($cacheNew, 2);
- $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
- $this->assertTrue($data);
- }
- public function testCheckScreenPay()
- {
- $city = false;
- $new = false;
- $pay = '>1';
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
- $this->assertFalse($data);
- $cacheNew = CacheConstants::getPayUserLimitCacheKey(AdminKlUpdateService::instance()->getUser()->channel_id);
- Redis::instance()->set($cacheNew, 2);
- $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
- $this->assertTrue($data);
- }
- public function testCheckScreen()
- {
- $city = '深圳市';
- $new = '<1';
- $pay = '=1';
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkScreen($city, $new, $pay, $op)->data;
- $this->assertFalse($data);
- }
- public function testCheckFilterUserPayTime()
- {
- $order = app\main\service\OrderService::instance()->getOrderModel()
- ->where('user_id', $this->user_id)
- ->where('state', \app\main\constants\OrderContents::ORDER_STATE_PAID)
- ->order('finishtime', 'desc')
- ->find();
- if ($order) {
- OrderService::instance()->getOrderModel()
- ->update(['finishtime' => time()], ['id' => $order['id']]);
- $pay_time_span = 1;
- $pay_type = false;
- $read_chapter_count = false;
- $shubi_left = false;
- $order_count = false;
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertTrue($data);
- OrderService::instance()->getOrderModel()
- ->update(['finishtime' => time() - $pay_time_span * 3600], ['id' => $order['id']]);
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertFalse($data);
- }
- }
- public function testCheckFilterUserPayType()
- {
- $order = new OrderObject();
- $order->bind(['book_id'=>1]);
- AdminKlUpdateService::instance()->setOrder($order);
- $pay_time_span = false;
- $pay_type = 'Z';
- $read_chapter_count = false;
- $shubi_left = false;
- $order_count = false;
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertTrue($data);
- $order->bind(['activity_id'=>1]);
- AdminKlUpdateService::instance()->setOrder($order);
- $pay_type = 'activity';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertTrue($data);
- }
- public function testCheckFilterUserChapter()
- {
- $pay_time_span = false;
- $pay_type = false;
- $read_chapter_count = '>5';
- $shubi_left = false;
- $order_count = false;
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertTrue($data);
- $read_chapter_count = '>100';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertFalse($data);
- }
- public function testCheckFilterUserShubi()
- {
- UserService::instance()->getUserModel()->setConnect($this->user_id)->update(
- ['kandian' => 101], ['id' => $this->user_id]
- );
- $user = UserService::instance()->getUserModel()->getUserInfo($this->user_id, true);
- AdminKlUpdateService::instance()->setUser((new UserObject())->bind($user));
- $pay_time_span = false;
- $pay_type = false;
- $read_chapter_count = false;
- $shubi_left = '>100';
- $order_count = false;
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertTrue($data);
- }
- public function testCheckFilterUserOrderCount()
- {
- $pay_time_span = false;
- $pay_type = false;
- $read_chapter_count = false;
- $shubi_left = false;
- $order_count = '>10';
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertTrue($data);
- $order_count = '>100';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertFalse($data);
- }
- public function testCheckFilterUser()
- {
- $order = new OrderObject();
- $order->bind(['day'=>1]);
- AdminKlUpdateService::instance()->setOrder($order);
- $pay_time_span = 1;
- $pay_type = 'vip';
- $read_chapter_count = '>2';
- $shubi_left = '>10';
- $order_count = '>10';
- $op = 'and';
- $data = AdminKlUpdateService::instance()->checkFilterUser($pay_time_span, $pay_type, $read_chapter_count, $shubi_left, $order_count, $op)->data;
- $this->assertFalse($data);
- }
- public function testCheckRegister()
- {
- $time = '>1';
- $data = AdminKlUpdateService::instance()->checkFilterOrderAndRegister($time)->data;
- $this->assertTrue($data);
- }
- public function testOrderKlDouble()
- {
- $double_pay = 40;
- $new = false;
- $old = false;
- $data = AdminKlUpdateService::instance()->checkOrderKL($double_pay, $new, $old)->data;
- }
- public function testOrderKlNew()
- {
- $double_pay = false;
- $new = 40;
- $old = false;
- $data = AdminKlUpdateService::instance()->checkOrderKL($double_pay, $new, $old)->data;
- }
- public function testOrderKlOld()
- {
- $double_pay = false;
- $new = false;
- $old = 40;
- $data = AdminKlUpdateService::instance()->checkOrderKL($double_pay, $new, $old)->data;
- }
- public function testKlEq()
- {
- $rule_id = 12;
- $redisKey = KlConstants::REDIS_KEY_PREFIX.$rule_id;
- Redis::instance()->del($redisKey);
- $data = \app\main\service\KlService::instance()->getRuleConfig($rule_id);
- var_dump($data);
- }
- }
|