/// <summary> /// 结算可用优惠券 /// </summary> /// <param name="userId"></param> /// <param name="entId"></param> /// <param name="goodsList"></param> /// <returns></returns> public JsonResult UsableCoupon(string userId, string entId, string goodsList, int pageIndex, int pageSize, string channelName, string ywyId = "") { try { if (string.IsNullOrEmpty(userId)) { return(Json(new { success = false, message = "用户未登录,请先登录" })); } ///获取用户信息 UserInfoDal udal = new UserInfoDal(); List <UserInfo> user = udal.GetUserInfo(userId, entId); if (user.Count <= 0) { return(Json(new { success = false, message = "E002" })); } ///获取金额信息 OrderInfoDal cdal = new OrderInfoDal(); OrderAmount Amount = cdal.OrderOriginalAmount(user[0].EntId, userId, goodsList, user[0].Pricelevel, user[0].KhType, "", "", ywyId)[0]; decimal OrdersAmount = Amount.OrdersAmount; decimal RealAmount = Amount.RealAmount; decimal DiscountAmount = Amount.DiscountAmount; decimal PtAmount = Amount.PtAmount; var dal = new CouponDal(); List <UserCoupon> list = dal.UsableCoupon(userId, entId, goodsList, pageIndex, pageSize, ywyId, out int pageCount, out int recordCount, channelName, user[0].Pricelevel, user[0].KhType, OrdersAmount, RealAmount, DiscountAmount, PtAmount);
public ActionResult GetCustomerData(string userId) { try { var targetCustomer = db.Users.SingleOrDefault(x => x.Id == userId); var customerDataDto = Mapper.Map <ApplicationUser, CustomerDataDto>(targetCustomer); customerDataDto.Picture = customerDataDto.Picture ?? "/Media/avatar-placeholder.png"; customerDataDto.TransactionHistory = new List <TransactionDto>(); customerDataDto.PurchaseableCoupons = new List <CouponDto>(); if (Global.CheckIfUserInRole( Global.GetUserRole(targetCustomer.Id), new List <string> { RoleList.Customer, RoleList.Groomer, RoleList.CSS })) { var guidCustomerId = Guid.Parse(targetCustomer.Id); var purchaseableCoupons = db.Coupons.Where(x => x.IsActive && x.Purchased < x.Amount && x.PointPrice <= customerDataDto.Points) .OrderBy(x => x.PointPrice) .ToList(); customerDataDto.TransactionHistory = TransactionDal.GetCustomerTransactionHistory(db, guidCustomerId); foreach (var coupon in purchaseableCoupons) { var couponDto = Mapper.Map <Coupon, CouponDto>(coupon); couponDto.CouponValue = CouponDal.GetCouponValue(coupon); couponDto.CouponTypeValue = coupon.CouponType.ToString(); customerDataDto.PurchaseableCoupons.Add(couponDto); } return(Json(new { success = customerDataDto }, JsonRequestBehavior.AllowGet)); } else { throw new NullReferenceException(); } } catch (NullReferenceException) { return(Json(new { error = "null" }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { error = "error" }, JsonRequestBehavior.AllowGet)); } }
public JsonResult CouponList(string entId, string userId, string source, int pageIndex = 1, int pageSize = 15, int enable = 0) { try { var list = new List <Coupon>(); CouponDal dal = new CouponDal(); list = dal.UserCouponList(entId, userId, source, pageIndex, pageSize, enable, out int recordCount, out int pageCount); return(Json(new { success = true, list = list, recordCount = recordCount, pageCount = pageCount })); } catch (Exception ex) { LogQueue.Write(LogType.Error, "Coupon/CouponList", ex.Message.ToString()); return(Json(new { success = false, message = "用户优惠券列表加载失败!" })); } }
public ActionResult Create(TransactionDto transactionDto) { if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); var transaction = Mapper.Map <TransactionDto, Transaction>(transactionDto); transaction.NewCreatedData(userId); transaction.EarnedPoint = TransactionDal.CalculateEarnedPointByTransanction(db, transaction.Total); CouponDal.AddCouponPurchaseCount(db, transaction.CouponId); TransactionDal.DeductCustomerPointByCoupon(db, transaction.CustomerId.ToString(), transaction.CouponId); TransactionDal.AddPointToCustomer(db, transaction.CustomerId.ToString(), transaction.EarnedPoint); db.Transactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Create")); } ViewBag.UserId = User.Identity.GetUserId(); return(View(transactionDto)); }
/// <summary> /// 领取优惠券 /// </summary> /// <param name="userId"></param> /// <param name="entId"></param> /// <param name="couponCode"></param> /// <returns></returns> public JsonResult GetCoupon(string userId, string entId, int couponCode) { try { if (string.IsNullOrEmpty(userId)) { return(Json(new { success = false, message = "用户未登录,请先登录" })); } CouponDal dal = new CouponDal(); string message = dal.GetCoupon(userId, entId, couponCode, out bool flag); return(Json(new { success = flag, message = message })); } catch (Exception ex) { LogQueue.Write(LogType.Error, "Coupon/GetCoupon", ex.Message.ToString()); return(Json(new { success = false, message = "用户领取优惠券失败!" })); } }
public IHttpActionResult GetFilterableTransactionHistory([FromUri] string startDate, string endDate) { var startFilterDate = DateTime.MinValue; var endFilterDate = DateTime.MaxValue; var listToReturn = new List <TransactionDto>(); if (startDate != "day-month-year") { startFilterDate = Global.ParseStringToDate(startDate); } if (endDate != "day-month-year") { endFilterDate = Global.ParseStringToDate(endDate).AddDays(1); } var transactionHistories = db.Transactions .Where(x => x.IsActive && x.CreatedDate >= startFilterDate && x.CreatedDate < endFilterDate) .OrderByDescending(x => x.CreatedDate) .ToList(); foreach (var history in transactionHistories) { var historyDto = Mapper.Map <Transaction, TransactionDto>(history); if (historyDto.CouponId != null) { historyDto.CouponValue = CouponDal.GetCouponValue(db.Coupons.SingleOrDefault(x => x.Id == historyDto.CouponId)); } else { historyDto.CouponValue = "-"; } historyDto.CreatedDate = Global.DateToString(history.CreatedDate); historyDto.CustomerName = Global.GetUserNameById(history.CustomerId.ToString()); listToReturn.Add(historyDto); } return(Ok(listToReturn)); }
public JsonResult CouponRedemptionCentre(string userId, string entId, string source, int pageIndex = 1, int pageSize = 15) { try { if (string.IsNullOrEmpty(userId)) { return(Json(new { success = false, message = "请求优惠券列表,异常空参!" })); } var list = new List <CouponCentre>(); CouponDal dal = new CouponDal(); list = dal.CouponList(pageIndex, pageSize, userId, entId, source, out int pageCount, out int recordCount); return(Json(new { success = true, list = list, recordCount = recordCount, pageCount = pageCount })); } catch (Exception ex) { LogQueue.Write(LogType.Error, "Coupon/CouponRedemptionCentre", ex.Message.ToString()); return(Json(new { success = false, message = "领券中心优惠券列表加载失败!" })); } }