<?php
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--	Application Market Followup
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */


function funcMarketFollowupAddProcess($params){
	global $configs;
	global $db;

	$returns = array('success' => false, 'errorcode' => '400', 'data' => array());


	$returns = funcMarketFollowupAdd($params);

	$returns['msg'] = $configs['errors'][$returns['errorcode']] . (($returns['msg']) ? $returns['msg'] : '');
	return $returns;
}
function funcMarketFollowupAdd($params){
	global $configs;
	global $db;

	$returns = array('success' => false, 'errorcode' => '400', 'data' => array());

	/* 写入 */
	$inserts = array();
	if(isset($params['join_followup_m_customer_id']))$inserts['join_followup_m_customer_id'] = $params['join_followup_m_customer_id'];
	if(isset($params['join_followup_m_member_id']))$inserts['join_followup_m_member_id'] = $params['join_followup_m_member_id'];
	if(isset($params['m_followup_times']))$inserts['m_followup_times'] = $params['m_followup_times'];
	if(isset($params['m_followup_mode']))$inserts['m_followup_mode'] = $params['m_followup_mode'];
	if(isset($params['m_followup_content']))$inserts['m_followup_content'] = $params['m_followup_content'];
	if(isset($params['m_followup_attch']))$inserts['m_followup_attch'] = $params['m_followup_attch'];
	if(isset($params['m_followup_extend_json']))$inserts['m_followup_extend_json'] = $params['m_followup_extend_json'];
	if(isset($params['m_followup_addtimes']))$inserts['m_followup_addtimes'] = $params['m_followup_addtimes'];
	$sql = executeSQL($inserts, array('mode' => "insert", 'table' => "yx_market_followup"));
	$idx = execSQL($sql, "insertid");
	if($idx){
		$returns['success'] = true;
		$returns['errorcode'] = "200";
		$returns['data'] = array('m_followup_id' => $idx);
	}

	$returns['msg'] = $configs['errors'][$returns['errorcode']] . (($returns['msg']) ? $returns['msg'] : '');
	return $returns;
}
function funcMarketFollowupUpdProcess($params){
	global $configs;
	global $db;

	$returns = array('success' => false, 'errorcode' => '400', 'data' => array());


	$returns = funcMarketFollowupUpd($params);

	$returns['msg'] = $configs['errors'][$returns['errorcode']] . (($returns['msg']) ? $returns['msg'] : '');
	return $returns;
}
function funcMarketFollowupUpd($params){
	global $configs;
	global $db;

	$returns = array('success' => false, 'errorcode' => '400', 'data' => array());

	/* 写入 */
	$data = array();
	if(isset($params['join_followup_m_customer_id']))$data['join_followup_m_customer_id'] = $params['join_followup_m_customer_id'];
	if(isset($params['join_followup_m_member_id']))$data['join_followup_m_member_id'] = $params['join_followup_m_member_id'];
	if(isset($params['m_followup_times']))$data['m_followup_times'] = $params['m_followup_times'];
	if(isset($params['m_followup_mode']))$data['m_followup_mode'] = $params['m_followup_mode'];
	if(isset($params['m_followup_content']))$data['m_followup_content'] = $params['m_followup_content'];
	if(isset($params['m_followup_attch']))$data['m_followup_attch'] = $params['m_followup_attch'];
	if(isset($params['m_followup_extend_json']))$data['m_followup_extend_json'] = $params['m_followup_extend_json'];
	if(isset($params['m_followup_addtimes']))$data['m_followup_addtimes'] = $params['m_followup_addtimes'];

	if(!isset($params['wheres'])){
		$params['wheres'] = "m_followup_id = " . $params['m_followup_id'];
	}

	$sql = executeSQL($data, array('mode' => "update", 'table' => "yx_market_followup", 'where' => $params['wheres']));
	if(execSQL($sql)){
		$returns['success'] = true;
		$returns['errorcode'] = "200";
	}

	$returns['msg'] = $configs['errors'][$returns['errorcode']] . (($returns['msg']) ? $returns['msg'] : '');
	return $returns;
}
function funcMarketFollowupDelProcess($params){
	global $configs;
	global $db;

	$returns = array('success' => false, 'errorcode' => '400', 'data' => array());


	$returns = funcMarketFollowupDel($params);

	$returns['msg'] = $configs['errors'][$returns['errorcode']] . (($returns['msg']) ? $returns['msg'] : '');
	return $returns;
}
function funcMarketFollowupDel($params){
	global $configs;
	global $db;

	$returns = array('success' => false, 'errorcode' => '400', 'data' => array(), 'page' => array());

	/* 执行 */	
	$sql  = "delete from yx_market_followup ";
	if(!isset($params['wheres'])){
		$sql .= "where m_followup_id = " . $params['m_followup_id'];
	}else{
		$sql .= "where " . $params['wheres'];
	}

	if(execSQL($sql)){
		$returns['success'] = true;
		$returns['errorcode'] = "200";
	}
	$returns['msg'] = $configs['errors'][$returns['errorcode']] . (($returns['msg']) ? $returns['msg'] : '');
	return $returns;
}
function funcMarketFollowupRead($params){
	global $configs;
	global $db;

	$returns = array('success' => false, 'errorcode' => '401', 'data' => array(), 'page' => array());

	$sql = "select * from yx_market_followup";

	/* 查询条件 */
	if(isset($params['m_followup_id']) && $params['m_followup_id']){
		$wheres = " m_followup_id = " . $params['m_followup_id'];
	}else{
		$wheres = " (m_followup_id > 0 or m_followup_id is null)";
	}

	if(isset($params['join_followup_m_customer_id'])){
		$wheres .= " and (join_followup_m_customer_id = " . $params["join_followup_m_customer_id"] . ")";
	}

	if(isset($params['join_followup_m_member_id'])){
		$wheres .= " and (join_followup_m_member_id = " . $params["join_followup_m_member_id"] . ")";
	}

	if(isset($params['m_followup_times'])){
		$wheres .= " and (m_followup_times = '" . $params['m_followup_times'] . "')";
	}

	if(isset($params['m_followup_mode'])){
		$wheres .= " and (m_followup_mode = '" . $params['m_followup_mode'] . "')";
	}

	if(isset($params['m_followup_content'])){
		$wheres .= " and (m_followup_content = '" . $params['m_followup_content'] . "')";
	}

	if(isset($params['m_followup_attch'])){
		$wheres .= " and (m_followup_attch = '" . $params['m_followup_attch'] . "')";
	}

	if(isset($params['m_followup_extend_json'])){
	}

	/* 外部其他条件 */
	if(isset($params['wheres']) && $params['wheres']){
		$wheres .= " and " . $params['wheres'];
	}

	/* 排序设置 */
	if(isset($params['orderby']) && $params['orderby']){
		$orders = " order by " . $params['orderby'];
	}else{
		$orders = " order by m_followup_id desc";
	}

	/* 监测并获取规范数据 */
	$pagecount       = (isset($params['pagecount']) && $params['pagecount']) ? $params['pagecount'] : $configs['database']['config']['pagecount'];
	$returns['page'] = doPage($sql, $wheres);
	if($returns['page']['counts'] > 0){
		/* 当前页码 */
		$returns['page']['current'] = (isset($params['pageno'])) ? $params['pageno'] : 1;
		$limits = doPageSQL(array('pageno' => $params['pageno'], 'pagecount' => $pagecount, 'limit' => $params['limit']));

		if($returns['page']['counts'] > 0){
			/* 具备数据 */
			$dataSQL = "select * from (" . $sql . ") data where " . $wheres . $orders . $limits;
	
			$returns['data'] = doSQL($dataSQL);
	
			$returns['data'] = funcFormatResultData(array('data' => $returns['data'], 'datafield' => '', 'datatimes' => ''));
	
			$returns['success'] = true;
			$returns['errorcode'] = "200";
		}
	}
	//$returns['sql'] = "select * from (" . $sql . ") data where " . $wheres . $orders . $limits;

	$returns['msg'] = $configs['errors'][$returns['errorcode']];
	return $returns;
}



?>