/// <summary> /// 购物车 -> 待付款立即购买 /// </summary> /// <param name="arrID"></param> /// <returns></returns> public Tuple<bool, string> ShopOrderToBeOrderOpe(string[] arrID) { //Init string strIDs = string.Join("','", arrID); strIDs = string.Format("'{0}'", strIDs); WX_ZZSCBeOrderDAL beOrderDal = new WX_ZZSCBeOrderDAL(); WX_ZZSCOrderLineDAL orderLienDal = new WX_ZZSCOrderLineDAL(); WX_ZZSCShopOrderDAL shopOrderDal = new WX_ZZSCShopOrderDAL(); //Query IEnumerable<WX_ZZSCShopOrderInfo> list = new WX_ZZSCShopOrderDAL().Query<WX_ZZSCShopOrderInfo>(string.Format(" ID IN ({0})", strIDs)); //Check if (list.Count().Equals(0)) { return new Tuple<bool, string>(false, "无购物车数据!"); } //SQL List<string> listSql = new List<string>(); List<object> listPar = new List<object>(); //Result Data string beOrderIDs = string.Empty; //1.需要分组:不同商城 string userID = list.FirstOrDefault().UserID; foreach (var item in list.GroupBy(x => x.StoreID)) { WX_ZZSCBeOrderInfo beOrderMod = new WX_ZZSCBeOrderInfo(); beOrderMod.ID = Guid.NewGuid().ToString("N"); beOrderIDs += beOrderMod.ID + ","; beOrderMod.StoreID = item.Key; beOrderMod.UserID = userID; beOrderMod.OpeDate = DateTime.Now; beOrderMod.OrderType = 3; beOrderMod.DiscountType = 0; beOrderMod.Remark = string.Empty; beOrderMod.RealPrice = 0; beOrderMod.Price = 0; beOrderMod.OrderState = 1; beOrderMod.OrderNum = GUIDHelper.GenerateOrderNum(); foreach (var vItem in item) { WX_ZZSCOrderLineInfo orderLineMod = new WX_ZZSCOrderLineInfo(); orderLineMod.ID = Guid.NewGuid().ToString("N"); orderLineMod.LineID = beOrderMod.ID; orderLineMod.CommodityID = vItem.CommodityID; orderLineMod.CommodityOptionID = string.IsNullOrEmpty(vItem.CommodityOptionID) ? string.Empty : vItem.CommodityOptionID; orderLineMod.Count = vItem.Count; orderLineMod.UnitPrice = vItem.Price / vItem.Count; orderLineMod.RealUnitPrice = vItem.RealPrice / vItem.Count; orderLineMod.TotalPrice = vItem.RealPrice; orderLineMod.DiscountType = vItem.DiscountType; orderLineMod.Remark = string.Empty; orderLineMod.CommodityType = vItem.CommodityType; orderLineMod.OpeDate = DateTime.Now; beOrderMod.RealPrice += Convert.ToDouble(vItem.RealPrice); beOrderMod.Price += Convert.ToDouble(vItem.Price); //存上BeOrder表的ID,作为凭证 vItem.Remark = beOrderMod.ID; listSql.Add(orderLienDal.AddSQL()); listPar.Add(orderLineMod); } listSql.Add(beOrderDal.AddSQL()); listPar.Add(beOrderMod); } //Update 购物车订单数据 foreach (var item in list) { item.OrderState = 1; item.OrderType = 3; listSql.Add(shopOrderDal.UpdateSQL()); listPar.Add(item); } //2执行SQL return new Tuple<bool, string>(new BaseDAL().ExecuteTran(listSql, listPar), beOrderIDs); }
/// <summary> /// 立即购买业务:Insert 表数据 /// </summary> /// <param name="model"></param> public bool PlaceOrderOpe(PlaceOrderServiceInfo model, Func<WX_ZZSCOrderLineInfo, WX_ZZSCOrderLineInfo> funNa = null) { //Init List<string> listSql = new List<string>(); List<object> listPar = new List<object>(); //DAL WX_ZZSCBeOrderDAL beOrderDal = new WX_ZZSCBeOrderDAL(); WX_ZZSCOrderLineDAL lineDal = new WX_ZZSCOrderLineDAL(); //Result bool result = false; try { //1.ZZSCOrderLine表 listSql.Add(beOrderDal.AddSQL()); listPar.Add(model.beOrderInfo); //2.ZZSCBeOrder表 foreach (var item in model.beOrderLineList) { if (funNa == null) { funNa = new WeShopSeviceOverride().PlaceOrderOpe; } listSql.Add(lineDal.AddSQL()); listPar.Add(funNa(item)); } //执行 result = beOrderDal.ExecuteTran(listSql, listPar); } catch (Exception ex) { result = false; LogFileHelper.WriteLogByTxt("立即购买:PlaceOrderOpe方法执行失败:" + ex.Message); } return result; }