yzh
2022-05-13 4ced58ce6d3cfd703de419a0a30945acd01295c8
web/web/GwClient.ashx
@@ -2,17 +2,23 @@
using System;
using System.Web;
using Dao;
using Model;
using Common;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
public class GwClientHandler : PageHandler<Model.SysUser>
{
    private UserDao _SysUserDao = new UserDao();
    private List<SysUser> _SysUserList;
    public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
    {
        string action = context.GetString("action");
@@ -21,7 +27,7 @@
        {
            case "clientSpList":
                return this.GetGwspList(context);
            case "loadGwClientPageList":
                return LoadGwClientPageList(context);
            case "save":
@@ -55,7 +61,7 @@
    private Dao.GwClientDao _Dao = new Dao.GwClientDao();
    private GwSpDao _GwSpDao = new GwSpDao();
    /// <summary>
    /// 加载代理商账号列表
    /// </summary>
@@ -77,12 +83,21 @@
        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>";
                    string Certification_StatusResult = "未认证";
                    if (item.Certification_Status == 1)
                    {
                        Certification_StatusResult = "已认证";
                    }
                    //edit:yangzh by 20220511
                    //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 += @"<tr ><td>" + item.ClientID + "</td><td>" + item.Company + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" + item.Balance/1000 + "元</td><td>" + item.Top_up_Amount_Total/1000 + "元</td><td>" + item.Agent + "</td><td>" + Certification_StatusResult + "</td>";
                    str += @"<tr ><td>" + item.ClientID + "</td><td>" + item.Company + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" + item.Balance/1000 + "元</td><td>" + item.Top_up_Amount_Total/1000 + "元</td><td>" + SysUserName(string.IsNullOrEmpty(item.Agent)? 0: int.Parse(item.Agent) ) + "</td><td>" + Certification_StatusResult + "</td>";
                    str += @"<td>";
                    string loginStr = "http://" + serverIp + ":" + clientPort + "/Attachedlogin.aspx?action=Attachedlogin&account=" + item.Account + "&password=" + item.Password;
@@ -112,13 +127,15 @@
            {
                str += @"<tr><td colspan=""8"">暂无信息</td></tr>";
            }
        }
        return new JsonPageResult(true, new { Table = str.ToString(), TotalCount = recordCount });
    }
    //add 2017-10-21
    //add 2017-10-21
    private JsonPageResult GetGwspList(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
@@ -145,10 +162,10 @@
            get = gwClient
        });
    }
    //end
    private JsonPageResult UpdateWhite(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
@@ -210,7 +227,7 @@
        return new JsonPageResult(true, "删除客户资料成功!");
    }
    /// <summary>
    /// 保存客户资料
    /// </summary>
@@ -220,13 +237,23 @@
    {
        int id = Int32.Parse(context.GetString("id"));
        string clientID = context.GetString("clientID");
        string company = context.GetString("company");
        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(','));
        string data = context.GetString("permissionData");
        if(data.Contains("1"))
        {
            data += ",sp.aspx,GwTaskSmssend,SpPrePattern.aspx";
        }
        if(data.Contains("2"))
        {
            data += ",molog.aspx,mtlog.aspx#stat,mtlog.aspx,statis.aspx";
        }
        string permissionData = Newtonsoft.Json.JsonConvert.SerializeObject(data.Split(','));
        if (string.IsNullOrEmpty(clientID))
        {
@@ -243,12 +270,26 @@
            throw new ArgumentException("联系人/联系电话,不能为空!");
        }
        string savePassword = "";
        if (!string.IsNullOrEmpty(clientID))
        {
            GwClient gwClient = this._Dao.Get(clientID);
            savePassword = (gwClient.Password == password ? gwClient.Password : DataHelper.MD5Hex(password) );
        }
        else
        {
            savePassword = DataHelper.MD5Hex(password);
        }
        var client = new Model.GwClient();
        client.Id = id;
        client.ClientID = clientID;
        client.Password = password;
        client.Company = company;
        //client.Password = password;
        client.Password = savePassword;
        client.ClientName = clientName;
        client.Address = address;
        client.Remark = remark;
@@ -261,7 +302,7 @@
        return new JsonPageResult(true, "修改客户资料成功!");
    }
    //创建新客户
    ///创建新客户
    private JsonPageResult Save(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
@@ -271,7 +312,17 @@
        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(','));
        string company = context.GetString("company");
        string data = context.GetString("permissionData");
        if(data.Contains("1"))
        {
            data += ",sp.aspx,GwTaskSmssend,SpPrePattern.aspx";
        }
        if(data.Contains("2"))
        {
            data += ",molog.aspx,mtlog.aspx#stat,mtlog.aspx,statis.aspx";
        }
        string permissionData = Newtonsoft.Json.JsonConvert.SerializeObject(data.Split(','));
        if (string.IsNullOrEmpty(clientID))
        {
@@ -283,20 +334,71 @@
            throw new ArgumentException("客户密码不能为空,且必须为4-10位英文或数字字符组合!");
        }
        if (string.IsNullOrEmpty(clientName))
        if (string.IsNullOrEmpty(clientName) || string.IsNullOrEmpty(telephone))
        {
            throw new ArgumentException("客户名称不能为空!");
            throw new ArgumentException("联系人/联系电话,不能为空!");
        }
        //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);
                }
            }
            else
            {
                throw new ArgumentException("文件格式错误,请确认是否为jpg|jpeg|gif|png。");
            }
        }
        //密码加密
        password = DataHelper.MD5Hex(password);
        var client = new Model.GwClient();
        client.ClientID = clientID;
        client.Password = password;
        client.ClientName = clientName;
        client.Address = address;
        client.Remark = remark;
@@ -304,12 +406,64 @@
        client.Agent = agent;
        client.PermissionData = permissionData;
        client.ParentId = context.OperatorID;
        _Dao.Add(client);
        client.Certification_Status = 1;
        client.Company = company;
        _Dao.Add(client);//插入数据库。创建账户
        return new JsonPageResult(true, "创建客户成功!");
        //保存产品记录
        //获取启用的默认的产品
        /**
        //edit:在客户激活时添加记录
        List<string> defaultProductList = GwProductDao.Instance.GetDefaultProduct();
        if (defaultProductList.Count > 0)
        {
            foreach (string productId in defaultProductList)
            {
                GwClientProduct gcp = new GwClientProduct();
                gcp.Id = Guid.NewGuid().ToString();
                gcp.ClientId = clientID;
                gcp.ProductId = productId;
                GwClientProductDao.Instance.Add(gcp);
            }
        }
        **/
        return new JsonPageResult(true, "创建账户成功!");
    }
}
    //获取管理端账户列表
    private List<SysUser> SysUserList
    {
        get
        {
            if (this._SysUserList == null)
            {
                using (UserDao sysUserDao = new UserDao())
                {
                    int recordCount = 0;
                    int int1 = 999999999;
                    int int2 = 1;
                    this._SysUserList = sysUserDao.LoadInfoList(out recordCount, int1, int2);
                }
            }
            return this._SysUserList;
        }
    }
    //管理端账户名称
    private string SysUserName(int userId)
    {
        if (this.SysUserList == null)
            return string.Empty;
        SysUser sysUser = this._SysUserList.Find((Predicate<SysUser>)(bean => bean.UserID == userId));
        if (sysUser != null)
            return string.Format("{0}-{1}", (object)sysUser.UserID, (object)sysUser.UserName);
        return string.Empty;
    }
}