Example #1
0
        public WechatUser Regiet(string realName, string phoneNumber, string openid)
        {
            var db = new ModelContext();
            //var temn = db.TerminalSet.FirstOrDefault(item => item.Name == System.Configuration.ConfigurationManager.AppSettings["termailname"]);
            var usr = WechatHelper.CheckOpenid(openid);


            UserInfo ui = new UserInfo
            {
                Name        = realName,
                PhoneNumber = phoneNumber,
                //LastLoginTerminalId = temn.TerminalId,
                LastLoginTime = DateTime.Now,
                CreateDate    = DateTime.Now,
            };

            //db.ActiveLogSet.Add(new ActiveLog
            //{
            //    CreateDate = DateTime.Now,
            //    OptionContent = "Regist in Doshine wechat service",
            //    TerminalId = temn.TerminalId,
            //    UserId = ui.UserInfoId,
            //});

            db.UserInfo.Add(ui);
            //usr.UserInfoId = ui.UserInfoId;

            db.SaveChanges();
            db.WechatUserSet.Find(usr.WechatUserId).UserInfoId = ui.UserInfoId;
            db.SaveChanges();

            LogHelper.AddLog("Regist in Doshine wechat service", "", openid);
            return(usr);
        }
Example #2
0
        /// <summary>
        /// 获得历史报修记录(限制条数),仅用于首页展示。
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        //[Obsolete("0.4之前版本使用,之后版本需要区分不同状态,请勿调用!", true)]
        public IEnumerable <Repair> GetHistoryRepair(string openid)
        {
            var wuser = WechatHelper.CheckOpenid(openid);
            var user  = WechatHelper.CheckUser(wuser);
            //获取config中记录的需要显示的历史纪录数量。
            int tCount = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["historyrepaircount"]);

            if (user == null)
            {
                return(null);
            }

            var db = new ModelContext();

            var ownhis = (
                from r in db.RepairSet
                where r.UserId == user.UserInfoId
                orderby r.CreateDate descending
                select r).Take(tCount).ToList();

            foreach (var item in ownhis)
            {
                item.IsUserself = true;
            }
            return(ownhis);
        }
Example #3
0
        /// <summary>
        /// 获取用户记录
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static Record GetRecord(string openid)
        {
            var db  = new ModelContext();
            var ret = db.RecordSet.OrderByDescending(item => item.CreateDate).FirstOrDefault(item => item.Type == RecordType.MpRepair && item.Openid == openid);

            if (ret == null)
            {
                var usr = WechatHelper.CheckOpenid(openid);
                usr = WechatHelper.CheckUser(usr);


                var rec = new Record
                {
                    Openid   = openid,
                    Type     = RecordType.MpRepair,
                    RecordId = 0
                };

                if (usr != null && usr.UserInfo != null)
                {
                    rec.PhoneNumber = usr.UserInfo.PhoneNumber;
                    rec.Name        = usr.UserInfo.Name;
                }

                return(rec);
            }
            return(ret);
        }
Example #4
0
        /// <summary>
        /// 获取经销商信息
        /// </summary>
        /// <param name="openid">用户openid</param>
        /// <returns></returns>
        public WechatUser GetPartnerInfo(string openid)
        {
            WechatUser wuser = WechatHelper.CheckOpenid(openid);

            wuser = WechatHelper.CheckPartner(wuser);
            return(wuser);
        }
Example #5
0
        //[HttpGet]
        /// <summary>
        /// 编辑合作伙伴
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="comName"></param>
        /// <param name="realname"></param>
        /// <param name="address"></param>
        /// <param name="comPhone"></param>
        /// <returns></returns>
        public Partner EditPartnerInfo(string openid, string comName, string realname, string address, string comPhone, string email)
        {
            var db  = new ModelContext();
            var usr = WechatHelper.CheckOpenid(openid);

            usr = WechatHelper.CheckUser(usr);
            if (usr.UserInfoId == null || usr.UserInfoId == 0 || usr.UserInfo == null)
            {
                return(null);
            }

            usr.UserInfo.Name = realname;
            var pat = db.PartnerSet.Find(usr.PartnerId);

            pat.RealName    = realname;
            pat.CompanyName = comName;
            //pat.Type = type;
            pat.Address      = address;
            pat.CompanyPhone = comPhone;
            pat.Email        = email;

            db.SaveChanges();

            LogHelper.AddLog("Edit patner info .", usr.PartnerId.ToString(), openid);

            return(usr.PartnerInfo);
        }
