<%@ WebHandler Language="C#" Class="GwClientHandler" %>
|
using System;
|
using System.Web;
|
using Dao;
|
using Common;
|
|
using System.Collections.Generic;
|
using System.Configuration;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
|
|
|
public class GwClientHandler : PageHandler<Model.SysUser>
|
{
|
public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
|
{
|
string action = context.GetString("action");
|
|
switch (action)
|
{
|
case "clientSpList":
|
return this.GetGwspList(context);
|
|
case "loadGwClientPageList":
|
return LoadGwClientPageList(context);
|
case "save":
|
return Save(context);
|
|
case "delete":
|
return Delete(context);
|
|
case "update":
|
return Update(context);
|
|
case "get":
|
return Get(context);
|
|
case "getWhite":
|
return GetWhite(context);
|
|
case "getBlack":
|
return GetBlack(context);
|
|
case "updateWhite":
|
return UpdateWhite(context);
|
|
case "updateBlack":
|
return UpdateBlack(context);
|
|
default:
|
throw new Exception("Invalid Action=" + action);
|
}
|
}
|
private Dao.GwClientDao _Dao = new Dao.GwClientDao();
|
private GwSpDao _GwSpDao = new GwSpDao();
|
|
|
/// <summary>
|
/// 加载代理商账号列表
|
/// </summary>
|
/// <param name="context"></param>
|
/// <returns></returns>
|
private JsonPageResult LoadGwClientPageList(PageContext<Model.SysUser> context)
|
{
|
string ClientID = context.GetString("ClientID");
|
string ClientName = context.GetString("ClientName");
|
string Telephone = context.GetString("Telephone");
|
int pageIndex = context.GetInt("pageIndex", 1);
|
|
string Agent = context.GetString("Agent");
|
int recordCount = 0;
|
int pageSize = context.GetInt("pageSize", 20);
|
string serverIp = ConfigurationManager.AppSettings["serverIp"];
|
string clientPort = ConfigurationManager.AppSettings["clientPort"];
|
string str = "";
|
using (GwClientDao dao = new GwClientDao())
|
{
|
var list = dao.LoadInfoList(out recordCount, pageIndex, pageSize, ClientID, ClientName, Telephone, Agent);
|
|
if (list != null && list.Count > 0)
|
{
|
foreach (Model.GwClient item in list)
|
{
|
str += @"<tr ><td>" + item.ClientID + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" +item.TotalAmount / 1000 + "元/" + item.Balance / 1000 + "元</td><td>" + item.Agent + "</td><td>" + item.Remark + "</td>";
|
|
str += @"<td>";
|
string loginStr = "http://" + serverIp + ":" + clientPort + "/Attachedlogin.aspx?action=Attachedlogin&account=" + item.Account + "&password=" + item.Password;
|
str += string.Format("<a class=\"action-modal-login btn btn-success btn-xs \" href=\"{0}\" data-id=\"{1}\" target=\"_blank\">", (object)loginStr, (object)item.ClientID);
|
str += " 登录</a> ";
|
|
str += string.Format(@"<a class=""action-modal-edit btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
|
str += @"编辑";
|
str += @"</a> ";
|
|
str += string.Format(@"<a class=""action-modal-white btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
|
str += @"白名单";
|
str += @"</a> ";
|
|
str += string.Format(@"<a class=""action-modal-black btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
|
str += @"黑名单";
|
str += @"</a> ";
|
|
str += string.Format(@"<a class=""action-delete btn btn-xs btn-default"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
|
str += @"删除";
|
str += @"</a>";
|
str += @"</td>";
|
str += @"</tr>";
|
}
|
}
|
else
|
{
|
str += @"<tr><td colspan=""8"">暂无信息</td></tr>";
|
}
|
|
}
|
return new JsonPageResult(true, new { Table = str.ToString(), TotalCount = recordCount });
|
}
|
|
//add 2017-10-21
|
|
private JsonPageResult GetGwspList(PageContext<Model.SysUser> context)
|
{
|
string clientID = context.GetString("clientID");
|
Model.GwClient gwClient = new GwClientDao().Get(clientID);
|
StringBuilder stringBuilder = new StringBuilder();
|
using (GwSpDao gwSpDao = new GwSpDao())
|
{
|
List<Model.GwSp> list = gwSpDao.LoadSpList(clientID);
|
if (list.Count != 0)
|
{
|
stringBuilder.AppendFormat("<option value=\"{0}\" selected>{1}</option>", (object)0, (object)"请选择账号");
|
foreach (Model.GwSp gwSp in list)
|
{
|
if (Convert.ToString(980001) == gwSp.SpID)
|
stringBuilder.AppendFormat("<option value=\"{0}\" selected>{1}-{2}</option>", (object)gwSp.SpID, (object)gwSp.ClientID, (object)gwSp.SpID);
|
else
|
stringBuilder.AppendFormat("<option value=\"{0}\">{1}-{2}</option>", (object)gwSp.SpID, (object)gwSp.ClientID, (object)gwSp.SpID);
|
}
|
}
|
}
|
return new JsonPageResult(true, (object)new
|
{
|
Datasp = stringBuilder.ToString(),
|
get = gwClient
|
});
|
}
|
|
//end
|
|
|
private JsonPageResult UpdateWhite(PageContext<Model.SysUser> context)
|
{
|
string clientID = context.GetString("clientID");
|
string mobileData = context.GetString("mobileData");
|
|
_Dao.UpdateWhiteList(clientID, mobileData);
|
|
return new JsonPageResult(true, "客户白名单保存成功!");
|
}
|
|
private JsonPageResult UpdateBlack(PageContext<Model.SysUser> context)
|
{
|
string clientID = context.GetString("clientID");
|
string mobileData = context.GetString("mobileData");
|
|
_Dao.UpdateBlackList(clientID, mobileData);
|
|
return new JsonPageResult(true, "客户黑名单保存成功!");
|
}
|
|
private JsonPageResult GetWhite(PageContext<Model.SysUser> context)
|
{
|
string clientID = context.GetString("clientID");
|
|
return new JsonPageResult(true, _Dao.GetWhiteList(clientID));
|
}
|
|
private JsonPageResult GetBlack(PageContext<Model.SysUser> context)
|
{
|
string clientID = context.GetString("clientID");
|
|
return new JsonPageResult(true, _Dao.GetBlackList(clientID));
|
}
|
|
/// <summary>
|
/// 通过账号名获取代理商信息
|
/// </summary>
|
/// <param name="context"></param>
|
/// <returns></returns>
|
private JsonPageResult Get(PageContext<Model.SysUser> context)
|
{
|
string clientID = context.GetString("clientID");
|
|
return new JsonPageResult(true, _Dao.Get(clientID));
|
}
|
|
private JsonPageResult Delete(PageContext<Model.SysUser> context)
|
{
|
string clientID = context.GetString("clientID");
|
|
if (string.IsNullOrEmpty(clientID))//add
|
throw new ArgumentException("你的账号信息获取失败!");//add
|
|
if (this._GwSpDao.ClientCount(clientID) > 0)//add
|
throw new ArgumentException("你删除的客户下有账号正在使用,请先删除此客户下正在使用的账号!");//add
|
|
_Dao.Delete(clientID);
|
|
return new JsonPageResult(true, "删除客户资料成功!");
|
}
|
|
|
/// <summary>
|
/// 保存客户资料
|
/// </summary>
|
/// <param name="context"></param>
|
/// <returns></returns>
|
private JsonPageResult Update(PageContext<Model.SysUser> context)
|
{
|
int id = Int32.Parse(context.GetString("id"));
|
string clientID = context.GetString("clientID");
|
string password = context.GetString("password");
|
string clientName = context.GetString("clientName");
|
string address = context.GetString("address");
|
string telephone = context.GetString("telephone");
|
string remark = context.GetString("remark");
|
string agent = context.GetString("agent");
|
string permissionData = Newtonsoft.Json.JsonConvert.SerializeObject(context.GetString("permissionData").Split(','));
|
|
if (string.IsNullOrEmpty(clientID))
|
{
|
throw new ArgumentException("客户账号不能为空,且必须为公司名称!");
|
}
|
|
if (string.IsNullOrEmpty(password) || !System.Text.RegularExpressions.Regex.IsMatch(password, @"[a-zA-Z0-9]{4,10}"))
|
{
|
throw new ArgumentException("客户密码不能为空,且必须为4-10位英文或数字字符组合!");
|
}
|
|
if (string.IsNullOrEmpty(clientName) || string.IsNullOrEmpty(telephone))
|
{
|
throw new ArgumentException("联系人/联系电话,不能为空!");
|
}
|
|
|
var client = new Model.GwClient();
|
|
client.Id = id;
|
client.ClientID = clientID;
|
client.Password = password;
|
client.ClientName = clientName;
|
client.Address = address;
|
client.Remark = remark;
|
client.Telephone = telephone;
|
client.Agent = agent;
|
client.PermissionData = permissionData;
|
|
_Dao.Update(client);
|
|
return new JsonPageResult(true, "修改客户资料成功!");
|
}
|
|
//创建新客户
|
private JsonPageResult Save(PageContext<Model.SysUser> context)
|
{
|
string clientID = context.GetString("clientID");
|
string password = context.GetString("password");
|
string clientName = context.GetString("clientName");
|
string address = context.GetString("address");
|
string telephone = context.GetString("telephone");
|
string remark = context.GetString("remark");
|
string agent = context.GetString("agent");
|
string permissionData = Newtonsoft.Json.JsonConvert.SerializeObject(context.GetString("permissionData").Split(','));
|
|
if (string.IsNullOrEmpty(clientID))
|
{
|
throw new ArgumentException("客户账号不能为空,且必须为公司名称!");
|
}
|
|
if (string.IsNullOrEmpty(password) || !System.Text.RegularExpressions.Regex.IsMatch(password, @"[a-zA-Z0-9]{4,10}"))
|
{
|
throw new ArgumentException("客户密码不能为空,且必须为4-10位英文或数字字符组合!");
|
}
|
|
if (string.IsNullOrEmpty(clientName))
|
{
|
throw new ArgumentException("客户名称不能为空!");
|
}
|
|
if (_Dao.IsIDExists(clientID))
|
{
|
throw new ArgumentException("客户账号已经存在!");
|
}
|
|
var client = new Model.GwClient();
|
client.ClientID = clientID;
|
client.Password = password;
|
|
client.ClientName = clientName;
|
client.Address = address;
|
client.Remark = remark;
|
client.Telephone = telephone;
|
client.Agent = agent;
|
client.PermissionData = permissionData;
|
client.ParentId = context.OperatorID;
|
|
_Dao.Add(client);
|
|
return new JsonPageResult(true, "创建客户成功!");
|
}
|
}
|
|
|
|
|
|
|