/// <summary> /// 处理 未成团退款 /// </summary> public void DealUnDiyGroupRefundExt() { try { ContextSession contextSession = ContextFactory.CurrentThreadContext; var diyGroupOrders = (from diyg in DiyGroup.ObjectSet() join diyGroupOrder in DiyGroupOrder.ObjectSet() on diyg.Id equals diyGroupOrder.DiyGroupId where diyg.State == 5 && diyGroupOrder.State == 1 select diyGroupOrder).ToList(); LogHelper.Debug("开始进入DealUnDiyGroupRefundExt,diyOrderDictionary:" + JsonHelper.JsSerializer(diyGroupOrders)); foreach (var diyGroupOrder in diyGroupOrders) { bool isOk = OrderSV.RefundOrderDiyGroup(diyGroupOrder.OrderId); if (isOk) { var diy = DiyGroup.FindByID(diyGroupOrder.DiyGroupId); diy.State = 6; diy.FailTime = DateTime.Now; diy.ModifiedOn = DateTime.Now; diy.EntityState = EntityState.Modified; contextSession.SaveObject(diy); } } contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error("DealUnDiyGroupRefundExt异常:", ex); } }
/// <summary> /// 确认成团(必传参数DiyGoupId) /// </summary> /// <param name="search"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO ConfirmDiyGroupExt(Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupSearchDTO search) { try { ContextSession contextSession = ContextFactory.CurrentThreadContext; var query = (from diyGroup in DiyGroup.ObjectSet() join diyGroupOrder in DiyGroupOrder.ObjectSet() on diyGroup.Id equals diyGroupOrder.DiyGroupId join order in CommodityOrder.ObjectSet() on diyGroupOrder.OrderId equals order.Id where diyGroup.Id == search.DiyGoupId && diyGroupOrder.State == 1 select order ).ToList(); if (query.Count > 0) { foreach (var diyorder in query) { diyorder.State = 1; diyorder.ModifiedOn = DateTime.Now; diyorder.EntityState = System.Data.EntityState.Modified; Jinher.AMP.BTP.BE.BELogic.AddMessage addmassage = new Jinher.AMP.BTP.BE.BELogic.AddMessage(); addmassage.AddMessages(diyorder.Id.ToString(), diyorder.UserId.ToString(), diyorder.AppId, diyorder.Code, diyorder.State, "", "order"); // 触发订单成功事件 OrderEventHelper.OnOrderPaySuccess(diyorder); } } var diyquery = DiyGroup.ObjectSet().FirstOrDefault(n => n.Id == search.DiyGoupId && n.AppId == search.AppId); if (diyquery != null) { diyquery.State = 3; diyquery.ModifiedOn = DateTime.Now; diyquery.EntityState = EntityState.Modified; } contextSession.SaveChange(); } catch (Exception ex) { LogHelper.Error(string.Format("异常。search:{0}", search), ex); return(new ResultDTO { ResultCode = 1, Message = "Error" }); } return(new ResultDTO { ResultCode = 0, Message = "Success" }); }
/// <summary> /// 获取拼团详情 /// </summary> /// <param name="search"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupDetailDTO> GetDiyGroupDetailExt(Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupDetailSearchDTO search) { ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupDetailDTO> result = new ResultDTO <DiyGroupDetailDTO>(); if (search == null || search.DiyGoupId == Guid.Empty) { result.ResultCode = 1; result.Message = "参数错误"; return(result); } var query = (from dg in DiyGroup.ObjectSet() join c in Commodity.ObjectSet() on dg.CommodityId equals c.Id join p in Promotion.ObjectSet() on dg.PromotionId equals p.Id where dg.Id == search.DiyGoupId select new { DiyGroup = dg, Commodity = c, Promotion = p }).FirstOrDefault(); if (query == null || query.Commodity == null || query.DiyGroup == null || query.Promotion == null) { result.ResultCode = 2; result.Message = "没有获取到相应的拼团详情"; return(result); } var commodity = query.Commodity; var diyGroup = query.DiyGroup; var promotion = query.Promotion; var promotionItem = PromotionItems.ObjectSet().Where(t => t.PromotionId == diyGroup.PromotionId).FirstOrDefault(); if (promotionItem == null) { result.ResultCode = 2; result.Message = "没有获取到相应的拼团详情"; return(result); } var productDetailPicture = ProductDetailsPicture.ObjectSet().Where(n => n.CommodityId == commodity.Id).OrderBy(n => n.Sort).Select(c => c.PicturesPath).FirstOrDefault(); result.Data = new DiyGroupDetailDTO() { Id = diyGroup.Id, Name = diyGroup.Name, Code = diyGroup.Code, SubTime = diyGroup.SubTime, SubId = diyGroup.SubId, AppId = diyGroup.AppId, CommodityId = diyGroup.CommodityId, PromotionId = diyGroup.PromotionId, ModifiedOn = diyGroup.ModifiedOn, ExpireTime = diyGroup.ExpireTime, State = diyGroup.State, JoinNumber = diyGroup.JoinNumber, SuccessProcessorId = diyGroup.SuccessProcessorId, SuccessTime = diyGroup.SuccessTime, FailProcessorId = diyGroup.FailProcessorId, FailTime = diyGroup.FailTime, EsAppId = diyGroup.EsAppId, //commodity PicturesPath = commodity.PicturesPath, CommodityName = commodity.Name, ProductDetailPicture = productDetailPicture, //promotion StartTime = promotion.StartTime, EndTime = promotion.EndTime, GroupMinVolume = promotion.GroupMinVolume ?? -1, ExpireSecond = promotion.ExpireSecond ?? -1, Description = promotion.Description, OutsideId = promotion.OutsideId.Value, //promotionitem LimitBuyEach = promotionItem.LimitBuyEach ?? -1, LimitBuyTotal = promotionItem.LimitBuyTotal ?? -1, DiscountPrice = promotionItem.DiscountPrice, SurplusLimitBuyTotal = promotionItem.SurplusLimitBuyTotal ?? -1 }; result.Data.DiyGroupOrderList = new List <DiyGroupOrderDetailDTO>(); var diyGroupOrder = (from dgOrder in DiyGroupOrder.ObjectSet() join co in CommodityOrder.ObjectSet() on dgOrder.OrderId equals co.Id where dgOrder.DiyGroupId == search.DiyGoupId && (dgOrder.Role == 0 || dgOrder.Role == 1 && dgOrder.State == 1) orderby dgOrder.SubTime ascending select new DiyGroupOrderDetailDTO { Id = dgOrder.Id, SubTime = dgOrder.SubTime, SubId = dgOrder.SubId, AppId = dgOrder.AppId, OrderId = dgOrder.OrderId, OrderCode = dgOrder.OrderCode, Role = dgOrder.Role, DiyGroupId = dgOrder.DiyGroupId, SubCode = dgOrder.SubCode, ModifiedOn = dgOrder.ModifiedOn, DiyGroupPrice = (decimal)co.RealPrice }).ToList(); result.Data.DiyGroupOrderList.AddRange(diyGroupOrder); //提取用户信息 var userIdList = result.Data.DiyGroupOrderList.Select(t => t.SubId).ToList(); var userInfolist = CBCSV.Instance.GetUserInfoWithAccountList(userIdList); if (userInfolist != null && userInfolist.Count > 0) { foreach (var item in result.Data.DiyGroupOrderList) { var tmpUserInfo = userInfolist.Where(t => t.UserId == item.SubId).FirstOrDefault(); if (tmpUserInfo != null) { item.UserCode = CBCSV.EncodeUserCode(tmpUserInfo.Account); item.UserPicture = tmpUserInfo.HeadIcon; } } } //var diyHeadOrder = diyGroupOrder.Where(t => t.Role == 0).FirstOrDefault(); //if (diyHeadOrder != null && diyHeadOrder.State == 0) //{ // result.Data.JoinNumber = result.Data.JoinNumber + 1; //} //系统当前时间,倒计时用 result.Data.DateTimeNow = DateTime.Now; return(result); }
/// <summary> /// 自动确认成团 -- JOB调用 /// </summary> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO VoluntarilyConfirmDiyGroupExt() { try { ContextSession contextSession = ContextFactory.CurrentThreadContext; //获取所有组团成功,但是没有手动成团的拼团订单 var diyQuery = (from diy in DiyGroup.ObjectSet() join c in Commodity.ObjectSet() on diy.CommodityId equals c.Id join ps in PromotionItems.ObjectSet() on c.Id equals ps.CommodityId join p in Promotion.ObjectSet() on ps.PromotionId equals p.Id where diy.JoinNumber != 0 && diy.PromotionId == p.Id && diy.State == 2 select new DiyGroupManageVM { DiyId = diy.Id, AppId = diy.EsAppId }); diyQuery = diyQuery.Distinct(); List <DiyGroupConfig> list = new List <DiyGroupConfig>(); foreach (var diyGroupManageVm in diyQuery) { DiyGroupConfigCDTO diyGroupConfig; if (list.Count > 0 && list.Any(t => t.EsAppId == diyGroupManageVm.AppId)) { diyGroupConfig = list.FirstOrDefault(t => t.EsAppId == diyGroupManageVm.AppId).DiyGroupConfigCdto; } else { diyGroupConfig = TPS.ZPHSV.Instance.GetDiyGroupConfig(diyGroupManageVm.AppId); DiyGroupConfig diyGroupConfigBp = new DiyGroupConfig { EsAppId = diyGroupManageVm.AppId, DiyGroupConfigCdto = diyGroupConfig }; list.Add(diyGroupConfigBp); } if (diyGroupConfig.IsClustering) { var query = (from diyGroup in DiyGroup.ObjectSet() join diyGroupOrder in DiyGroupOrder.ObjectSet() on diyGroup.Id equals diyGroupOrder.DiyGroupId join order in CommodityOrder.ObjectSet() on diyGroupOrder.OrderId equals order.Id where diyGroup.Id == diyGroupManageVm.DiyId && diyGroupOrder.State == 1 && diyGroup.State == 2 select order ).ToList(); if (query.Count > 0) { foreach (var diyorder in query) { diyorder.State = 1; diyorder.ModifiedOn = DateTime.Now; diyorder.EntityState = System.Data.EntityState.Modified; contextSession.SaveObject(diyorder); Jinher.AMP.BTP.BE.BELogic.AddMessage addmassage = new Jinher.AMP.BTP.BE.BELogic.AddMessage(); addmassage.AddMessages(diyorder.Id.ToString(), diyorder.UserId.ToString(), diyorder.AppId, diyorder.Code, diyorder.State, "", "order"); // 触发订单成功事件 OrderEventHelper.OnOrderPaySuccess(diyorder); } } var diyquery = DiyGroup.ObjectSet().FirstOrDefault(n => n.Id == diyGroupManageVm.DiyId && n.EsAppId == diyGroupManageVm.AppId && n.State == 2); if (diyquery != null) { diyquery.State = 3; diyquery.ModifiedOn = DateTime.Now; diyquery.EntityState = EntityState.Modified; contextSession.SaveObject(diyquery); } } } contextSession.SaveChange(); } catch (Exception ex) { LogHelper.Error(string.Format("自动确认成团 -- JOB调用异常"), ex); return(new ResultDTO { ResultCode = 1, Message = "Error" }); } return(new ResultDTO { ResultCode = 0, Message = "Success" }); }
/// <summary> /// 我的拼团订单列表 /// </summary> /// <param name="search"></param> /// <returns></returns> public List <Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupOrderListDTO> GetDiyGroupListExt(Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupSearchDTO search) { List <Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupOrderListDTO> resultlist = new List <DiyGroupOrderListDTO>(); if (search == null) { return(resultlist); } search.PageIndex = search.PageIndex == 0 ? 1 : search.PageIndex; search.PageSize = search.PageSize == 0 ? 20 : search.PageSize; var diyList = (from diy in DiyGroup.ObjectSet() join pro in PromotionItems.ObjectSet() on diy.PromotionId equals pro.PromotionId join p in Promotion.ObjectSet() on pro.PromotionId equals p.Id join diyo in DiyGroupOrder.ObjectSet() on diy.Id equals diyo.DiyGroupId join com in CommodityOrder.ObjectSet() on diyo.OrderId equals com.Id where diy.EsAppId == search.EsAppId && com.UserId == search.UserId && diyo.State == 1 && diy.State != 0 orderby diyo.SubTime descending select new DiyGroupOrderListDTO { Price = com.RealPrice, DiyGroupPrice = pro.DiscountPrice, SubTime = diyo.SubTime, DiyGroupState = diy.State, GroupMinVolume = p.GroupMinVolume ?? -1, JoinNumber = diy.JoinNumber, DiyGroupId = diy.Id, EsAppId = diy.EsAppId, OrderId = diyo.OrderId, DiyOrderSubTime = diyo.SubTime, ModifiedOn = diyo.ModifiedOn, EndTime = p.EndTime }).Skip((search.PageIndex - 1) * search.PageSize).Take(search.PageSize).ToList(); var diyorderIds = diyList.Select(n => n.OrderId).ToList(); if (diyList.Any()) { var diyorderList = (from ord in OrderItem.ObjectSet() where diyorderIds.Contains(ord.CommodityOrderId) select new DiyGroupManageMM { Pic = ord.PicturesPath, Name = ord.Name, DiyNumber = ord.Number, DiyGroupOrderId = ord.CommodityOrderId, attributes = ord.CommodityAttributes }).ToList(); Dictionary <Guid, List <DiyGroupManageMM> > csdtoList = diyorderList.GroupBy(c => c.DiyGroupOrderId, (key, group) => new { DiyGroupOrderId = key, CommodityList = group }) .ToDictionary(c => c.DiyGroupOrderId, c => c.CommodityList.ToList()); var listAppIds = (from co in diyList select co.EsAppId).Distinct().ToList(); Dictionary <Guid, string> dictAppName = APPSV.GetAppNameListByIds(listAppIds); foreach (var diyGroupOrder in diyList) { if (csdtoList.ContainsKey(diyGroupOrder.OrderId)) { var commodityDtoList = csdtoList[diyGroupOrder.OrderId]; diyGroupOrder.OrderDataList = commodityDtoList; } if (dictAppName != null && dictAppName.Count > 0 && dictAppName.ContainsKey(diyGroupOrder.EsAppId)) { var appNameDto = dictAppName[diyGroupOrder.EsAppId]; diyGroupOrder.AppName = appNameDto; } resultlist.Add(diyGroupOrder); } } return(resultlist); }
/// <summary> /// 获取拼团信息(必传参数AppId、PageIndex、PageSize、State,可选参数ComNameSub) /// </summary> /// <param name="search"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupManageDTO> GetDiyGroupsExt(Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupSearchDTO search) { Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupManageDTO> result = new ResultDTO <DiyGroupManageDTO>(); if (search == null) { result.Message = "参数错误,appId不能为空!"; result.ResultCode = 1; return(result); } var resultData = new Jinher.AMP.BTP.Deploy.CustomDTO.DiyGroupManageDTO(); var diyQuery = (from diy in DiyGroup.ObjectSet() join c in Commodity.ObjectSet() on diy.CommodityId equals c.Id join ps in PromotionItems.ObjectSet() on c.Id equals ps.CommodityId join p in Promotion.ObjectSet() on ps.PromotionId equals p.Id where c.AppId == search.AppId && diy.State != 0 && diy.JoinNumber != 0 && diy.PromotionId == p.Id select new DiyGroupManageVM { DiyGroupNumber = diy.Code, DiyGroupName = c.Name, DiyGroupPrice = ps.DiscountPrice, DiyGroupCount = p.GroupMinVolume, DiyId = diy.Id, DiyGroupSubTime = diy.SubTime, DiyGroupState = diy.State }); if (!String.IsNullOrEmpty(search.ComNameSub)) { diyQuery = diyQuery.Where(c => c.DiyGroupName.Contains(search.ComNameSub)); } if (!String.IsNullOrEmpty(search.State)) { if (search.State.Contains(",")) { int[] arrystate = Array.ConvertAll <string, int>(search.State.Split(','), s => int.Parse(s)).ToArray(); diyQuery = diyQuery.Where(c => arrystate.Contains(c.DiyGroupState)); } else { diyQuery = diyQuery.Where(c => c.DiyGroupState == 1); } } else if (search.State == "") { } diyQuery = diyQuery.Distinct(); resultData.Count = diyQuery.Count(); var searchResult = diyQuery.OrderByDescending(c => c.DiyGroupNumber).Skip((search.PageIndex - 1) * search.PageSize).Take(search.PageSize).ToList(); var diygroupIdList = searchResult.Select(c => c.DiyId).ToList(); //构建拼团订单id数组 List <Guid> diyOrderIdList = new List <Guid>(); for (int i = 0; i < searchResult.Count; i++) { diyOrderIdList.Add(searchResult[i].DiyId); } List <DiyGroupManageMM> diyGroupManageMmList = (from diyo in DiyGroupOrder.ObjectSet() join co in CommodityOrder.ObjectSet() on diyo.OrderId equals co.Id where diyo.AppId == search.AppId && diygroupIdList.Contains(diyo.DiyGroupId) && diyo.State == 1 select new DiyGroupManageMM { DiyGroupOrderCode = diyo.OrderCode, DiyGroupPersonCode = diyo.SubCode, DiyGroupPersonRole = diyo.Role, DiyGroupOrderId = diyo.OrderId, DiyGroupId = diyo.DiyGroupId, DiyGroupPrice = (decimal)co.RealPrice } ).OrderBy(c => c.DiyGroupOrderCode).ToList(); foreach (DiyGroupManageVM vm in searchResult) { List <DiyGroupManageMM> diyorderItemslist = new List <DiyGroupManageMM>(); foreach (DiyGroupManageMM model in diyGroupManageMmList) { if (model.DiyGroupId == vm.DiyId) { diyorderItemslist.Add(model); } } vm.OrderDataList = diyorderItemslist; } resultData.Data = searchResult; result.Data = resultData; return(result); }
/// <summary> /// 获取 未完成的拼团列表 /// </summary> /// <param name="inputDTO"></param> /// <returns></returns> public Deploy.CustomDTO.ResultDTO <List <UnfinishedDiyGroupOutputDTO> > UnfinishedDiyGrouplistExt(UnfinishedDiyGroupInputDTO inputDTO) { var appId = inputDTO.AppId; var outsidePromotionId = inputDTO.OutsidePromoId; var maxTakeCount = 10; var appinfos = ZPHSV.Instance.GetAppIdlist(new List <Guid>() { appId }); var appids = appinfos.Select(t => t.AppId).ToList(); appids.Add(appId); try { LogHelper.Debug(string.Format("查询到的未完成的拼团列表. Input:{0}", JsonHelper.JsonSerializer(inputDTO))); //计算未完成的拼团列表 var query = from g in DiyGroup.ObjectSet() join p in Promotion.ObjectSet() on g.PromotionId equals p.Id join go in (from o in DiyGroupOrder.ObjectSet() where o.State == 1 group o by o.DiyGroupId into og select new { Key = og.Key, MemberCount = og.Count() }) on g.Id equals go.Key where p.PromotionType == 3 && g.State == 1 && g.ExpireTime >= DateTime.Now && appids.Contains(g.AppId) && p.OutsideId == outsidePromotionId select new { GroupId = g.Id, OwnerId = g.SubId, LackMember = (p.GroupMinVolume ?? 0) - go.MemberCount, ExpireTime = g.ExpireTime }; var list = query .OrderByDescending(selector => selector.LackMember) .ThenBy(selector => selector.ExpireTime) .Take(maxTakeCount) .ToList(); //获取团长信息 var cbcFacade = new TPS.CBCSVFacade(); var userNameFunc = new Func <Guid, string>(userId => { var user = cbcFacade.GetUserNameIconDTO(userId); if (user != null) { return(user.Name); } return(string.Empty); }); var userIconFunc = new Func <Guid, string>(userId => { var user = cbcFacade.GetUserNameIconDTO(userId); if (user != null) { return(user.HeadIcon); } return(string.Empty); }); var data = list.Select(selector => new UnfinishedDiyGroupOutputDTO() { GroupId = selector.GroupId, LackMember = selector.LackMember, ExpireTime = selector.ExpireTime, OwnerIcon = userIconFunc(selector.OwnerId), OwnerName = userNameFunc(selector.OwnerId) }).ToList(); var result = new ResultDTO <List <UnfinishedDiyGroupOutputDTO> >() { isSuccess = true, ResultCode = 0, Data = data }; LogHelper.Debug(string.Format("查询到的未完成的拼团列表. Output:{0}", JsonHelper.JsonSerializer(result))); return(result); } catch (Exception ex) { LogHelper.Error(string.Format("查询未完成的拼团列表发生异常. {0}", ex.Message), ex); return(new ResultDTO <List <UnfinishedDiyGroupOutputDTO> > { Data = new List <UnfinishedDiyGroupOutputDTO>() }); } }