Example #1
0
        /// <summary>
        /// 报价 图片上传
        /// </summary>
        /// <returns></returns>
        public Task <ApiReturnModel> QuotationProductImgUpload()
        {
            // 检查是否是 multipart/form-data
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            //文件保存目录路径
            string SaveTempPath = ConfigHelp.GetValueByNameInAppSettings("QuotationProductImg");

            SaveTempPath += DateTime.Now.ToString("yyyy") + '/';
            SaveTempPath += DateTime.Now.ToString("MM") + '/';
            String dirTempPath = HttpContext.Current.Server.MapPath(SaveTempPath);

            if (!System.IO.Directory.Exists(dirTempPath))
            {
                System.IO.Directory.CreateDirectory(dirTempPath);
            }

            // 设置上传目录
            var provider = new MultipartFormDataStreamProvider(dirTempPath);
            //var queryp = Request.GetQueryNameValuePairs();//获得查询字符串的键值集合
            var task = Request.Content.ReadAsMultipartAsync(provider).
                       ContinueWith <ApiReturnModel>(o =>
            {
                var file          = provider.FileData[0];//provider.FormData
                string orfilename = file.Headers.ContentDisposition.FileName.TrimStart('"').TrimEnd('"');
                FileInfo fileinfo = new FileInfo(file.LocalFileName);
                //最大文件大小
                int maxSize = 10000000;
                if (fileinfo.Length <= 0)
                {
                    return(ApiReturnModel.ReturnError("请上传文件"));
                }
                else if (fileinfo.Length > maxSize)
                {
                    return(ApiReturnModel.ReturnError("文件大小超过限制"));
                }
                else
                {
                    string fileExt = orfilename.Substring(orfilename.LastIndexOf('.'));
                    //定义允许上传的文件扩展名
                    String fileTypes = "gif,jpg,jpeg,png,bmp";
                    if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
                    {
                        return(ApiReturnModel.ReturnError("只能上传 图片"));
                    }
                    else
                    {
                        String ymd         = DateTime.Now.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                        String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                        fileinfo.CopyTo(Path.Combine(dirTempPath, newFileName + fileExt), true);
                        fileinfo.Delete();
                        return(ApiReturnModel.ReturnOk("上传 成功", SaveTempPath + newFileName + fileExt));
                    }
                }
            });

            return(task);
        }
        /// <summary>
        /// 用户提交意见
        /// </summary>
        /// <param name="apiSuggestionModel"></param>
        /// <returns></returns>
        public object AddSuggestion([FromBody] ApiSuggestionModel apiSuggestionModel)
        {
            var            userInfo       = GetCurrentUserInfo();
            UserSuggestion userSuggestion = new UserSuggestion()
            {
                Id         = Guid.NewGuid(),
                Msg        = apiSuggestionModel.Msg,
                UserId     = userInfo.Id,
                CreateTime = DateTime.Now
            };

            try
            {
                SuggestionBusiness.AddItem(userSuggestion);

                return(ApiReturnModel.ReturnOk("提交成功"));
            }

            catch (Exception e)
            {
                //记录日志
                LogHelp.WriteLog(e.Message, ApiFileDirectoryPara.ApiErrorDir);

                return(ApiReturnModel.ReturnError("提交错误"));
            }
        }
