<?php

/**
 * Desc: 房源扩展信息
 * User: mellon
 * Date: 2023/5/11
 * Time: 15:19
 */
class sell_ext extends MY_Model
{
    public $table = 'sell_ext';

    public function __construct()
    {
        parent::__construct(1, 1, 0);
    }

    /**
     * 更新插入数据
     * @param $houseId
     * @param $data
     * @author mellon
     */
    public function dataModel($houseId, $data)
    {
        $standRemark = $data['stand_remark'] ? $data['stand_remark'] : '';
        $serviceRemark = $data['service_remark'] ? $data['service_remark'] : '';
        // 查询数据
        $this->dbback->from($this->table)->where('house_id', $houseId);
        $query = $this->dbback->get()->row();
        if (!empty($query)) {
            // 更新
            $this->db->where('house_id', $houseId);
            $this->db->update($this->table, array(
                'stand_remark' => $standRemark,
                'service_remark' => $serviceRemark,
            ));
        } else {
            // 插入
            $insert_data['house_id'] = $houseId;
            $insert_data['uid'] = $data['uid'] ? $data['uid'] : 0;
            $insert_data['telno'] = $data['telno'] ? $data['telno'] : '';
            $insert_data['create_time'] = date('Y-m-d H:i:s');
            $insert_data['ip'] = get_ip();
            $insert_data['stand_remark'] = $standRemark;
            $insert_data['service_remark'] = $serviceRemark;
            $this->db->insert($this->table, $insert_data);
        }
    }

    /**
     * 获取房源扩展信息
     * @param $houseId
     * @return mixed
     * @author mellon
     */
    public function getSellExt($houseId)
    {
        $this->dbback->from($this->table)->where('house_id', $houseId);
        return $this->dbback->get()->row_array();
    }

}