<?php
/**
 * 用户管理
 * $Id: user_edit_result.php,v 1.1 2016-9-22 09:58:31 cuixl Exp $
 * @author cuixl
 * @package manager.public_html
 */

// 底层包含
require_once("manager_include.inc");

// 登录检查
require_once("check_login.inc");

// 权限检查
if (!checkAuthority("ADMIN,MANAGER,STAFF")) {
	// エラー表示
	$layout_pages = array();
	$layout_pages["footer"] = "footer.inc";
	$layout_pages["top"] = "menu.inc";
	$layout_pages["middle"] = "error.inc";
	$message = "权限不足,请联系系统管理员。";
	require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/topmenutopsub_layout.inc");
	exit;
}

// 参数取得
$id = ParamUtil::getRequestString("id");
$action = ParamUtil::getRequestString("action");
$mobile = ParamUtil::getRequestString("mobile");
$nickname = ParamUtil::getRequestString("nickname");
$sex = ParamUtil::getRequestString("sex");
$wechat_no = ParamUtil::getRequestString("wechat_no");
$qq_no = ParamUtil::getRequestString("qq_no");
$status = ParamUtil::getRequestString("status");
$channel_no = ParamUtil::getRequestString("channel_no");
$account_id = ParamUtil::getRequestNumber("account_id", 0);

//新增添加
if($action == "new") {
	$user_mst = new UserMst();
	$user_mst->mobile = $mobile;
	$user_mst->nickname = $nickname;
	$user_mst->sex = $sex;
	$user_mst->wechat_no = $wechat_no;
	$user_mst->qq_no = $qq_no;
	$user_mst->status = $status;
	$user_mst->channel_no = $channel_no;
	$user_mst->account_id = $account_id;

	//如果已经登陆,不再重复登陆
	$user_list_mobile = Array();
	$user_list_wechat = Array();
	if(!empty($mobile)) {
		$param = array();
		$param["mobile"] = $mobile;
		$param["delete_flg"] = false;
		$user_list = UserMst::getList($param);
	}
	if(!empty($wechat_no)) {
		$param = array();
		$param["wechat_no"] = $wechat_no;
		$param["delete_flg"] = false;
		$user_list_wechat = UserMst::getList($param);
	}
	if (empty($user_list_mobile) && empty($user_list_mobile)) {
		$user_mst->save();
	}
}
//资料编辑
if($action == "edit") {
	$user_mst = UserMst::getById($id);
	$user_mst->mobile = $mobile;
	$user_mst->nickname = $nickname;
	$user_mst->nickname = $nickname;
	$user_mst->sex = $sex;
	$user_mst->wechat_no = $wechat_no;
	$user_mst->qq_no = $qq_no;
	$user_mst->status = $status;
	$user_mst->channel_no = $channel_no;
	if($account_id > 0) {
		$user_mst->account_id = $account_id;
	}
	$user_mst->save();
}

header("Location:ocean_user_list.php");
exit;