把var pList = new List<PriceCalculatorPackges>(); var priceCalculatorSet = PriceCalculatorSet.PriceCalculatorSet_GetByID(model.PriceCalculatorSetId); var pm = new PriceCalculatorHelperModel(); pm = JsonConvert.DeserializeObject<PriceCalculatorHelperModel>(priceCalculatorSet.BaseSetting); if(pm != null) { if (!pm.packgeName.StrIsNullOrEmpty()) { decimal price = totalPrice; if (pm.profit_rate != 0 && totalPrice != 0) { price = totalPrice + (totalPrice * pm.profit_rate / 100); } var pmodel = new PriceCalculatorPackges { hours = totalHours, packgeName = pm.packgeName, price = Convert.ToInt32(StringExte.ChinaRound(price.ToString().ToFloat(0), 0)), project = viewProject, words = pm.words }; //把首单特价也附加上 var famount = 0m; if (pm.firstOrderModel == 1) { //按固定价 famount = pm.firstOrderValue; } else { //按百分比 famount = price + (price * pm.firstOrderValue / 100); } pmodel.firstOrderPrice = (decimal)StringExte.ChinaRound((double)famount, 0); pmodel.firstOrderMark = !pm.firstOrderMark.StrIsNullOrEmpty() ? pm.firstOrderMark.Replace("{price}", pmodel.firstOrderPrice.NToString()) : ""; pmodel.firstOrderAppendModel = pm.firstOrderAppendModel; pList.Add(pmodel); } }里面的内容提炼成新的方法
时间: 2023-02-08 17:59:58 浏览: 103
这段代码创建了一个名为pList的List变量,类型为PriceCalculatorPackges。然后它通过调用PriceCalculatorSet的静态方法PriceCalculatorSet_GetByID来获取一个PriceCalculatorSet对象,并将其赋值给priceCalculatorSet变量。接着,它创建了一个新的PriceCalculatorHelperModel对象,并使用JsonConvert.DeserializeObject将priceCalculatorSet.BaseSetting反序列化为PriceCalculatorHelperModel对象。最后,如果pm不为null,它会检查pm.packgeName是否为空,如果不是,则将price设为totalPrice,并判断pm.profit_rate是否不等于0,如果是,那么就会对price进行某些操作。
阅读全文