<?php
/**
 * Created by PhpStorm.
 * User: xiaofeng
 * Date: 2018/4/24
 * Time: 下午3:51
 */

namespace frontend\server;

use Yii;
use common\models\NewsIprecord;
class IpServer
{

    public function add()
    {
        $ip = Yii::$app->request->userIP;
//            $data = json_decode(file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip),true);
//            if(!empty($data) && $data['code'] == 0)
//            {
        $model = new NewsIprecord();
        $model->ip = $ip;
        $model->nid = Yii::$app->request->get('nid');
        $row = $model->FindByIp();
        if($row == null)
        {
//                    $model->region = $data['data']['region'];
//                    $model->city = $data['data']['city'];
//                    $model->country = $data['data']['country'];
            if($model->save())return true;
        }
//            }
        return false;
    }



}