예제 #1
0
        public JsonResult CancelFarmerRequirement(long id, string OperatorUserId, string FarmerUserId, int OrderState)
        {
            using (ResponseResult <T_FARMER_PUBLISHED_DEMAND> result = new ResponseResult <T_FARMER_PUBLISHED_DEMAND>())
            {
                T_FARMER_PUBLISHED_DEMAND model = _commonRepository.GetById <T_FARMER_PUBLISHED_DEMAND>(f => f.Id == id && f.IsDeleted == false && f.CreateUserId.ToString() == FarmerUserId);
                //验证当前需求编号是否存在于大农户需求表中且当前需求没有被删除并且是excuteuserId创建的
                if (model != null)
                {
                    if (OrderState == 539)
                    {
                        model.PublishStateId = (int)PublishState.WaitForResponse; //100501;//待响应
                    }
                    try
                    {
                        var taskresult = Task.Run(() => this._operatorRepository.UpdateDEMAND(model, id, OperatorUserId)).Result;
                        result.IsSuccess = taskresult > 0 ? true : false;
                    }
                    catch (Exception ex)
                    {
                        string logErrstring = DateTime.Now.ToString("\r\n---------MM/dd/yyyy HH:mm:ss,fff---------\r\n") + "错误";
                        IOHelper.WriteLogToFile(logErrstring + ex.Message, HttpContext.Server.MapPath("~/App_Data/Log") + @"\DuPontRequestEtLog");
                    }
                    //result.IsSuccess= _operatorRepository.UpdateDemand(model, id, OperatorUserId);
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = "接口安全验证通过,但是" + ResponeString.NoJurisdiction;
                }

                return(Json(result));
            }
        }
        public readonly int[] farmerDemandOffline = { 100503, 100504, 100505, 100506 }; //已评价、已取消、系统关闭、已关闭


        public int Insert(T_FARMER_PUBLISHED_DEMAND entity)
        {
            using (var dbContext = new DuPont_TestContext())
            {
                dbContext.T_FARMER_PUBLISHED_DEMAND.Add(entity);
                return(dbContext.SaveChanges());
            }
        }
 public int Delete(T_FARMER_PUBLISHED_DEMAND entity)
 {
     if (entity != null)
     {
         using (var dbContext = new DuPont_TestContext())
         {
             dbContext.T_FARMER_PUBLISHED_DEMAND.Remove(entity);
             return(dbContext.SaveChanges());
         }
     }
     return(0);
 }
 public int Update(T_FARMER_PUBLISHED_DEMAND entity)
 {
     using (var dbContext = new DuPont_TestContext())
     {
         var dbEntry = dbContext.T_FARMER_PUBLISHED_DEMAND.Find(entity.Id);
         if (dbEntry != null)
         {
             ClassValueCopyHelper.Copy(dbEntry, entity);
             return(dbContext.SaveChanges());
         }
     }
     return(0);
 }
