private EOrder CreateBuyCourseOrder(string userOpenId, ECoursePrice coursePrice) { EOrder order = null; try { order = new EOrder { CreateDateTime = DateTime.Now, CustOpenId = userOpenId, OrderStatus = OrderStatus.Created, OrderType = OrderType.UserCourse, OrderId = EduCodeGenerator.GetOrderOrder(), }; _dbContext.Add(order); EOrderLine line = new EOrderLine { OrderId = order.OrderId, ItemCode = coursePrice.PriceCode, ItemName = $"课时购买{coursePrice.PriceCode}_{coursePrice.CourseScheduleType}", Price = coursePrice.Price, Qty = coursePrice.Qty, Ext1 = (int)coursePrice.CourseScheduleType, }; _dbContext.Add(line); } catch (Exception ex) { throw ex; } return(order); }
/// <summary> /// /获取订单行,更新课时 /// </summary> /// <param name="userOpenId"></param> /// <param name="line"></param> private EUserAccount UpdateUserAccountByOrderLine(string userOpenId, EOrderLine line) { EUserAccount userAccount = _dbContext.DBUserAccount.Where(a => a.UserOpenId == userOpenId).FirstOrDefault(); if (userAccount == null) { UserSrv userSrv = new UserSrv(_dbContext); userAccount = userSrv.CreateNewUserAccount(userOpenId); } CourseScheduleType courseScheduleType = (CourseScheduleType)line.Ext1; ECourseDateRange dr = null; switch (courseScheduleType) { case CourseScheduleType.Standard: case CourseScheduleType.VIP: userAccount.RemainCourseTime += line.Qty; if (userAccount.BuyDate == DateTime.MinValue) { userAccount.BuyDate = DateTime.Now; } if (userAccount.DeadLine == DateTime.MinValue) { userAccount.DeadLine = DateTime.Now; } userAccount.DeadLine = userAccount.DeadLine.AddYears(1); break; case CourseScheduleType.Summer: userAccount.RemainSummerTime += line.Qty; dr = StaticDataSrv.CourseDateRange.Where(a => a.CourseScheduleType == CourseScheduleType.Summer && a.Year == DateTime.Now.Year).FirstOrDefault(); userAccount.SummerDeadLine = dr.EndDate; if (userAccount.SummerBuyDate == DateTime.MinValue) { userAccount.SummerBuyDate = DateTime.Now; } break; case CourseScheduleType.Winter: userAccount.RemainWinterTime += line.Qty; dr = StaticDataSrv.CourseDateRange.Where(a => a.CourseScheduleType == CourseScheduleType.Winter && a.Year == DateTime.Now.Year).FirstOrDefault(); userAccount.WinterDeadLine = dr.EndDate; if (userAccount.WinterBuyDate == DateTime.MinValue) { userAccount.WinterBuyDate = DateTime.Now; } break; } return(userAccount); }
public static void test() { EOrderLine order = null; EMemberInfo mi = null; using (TransactionScope sc = new TransactionScope()) { using (UserContent db = new UserContent()) { string openId = "orKUAw16WK0BmflDLiBYsR-Kh5bE"; db.UpdateToMemberLevel2(openId); mi = db.GetMemberInfoByOpenId(openId); db.SaveChanges(); } using (OrderContent odb = new OrderContent()) { order = odb.UpdateToPaidOrder(mi); } } }