Ejemplo n.º 1
0
        //值班认领 签到、签退
        public int HandleAdd(VA_HandleAddViewModel AddViewModel)
        {
            int count = 0;
            MydutyClaim_Sign model = new MydutyClaim_Sign();
            //是否注册
            var VolunteerInfo = _IVolunteerInfoRepository.SearchInfoByID(AddViewModel.VID);

            if (VolunteerInfo == null)
            {
                count = 6;
                return(count);
            }

            double points = 0;
            ////认领得 值班信息
            MydutyClaim_Info claim_Info = _IMydutyClaimInfoRepository.GetByUidandID(AddViewModel.VID, AddViewModel.ContentID);

            if (claim_Info != null)
            {
                //判断是否在值班区间内进行打卡 20200622  值班时间前后15 分钟均可签到签退
                DateTime start = DateTime.Parse(claim_Info.StartDutyTime.ToString());
                DateTime end   = DateTime.Parse(claim_Info.EndDutyTime.ToString());

                if ((DateTime.Now >= start.AddMinutes(-15) && DateTime.Now <= start.AddMinutes(15) && AddViewModel.type == "in") ||
                    (DateTime.Now >= end && DateTime.Now <= end.AddMinutes(15) && AddViewModel.type == "out"))
                {
                    OndutyClaims_Info ondutyClaims = _claimsInfoRepository.GetByID(claim_Info.OndutyClaims_InfoId);
                    if (ondutyClaims != null)
                    {
                        Normalization_Info Normalization = _normalizationInfo.NormalizationByID(ondutyClaims.Normalization_InfoId);
                        if (Normalization != null)
                        {
                            points = double.Parse(Normalization.PointsEarned);
                        }

                        model.OndutyClaims_InfoId = ondutyClaims.id;
                        model.MydutyClaim_InfoID  = AddViewModel.ContentID;
                        //获取小区经纬度信息
                        List <User_Depart> departAll = _IVolunteerInfoRepository.GetDepartAll();

                        var departList = _IMapper.Map <List <User_Depart>, List <UserDepartSearchMidModel> >(departAll);

                        List <UserDepartSearchMidModel> result = new List <UserDepartSearchMidModel>();
                        result.AddRange(departList.Where(p => p.Code == ondutyClaims.SubdistrictID).ToList());
                        UserDepartSearchMidModel depart = new UserDepartSearchMidModel();
                        if (result.Count > 0)
                        {
                            depart = result.First();
                        }


                        //获取 经纬度
                        if (!String.IsNullOrEmpty(AddViewModel.Checklongitude) && !String.IsNullOrEmpty(AddViewModel.Checklatitude))
                        {
                            //进行地址判断 活动地址方圆1000米可以签到
                            if (!String.IsNullOrEmpty(depart.longitude) && !String.IsNullOrEmpty(depart.latitude))
                            {
                                var checks = CheckAddress(double.Parse(depart.longitude), double.Parse(depart.latitude), double.Parse(AddViewModel.Checklongitude), double.Parse(AddViewModel.Checklatitude), 1);
                                if (!checks)
                                {
                                    count = 9;
                                    return(count);
                                }
                            }
                            else
                            {
                                count = 8;
                                return(count);
                            }
                        }
                        else
                        {
                            count = 7;
                            return(count);
                        }
                    }
                }
                else
                {
                    count = 5;
                    return(count);
                }
            }
            else
            {
                count = 4;
                return(count);
            }

            DEncrypt encrypt = new DEncrypt();

            //保存签到签退信息
            model.id             = Guid.NewGuid().ToString();
            model.Userid         = AddViewModel.VID;
            model.UserName       = encrypt.Decrypt(VolunteerInfo.Name);
            model.CheckTime      = DateTime.Now;
            model.type           = AddViewModel.type;
            model.CreateUser     = VolunteerInfo.ID;
            model.CreateDate     = DateTime.Now;
            model.CheckAddress   = AddViewModel.CheckAddress;
            model.Checklongitude = AddViewModel.Checklongitude;
            model.Checklatitude  = AddViewModel.Checklatitude;


            _mydutyClaim_Sign.Add(model);
            count = _mydutyClaim_Sign.SaveChanges();
            if (count == 1)
            {
                string id = Guid.NewGuid().ToString();

                //签退 时按时长积分继续计算
                if (AddViewModel.type == "out")
                {
                    Volunteer_Score score = new Volunteer_Score();
                    score.ID         = id;
                    score.ContentID  = AddViewModel.ContentID;
                    score.tableName  = "MydutyClaim_Info";
                    score.VID        = AddViewModel.VID;
                    score.type       = "out";
                    score.Score      = points;
                    score.CreateUser = AddViewModel.VID;
                    score.CreateDate = DateTime.Now;

                    _IVolunteer_ScoreRepository.Add(score);
                    int b = _IVolunteer_ScoreRepository.SaveChanges();
                    if (b > 0)
                    {
                        //插入到  泰便利积分表  20200622
                        ET_points ipointMiddle = new ET_points();

                        ipointMiddle.ID         = id;
                        ipointMiddle.uid        = AddViewModel.VID;
                        ipointMiddle.points     = score.Score;
                        ipointMiddle.type       = "MydutySign";
                        ipointMiddle.tableName  = "TedaVolunteerDB.dbo.Volunteer_Score";
                        ipointMiddle.CreateUser = AddViewModel.VID;
                        ipointMiddle.CreateDate = DateTime.Now;
                        eT_PointsRepository.Add(ipointMiddle);
                        int j = eT_PointsRepository.SaveChanges();
                    }
                }
            }

            return(count);
        }
 //删除信息
 public void RemoveInfo(ET_points points)
 {
     DbSet.Remove(points);
 }
 public virtual void Add(ET_points obj)
 {
     DbSet.Add(obj);
 }
 public virtual void Update(ET_points obj)
 {
     DbSet.Update(obj);
 }
        //发布者审核 认领人上传的 处理结果信息    审核通过任务完结
        public BaseViewModel SetSignPass(ContentIDandVIDModel model)
        {
            BaseViewModel result        = new BaseViewModel();
            var           VolunteerInfo = _IVolunteerInfoRepository.SearchInfoByID(model.VID);

            if (VolunteerInfo == null)
            {
                result.ResponseCode = 400;
                result.Message      = "操作失败";
                return(result);
            }

            //该互助信息  更新状态为 已完结  2
            VHelpArea area = _IVHelpAreaRepository.SearchInfoByID(model.ContentID);
            //获取 志愿者 上传的 处理结果的信息进行审核
            List <VHA_Sign> list = _IVHA_SignRepository.GetByContentID(model.ContentID, "2");
            VHA_Sign        item = list.First();

            item.opinion    = "审核通过,任务完结";
            item.Status     = "1";
            item.UpdateUser = area.CreateUser;
            item.UpdateDate = DateTime.Now;
            _IVHA_SignRepository.Update(item);
            int a = _IVHA_SignRepository.SaveChanges();

            //本次处理结果 审核信息通过
            VHA_Handle modelHandle = _IVHA_HandleRepository.GetVolunteerHandle(item.bak1);

            modelHandle.Status     = "1";
            modelHandle.UpdateUser = area.CreateUser;
            modelHandle.UpdateDate = DateTime.Now;
            _IVHA_HandleRepository.Update(modelHandle);
            int b = _IVHA_HandleRepository.SaveChanges();


            area.Status     = "2";
            area.UpdateUser = area.CreateUser;
            area.UpdateDate = DateTime.Now;
            _IVHelpAreaRepository.Update(area);
            int c = _IVHelpAreaRepository.SaveChanges();

            if (c > 0)
            {
                string id = Guid.NewGuid().ToString();
                //插入积分表
                Volunteer_Score score = new Volunteer_Score();
                score.ID         = id;
                score.ContentID  = model.ContentID;
                score.tableName  = "VHelpArea";
                score.VID        = model.VID;
                score.type       = "done";
                score.Score      = double.Parse(area.Score);
                score.CreateUser = model.VID;
                score.CreateDate = DateTime.Now;

                _IVolunteer_ScoreRepository.Add(score);
                int n = _IVolunteer_ScoreRepository.SaveChanges();
                if (n > 0)
                {
                    //插入到 泰便利积分表 20200622
                    ET_points ipointMiddle = new ET_points();

                    ipointMiddle.ID         = id;
                    ipointMiddle.uid        = VolunteerInfo.ID;
                    ipointMiddle.points     = double.Parse(area.Score);
                    ipointMiddle.type       = "VolunteerHelp";
                    ipointMiddle.tableName  = "TedaVolunteerDB.dbo.Volunteer_Score";
                    ipointMiddle.CreateUser = VolunteerInfo.ID;
                    ipointMiddle.CreateDate = DateTime.Now;
                    eT_PointsRepository.Add(ipointMiddle);
                    int j = eT_PointsRepository.SaveChanges();
                }


                //提示信息:您认领标题为XXX互助信息,互助信息,处理审核通过,任务完结
                Volunteer_MessageMiddle middle = new Volunteer_MessageMiddle();
                middle.Contents = "您认领标题为 " + area.Title + " 互助信息,处理审核通过,任务完结";

                Volunteer_Info volunteer_Info = _IVolunteerInfoRepository.SearchInfoByID(model.VID);
                middle.Name = volunteer_Info.Name;
                middle.VID  = volunteer_Info.ID;
                middle.VNO  = volunteer_Info.VNO;

                Volunteer_Message message = _IMapper.Map <Volunteer_MessageMiddle, Volunteer_Message>(middle);
                message.ID         = Guid.NewGuid().ToString();
                message.CreateDate = DateTime.Now;
                message.CreateUser = model.VID;
                message.Status     = "0";

                _IVolunteer_MessageRepository.Add(message);
                int f = _IVolunteer_MessageRepository.SaveChanges();


                result.ResponseCode = 200;
                result.Message      = "操作成功";
            }
            else
            {
                result.ResponseCode = 400;
                result.Message      = "操作失败";
            }

            return(result);
        }