public ActionResult SendCoupon(SendCouponModel model, int couponTypeId = -1) { CouponTypeInfo couponTypeInfo = AdminCoupons.AdminGetCouponTypeById(couponTypeId); if (couponTypeInfo == null) return PromptView("优惠劵类型不存在"); if (couponTypeInfo.StoreId != WorkContext.StoreId) return PromptView("不能操作其它店铺的优惠劵类型"); if (couponTypeInfo.SendMode != 1) return PromptView("此优惠劵类型不能手动发放"); //发放数量 int sendCount = Coupons.GetSendCouponCount(couponTypeId); //剩余数量 int surplusCount = couponTypeInfo.Count - sendCount; //判断是否大于剩余数量 if (model.Count > surplusCount) ModelState.AddModelError("Count", "数量不能大于" + surplusCount + "!"); if (ModelState.IsValid) { if (model.UType == 0) { int uid = TypeHelper.StringToInt(model.UValue); AdminCoupons.AdminSendCouponToUser(uid, couponTypeId, WorkContext.StoreId, couponTypeInfo.Money, model.Count, WorkContext.Uid, DateTime.Now, WorkContext.IP); AddStoreAdminLog("按用户id发放优惠劵", string.Format("用户id:{0},优惠劵类型id:{1},名称:{2},发放数量:{3}", model.UValue, couponTypeId, couponTypeInfo.Name, model.Count)); } else if (model.UType == 1) { int uid = Users.GetUidByAccountName(model.UValue); AdminCoupons.AdminSendCouponToUser(uid, couponTypeId, WorkContext.StoreId, couponTypeInfo.Money, model.Count, WorkContext.Uid, DateTime.Now, WorkContext.IP); AddStoreAdminLog("按账户名发放优惠劵", string.Format("账户名:{0},优惠劵类型id:{1},名称:{2},发放数量:{3}", model.UValue, couponTypeId, couponTypeInfo.Name, model.Count)); } else { AdminCoupons.AdminBatchGenerateCoupon(couponTypeId, WorkContext.StoreId, couponTypeInfo.Money, model.Count, WorkContext.Uid, DateTime.Now, WorkContext.IP); AddStoreAdminLog("批量生成优惠劵", string.Format("优惠劵类型id:{0},名称:{1},生成数量:{2}", couponTypeId, couponTypeInfo.Name, model.Count)); } return PromptView("优惠劵发放成功"); } ViewData["surplusCount"] = couponTypeInfo.Count - Coupons.GetSendCouponCount(couponTypeId); ViewData["referer"] = MallUtils.GetStoreAdminRefererCookie(); return View(model); }
public ActionResult SendCoupon(int couponTypeId = -1) { CouponTypeInfo couponTypeInfo = AdminCoupons.AdminGetCouponTypeById(couponTypeId); if (couponTypeInfo == null) return PromptView("优惠劵类型不存在"); if (couponTypeInfo.StoreId != WorkContext.StoreId) return PromptView("不能操作其它店铺的优惠劵类型"); if (couponTypeInfo.SendMode != 1) return PromptView("此优惠劵类型不能手动发放"); SendCouponModel model = new SendCouponModel(); ViewData["surplusCount"] = couponTypeInfo.Count - Coupons.GetSendCouponCount(couponTypeId); ViewData["referer"] = MallUtils.GetStoreAdminRefererCookie(); return View(model); }