コード例 #1
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));
            }
        }
コード例 #2
0
        /// <summary>
        /// 产业商发布需求
        /// </summary>
        /// <param name="id">0表示执行添加操作</param>
        /// <param name="userid">产业商id</param>
        /// <param name="Type">需求类型编号</param>
        /// <param name="Dates">预期时间</param>
        /// <param name="Address">地址</param>
        /// <param name="DetailAddress">详细地址</param>
        /// <param name="PurchaseWeight">收购区间类型编号</param>
        /// <param name="CommenceWeight">起购重量</param>
        /// <param name="PhoneNumber">手机号</param>
        /// <param name="Remark">摘要</param>
        /// <param name="cropId">农作物Id</param>
        /// <param name="PurchaseStartPrice">预期最低价格</param>
        /// <param name="PurchaseEndPrice">预期最高价格</param>
        /// <param name="?">The ?.</param>
        /// <returns>JsonResult.</returns>
        public JsonResult SaveRequirement(long id, long userid, int Type, string Dates, string Address, string DetailAddress,
                                          int PurchaseWeight, int CommenceWeight, string PhoneNumber, string Remark, int cropId, double PurchaseStartPrice = 0, double PurchaseEndPrice = 0)
        {
            using (ResponseResult <T_BUSINESS_PUBLISHED_DEMAND> result = new ResponseResult <T_BUSINESS_PUBLISHED_DEMAND>())
            {
                int pwnumber = 0;
                int conumber = 0;
                //收粮:100201
                //产业商收购粮食重量区间:100400
                //产业商收购粮食起购重量:100600
                //收青贮:100202
                //产业商收购青贮重量区间:101100
                //产业商收购青贮起购亩数:101200
                if (string.IsNullOrEmpty(Dates))
                {
                    result.IsSuccess = false;
                    result.Message   = ResponeString.DateNotNull;
                    return(Json(result));
                }
                if (!Utility.RegexHelper.IsMatch(Address, @"^\d*\|\d*\|\d*\|\d*\|\d*$"))
                {
                    result.IsSuccess = false;
                    result.Message   = ResponeString.AddressError;
                    return(Json(result));
                }
                if (string.IsNullOrEmpty(PhoneNumber))
                {
                    result.IsSuccess = false;
                    result.Message   = ResponeString.PhonenumberNotNull;
                    return(Json(result));
                }
                if (cropId < 0)
                {
                    cropId = 0;
                }
                switch (Type)
                {
                case 100201:
                    if (!_commonRepository.CheckTypeid <T_SYS_DICTIONARY>(s => (s.Code == PurchaseWeight && s.ParentCode == 100400)))
                    {
                        result.IsSuccess = false;
                        result.Message   = String.Format("{0} -" + ResponeString.ParmetersInvalidMessage, PurchaseWeight.ToString());
                        return(Json(result));
                    }
                    if (!_commonRepository.CheckTypeid <T_SYS_DICTIONARY>(s => (s.Code == CommenceWeight && s.ParentCode == 100600)))
                    {
                        result.IsSuccess = false;
                        result.Message   = String.Format("{0} -" + ResponeString.ParmetersInvalidMessage, CommenceWeight.ToString());
                        return(Json(result));
                    }
                    var pwmodel = _commonRepository.GetById <T_SYS_DICTIONARY>(s => s.Code == PurchaseWeight);
                    var comodel = _commonRepository.GetById <T_SYS_DICTIONARY>(s => s.Code == CommenceWeight);
                    pwnumber = pwmodel.DisplayName.Contains("以上") == true?Convert.ToInt32(pwmodel.DisplayName.Replace("吨以上", "")) + 1 : Convert.ToInt32(pwmodel.DisplayName.Replace("吨", "").Split('-')[1]);

                    conumber = comodel.DisplayName.Contains("以上") == true?Convert.ToInt32(comodel.DisplayName.Replace("吨以上", "")) + 1 : Convert.ToInt32(comodel.DisplayName.Replace("吨", ""));

                    if (conumber > pwnumber)
                    {
                        result.IsSuccess = false;
                        result.Message   = ResponeString.WeightIsError;
                        return(Json(result));
                    }
                    break;

                case 100202:
                    if (!_commonRepository.CheckTypeid <T_SYS_DICTIONARY>(s => (s.Code == PurchaseWeight && s.ParentCode == 101100)))
                    {
                        result.IsSuccess = false;
                        result.Message   = String.Format("{0} -" + ResponeString.ParmetersInvalidMessage, PurchaseWeight.ToString());
                        return(Json(result));
                    }
                    if (!_commonRepository.CheckTypeid <T_SYS_DICTIONARY>(s => (s.Code == CommenceWeight && s.ParentCode == 101200)))
                    {
                        result.IsSuccess = false;
                        result.Message   = String.Format("{0} -" + ResponeString.ParmetersInvalidMessage, CommenceWeight.ToString());
                        return(Json(result));
                    }
                    pwmodel  = _commonRepository.GetById <T_SYS_DICTIONARY>(s => s.Code == PurchaseWeight);
                    comodel  = _commonRepository.GetById <T_SYS_DICTIONARY>(s => s.Code == CommenceWeight);
                    pwnumber = pwmodel.DisplayName.Contains("以上") == true?Convert.ToInt32(pwmodel.DisplayName.Replace("亩以上", "")) + 1 : Convert.ToInt32(pwmodel.DisplayName.Replace("亩", "").Split('-')[1]);

                    conumber = comodel.DisplayName.Contains("以上") == true?Convert.ToInt32(comodel.DisplayName.Replace("亩以上", "")) + 1 : Convert.ToInt32(comodel.DisplayName.Replace("亩", ""));

                    if (conumber > pwnumber)
                    {
                        result.IsSuccess = false;
                        result.Message   = ResponeString.WeightIsError;
                        return(Json(result));
                    }
                    break;

                default:
                    result.IsSuccess = false;
                    result.Message   = String.Format("{0} -" + ResponeString.ParmetersInvalidMessage, Type.ToString());
                    return(Json(result));
                }
                //验证userid是否有操作权限
                if (_commonRepository.CheckUserId(userid, (int)RoleType.Business))
                {
                    //执行添加操作
                    if (id == 0)
                    {
                        T_BUSINESS_PUBLISHED_DEMAND newRequirement = new T_BUSINESS_PUBLISHED_DEMAND();
                        newRequirement.CreateUserId   = userid;
                        newRequirement.DemandTypeId   = Type;
                        newRequirement.ExpectedDate   = Dates;
                        newRequirement.PublishStateId = 100501;
                        Dictionary <string, string> adc = StringHelper.GetAddress(Address);

                        newRequirement.Province = adc["Province"];
                        newRequirement.City     = adc["City"];
                        newRequirement.Region   = adc["Region"];
                        newRequirement.Township = adc["Township"];
                        newRequirement.Village  = adc["Village"];

                        newRequirement.DetailedAddress              = DetailAddress != null ? DetailAddress : "";
                        newRequirement.ExpectedStartPrice           = Convert.ToDecimal(PurchaseStartPrice);
                        newRequirement.ExpectedEndPrice             = Convert.ToDecimal(PurchaseEndPrice);
                        newRequirement.AcquisitionWeightRangeTypeId = PurchaseWeight;
                        newRequirement.FirstWeight = CommenceWeight;
                        newRequirement.PhoneNumber = PhoneNumber;
                        newRequirement.Brief       = Remark != null ? Remark : "";
                        newRequirement.CreateTime  = Utility.TimeHelper.GetChinaLocalTime();
                        newRequirement.CropId      = cropId;
                        repository.Insert(newRequirement);

                        result.Entity    = newRequirement;
                        result.IsSuccess = true;
                        result.Message   = ResponeString.SaveSuccessfullyMessage;

                        return(Json(result));
                    }
                    //执行修改操作
                    T_BUSINESS_PUBLISHED_DEMAND updateRequirement = repository.GetByKey(id);
                    if (!updateRequirement.Equals(null))
                    {
                        //当前需求已被响应不能在修改
                        if (updateRequirement.PublishStateId == 100501)
                        {
                            updateRequirement.ModifiedUserId = userid;
                            updateRequirement.ModifiedTime   = Utility.TimeHelper.GetChinaLocalTime();
                            updateRequirement.DemandTypeId   = Type;
                            updateRequirement.ExpectedDate   = Dates;
                            updateRequirement.PublishStateId = 100501;
                            Dictionary <string, string> adc = StringHelper.GetAddress(Address);

                            updateRequirement.Province = adc["Province"];
                            updateRequirement.City     = adc["City"];
                            updateRequirement.Region   = adc["Region"];
                            updateRequirement.Township = adc["Township"];
                            updateRequirement.Village  = adc["Village"];

                            updateRequirement.DetailedAddress              = DetailAddress;
                            updateRequirement.ExpectedStartPrice           = Convert.ToDecimal(PurchaseStartPrice);
                            updateRequirement.ExpectedEndPrice             = Convert.ToDecimal(PurchaseEndPrice);
                            updateRequirement.AcquisitionWeightRangeTypeId = PurchaseWeight;
                            updateRequirement.FirstWeight = CommenceWeight;
                            updateRequirement.PhoneNumber = PhoneNumber;
                            updateRequirement.Brief       = Remark;
                            updateRequirement.CropId      = cropId;
                            _commonRepository.Modify <T_BUSINESS_PUBLISHED_DEMAND>(updateRequirement, b => b.Id == id);
                            result.Entity    = updateRequirement;
                            result.IsSuccess = true;
                            result.Message   = ResponeString.SaveSuccessfullyMessage;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Message   = ResponeString.NotUpdate;
                        }
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = String.Format("{0} -" + ResponeString.ParmetersInvalidMessage, id.ToString());
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = String.Format("{0} -" + ResponeString.NoJurisdiction, userid.ToString());
                }
                return(Json(result));
            }
        }