Example #6
0
        /// <summary>
        /// 通过网页获取的code换取用户openid
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetOpenidByCode(string code)
        {
            //  var a = new Helper();
            // a.WriteTxt(code);
            string openid = "err";

            string apps  = System.Configuration.ConfigurationManager.AppSettings["appsecrect"];
            string appid = System.Configuration.ConfigurationManager.AppSettings["appid"];
            string url   = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appid, apps, code);

            string resStr = WechatHelper.GetResponse("", url);

            //a.WriteTxt(resStr);

            //  resStr = string.Format("{{\"res\":{0} }}", resStr);
            var resXml = JsonConvert.DeserializeXNode(resStr, "res");
            var node   = resXml.Element("res").Element("openid");

            if (node != null)
            {
                openid = node.Value;;
            }
            else
            {
                openid = resStr;
            }
            if (openid.Contains("{"))
            {
                openid = null;
            }

            return(openid);
        }
Example #7
0
        /// <summary>
        /// 添加客户端消息记录
        /// </summary>
        /// <param name="openid">openid</param>
        /// <param name="content">消息内容</param>
        /// <param name="isNew">是否为新连接</param>
        /// <param name="type">消息发送方类型</param>
        /// <param name="detailInfo">消息体完成内容</param>
        /// <returns></returns>
        public Message AddCustomMessage(string openid, string content, bool isNew, MessageType type, string detailInfo)
        {
            var wuser = WechatHelper.CheckOpenid(openid);

            wuser = WechatHelper.CheckUser(wuser);
            if (wuser == null || wuser.UserInfoId == null)
            {
                return(null);
            }
            //var tmnName = type == MessageType.Service ? System.Configuration.ConfigurationManager.AppSettings["ServerService"] : System.Configuration.ConfigurationManager.AppSettings["DoshineWechatService"];
            string tmnName = System.Configuration.ConfigurationManager.AppSettings["termailname"];
            var    db      = new ModelContext();
            var    tmn     = db.TerminalSet.FirstOrDefault(item => item.Name == tmnName);
            var    msg     = new Message
            {
                Content    = content,
                CreateDate = DateTime.Now,
                Type       = type,
                UserId     = wuser.UserInfoId,
                TerminalId = tmn.TerminalId,
            };

            db.MessageSet.Add(msg);
            db.SaveChanges();
            if (isNew)
            {
                LogHelper.AddLog("send a message", msg.MessageId.ToString(), openid);

                ChatLogHelper.AddNewLog(openid, ChatStatus.Chatting, null);
            }

            return(msg);
        }
Example #8
0
        /// <summary>
        /// 合作伙伴注册
        /// </summary>
        /// <param name="openid">openid</param>
        /// <param name="comName">公司名称</param>
        /// <param name="type">类型(经销商,供应商)</param>
        /// <param name="realname">真实姓名</param>
        /// <param name="address">公司地址</param>
        /// <param name="comPhone">公司电话</param>
        /// <param name="email">电子邮件</param>
        /// <param name="salesmanId">对应的销售id</param>
        /// <param name="files">相关资质图片字符串,格式为文件 名称1 :mediaid; eg:经营许可证:000001;组织机构代码:000005;</param>
        /// <param name="discrictid">区域id</param>
        /// <param name="money">加盟资金</param>
        /// <param name="sex">性别</param>
        /// <returns></returns>
        public Partner ReginPartner(string openid, string comName, PartnerType type, string realname, string address, string comPhone, int?salesmanId, string email, string files, int?discrictid, Sex sex, string money)
        {
            var db  = new ModelContext();
            var usr = WechatHelper.CheckOpenid(openid);

            usr = WechatHelper.CheckUser(usr);
            if (usr.UserInfoId == null || usr.UserInfoId == 0 || usr.UserInfo == null)
            {
                return(null);
            }

            // 将用户信息中的姓名更新
            usr.UserInfo.Name = realname;

            var pat = new Partner
            {
                RealName     = realname,
                Address      = address,
                CompanyName  = comName,
                CreateDate   = DateTime.Now,
                UserId       = usr.UserInfoId,
                CompanyPhone = comPhone,
                Point        = 0,
                Type         = type,
                Email        = email,
                SalesmanId   = salesmanId,
                DistrictId   = discrictid,
                Status       = PartnerStatus.Apply,
                Sex          = sex,
                Money        = money,
            };

            db.PartnerSet.Add(pat);
            db.SaveChanges();
            db.WechatUserSet.Find(usr.WechatUserId).PartnerId = pat.PartnerId;
            db.SaveChanges();

            //下载文件
            var filestrList = files.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            var fileDic     = new Dictionary <string, string>();

            foreach (var filestr in filestrList)
            {
                var fileinfo = filestr.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                if (fileinfo.Length == 2)
                {
                    fileDic.Add(fileinfo[0], fileinfo[1]);
                }
            }
            if (fileDic != null && fileDic.Count > 0)
            {
                WechatImageHelper.AddNewImageForPartner(fileDic, pat.PartnerId, openid);
            }

            LogHelper.AddLog("Regist as a patner.", pat.PartnerId.ToString(), openid);

            return(pat);
        }
