/// <summary> /// 获取最新的订单号 /// </summary> /// <param name="loggingSesssionInfo">登录信息</param> /// <param name="unitId">门店ID</param> /// <param name="count">订单号增加数量</param> /// <returns>返回最新的订单号</returns> public int GetOrderNo(LoggingSessionInfo loggingSesssionInfo, string unitId, int count) { TUnitExpandBLL service = new TUnitExpandBLL(loggingSesssionInfo); var unitExpandEntity = new TUnitExpandEntity() { UnitId = unitId }; var unitExpandEntitys = this.QueryByEntity(unitExpandEntity, null); int orderNo = 0; //订单号 if (unitExpandEntitys != null && unitExpandEntitys.Length > 0) { //更新 orderNo = Convert.ToInt32(unitExpandEntitys.FirstOrDefault().OrderNo) + 1; unitExpandEntity.OrderNo = Convert.ToInt32(unitExpandEntitys.FirstOrDefault().OrderNo) + count; service.Update(unitExpandEntity, false); } else { //新增 orderNo = 1; unitExpandEntity.OrderNo = count; service.Create(unitExpandEntity); } return(orderNo); }
public string SetOrderInfo(SetOrderInfoReqPara para) { var loggingSessionInfo = this.CurrentUserInfo as LoggingSessionInfo; //获取订单号 TUnitExpandBLL serviceUnitExpand = new TUnitExpandBLL(loggingSessionInfo); string OrderCode = serviceUnitExpand.GetUnitOrderNo(); ////如果StoreID为空,是在线商城订单,重复的逻辑 //if (string.IsNullOrEmpty(para.storeId.Trim())) //{ // UnitService unitServer = new UnitService(loggingSessionInfo); // para.storeId = unitServer.GetUnitByUnitType("OnlineShopping", null).Id; //获取在线商城的门店标识 //} //判断活动的有效性 #region 活动有效性 decimal salesPrice = 0; //活动销售价 decimal qty = Convert.ToInt32(para.qty); //所购数量 //砍价活动 if (para.isBargain == "1") { var eventBll = new PanicbuyingEventBLL(loggingSessionInfo); var detail = eventBll.GetKJEventWithSkuDetail(para.eventId.ToString(), para.orderDetailList[0].skuId.ToString()); if (detail == null) { throw new Exception("未找到相关活动商品信息"); } //1.需要判断,该订单的商品是否还有盈余 if (detail.RemainingQty <= 0) { throw new Exception("活动商品数量不足,当前数量:0"); } //2.判断,该商品活动是否已经终止 if (!string.IsNullOrEmpty(detail.StopReason)) { throw new Exception("活动已停止,停止原因:" + detail.StopReason); } //3.判断购买个数是否小于等于剩余个数 if (int.Parse(para.qty) > detail.RemainingQty) { throw new Exception("活动商品数量不足,当前数量:" + detail.RemainingQty); } //获取当前会员购买个数 if (detail.SinglePurchaseQty > 0)//限购 { List <IWhereCondition> buyCondition = new List <IWhereCondition> { }; buyCondition.Add(new EqualsCondition() { FieldName = "VipId", Value = para.userId }); buyCondition.Add(new EqualsCondition() { FieldName = "itemId", Value = detail.ItemId }); //修改为商品与活动都筛选 xiaowen.qin 2016.5.21 buyCondition.Add(new EqualsCondition() { FieldName = "EventId", Value = para.eventId }); buyCondition.Add(new DirectCondition(" EventOrderMappingId IS NOT NULL ")); var panicbuyingKJEventJoinBLL = new PanicbuyingKJEventJoinBLL(loggingSessionInfo); int buyCount = panicbuyingKJEventJoinBLL.Query(buyCondition.ToArray(), null).Count(); if (buyCount + int.Parse(para.qty) > detail.SinglePurchaseQty) { throw new Exception("限购" + detail.SinglePurchaseQty + "件,你还能购买" + (detail.SinglePurchaseQty - buyCount) + "件,请修改购买数量"); } } } else //团购抢购 { var eventBll = new vwItemPEventDetailBLL(loggingSessionInfo); var detail = eventBll.GetByEventIDAndSkuID(para.eventId, para.orderDetailList[0].skuId.ToString()); salesPrice = detail.SalesPrice ?? 0; //团购抢购销售价 para.totalAmount = (salesPrice * qty).ToString(); //团购抢购总金额 if (detail == null) { throw new Exception("未找到相关活动商品信息"); } //1.需要判断,该订单的商品是否还有盈余 if (detail.RemainingQty <= 0) { throw new Exception("活动商品数量不足,当前数量:0"); } //2.判断,该商品活动是否已经终止 if (!string.IsNullOrEmpty(detail.StopReason)) { throw new Exception("活动已停止,停止原因:" + detail.StopReason); } //3.判断购买个数是否小于等于剩余个数 if (int.Parse(para.qty) > detail.RemainingQty) { throw new Exception("活动商品数量不足,当前数量:" + detail.RemainingQty); } } if (string.IsNullOrEmpty(para.userId)) { throw new Exception("会员信息不存在"); } #endregion //订单类型 #region 根据订单参数设置订单类型 string order_reason_id = string.Empty; if (para.isGroupBy == "1") //团购 { order_reason_id = "CB43DD7DD1C94853BE98C4396738E00C"; } else if (para.isPanicbuying == "1") //抢购 { order_reason_id = "671E724C85B847BDA1E96E0E5A62055A"; } else if (para.isBargain == "1") //砍价 { order_reason_id = "096419BFDF394F7FABFE0DFCA909537F"; } else //普通 { order_reason_id = "2F6891A2194A4BBAB6F17B4C99A6C6F5"; } #endregion //创建事务 var tran = this._currentDAO.GetTran(); var orderId = string.Empty; try { using (tran.Connection) { T_InoutEntity entity = new T_InoutEntity() { #region 订单初始化 order_date = DateTime.Now.ToString("yyyy-MM-dd"), order_type_id = "1F0A100C42484454BAEA211D4C14B80F", create_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), customer_id = para.customerId, status = "1", total_qty = Convert.ToDecimal(para.qty), unit_id = para.storeId, order_no = OrderCode, order_id = Guid.NewGuid().ToString("N"), order_reason_id = order_reason_id, //订单类型:普通,团购,抢购 red_flag = "1", warehouse_id = "67bb4c12785c42d4912aff7d34606592", //???是否是这个?? create_unit_id = para.storeId, create_user_id = para.userId, total_amount = Convert.ToDecimal(para.totalAmount), actual_amount = Convert.ToDecimal(para.actualAmount), discount_rate = para.Rate, total_retail = Convert.ToDecimal(para.totalAmount), print_times = Convert.ToInt32(para.joinNo), vip_no = para.userId, data_from_id = para.reqBy, if_flag = "0", remark = para.remark, Field1 = "0", Field3 = para.isALD, Field7 = "-99", Field8 = para.deliveryId, send_time = para.deliveryTime, Field9 = para.deliveryTime, Field4 = para.deliveryAddress, Field6 = para.mobile, Field12 = para.email, Field13 = para.openId, Field10 = "未审核", Field14 = para.username, Field20 = para.tableNumber, Field16 = para.couponsPrompt, Field15 = order_reason_id, sales_unit_id = para.storeId, purchase_unit_id = para.storeId #endregion }; //订单状态 if (loggingSessionInfo.CurrentLoggingManager.IsApprove == null || loggingSessionInfo.CurrentLoggingManager.IsApprove.Equals("0")) { entity.status = "100"; entity.status_desc = "未审批"; } //创建订单 this._currentDAO.Create(entity, tran); orderId = entity.order_id; //创建订单明细 #region 订单明细列表 var detailbll = new T_Inout_DetailBLL(loggingSessionInfo); foreach (var item in para.orderDetailList) { var detailEntity = new T_Inout_DetailEntity() { create_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), create_user_id = para.userId, modify_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), modify_user_id = para.userId, unit_id = para.storeId, discount_rate = para.Rate, std_price = Convert.ToDecimal(item.salesPrice), enter_price = Convert.ToDecimal(item.salesPrice), sku_id = item.skuId, enter_qty = Convert.ToDecimal(para.qty), order_id = entity.order_id, order_detail_id = Guid.NewGuid().ToString("N"), order_qty = entity.total_qty, enter_amount = item.Amount, order_detail_status = "1", retail_amount = item.Amount, retail_price = item.Amount, display_index = 1, if_flag = 0 }; detailbll.Create(detailEntity, tran); } #endregion //下订单,修改抢购商品的数量信息存储过程ProcPEventItemQty //var eventbll = new vwItemPEventDetailBLL(loggingSessionInfo); //eventbll.ExecProcPEventItemQty(para, entity, tran); tran.Commit(); } } catch (Exception ex) { tran.Rollback(); throw ex; } // return(orderId); }