/// <summary> /// Returns a shallow copy. /// </summary> public IndicatorSlot ShallowCopy() { var slot = new IndicatorSlot { SlotNumber = SlotNumber, SlotType = SlotType, LogicalGroup = LogicalGroup, IsDefined = IsDefined, IsCalculated = IsCalculated, IndicatorName = IndicatorName, SeparatedChart = SeparatedChart, MinValue = MinValue, MaxValue = MaxValue, IndParam = IndParam.Clone(), SpecValue = new double[SpecValue.Length], SignalShiftType = SignalShiftType, SignalShift = SignalShift, IndicatorSymbol = IndicatorSymbol, IndicatorPeriod = IndicatorPeriod, }; SpecValue.CopyTo(slot.SpecValue, 0); return(slot); }
/// <summary> /// Returns a copy /// </summary> public IndicatorSlot Clone() { var slot = new IndicatorSlot { SlotNumber = SlotNumber, SlotType = SlotType, SlotStatus = SlotStatus, LogicalGroup = LogicalGroup, IsDefined = IsDefined, IndicatorName = IndicatorName, SeparatedChart = SeparatedChart, MinValue = MinValue, MaxValue = MaxValue, IndParam = IndParam.Clone(), SpecValue = new double[SpecValue.Length] }; SpecValue.CopyTo(slot.SpecValue, 0); slot.Component = new IndicatorComp[Component.Length]; for (int i = 0; i < Component.Length; i++) { slot.Component[i] = Component[i].Clone(); } return(slot); }
/// <summary> /// 获取规格详情 /// </summary> /// <param name="specset"></param> /// <returns></returns> public string GetSkuMsg(string specset) { StringBuilder sb = new StringBuilder(); string[] arr = StringHelper.StringToArray(specset); using (ISession s = SessionFactory.Instance.CreateSession()) { foreach (string i in arr) { int specname_id = 0; int specvalue_id = 0; if (i.IndexOf("_") != -1) { int.TryParse(i.Split('_')[0], out specname_id); int.TryParse(i.Split('_')[1], out specvalue_id); SpecName specname = s.Get <SpecName>("where id = @0 ", specname_id); SpecValue specvalue = s.Get <SpecValue>("where id = @0 ", specvalue_id); if (specname != null && specvalue != null) { sb.Append(string.Format("{0}:{1}; ", specname.name, specvalue.val)); } else { throw new Exception("商品规格信息异常"); } } } return(sb.Length > 0 ? sb.Remove(sb.Length - 1, 1).ToString() : null); } }
public async Task <IActionResult> AddSpec(string specName, string specValue) { // 判断规格组是否存在 long specId = await _fsql.Select <Spec>().Where(l => l.SpecName == specName).ToOneAsync(l => l.SpecId); if (specId == 0) { var specModel = new Spec { SpecName = specName, WxappId = GetSellerSession().WxappId, CreateTime = DateTime.Now.ConvertToTimeStamp(), UpdateTime = DateTime.Now.ConvertToTimeStamp() }; specId = await _fsql.Insert <Spec>().AppendData(specModel).ExecuteIdentityAsync(); } // 判断规格值是否存在 long specValueId = await _fsql.Select <SpecValue>().Where(l => l.SpecId == specId && l.SpecValueName == specValue).ToOneAsync(l => l.SpecValueId); if (specValueId == 0) { var specValueModel = new SpecValue { SpecId = (uint)specId, SpecValueName = specValue, WxappId = GetSellerSession().WxappId, CreateTime = DateTime.Now.ConvertToTimeStamp(), UpdateTime = DateTime.Now.ConvertToTimeStamp() }; specValueId = await _fsql.Insert <SpecValue>().AppendData(specValueModel).ExecuteIdentityAsync(); } return(YesResult(new { specId, specValueId })); }
/// <summary> /// 保存 /// </summary> /// <param name="specName"></param> /// <param name="specValues"></param> public StateCode Save(SpecName specName, string[] specValues) { using (ISession s = SessionFactory.Instance.CreateSession()) { try { s.StartTransaction(); if (specName.id == 0) { s.Insert(specName); foreach (string str in specValues) { if (!string.IsNullOrEmpty(str)) { string val = str; if (str.Length > 15) { val = str.Substring(0, 14).ToString(); } SpecValue ssv = new SpecValue(); //所属属性 ssv.specname_id = specName.id; ssv.val = val; ssv.product_type_id = specName.product_type_id; ssv.created_user_id = specName.created_user_id; ssv.created_date = DateTime.Now; s.Insert(ssv); } } } else { s.Update(specName); } s.Commit(); return(StateCode.State_200); } catch { s.RollBack(); return(StateCode.State_500); } } }
public SpecValue DeepCopy() { var tmp78 = new SpecValue(); if (__isset.comp) { tmp78.Comp = this.Comp; } tmp78.__isset.comp = this.__isset.comp; if ((V != null) && __isset.v) { tmp78.V = this.V.ToArray(); } tmp78.__isset.v = this.__isset.v; return(tmp78); }
/// <summary> /// 保存扩展属性值 /// </summary> /// <param name="user"></param> /// <returns></returns> public JsonResult SaveSpecValue(SysUser user, SpecValue specValue) { if (specValue.id != 0) { specValue.updated_user_id = user.id; specValue.updated_date = DateTime.Now; } else { specValue.created_user_id = user.id; specValue.created_date = DateTime.Now; } StateCode state = ServiceIoc.Get <SpecValueService>().SaveSpecValue(specValue); return(Json(GetResult(state))); }
/// <summary> /// 加入购物车 /// </summary> /// <param name="user_id"></param> /// <param name="product_id"></param> /// <param name="specset"></param> /// <param name="qty"></param> /// <returns></returns> public StateCode Join(long user_id, long product_id, string specset, int qty) { using (ISession s = SessionFactory.Instance.CreateSession()) { try { //商品SKU ProductSku sku = s.Get <ProductSku>("where product_id = @0 and dbo.fn_check_specset(specset,@1) = 1 ", product_id, specset ?? ""); //商品已删除 Product product = s.Get <Product>("where id = @0 ", sku.product_id); if (product == null) { return(StateCode.State_501); } //商品已下架 if (!((bool)product.is_shelves && !(bool)product.is_delete && (DateTime.Now > product.shelves_sdate && DateTime.Now < product.shelves_edate))) { return(StateCode.State_505); } s.StartTransaction(); //购买数量大于0 if (qty > 0 || qty == -1) { //规格详细信息 StringBuilder sb = new StringBuilder(); //是否开启规格 if (product.is_open_spec) { string[] arr = StringHelper.StringToArray(sku.specset); foreach (string i in arr) { int specname_id = 0; int specvalue_id = 0; if (i.IndexOf("_") != -1) { int.TryParse(i.Split('_')[0], out specname_id); int.TryParse(i.Split('_')[1], out specvalue_id); SpecName specname = s.Get <SpecName>("where id = @0 ", specname_id); SpecValue specvalue = s.Get <SpecValue>("where id = @0 ", specvalue_id); if (specname != null && specvalue != null) { if (sb.Length == 0) { sb.Append(string.Format("{0}:{1}", specname.name, specvalue.val)); } else { sb.Append(string.Format(",{0}:{1}", specname.name, specvalue.val)); } } else { throw new Exception("商品规格信息异常"); } } } } string img_url = ""; Img img = s.Get <Img>(" where biz_type = @0 and biz_id = @1 and is_main = @2", ImgType.Product_Cover, sku.product_id, true); if (img != null) { if (img.is_webimg) { img_url = img.webimg_url; } else { img.visit_path = img.visit_path.Replace("/Image/", "/Thm_Image/"); img_url = img.domain_name + img.visit_path + img.file_name + img.extend_name; } } //当前购物车信息 ShoppingCart shoppingcart = s.Get <ShoppingCart>("where user_id = @0 and dbo.fn_check_specset(specset,@1) = 1 and product_id = @2", user_id, sku.specset, product_id); if (shoppingcart != null) { shoppingcart.product_img_url = img_url; shoppingcart.count += qty; shoppingcart.market_price = product.market_price; shoppingcart.product_price = sku.sale_price; shoppingcart.product_name = product.name; shoppingcart.weight = sku.weight; shoppingcart.updated_date = DateTime.Now; s.Update <ShoppingCart>(shoppingcart); } else { shoppingcart = new ShoppingCart() { user_id = user_id, product_id = sku.product_id, market_price = product.market_price, product_price = sku.sale_price, product_name = product.name, product_en_name = product.en_name, weight = sku.weight, specset = sku.specset, spec_msg = sb.ToString(), product_img_url = img_url, count = qty, created_date = DateTime.Now, updated_date = DateTime.Now }; s.Insert <ShoppingCart>(shoppingcart); } } s.Commit(); return(StateCode.State_200); } catch (Exception ex) { s.RollBack(); return(StateCode.State_500); } } }
//更新信息 public static SpecInfo SpecInfoUpload(SpecInfo specInfo, List <string> specValues, out AlertMessage alertMessage) { //权限检查 if (!AUTH.PermissionCheck(ModuleInfo, ActionInfos.Where(i => i.Name == (specInfo.ID == 0 ? "Create" : "Modify")).FirstOrDefault(), out string Message)) { alertMessage = new AlertMessage { Message = Message, Type = AlertType.warning }; return(null); } //表单检查 if (string.IsNullOrWhiteSpace(specInfo.Name)) { alertMessage = new AlertMessage { Message = "规格代码不能为空。", Type = AlertType.warning }; return(null); } if (string.IsNullOrWhiteSpace(specInfo.Title)) { alertMessage = new AlertMessage { Message = "规格名称不能为空。", Type = AlertType.warning }; return(null); } using (var EF = new EF()) { //修改是否存在?规格代码、名称唯一? SpecInfo spec_exist = null; SpecInfo spec_name_exist = null; SpecInfo spec_title_exist = null; if (specInfo.ID == 0) { spec_name_exist = EF.SpecInfos.Where(i => i.Name == specInfo.Name).FirstOrDefault(); spec_title_exist = EF.SpecInfos.Where(i => i.Title == specInfo.Title).FirstOrDefault(); } else { spec_exist = EF.SpecInfos.Where(i => i.ID == specInfo.ID).FirstOrDefault(); if (spec_exist == null) { alertMessage = new AlertMessage { Message = string.Format("规格编号[{0}]不存在。", specInfo.ID), Type = AlertType.warning }; return(null); } spec_name_exist = EF.SpecInfos.Where(i => i.ID != specInfo.ID && i.Name == specInfo.Name).FirstOrDefault(); spec_title_exist = EF.SpecInfos.Where(i => i.ID != specInfo.ID && i.Title == specInfo.Title).FirstOrDefault(); } if (spec_name_exist != null && spec_name_exist.ID > 0) { alertMessage = new AlertMessage { Message = string.Format("规格代码[{0}]已被ID[{1}]使用。", specInfo.Name, spec_name_exist.ID), Type = AlertType.warning }; return(null); } if (spec_title_exist != null && spec_title_exist.ID > 0) { alertMessage = new AlertMessage { Message = string.Format("规格名称[{0}]已被ID[{1}]使用。", specInfo.Title, spec_title_exist.ID), Type = AlertType.warning }; return(null); } //数据保存 using (TransactionScope TS = new TransactionScope()) { //规格信息 if (specInfo.ID == 0) { spec_exist = EF.SpecInfos.Add(new SpecInfo { Enabled = true }); } spec_exist.Name = specInfo.Name; spec_exist.Title = specInfo.Title; spec_exist.IconFont = specInfo.IconFont; EF.SaveChanges(); //规格参数 foreach (var item in specValues) { var specValue_exist = EF.SpecValues.Where(i => i.SpecID == spec_exist.ID && i.Value == item).FirstOrDefault(); if (specValue_exist == null) { EF.SpecValues.Add(specValue_exist = new SpecValue { SpecID = spec_exist.ID, Value = item, Enabled = true }); } EF.SaveChanges(); } TS.Complete(); } //更新完成 alertMessage = null; return(spec_exist); } }
/// <summary> /// 新增定单 /// </summary> /// <param name="orderProduct"></param> /// <param name="isShoppingCart"></param> /// <param name="productOrder"></param> /// <param name="addressID"></param> /// <returns></returns> public StateCode Save(List <JsonOrderProduct> orderProduct, ProductOrder productOrder, long addressID, bool isShoppingCart) { string freight_str = ""; decimal freight = 0; long deliveryModeID = 0; //如果是自提则不计算运费 if (productOrder.logistic_method == 0) { StateCode code = ServiceIoc.Get <DeliveryModeService>().GetDefaultFreight(orderProduct, addressID, out freight_str); if (code != StateCode.State_200) { return(code); } //运费 freight = decimal.Parse(freight_str.Split('#')[1]); //运费模板ID deliveryModeID = int.Parse(freight_str.Split('#')[0]); } using (ISession s = SessionFactory.Instance.CreateSession()) { try { s.StartTransaction(); //订单商品较验 foreach (var op in orderProduct) { //较验商品规格是否存在 ProductSku sku = s.Get <ProductSku>("where product_id = @0 and dbo.fn_check_specset(specset,@1) = 1 ", op.product_id, op.specset); if (sku == null) { productOrder = null; s.RollBack(); return(StateCode.State_1); } //较验商品是否存在 Product product = s.Get <Product>("where id = @0 ", sku.product_id); if (product == null) { productOrder = null; s.RollBack(); return(StateCode.State_1); } //较验商品库存 if (op.qty > sku.stock) { productOrder = null; s.RollBack(); return(StateCode.State_502); } //较验商品状态 if (!((bool)product.is_shelves && !(bool)product.is_delete && (DateTime.Now > product.shelves_sdate && DateTime.Now < product.shelves_edate))) { productOrder = null; s.RollBack(); return(StateCode.State_505); } //商品库存处理 sku.stock = sku.stock - op.qty; s.Update <ProductSku>(sku); } //创建订单 productOrder.serial_no = AlgorithmHelper.CreateNo(); productOrder.status = OrderStatus.WaitingPayment; productOrder.delete_status = 0; productOrder.created_date = DateTime.Now; productOrder.total_amount = 0; productOrder.actual_amount = 0; productOrder.cost_price = 0; productOrder.delivery_mode_id = deliveryModeID; s.Insert <ProductOrder>(productOrder); //总金额,成本价,优惠卷金额 decimal totalProdutPrice = 0, costProdutPrice = 0; //商品的总重量,包邮商品的总重量 int total_weight = 0, sum_total_weight = 0; int index = 0; foreach (var op in orderProduct) { //商品规格 ProductSku sku = s.Get <ProductSku>("where product_id = @0 and dbo.fn_check_specset(specset,@1) = 1", op.product_id, op.specset); //商品 Product product = s.Get <Product>(sku.product_id); string[] arr = StringHelper.StringToArray(sku.specset); StringBuilder specinfo = new StringBuilder(); foreach (string i in arr) { int specname_id = 0; int specvalue_id = 0; if (i.IndexOf("_") != -1) { int.TryParse(i.Split('_')[0], out specname_id); int.TryParse(i.Split('_')[1], out specvalue_id); SpecName specname = s.Get <SpecName>("where id = @0 ", specname_id); SpecValue specvalue = s.Get <SpecValue>("where id = @0 ", specvalue_id); if (specname != null && specvalue != null) { specinfo.Append(string.Format("{0}:{1}; ", specname.name, specvalue.val)); } else { throw new Exception("商品规格信息异常"); } } } //当前当商品成本 decimal cost_sum = sku.cost_price * op.qty; //押金 decimal sum = sku.sale_price * op.qty; totalProdutPrice += sum; costProdutPrice += cost_sum; //该商品是否包邮 if (!product.is_postage) { sum_total_weight += sku.weight * op.qty; } //计算重量 total_weight += sku.weight * op.qty; //获取产品主图片 string mainPic = ""; List <Img> pictures = s.List <Img>("where biz_type = @0 and biz_id = @1", ImgType.Product_Cover, product.id); Img img = pictures.Where(p => p.is_main).SingleOrDefault(); if (img != null) { mainPic = img.is_webimg ? img.webimg_url : img.getThmImgUrl(); } //创建订单明细 ProductOrderDetail orderDetail = new ProductOrderDetail() { order_id = productOrder.id, product_id = product.id, specset = op.specset, product_name = product.name, product_en_name = product.en_name, product_img_url = mainPic, spec_msg = specinfo.ToString().Trim(), unit_price = sku.sale_price, count = op.qty, total_weight = sku.weight * op.qty, order_index = ++index, cost_price = cost_sum, total_amount = sum, actual_amount = sum }; s.Insert(orderDetail); //购物车删除商品 if (isShoppingCart) { s.ExcuteUpdate("delete tb_ord_shoppingcart where user_id = @0 and product_id = @1 and dbo.fn_check_specset(specset,@2) = 1", productOrder.created_user_id, orderDetail.product_id, orderDetail.specset ?? ""); } } #region 会员折扣模块 //会员折扣优惠金额 decimal discount = 0; //累计消费金额 object user_total_amount = s.ExecuteScalar("select COALESCE(SUM(total_amount),0) from tb_odr_order where created_user_id = @0 and is_pay = @1", productOrder.created_user_id, true); //累计消费金额 decimal amount = decimal.Parse(user_total_amount.ToString()); //获取等级列表 List <MemberLevelSetting> levels = s.List <MemberLevelSetting>("order by total_amount desc"); foreach (var level in levels) { if (amount >= level.total_amount) { discount = totalProdutPrice * (100 - level.discount) / 100; break; } } //会员折扣 productOrder.discount_amount = discount; #endregion #region 优惠卷模块 if (productOrder.user_coupon_id != 0) { //存在未使用的优惠卷 string coupon_sql = "where id = @0 and is_used = @1 and full_amount <= @2"; UserCoupon userCoupon = s.Get <UserCoupon>(coupon_sql, productOrder.user_coupon_id, false, totalProdutPrice); if (userCoupon != null) { //优惠卷金额 productOrder.coupon_amount = userCoupon.coupon_amount; //修改会员优惠卷状态 s.ExcuteUpdate("update tb_user_aty_coupon set is_used = @0 where id = @1", true, userCoupon.id); } } #endregion #region 发货单 ShoppingAddress sa = s.Get <ShoppingAddress>(addressID); if (sa == null) { throw new Exception("收货地址不存在"); } //订单发货信息 OrderDelivery orderDelivery = new OrderDelivery(); orderDelivery.order_id = productOrder.id; orderDelivery.province = sa.province; orderDelivery.city = sa.city; orderDelivery.area = sa.area; orderDelivery.address = sa.address; orderDelivery.contact = sa.contact; orderDelivery.mobile = sa.mobile; orderDelivery.postal_code = sa.postal_code; orderDelivery.tel = sa.tel; s.Insert <OrderDelivery>(orderDelivery); #endregion //总计金额(商品总金额+物流费用) var totalPrice = totalProdutPrice + freight; //成本价 productOrder.cost_price = costProdutPrice; //配送费 productOrder.freight = freight; //总金额 productOrder.total_amount = totalPrice; //实付金额 productOrder.actual_amount = totalPrice - productOrder.coupon_amount - discount; //总重量 productOrder.total_weight = total_weight; //更新订单 s.Update <ProductOrder>(productOrder); s.Commit(); return(StateCode.State_200); } catch (Exception ex) { s.RollBack(); return(StateCode.State_500); } } }
public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken) { iprot.IncrementRecursionDepth(); try { TField field; await iprot.ReadStructBeginAsync(cancellationToken); while (true) { field = await iprot.ReadFieldBeginAsync(cancellationToken); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.List) { { TList _list98 = await iprot.ReadListBeginAsync(cancellationToken); Range_begin = new List <byte[]>(_list98.Count); for (int _i99 = 0; _i99 < _list98.Count; ++_i99) { byte[] _elem100; _elem100 = await iprot.ReadBinaryAsync(cancellationToken); Range_begin.Add(_elem100); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 2: if (field.Type == TType.List) { { TList _list101 = await iprot.ReadListBeginAsync(cancellationToken); Range_end = new List <byte[]>(_list101.Count); for (int _i102 = 0; _i102 < _list101.Count; ++_i102) { byte[] _elem103; _elem103 = await iprot.ReadBinaryAsync(cancellationToken); Range_end.Add(_elem103); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 3: if (field.Type == TType.List) { { TList _list104 = await iprot.ReadListBeginAsync(cancellationToken); Offset_key = new List <byte[]>(_list104.Count); for (int _i105 = 0; _i105 < _list104.Count; ++_i105) { byte[] _elem106; _elem106 = await iprot.ReadBinaryAsync(cancellationToken); Offset_key.Add(_elem106); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 4: if (field.Type == TType.I64) { Offset_rev = await iprot.ReadI64Async(cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 5: if (field.Type == TType.List) { { TList _list107 = await iprot.ReadListBeginAsync(cancellationToken); Key_intervals = new List <SpecKeyInterval>(_list107.Count); for (int _i108 = 0; _i108 < _list107.Count; ++_i108) { SpecKeyInterval _elem109; _elem109 = new SpecKeyInterval(); await _elem109.ReadAsync(iprot, cancellationToken); Key_intervals.Add(_elem109); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 6: if (field.Type == TType.List) { { TList _list110 = await iprot.ReadListBeginAsync(cancellationToken); Values = new List <SpecValue>(_list110.Count); for (int _i111 = 0; _i111 < _list110.Count; ++_i111) { SpecValue _elem112; _elem112 = new SpecValue(); await _elem112.ReadAsync(iprot, cancellationToken); Values.Add(_elem112); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 7: if (field.Type == TType.Struct) { Ts_start = new SpecTimestamp(); await Ts_start.ReadAsync(iprot, cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 8: if (field.Type == TType.Struct) { Ts_finish = new SpecTimestamp(); await Ts_finish.ReadAsync(iprot, cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 9: if (field.Type == TType.Struct) { Flags = new SpecFlags(); await Flags.ReadAsync(iprot, cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 10: if (field.Type == TType.I32) { Options = (SpecIntervalOptions)await iprot.ReadI32Async(cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 11: if (field.Type == TType.Struct) { Updating = new SpecIntervalUpdate(); await Updating.ReadAsync(iprot, cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; default: await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); break; } await iprot.ReadFieldEndAsync(cancellationToken); } await iprot.ReadStructEndAsync(cancellationToken); } finally { iprot.DecrementRecursionDepth(); } }