| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace Units;
- use App\Model\Mongo\HotelLogModel;
- use HyperfTest\HttpTestCase;
- use Zhuzhichao\IpLocationZh\Ip;
- class MongoTest extends HttpTestCase
- {
- protected function setUp():void
- {
- parent::setUp();
- }
- protected function tearDown():void
- {
- parent::tearDown();
- }
- public function testAggregateLimit()
- {
- $pipeline = [
- [
- '$match' => [
- 'ct_type' => 'ID'
- ],
- ],
- [
- '$group' => [
- '_id' => '$ct_fid',
- 'no' => [
- '$first' => '$ct_fid'
- ],
- 'list_items' => [
- '$push' => '$username',
- ],
- 'username' => [
- '$first' => '$username'
- ],
- 'gender' => [
- '$first' => '$gender'
- ],
- ],
- ],
- [
- '$sort' => [
- '_id' => -1
- ],
- ],
- [
- '$limit' => 20,
- ],
- ];
- $options = [];
- /**
- * @var \MongoDB\Driver\Cursor $cursor
- */
- $cursor = make(HotelLogModel::class)->db()->aggregate($pipeline, $options);
- foreach ($cursor as $v) {
- var_dump($v);
- }
- $this->assertTrue(true);
- }
- public function testGetIpAddr()
- {
- $arrIps = [
- '113.16.131.73',
- '203.168.7.172',
- '180.142.72.108',
- '117.150.69.80',
- ];
- foreach ($arrIps as $ip) {
- $arrIpAddr = Ip::find($ip);
- array_pop($arrIpAddr); //剔除最后一个下标, 国标
- $arrIpAddr = array_filter($arrIpAddr);
- $ipAddr = !empty($arrIpAddr) ? implode('|', $arrIpAddr) : '';
- var_dump($ipAddr);
- }
- $this->assertTrue(true);
- }
- public function testA1()
- {
- $str = 'a:2:{i:0;a:16:{s:2:"id";i:12;s:8:"position";s:10:"video_home";s:5:"title";s:46:"抖窥短视频-你手中的偷拍最强抖音";s:5:"cover";s:26:"f1|/f1/535535/U3zB1GC3.ceb";s:10:"start_time";N;s:8:"end_time";N;s:5:"click";i:0;s:4:"sort";i:1000;s:4:"link";s:35:"https://dk8.in/?channel_code=zbmamb";s:6:"scheme";s:6:"url://";s:6:"status";i:1;s:4:"type";i:2;s:4:"ply2";s:0:"";s:10:"created_at";s:19:"2022-02-25 05:14:15";s:10:"updated_at";s:19:"2022-02-25 05:55:11";s:10:"deleted_at";N;}i:1;a:16:{s:2:"id";i:13;s:8:"position";s:10:"video_home";s:5:"title";s:46:"抖窥短视频-你手中的偷拍最强抖音";s:5:"cover";s:26:"f1|/f1/535535/U3zB1GC3.ceb";s:10:"start_time";N;s:8:"end_time";N;s:5:"click";i:0;s:4:"sort";i:1000;s:4:"link";s:35:"https://dk8.in/?channel_code=zbmamb";s:6:"scheme";s:6:"url://";s:6:"status";i:1;s:4:"type";i:2;s:4:"play";s:1:"1";s:10:"created_at";s:19:"2022-02-25 05:14:16";s:10:"updated_at";s:19:"2022-02-25 05:14:16";s:10:"deleted_at";N;}}';
- $arr = unserialize($str);
- var_dump($arr);
- $this->assertTrue(true);
- }
- }
|