Beispiel #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));
            }
        }
Beispiel #2
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));
            }
        }