Example #3
0
        public object UserRegister(ApiUserRegisterModel register)
        {
            if (register.Type == ApiRegisterFlag.ByPwd) //通过密码
            {
                var isHave = UserBusiness.GetItemByUserAccount(register.UserAccount);
                if (isHave != null)
                {
                    return(ApiReturnModel.ReturnError("当前账号已经注册"));
                }
                var userInfo = ApiToDalModelMapping.UserRegisterModelToUserInfo(register, (int)UserLvModel.User);

                userInfo = UserBusiness.AddItem(userInfo);

                #region 开始写入缓存

                var token = Guid.NewGuid();
                CacheHelper.TryAddCache($"{token}-{AuthenticationPara.UserAuthentication}", userInfo, DateTime.Now.AddDays(30)); //缓存

                ApiUserInfoModel apiUserInfo = new ApiUserInfoModel()
                {
                    Token       = token.ToString(),
                    UserAccount = userInfo.UserAccount,
                    UserLv      = userInfo.UserLv.ToString()
                };

                #endregion

                ApiReturnModel.ReturnOk("注册成功", apiUserInfo);
            }
            else if (register.Type == ApiRegisterFlag.ByValidate) //通过验证码注册
            {
            }

            return(ApiReturnModel.ReturnOk());
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="actionContext"></param>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            if (actionContext.Request.Headers.Authorization == null)
            {
                string returnJson = JsonConvert.SerializeObject(ApiReturnModel.ReturnError("请提交身份凭证 token 存放在请求头中的Authorization里"));

                actionContext.Response         = new System.Net.Http.HttpResponseMessage();
                actionContext.Response.Content = new StringContent(returnJson);

                return;
            }

            #region 测试阶段凭证
            if (actionContext.Request.Headers.Authorization.Parameter == "123")
            {
                HttpContext.Current.Items[ApiCachePara.CacheUserKey] = new UserInfo()
                {
                    Id          = new Guid("55c6fc68-e47a-41f9-a290-506e72018bc6"),
                    UserName    = "******",
                    UserAccount = "wuji业务",
                    UserLv      = 2,
                    CreateTime  = DateTime.Now
                };
                return;
            }
            #endregion

            var scheme = actionContext.Request.Headers.Authorization.Scheme;

            if (scheme == AuthenticationPara.CountermanAuthentication)
            {
                var token = actionContext.Request.Headers.Authorization.Parameter;
                if (CacheHelper.GetCache($"{token}-{scheme}") == null) //没有对应的 缓存数据
                {
                    string returnJson = JsonConvert.SerializeObject(ApiReturnModel.ReturnIdentityInvalid("token失效 请重新登陆"));

                    actionContext.Response         = new System.Net.Http.HttpResponseMessage();
                    actionContext.Response.Content = new StringContent(returnJson);

                    return;
                }
                else
                {
                    var userInfo = CacheHelper.GetCache($"{token}-{scheme}") as UserInfo;
                    HttpContext.Current.Items[ApiCachePara.CacheUserKey] = userInfo;

                    return;
                }
            }

            else
            {
                string returnJson = JsonConvert.SerializeObject(ApiReturnModel.ReturnError("Scheme 错误"));

                actionContext.Response         = new System.Net.Http.HttpResponseMessage();
                actionContext.Response.Content = new StringContent(returnJson);
                return;
            }
        }
 public object DeleteCounterman([FromBody] ApiCountermanManagerModel apiCountermanManagerModel)
 {
     if (userBusiness.UpdateUserStateByIdAndLv(apiCountermanManagerModel.Id, (int)UserLvModel.Counterman, (int)UserFlag.Delete))
     {
         return(ApiReturnModel.ReturnOk());
     }
     return(ApiReturnModel.ReturnError());
 }
 public object UpdateCounterman([FromBody] ApiCountermanManagerModel apiCountermanManagerModel)
 {
     if (userBusiness.UpdateUserByIdAndLv(apiCountermanManagerModel.Id, apiCountermanManagerModel.UserPassWord, apiCountermanManagerModel.UserAccount, (int)UserLvModel.Counterman))
     {
         return(ApiReturnModel.ReturnOk());
     }
     return(ApiReturnModel.ReturnError());
 }
        /// <summary>
        /// 修改 某个物流信息
        /// </summary>
        /// <param name="apiCountermanLogisticsModel"></param>
        /// <returns></returns>
        public ApiReturnModel UpdateLogisticsItem([FromBody] ApiCountermanLogisticsModel apiCountermanLogisticsModel)
        {
            var userInfo = GetCurrentUserInfo();

            if (userLogisticsBusiness.UpdateLogisticsById(apiCountermanLogisticsModel.Id, userInfo.Id, apiCountermanLogisticsModel.DetailedInformation, apiCountermanLogisticsModel.LogisticsTime))
            {
                return(ApiReturnModel.ReturnOk());
            }
            return(ApiReturnModel.ReturnError());
        }
        public ApiReturnModel UploadInquiryOrder([FromBody] ApiUserProductModel apiUserProductModel)
        {
            var userInfo = GetCurrentUserInfo();

            if (inquiryOrderBusiness.AddUserInquiryOrder(userInfo.Id, apiUserProductModel.Remarks, apiUserProductModel.Price, apiUserProductModel.ImgUrl))
            {
                return(ApiReturnModel.ReturnOk());
            }
            return(ApiReturnModel.ReturnError());
        }
        /// <summary>
        /// 业务员 取消询价单
        /// </summary>
        /// <param name="apiIntentionOrderModel"></param>
        /// <returns></returns>
        public ApiReturnModel CancelIntentionOrder([FromBody] ApiInquiryOrderModel apiIntentionOrderModel)
        {
            var userInfo = GetCurrentUserInfo();
            var msg      = inquiryOrderBusiness.UpdateInquiryOrderFlag(apiIntentionOrderModel.Id, userInfo.Id, apiIntentionOrderModel.Remarks, BusinessOrderFlag.Invalid);

            if (msg == BReturnModel.IsOk)
            {
                return(ApiReturnModel.ReturnOk());
            }
            return(ApiReturnModel.ReturnError(msg));
        }
        /// <summary>
        /// 业务员 确认询价订单
        /// </summary>
        /// <param name="apiInquiryOrderModel"></param>
        /// <returns></returns>
        public ApiReturnModel ConfirmInquiryOrder([FromBody] ApiInquiryOrderModel apiInquiryOrderModel)
        {
            var userInfo = GetCurrentUserInfo();
            var msg      = inquiryOrderBusiness.UpdateInquiryOrderFlag(apiInquiryOrderModel.Id, userInfo.Id, apiInquiryOrderModel.Remarks, BusinessOrderFlag.Effective, DateTime.Now);

            if (msg == BReturnModel.IsOk)
            {
                return(ApiReturnModel.ReturnOk());
            }
            return(ApiReturnModel.ReturnError(msg));
        }
