<?php 
if (!defined('BASEPATH'))
    exit('No direct script access allowed');


class ding_login_model extends CI_Model {
	
	function __construct(){
        parent::__construct();
        $this->HT = $this->load->database('HT', TRUE);
    }
	
	public function addorupdateuser($data){
		$sql = "
			IF NOT EXISTS(
				select * from Dingding_User where ddu_Unionid = ?
			)
				INSERT INTO Dingding_User (ddu_Name,ddu_Unionid,ddu_Mobile,ddu_Email,ddu_Position,ddu_Avatar,ddu_Datetime) VALUES (N?,?,?,?,N?,?,?)
			
			ELSE
				UPDATE Dingding_User SET 
										ddu_Name = N?,
										ddu_Mobile = ?,
										ddu_Email = ?,
										ddu_Position = N?,
										ddu_Avatar = ?,
										ddu_Datetime = ?
								WHERE ddu_Unionid = ?
		";
		$query = $this->HT->query($sql,array($data['unionid'],$data['name'],$data['unionid'],$data['mobile'],$data['orgEmail'],$data['position'],$data['avatar'],$data['datetime'],$data['name'],$data['mobile'],$data['orgEmail'],$data['position'],$data['avatar'],$data['datetime'],$data['unionid']));
	}
}

?>