Esempio n. 1
0
        public JsonResult CommentRequirement(long id, long OperatorUserid, long FarmerUserId, string CommentString, int Score, int SourceType = 0)
        {
            using (ResponseResult <T_FARMER_DEMAND_RESPONSE_RELATION> result = new ResponseResult <T_FARMER_DEMAND_RESPONSE_RELATION>())
            {
                T_FARMER_PUBLISHED_DEMAND model = _commonRepository.GetById <T_FARMER_PUBLISHED_DEMAND>(f => f.Id == id && f.IsDeleted == false && f.CreateUserId == FarmerUserId);
                //验证当前需求编号是否存在于大农户需求表中且当前需求没有被删除并且是excuteuserId创建的
                if (model != null)
                {
                    T_FARMER_DEMAND_RESPONSE_RELATION responseRelation = _commonRepository.GetById <T_FARMER_DEMAND_RESPONSE_RELATION>(f => f.DemandId == id && f.UserId == OperatorUserid);
                    //验证ueserid是否有效
                    if (responseRelation != null)
                    {
                        responseRelation.ScoreFarmer     = Score;
                        responseRelation.CommentsFarmer  = CommentString != null ? CommentString : "";
                        responseRelation.ReplyTimeFarmer = Utility.TimeHelper.GetChinaLocalTime();
                        var bonusDPoint = int.Parse(_sysSettingRepository.GetSetting(DataKey.BonusDPointByCommentSettingID).SETTING_VALUE);
                        responseRelation.BonusDPoint = bonusDPoint;

                        //评价成功后更改需求状态为已评价(100503)
                        T_FARMER_PUBLISHED_DEMAND fmodel = _commonRepository.GetById <T_FARMER_PUBLISHED_DEMAND>(f => f.Id == id);
                        if (fmodel == null)
                        {
                            result.IsSuccess = false;
                            result.Message   = "数据意外丢失!";
                            return(Json(result));
                        }

                        if (fmodel.DemandTypeId.ToString().StartsWith("1008"))
                        {
                            result.IsSuccess = false;
                            result.Message   = "您不能评价产业商,操作被禁止!";
                            return(Json(result));
                        }

                        //执行评价操作
                        _commonRepository.Modify <T_FARMER_DEMAND_RESPONSE_RELATION>(responseRelation, f => f.DemandId == id && f.UserId == OperatorUserid);
                        //需求单状态判断
                        if (fmodel.PublishStateId == 100507)//大农户已经评价过,农机手再评论此需求单时,状态为已评价(100503)
                        {
                            fmodel.PublishStateId = 100503;
                        }
                        else
                        {
                            fmodel.PublishStateId = 100508;//农机手的评价
                        }
                        _commonRepository.Modify <T_FARMER_PUBLISHED_DEMAND>(fmodel, f => f.Id == id);
                        if (Score > 0)
                        {
                            var dpointTotal = Score * bonusDPoint;
                            //给评价人农机手自己添加系统默认先锋币
                            _commonRepository.AddDuPontPoint(responseRelation.UserId, "评价添加先锋币", (int)SysCfg.SysUserId, bonusDPoint);

                            //给被评价人大农户添加先锋币
                            _commonRepository.AddDuPontPoint(model.CreateUserId, "被评价添加先锋币", (int)SysCfg.SysUserId, dpointTotal);

                            //计算被评价者的角色等级
                            var operatorRoleId = (int)RoleType.Farmer;
                            var userRoleInfo   = _userRoleService.GetAll(p => p.MemberType && p.UserID == FarmerUserId && p.RoleID == operatorRoleId).FirstOrDefault();
                            if (userRoleInfo != null)
                            {
                                if (userRoleInfo.TotalReplyCount == null)
                                {
                                    userRoleInfo.TotalReplyCount = 0;
                                }

                                if (userRoleInfo.TotalStarCount == null)
                                {
                                    userRoleInfo.TotalStarCount = 0;
                                }

                                userRoleInfo.TotalReplyCount++;
                                userRoleInfo.TotalStarCount += Score;
                                var averageStar = userRoleInfo.TotalStarCount / userRoleInfo.TotalReplyCount;
                                _userRoleService.Update(p => p.UserID == FarmerUserId && p.RoleID == operatorRoleId, t => new T_USER_ROLE_RELATION
                                {
                                    Star            = averageStar,
                                    TotalStarCount  = userRoleInfo.TotalStarCount,
                                    TotalReplyCount = userRoleInfo.TotalReplyCount
                                });
                            }
                        }

                        result.IsSuccess = true;
                        result.Entity    = responseRelation;
                        #region 调用E田接口,更新订单状态
                        //评价大农户订单
                        Task taskasync = new Task(() => AcceptOrder(model, responseRelation.UserId, responseRelation, 1));
                        taskasync.Start();
                        #endregion
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = String.Format("{0} - " + ResponeString.ParmetersInvalidMessage, OperatorUserid.ToString());
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = ResponeString.NoJurisdiction;
                }

                return(Json(result));
            }
        }
        public ActionResult RepairOriginalUserStar()
        {
            if (UserInfo == null || UserInfo.IsSuperAdmin == false)
            {
                throw new UnauthorizedAccessException();
            }

            using (var result = new ResponseResult <object>())
            {
                var farmerRoleId = (int)RoleType.Farmer;
                //获取所有的大农户用户
                var farmerList = _userRoleService.GetAll(p => p.RoleID == farmerRoleId && p.MemberType);
                //获取大农户可以发给产业商的需求类型编号列表
                var farmerPublishedForBusinessDemandList = _sysDictionaryService.GetAll(p => p.ParentCode == 100800);
                var forBusinessDemandCodeList            = farmerPublishedForBusinessDemandList.Select(p => p.Code).ToList();

                if (farmerList != null && farmerList.Count() > 0)
                {
                    foreach (var farmer in farmerList)
                    {
                        //获取大农户发布的所有针对产业商需求
                        var farmerPublishedDemandsForBusiness = _farmerDemandService.GetAll(p =>
                                                                                            forBusinessDemandCodeList.Contains(p.DemandTypeId) &&
                                                                                            p.CreateUserId == farmer.UserID);

                        var totalCommentCount      = 0;
                        var totalCommentStartCount = 0;

                        if (farmerPublishedDemandsForBusiness != null && farmerPublishedDemandsForBusiness.Count() > 0)
                        {
                            foreach (var demand in farmerPublishedDemandsForBusiness)
                            {
                                //获取该需求的响应记录,大农户发布的需求,响应记录只有一条
                                var farmerDemandReplyList = _farmerDemandService.GetDemandReplyList(demand.Id);
                                if (farmerDemandReplyList != null && farmerDemandReplyList.Count() > 0)
                                {
                                    var farmerDemandReplyDetail = farmerDemandReplyList.FirstOrDefault();
                                    if (farmerDemandReplyDetail.Score > 0)
                                    {
                                        totalCommentCount++;
                                        totalCommentStartCount += farmerDemandReplyDetail.Score;
                                    }
                                }
                            }
                        }

                        //获取产业商发布给大农户的需求
                        var businessDemandReplyList = _businessDemandResponseService.GetAll(p => p.UserId == farmer.UserID);
                        if (businessDemandReplyList != null && businessDemandReplyList.Count() > 0)
                        {
                            foreach (var demand in businessDemandReplyList)
                            {
                                if (demand.Score > 0)
                                {
                                    totalCommentCount++;
                                    totalCommentStartCount += demand.Score;
                                }
                            }
                        }

                        if (totalCommentCount > 0)
                        {
                            _userRoleService.Update(p => p.UserID == farmer.UserID && p.RoleID == farmerRoleId && p.MemberType, t => new T_USER_ROLE_RELATION
                            {
                                TotalReplyCount = totalCommentCount,
                                TotalStarCount  = totalCommentStartCount,
                                Star            = totalCommentStartCount / totalCommentCount
                            });
                        }
                    }
                }

                var operatorRoleId = (int)RoleType.MachineryOperator;

                //获取农机手信息
                var operatorList = _userRoleService.GetAll(p => p.MemberType && p.RoleID == operatorRoleId);
                if (operatorList != null && operatorList.Count() > 0)
                {
                    foreach (var operatorUser in operatorList)
                    {
                        var totalCommentCount      = 0;
                        var totalCommentStartCount = 0;
                        //获取农机手响应记录
                        var farmerDemandResponseList = _farmerDemandResponse.GetAll(p => p.UserId == operatorUser.UserID);
                        if (farmerDemandResponseList != null && farmerDemandResponseList.Count() > 0)
                        {
                            foreach (var demand in farmerDemandResponseList)
                            {
                                if (demand.Score > 0)
                                {
                                    totalCommentCount++;
                                    totalCommentStartCount += demand.Score;
                                }
                            }
                        }

                        if (totalCommentCount > 0)
                        {
                            _userRoleService.Update(p => p.UserID == operatorUser.UserID && p.RoleID == operatorRoleId && p.MemberType, t => new T_USER_ROLE_RELATION
                            {
                                TotalReplyCount = totalCommentCount,
                                TotalStarCount  = totalCommentStartCount,
                                Star            = totalCommentStartCount / totalCommentCount
                            });
                        }
                    }
                }

                result.IsSuccess = true;
                result.Message   = "用户等级数据修复成功!";
                return(new JsonResultEx(result));
            }
        }
Esempio n. 3
0
        public JsonResult CommentRequirement(int isOwn, long id, long userid, string commentString, int score)
        {
            using (ResponseResult <object> result = new ResponseResult <object>())
            {
                //产业商的需求
                if (isOwn == 0)
                {
                    T_BUSINESS_PUBLISHED_DEMAND model = _commonRepository.GetById <T_BUSINESS_PUBLISHED_DEMAND>(b => b.Id == id);
                    //验证当前需求编号是否存在
                    if (model != null)
                    {
                        T_BUSINESS_DEMAND_RESPONSE_RELATION responseRelation = _commonRepository.GetById <T_BUSINESS_DEMAND_RESPONSE_RELATION>(b => b.DemandId == id && b.UserId == userid);
                        //验证ueserid是否有效
                        if (responseRelation != null)
                        {
                            responseRelation.Score     = score;
                            responseRelation.Comments  = commentString != null ? commentString : "";
                            responseRelation.ReplyTime = Utility.TimeHelper.GetChinaLocalTime();
                            var bonusDPoint = int.Parse(this._sysSettingRepository.GetSetting(DataKey.BonusDPointByCommentSettingID).SETTING_VALUE);
                            responseRelation.BonusDPoint = bonusDPoint;

                            //执行评价操作
                            _commonRepository.Modify <T_BUSINESS_DEMAND_RESPONSE_RELATION>(responseRelation, b => b.DemandId == id && b.UserId == userid);
                            if (score > 0)
                            {
                                var dpointTotal = score * bonusDPoint;
                                //给评价人自己添加系统默认先锋币
                                _commonRepository.AddDuPontPoint(model.CreateUserId, "评价添加先锋币", (int)SysCfg.SysUserId, bonusDPoint);
                                //给被评价人添加先锋币
                                _commonRepository.AddDuPontPoint(responseRelation.UserId, "被评价添加先锋币", (int)SysCfg.SysUserId, dpointTotal);

                                //计算被评价者的角色等级
                                var farmerRoleId = (int)RoleType.Farmer;
                                var userRoleInfo = _userRoleService.GetAll(p => p.MemberType && p.UserID == userid && p.RoleID == farmerRoleId).FirstOrDefault();
                                if (userRoleInfo != null)
                                {
                                    if (userRoleInfo.TotalReplyCount == null)
                                    {
                                        userRoleInfo.TotalReplyCount = 0;
                                    }

                                    if (userRoleInfo.TotalStarCount == null)
                                    {
                                        userRoleInfo.TotalStarCount = 0;
                                    }

                                    userRoleInfo.TotalReplyCount++;
                                    userRoleInfo.TotalStarCount += score;
                                    var averageStar = userRoleInfo.TotalStarCount / userRoleInfo.TotalReplyCount;
                                    _userRoleService.Update(p => p.UserID == userid && p.RoleID == farmerRoleId, t => new T_USER_ROLE_RELATION
                                    {
                                        Star            = averageStar,
                                        TotalStarCount  = userRoleInfo.TotalStarCount,
                                        TotalReplyCount = userRoleInfo.TotalReplyCount
                                    });
                                }
                            }

                            //评价成功后更改需求状态为已评价(100503)
                            T_BUSINESS_PUBLISHED_DEMAND fmodel = _commonRepository.GetById <T_BUSINESS_PUBLISHED_DEMAND>(f => f.Id == id);
                            fmodel.PublishStateId = 100503;
                            _commonRepository.Modify <T_BUSINESS_PUBLISHED_DEMAND>(fmodel, f => f.Id == id);
                            result.IsSuccess = true;
                            result.Entity    = responseRelation;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Message   = string.Format("{0} - " + ResponeString.NoJurisdiction, userid.ToString());
                        }
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = string.Format("{0} - " + ResponeString.ParmetersInvalidMessage, id.ToString());
                    }
                }
                else
                {
                    T_FARMER_PUBLISHED_DEMAND model = _commonRepository.GetById <T_FARMER_PUBLISHED_DEMAND>(b => b.Id == id);
                    //验证当前需求编号是否存在于产业商需求表中且当前需求没有被删除且是excuteuserId创建的
                    if (model != null)
                    {
                        T_FARMER_DEMAND_RESPONSE_RELATION responseRelation = _commonRepository.GetById <T_FARMER_DEMAND_RESPONSE_RELATION>(b => b.DemandId == id && b.UserId == userid);
                        //验证ueserid是否有效
                        if (responseRelation != null)
                        {
                            responseRelation.Score     = score;
                            responseRelation.Comments  = commentString != null ? commentString : "";
                            responseRelation.ReplyTime = Utility.TimeHelper.GetChinaLocalTime();
                            var bonusDPoint = int.Parse(this._sysSettingRepository.GetSetting(DataKey.BonusDPointByCommentSettingID).SETTING_VALUE);
                            responseRelation.BonusDPoint = bonusDPoint;
                            //执行评价操作
                            _commonRepository.Modify <T_FARMER_DEMAND_RESPONSE_RELATION>(responseRelation, b => b.DemandId == id && b.UserId == userid);
                            //评价成功后更改需求状态为已评价(100503)
                            T_FARMER_PUBLISHED_DEMAND fmodel = _commonRepository.GetById <T_FARMER_PUBLISHED_DEMAND>(f => f.Id == id);
                            fmodel.PublishStateId = 100503;
                            _commonRepository.Modify <T_FARMER_PUBLISHED_DEMAND>(fmodel, f => f.Id == id);
                            if (score > 0)
                            {
                                var dpointTotal = score * bonusDPoint;
                                //给评价人自己添加系统默认先锋币
                                _commonRepository.AddDuPontPoint(responseRelation.UserId, "评价添加先锋币", (int)SysCfg.SysUserId, bonusDPoint);
                                //给被评价人添加先锋币
                                _commonRepository.AddDuPontPoint(model.CreateUserId, "被评价添加先锋币", (int)SysCfg.SysUserId, dpointTotal);

                                //计算被评价者的角色等级
                                var farmerRoleId = (int)RoleType.Farmer;
                                var userRoleInfo = _userRoleService.GetAll(p => p.MemberType && p.UserID == userid && p.RoleID == farmerRoleId).FirstOrDefault();
                                if (userRoleInfo != null)
                                {
                                    if (userRoleInfo.TotalReplyCount == null)
                                    {
                                        userRoleInfo.TotalReplyCount = 0;
                                    }

                                    if (userRoleInfo.TotalStarCount == null)
                                    {
                                        userRoleInfo.TotalStarCount = 0;
                                    }

                                    userRoleInfo.TotalReplyCount++;
                                    userRoleInfo.TotalStarCount += score;
                                    var averageStar = userRoleInfo.TotalStarCount / userRoleInfo.TotalReplyCount;
                                    _userRoleService.Update(p => p.UserID == userid && p.RoleID == farmerRoleId, t => new T_USER_ROLE_RELATION
                                    {
                                        Star            = averageStar,
                                        TotalStarCount  = userRoleInfo.TotalStarCount,
                                        TotalReplyCount = userRoleInfo.TotalReplyCount
                                    });
                                }
                            }
                            result.IsSuccess = true;
                            result.Entity    = responseRelation;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Message   = string.Format("{0} - " + ResponeString.NoJurisdiction, userid.ToString());
                        }
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = string.Format("{0} - " + ResponeString.ParmetersInvalidMessage, id.ToString());
                    }
                }
                return(Json(result));
            }
        }