| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- using CallCenter.Utility;
- using CallCenterApi.DB;
- using CallCenterApi.Interface.Controllers.Base;
- using CallCenterApi.Interface.App_Start;
- using CallCenterAPI.WechatSDK;
- using CallCenterAPI.WechatSDK.Models;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Transactions;
- using System.IO;
- namespace CallCenterApi.Interface.Controllers.weixin
- {
- public class WxLoginController : BaseController
- {
- private readonly BLL.T_Sys_UserAccount userAccountBLL = new BLL.T_Sys_UserAccount();
- /// <summary>
- /// 绑定微信号
- /// </summary>
- /// <param name="login"></param>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult Login(WxLoginDto login)
- {
- Dictionary<string, string> paras = new Dictionary<string, string>();
- string sql = " select * from T_Sys_UserAccount where F_UserCode=@F_UserCode and F_PassWord=@F_PassWord ";
- paras.Add("@F_UserCode", login.UserCode);
- paras.Add("@F_PassWord", login.Password);
- var dt = DbHelperSQL.Query(sql, paras).Tables[0];
- if (dt != null)
- {
- var user = userAccountBLL.GetModel(login.UserCode);
- user.F_WxOpenId = login.OpenId;
- if (userAccountBLL.Update(user))
- {
- return Success("绑定成功");
- }
- else
- {
- return Error("绑定失败");
- }
- }
- else
- {
- return Error("账号或密码错误,请重新登录");
- }
- }
- /// <summary>
- /// 获取微信openid
- /// </summary>
- /// <param name="login"></param>
- /// <returns></returns>
- public ActionResult GetOpenId(WxLoginDto wld)
- {
- wld.RedirectUrl = RequestString.GetUrlReferrer();
- if (string.IsNullOrEmpty(wld.OpenId))
- {
- var temp = WxHelper.GetOpenId(wld);
- if (string.IsNullOrWhiteSpace(temp.OpenId))
- {
- return Redirect("请求", temp.RedirectUrl);
- }
- wld.OpenId = temp.OpenId;
- }
- var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
- if (model == null)
- {
- model = new Model.T_Sys_Users();
- model.F_OpenId = wld.OpenId;
- model.F_Type = 1;
- model.F_CreateTime = DateTime.Now;
- new BLL.T_Sys_Users().Add(model);
- }
- return Success("成功", wld.OpenId);
- }
- #region 工单相关
- /// <summary>
- /// 获取工单列表
- /// </summary>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult GetList()
- {
- DataTable dt = new DataTable();
- //string sql = " and F_IsDelete=0 ";
- string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
- string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));//状态
- string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));//联系人
- string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));//联系电话
- string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));//关键字
- string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
- string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
- string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));//工单编号
- string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));//创建人工号
- string source = HttpUtility.UrlDecode(RequestString.GetQueryString("source"));//工单来源
- string infotype = HttpUtility.UrlDecode(RequestString.GetQueryString("infotype"));//信息分类
- string strpageindex = RequestString.GetQueryString("page");
- int pageindex = 1;
- string strpagesize = RequestString.GetQueryString("pagesize");
- int pagesize = 10;
- #region sql 语句相关处理
- //根据openid获取所有工单号
- var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
- string sql = " and id in (select distinct F_WorkOrderID from T_WO_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') ";
- if (strstate.Trim() != "" && strstate != "undefined")
- {
- sql += " and State = '" + strstate.Trim() + "' ";
- }
- if (strworkid.Trim() != "" && strworkid != "undefined")
- {
- sql += " and WorkOrderID like '%" + strworkid + "%' ";
- }
- if (strname.Trim() != "" && strname != "undefined")
- {
- sql += " and Customer like '%" + strname + "%' ";
- }
- if (strtel.Trim() != "" && strtel != "undefined")
- {
- sql += " and (CustomerTel like '%" + strtel + "%' ) ";
- }
- if (strkey.Trim() != "" && strkey != "undefined")
- {
- sql += " and (Title like '%" + strkey + "%' or Detail like '%" + strkey + "%') ";
- }
- if (strusercode.Trim() != "" && strusercode != "undefined")
- {
- sql += " and CreateUser = '" + strusercode + "' ";
- }
- if (infotype.Trim() != "" && infotype != "undefined")
- {
- sql += " and InfoTypeID = " + infotype + " ";
- }
- if (source.Trim() != "" && source != "undefined")
- {
- sql += " and Source = '" + source + "' ";
- }
- if (strstarttime.Trim() != "" && strstarttime != "undefined")
- {
- sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
- }
- if (strendtime.Trim() != "" && strendtime != "undefined")
- {
- sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
- }
- #endregion
- if (strpageindex.Trim() != "")
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- if (strpagesize.Trim() != "")
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- string cols = "*,dbo.GetUserName(CreateUser) as UserName";
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_Wo_WorkOrder",
- "WorkOrderID",
- cols,
- sql,
- "ORDER BY CreateTime DESC",
- pagesize,
- pageindex,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 新增工单
- /// </summary>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult AddWorkOrder()
- {
- DataTable dt = new DataTable();
- string cusname = RequestString.GetFormString("cusname");
- string cusphone = RequestString.GetFormString("cusphone");//GetFormString
- string content = RequestString.GetFormString("content");
- string files = RequestString.GetFormString("files");
- int type = RequestString.GetInt("type", 3);//默认为3投诉建议
- string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
- var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
- workorder.WorkOrderController wo = new workorder.WorkOrderController();
- string workorderid = wo.AddWorkOrders(type, cusname, cusphone, content, files);
- if (string.IsNullOrEmpty(workorderid))
- {
- return Error("新增失败");
- }
- else
- {
- Model.T_WO_UserWorkOrder tbu = new Model.T_WO_UserWorkOrder();
- tbu.F_UserId = wxuser.F_Id;
- tbu.F_WorkOrderId = workorderid;
- new BLL.T_WO_UserWorkOrder().Add(tbu);
- return Success("新增成功", workorderid);
- }
- }
- /// <summary>
- /// 处理工单
- /// </summary>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult DealWorkOrder()
- {
- DataTable dt = new DataTable();
- string orderid = RequestString.GetFormString("orderid");
- string clcont = HttpUtility.UrlDecode(RequestString.GetFormString("clcont"));
- int isaudit = RequestString.GetFormInt("isaudit", 0);
- int infotypeid = RequestString.GetFormInt("infotypeid", 0);
- int unitid = RequestString.GetFormInt("unitid", 0);
- string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
- workorder.WorkOrderController wo = new workorder.WorkOrderController();
- bool res = wo.DealWorkOrders(orderid, clcont, stropenid, isaudit, infotypeid, unitid);
- if (res)
- {
- return Error("操作失败");
- }
- else
- {
- return Success("操作成功");
- }
- }
- /// <summary>
- /// 获取工单详情
- /// </summary>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult GetWorkOrder()
- {
- string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
- string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
- var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
- var tbu = new BLL.T_WO_UserWorkOrder().GetList(" F_UserId='" + wxuser.F_Id + "' and F_WorkOrderId=" + strworkorderid + " ").Tables[0];
- if (tbu.Rows.Count > 0)
- {
- string sql = "select *,dbo.GetUserName(CreateUser) as CreateUserName "
- + " from T_Wo_WorkOrder where id =" + strworkorderid + " ";
- var dt = DbHelperSQL.Query(sql).Tables[0];
- if (dt.Rows.Count > 0)
- {
- var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
- var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
- if (configfj != null)
- {
- dt = BindFileData(dt, configfj.F_ParamValue);
- }
- string gcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
- + "from T_Wo_Operation where F_IsDelete=0 and F_WorkOrderId ='" + dt.Rows[0]["WorkOrderId"] + "'";
- var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
- dt.Columns.Add("FilePath", typeof(string));
- if (configfj != null || config != null)
- {
- foreach (DataRow bldr in dt.Rows)
- {
- if (bldr["CallID"] != null && config != null)
- {
- bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
- }
- }
- }
- var obj = new
- {
- data = dt,
- item = gcdt
- };
- return Success("查询成功", obj);
- }
- else
- {
- return Error("查询失败");
- }
- }
- else
- {
- return Error("查询失败");
- }
- }
- #endregion
- #region 获取下拉框
- /// <summary>
- /// 获取信息分类列表
- /// </summary>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult GetTypeList()
- {
- string sql = "select * from T_Sys_DictionaryValue where F_DictionaryFlag='XXFL' and F_State=1 ";
- var dt = DbHelperSQL.Query(sql).Tables[0];
- return Success("列表加载成功", dt);
- }
- /// <summary>
- /// 获取交办单位列表
- /// </summary>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult GetAreaList()
- {
- string sql = "select * from T_Sys_DictionaryValue where F_DictionaryFlag='JBDW' and F_State=1 ";
- var dt = DbHelperSQL.Query(sql).Tables[0];
- return Success("列表加载成功", dt);
- }
- #endregion
- #region 附件和语音文件
- /// <summary>
- /// 获取留言路径
- /// </summary>
- /// <param name="lid">留言id</param>
- /// <param name="prefix">前缀</param>
- /// <returns></returns>
- public string GetLeavePath(string lid, string prefix)
- {
- string path = string.Empty;
- var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
- if (liuyan != null)
- {
- if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
- {
- path = prefix + liuyan.F_RecFileUrl;
- }
- }
- return path;
- }
- /// <summary>
- /// 获取通话录音路径
- /// </summary>
- /// <param name="cid">通话id</param>
- /// <param name="prefix">前缀</param>
- /// <returns></returns>
- public string GetCallPath(string cid, string prefix)
- {
- string path = string.Empty;
- var luyin = new BLL.T_Call_CallRecords().GetModelList(" callid='" + cid + "' ").FirstOrDefault();
- if (luyin != null)
- {
- if (!string.IsNullOrEmpty(luyin.FilePath))
- {
- var ym = prefix;
- ym = ym.Substring(0, ym.Length - 1);
- path = ym + luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
- }
- }
- return path;
- }
- /// <summary>
- /// 获取附件数据
- /// </summary>
- /// <param name="ids">附件id,多个用英文逗号,隔开</param>
- /// <param name="prefix">前缀</param>
- /// <returns></returns>
- public DataTable GetFileData(string ids, string prefix)
- {
- DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_FileId in (" + ids + ")").Tables[0];
- foreach (DataRow dr in dt.Rows)
- {
- dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
- }
- return dt;
- }
- /// <summary>
- /// 绑定附件信息
- /// </summary>
- /// <param name="dt"></param>
- /// <param name="prefix"></param>
- /// <returns></returns>
- public DataTable BindFileData(DataTable dt, string prefix)
- {
- dt.Columns.Add("File", typeof(object));
- foreach (DataRow dr in dt.Rows)
- {
- if (dr["Files"] != null && dr["Files"].ToString() != "")
- {
- dr["File"] = GetFileData(dr["Files"].ToString(), prefix);
- }
- }
- return dt;
- }
- /// <summary>
- /// 上传附件
- /// </summary>
- /// <returns></returns>
- public ActionResult UpdateFile()
- {
- //string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
- //byte[] filesss = HttpUtility.UrlDecodeToBytes(RequestString.GetFormString("filesss"));
- string filess = HttpUtility.UrlDecode(RequestString.GetFormString("filesss"));
- Error(filess);
- byte[] filesss = Convert.FromBase64String(filess.Split(',')[1]);
- //string fileurl = HttpUtility.UrlDecode(RequestString.GetFormString("fileurl"));
- string filename = HttpUtility.UrlDecode(RequestString.GetFormString("filename"));
- string filesize = HttpUtility.UrlDecode(RequestString.GetFormString("filesize"));
- string filetype = HttpUtility.UrlDecode(RequestString.GetFormString("filetype"));
- FileUp fu = new FileUp();
- string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
- #region
- if (filesss.Length > 0)
- {
- //byte[] by = fu.GetBinaryFile(fileurl);
- string newfilename = DateTime.Now.ToString("yyyyMMddHHmmssmsfff") + "_" + filename;
- fu.SaveFile(filesss, path, newfilename, filetype);
- Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
- model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
- model_T_Sys_Accessories.F_FileName = newfilename;//附件名称
- model_T_Sys_Accessories.F_FileType = filetype;//附件类型
- model_T_Sys_Accessories.F_FileUrl = path + newfilename;//附件地址
- model_T_Sys_Accessories.F_Size = long.Parse(filesize);
- //model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
- int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
- if (id > 0)
- {
- return Success("文件日志都成功", id);
- }
- else
- return Success("文件成功");
- }
- else
- {
- return Error("请选择要上传的文件");
- }
- #endregion
- #region 多个上传
- //HttpFileCollection files = RequestString.GetFiles();
- //if (files.Count > 0)
- //{
- // List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
- // for (int i = 0; i < files.Count; i++)
- // {
- // HttpPostedFile file = files[i];
- // string name = fu.Upload(file, path);
- // Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
- // model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
- // model_T_Sys_Accessories.F_FileName = name;//附件名称
- // model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(file.FileName);//附件类型
- // model_T_Sys_Accessories.F_FileUrl = path + name;//附件地址
- // model_T_Sys_Accessories.F_Size = file.ContentLength;
- // //model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
- // int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
- // model_T_Sys_Accessories.F_FileId = id;
- // acs.Add(model_T_Sys_Accessories);
- // }
- // return Success("成功", acs);
- //}
- //else
- //{
- // return Error("请选择要上传的文件");
- //}
- #endregion
- }
- #endregion
- #region
- public ActionResult UpLoadProcess(string id, HttpPostedFileBase file)
- {
- try
- {
- string filePathName = string.Empty;
- string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
- string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, path);
- if (Request.Files.Count == 0)
- {
- return Json(new { jsonrpc = 2.0, error = new { code = 102, message = "保存失败" }, id = "id" });
- }
- string ex = Path.GetExtension(file.FileName);
- filePathName = DateTime.Now.ToString("yyyyMMddHHmmssmsfff") + "_" + Guid.NewGuid().ToString("N") + ex;
- if (!System.IO.Directory.Exists(localPath))
- {
- System.IO.Directory.CreateDirectory(localPath);
- }
- file.SaveAs(Path.Combine(localPath, filePathName));
- return Success("上传成功", path + filePathName);
- }
- catch (Exception ex)
- {
- return Error(ex.Message);
- }
- }
- #endregion
- }
- }
|