Example #11
0
        public ApiReturnModel DeleteUserAddress([FromBody] ApiUserAddressModel apiUserAddressModel)
        {
            var userInfo = GetCurrentUserInfo();


            if (UserAddressBusiness.DeleteUserAddress(apiUserAddressModel.Id, userInfo.Id))
            {
                return(ApiReturnModel.ReturnOk());
            }
            return(ApiReturnModel.ReturnError());
        }
        /// <summary>
        /// 业务员 取消合同单
        /// </summary>
        /// <param name="apiContractOrderModel"></param>
        /// <returns></returns>
        public ApiReturnModel CancelContractOrder([FromBody] ApiContractOrderModel apiContractOrderModel)
        {
            var userInfo = GetCurrentUserInfo();

            var BReturnModel = contractOrderBusiness.UpdateContractOrderFlag(apiContractOrderModel.Id, userInfo.Id, apiContractOrderModel.Remarks, BusinessOrderFlag.Invalid);

            if (BReturnModel.IsOk == BReturnModel.Code)
            {
                return(ApiReturnModel.ReturnOk());
            }
            return(ApiReturnModel.ReturnError(BReturnModel.Msg));
        }
        /// <summary>
        /// 业务员 确认意向订单
        /// </summary>
        /// <param name="apiIntentionOrderModel"></param>
        /// <returns></returns>
        public ApiReturnModel ConfirmIntentionOrder([FromBody] ApiIntentionOrderModel apiIntentionOrderModel)
        {
            var userInfo = GetCurrentUserInfo();

            var msg = intentionOrderBusiness.UpdateIntentionOrderFlag(apiIntentionOrderModel.Id, userInfo.Id, apiIntentionOrderModel.ReceiveRemarks, BusinessOrderFlag.Effective);

            if (msg == BReturnModel.IsOk)
            {
                return(ApiReturnModel.ReturnOk());
            }
            else
            {
                return(ApiReturnModel.ReturnError(msg));
            }
        }
        /// <summary>
        /// 发生错误 处理方式
        /// </summary>
        /// <param name="actionExecutedContext"></param>
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            LogQueueModel logQueueModel = new LogQueueModel()
            {
                FileName = ApiFileDirectoryPara.ApiErrorDir,
                Msg      = actionExecutedContext.Exception.Message
            };

            LogHelp.AddLogQueue(logQueueModel);

            var returnModel = ApiReturnModel.ReturnError(actionExecutedContext.Exception.Message);

            actionExecutedContext.Response         = new HttpResponseMessage();
            actionExecutedContext.Response.Content = new StringContent(JsonConvert.SerializeObject(returnModel));

            return;
        }
