<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/28
 * Time: 17:20
 */
namespace app\index\model;

use think\Db;
use think\Model;

class User extends Model
{
    public function findData($where){
        $data = $this->where($where)->find();
        if(!empty($data)){
            //判断是否为会员
            $is_vip = '2';
            if(!empty($data['vip_passtime'])){
                if($data['vip_passtime'] > time()){
                    $is_vip = "1";
                }
            }
            $is_svip = '2';
            if(!empty($data['svip_passtime'])){
                if($data['svip_passtime'] > time()){
                    $is_svip = "1";
                }
            }
            $data['is_vip'] = $is_vip;
            $data['is_svip'] = $is_svip;
            //获取购买的vip省份
            $province_ids = [];
            $user_province = Db::name('user_province')->where(['user_id'=>$data['id'],'expiration_time'=>['gt',time()]])->select();
            foreach($user_province as $key => $u_p){
                $province_ids[] = $u_p['province_id'];
            }
            $data['province_ids'] = $province_ids;
        }
        return $data;
    }
    public function updateData($where,$data){
        $result = $this->where($where)->update($data);
        return $result;
    }
    public function insertData($data){
        $result = $this->insertGetId($data);
        return $result;
    }
    public function selectData($where){
        $where['status'] = ['eq',"normal"];
        $data = $this->where($where)->select();
        return $data;
    }
}