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;
using CallCenterApi.Common;

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();
        private readonly BLL.T_Msg_NoticeInfo noticeBll = new BLL.T_Msg_NoticeInfo();

        /// <summary>
        /// 绑定微信号
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        [WechatActionFilter]
        public ActionResult Login(WxLoginDto login)
        {
            #region 把其他OpenId更新为空
            var userAccount = userAccountBLL.GetModelByOpenid(login.OpenId);
            if (userAccount != null)
            {
                userAccount.F_WxOpenId = "";
                userAccountBLL.Update(userAccount);
            }
            #endregion
            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 && dt.Rows.Count > 0)
            {
                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 = "";
            var userexit = new BLL.T_Sys_UserAccount().GetModelByOpenid(stropenid.Trim());
            if (userexit != null)
            {
                // if(useraccount . openid ==wxuser.F_Id) 查询 所有的工单
                sql = " and IsDel=0 and id in (select distinct F_WorkOrderID from T_WO_UserWorkOrder) ";
            }
            else
            {
                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");
            //2018-7-5
            string infotype = HttpUtility.UrlDecode(RequestString.GetFormString("infotype"));
            string infotypeid = HttpUtility.UrlDecode(RequestString.GetFormString("infotypeid"));
            string unit = HttpUtility.UrlDecode(RequestString.GetFormString("unit"));
            string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
            var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "'  and F_Type=1 ").FirstOrDefault();
            var wxuserinfo = new BLL.T_Sys_UserAccount().GetModelList(" F_WxOpenId='" + stropenid.Trim() + "'  and F_DeleteFlag=0 ").FirstOrDefault();
            string agentcode = "";
            string agentname = "";
            if (wxuserinfo != null)
            {
                agentcode = wxuserinfo.F_UserCode;
                agentname = wxuserinfo.F_UserName;
            }
            workorder.WorkOrderController wo = new workorder.WorkOrderController();
            string workorderid = wo.AddWorkOrders(cusname, cusphone,country,address, content, files,infotype, infotypeid,agentcode ,agentname,unit );
            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,cont,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"));
            //测试
            //strworkorderid = "2";
            //stropenid = "oVaSiv_rmKGU4fITAOEzhGrRU8M0";


            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];
            #region
            
            var userexit = new BLL.T_Sys_UserAccount().GetModelByOpenid(stropenid.Trim());
            if (userexit != null)
            {
                // if(useraccount . openid ==wxuser.F_Id) 查询 所有的工单
                tbu = new BLL.T_WO_UserWorkOrder().GetList("  F_WorkOrderId=" + strworkorderid + " ").Tables[0];
            }
            
            #endregion

            if (tbu.Rows.Count > 0)
            {
                string sql = "select *,dbo.GetUserName(CreateUser) as CreateUserName,dbo.GetCountry(County) CountryName "
                    + " 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 GetNoticeList()
        {
            DataTable dt = new DataTable();
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            string sql = " ";
            //if (datetime != null && datetime.Trim() != "")
            //{
            //    sql += " and Datediff(day,F_Startdate,'" + datetime.Trim() + "')>=0";
            //    sql += " and Datediff(day,F_Enddate,'" + datetime.Trim() + "')<=0";
            //}
            
            sql += " and Datediff(day,F_Startdate,getdate())>=0";
            sql += " and Datediff(day,F_Enddate,getdate())<=0";

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }
            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Msg_NoticeInfo",
                "F_NoticeId",
                "*",
                sql,
                "ORDER BY F_NoticeId 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 GetNoticeDetails()
        {
            int cid = Utils.StrToInt(RequestString.GetQueryString("cid"), 0);
            if (cid != 0)
                return Error("参数错误");
            var model = noticeBll.GetModel(cid);
            return Success("获取成功", model);
        }
        #endregion

        #region 问卷相关
        /// <summary>
        /// 获取问卷
        /// </summary>
        /// <returns></returns>
        [WechatActionFilter]
        public ActionResult GetPagers()
        {
            //int pagerid = int.Parse(Configs.GetValue("WXPagerID"));
            int pagerid = 8;
            var model = pagerInfoBLL.GetModel(pagerid);
            if (model != null)
            {
                var qlist = questionBLL.GetModelList(" F_DeleteFlag=0 and F_QuestionId in (select F_QuestionId from T_Ask_PagerItems where F_PagerId=" + pagerid + ")  order by F_QuestionId ");
                var qilist = questionItemBLL.GetModelList(" F_QuestionId in (select F_QuestionId from T_Ask_PagerItems where F_PagerId=" + pagerid + ")  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)
        {
            if (ans != null)
            {
                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, wxuser);

                if (res)
                {
                    return Success("问卷提交成功");
                }
                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);
        }

        /// <summary>
        /// 获取交办单位列表
        /// </summary>
        /// <returns></returns>
        [WechatActionFilter]
        public ActionResult GetZBDWList()
        {
            string sql = "select * from T_Sys_DictionaryValue where F_DictionaryFlag='ZBDW' 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
                    model_T_Sys_Accessories.F_FileId = fid;//修改为返回对象以便查看图片
                    return Success("文件日志都成功", model_T_Sys_Accessories);
                }
                else
                    return Success("文件成功");
                
            }
            catch (Exception ex)
            {
                return Error(ex.Message);
            }
        }
        #endregion
    }
}