예제 #5
0
        /// <summary>
        /// 先锋帮大农户取消需求订单
        /// </summary>
        /// <param name="t_FARMER_PUBLISHED_DEMAND"></param>
        /// <returns></returns>
        private string UpdateCancleOrder(T_FARMER_PUBLISHED_DEMAND t_FARMER_PUBLISHED_DEMAND)
        {
            DtoUpdateFarmerDemandModel updatemodel = new DtoUpdateFarmerDemandModel();

            updatemodel.Id         = t_FARMER_PUBLISHED_DEMAND.Id;
            updatemodel.OrderState = t_FARMER_PUBLISHED_DEMAND.PublishStateId;
            updatemodel.FarmerName = t_FARMER_PUBLISHED_DEMAND.CreateUserId.ToString();
            #region 调用内网服务返回数据
            //var content = new Dictionary<string, string>();
            //content.Add("Id", updatemodel.Id.ToString());
            ////农机手id
            //var resultmodel = PostStandardWithSameControllerAction<DtoUpdateFarmerDemandModel>("Operator", "AcceptOrder", content);
            //if (resultmodel.IsSuccess == true)
            //{
            //    if (resultmodel.Entity != null)
            //    {
            //        updatemodel.OperatoName = resultmodel.Entity.OperatoName;
            //        updatemodel.FarmerName = resultmodel.Entity.FarmerName;
            //    }
            //}
            #endregion
            #region 调用E田接口
            var etcontent = new Dictionary <string, string>();
            etcontent = ModelHelper.GetPropertyDictionary <DtoUpdateFarmerDemandModel>(updatemodel);
            //加密要传递的参数
            Dictionary <string, string> rurlcontent = EncryptDictionary(etcontent);
            //e田接口地址
            string Apiurl = ConfigHelper.GetAppSetting("EtApiUrl");
            string Eturl  = Apiurl + "/wei/work/dupont/order_status.jsp";
            //证书的路径
            var etcertification = GetCertificationFilePath();
            //证书的密码
            var etcertificationPwd = GetCertificationPwd();
            var etresult           = HttpAsynchronousTool.CustomHttpWebRequestPost(Eturl, rurlcontent, etcertification, etcertificationPwd);
            var resultModel        = JsonConvert.DeserializeObject <ETResponseResult <object> >(etresult);
            if (resultModel.IsSuccess == true)
            {
                //写文件确认我方调用e田接口完成
                string logErrstring = DateTime.Now.ToString("\r\n---------MM/dd/yyyy HH:mm:ss,fff---------\r\n") + "先锋帮大农户取消需求订单";
                string parmeters    = null;
                foreach (var item in rurlcontent)
                {
                    parmeters += item.Key + ":" + item.Value + "\r\n";
                }
                IOHelper.WriteLogToFile(logErrstring + "\r\n" + parmeters, RelativePath() + @"\DuPontRequestEtLog");
            }
            return(resultModel.IsSuccess.ToString());

            #endregion
        }
        /// <summary>
        /// E田农机手取消订单
        /// </summary>
        /// <param name="fmodel"></param>
        /// <param name="id"></param>
        /// <param name="OperatorUserId"></param>
        /// <returns></returns>
        public async Task <int> UpdateDEMAND(T_FARMER_PUBLISHED_DEMAND fmodel, long id, string OperatorUserId)
        {
            using (var dbContext = new DuPont_TestContext())
            {
                using (var dbTransaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        if (fmodel.Id == id)
                        {
                            fmodel.ModifiedTime = DateTime.Now;
                            var dbEntry = dbContext.Entry <T_FARMER_PUBLISHED_DEMAND>(fmodel);
                            dbEntry.State = EntityState.Modified;
                            var  operatoruser   = dbContext.T_USER.SingleOrDefault(x => x.WeatherCity == OperatorUserId);
                            long operatoruserid = 0;
                            if (operatoruser == null)
                            {
                                operatoruserid = dbContext.T_USER.SingleOrDefault(x => x.Id.ToString() == OperatorUserId).Id;
                            }
                            else
                            {
                                operatoruserid = operatoruser.Id;
                            }
                            var responsemodel = dbContext.T_FARMER_DEMAND_RESPONSE_RELATION.SingleOrDefault(x => x.DemandId == id && x.UserId == operatoruserid);
                            dbContext.T_FARMER_DEMAND_RESPONSE_RELATION.Remove(responsemodel);
                        }
                        var r = await dbContext.SaveChangesAsync();//要使用异步保存,必须使用await

                        dbTransaction.Commit();
                        return(r);
                    }
                    catch (Exception ex) {
                        dbTransaction.Rollback();
                        return(0);
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        ///  重新整理订单数据发送给E田
        /// </summary>
        /// <param name="farmerdemand">大农户需求单</param>
        /// <returns></returns>
        private string ReturnOrderModel(T_FARMER_PUBLISHED_DEMAND farmerdemand)
        {
            try
            {
                var content = new Dictionary <string, string>();
                content.Add("AcresId", farmerdemand.AcresId.ToString());
                if (!string.IsNullOrWhiteSpace(farmerdemand.Township))
                {
                    content.Add("Address", farmerdemand.Township);
                }
                else if (!string.IsNullOrWhiteSpace(farmerdemand.Region))
                {
                    content.Add("Address", farmerdemand.Region);
                }
                else if (!string.IsNullOrWhiteSpace(farmerdemand.City))
                {
                    content.Add("Address", farmerdemand.City);
                }
                else if (!string.IsNullOrWhiteSpace(farmerdemand.Province))
                {
                    content.Add("Address", farmerdemand.Province);
                }
                content.Add("UserId", farmerdemand.CreateUserId.ToString());
                //证书的路径
                var certification = GetCertificationFilePath();
                //证书的密码
                var    certificationPwd = GetCertificationPwd();
                string baseurl          = ConfigHelper.GetAppSetting(DataKey.RemoteApiForRelease);
                //这里发布了需要替换,因为多一层api目录
                var result = PostStandardWithSameControllerAction <DtoFarmerRequirementModel>("FarmerRequirement", "ReturnOrderModel", content);
                DtoFarmerRequirementModel resultmodel = new DtoFarmerRequirementModel();
                if (result.IsSuccess)
                {
                    resultmodel = result.Entity;
                }
                resultmodel.OrderId      = farmerdemand.Id;
                resultmodel.UserId       = farmerdemand.CreateUserId;
                resultmodel.CropId       = farmerdemand.CropId;
                resultmodel.DemandTypeId = farmerdemand.DemandTypeId;
                resultmodel.Brief        = farmerdemand.Brief;
                resultmodel.PhoneNum     = farmerdemand.PhoneNumber;
                resultmodel.CreateTime   = DateTime.Now;
                //干活日期
                string tempdate = farmerdemand.ExpectedDate;
                if (tempdate.Contains(',') || tempdate.Contains('-'))
                {
                    string[] tempdates = tempdate.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (tempdates.Length > 1)
                    {
                        resultmodel.StartDate = tempdates[0].ToString();
                        resultmodel.EndDate   = tempdates[tempdates.Length - 1].ToString();
                    }
                    else
                    {
                        resultmodel.StartDate = tempdates[0].ToString();
                        resultmodel.EndDate   = tempdates[0].ToString();
                    }
                }
                else if (tempdate.Contains('、'))
                {
                    if (tempdate.EndsWith("、"))
                    {
                        tempdate = tempdate.TrimEnd('、');
                    }
                    string[] tempdates = tempdate.Split(new char[] { '、' }, StringSplitOptions.RemoveEmptyEntries);
                    if (tempdates.Length > 1)
                    {
                        resultmodel.StartDate = Convert.ToDateTime(tempdates[0].ToString()).ToString("yyyy-MM-dd");
                        resultmodel.EndDate   = Convert.ToDateTime(tempdates[tempdates.Length - 1].ToString()).ToString("yyyy-MM-dd");
                    }
                    else
                    {
                        resultmodel.StartDate = Convert.ToDateTime(tempdates[0].ToString()).ToString("yyyy-MM-dd");
                        resultmodel.EndDate   = Convert.ToDateTime(tempdates[0].ToString()).ToString("yyyy-MM-dd");
                    }
                }
                else
                {
                    resultmodel.StartDate = Convert.ToDateTime(tempdate).ToString("yyyy-MM-dd");
                    resultmodel.EndDate   = Convert.ToDateTime(tempdate).ToString("yyyy-MM-dd");
                }
                #region 调用E田接口
                var etcontent = new Dictionary <string, string>();
                etcontent = ModelHelper.GetPropertyDictionary <DtoFarmerRequirementModel>(resultmodel);
                //加密要传递的参数
                Dictionary <string, string> rurlcontent = EncryptDictionary(etcontent);
                //e田接口地址
                string Apiurl = ConfigHelper.GetAppSetting("EtApiUrl");
                string Eturl  = Apiurl + "/wei/work/dupont/farmer_order.jsp";
                //证书的路径
                var etcertification = GetCertificationFilePath();
                //证书的密码
                var etcertificationPwd = GetCertificationPwd();
                var etresult           = HttpAsynchronousTool.CustomHttpWebRequestPost(Eturl, rurlcontent, etcertification, etcertificationPwd);
                var resultModel        = JsonConvert.DeserializeObject <ETResponseResult <object> >(etresult);
                if (resultModel.IsSuccess == true)
                {  //写文件确认我方调用e田接口完成
                    string logErrstring = DateTime.Now.ToString("\r\n---------MM/dd/yyyy HH:mm:ss,fff---------\r\n") + "大农户的订单";
                    string parmeters    = null;
                    foreach (var item in rurlcontent)
                    {
                        parmeters += item.Key + ":" + item.Value + "\r\n";
                    }

                    IOHelper.WriteLogToFile("FarmerRequirement/SaveRequirement" + logErrstring + "\r\n" + parmeters, RelativePath() + @"\DuPontRequestEtLog");
                }
                return(resultModel.IsSuccess.ToString());
            }
            catch (Exception ex)
            {
                IOHelper.WriteLogToFile("FarmerRequirement/SaveRequirement" + "\r\n错误:" + ex.Message, RelativePath() + @"\DuPontRequestEtLog");
            }
            return("");

            #endregion
        }
예제 #8
0
        /// <summary>
        /// 应答详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BusinessReplyDetailModel GetReplyDetail(long id)
        {
            using (var dbContext = new DuPont_TestContext())
            {
                //农机手应答详情包括订单详情和应答详情,订单详情中的地址是大农户发布需求的地址,应答详情中的地址是农机手注册时的地址
                var rmodel = dbContext.Set <T_FARMER_DEMAND_RESPONSE_RELATION>().Where(b => b.Id == id).FirstOrDefault();
                if (rmodel != null)
                {
                    T_FARMER_PUBLISHED_DEMAND tmodel = dbContext.Set <T_FARMER_PUBLISHED_DEMAND>().Where(f => f.Id == rmodel.DemandId).FirstOrDefault();
                    if (tmodel != null)
                    {
                        var    type       = dbContext.Set <T_SYS_DICTIONARY>().Where(s => s.Code == tmodel.DemandTypeId).FirstOrDefault();
                        string typestring = type != null ? type.DisplayName : "";

                        var    publishstate       = dbContext.Set <T_SYS_DICTIONARY>().Where(s => s.Code == tmodel.PublishStateId).FirstOrDefault();
                        string publishstatestring = publishstate != null ? publishstate.DisplayName : "";

                        var    name       = dbContext.Set <T_USER>().Where(u => u.Id == tmodel.CreateUserId).FirstOrDefault();
                        string namestring = name != null ? name.UserName != null ? name.UserName : "" : "";

                        var  level       = dbContext.Set <T_USER_ROLE_RELATION>().Where(u => u.MemberType && u.UserID == tmodel.CreateUserId).FirstOrDefault();
                        long?levelstring = level != null ? level.Star : 0;

                        var    crops      = dbContext.Set <T_SYS_DICTIONARY>().Where(s => s.Code == tmodel.CropId).FirstOrDefault();
                        string cropstring = crops != null ? crops.DisplayName : "";

                        string replynamestring  = "";
                        string addressstring    = "";
                        string replyphonenumber = "";
                        var    replymodel       = dbContext.Set <T_USER>().Where(u => u.Id == rmodel.UserId).FirstOrDefault();
                        if (replymodel != null)
                        {
                            replynamestring  = replymodel.UserName != null ? replymodel.UserName : "";
                            addressstring    = GetAreaName(replymodel.Province) + GetAreaName(replymodel.City) + GetAreaName(replymodel.Region) + GetAreaName(replymodel.Township) + GetAreaName(replymodel.Village);
                            replyphonenumber = replymodel.PhoneNumber;
                        }
                        BusinessReplyDetailModel model = new BusinessReplyDetailModel()
                        {
                            UserName           = namestring,
                            UserLevel          = levelstring,
                            Id                 = tmodel.Id,
                            CropId             = tmodel.CropId,
                            Crop               = cropstring,
                            TypeId             = tmodel.DemandTypeId,
                            Type               = typestring,
                            AcreageId          = tmodel.AcresId,
                            Acreage            = getDisplayName(dbContext.Set <T_SYS_DICTIONARY>().Where(s => s.Code == tmodel.AcresId).FirstOrDefault()),
                            Remark             = tmodel.Brief != null ? tmodel.Brief : "",
                            Dates              = StringHelper.TransfeDate(tmodel.ExpectedDate),
                            PublishedDate      = Utility.TimeHelper.GetMilliSeconds(tmodel.CreateTime),
                            Address            = GetAreaName(tmodel.Province) + "" + GetAreaName(tmodel.City) + "" + GetAreaName(tmodel.Region) + "" + GetAreaName(tmodel.Township) + "" + GetAreaName(tmodel.Village),
                            DetailAddress      = tmodel.DetailedAddress != null ? tmodel.DetailedAddress : "",
                            PhoneNumber        = tmodel.PhoneNumber,
                            ExpectedStartPrice = Convert.ToDouble(tmodel.ExpectedStartPrice),
                            ExpectedEndPrice   = Convert.ToDouble(tmodel.ExpectedEndPrice),
                            PublishStateId     = tmodel.PublishStateId,
                            PublishState       = publishstatestring,

                            ReplyUserId          = rmodel.UserId,
                            ReplyUserName        = replynamestring,
                            ReplyPhoneNumber     = replyphonenumber,
                            ReplyDetailedAddress = addressstring,
                            ReplyTime            = Utility.TimeHelper.GetMilliSeconds(rmodel.CreateTime),
                            ReplyRemark          = "",
                            Score             = rmodel.Score,
                            UserId            = tmodel.CreateUserId,
                            PublisherRoleId   = (int)RoleType.Farmer,
                            PublisherRoleName = RoleType.Farmer.GetDescription()
                        };
                        return(model);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #9
0
        public JsonResult EtCommentRequirement(long id, string OperatorUserid, long FarmerUserId, string CommentString, int Score, int SourceType = 1)
        {
            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)
                {
                    //通过WeatherCity保存的e田农机手id,查询先锋帮农机手id
                    long operatorid = _userRepository.GetByWhere(x => x.WeatherCity.Contains(OperatorUserid)).Id;
                    T_FARMER_DEMAND_RESPONSE_RELATION responseRelation = _commonRepository.GetById <T_FARMER_DEMAND_RESPONSE_RELATION>(f => f.DemandId == id && f.UserId == operatorid);
                    //验证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 == operatorid);
                        //需求单状态判断
                        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;
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = String.Format("{0} - " + ResponeString.ParmetersInvalidMessage, OperatorUserid.ToString());
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = "接口安全验证通过,但是" + ResponeString.NoJurisdiction;
                }

                return(Json(result));
            }
        }
예제 #10
0
        /// <summary>
        /// 农机手应大农户的需求(向大农户需求响应表添加记录)
        /// </summary>
        /// <param name="id">需求id</param>
        /// <param name="userId">农机手id</param>
        /// <returns>JsonResult.</returns>
        public JsonResult ReplyRequirement(long id, long userId)
        {
            using (ResponseResult <T_FARMER_DEMAND_RESPONSE_RELATION> result = new ResponseResult <T_FARMER_DEMAND_RESPONSE_RELATION>())
            {
                T_FARMER_PUBLISHED_DEMAND firstmodel = _commonRepository.GetById <T_FARMER_PUBLISHED_DEMAND>(f => f.Id == id);
                //验证需求是否存在于大农户需求表中
                if (firstmodel != null)
                {
                    //判断用户是否在骗积分
                    if (userId == firstmodel.CreateUserId)
                    {
                        result.IsSuccess = false;
                        result.Message   = ResponeString.YourSelfRequirement;
                        return(Json(result));
                    }
                    //验证是否是发布给农机手的需求
                    if (_commonRepository.CheckTypeid <T_SYS_DICTIONARY>(s => s.Code == firstmodel.DemandTypeId && s.ParentCode == 100100))
                    {
                        //验证userid是否是农机手id
                        if (_commonRepository.CheckUserId(userId, (int)RoleType.MachineryOperator))
                        {
                            //验证需求为待响应
                            if (firstmodel.PublishStateId == 100501)
                            {
                                //验证当前用户是否接受过此订单
                                if (!_commonRepository.CheckTypeid <T_FARMER_DEMAND_RESPONSE_RELATION>(f => f.DemandId == id && f.UserId == userId))
                                {
                                    T_FARMER_DEMAND_RESPONSE_RELATION model = new T_FARMER_DEMAND_RESPONSE_RELATION()
                                    {
                                        DemandId   = id,
                                        UserId     = userId,
                                        CreateTime = Utility.TimeHelper.GetChinaLocalTime(),
                                        ReplyTime  = Utility.TimeHelper.GetChinaLocalTime(),
                                        //增加新增字段ww
                                        ReplyTimeFarmer = Utility.TimeHelper.GetChinaLocalTime()
                                    };
                                    //添加响应记录
                                    _commonRepository.Add <T_FARMER_DEMAND_RESPONSE_RELATION>(model);
                                    //响应成功后更改需求状态为待评价(100502)
                                    firstmodel.PublishStateId = 100502;
                                    _commonRepository.Modify <T_FARMER_PUBLISHED_DEMAND>(firstmodel, f => f.Id == id);
                                    result.IsSuccess = true;
                                    result.Entity    = model;

                                    //给大农户发送一个通知
                                    _notificationService.Insert(new T_NOTIFICATION
                                    {
                                        MsgContent           = "您的需求有人响应啦,快去看看吧!",
                                        IsPublic             = false,
                                        TargetUserId         = firstmodel.CreateUserId,
                                        NotificationType     = 3,
                                        NotificationSource   = "",
                                        NotificationSourceId = firstmodel.Id
                                    });
                                    #region 调用E田接口,更新订单状态
                                    //接受订单
                                    Task taskasync = new Task(() => AcceptOrder(firstmodel, model.UserId, model, 0));
                                    taskasync.Start();
                                    #endregion
                                }
                                else
                                {
                                    result.IsSuccess = false;
                                    result.Message   = ResponeString.NotRepeatApplication;
                                }
                            }
                            else
                            {
                                result.IsSuccess = false;
                                result.Message   = ResponeString.RequirementOver;
                            }
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Message   = string.Format("{0} - " + ResponeString.NoJurisdiction, userId.ToString());
                        }
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = ResponeString.NotFAccept;
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = ResponeString.NoRequirement;
                }

                return(Json(result));
            }
        }
예제 #11
0
        public JsonResult ReplyFarmerRequirement(long id, string userId, string Name, string NickName, string Address, string PhoneNum, string OtherMachinery, int Credit, int SourceType = 1)
        {
            using (ResponseResult <T_FARMER_DEMAND_RESPONSE_RELATION> result = new ResponseResult <T_FARMER_DEMAND_RESPONSE_RELATION>())
            {
                //e田农机手,在先锋帮的用户id
                long UserId = 0;
                T_FARMER_PUBLISHED_DEMAND firstmodel = _commonRepository.GetById <T_FARMER_PUBLISHED_DEMAND>(f => f.Id == id);
                //验证需求是否存在于大农户需求表中
                if (firstmodel != null)
                {
                    #region 保存农机手数据

                    List <T_USER> list = _userRepository.GetAll(c => c.WeatherCity == userId).ToList();
                    if (list.Count() > 0)
                    {
                        UserId = list[0].Id;
                    }
                    else
                    {
                        var user = new T_USER
                        {
                            PhoneNumber       = PhoneNum,
                            Password          = Encrypt.MD5Encrypt("111"),
                            CreateTime        = DateTime.Now,
                            IsDeleted         = false,
                            LoginUserName     = PhoneNum,
                            LastLoginTime     = DateTime.Now,
                            LastUpdatePwdTime = DateTime.Now,
                            SourceType        = SourceType,
                            WeatherCity       = userId//因为e田的农机手不登录,所以用本字段
                        };
                        int rows = _userRepository.Insert(user);
                        //构建农机手角色申请信息实体
                        var entity = new T_MACHINERY_OPERATOR_VERIFICATION_INFO()
                        {
                            UserId     = user.Id,
                            CreateTime = DateTime.Now,
                            AuditState = 0,
                            Machinery  = "[]",//必须有内容,否则后台getUpddata方法会报错
                            OtherMachineDescription = OtherMachinery,
                            RealName    = Name,
                            PhoneNumber = PhoneNum
                        };
                        _operatorRepository.Insert(entity);

                        var userRoleDemandTypeLevelMapping = new Dictionary <int, int> {
                            { 1, 1 }
                        };

                        var verificationSuccess = this._roleVerificationRepository.ApproveOperatorVerification(entity.Id, user.Id, userRoleDemandTypeLevelMapping);
                        UserId = user.Id;//农机手id
                    }


                    #endregion
                    //验证是否是发布给农机手的需求
                    if (_commonRepository.CheckTypeid <T_SYS_DICTIONARY>(s => s.Code == firstmodel.DemandTypeId && s.ParentCode == 100100))
                    {
                        //验证userid是否是农机手id
                        if (_commonRepository.CheckUserId(UserId, (int)RoleType.MachineryOperator))
                        {
                            //验证需求为待响应
                            if (firstmodel.PublishStateId == 100501)
                            {
                                //验证当前用户是否接受过此订单
                                if (!_commonRepository.CheckTypeid <T_FARMER_DEMAND_RESPONSE_RELATION>(f => f.DemandId == id && f.UserId == UserId))
                                {
                                    T_FARMER_DEMAND_RESPONSE_RELATION model = new T_FARMER_DEMAND_RESPONSE_RELATION()
                                    {
                                        DemandId   = id,
                                        UserId     = UserId,
                                        CreateTime = Utility.TimeHelper.GetChinaLocalTime(),
                                        ReplyTime  = Utility.TimeHelper.GetChinaLocalTime(),
                                        //增加新增字段ww
                                        ReplyTimeFarmer = Utility.TimeHelper.GetChinaLocalTime(),
                                        //1 E田的农机手
                                        SourceType = 1
                                    };
                                    //添加响应记录
                                    _commonRepository.Add <T_FARMER_DEMAND_RESPONSE_RELATION>(model);
                                    //响应成功后更改需求状态为待评价(100502)
                                    firstmodel.PublishStateId = 100502;
                                    _commonRepository.Modify <T_FARMER_PUBLISHED_DEMAND>(firstmodel, f => f.Id == id);
                                    result.IsSuccess = true;
                                    result.Entity    = model;

                                    //给大农户发送一个通知
                                    _notificationService.Insert(new T_NOTIFICATION
                                    {
                                        MsgContent           = "您的需求有人响应啦,快去看看吧!",
                                        IsPublic             = false,
                                        TargetUserId         = firstmodel.CreateUserId,
                                        NotificationType     = 3,
                                        NotificationSource   = "",
                                        NotificationSourceId = firstmodel.Id
                                    });
                                }
                                else
                                {
                                    result.IsSuccess = false;
                                    result.Message   = ResponeString.NotRepeatApplication;
                                }
                            }
                            else
                            {
                                result.IsSuccess = false;
                                result.Message   = ResponeString.RequirementOver;
                            }
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Message   = string.Format("{0} - " + ResponeString.NoJurisdiction, userId.ToString());
                        }
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = ResponeString.NotFAccept;
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = ResponeString.NoRequirement;
                }

                return(Json(result));
            }
        }
예제 #12
0
        /// <summary>
        /// 重新整理订单数据
        /// </summary>
        /// <param name="model">需求表</param>
        /// <param name="UserId">农机手id</param>
        /// <param name="t_FARMER_DEMAND_RESPONSE_RELATION">应答表</param>
        /// <param name="type">0:接单,1:评价订单</param>
        /// <author>ww</author>
        /// <returns></returns>
        public JsonResult AcceptOrder(T_FARMER_PUBLISHED_DEMAND model, long UserId, T_FARMER_DEMAND_RESPONSE_RELATION t_FARMER_DEMAND_RESPONSE_RELATION, int type)
        {
            using (ResponseResult <object> result = new ResponseResult <object>())
            {
                DtoUpdateFarmerDemandModel updatemodel = new DtoUpdateFarmerDemandModel();
                try
                {
                    updatemodel.FarmerName = model.CreateUserId.ToString();
                    //查询用户名称
                    T_USER umodel = new DuPont.Repository.UserRepository().GetByWhere(x => x.Id == UserId);
                    if (umodel != null)
                    {
                        updatemodel.OperatoName = umodel.UserName;
                    }
                    if (type == 0)//接单
                    {
                        updatemodel.Id         = model.Id;
                        updatemodel.OrderState = 100502;
                    }
                    else if (type == 1)//评价需求
                    {
                        updatemodel.Id            = t_FARMER_DEMAND_RESPONSE_RELATION.DemandId;
                        updatemodel.OrderState    = 100508;
                        updatemodel.CommentString = t_FARMER_DEMAND_RESPONSE_RELATION.CommentsFarmer;
                        updatemodel.Score         = t_FARMER_DEMAND_RESPONSE_RELATION.ScoreFarmer;
                    }
                    #region 调用E田接口
                    var etcontent = new Dictionary <string, string>();
                    etcontent = ModelHelper.GetPropertyDictionary <DtoUpdateFarmerDemandModel>(updatemodel);
                    //加密要传递的参数
                    Dictionary <string, string> rurlcontent = EncryptDictionary(etcontent);
                    //e田接口地址
                    string Apiurl = ConfigHelper.GetAppSetting("EtApiUrl");
                    string Eturl  = Apiurl + "/wei/work/dupont/order_status.jsp";
                    //证书的路径
                    var etcertification = GetCertificationFilePath();
                    //证书的密码
                    var etcertificationPwd = GetCertificationPwd();
                    var etresult           = HttpAsynchronousTool.CustomHttpWebRequestPost(Eturl, rurlcontent, etcertification, etcertificationPwd);
                    var resultModel        = JsonHelper.FromJsonTo <ETResponseResult <object> >(etresult);
                    if (resultModel.IsSuccess == true)
                    {
                        //写文件确认我方调用e田接口完成
                        string logErrstring = DateTime.Now.ToString("\r\n---------MM/dd/yyyy HH:mm:ss,fff---------\r\n") + "先锋帮的农机手接受或评价订单";
                        string parmeters    = null;
                        foreach (var item in rurlcontent)
                        {
                            parmeters += item.Key + ":" + item.Value + "\r\n";
                        }
                        IOHelper.WriteLogToFile("Operator/AcceptOrder" + logErrstring + parmeters, RelativePath() + @"\DuPontRequestEtLog");
                    }

                    #endregion
                    result.IsSuccess = true;
                    result.Entity    = updatemodel;
                }
                catch
                {
                    result.IsSuccess = false;
                }
                return(Json(result));
            }
        }
예제 #13
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));
            }
        }