Example #9
0
        /// <summary>
        /// 获取用户信息,返回值的UserInfo字段为null则表示用户未注册
        /// </summary>
        /// <param name="openid">openid</param>
        /// <returns></returns>
        public WechatUser GetUserInfo(string openid)
        {
            var wuser = WechatHelper.CheckOpenid(openid);
            var user  = WechatHelper.CheckUser(wuser);

            if (user == null || user.UserInfoId == null)
            {
                return(wuser);
            }
            return(user);
        }
Example #10
0
        /// <summary>
        /// 发送模板消息
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="templateId"></param>
        /// <param name="dataStr"></param>
        public static void SendModelMessage(string openid, string url, string templateId, string dataStr)
        {
            var    token    = WechatHelper.GetToken(AccountType.Service);
            string msgModle = "{{\"touser\":\"{0}\",\"template_id\":\"{1}\",\"url\":\"{2}\",\"data\":{{{3}}}}}";
            string msg      = string.Format(msgModle, openid, templateId, url, dataStr);

            string turl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
            string ret  = WechatHelper.GetResponse(msg, turl);

            //throw new NotImplementedException();
        }
Example #11
0
        /// <summary>
        /// 为经销商添加文件
        /// </summary>
        /// <param name="mediaidDic">key为文件名,value为mediaId</param>
        /// <param name="partnerid">合作伙伴id</param>
        /// <param name="openid">openid</param>
        /// <returns></returns>
        public static IEnumerable <ImageDownloadLog> AddNewImageForPartner(Dictionary <string, string> mediaidDic, int partnerid, string openid)
        {
            var db  = new ModelContext();
            var pat = db.PartnerSet.FirstOrDefault(item => item.PartnerId == partnerid);

            if (pat == null)
            {
                yield break;
            }
            var ret = new List <ImageDownloadLog>();

            foreach (var media in mediaidDic)
            {
                //添加下载记录
                var log = new ImageDownloadLog
                {
                    CreateDate  = DateTime.Now,
                    IsSuccess   = false,
                    OpenId      = openid,
                    Scene       = "Add partener image",
                    MediaNumber = media.Value,
                    Remarks     = partnerid.ToString(),
                };
                db.ImageDownloadLogSet.Add(log);
                db.SaveChanges();


                //下载
                var fileName = WechatHelper.DownloadImgFile(media.Value);

                var file = new ImageFile
                {
                    CreateDate = DateTime.Now,
                    FileName   = fileName,
                };
                db.ImageFileSet.Add(file);
                log.IsSuccess  = true;
                log.Remarks    = "";
                log.FinishDate = DateTime.Now;
                db.SaveChanges();

                //将下载的文件关联到报修记录中
                if (pat.Files == null)
                {
                    pat.Files = new Dictionary <int, string>();
                }
                pat.Files  = pat.Files.Concat(new KeyValuePair <int, string>[] { new KeyValuePair <int, string>(file.ImageFileId, media.Key) }).ToDictionary(item => item.Key, item => item.Value);
                log.FileId = file.ImageFileId;

                db.SaveChanges();

                yield return(log);
            }
        }
