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

namespace mobile\server;

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

        public function add($nid)
        {
            $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 = $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;
        }



}