<?php

class HouseDao {
    public static function updateStatus($status,$houseId){
        global $wpdb;
        $result = $wpdb->update(Config::TOSPUR_HOUSE_TABLE,array(
            'status' => $status
        ),array(
            'id' => $houseId
        ));
        if($wpdb->last_error)
            return $wpdb->last_error;
        return $result;
    }

    public static function checkHouseStatus($houseId){
        global $wpdb;
        $result = $wpdb->get_row(Config::TOSPUR_HOUSE_TABLE,array(
            'id' => $houseId
        ));
        if($wpdb->last_error)
            return $wpdb->last_error;
        return $result;
    }

    public static function houseAllotConsultant($consultant_id, $house_ids)
    {
        if ($consultant_id) {
            $string = '(' . implode(',', array_map('intval', $house_ids)) . ')';
            global $wpdb;
            $result = $wpdb->query('update ' . Config::A_HOUSE_USER_TABLE
                . ' SET user_id = ' . $consultant_id
                . ' where house_id in ' . $string);
            if($result){
                echo '<script>alert("分配置业顾问成功");</script>';
            }
        }
    }
}