Example #12
0
        /// <summary>
        /// 根据地理位置距离升序
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public IEnumerable <Village> GetAllVillage(double x, double y)
        {
            var db  = new ModelContext();
            var ret = new List <Village>();

            foreach (var vil in db.VillageSet)
            {
                vil.Distance = WechatHelper.GetDistance(x, y, vil.LocationX, vil.LocationY);
                ret.Add(vil);
            }

            return(ret.OrderBy(item => item.Distance).ToList());
        }
Example #13
0
        /// <summary>
        /// 为完成报修添加图片
        /// </summary>
        /// <param name="repairid"></param>
        /// <param name="mediaidList"></param>
        /// <returns></returns>
        internal static IEnumerable <ImageDownloadLog> AddNewImageForHandleRepair(int repairid, IEnumerable <string> mediaidList)
        {
            var db  = new ModelContext();
            var rep = db.RepairSet.FirstOrDefault(item => item.RepairId == repairid);

            if (rep == null)
            {
                yield break;
            }

            foreach (var mediaid in mediaidList)
            {
                //添加下载记录
                var log = new ImageDownloadLog
                {
                    CreateDate = DateTime.Now,
                    IsSuccess  = false,
                    //OpenId = openid,
                    Scene       = "Handlen repair",
                    MediaNumber = mediaid,
                    Remarks     = repairid.ToString(),
                };
                db.ImageDownloadLogSet.Add(log);
                db.SaveChanges();


                //下载
                var fileName = WechatHelper.DownloadImgFile(mediaid);

                var file = new ImageFile
                {
                    CreateDate = DateTime.Now,
                    FileName   = fileName,
                };
                db.ImageFileSet.Add(file);
                log.IsSuccess  = true;
                log.Remarks    = "";
                log.FinishDate = DateTime.Now;
                db.SaveChanges();

                //将下载的文件关联到报修记录中
                //rep.ImageFileId = file.ImageFileId;
                rep.FinishImageFiles = rep.FinishImageFiles.Concat(new ImageFile[] { file }).ToList();
                log.FileId           = file.ImageFileId;

                db.SaveChanges();

                yield return(log);
            }
        }
Example #14
0
        /// <summary>
        /// 下载报修时候添加的图片,请先保证数据库中已经该报修记录
        /// </summary>
        /// <param name="mediaid">media _id 由微信分发</param>
        /// <param name="repairid">报修记录id</param>
        /// <param name="openid">用户openid</param>
        /// <returns></returns>
        public static ImageDownloadLog AddNewImageForRepair(string mediaid, int repairid, string openid)
        {
            var db  = new ModelContext();
            var rep = db.RepairSet.FirstOrDefault(item => item.RepairId == repairid);

            if (rep == null)
            {
                return(null);
            }

            //添加下载记录
            var log = new ImageDownloadLog
            {
                CreateDate  = DateTime.Now,
                IsSuccess   = false,
                OpenId      = openid,
                Scene       = "Add repair ",
                MediaNumber = mediaid,
                Remarks     = repairid.ToString(),
            };

            db.ImageDownloadLogSet.Add(log);
            db.SaveChanges();


            //下载
            var fileName = WechatHelper.DownloadImgFile(mediaid);

            var file = new ImageFile
            {
                CreateDate = DateTime.Now,
                FileName   = fileName,
            };

            db.ImageFileSet.Add(file);
            log.IsSuccess  = true;
            log.Remarks    = "";
            log.FinishDate = DateTime.Now;
            db.SaveChanges();

            //将下载的文件关联到报修记录中
            rep.ImageFileId = file.ImageFileId;
            log.FileId      = file.ImageFileId;

            db.SaveChanges();

            return(log);
        }
Example #15
0
        /// <summary>
        /// 获得维修记录
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="status">需要获取的记录状态(提交=5,受理=10,处理完成待评价=20,完成=99 ,未知=0)</param>
        /// <param name="count">每页数量</param>
        /// <param name="page">当前页数(从0开始计数)</param>
        /// <returns></returns>
        public IEnumerable <Repair> GetHistoryRepair(string openid, RepairStatus status, int count, int page)
        {
            var wuser = WechatHelper.CheckOpenid(openid);
            var user  = WechatHelper.CheckUser(wuser);

            if (user == null)
            {
                return(null);
            }

            var db = new ModelContext();

            int skip = count * page;

            return(db.RepairSet.Where(item => item.UserId == user.UserInfoId && item.Status == status).OrderByDescending(item => item.CreateDate).Skip(skip).Take(count));
        }
