<?php
/**
 * 跨平台CRM的接口函数
 *
 */
class API_Crm{
    /**
     * 用户数据入CRM
     * 3.0的入口程序
     *
     * $data = array(
     *  'mobile' => '',  //报名的手机(必填)
     *  'activefrom' => '',  //活动来源(必填)
     *  'city' => '',  //报名的城市(必填)
     *  'activename' => '',  //活动名称(必填)
     *  'bbsname' => '',  //报名的bbsname
     *  'username' => '',  //报名的姓名
     *  'loupanids' => '',  //意向楼盘
     *  'bankuai' => '',  //意向板块
     *  'qushu' => '',  //意向区属
     *  'total' => '',  //意向总价
     *  'meters' => '',  //意向面积
     *  'joinremark' => '',  //报名备注
     *  'begtime' => '',  //活动开始时间
     *  'endtime' => '',  //活动结束时间
     *  'otherinfo' => array(  //附加信息
     *      'sex' => '',  //性别 1男 2 女
     *      'tel' => '',  //电话
     *      'idcard' => '',  //身份证
     *      'email' => '',  //邮箱
     *      'memcard' => '',  //卡号
     *  ),
     * );
     * @param array $data
     * 
     * @example API_Crm::joinCrm($data);
     */
    static public function joinCrm( $data = array() ){
        if( !isset($data['mobile']) || !isset($data['activefrom']) || !isset($data['city']) || !isset($data['activename']) ){
            return false;
        }
        //如果是多楼盘，多楼盘要分次入CRM
        if( $data['loupanids'] ){
            $ids_arr = explode(',',$data['loupanids']);
            foreach ($ids_arr as $id){
                $data['loupanids'] = trim($id);
                //参数拼装
                $param_arr = array();
                foreach ($data as $key => $val){
                    if($val){
                        $param_arr[] = $key.'='.(is_array($val) ? serialize($val) : urlencode($val));
                    }
                }
                $param = implode('&',$param_arr);
                $url = API_PT_CRM3_SIMULATE_SEA."?".$param;
                $nocache=1;
            	$server = new Server(__CLASS__);
                $rs = $server->curl_get_contents($url);
                return $rs;
            }
        }else {
            //参数拼装
        	$param_arr = array();
            foreach ($data as $key => $val){
                if($val){
                    $param_arr[] = $key.'='.(is_array($val) ? serialize($val) : urlencode($val));
                }
            }
            $param = implode('&',$param_arr);
            //echo "http://crm.house365.com:81/index.php/Simulate/sea?".$param;die();
            $url = API_PT_CRM3_SIMULATE_SEA."?".$param;
            $nocache=1;
            $server = new Server(__CLASS__);
            $rs = $server->curl_get_contents($url);
            return $rs;
        }
    }
}