Example #15
0
        /// <summary>
        /// 业务员登陆
        /// </summary>
        /// <param name="apiLoginUserModel"></param>
        /// <returns></returns>
        public object CountermanLogin([FromBody] ApiLoginUserModel apiLoginUserModel)
        {
            var userInfo = employeeBusiness.GetItemByEmployeePwd(apiLoginUserModel.UserId, apiLoginUserModel.Pwd, (int)UserLvModel.Counterman);

            if (userInfo != null) //密码登陆成功
            {
                var token = Guid.NewGuid();
                CacheHelper.TryAddCache($"{token}-{AuthenticationPara.CountermanAuthentication}", userInfo, DateTime.Now.AddDays(30)); //缓存
                ApiUserInfoModel apiUserInfo = new ApiUserInfoModel()
                {
                    Token    = token.ToString(),
                    UserName = userInfo.EmployeeName,
                    UserLv   = EnumHelper.GetDescriptionByValue <UserLvModel>(userInfo.RoleLv)
                };
                return(ApiReturnModel.ReturnOk("登陆成功", apiUserInfo));
            }

            return(ApiReturnModel.ReturnError("用户名或者密码错误"));
        }
Example #16
0
        public ApiReturnModel UploadIntentionOrder([FromBody] ApiIntentionOrderModel apiIntentionOrderModel)
        {
            var userInfo = GetCurrentUserInfo();
            IList <BProductDetailModel> bProductDetailModelList = new List <BProductDetailModel>();

            foreach (var item in apiIntentionOrderModel.apiOrderProductModel)
            {
                var productModel = ApiToBusinessModelMapping.GetBProductDetailModelByApiUserProductModel(item);
                bProductDetailModelList.Add(productModel);
            }
            var msg = intentionOrderBusiness.AddIntentionOrder(apiIntentionOrderModel.OrderId, userInfo.Id, apiIntentionOrderModel.Remarks, bProductDetailModelList);

            if (msg == BReturnModel.IsOk)
            {
                return(ApiReturnModel.ReturnOk());
            }
            else
            {
                return(ApiReturnModel.ReturnError(msg));
            }
        }
Example #17
0
        public ApiReturnModel UpdateUserAddress([FromBody] ApiUserAddressModel apiUserAddressModel)
        {
            var         userInfo    = GetCurrentUserInfo();
            UserAddress userAddress = new UserAddress()
            {
                Id              = apiUserAddressModel.Id,
                UserId          = userInfo.Id,
                City            = apiUserAddressModel.City,
                Province        = apiUserAddressModel.Province,
                DetailedAddress = apiUserAddressModel.DetailedAddress,
                ConsigneeName   = apiUserAddressModel.ConsigneeName,
                Flag            = 0,
                Phone           = apiUserAddressModel.Phone
            };

            if (UserAddressBusiness.UpdateUserAddress(userAddress))
            {
                return(ApiReturnModel.ReturnOk());
            }
            return(ApiReturnModel.ReturnError());
        }
Example #18
0
        public ApiReturnModel GetUserAddressList(int pageIndex, int pageSize = 5)
        {
            var userInfo = GetCurrentUserInfo();

            if (pageIndex < 0 || pageSize < 0)
            {
                return(ApiReturnModel.ReturnError("参数值不能小于0"));
            }

            if (pageSize == 0)
            {
                var allAddress = UserAddressBusiness.GetAllUserAddress(userInfo.Id);

                return(ApiReturnModel.ReturnOk("获取成功", allAddress));
            }
            else
            {
                var allAddress = UserAddressBusiness.GetUserAddressPaging(pageIndex, pageSize, userInfo.Id);
                return(ApiReturnModel.ReturnOk("分页获取成功", allAddress));
            }
        }
        /// <summary>
        /// 业务员 提交合同订单
        /// </summary>
        /// <param name="apiContractOrderModel"></param>
        /// <returns></returns>
        public ApiReturnModel UploadContractOrder([FromBody] ApiContractOrderModel apiContractOrderModel)
        {
            var userInfo = GetCurrentUserInfo();

            IList <BProductDetailModel> bProductDetailModelList = new List <BProductDetailModel>();

            foreach (var item in apiContractOrderModel.apiOrderProductModel)
            {
                var productModel = ApiToBusinessModelMapping.GetBProductDetailModelByApiUserProductModel(item);
                bProductDetailModelList.Add(productModel);
            }

            var BReturnModel = contractOrderBusiness.AddContractOrder(apiContractOrderModel.OrderId, userInfo.Id, apiContractOrderModel.ExpireTime, bProductDetailModelList);

            if (BReturnModel.Code == BReturnModel.IsOk)
            {
                return(ApiReturnModel.ReturnOk());
            }

            else
            {
                return(ApiReturnModel.ReturnError(BReturnModel.Msg));
            }
        }