Example #16
0
        /// <summary>
        /// 检查用户的openid,若不存在则添加并获取用户信息。
        /// </summary>
        /// <param name="openid"></param>
        /// <returns>111</returns>
        public static WechatUser CheckOpenid(string openid)
        {
            var db   = new ModelContext();
            var user = db.WechatUserSet.Include("UserInfo").FirstOrDefault(item => item.OpenId == openid);

            if (user == null || string.IsNullOrEmpty(user.OpenId))
            {
                user = new WechatUser {
                    OpenId = openid
                };
                db.WechatUserSet.Add(user);
                db.SaveChanges();
                WechatHelper.GetUserInfo(user);
            }

            return(user);
        }
Example #17
0
        /// <summary>
        /// 提交一个新的报修申请手机
        /// </summary>
        /// <param name="content"></param>
        /// <param name="mediaidList">图片</param>
        /// <param name="phone"></param>
        /// <param name="villageid"></param>
        /// <param name="name"></param>
        /// <param name="recordid"></param>
        /// <returns></returns>
        public Repair Add(string content, string phone, int villageid, string name, int recordid)
        {
            var db  = new ModelContext();
            var usr = db.UserInfo.FirstOrDefault(item => item.PhoneNumber == phone);

            if (usr == null)
            {
                return(null);
            }
            //var mediaIdArr = mediaidList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            var number = GetNewInnerNumber();
            var rep    = new Repair
            {
                Contenet    = content,
                CreateDate  = DateTime.Now,
                Status      = RepairStatus.Apply,
                UserId      = usr.UserInfoId,
                InnerNumber = number,
                PhoneNumber = phone,
                VillageId   = villageid,
                Name        = name,
            };


            db.RepairSet.Add(rep);

            db.SaveChanges();

            var vill = db.VillageSet.Find(villageid);

            RecordHelper.UpdateRecord(recordid, "openid", RecordType.MpRepair, phone, name, vill.Name);

            //发送企业号通知
            var    workernamArr = System.Configuration.ConfigurationManager.AppSettings["repairworkers"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string scontent     = rep.Contenet.Replace("<br />", ",").Length > 7 ? rep.Contenet.Replace("<br />", ",").Substring(0, 6) + "..." : rep.Contenet.Replace("<br />", ",");
            var    msg          = $"收到新的报修申请,请尽快处理!\n报修单位:{rep.Village?.Name}\n报修人:{rep.Name}\n联系方式:{rep.PhoneNumber}\n报修内容:{scontent}\n报修时间:{rep.CreateDate.ToString("yyyy-MM-dd hh:mm")}\n\n<a href=\\\"http://mp.doshine.com/DoShineMP/PhoneWeb/RepairDetailsInterior?repairid={rep.RepairId}\\\">点击查看</a>";

            WechatHelper.SendComponyMessage(workernamArr, msg);

            return(rep);
        }
Example #18
0
        public WechatUser EditUserInfo(string openid, string realName, string phoneNumber, string address)
        {
            var db  = new ModelContext();
            var usr = WechatHelper.CheckOpenid(openid);

            usr = WechatHelper.CheckUser(usr);
            if (usr.UserInfoId == null || usr.UserInfoId == 0 || usr.UserInfo == null)
            {
                return(null);
            }
            var ui = db.UserInfo.Find(usr.UserInfoId);

            ui.Name        = realName;
            ui.PhoneNumber = phoneNumber;
            ui.Address     = address;
            db.SaveChanges();

            LogHelper.AddLog("Edit infomation", "", openid);
            return(usr);
        }
Example #19
0
        /// <summary>
        /// 检查是否有未评论的报修,若无返回0,有则返回id,返回小于零的数表示错误!
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public int HasUnFinishedRepair(string openid)
        {
            var user = WechatHelper.CheckOpenid(openid);

            user = WechatHelper.CheckUser(user);

            if (user == null || user.UserInfo == null)
            {
                return(-1);
            }

            var db  = new ModelContext();
            var rep = db.RepairSet.Where(item => item.UserId == user.UserInfoId && item.Status == RepairStatus.FinishHandle);

            if (rep.Count() == 0)
            {
                return(0);
            }

            return(rep.OrderBy(item => item.CreateDate).First().RepairId);
        }
Example #20
0
        /// <summary>
        /// 发送企业号信息
        /// </summary>
        /// <param name="account"></param>
        /// <param name="msg"></param>
        internal static void SendComponyMessage(IEnumerable <string> accounts, string msg)
        {
            //   account = "chenzijun|[email protected]";
            var account = string.Join("|", accounts);

            //foreach (string str in accounts)
            //{
            //    account += (str + "|");
            //}
            account.Remove(account.Length - 1);


            var send = "{{\"touser\": \"{0}\",\"msgtype\": \"text\",\"agentid\": \"{1}\",\"text\": {{\"content\": \"{2}\"}},\"safe\":\"0\"}}";

            send = string.Format(send, account, System.Configuration.ConfigurationManager.AppSettings["repairhelperagentid"], msg);

            var token = WechatHelper.GetToken(AccountType.Company);
            var url   = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + token;

            WechatHelper.GetResponse(send, url);
        }
Example #21
0
        /// <summary>
        /// 获得某类维修记录的总页数(企业号使用)
        /// </summary>
        /// <param name="sta">需要获取的记录状态(获取 全部状态=0,提交=5,受理=10,处理完成待评价=20,完成=99)</param>
        /// <param name="count">每页的数量</param>
        /// <returns></returns>
        public int GetAllPageCount(RepairStatus sta, int count, string openid)
        {
            var db    = new ModelContext();
            var wuser = WechatHelper.CheckOpenid(openid);
            var user  = WechatHelper.CheckUser(wuser);

            if (user == null)
            {
                return(0);
            }

            var set = db.RepairSet.Where(item => item.UserId == user.UserInfoId);

            if (sta == RepairStatus.Unknow)
            {
                return(set.Count() / count + 1);
            }
            else
            {
                return(set.Where(item => item.Status == sta).Count() / count + 1);
            }
        }
Example #22
0
        /// <summary>
        /// 完成处理
        /// </summary>
        /// <param name="repairId">报修记录id</param>
        /// <param name="mediaIdList">meidia Id列表</param>
        /// <param name="describe">文字描述</param>
        /// <param name="type">完成类型</param>
        /// <returns></returns>
        public Repair FinishHandlen(int repairId, IEnumerable <string> mediaIdList, string describe, RepairFinishType type)
        {
            var db  = new ModelContext();
            var rep = db.RepairSet.Include("Village").FirstOrDefault(item => item.RepairId == repairId);

            if (rep == null)
            {
                return(null);
            }

            rep.Status             = RepairStatus.FinishHandle;
            rep.FinishHandlendDate = DateTime.Now;
            rep.FinishType         = type;
            rep.Describe           = describe;
            db.SaveChanges();
            var cl = WechatImageHelper.AddNewImageForHandleRepair(rep.RepairId, mediaIdList).ToList();

            cl.Clear();

            //发送模板消息
            string content = rep.Contenet.Replace("<br />", "").Length > 7 ? rep.Contenet.Replace("<br />", "").Substring(0, 6) + "..." : rep.Contenet.Replace("<br />", "");
            var    wuser   = WechatHelper.CheckWechatUser(rep.UserId ?? 0);

            if (wuser != null && !string.IsNullOrEmpty(wuser.OpenId))
            {
                string url = string.Format("http://mp.doshine.com/doshinemp/PhoneWeb/RepairDetails?repairid={0}", rep.RepairId);
                WechatHelper.SendModelMessage(
                    wuser.OpenId,
                    url,
                    "bI7o_XjdW10WRf1gPvmEpddVmBahfh97Irgv4u-__Gc",
                    string.Format("\"first\":{{\"value\":\"您好,您的报修申请已完成处理\",\"color\":\"#000000\"}},\"keyword1\":{{\"value\":\"{0}\",\"color\":\"#173177\"}},\"keyword2\":{{\"value\":\"{1}\",\"color\":\"#173177\"}},\"remark\":{{\"value\":\"保修内容:{3}\\n处理结果:{2}\",\"color\":\"#000000\"}}",
                                  rep.InnerNumber,
                                  rep.FinishHandlendDate.Value.ToLongDateString() + " " + rep.FinishHandlendDate.Value.ToShortTimeString(),
                                  EnumFormat.GetDescription(rep.FinishType),
                                  content));
            }
            return(rep);
        }
Example #23
0
        /// <summary>
        /// 受理报修
        /// </summary>
        /// <param name="repairId">报修记录id</param>
        /// <param name="exceptDate">预计上门时间</param>
        /// <returns></returns>
        public Repair Accept(int repairId, DateTime exceptDate, string innderNumber)
        {
            var db  = new ModelContext();
            var rep = db.RepairSet.Include("Village").FirstOrDefault(item => item.RepairId == repairId);

            if (rep == null)
            {
                return(null);
            }

            rep.Status           = RepairStatus.Accept;
            rep.AccepDate        = DateTime.Now;
            rep.ExceptHandleDate = exceptDate;
            //  rep.InnerNumber = innderNumber;

            db.SaveChanges();

            //发送模板消息
            string content = rep.Contenet.Replace("<br />", "").Length > 7 ? rep.Contenet.Replace("<br />", "").Substring(0, 6) + "..." : rep.Contenet.Replace("<br />", "");
            var    wuser   = WechatHelper.CheckWechatUser(rep.UserId ?? 0);

            if (wuser != null && !string.IsNullOrEmpty(wuser.OpenId))
            {
                string url = string.Format("http://mp.doshine.com/doshinemp/PhoneWeb/RepairDetails?repairid={0}", rep.RepairId);
                WechatHelper.SendModelMessage(
                    wuser.OpenId,
                    url,
                    "qg8GNMOl1vwqU_1ks2p5UJqkrO6eg1bqak1qANGMkNU",
                    string.Format("\"first\":{{\"value\":\"您好,您的报修申请已被成功受理\",\"color\":\"#000000\"}},\"keyword1\":{{\"value\":\"{0}\",\"color\":\"#173177\"}},\"keyword2\":{{\"value\":\"{1}\",\"color\":\"#173177\"}},\"keyword3\":{{\"value\":\"{2}\",\"color\":\"#173177\"}},\"remark\":{{\"value\":\"我们将于 {3} 上门,敬请做好准备。\",\"color\":\"#000000\"}}",
                                  rep.Village.Name,
                                  content,
                                  rep.CreateDate.ToLongDateString() + " " + rep.CreateDate.ToShortTimeString(),
                                  rep.ExceptHandleDate.Value.ToLongDateString() + " " + rep.ExceptHandleDate.Value.ToShortTimeString()));
            }
            return(rep);
        }
Example #24
0
        /// <summary>
        /// 取消报修
        /// </summary>
        /// <param name="repairId">报修记录id</param>
        /// <param name="reason">取消原因描述</param>
        /// <returns></returns>
        public Repair Cancel(int repairId, string reason)
        {
            var db  = new ModelContext();
            var rep = db.RepairSet.FirstOrDefault(item => item.RepairId == repairId);

            if (rep == null)
            {
                return(null);
            }

            rep.Status             = RepairStatus.Cancel;
            rep.Response           = reason;
            rep.FinishHandlendDate = DateTime.Now;

            db.SaveChanges();


            //发送模板消息
            string content = rep.Response.Length > 7 ? rep.Response.Substring(0, 6) + "..." : rep.Response;
            var    wuser   = WechatHelper.CheckWechatUser(rep.UserId ?? 0);

            if (wuser != null && !string.IsNullOrEmpty(wuser.OpenId))
            {
                string url = string.Format("http://mp.doshine.com/doshinemp/PhoneWeb/RepairDetails?repairid={0}", rep.RepairId);
                WechatHelper.SendModelMessage(
                    wuser.OpenId,
                    url,
                    "EPg0GWHMJR0xupn1IV4VRz3iVrsFakORJ-hxqQ5CZ-U",
                    string.Format("\"first\":{{\"value\":\"抱歉,您的报修订单已经被取消\",\"color\":\"#000000\"}},\"keyword1\":{{\"value\":\"{0}\",\"color\":\"#173177\"}},\"keyword2\":{{\"value\":\"{1}\",\"color\":\"#173177\"}},\"remark\":{{\"value\":\"期待下次再为您服务。\",\"color\":\"#000000\"}}",
                                  content,
                                  rep.CreateDate.ToLongDateString() + " " + rep.CreateDate.ToShortTimeString()
                                  ));
            }

            return(rep);
        }
Example #25
0
        public static ActiveLog AddLog(string option, string remaeks, string openid)
        {
            var db = new ModelContext();

            var usr = WechatHelper.CheckOpenid(openid);

            usr = WechatHelper.CheckUser(usr);
            //usr = WechatHelper.CheckUser(usr);
            if (usr.UserInfoId == null || usr.UserInfoId == 0 || usr.UserInfo == null)
            {
                return(null);
            }

            var tname = System.Configuration.ConfigurationManager.AppSettings["termailname"];
            var tmn   = db.TerminalSet.FirstOrDefault(item => item.Name == tname);

            usr.UserInfo.LastLoginTerminalId = tmn.TerminalId;
            usr.UserInfo.LastLoginTime       = DateTime.Now;

            var log = new ActiveLog
            {
                CreateDate    = DateTime.Now,
                TerminalId    = tmn.TerminalId,
                UserId        = usr.UserInfoId,
                OptionContent = option,
                Remarks       = remaeks,
            };

            db.ActiveLogSet.Add(log);

            usr.UserInfo.LastLoginTime       = DateTime.Now;
            usr.UserInfo.LastLoginTerminalId = tmn.TerminalId;
            db.SaveChanges();

            return(log);
        }
Example #26
0
        /// <summary>
        /// 提交一个新的报修申请
        /// </summary>
        /// <param name="openid">用户openid</param>
        /// <param name="content"></param>
        /// <param name="mediaidList">图片列表,用逗号分割</param>
        /// <returns></returns>
        public Repair Add(string openid, string content, string mediaidList, string phone, int villageid, string name, int recordid)
        {
            var db  = new ModelContext();
            var usr = WechatHelper.CheckOpenid(openid);

            usr = WechatHelper.CheckUser(usr);
            if (usr.UserInfoId == null || usr.UserInfoId == 0 || usr.UserInfo == null)
            {
                return(null);
            }
            var mediaIdArr = mediaidList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);


            var number = GetNewInnerNumber();
            var rep    = new Repair
            {
                Contenet    = content,
                CreateDate  = DateTime.Now,
                Status      = RepairStatus.Apply,
                UserId      = usr.UserInfoId,
                InnerNumber = number,
                PhoneNumber = phone,
                VillageId   = villageid,
                Name        = name,
            };


            db.RepairSet.Add(rep);
            db.SaveChanges();

            //下载文件

            //单个
            //if (!string.IsNullOrEmpty(mediaid))
            //{
            //    WechatImageHelper.AddNewImageForRepair(mediaid, rep.RepairId, openid);
            //}


            //多个
            if (mediaIdArr != null && mediaIdArr.Length > 0)
            {
                List <ImageDownloadLog> md = WechatImageHelper.AddNewImageForRepair(mediaIdArr, rep.RepairId, openid).ToList();
                md.Clear();
            }


            LogHelper.AddLog("Apply a new repair", rep.RepairId.ToString(), openid);

            db.SaveChanges();

            var vill = db.VillageSet.Find(villageid);

            RecordHelper.UpdateRecord(recordid, openid, RecordType.MpRepair, phone, name, vill.Name);

            //发送企业号通知
            var    workernamArr = System.Configuration.ConfigurationManager.AppSettings["repairworkers"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string scontent     = rep.Contenet.Replace("<br />", ",").Length > 7 ? rep.Contenet.Replace("<br />", ",").Substring(0, 6) + "..." : rep.Contenet.Replace("<br />", ",");
            var    msg          = $"收到新的报修申请,请尽快处理!\n报修单位:{rep.Village?.Name}\n报修人:{rep.Name}\n联系方式:{rep.PhoneNumber}\n报修内容:{scontent}\n报修时间:{rep.CreateDate.ToString("yyyy-MM-dd hh:mm")}\n\n<a href=\\\"http://mp.doshine.com/DoShineMP/PhoneWeb/RepairDetailsInterior?repairid={rep.RepairId}\\\">点击查看</a>";

            WechatHelper.SendComponyMessage(workernamArr, msg);

            return(rep);
        }