/// <summary> /// 是否批准申请 /// </summary> /// <remarks> /// 1.需要触发的事件:1)Update的OnBefore、OnAfter; /// 2.如果申请通过,则不能被取消。 /// 3.申请通过后触发动态,通知。 /// 4.申请被否决后,积分返还。 /// </remarks> /// <param name="record">记录对象</param> /// <param name="isApprove">是否批准</param> public void IsApprove(PointGiftExchangeRecord record, bool isApprove) { if (isApprove) { PointGift gift = this.GetGift(record.GiftId); record.LastModified = DateTime.UtcNow; record.Status = ApproveStatus.Approved; gift.ExchangedCount = gift.ExchangedCount + record.Number; giftRepository.Update(gift); pointService.TradeToSystem(record.PayerUserId, record.Price, "兑换商品", false); EventBus <PointGiftExchangeRecord> .Instance().OnAfter(record, new CommonEventArgs(EventOperationType.Instance().Approved())); } else { record.Status = ApproveStatus.Rejected; userService.UnfreezeTradePoints(record.PayerUserId, record.Price); EventBus <PointGiftExchangeRecord> .Instance().OnAfter(record, new CommonEventArgs(EventOperationType.Instance().Disapproved())); } //处理统计数据 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(record.PayerUserId, OwnerDataKeys.Instance().PostCount(), -1); recordRepository.Update(record); }
/// <summary> /// 编辑商品 /// </summary> /// <remarks> /// 1.编辑商品 /// 2.处理商品图片,将附件关联到商品 /// </remarks> /// <param name="gift">商品对象</param> public void UpdateGift(PointGift gift) { giftRepository.Update(gift); //处理展示图 attachmentService.ToggleTemporaryAttachments(gift.UserId, TenantTypeIds.Instance().PointGift(), gift.GiftId); }
/// <summary> /// 是否上架 /// </summary> /// <param name="gift">商品对象</param> /// <param name="isEnabled">是否显示</param> public void SetEnabled(PointGift gift, bool isEnabled) { if (gift.IsEnabled != isEnabled) { gift.IsEnabled = isEnabled; gift.LastModified = DateTime.UtcNow; giftRepository.Update(gift); } }
/// <summary> /// 创建商品 /// </summary> /// <remarks> /// 1.创建商品 /// 2.处理商品图片,将附件关联到商品 /// </remarks> /// <param name="gift">商品对象</param> /// <returns></returns> public bool CreateGift(PointGift gift) { giftRepository.Insert(gift); //处理展示图 attachmentService.ToggleTemporaryAttachments(gift.UserId, TenantTypeIds.Instance().PointGift(), gift.GiftId); return(gift.GiftId > 0); }
/// <summary> /// 积分换商品 /// </summary> /// <remarks> /// 登录用户并且积分够的用户 /// </remarks> public static bool Gift_Exchange(this Authorizer authorizer, PointGift gift) { IUser currentUser = UserContext.CurrentUser; if (currentUser != null && currentUser.TradePoints >= gift.Price) { return(true); } return(false); }
/// <summary> /// 新建实体时使用 /// </summary> public static PointGift New() { PointGift gifts = new PointGift() { DateCreated = DateTime.UtcNow, LastModified = DateTime.UtcNow }; return(gifts); }
/// <summary> /// 转化为PointGiftEditModel /// </summary> /// <param name="pointGift">数据库实体</param> /// <returns>对应的EditModel</returns> public static PointGiftEditModel AsPointGiftEditModel(this PointGift pointGift) { PointGiftEditModel pointGiftEditModel = new PointGiftEditModel(); pointGiftEditModel.Description = pointGift.Description ?? string.Empty; pointGiftEditModel.FeaturedImage = pointGift.FeaturedImage ?? string.Empty; pointGiftEditModel.FeaturedImageIds = pointGift.FeaturedImageIds ?? string.Empty; pointGiftEditModel.IsEnabled = pointGift.IsEnabled; pointGiftEditModel.Name = pointGift.Name; pointGiftEditModel.Price = pointGift.Price; pointGiftEditModel.GiftId = pointGift.GiftId; pointGiftEditModel.CategoryId = pointGift.Category == null ? 0 : pointGift.Category.CategoryId; return(pointGiftEditModel); }
/// <summary> /// 转化为PointGift /// </summary> /// <returns>PointGift</returns> public PointGift AsPointGift() { PointGift gift = null; if (this.GiftId > 0) { gift = new PointMallService().GetGift(this.GiftId); } else { gift = PointGift.New(); gift.UserId = UserContext.CurrentUser.UserId; } gift.Description = this.Description; gift.FeaturedImage = this.FeaturedImage ?? string.Empty; gift.IsEnabled = this.IsEnabled; gift.LastModified = DateTime.UtcNow; gift.Name = this.Name; gift.Price = this.Price; gift.FeaturedImageIds = this.FeaturedImageIds ?? string.Empty; if (!string.IsNullOrEmpty(this.FeaturedImageIds)) { gift.FeaturedImageAttachmentId = long.Parse(FeaturedImageIds.Split(',').First()); } else { gift.FeaturedImageAttachmentId = 0; } var attachment = new AttachmentService(TenantTypeIds.Instance().PointGift()).Get(gift.FeaturedImageAttachmentId); gift.FeaturedImage = attachment != null?attachment.GetRelativePath() + "\\" + attachment.FileName : string.Empty; gift.LastModified = DateTime.UtcNow; return(gift); }