Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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));
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
            }
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }