public bool UpdateStock(PinGoods goods, string specificationId, int count, ref SpecificationDetailModel specificationDetail, out string msg) { bool result = false; if (!string.IsNullOrEmpty(specificationId)) { specificationDetail = goods.SpecificationDetailList.Find(s => s.id == specificationId); if (specificationDetail == null) { msg = "所选规格已失效"; return(result); } if (specificationDetail.stock - count < 0 && goods.stockLimit) { msg = "库存不足"; return(result); } else if (goods.stockLimit) { List <SpecificationDetailModel> list = goods.SpecificationDetailList; list.ForEach(spec => { if (spec.id == specificationId) { spec.stock = spec.stock - count; } }); goods.specificationdetail = JsonConvert.SerializeObject(list); result = Update(goods, "specificationdetail");//减库存 } else { result = true; } } else { if (goods.stockLimit && goods.stock - count < 0) { msg = "库存不足"; return(result); } else if (goods.stockLimit) { goods.stock = goods.stock - count; result = Update(goods, "stock");//减库存 } else { result = true; } } msg = result ? "" : "系统繁忙";//去库存失败 return(result); }
public void CreateOrder(PinGoodsOrder order, C_UserInfo userInfo, PinGoods goods, SpecificationDetailModel specificationDetail) { if (order == null || userInfo == null || goods == null) { order = new PinGoodsOrder(); return; } int price = specificationDetail != null ? specificationDetail.price : goods.price; int groupPrice = specificationDetail != null ? specificationDetail.groupPrice : goods.groupPrice; order.price = price * order.count; order.money = order.price + order.freight; order.returnMoney = groupPrice * order.count; order.userId = userInfo.Id; order.receivingNo = GetCount($" aid={order.aid} and storeId={order.storeId}") + 100001; order.outTradeNo = $"{DateTime.Now.ToString("yyyyMMdd")}{order.receivingNo}"; order.goodsPhoto = JsonConvert.SerializeObject(goods); if (specificationDetail != null) { order.specificationPhoto = JsonConvert.SerializeObject(specificationDetail); } order.id = Convert.ToInt32(Add(order)); if (order.id > 0) { switch (order.payway) { case (int)PayWay.微信支付: order.payNo = CreateWxOrder(order, userInfo.NickName); Update(order, "payno"); break; case (int)PayWay.余额支付: PayOrderByAccount(order); //未写 break; case (int)PayWay.线下支付: order.state = (int)PinOrderState.交易成功; Update(order, "state"); break; } } }