| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- 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();
- private readonly BLL.T_Ask_PagerInfo pagerInfoBLL = new BLL.T_Ask_PagerInfo();
- private readonly BLL.T_Ask_Question questionBLL = new BLL.T_Ask_Question();
- private readonly BLL.T_Ask_QuestionItems questionItemBLL = new BLL.T_Ask_QuestionItems();
- /// <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 usertemp = new BLL.T_Sys_UserAccount().GetModelByOpenid(wld.OpenId);
- if (usertemp != null)
- {
- wld.UserCode = usertemp.F_UserCode;
- }
- else
- {
- wld.UserCode = "";
- }
- }
- 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);
- }
- var newobj = new
- {
- openid = wld.OpenId,
- usercode = wld.UserCode,
- };
- return Success("成功", newobj);
- }
- #region 工单相关
- /// <summary>
- /// 获取工单列表
- /// </summary>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult GetList()
- {
- DataTable dt = new DataTable();
- //string sql = " and IsDel=0 ";
- string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
- string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));//状态 0待处理 1已处理
- 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 IsDel=0 and id in (select distinct F_WorkOrderID from T_WO_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') ";
- if (strstate.Trim() != "" && strstate != "undefined")
- {
- if (strstate.Trim() == "0")
- {
- sql += " and State in(0,1) ";
- }
- else
- {
- sql += " and State =2 ";
- }
- //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 = HttpUtility.UrlDecode(RequestString.GetFormString("cusname"));
- string cusphone = RequestString.GetFormString("cusphone");//GetFormString
- string country = HttpUtility.UrlDecode(RequestString.GetFormString("country"));
- string address = HttpUtility.UrlDecode(RequestString.GetFormString("address"));
- string content = HttpUtility.UrlDecode(RequestString.GetFormString("content"));
- string files = RequestString.GetFormString("files");
- 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(cusname, cusphone,country,address, 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");//GetFormString
- string customer= HttpUtility.UrlDecode(RequestString.GetFormString("customer"));
- string inqtime = HttpUtility.UrlDecode(RequestString.GetFormString("inqtime"));
- string inquser = HttpUtility.UrlDecode(RequestString.GetFormString("inquser"));
- string country = HttpUtility.UrlDecode(RequestString.GetFormString("country"));
- string address = HttpUtility.UrlDecode(RequestString.GetFormString("address"));
- string detail = HttpUtility.UrlDecode(RequestString.GetFormString("detail"));
- string cont = HttpUtility.UrlDecode(RequestString.GetFormString("cont"));
- string answer = HttpUtility.UrlDecode(RequestString.GetFormString("answer"));
- string remark = HttpUtility.UrlDecode(RequestString.GetFormString("remark"));
- string infotype = HttpUtility.UrlDecode(RequestString.GetFormString("infotype"));
- string unit = HttpUtility.UrlDecode(RequestString.GetFormString("unit"));
- int issend = RequestString.GetFormInt("issend", 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,issend, customer,inqtime,inquser,country,address,detail,detail,answer,remark, infotype, unit, stropenid);
- if (res)
- {
- return Success("操作成功");
- }
- else
- {
- return Error("操作失败");
- }
- }
- /// <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(CreateUser) as UserName "
- + "from T_Wo_WorkOrderItem where IsDel=0 and 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 GetPagers()
- {
- var model = pagerInfoBLL.GetModel(8);
- if (model != null)
- {
- var qlist = questionBLL.GetModelList(" F_DeleteFlag=0 and F_QuestionId in (select F_QuestionId from T_Ask_PagerItems where F_PagerId=8) order by F_QuestionId ");
- var qilist = questionItemBLL.GetModelList(" F_QuestionId in (select F_QuestionId from T_Ask_PagerItems where F_PagerId=8) order by F_ItemId ");
- var newmodel = new
- {
- F_Title = model.F_Title,
- F_StartText = model.F_StartText,
- F_EndText = model.F_EndText,
- F_Remark = model.F_Remark,
- F_Questions = qlist.Select(q =>
- {
- return new
- {
- quesid = q.F_QuestionId,
- questitle = q.F_Title,
- questype = q.F_Type,
- quescontent = q.F_Content,
- quesremark = q.F_Remark,
- quesitems = qilist.Where(qq => qq.F_QuestionId == q.F_QuestionId).Select(qi =>
- {
- return new
- {
- itemid = qi.F_ItemId,
- itemname = qi.F_ItemName,
- itemremark = qi.F_Remark,
- };
- })
- };
- })
- };
- return Success("获取问卷试题信息成功", newmodel);
- }
- return Error("获取问卷试题信息失败");
- }
- /// <summary>
- /// 提交问卷
- /// </summary>
- /// <returns></returns>
- [WechatActionFilter]
- public ActionResult AddPagers(string openid, string[] ans, string cusname,
- string telphone,string phone,string countryid,string address)
- {
- var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + openid + "' and F_Type=1 ").FirstOrDefault();
- bool res = new callout.PagerAnswerWXController().AnswersWX(telphone, openid, ans, cusname, phone, countryid, address);
- string msg = "";
- if (ans != null)
- {
- foreach (var item in ans)
- {
- msg += item + ";**;";
- }
- }
- else
- {
- msg = "ans为空";
- }
- if (res)
- {
- return Success("问卷提交成功:::" + msg);
- }
- else
- {
- return Error("问卷提交失败:::" + msg);
- }
- }
- #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;
- }
-
- #endregion
- #region
- /// <summary>
- /// 上传附件
- /// </summary>
- /// <returns></returns>
- public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file)
- {
- try
- {
- string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
- string filePathName = string.Empty;
- string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
- string localPath = Server.MapPath(Path.Combine(HttpRuntime.AppDomainAppPath, path));
- if (Request.Files.Count == 0)
- {
- return Error("保存失败");
- }
- 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));
- #region 添加日志
- 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 = filePathName;//附件名称
- model_T_Sys_Accessories.F_FileType = type;//附件类型
- model_T_Sys_Accessories.F_FileUrl = path + filePathName;//附件地址
- model_T_Sys_Accessories.F_Size = size;
- model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
- int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
- #endregion
- if (fid > 0)
- {//返回附件的ID
- return Success("文件日志都成功", fid);
- }
- else
- return Success("文件成功");
-
- }
- catch (Exception ex)
- {
- return Error(ex.Message);
- }
- }
- #endregion
- }
- }
|