<?php

/**
 * 最近来访
 * 2020-4-21 10:45:15
 * 军师
*/

class userHistoryModule extends commonModule
{
    public function __construct()
    {
        parent::__construct("sl_user_history");
    }

    public function addHistory($data){
        //获取今天零点的时间
        $time = date('Y-m-d 00:00:00');
        //今天12点的时间
        $time1 = date("Y-m-d 23:59:59");
        //先查询该用户在今天是否访问过被访问的用户
//        $exist = $this->where(['user_number'=>$data['user_number'],'usered_number'=>$data['usered_number']])->one();
        $exist = $this->findBySql("select * from sl_user_history where user_number = '{$data['user_number']}' and usered_number
               = '{$data['usered_number']}' and  create_time > '{$time}' and create_time<'{$time1}'");
        if ($exist){
            $arr = $this->where(['id'=>$exist[0]['id']])->update(['create_time'=>date('Y-m-d H:i:s')]);
        }else{
            $arr = $this->insert($data);
        }
        return $arr;
    }
}