<%@ 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;
|
using System.IO;
|
using Newtonsoft.Json;
|
|
|
|
|
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 "loadGwClientAllPageList":
|
return LoadGwClientAllPageList(context);
|
//确定推送
|
case "saveClientProduct":
|
return SaveClientProduct(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 Dao.GwClientProductDao gwClientProductDao = new Dao.GwClientProductDao();
|
private Dao.SysXhDao sysXhDao = new Dao.SysXhDao();
|
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 Company = context.GetString("Company");
|
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, Company, ClientName, Telephone, Agent);
|
|
if (list != null && list.Count > 0)
|
{
|
foreach (Model.GwClient item in list)
|
{
|
string Certification_StatusResult = "未认证";
|
if (item.Certification_Status == 1)
|
{
|
Certification_StatusResult = "已认证";
|
}
|
str += @"<tr ><td>" + item.ClientID + "</td><td>" + item.Company + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" + item.Top_up_Amount_Total + "元</td><td>" + item.Agent + "</td><td>" + Certification_StatusResult + "</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 });
|
}
|
|
|
/// <summary>
|
/// 加载待推送产品的代理商账号列表
|
/// </summary>
|
/// <param name="context"></param>
|
/// <returns></returns>
|
private JsonPageResult LoadGwClientAllPageList(PageContext<Model.SysUser> context)
|
{
|
int pageIndex = context.GetInt("pageIndex", 1);
|
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, null, null, null, null, null);
|
|
if (list != null && list.Count > 0)
|
{
|
foreach (Model.GwClient item in list)
|
{
|
string Certification_StatusResult = "未认证";
|
if (item.Certification_Status == 1)
|
{
|
Certification_StatusResult = "已认证";
|
}
|
str += "<tr><td rowspan=\"1\" ><input type=\"checkbox\"name=\"checkbox\" value=\"" + item.ClientID + "\"/></td>" ;
|
str += @"<td>" + item.ClientID + "</td><td>" + item.Company + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" + item.Top_up_Amount_Total + "元</td><td>" + item.Agent + "</td><td>" + Certification_StatusResult + "</td>";
|
|
str += @"</tr>";
|
}
|
}
|
else
|
{
|
str += @"<tr><td colspan=""8"">暂无信息</td></tr>";
|
}
|
|
}
|
return new JsonPageResult(true, new { Table = str.ToString(), TotalCount = recordCount });
|
}
|
|
//确定推送
|
private JsonPageResult SaveClientProduct(PageContext<Model.SysUser> context)
|
{
|
string product_id = context.GetString("product_id");
|
if (string.IsNullOrEmpty(product_id))
|
throw new ArgumentException("请选择要分配的产品!");
|
|
foreach (string clientId in JsonConvert.DeserializeObject<string[]>(context.GetString("idArray"))) {
|
if(gwClientProductDao.IsClientProductExists(clientId, product_id))
|
{
|
continue;
|
}else {
|
Model.GwClientProduct gwClientProduct = new Model.GwClientProduct();
|
string client_product_id = sysXhDao.getXh("GW_CLIENT_PRODUCT");
|
gwClientProduct.client_product_id = client_product_id;
|
gwClientProduct.client_id = clientId;
|
gwClientProduct.product_id = product_id;
|
gwClientProduct.activate_status = 0;
|
|
//保存产品分配给账户
|
this.gwClientProductDao.Add(gwClientProduct);
|
}
|
}
|
return new JsonPageResult(true, (object)"确定分配账户产品成功!");
|
}
|
|
|
//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 company = context.GetString("company");
|
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("客户账号已经存在!");
|
}
|
|
HttpFileCollection _file = HttpContext.Current.Request.Files;
|
if (_file.Count > 0)
|
{
|
long size = _file[0].ContentLength; //文件大小
|
string type = _file[0].ContentType; //文件类型
|
string name = _file[0].FileName; //文件名
|
string _tp = Path.GetExtension(name);//文件扩展名
|
if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png")
|
{
|
Stream stream = _file[0].InputStream;//获取文件流
|
string savaName = clientID + "-" + DateTime.Now.ToString("yyyyMMddHHssmm") + _tp; //保存文件。文件名
|
string filepath = "\\UploadFile\\" + savaName;
|
string path = AppDomain.CurrentDomain.BaseDirectory + filepath;//图片路径
|
_file[0].SaveAs(path);
|
|
try
|
{
|
//创建审核通过的记录
|
Model.GwClientCertification gwClientCertification = new Model.GwClientCertification();
|
gwClientCertification.Client_ID = clientID;
|
gwClientCertification.Certificate_Path = path;
|
gwClientCertification.Client_Classes = 0;//类型:0-企业、1-个人
|
gwClientCertification.Audit_Status = 1;//审核状态,0-待审核,1-通过,2-不通过
|
gwClientCertification.Certification_Time = DateTime.Now;//认证审核时间
|
gwClientCertification.Operator = context.OperatorID;//操作审核人
|
gwClientCertification.Upload_Time = DateTime.Now;//上传时间
|
gwClientCertification.Remark = "管理后台操作创建";
|
|
//保存审核记录
|
GwClientCertificationDao certificationDao = new GwClientCertificationDao();
|
certificationDao.Insert(gwClientCertification);
|
}
|
catch (Exception ex)
|
{
|
return new JsonPageResult(false, "上传图片处理异常:" + ex.Message);
|
}
|
}
|
}
|
|
|
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;
|
client.Certification_Status = 1;
|
client.Company = company;
|
_Dao.Add(client);//插入数据库。创建账户
|
|
return new JsonPageResult(true, "创建账户成功!");
|
}
|
}
|
|
|
|
|
|
|