public async Task <ApiResult <GetForShopUserOutput> > GetForShopUser([FromUri] GetForShopUserInput input, CancellationToken cancelToken) { if (Authorization == null) { return(new ApiResult <GetForShopUserOutput>(APIResultCode.Unknown, new GetForShopUserOutput { }, APIResultMessage.TokenNull)); } var user = _tokenRepository.GetUser(Authorization); if (user == null) { return(new ApiResult <GetForShopUserOutput>(APIResultCode.Unknown, new GetForShopUserOutput { }, APIResultMessage.TokenError)); } if (string.IsNullOrWhiteSpace(input.ShopId)) { throw new NotImplementedException("商户Id信息为空!"); } var data = await _smallDistrictShopRepository.GetIncludeAsync(input.ShopId, cancelToken); var shoppingTrolleyList = await _shoppingTrolleyRepository.GetAllIncludeAsync(new ShoppingTrolleyDto { //OwnerCertificationRecordId = input.ApplicationRecordId, OperationUserId = user.Id.ToString(), ShopId = input.ShopId }, cancelToken); List <Activity> alist = new List <Activity>(); int activitySource = 1; if (data.Shop.ActivitySign == "0" || string.IsNullOrEmpty(data.Shop.ActivitySign)) { alist = (await _activityRepository.GetAllAsync(new Domain.Dto.Store.ActivityDto { IsSelectByTime = true, ActivitySource = 2 }, cancelToken)).Select(x => new Activity { ActivitySource = x.ActivitySource, ActivityType = x.ActivityType, ID = x.ID.ToString(), Money = x.Money, Off = x.Off, ActivityBeginTime = x.ActivityBeginTime, ActivityEndTime = x.ActivityEndTime, ShopId = x.ShopId.ToString() }).OrderBy(b => b.Money).ToList(); activitySource = 2; } else { alist = (await _activityRepository.GetAllAsync(new Domain.Dto.Store.ActivityDto { ShopId = data.ShopId.ToString(), IsSelectByTime = true, ActivitySource = 1 }, cancelToken)).Select(x => new Activity { ActivitySource = x.ActivitySource, ActivityType = x.ActivityType, ID = x.ID.ToString(), Money = x.Money, Off = x.Off, ActivityBeginTime = x.ActivityBeginTime, ActivityEndTime = x.ActivityEndTime, ShopId = x.ShopId.ToString() }).OrderBy(b => b.Money).ToList(); //判断如果没有店铺活动则查询平台活动 if (alist == null || alist.Count == 0) { alist = (await _activityRepository.GetAllAsync(new Domain.Dto.Store.ActivityDto { IsSelectByTime = true, ActivitySource = 2 }, cancelToken)).Select(x => new Activity { ActivitySource = x.ActivitySource, ActivityType = x.ActivityType, ID = x.ID.ToString(), Money = x.Money, Off = x.Off, ActivityBeginTime = x.ActivityBeginTime, ActivityEndTime = x.ActivityEndTime, ShopId = x.ShopId.ToString() }).OrderBy(b => b.Money).ToList(); activitySource = 2; } } return(new ApiResult <GetForShopUserOutput>(APIResultCode.Success, new GetForShopUserOutput { Id = data.Id.ToString(), Name = data.Shop.Name, Address = data.Shop.Address, LogoImageUrl = data.Shop.LogoImageUrl, PhoneNumber = data.Shop.PhoneNumber, IsPresence = shoppingTrolleyList.Any(), Postage = data.Postage, ShopActivityList = alist, ActivitySource = activitySource })); }
public async Task <ApiResult <GetShoppingTrollerOutput> > Add([FromBody] AddShoppingTrollerInput input, CancellationToken cancelToken) { if (Authorization == null) { return(new ApiResult <GetShoppingTrollerOutput>(APIResultCode.Unknown, new GetShoppingTrollerOutput { }, APIResultMessage.TokenNull)); } //if (string.IsNullOrWhiteSpace(input.OwnerCertificationRecordId)) //{ // throw new NotImplementedException("业主ID参数无效!"); //} if (string.IsNullOrWhiteSpace(input.ShopCommodityId)) { throw new NotImplementedException("商品ID参数无效!"); } if (input.CommodityCount <= 0) { throw new NotImplementedException("商品数量参数无效!"); } var user = _tokenRepository.GetUser(Authorization); if (user == null) { return(new ApiResult <GetShoppingTrollerOutput>(APIResultCode.Success_NoB, new GetShoppingTrollerOutput { }, "创建人信息不正确")); } var result = await _shoppingTrolleyRepository.AddAsync(new ShoppingTrolleyDto { CommodityCount = input.CommodityCount, ShopCommodityId = input.ShopCommodityId, //OwnerCertificationRecordId = input.OwnerCertificationRecordId, OperationTime = DateTimeOffset.Now, OperationUserId = user.Id.ToString() }, cancelToken); var shopCommodity = await _shopCommodityRepository.GetIncludeAsync(input.ShopCommodityId, cancelToken); var data = await _shoppingTrolleyRepository.GetAllIncludeAsync(new ShoppingTrolleyDto { // OwnerCertificationRecordId = input.OwnerCertificationRecordId, OperationUserId = user.Id.ToString(), ShopId = shopCommodity.GoodsType.ShopId.ToString() }, cancelToken); List <GetShoppingTrollerOutputModel> list = new List <GetShoppingTrollerOutputModel>(); foreach (var item in data) { list.Add(new GetShoppingTrollerOutputModel { CommodityCount = item.CommodityCount, CommodityImageUrl = item.ShopCommodity.ImageUrl, CommodityPrice = item.ShopCommodity.DiscountPrice, CommodityId = item.ShopCommodityId.ToString(), CommodityName = item.ShopCommodity.Name, OriginalPrice = item.ShopCommodity.Price }); } return(new ApiResult <GetShoppingTrollerOutput>(APIResultCode.Success, new GetShoppingTrollerOutput { DiscountAmount = list.Sum(x => x.CommodityCount * x.OriginalPrice) - list.Sum(x => x.CommodityCount * x.CommodityPrice), Count = list.Sum(x => x.CommodityCount), Price = list.Sum(x => x.CommodityCount * x.CommodityPrice), List = list })); }