<?php
/*
@author waychar
@技术支持 150572314@qq.com
@copyright 2018 waychar.cn 声明：本代码可以用于学习交流使用及要商业化用途
*/
class ajax extends db
{
    public function get_dashboard_new_msg()
    {
        $to_user_id = $_COOKIE['id'];
        $sql = "SELECT w.fullname, m.to_user_id,m.from_user_id,  m.content,  m.create_time,  m.msg_type FROM msg m left join w_user w on w.id = m.from_user_id WHERE  m.to_user_id = $to_user_id limit 5";
        $result = $this->get_data($sql);
        return $result;
    }

    public function get_new_msg($from_user_id)
    {
        $sql = "SELECT w.fullname, m.to_user_id,  m.content,  m.create_time,  m.msg_type FROM msg m left join w_user w on w.id = m.from_user_id WHERE (m.from_user_id = $from_user_id and m.to_user_id =$to_user_id) order by create";
    }

    public function check_talk_mapping($to_user_id, $from_user_id)
    {
        $sql = "select id,mapping_id_1 from talk_mapping where  (mapping_id_1 =$to_user_id  and mapping_id_2 =$from_user_id ) or   (mapping_id_2 =$to_user_id  and mapping_id_1 =$from_user_id ) ";
        $result = $this->get_data($sql);
        return $result[0];
    }

    //update talk mapping update status
    public function talk_mapping_update($from_user_id, $status)
    {
        //check mapping
        $sql = "select id,mapping_id_1,mapping_id_2,last_update_finish_1,last_update_finish_2 from talk_mapping where (mapping_id_1 = $from_user_id and  mapping_id_2 = $to_user_id) or (mapping_id_2 = $from_user_id and  mapping_id_1 = $to_user_id)  ";
        $result = $this->get_data($sql);

        if ($result[0]['mapping_id_1'] == $to_user_id) {
            $sql = "update talk_mapping set last_update_finish_2 = 0,last_update_2 =$time  where id = " . $result[0]['id'];
        } else {
            $sql = "update talk_mapping set last_update_finish_1 = 0,last_update_1 =$time where id = " . $result[0]['id'];
        }
        $this->query($sql);
    }

}