protected void Page_Load(object sender, EventArgs e) { websiteInfo = DataLoadTool.GetWebsiteInfoModel(); if (string.IsNullOrEmpty(websiteInfo.MallType)) { websiteInfo.MallType = "0"; } model = bll.GetProduct(Request["pid"]); shareLink = Request.Url.AbsoluteUri; if (bll.GetWebsiteInfoModel().IsDistributionMall.Equals(1)) { if (bll.IsLogin) { UserInfo CurrentUserInfo = bll.GetCurrentUserInfo(); if (bll.IsWeiXinBrowser && (string.IsNullOrEmpty(CurrentUserInfo.WXNickname) || string.IsNullOrEmpty(CurrentUserInfo.WXHeadimgurl))) { Session.Clear(); Response.Redirect(Request.Url.AbsoluteUri); } if (string.IsNullOrEmpty(Request["sid"])) { shareLink = string.Format("http://{0}{1}?action=show&pid={2}&sid={3}", Request.Url.Host, Request.FilePath, Request["pid"], CurrentUserInfo.AutoID); } else { ShareUserInfo = bllUser.GetUserInfoByAutoID(int.Parse(Request["sid"])); } } else { Response.Write("请用微信打开"); Response.End(); } } }
/// <summary> /// 是否所有客服都己下线 /// </summary> //public string IsAllKefuOffLine = "false"; protected void Page_Load(object sender, EventArgs e) { if (bllUser.IsLogin) { currentUserInfo = bllUser.GetCurrentUserInfo(); //if (currentUserInfo.UserID=="jubit") //{ // currentUserInfo.AutoID = 7984; //} } else { Response.Redirect("/error/commonmsg.aspx?msg=请用微信打开"); } WebSocketHost = ZentCloud.Common.ConfigHelper.GetConfigString("WebSocketHost"); config = bllWebsite.GetCompanyWebsiteConfig(); if (string.IsNullOrEmpty(config.DistributionQRCodeIcon)) { config.DistributionQRCodeIcon = "/img/icons/kefu.png"; } RecordList = bll.GetLiveChatDetailList(currentUserInfo.AutoID.ToString()); WebsiteInfo = bll.GetWebsiteInfoModelFromDataBase(bll.WebsiteOwner); //IsAllKefuOffLine = bll.IsAllKefuOffLine(bll.WebsiteOwner).ToString(); if (!string.IsNullOrEmpty(Request["product_id"])) { productInfo = bllMall.GetProduct(int.Parse(Request["product_id"])); } }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request["id"])) { webAction = "edit"; } if (webAction == "edit") { id = Convert.ToInt32(Request["id"]); productModel = bllMall.GetProduct(id.ToString()); if (productModel == null) { Response.End(); } else { headTitle = string.Format("{0}", productModel.PName); } } string type = Request["type"]; if (!string.IsNullOrEmpty(type)) { //BookingDoctorFuYou //医生预约妇幼 sbCategory.Append(new MySpider.MyCategories().GetSelectOptionHtml(bllMall.GetCategoryList().Where(p => p.Type.Equals(type)).ToList(), "AutoID", "PreID", "CategoryName", 0, "ddlCategory", "width:200px", "", "", "全部")); } else { //BookingDoctor 医生预约 sbCategory.Append(new MySpider.MyCategories().GetSelectOptionHtml(bllMall.GetCategoryList().Where(p => p.Type == "BookingDoctor").ToList(), "AutoID", "PreID", "CategoryName", 0, "ddlCategory", "width:200px", "", "", "全部")); } }
//public System.Text.StringBuilder sbStores = new System.Text.StringBuilder(); //属性列表 protected void Page_Load(object sender, EventArgs e) { webAction = Request["Action"]; if (webAction == "edit") { pid = Convert.ToInt32(Request["pid"]); productModel = bllMall.GetProduct(pid.ToString()); if (productModel == null) { Response.End(); } else { headTitle = string.Format("{0}", productModel.PName); } } sbCategory.Append(new MySpider.MyCategories().GetSelectOptionHtml(bllMall.GetCategoryList(), "AutoID", "PreID", "CategoryName", 0, "ddlcategory", "width:200px", "")); //foreach (var item in bll.GetWXMallStoreListByWebSite()) //{ // sbStores.AppendFormat("<option value=\"{0}\">{1}</option>", item.AutoID, item.StoreName); //} // propList = bllMall.GetProductPropertyList(); }
/// <summary> /// 计算商品获得的积分 /// </summary> /// <param name="product"></param> /// <param name="rebateRate"></param> /// <param name="count"></param> /// <param name="isGetInt"></param> /// <returns></returns> public decimal CalcProductRebateScore(WXMallProductInfo product, decimal rebateRate, int count = 1, bool isGetInt = false) { BLLMall bllMall = new BLLMall(); decimal addScore = 0; //如果是特卖中 则不返积分 if (product.IsPromotionProduct == 1) { var productSkuList = bllMall.GetProductSkuList(int.Parse(product.PID));//源SKU foreach (var item in productSkuList) { if (bllMall.IsPromotionTime(item)) { return(0); } } } decimal price = product.Price - product.BasePrice; if (price < 0) { price = 0; } addScore = rebateRate * price * count; if (isGetInt) { addScore = RebateScoreGetInt(addScore); } return(addScore); }
/// <summary> /// 添加编辑医生 /// </summary> /// <param name="context"></param> /// <returns></returns> private string DoctorAddEdit(HttpContext context) { WXMallProductInfo model = bllMall.ConvertRequestToModel <WXMallProductInfo>(new WXMallProductInfo()); if (model.PID == "0")//添加 { model.PID = bllMall.GetGUID(BLLJIMP.TransacType.AddWXMallProductID); model.WebsiteOwner = bllMall.WebsiteOwner; model.UserID = currentUserInfo.UserID; model.InsertDate = DateTime.Now; if (model.ArticleCategoryType == "BookingDoctorFuYou") { model.ArticleCategoryType = "BookingDoctorFuYou"; } else { model.ArticleCategoryType = "BookingDoctor"; } if (bllMall.Add(model)) { apiResp.status = true; apiResp.msg = "添加成功"; } else { apiResp.msg = "添加失败"; } } else//编辑 { WXMallProductInfo productInfo = bllMall.GetProduct(model.PID); productInfo.PName = model.PName; productInfo.RecommendImg = model.RecommendImg; productInfo.Stock = model.Stock; productInfo.ExArticleTitle_1 = model.ExArticleTitle_1; productInfo.ExArticleTitle_2 = model.ExArticleTitle_2; productInfo.ExArticleTitle_3 = model.ExArticleTitle_3; productInfo.ExArticleTitle_4 = model.ExArticleTitle_4; productInfo.Sort = model.Sort; productInfo.CategoryId = model.CategoryId; productInfo.SaleCount = model.SaleCount; productInfo.PDescription = model.PDescription; productInfo.ShowImage1 = model.ShowImage1; productInfo.Summary = model.Summary; productInfo.IsOnSale = model.IsOnSale; productInfo.Tags = model.Tags; if (bllMall.Update(productInfo)) { apiResp.status = true; apiResp.msg = "修改成功"; } else { apiResp.msg = "修改失败"; } } return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string orderId = context.Request["order_id"]; WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(orderId); if (orderInfo == null) { resp.errcode = 1; resp.errmsg = "订单号不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (orderInfo.OrderType != 1) { resp.errcode = 1; resp.errmsg = "不是礼品订单"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (orderInfo.PaymentStatus == 0) { resp.errcode = 1; resp.errmsg = "礼品订单未付款"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (!string.IsNullOrEmpty(orderInfo.ParentOrderId)) { //resp.errcode =1; //resp.errmsg = "不是父订单"; //context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); //return; orderInfo = bllMall.GetOrderInfo(orderInfo.ParentOrderId); } WXMallOrderDetailsInfo orderDetail = bllMall.GetOrderDetail(orderInfo.OrderID).First(); WXMallProductInfo productInfo = bllMall.GetProduct(orderDetail.PID); ProductSku skuInfo = bllMall.GetProductSku((int)orderDetail.SkuId); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(new { errcode = 0, errmsg = "ok", order_id = orderInfo.OrderID, product_name = productInfo.PName, product_img_url = bllMall.GetImgUrl(productInfo.RecommendImg), product_count = orderDetail.TotalCount, //product_properties = bllMall.GetProductProperties(skuInfo.SkuId), product_properties = "", is_get_gift = IsGetGift(orderInfo.OrderID), receiver_list = GetReceiverList(orderInfo.OrderID), send_user_info = GiftOrderUserInfo(orderInfo.OrderUserID) })); }
/// <summary> /// 添加 /// </summary> /// <param name="context"></param> /// <returns></returns> private string Add(HttpContext context) { string productId = context.Request["product_id"]; //商品编号 decimal promotionPrice = decimal.Parse(context.Request["promotion_price"]); //特卖价格 int promotionCount = int.Parse(context.Request["promotion_count"]); //特卖库存 double promotionStartTimeStamp = double.Parse(context.Request["promotion_start_timestamp"]); //特卖开始时间 double promotionStopTimeStamp = double.Parse(context.Request["promotion_stop_timestamp"]); //特卖结束时间 WXMallProductInfo productInfo = bllMall.GetProduct(productId); if (productInfo == null) { resp.errcode = 1; resp.errmsg = "商品不存在"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (productInfo.IsPromotionProduct == 1) { resp.errcode = 1; resp.errmsg = "此商品已经加入限时特卖"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (productInfo.IsOnSale == "0") { resp.errcode = 1; resp.errmsg = "此商品已经下架"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (promotionPrice <= 0) { resp.errcode = 1; resp.errmsg = "特卖价不能小于0"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } productInfo.IsPromotionProduct = 1; productInfo.PromotionPrice = promotionPrice; productInfo.PromotionStartTime = promotionStartTimeStamp; productInfo.PromotionStopTime = promotionStopTimeStamp; productInfo.PromotionStock = promotionCount; if (bllMall.Update(productInfo)) { resp.errmsg = "ok"; } else { resp.errcode = 1; resp.errmsg = "添加限时特卖商品失败"; } return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }
protected void Page_Load(object sender, EventArgs e) { config = bllWebSite.GetCompanyWebsiteConfig(); if (config == null) { config = new CompanyWebsite_Config(); config.WebsiteTitle = "膏方专家预约平台"; config.WebsiteDescription = "膏方专家预约平台"; } if (string.IsNullOrEmpty(Request["id"])) { Response.Write("id 参数必传"); Response.End(); } model = bllMall.GetProduct(Request["id"]); if (model == null) { Response.Write("id 参数错误"); Response.End(); } config.WebsiteTitle = string.Format("中医专家-{0}-膏方预约平台已开通!", model.PName); if (model.IsOnSale == "0") { config.WebsiteTitle = string.Format("中医专家-{0}-膏方预约平台即将开通!", model.PName); } StringBuilder sbWhere = new StringBuilder(); sbWhere.AppendFormat(" WebsiteOwner='{0}' And TableName ='ZCJ_WXMallOrderInfo' Order by Sort DESC", bllMall.WebsiteOwner); fieldList = bllMall.GetList <TableFieldMapping>(sbWhere.ToString()); categoryList = bllMall.GetCategoryList().Where(p => p.PreID == 0).Where(p => p.Type == "BookingDoctorFuYou").ToList(); if (!string.IsNullOrEmpty(model.CategoryId)) { categoryId = model.CategoryId; WXMallCategory category = bllMall.Get <WXMallCategory>(string.Format(" AutoID={0}", model.CategoryId)); if (category != null) { if (category.PreID > 0) { categoryId = bllMall.Get <WXMallCategory>(string.Format(" AutoID={0}", category.PreID)).AutoID.ToString(); } } } }
protected void Page_Load(object sender, EventArgs e) { pid = Request["pid"]; pv = Request["pv"]; spreadUserID = Request["spreadUserID"]; if (!string.IsNullOrEmpty(Request["type"])) { type = Request["type"]; } productModel = bllMall.GetProduct(pid); if (productModel == null) { return; } }
public void ProcessRequest(HttpContext context) { string productId = context.Request["product"]; DateTime start = Convert.ToDateTime(context.Request["start"]); DateTime end = Convert.ToDateTime(context.Request["end"]); string type = context.Request["type"]; List <WXMallOrderDetailsInfo> oDetailList = bllMall.GetOrderDetailsList(null, productId, type, start, end); List <OrderDetailsGroupBy> rReusltList = new List <OrderDetailsGroupBy>(); if (oDetailList.Count > 0) { WXMallProductInfo tProductInfo = bllMall.GetByKey <WXMallProductInfo>("PID", productId); int maxCount = tProductInfo.Stock; string oOrderIds = ZentCloud.Common.MyStringHelper.ListToStr(oDetailList.Select(p => p.OrderID).Distinct().ToList(), "'", ","); List <WXMallOrderInfo> orderList = bllMall.GetMultListByKey <WXMallOrderInfo>("OrderID", oOrderIds, true); orderList = orderList.Where(p => p.Status == "预约成功").ToList(); if (orderList.Count >= maxCount) { List <string> sOrderIdList = orderList.Select(p => p.OrderID).Distinct().ToList(); oDetailList = oDetailList.Where(p => sOrderIdList.Contains(p.OrderID)).ToList(); rReusltList = oDetailList.GroupBy(p => new { p.StartDate, p.EndDate }).Select(g => new OrderDetailsGroupBy { StartDate = g.Key.StartDate, EndDate = g.Key.EndDate, GroupByCount = g.Count() }).Where(p => p.GroupByCount >= maxCount).OrderBy(x => x.StartDate).ToList(); } } var result = from p in rReusltList select new { start = p.StartDate.ToString("yyyy-MM-dd HH:mm:ss"), end = p.EndDate.ToString("yyyy-MM-dd HH:mm:ss") }; apiResp.status = true; apiResp.result = result; apiResp.code = (int)APIErrCode.IsSuccess; bllMall.ContextResponse(context, apiResp); }
/// <summary> /// 获取相关商品 /// </summary> /// <param name="prodcutInfo"></param> /// <returns></returns> private dynamic GetRelevantProduct(WXMallProductInfo prodcutInfo) { if (!string.IsNullOrEmpty(prodcutInfo.RelevantProductIds)) { string pids = "'" + prodcutInfo.RelevantProductIds.Replace(",", "','") + "'"; var productList = bllMall.GetList <WXMallProductInfo>(string.Format(" WebsiteOwner='{0}' And PID in({1})", bllMall.WebsiteOwner, pids)); var data = from p in productList select new { product_id = p.PID, title = p.PName, price = p.Price, img_url = p.RecommendImg }; return(data); } return(null); }
protected void Page_Load(object sender, EventArgs e) { if (bllMall.IsLogin) { UserInfo userInfo = DataLoadTool.GetCurrUserModel(); string orderid = Request["oid"]; if (string.IsNullOrEmpty(orderid)) { Response.End(); } WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(orderid); if (orderInfo == null) { Response.End(); } if (!orderInfo.OrderUserID.Equals(userInfo.UserID)) { Response.End(); } QCode.Append(string.Format("订单编号:{0}; ", orderInfo.OrderID)); //QCode.AppendFormat("商品数量:{0}", orderInfo.ProductCount); //QCode.AppendFormat("总金额:{0}", orderInfo.TotalAmount); //QCode.AppendFormat("收货人:{0}", orderInfo.Consignee); //QCode.AppendFormat("手机号:{0}", orderInfo.Phone); //QCode.AppendFormat("手机号:{0}", orderInfo.Phone); List <WXMallOrderDetailsInfo> orderdetails = bllMall.GetOrderDetailsList(orderid); foreach (var item in orderdetails) { WXMallProductInfo productInfo = bllMall.GetProduct(item.PID); if (productInfo != null) { QCode.AppendFormat("[{0} X {1}];", productInfo.PName, item.TotalCount); } } } else { Response.Redirect(string.Format("/App/Cation/Wap/Login.aspx?redirecturl={0}", Request.Url.PathAndQuery)); } }
protected void Page_Load(object sender, EventArgs e) { try { WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(Request["oid"]); if (orderInfo == null) { Response.End(); } if (!orderInfo.WebsiteOwner.Equals(bllMall.WebsiteOwner)) { Response.End(); } WebsiteInfo websiteInfo = bllMall.GetWebsiteInfoModel(); sbPrint.Append("欢迎光临"); sbPrint.Append("<br/>"); sbPrint.AppendFormat("{0}", websiteInfo.WebsiteName); sbPrint.Append("<br/>"); sbPrint.Append("<hr/>"); int totalProductCount = 0; foreach (var item in bllMall.GetOrderDetailsList(Request["oid"])) { WXMallProductInfo productInfo = bllMall.GetProduct(item.PID); if (productInfo != null) { sbPrint.AppendFormat(" {0}", productInfo.PName); sbPrint.Append("<br/>"); sbPrint.AppendFormat("{0} X {1}= {2}元", item.OrderPrice, item.TotalCount, (item.OrderPrice * item.TotalCount)); sbPrint.Append("<br/>"); sbPrint.Append("<hr/>"); totalProductCount += item.TotalCount; } } sbPrint.AppendFormat("数量: {0}", totalProductCount); sbPrint.AppendFormat("<br/>"); sbPrint.AppendFormat("金额: {0}", orderInfo.Product_Fee); sbPrint.AppendFormat("<br/>"); sbPrint.AppendFormat("配送费用: {0} 元", orderInfo.Transport_Fee); sbPrint.AppendFormat("<br/>"); sbPrint.AppendFormat("合计: {0} 元", orderInfo.TotalAmount); sbPrint.Append("<hr/>"); sbPrint.AppendFormat("订单编号: {0}", orderInfo.OrderID); sbPrint.AppendFormat("<br/>"); sbPrint.AppendFormat("姓名:{0}", orderInfo.Consignee); sbPrint.AppendFormat("<br/>"); sbPrint.AppendFormat("电话:{0}", orderInfo.Phone); sbPrint.AppendFormat("<br/>"); sbPrint.AppendFormat("地址:{0}", orderInfo.Address); sbPrint.AppendFormat("<br/>"); string PayMentType = ""; switch (orderInfo.PaymentType) { case 0: PayMentType = "现金"; break; case 1: PayMentType = "支付宝" + (orderInfo.PaymentStatus.Equals(0) ? "[未付]" : "[已付]"); break; case 2: PayMentType = "微信支付" + (orderInfo.PaymentStatus.Equals(0) ? "[未付]" : "[已付]"); break; default: break; } sbPrint.AppendFormat("支付方式:{0}", PayMentType); sbPrint.AppendFormat("<br/>"); if (!string.IsNullOrEmpty(orderInfo.DeliveryStaff)) { sbPrint.AppendFormat("配送员姓名:{0}", orderInfo.DeliveryStaff); sbPrint.AppendFormat("<br/>"); var deliverStaffInfo = bllMall.GetDeliveryStaff(orderInfo.DeliveryStaff); if (deliverStaffInfo != null) { sbPrint.AppendFormat("配送员电话:{0}", deliverStaffInfo.StaffPhone); sbPrint.AppendFormat("<br/>"); } } if (orderInfo.DeliveryTime != null) { sbPrint.AppendFormat("用餐时间:{0}", orderInfo.DeliveryTime); sbPrint.AppendFormat("<br/>"); } sbPrint.AppendFormat("备注:{0}", orderInfo.OrderMemo); sbPrint.AppendFormat("<br/>"); sbPrint.AppendFormat("谢谢惠顾!"); } catch (Exception) { Response.End(); } }
public void ProcessRequest(HttpContext context) { string data = context.Request["data"]; decimal productFee = 0; //商品总价格 OrderModel orderRequestModel; //订单模型 try { orderRequestModel = ZentCloud.Common.JSONHelper.JsonToModel <OrderModel>(data); } catch (Exception ex) { apiResp.code = 1; apiResp.msg = "JSON格式错误,请检查.错误信息:" + ex.Message; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 检查是否可以下单 if (string.IsNullOrEmpty(orderRequestModel.select_time_type)) { apiResp.code = 1; apiResp.msg = "请选择一种时间预约方式"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } int totalHours = 0; //预约小时数 if (orderRequestModel.select_time_type == "0") //直接选择开始时间结束时间方式 { if (string.IsNullOrEmpty(orderRequestModel.start_time) || string.IsNullOrEmpty(orderRequestModel.stop_time)) { apiResp.code = 1; apiResp.msg = "请选择开始时间与结束时间"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (DateTime.Parse(orderRequestModel.start_time) <= DateTime.Now) { apiResp.code = 1; apiResp.msg = "开始时间需要晚于当前时间"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (DateTime.Parse(orderRequestModel.stop_time) <= DateTime.Parse(orderRequestModel.start_time)) { apiResp.code = 1; apiResp.msg = "结束时间需要晚于开始时间"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } totalHours = (int)(DateTime.Parse(orderRequestModel.stop_time) - DateTime.Parse(orderRequestModel.start_time)).TotalHours; } else if (orderRequestModel.select_time_type == "1")//选择某一天的多个时间段的方式 { if (string.IsNullOrEmpty(orderRequestModel.date) || string.IsNullOrEmpty(orderRequestModel.date_time_ranges)) { apiResp.code = 1; apiResp.msg = "请选择预约时间段"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (DateTime.Parse(orderRequestModel.date) <= DateTime.Now) { apiResp.code = 1; apiResp.msg = "开始时间需要晚于当前时间"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } totalHours = orderRequestModel.date_time_ranges.Split(';').Count(); } if (!Check(orderRequestModel)) { apiResp.code = 1; apiResp.msg = "您所选的时间段已经被占用,请选择别的时间段"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #endregion WXMallOrderInfo orderInfo = new WXMallOrderInfo();//订单表 orderInfo.OrderID = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder); orderInfo.Consignee = orderRequestModel.receiver_name; orderInfo.InsertDate = DateTime.Now; orderInfo.OrderUserID = CurrentUserInfo.UserID; orderInfo.Phone = orderRequestModel.receiver_phone; orderInfo.WebsiteOwner = bllMall.WebsiteOwner; orderInfo.Transport_Fee = 0; orderInfo.OrderMemo = orderRequestModel.buyer_memo; orderInfo.MyCouponCardId = orderRequestModel.cardcoupon_id.ToString(); orderInfo.UseScore = orderRequestModel.use_score; orderInfo.Status = "待付款"; orderInfo.OrderType = 3; orderInfo.Ex3 = orderRequestModel.select_time_type; orderInfo.Ex4 = orderRequestModel.start_time; orderInfo.Ex5 = orderRequestModel.stop_time; orderInfo.Ex6 = orderRequestModel.date; orderInfo.Ex7 = orderRequestModel.date_time_ranges; orderInfo.LastUpdateTime = DateTime.Now; if (!string.IsNullOrEmpty(orderRequestModel.sale_id))//分销ID { long saleId = 0; if (long.TryParse(orderRequestModel.sale_id, out saleId)) { orderInfo.SellerId = saleId; } } if (orderRequestModel.pay_type == "WEIXIN")//微信支付 { orderInfo.PaymentType = 2; } else if (orderRequestModel.pay_type == "ALIPAY")//支付宝支付 { orderInfo.PaymentType = 1; } #region 格式检查 if (string.IsNullOrEmpty(orderInfo.Consignee)) { apiResp.code = 1; apiResp.msg = "收货人姓名不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderRequestModel.receiver_phone)) { apiResp.code = 1; apiResp.msg = "联系手机号不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (orderRequestModel.skus == null) { apiResp.code = 1; apiResp.msg = "skus 参数不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //相关检查 #endregion #region 商品检查 订单详情生成 ///订单详情 List <WXMallOrderDetailsInfo> detailList = new List <WXMallOrderDetailsInfo>();//订单详情 #region 购买的商品 List <WXMallProductInfo> productList = new List <WXMallProductInfo>(); foreach (var sku in orderRequestModel.skus) { ProductSku productSku = bllMall.GetProductSku(sku.sku_id); WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); productList.Add(productInfo); } productList = productList.Distinct().ToList(); #endregion #region 检查优惠券是否可用 if (orderRequestModel.cardcoupon_id > 0) { var mycardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, CurrentUserInfo.UserID); if (mycardCoupon == null) { apiResp.code = 1; apiResp.msg = "无效的优惠券"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } var cardCoupon = bllCardCoupon.GetCardCoupon(mycardCoupon.CardId); if (cardCoupon == null) { apiResp.code = 1; apiResp.msg = "无效的优惠券"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 需要购买指定商品 if ((!string.IsNullOrEmpty(cardCoupon.Ex2)) && (cardCoupon.Ex2 != "0")) { if (productList.Count(p => p.PID == cardCoupon.Ex2) == 0) { var productInfo = bllMall.GetProduct(cardCoupon.Ex2); apiResp.code = 1; apiResp.msg = string.Format("此优惠券需要购买{0}时才可以使用", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion #region 需要购买指定标签商品 if (!string.IsNullOrEmpty(cardCoupon.Ex8)) { if (productList.Where(p => p.Tags == "" || p.Tags == null).Count() == productList.Count)//全部商品都没有标签 { apiResp.code = 1; apiResp.msg = string.Format("使用此优惠券需要购买标签为{0}的商品", cardCoupon.Ex8); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } bool checkResult = false; foreach (var product in productList) { if (!string.IsNullOrEmpty(product.Tags)) { foreach (string tag in product.Tags.Split(',')) { if (cardCoupon.Ex8.Contains(tag)) { checkResult = true; break; } } } } if (!checkResult) { apiResp.code = 1; apiResp.msg = string.Format("使用此优惠券需要购买标签为{0}的商品", cardCoupon.Ex8); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion } #endregion foreach (var sku in orderRequestModel.skus) { //先检查库存 ProductSku productSku = bllMall.GetProductSku(sku.sku_id); if (productSku == null) { apiResp.code = 1; apiResp.msg = "SKU不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); if (productInfo.IsOnSale == "0") { apiResp.code = 1; apiResp.msg = string.Format("{0}已下架", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } WXMallOrderDetailsInfo detailModel = new WXMallOrderDetailsInfo(); detailModel.OrderID = orderInfo.OrderID; detailModel.PID = productInfo.PID; detailModel.TotalCount = sku.count; detailModel.OrderPrice = bllMall.GetSkuPrice(productSku) * totalHours; detailModel.ProductName = productInfo.PName; detailModel.SkuId = productSku.SkuId; detailList.Add(detailModel); } #endregion productFee = detailList.Sum(p => p.OrderPrice * p.TotalCount).Value; //商品费用 orderInfo.Transport_Fee = 0; orderInfo.Product_Fee = productFee; orderInfo.TotalAmount = orderInfo.Product_Fee + orderInfo.Transport_Fee; #region 优惠券计算 decimal discountAmount = 0;//优惠金额 bool canUseCardCoupon = false; string msg = ""; if (orderRequestModel.cardcoupon_id > 0)//有优惠券 { discountAmount = bllMall.CalcDiscountAmount(orderRequestModel.cardcoupon_id.ToString(), data, CurrentUserInfo.UserID, out canUseCardCoupon, out msg); if (!canUseCardCoupon) { apiResp.code = 1; apiResp.msg = msg; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (discountAmount > productFee) { apiResp.code = 1; apiResp.msg = "优惠券可优惠金额超过了订单总金额"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } orderInfo.CardcouponDisAmount = discountAmount; } #endregion #region 积分计算 decimal scoreExchangeAmount = 0;///积分抵扣的金额 //积分计算 if (orderRequestModel.use_score > 0) { if (CurrentUserInfo.TotalScore < orderRequestModel.use_score) { apiResp.code = 1; apiResp.msg = "积分不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } ScoreConfig scoreConfig = bllScore.GetScoreConfig(); scoreExchangeAmount = Math.Round(orderRequestModel.use_score / (scoreConfig.ExchangeScore / scoreConfig.ExchangeAmount), 2); } //积分计算 #endregion #region 合计计算 orderInfo.TotalAmount -= discountAmount; //优惠券优惠金额 orderInfo.TotalAmount -= scoreExchangeAmount; //积分优惠金额 orderInfo.PayableAmount = orderInfo.TotalAmount; //应付金额 if ((productFee - discountAmount - scoreExchangeAmount) < orderInfo.TotalAmount) { apiResp.code = 1; apiResp.msg = "积分兑换金额不能大于订单总金额,请减少积分兑换"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #endregion if (orderInfo.TotalAmount < 0) { apiResp.code = 1; apiResp.msg = "付款金额不能小于0"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (orderInfo.TotalAmount == 0) { orderInfo.PaymentStatus = 1; orderInfo.PayTime = DateTime.Now; orderInfo.Status = "待发货"; } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { if (!this.bllMall.Add(orderInfo, tran)) { tran.Rollback(); apiResp.code = 1; apiResp.msg = "提交失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 更新优惠券使用状态 //优惠券 if (orderRequestModel.cardcoupon_id > 0 && (canUseCardCoupon == true))//有优惠券且已经成功使用 { MyCardCoupons myCardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, CurrentUserInfo.UserID); myCardCoupon.UseDate = DateTime.Now; myCardCoupon.Status = 1; if (!bllCardCoupon.Update(myCardCoupon, tran)) { tran.Rollback(); apiResp.code = 1; apiResp.msg = "更新优惠券状态失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } //优惠券 #endregion #region 积分抵扣 //积分扣除 if (orderRequestModel.use_score > 0) { CurrentUserInfo.TotalScore -= orderRequestModel.use_score; if (bllMall.Update(CurrentUserInfo, string.Format(" TotalScore-={0}", orderRequestModel.use_score), string.Format(" AutoID={0}", CurrentUserInfo.AutoID)) < 0) { tran.Rollback(); apiResp.code = 1; apiResp.msg = "更新用户积分失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //积分记录 UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = -orderRequestModel.use_score; scoreRecord.ScoreType = "OrderSubmit"; scoreRecord.UserID = CurrentUserInfo.UserID; scoreRecord.AddNote = "预约使用积分"; if (!bllMall.Add(scoreRecord)) { tran.Rollback(); apiResp.code = 1; apiResp.msg = "插入积分记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //积分记录 } //积分扣除 #endregion #region 插入订单详情页 foreach (var item in detailList) { ProductSku productSku = bllMall.GetProductSku((int)(item.SkuId)); WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); if (!this.bllMall.Add(item, tran)) { tran.Rollback(); apiResp.code = 1; apiResp.msg = "提交失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion tran.Commit();//提交订单事务 } catch (Exception ex) { //回滚事物 tran.Rollback(); apiResp.code = 1; apiResp.msg = "提交订单失败,内部错误"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } apiResp.status = true; apiResp.msg = "ok"; apiResp.result = new { order_id = orderInfo.OrderID }; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); }
protected void Page_Load(object sender, EventArgs e) { try { //Tolog("进入支付回调"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Request.InputStream); xmlDoc.Save(string.Format("C:\\WXPay\\Notify{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));//写入日志 //全部参数 Dictionary <string, string> parametersAll = new Dictionary <string, string>(); foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes) { string key = item.Name; string value = item.InnerText; if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value))) { parametersAll.Add(key, value); } } parametersAll = (from entry in parametersAll orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);//全部参数排序 orderInfo = bllMall.GetOrderInfo(parametersAll["out_trade_no"]); PayConfig payConfig = bllPay.GetPayConfig(); if (!bllPay.VerifySignatureWx(parametersAll, payConfig.WXPartnerKey))//验证签名 { Tolog("验证签名出错"); Response.Write(failXml); return; } if (orderInfo == null) { Tolog("订单未找到"); Response.Write(failXml); return; } if (orderInfo.PaymentStatus.Equals(1)) { //Tolog("已支付"); Response.Write(successXml); return; } orderInfo.PaymentType = 2; //更新订单状态 WXMallProductInfo tProductInfo = new WXMallProductInfo(); if (parametersAll["return_code"].Equals("SUCCESS") && parametersAll["result_code"].Equals("SUCCESS")) //交易成功 { UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, bllUser.WebsiteOwner); //下单用户信息 string hasOrderIDs = ""; int maxCount = 1; //Tolog("准备检查更新订单状态"); if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType)) { //Tolog("预订类型"); #region 预约订单修改状态 orderInfo.PaymentStatus = 1; orderInfo.PayTime = DateTime.Now; orderInfo.Status = "预约成功"; #region 检查是否有预约成功的订单 List <WXMallOrderDetailsInfo> tDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID, null, orderInfo.ArticleCategoryType, null, null); List <WXMallOrderDetailsInfo> oDetailList = bllMall.GetOrderDetailsList(null, tDetailList[0].PID, orderInfo.ArticleCategoryType, tDetailList.Min(p => p.StartDate), tDetailList.Max(p => p.EndDate)); tProductInfo = bllMall.GetByKey <WXMallProductInfo>("PID", tDetailList[0].PID); maxCount = tProductInfo.Stock; List <string> hasOrderIDList = new List <string>(); foreach (var item in tDetailList) { List <WXMallOrderDetailsInfo> hasOrderDetailList = oDetailList.Where(p => !((item.StartDate >= p.EndDate && item.EndDate > p.EndDate) || (item.StartDate < p.StartDate && item.EndDate <= p.StartDate))).ToList(); if (hasOrderDetailList.Count >= maxCount) { hasOrderIDList.AddRange(hasOrderDetailList.Select(p => p.OrderID).Distinct()); } } hasOrderIDList = hasOrderIDList.Where(p => !p.Contains(orderInfo.OrderID)).ToList(); if (hasOrderIDList.Count > 0) { hasOrderIDList = hasOrderIDList.Distinct().ToList(); hasOrderIDs = MyStringHelper.ListToStr(hasOrderIDList, "'", ","); } #endregion 检查是否有预约成功的订单 #endregion 预约订单修改状态 } else { //Tolog("普通类型"); #region 原订单修改状态 orderInfo.PaymentStatus = 1; orderInfo.Status = "待发货"; orderInfo.PayTime = DateTime.Now; if (orderInfo.DeliveryType == 1) { orderInfo.Status = "待自提"; } Tolog("更改状态start"); //if (bllMall.GetWebsiteInfoModelFromDataBase().IsDistributionMall.Equals(1)) //{ orderInfo.GroupBuyStatus = "0"; orderInfo.DistributionStatus = 1; //if (orderInfo.IsMain==1) //{ // bllMall.Update(orderInfo,string.Format(" DistributionStatus=1"),string.Format("ParentOrderId='{0}'",orderInfo.OrderID)); //} #region 活动订单 if (orderInfo.OrderType == 4) { ActivityDataInfo data = bllMall.Get <ActivityDataInfo>(string.Format(" OrderId='{0}'", orderInfo.OrderID)); if (data != null) { bllMall.Update(data, string.Format(" PaymentStatus=1"), string.Format(" OrderId='{0}'", orderInfo.OrderID)); } } #endregion bllMall.Update(orderInfo, string.Format("PaymentStatus=1,Status='待发货',PayTime=GETDATE(),DistributionStatus=1"), string.Format("ParentOrderId='{0}'", orderInfo.OrderID)); //} #endregion 原订单修改状态 try { //设置交易流水号 orderInfo.PayTranNo = parametersAll["transaction_id"]; } catch (Exception ex) { Tolog("设置交易流水号失败:" + ex.Message); } } bool result = false; if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType)) { if (string.IsNullOrWhiteSpace(hasOrderIDs)) { hasOrderIDs = "'0'"; } result = bllMall.Update(new WXMallOrderInfo(), string.Format("PaymentStatus={0},PayTime=GetDate(),Status='{1}'", 1, "预约成功"), string.Format("OrderID='{0}' and WebsiteOwner='{4}' AND (select count(1) from [ZCJ_WXMallOrderInfo] where Status='{3}' and WebsiteOwner='{4}' and OrderID IN({1}))<{2}", orderInfo.OrderID, hasOrderIDs, maxCount, "预约成功", bllMall.WebsiteOwner) ) > 0; if (result) { // #region 交易成功加积分 //增加积分 (慧聚不需要) //if (orderInfo.TotalAmount > 0) //{ // ScoreConfig scoreConfig = bllScore.GetScoreConfig(); // int addScore = 0; // if (scoreConfig != null && scoreConfig.OrderAmount > 0 && scoreConfig.OrderScore > 0) // { // addScore = (int)(orderInfo.PayableAmount / (scoreConfig.OrderAmount / scoreConfig.OrderScore)); // } // if (addScore > 0) // { // if (bllUser.Update(new UserInfo(), // string.Format(" TotalScore+={0},HistoryTotalScore+={0}", addScore), // string.Format(" UserID='{0}'", orderInfo.OrderUserID)) > 0) // { // UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); // scoreRecord.AddTime = DateTime.Now; // scoreRecord.Score = addScore; // scoreRecord.ScoreType = "OrderSuccess"; // scoreRecord.UserID = orderInfo.OrderUserID; // scoreRecord.AddNote = "预约-交易成功获得积分"; // bllMall.Add(scoreRecord); // } // } //} // #endregion #region 修改其他预约订单为预约失败 返还积分 if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType) && !string.IsNullOrWhiteSpace(hasOrderIDs)) { int tempCount = 0; List <WXMallOrderInfo> tempList = bllMall.GetOrderList(0, 1, "", out tempCount, "预约成功", null, null, null, null, null, null, null, null, null, null, orderInfo.ArticleCategoryType, hasOrderIDs); tempCount = tempCount + 1; //加上当前订单的数量 if (tempCount >= maxCount) { tempList = bllMall.GetColOrderListInStatus("'待付款','待审核'", hasOrderIDs, "OrderID,OrderUserID,UseScore", bllMall.WebsiteOwner); if (tempList.Count > 0) { string stopOrderIds = MyStringHelper.ListToStr(tempList.Select(p => p.OrderID).ToList(), "'", ","); tempList = tempList.Where(p => p.UseScore > 0).ToList(); foreach (var item in tempList) { orderUserInfo.TotalScore += item.UseScore; if (bllUser.Update(new UserInfo(), string.Format(" TotalScore+={0}", item.UseScore), string.Format(" UserID='{0}'", item.OrderUserID)) > 0) { UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = item.UseScore; scoreRecord.TotalScore = orderUserInfo.TotalScore; scoreRecord.ScoreType = "OrderCancel"; scoreRecord.UserID = item.OrderUserID; scoreRecord.RelationID = item.OrderID; scoreRecord.AddNote = "预约-订单失败返还积分"; scoreRecord.WebSiteOwner = item.WebsiteOwner; bllMall.Add(scoreRecord); } } bllMall.Update(new WXMallOrderInfo(), string.Format("Status='{0}'", "预约失败"), string.Format("OrderID In ({0}) and WebsiteOwner='{1}'", stopOrderIds, bllMall.WebsiteOwner)); } } //Tolog("更改修改其他预约为预约失败"); } #endregion } } else { result = bllMall.Update(orderInfo); } if (result) { #region 拼团订单 if (orderInfo.OrderType == 2) { try { if (!string.IsNullOrEmpty(orderInfo.GroupBuyParentOrderId)) { var parentOrderInfo = bllMall.GetOrderInfo(orderInfo.GroupBuyParentOrderId); if (parentOrderInfo.Ex10 == "1") { if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And GroupBuyParentOrderId='{0}' ", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount) { bllMall.Update(new WXMallOrderInfo(), string.Format("Status='已取消'"), string.Format(" GroupBuyParentOrderId='{0}' And PaymentStatus=0", parentOrderInfo.OrderID)); parentOrderInfo.GroupBuyStatus = "1"; bllMall.Update(parentOrderInfo); } } else { if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And GroupBuyParentOrderId='{0}' Or OrderId='{0}'", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount) { bllMall.Update(new WXMallOrderInfo(), string.Format("Status='已取消'"), string.Format(" GroupBuyParentOrderId='{0}' And PaymentStatus=0", parentOrderInfo.OrderID)); parentOrderInfo.GroupBuyStatus = "1"; bllMall.Update(parentOrderInfo); } } } } catch (Exception) { } } #endregion Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(orderInfo.WebsiteOwner); //Tolog("更改状态true"); #region Efast同步 //判读当前站点是否需要同步到驿氪和efast if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncEfast, bllCommRelation.WebsiteOwner, "")) { try { Tolog("开始同步efast"); string outOrderId = string.Empty, msg = string.Empty; var syncResult = bllEfast.CreateOrder(orderInfo.OrderID, out outOrderId, out msg); if (syncResult) { orderInfo.OutOrderId = outOrderId; bllMall.Update(orderInfo); } Tolog(string.Format("efast订单同步结果:{0},订单号:{1},提示信息:{2}", syncResult, outOrderId, msg)); } catch (Exception ex) { Tolog("efast订单同步异常:" + ex.Message); } } #endregion #region 驿氪同步 if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, bllCommRelation.WebsiteOwner, "")) { try { Tolog("开始同步驿氪"); //同步成功订单到驿氪 //UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID); //if ((!string.IsNullOrEmpty(orderUserInfo.Ex1)) && (!string.IsNullOrEmpty(orderUserInfo.Ex2)) && (!string.IsNullOrEmpty(orderUserInfo.Phone))) //{ // client.BonusUpdate(orderUserInfo.Ex2, -(orderInfo.UseScore), "商城下单使用积分" + orderInfo.UseScore); //} var uploadOrderResult = yikeClient.OrderUpload(orderInfo); Tolog(string.Format("驿氪订单同步结果:{0}", Common.JSONHelper.ObjectToJson(uploadOrderResult))); } catch (Exception ex) { Tolog("驿氪订单同步异常:" + ex.Message); } } #endregion #region 付款加积分 try { bllUser.AddUserScoreDetail(orderInfo.OrderUserID, CommonPlatform.Helper.EnumStringHelper.ToString(ZentCloud.BLLJIMP.Enums.ScoreDefineType.OrderPay), bllMall.WebsiteOwner, null, null); } catch (Exception) { } #endregion #region 消息通知 if (!BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType)) { try { var productName = bllMall.GetOrderDetailsList(orderInfo.OrderID)[0].ProductName; string remark = ""; if (!string.IsNullOrEmpty(orderInfo.OrderMemo)) { remark = string.Format("客户留言:{0}", orderInfo.OrderMemo); } bllWeiXin.SendTemplateMessageToKefu("有新的订单", string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}\\n商品:{4}\\n{5}", orderInfo.OrderID, Math.Round(orderInfo.TotalAmount, 2), orderInfo.Consignee, orderInfo.Phone, productName, remark)); if (orderInfo.OrderType != 4)//付费的活动不发消息 { if (orderInfo.WebsiteOwner != "jikuwifi") { string url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/orderDetail/{1}#/orderDetail/{1}", Request.Url.Host, orderInfo.OrderID); if (orderInfo.IsMain == 1) { url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/orderList#/orderList", Request.Url.Host); } bllWeiXin.SendTemplateMessageNotifyComm(orderUserInfo, "订单已成功支付,我们将尽快发货,请保持手机畅通等待物流送达!", string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}\\n商品:{4}...\\n查看详情", orderInfo.OrderID, Math.Round(orderInfo.TotalAmount, 2), orderInfo.Consignee, orderInfo.Phone, productName), url); } } } catch (Exception) { } } else { try { bllWeiXin.SendTemplateMessageToKefu(orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元\\n预约人:{3}\\n预约人手机:{4}", orderInfo.OrderID, orderInfo.TotalAmount, tProductInfo.PName, orderUserInfo.TrueName, orderUserInfo.Phone)); bllWeiXin.SendTemplateMessageNotifyComm(orderUserInfo, orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元", orderInfo.OrderID, orderInfo.TotalAmount, tProductInfo.PName)); } catch (Exception) { } } #endregion WebsiteInfo websiteInfo = bllMall.Get <WebsiteInfo>(string.Format(" WebsiteOwner='{0}'", orderInfo.WebsiteOwner)); #region 分销相关 try { if (bllMenuPermission.CheckUserAndPmsKey(websiteInfo.WebsiteOwner, BLLPermission.Enums.PermissionSysKey.OnlineDistribution, websiteInfo.WebsiteOwner)) { if (string.IsNullOrWhiteSpace(orderUserInfo.DistributionOwner)) { if (websiteInfo.DistributionRelationBuildMallOrder == 1) { orderUserInfo.DistributionOwner = orderInfo.WebsiteOwner; bllMall.Update(orderUserInfo); } } bllDis.AutoUpdateLevel(orderInfo); bllDis.TransfersEstimate(orderInfo); bllDis.SendMessageToUser(orderInfo); bllDis.UpdateDistributionSaleAmountUp(orderInfo); } } catch (Exception ex) { Tolog("设置分销员异常:" + ex.Message + " 用户id:" + orderUserInfo.UserID); } #endregion #region 宏巍通知 try { if (websiteInfo.IsUnionHongware == 1) { hongWareClient.OrderNotice(orderUserInfo.WXOpenId, orderInfo.OrderID); } } catch (Exception) { } #endregion bllCard.Give(orderInfo.TotalAmount, orderUserInfo); string v1ProductId = Common.ConfigHelper.GetConfigString("YGBV1ProductId"); string v2ProductId = Common.ConfigHelper.GetConfigString("YGBV2ProductId"); string v1CouponId = Common.ConfigHelper.GetConfigString("YGBV1CouponId"); string v2CouponId = Common.ConfigHelper.GetConfigString("YGBV2CouponId"); List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID); foreach (var item in orderDetailList) { item.IsComplete = 1; bllMall.Update(item); #region 购买指定商品发送指定的优惠券 if (!string.IsNullOrEmpty(v1ProductId) && !string.IsNullOrEmpty(v1CouponId) && item.PID == v1ProductId) { bllCard.SendCardCouponsByCurrUserInfo(orderUserInfo, v1CouponId); } if (!string.IsNullOrEmpty(v2ProductId) && !string.IsNullOrEmpty(v2CouponId) && item.PID == v2ProductId) { bllCard.SendCardCouponsByCurrUserInfo(orderUserInfo, v2CouponId); } #endregion } //更新销量 bllMall.UpdateProductSaleCount(orderInfo); Response.Write(successXml); return; } else { Tolog("更改状态false"); Response.Write(failXml); return; } } Tolog("返回信息有误"); Response.Write(failXml); } catch (Exception ex) { Tolog("出错了:" + ex.Message); Response.Write(failXml); } }
public void ProcessRequest(HttpContext context) { WebsiteInfo websiteInfo = bllMall.GetWebsiteInfoModelFromDataBase(); Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(websiteInfo.WebsiteOwner); Open.HongWareSDK.MemberInfo hongWeiWareMemberInfo = null; if (websiteInfo.IsUnionHongware == 1) { hongWeiWareMemberInfo = hongWareClient.GetMemberInfo(CurrentUserInfo.WXOpenId); if (hongWeiWareMemberInfo.member == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "您尚未绑定宏巍账号,请先绑定"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } string data = context.Request["data"]; if (string.IsNullOrEmpty(data)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "data 参数必传"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } decimal productFee = 0; //商品总价格 不包含邮费 OrderModel orderRequestModel; //订单模型 try { orderRequestModel = ZentCloud.Common.JSONHelper.JsonToModel <OrderModel>(data); } catch (Exception ex) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "JSON格式错误,请检查。错误信息:" + ex.Message; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderRequestModel.order_id)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "order_id 必传"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } WXMallOrderInfo parentOrderInfo = bllMall.GetOrderInfo(orderRequestModel.order_id);//父订单 if (parentOrderInfo == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "订单不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (parentOrderInfo.OrderUserID == CurrentUserInfo.UserID) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "团长不可以参加"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (parentOrderInfo.OrderType != 2) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "不是拼团订单"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (!string.IsNullOrEmpty(parentOrderInfo.GroupBuyParentOrderId)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "订单无效"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (parentOrderInfo.PaymentStatus == 0) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "团长订单未付款"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And GroupBuyParentOrderId='{0}' Or OrderId='{0}'", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "团购人数已满"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (bllMall.GetCount <WXMallOrderInfo>(string.Format("GroupBuyParentOrderId='{0}' And OrderUserId='{1}' And PaymentStatus=0", parentOrderInfo.OrderID, CurrentUserInfo.UserID)) > 0) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "您还有未支付的订单,请先支付"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (DateTime.Now >= (((DateTime)parentOrderInfo.PayTime).AddDays(parentOrderInfo.ExpireDay))) { parentOrderInfo.GroupBuyStatus = "2"; bllMall.Update(parentOrderInfo); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "拼团已过期"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 分销关系建立 if (websiteInfo.DistributionRelationBuildMallOrder == 1) { UserInfo orderUserInfo = bllUser.GetUserInfo(parentOrderInfo.OrderUserID, parentOrderInfo.WebsiteOwner); if (bllUser.IsDistributionMember(orderUserInfo)) { if (string.IsNullOrEmpty(CurrentUserInfo.DistributionOwner)) { var setUserDistributionOwnerResult = bllDis.SetUserDistributionOwner(CurrentUserInfo.UserID, orderUserInfo.UserID, CurrentUserInfo.WebsiteOwner); if (setUserDistributionOwnerResult) { CurrentUserInfo.DistributionOwner = orderUserInfo.UserID; CurrentUserInfo.Channel = orderUserInfo.Channel; } } } } #endregion WXMallOrderInfo orderInfo = new WXMallOrderInfo();//订单表 orderInfo.Address = orderRequestModel.receiver_address; orderInfo.Consignee = orderRequestModel.receiver_name; orderInfo.InsertDate = DateTime.Now; orderInfo.OrderUserID = CurrentUserInfo.UserID; orderInfo.Phone = orderRequestModel.receiver_phone; orderInfo.WebsiteOwner = bllMall.WebsiteOwner; orderInfo.Transport_Fee = 0; orderInfo.OrderID = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder); if (bllMall.WebsiteOwner != "mixblu") { orderInfo.OutOrderId = orderInfo.OrderID; } orderInfo.OrderMemo = orderRequestModel.buyer_memo; orderInfo.ReceiverProvince = orderRequestModel.receiver_province; orderInfo.ReceiverProvinceCode = orderRequestModel.receiver_province_code.ToString(); orderInfo.ReceiverCity = orderRequestModel.receiver_city; orderInfo.ReceiverCityCode = orderRequestModel.receiver_city_code.ToString(); orderInfo.ReceiverDist = orderRequestModel.receiver_dist; orderInfo.ReceiverDistCode = orderRequestModel.receiver_dist_code.ToString(); orderInfo.ZipCode = orderRequestModel.receiver_zip; orderInfo.Status = "待付款"; orderInfo.OrderType = 2; orderInfo.GroupBuyParentOrderId = parentOrderInfo.OrderID; orderInfo.MyCouponCardId = orderRequestModel.cardcoupon_id.ToString(); orderInfo.UseScore = orderRequestModel.use_score; orderInfo.UseAmount = orderRequestModel.use_amount; orderInfo.LastUpdateTime = DateTime.Now; if (orderRequestModel.pay_type == "WEIXIN")//微信支付 { orderInfo.PaymentType = 2; } else if (orderRequestModel.pay_type == "ALIPAY")//支付宝支付 { orderInfo.PaymentType = 1; } #region 格式检查 if (string.IsNullOrEmpty(orderInfo.Consignee)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "收货人姓名不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.Phone)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "收货人联系电话不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverProvince)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "省份名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverProvinceCode)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "省份代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverCity)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "城市名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverCityCode)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "城市代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverDist)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "城市区域名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverCityCode)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "城市区域代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.Address)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "收货地址不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //相关检查 #endregion #region 商品检查 订单详情生成 var needUseScore = 0; //必须使用的积分 decimal needUseCash = 0; //必须使用的现金 var parentOrderDetailList = bllMall.GetOrderDetailsList(parentOrderInfo.OrderID); //先检查库存 ProductSku productSku = bllMall.GetProductSku((int)parentOrderDetailList[0].SkuId); if (productSku == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "SKU不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); string cardCouponType = "";//优惠券类型 #region 检查优惠券是否可用 if (orderRequestModel.cardcoupon_id > 0) { var mycardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, CurrentUserInfo.UserID); if (mycardCoupon == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "无效的优惠券"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } var cardCoupon = bllCardCoupon.GetCardCoupon(mycardCoupon.CardId); if (cardCoupon == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "无效的优惠券"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } cardCouponType = cardCoupon.CardCouponType; #region 需要购买指定商品 if ((!string.IsNullOrEmpty(cardCoupon.Ex2)) && (cardCoupon.Ex2 != "0")) { if (productInfo.PID != cardCoupon.Ex2) { var productInfoCard = bllMall.GetProduct(cardCoupon.Ex2); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("此优惠券需要购买{0}时才可以使用", productInfoCard.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion #region 需要购买指定标签商品 if (!string.IsNullOrEmpty(cardCoupon.Ex8)) { if (string.IsNullOrEmpty(productInfo.Tags))//全部商品都没有标签 { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("使用此优惠券需要购买标签为{0}的商品", cardCoupon.Ex8); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } bool checkResult = true; if (!string.IsNullOrEmpty(productInfo.Tags)) { bool tempResult = false; foreach (string tag in productInfo.Tags.Split(',')) { if (cardCoupon.Ex8.Contains(tag)) { tempResult = true; break; } } if (!tempResult) { checkResult = false; } } else//商品不包含标签 { checkResult = false; } if (!checkResult) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("使用此优惠券需要购买标签为{0}的商品", cardCoupon.Ex8); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion } #endregion if (productInfo.IsOnSale == "0") { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}已下架", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (productSku.Stock < 1) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}{1}库存余量为{2},库存不足", productInfo.PName, bllMall.GetProductShowProperties(productSku.SkuId), productSku.Stock); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (productInfo.Score > 0)//必须使用的积分 { needUseScore = productInfo.Score; } if (productInfo.IsCashPayOnly == 1) //必须使用的现金 { needUseCash = Math.Round((decimal)(productSku.Price * (decimal)(parentOrderInfo.MemberDiscount / 10)), 2); //四舍五入 } WXMallOrderDetailsInfo detailModel = new WXMallOrderDetailsInfo(); detailModel.OrderID = orderInfo.OrderID; detailModel.PID = productInfo.PID; detailModel.TotalCount = 1; detailModel.OrderPrice = Math.Round((decimal)(productSku.Price * (decimal)(parentOrderInfo.MemberDiscount / 10)), 2);//四舍五入 detailModel.ProductName = productInfo.PName; detailModel.SkuId = productSku.SkuId; detailModel.SkuShowProp = bllMall.GetProductShowProperties(productSku.SkuId); detailModel.IsComplete = 1;//拼团的只要下单就算销量 #endregion #region 纯积分购买 if (needUseScore > 0) { if ((CurrentUserInfo.TotalScore < needUseScore) || (orderRequestModel.use_score < needUseScore)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("您需要使用{0}积分来兑换, 可用积分不足", needUseScore); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion productFee = (decimal)detailModel.OrderPrice; //物流费用 #region 运费计算 List <SkuModel> skus = new List <SkuModel>(); skus.Add(new SkuModel { sku_id = productSku.SkuId, count = 1 }); FreightModel freightModel = new FreightModel(); freightModel.receiver_province_code = orderRequestModel.receiver_province_code; freightModel.receiver_city_code = orderRequestModel.receiver_city_code; freightModel.receiver_dist_code = orderRequestModel.receiver_dist_code; freightModel.skus = skus; decimal freight = 0;//运费 string freightMsg = ""; if (!bllMall.CalcFreight(freightModel, out freight, out freightMsg)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = freightMsg; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } orderInfo.Transport_Fee = freight; #endregion #region 优惠券计算 decimal discountAmount = 0;//优惠金额 bool canUseCardCoupon = false; string msg = ""; if (orderRequestModel.cardcoupon_id > 0)//有优惠券 { discountAmount = bllMall.CalcDiscountAmount(orderRequestModel.cardcoupon_id.ToString(), data, CurrentUserInfo.UserID, out canUseCardCoupon, out msg); if (!canUseCardCoupon) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = msg; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (cardCouponType == "MallCardCoupon_FreeFreight")//免邮券 { orderInfo.Transport_Fee = 0; } } //优惠券计算 #endregion #region 积分计算 decimal scoreExchangeAmount = 0;///积分抵扣的金额 //积分计算 if (orderRequestModel.use_score > 0) { #region 使用宏巍积分 if (websiteInfo.IsUnionHongware == 1) { CurrentUserInfo.TotalScore = hongWeiWareMemberInfo.member.point; } #endregion orderInfo.UseScore = orderRequestModel.use_score; if (CurrentUserInfo.TotalScore < orderRequestModel.use_score) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "积分不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } ScoreConfig scoreConfig = bllScore.GetScoreConfig(); if (scoreConfig != null && scoreConfig.ExchangeAmount > 0) { scoreExchangeAmount = Math.Round(orderRequestModel.use_score / (scoreConfig.ExchangeScore / scoreConfig.ExchangeAmount), 2); } //scoreExchangeAmount = Math.Round(orderRequestModel.use_score / (scoreConfig.ExchangeScore / scoreConfig.ExchangeAmount), 2); } //积分计算 #endregion #region 使用账户余额 if (orderRequestModel.use_amount > 0) { if (!bllMall.IsEnableAccountAmountPay()) { apiResp.msg = "尚未启用余额支付功能"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 使用宏巍余额 if (websiteInfo.IsUnionHongware == 1) { CurrentUserInfo.AccountAmount = (decimal)hongWeiWareMemberInfo.member.balance; } #endregion if (CurrentUserInfo.AccountAmount < orderRequestModel.use_amount) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "您的账户余额不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion //合计计算 orderInfo.Product_Fee = productFee; orderInfo.TotalAmount = orderInfo.Product_Fee + orderInfo.Transport_Fee; orderInfo.TotalAmount -= discountAmount; //优惠券优惠金额 orderInfo.TotalAmount -= scoreExchangeAmount; //积分优惠金额 orderInfo.TotalAmount -= orderRequestModel.use_amount; //余额 orderInfo.PayableAmount = orderInfo.TotalAmount - freight; //应付金额 orderInfo.HeadDiscount = parentOrderInfo.HeadDiscount; orderInfo.MemberDiscount = parentOrderInfo.MemberDiscount; orderInfo.PeopleCount = parentOrderInfo.PeopleCount; orderInfo.ExpireDay = parentOrderInfo.ExpireDay; orderInfo.GroupBuyParentOrderId = parentOrderInfo.OrderID; orderInfo.ScoreExchangAmount = scoreExchangeAmount; //优惠券抵扣金额 orderInfo.CardcouponDisAmount = discountAmount; //卡券抵扣金额 if (orderInfo.TotalAmount <= 0) { orderInfo.TotalAmount = 0; orderInfo.PaymentStatus = 1; orderInfo.PayTime = DateTime.Now; orderInfo.Status = "待发货"; } if (orderInfo.TotalAmount < needUseCash) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("最少需要支付{0}元" + needUseCash); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { if (!this.bllMall.Add(orderInfo, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 更新优惠券使用状态 //优惠券 if (orderRequestModel.cardcoupon_id > 0 && (canUseCardCoupon == true))//有优惠券且已经成功使用 { MyCardCoupons myCardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, CurrentUserInfo.UserID); myCardCoupon.UseDate = DateTime.Now; myCardCoupon.Status = 1; if (!bllCardCoupon.Update(myCardCoupon, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新优惠券状态失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } //优惠券 #endregion #region 积分抵扣 //积分扣除 if (orderRequestModel.use_score > 0) { CurrentUserInfo.TotalScore -= orderRequestModel.use_score; if (bllMall.Update(CurrentUserInfo, string.Format(" TotalScore-={0}", orderRequestModel.use_score), string.Format(" AutoID={0}", CurrentUserInfo.AutoID), tran) < 0) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新用户积分失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //积分记录 UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = -orderRequestModel.use_score; scoreRecord.TotalScore = CurrentUserInfo.TotalScore; scoreRecord.ScoreType = "OrderSubmit"; scoreRecord.UserID = CurrentUserInfo.UserID; scoreRecord.AddNote = "微商城-参加团购使用积分"; scoreRecord.WebSiteOwner = CurrentUserInfo.WebsiteOwner; if (!bllMall.Add(scoreRecord, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "插入积分记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 更新宏巍积分 if (websiteInfo.IsUnionHongware == 1) { if (!hongWareClient.UpdateMemberScore(hongWeiWareMemberInfo.member.mobile, CurrentUserInfo.WXOpenId, -orderRequestModel.use_score)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新宏巍积分失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion } //积分扣除 #endregion #region 余额抵扣 if (orderRequestModel.use_amount > 0 && bllMall.IsEnableAccountAmountPay()) { CurrentUserInfo.AccountAmount -= orderRequestModel.use_amount; if (bllMall.Update(CurrentUserInfo, string.Format(" AccountAmount={0}", CurrentUserInfo.AccountAmount), string.Format(" AutoID={0}", CurrentUserInfo.AutoID)) < 0) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新用户余额失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = -(double)orderRequestModel.use_amount; scoreRecord.TotalScore = (double)CurrentUserInfo.AccountAmount; scoreRecord.UserID = CurrentUserInfo.UserID; scoreRecord.AddNote = "拼团-参团使用余额"; scoreRecord.RelationID = orderInfo.OrderID; scoreRecord.WebSiteOwner = bllUser.WebsiteOwner; scoreRecord.ScoreType = "AccountAmount"; if (!bllMall.Add(scoreRecord)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "插入余额记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } UserCreditAcountDetails record = new UserCreditAcountDetails(); record.WebsiteOwner = bllUser.WebsiteOwner; record.Operator = CurrentUserInfo.UserID; record.UserID = CurrentUserInfo.UserID; record.CreditAcount = -orderRequestModel.use_amount; record.SysType = "AccountAmount"; record.AddTime = DateTime.Now; record.AddNote = "账户余额变动-" + orderRequestModel.use_amount; if (!bllMall.Add(record)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "插入余额记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 更新宏巍余额 if (websiteInfo.IsUnionHongware == 1) { if (!hongWareClient.UpdateMemberBlance(hongWeiWareMemberInfo.member.mobile, CurrentUserInfo.WXOpenId, -(float)orderRequestModel.use_amount)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新宏巍余额失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion } #endregion #region 插入订单详情表及更新库存 if (!this.bllMall.Add(detailModel, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //更新 SKU库存 System.Text.StringBuilder sbUpdateStock = new StringBuilder();//更新库存sql sbUpdateStock.AppendFormat(" Update ZCJ_ProductSku Set Stock-={0} ", 1); sbUpdateStock.AppendFormat(" Where SkuId={0} And Stock>0 ", productSku.SkuId); if (ZentCloud.ZCBLLEngine.BLLBase.ExecuteSql(sbUpdateStock.ToString(), tran) <= 0) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交订单失败,库存不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #endregion tran.Commit();//提交订单事务 #region 宏巍通知 if (websiteInfo.IsUnionHongware == 1) { hongWareClient.OrderNotice(CurrentUserInfo.WXOpenId, orderInfo.OrderID); } #endregion try { //团购完成取消其它未付款订单 if (parentOrderInfo.Ex10 == "1") { if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And (GroupBuyParentOrderId='{0}')", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount) { bllMall.Update(new WXMallOrderInfo(), string.Format("Status='已取消'"), string.Format(" GroupBuyParentOrderId='{0}' And PaymentStatus=0", parentOrderInfo.OrderID)); parentOrderInfo.GroupBuyStatus = "1"; bllMall.Update(parentOrderInfo); } } else { if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And (GroupBuyParentOrderId='{0}' Or OrderId='{0}')", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount) { bllMall.Update(new WXMallOrderInfo(), string.Format("Status='已取消'"), string.Format(" GroupBuyParentOrderId='{0}' And PaymentStatus=0", parentOrderInfo.OrderID)); parentOrderInfo.GroupBuyStatus = "1"; bllMall.Update(parentOrderInfo); } } #region 微信模板消息 string title = "订单已成功提交"; if (orderInfo.TotalAmount > 0) { title += ",请尽快付款"; } bllWeiXin.SendTemplateMessageNotifyComm(CurrentUserInfo, title, string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}", orderInfo.OrderID, orderInfo.TotalAmount, orderInfo.Consignee, orderInfo.Phone)); #endregion } catch { } } catch (Exception ex) { //回滚事物 tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交订单失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } apiResp.status = true; apiResp.msg = "ok"; apiResp.result = new { order_id = orderInfo.OrderID }; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); }
public void ProcessRequest(HttpContext context) { string data = context.Request["data"]; OrderModel orderRequestModel;//订单模型 try { orderRequestModel = JSONHelper.JsonToModel <OrderModel>(data); } catch (Exception ex) { apiResp.msg = "提交格式错误"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } WXMallProductInfo productInfo = bllMall.GetProduct(orderRequestModel.product_id.ToString()); if (productInfo == null) { apiResp.msg = "记录没有找到"; apiResp.code = (int)APIErrCode.IsNotFound; bllMall.ContextResponse(context, apiResp); return; } WXMallOrderInfo orderInfo = new WXMallOrderInfo();//订单表 orderInfo.ArticleCategoryType = productInfo.ArticleCategoryType; orderInfo.InsertDate = DateTime.Now; orderInfo.OrderUserID = CurrentUserInfo.UserID; orderInfo.WebsiteOwner = bllMall.WebsiteOwner; orderInfo.OrderMemo = orderRequestModel.buyer_memo; orderInfo.UseAmount = orderRequestModel.use_amount; if (orderRequestModel.receiver_id == 0) { orderInfo.Consignee = CurrentUserInfo.TrueName; orderInfo.Phone = CurrentUserInfo.Phone; } else { WXConsigneeAddress nUserAddress = bllMall.GetByKey <WXConsigneeAddress>("AutoID", orderRequestModel.receiver_id.ToString()); orderInfo.Consignee = nUserAddress.ConsigneeName; orderInfo.Phone = nUserAddress.Phone; orderInfo.Address = nUserAddress.Address; orderInfo.ZipCode = nUserAddress.ZipCode; orderInfo.ReceiverProvince = nUserAddress.Province; orderInfo.ReceiverProvinceCode = nUserAddress.ProvinceCode; orderInfo.ReceiverCity = nUserAddress.City; orderInfo.ReceiverCityCode = nUserAddress.CityCode; orderInfo.ReceiverDist = nUserAddress.Dist; orderInfo.ReceiverDistCode = nUserAddress.DistCode; } orderInfo.Transport_Fee = 0; orderInfo.Status = "待付款"; if (orderRequestModel.pay_type == "WEIXIN")//微信支付 { orderInfo.PaymentType = 2; } else if (orderRequestModel.pay_type == "ALIPAY")//支付宝支付 { orderInfo.PaymentType = 1; } if (orderRequestModel.skus == null || orderRequestModel.skus.Count == 0) { apiResp.msg = "Skus不能为空"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } #region 商品检查 订单详情生成 //订单详情 List <WXMallOrderDetailsInfo> detailList = new List <WXMallOrderDetailsInfo>(); //主商品订单明细 List <WXMallOrderDetailsInfo> detailAddedList = new List <WXMallOrderDetailsInfo>(); //增值服务订单明细 orderRequestModel.skus = orderRequestModel.skus.Distinct().ToList(); #region 购买的商品 foreach (var sku in orderRequestModel.skus) { ProductSku productSku = bllMall.GetProductSku(sku.sku_id); WXMallOrderDetailsInfo detailModel = new WXMallOrderDetailsInfo(); detailModel.TotalCount = sku.count; detailModel.OrderPrice = bllMall.GetSkuPrice(productSku); detailModel.SkuId = productSku.SkuId; detailModel.ArticleCategoryType = productSku.ArticleCategoryType; if (productSku.ArticleCategoryType.Contains("Added")) { WXMallProductInfo rproductInfo = bllMall.GetProduct(productSku.ProductId.ToString()); detailModel.PID = rproductInfo.PID; detailModel.ProductName = rproductInfo.PName; detailModel.Unit = rproductInfo.Unit; detailAddedList.Add(detailModel); } else { detailModel.PID = productInfo.PID; detailModel.ProductName = productInfo.PName; detailModel.StartDate = sku.start_date; detailModel.EndDate = sku.end_date; detailModel.Unit = productInfo.Unit; detailList.Add(detailModel); } } #endregion if (detailList.Count == 0) { apiResp.msg = "请选择预约时间"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } //已有订单详情 List <WXMallOrderDetailsInfo> oDetailList = bllMall.GetOrderDetailsList(null, productInfo.PID, productInfo.ArticleCategoryType, detailList.Min(p => p.StartDate), detailList.Max(p => p.EndDate)); List <string> hasOrderID_List = new List <string>(); string hasOrderIDs = ""; int maxCount = productInfo.Stock; foreach (var item in detailList) { List <WXMallOrderDetailsInfo> hasOrderDetailList = oDetailList.Where(p => !((item.StartDate >= p.EndDate && item.EndDate > p.EndDate) || (item.StartDate < p.StartDate && item.EndDate <= p.StartDate))).ToList(); if (hasOrderDetailList.Count >= maxCount) { hasOrderID_List.AddRange(hasOrderDetailList.Select(p => p.OrderID).Distinct()); } } if (hasOrderID_List.Count > 0) { hasOrderID_List = hasOrderID_List.Distinct().ToList(); hasOrderIDs = MyStringHelper.ListToStr(hasOrderID_List, "'", ","); int tempCount = 0; List <WXMallOrderInfo> tempList = bllMall.GetOrderList(0, 1, "", out tempCount, "预约成功", null, null, null, null, null, null, null, null, null, null, orderInfo.ArticleCategoryType, hasOrderIDs); if (tempCount >= maxCount) { apiResp.msg = "所选时间已有成功的预约"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } } //增值服务合并到主订单明细列表 detailList.AddRange(detailAddedList); //合计计算 orderInfo.Product_Fee = detailList.Sum(p => p.OrderPrice * p.TotalCount).Value; #region 积分计算 decimal scoreExchangeAmount = 0;//积分抵扣的金额 //积分计算 if (orderRequestModel.use_score > 0 && orderInfo.Product_Fee > 0) { orderInfo.UseScore = orderRequestModel.use_score; if (CurrentUserInfo.TotalScore < orderRequestModel.use_score) { apiResp.msg = "积分不足"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } ScoreConfig scoreConfig = bllScore.GetScoreConfig(); scoreExchangeAmount = Math.Round(orderRequestModel.use_score / (scoreConfig.ExchangeScore / scoreConfig.ExchangeAmount), 2); } //积分计算 #endregion #region 使用账户余额 if (orderRequestModel.use_amount > 0) { if (!bllMall.IsEnableAccountAmountPay()) { apiResp.msg = "未开启余额支付"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } if (CurrentUserInfo.AccountAmount < orderRequestModel.use_amount) { apiResp.msg = "您的账户余额不足"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } } #endregion orderInfo.TotalAmount = orderInfo.Product_Fee + orderInfo.Transport_Fee; orderInfo.TotalAmount -= scoreExchangeAmount; //积分优惠金额 orderInfo.TotalAmount -= orderRequestModel.use_amount; //余额抵扣金额 orderInfo.PayableAmount = orderInfo.TotalAmount - orderInfo.Transport_Fee; //应付金额 if ((orderInfo.Product_Fee + orderInfo.Transport_Fee - scoreExchangeAmount) < orderInfo.TotalAmount) { apiResp.msg = "积分兑换金额不能大于订单总金额,请减少积分兑换"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } if (orderInfo.TotalAmount < 0) { orderInfo.TotalAmount = 0; } if (orderInfo.TotalAmount == 0 && orderInfo.UseScore == 0) { orderInfo.Status = "待审核"; } else if (orderInfo.TotalAmount == 0 && (orderInfo.UseAmount > 0 || orderInfo.UseScore > 0)) { orderInfo.PaymentStatus = 1; orderInfo.PayTime = DateTime.Now; orderInfo.Status = "预约成功"; } #endregion //生成订单ID orderInfo.OrderID = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder); BLLTransaction tran = new BLLTransaction(); if (!this.bllMall.Add(orderInfo, tran)) { tran.Rollback(); apiResp.msg = "提交失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } foreach (var item in detailList) { item.OrderID = orderInfo.OrderID; if (!this.bllMall.Add(item, tran)) { tran.Rollback(); apiResp.msg = "提交失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } } #region 积分抵扣 //积分扣除 if (orderRequestModel.use_score > 0) { CurrentUserInfo.TotalScore -= orderRequestModel.use_score; if (bllMall.Update(CurrentUserInfo, string.Format(" TotalScore-={0}", orderRequestModel.use_score), string.Format(" AutoID={0}", CurrentUserInfo.AutoID) , tran) < 0) { tran.Rollback(); apiResp.msg = "更新用户积分失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } //积分记录 UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = -orderRequestModel.use_score; scoreRecord.TotalScore = CurrentUserInfo.TotalScore; scoreRecord.ScoreType = "OrderSubmit"; scoreRecord.UserID = CurrentUserInfo.UserID; scoreRecord.AddNote = "预约-下单使用积分"; scoreRecord.RelationID = orderInfo.OrderID; scoreRecord.WebSiteOwner = CurrentUserInfo.WebsiteOwner; if (!bllMall.Add(scoreRecord)) { tran.Rollback(); apiResp.msg = "插入积分记录失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } } //积分扣除 #endregion #region 余额抵扣 if (orderRequestModel.use_amount > 0 && bllMall.IsEnableAccountAmountPay()) { CurrentUserInfo.AccountAmount -= orderRequestModel.use_amount; if (bllMall.Update(CurrentUserInfo, string.Format(" AccountAmount={0}", CurrentUserInfo.AccountAmount), string.Format(" AutoID={0}", CurrentUserInfo.AutoID)) < 0) { tran.Rollback(); apiResp.msg = "更新用户余额失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = -(double)orderRequestModel.use_amount; scoreRecord.TotalScore = (double)CurrentUserInfo.AccountAmount; scoreRecord.UserID = CurrentUserInfo.UserID; scoreRecord.AddNote = "账户余额变动-下单使用余额"; scoreRecord.RelationID = orderInfo.OrderID; scoreRecord.WebSiteOwner = bllMall.WebsiteOwner; scoreRecord.ScoreType = "AccountAmount"; if (!bllMall.Add(scoreRecord)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "插入余额记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } UserCreditAcountDetails record = new UserCreditAcountDetails(); record.WebsiteOwner = bllMall.WebsiteOwner; record.Operator = CurrentUserInfo.UserID; record.UserID = CurrentUserInfo.UserID; record.CreditAcount = -orderRequestModel.use_amount; record.SysType = "AccountAmount"; record.AddTime = DateTime.Now; record.AddNote = "账户余额变动-" + orderRequestModel.use_amount; if (!bllMall.Add(record)) { tran.Rollback(); apiResp.msg = "插入余额记录失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } } #endregion tran.Commit();//提交订单事务 if (orderInfo.Status == "预约成功") { int tempCount = 0; if (string.IsNullOrWhiteSpace(hasOrderIDs)) { hasOrderIDs = "'0'"; } List <WXMallOrderInfo> tempList = bllMall.GetOrderList(0, 1, "", out tempCount, "预约成功", null, null, null, null, null, null, null, null, null, null, orderInfo.ArticleCategoryType, hasOrderIDs); tempCount = tempCount + 1; //加上当前订单的数量 if (tempCount >= maxCount) { tempList = bllMall.GetColOrderListInStatus("'待付款','待审核'", hasOrderIDs, "OrderID,OrderUserID,UseScore", bllMall.WebsiteOwner); if (tempList.Count > 0) { string stopOrderIds = MyStringHelper.ListToStr(tempList.Select(p => p.OrderID).ToList(), "'", ","); tempList = tempList.Where(p => p.UseScore > 0).ToList(); foreach (var item in tempList) { UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, bllMall.WebsiteOwner);//下单用户信息 if (orderUserInfo == null) { continue; } orderUserInfo.TotalScore += item.UseScore; if (bllMall.Update(orderUserInfo, string.Format(" TotalScore+={0}", item.UseScore), string.Format(" UserID='{0}'", item.OrderUserID)) > 0) { UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = item.UseScore; scoreRecord.TotalScore = orderUserInfo.TotalScore; scoreRecord.ScoreType = "OrderCancel"; scoreRecord.UserID = item.OrderUserID; scoreRecord.RelationID = item.OrderID; scoreRecord.AddNote = "预约-订单失败返还积分"; scoreRecord.WebSiteOwner = item.WebsiteOwner; bllMall.Add(scoreRecord); } } bllMall.Update(new WXMallOrderInfo(), string.Format("Status='{0}'", "预约失败"), string.Format("OrderID In ({0}) and WebsiteOwner='{1}'", stopOrderIds, bllMall.WebsiteOwner)); } } } //预约通知 bllWeiXin.SendTemplateMessageNotifyComm(CurrentUserInfo, orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元", orderInfo.OrderID, orderInfo.TotalAmount, productInfo.PName)); apiResp.result = new { order_id = orderInfo.OrderID }; apiResp.msg = "提交完成"; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.status = true; bllMall.ContextResponse(context, apiResp); }
/// <summary> /// 添加预约 /// </summary> /// <param name="context"></param> /// <returns></returns> private string AddOrder(HttpContext context) { try { string id = context.Request["id"]; //多个医生id string[] ids = new string[] { }; //多个医生id if (!string.IsNullOrEmpty(id)) { id = id.TrimStart(',').TrimEnd(','); ids = id.Split(','); } if (ids.Length >= 1)//检查是否可以预约 { foreach (var item in ids) { WXMallProductInfo productInfoCheck = bllMall.GetProduct(item); if (productInfoCheck != null) { if (productInfoCheck.Stock <= 0) { apiResp.msg = string.Format("专家{0}的预约已满", productInfoCheck.PName); return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } } } } WXMallProductInfo productInfo = new WXMallProductInfo(); WXMallOrderInfo orderInfo = bllMall.ConvertRequestToModel <WXMallOrderInfo>(new WXMallOrderInfo()); if (string.IsNullOrEmpty(orderInfo.Consignee)) { apiResp.msg = "请填写姓名"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (string.IsNullOrEmpty(orderInfo.Ex1)) { apiResp.msg = "请填写年龄"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (string.IsNullOrEmpty(orderInfo.Ex2)) { apiResp.msg = "请选择性别"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (string.IsNullOrEmpty(orderInfo.Phone)) { apiResp.msg = "请填写手机号"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (!Common.MyRegex.PhoneNumLogicJudge(orderInfo.Phone)) { apiResp.msg = "请输入正确手机号"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } StringBuilder sbWhere = new StringBuilder(); sbWhere.AppendFormat(" WebsiteOwner='{0}' And TableName ='ZCJ_WXMallOrderInfo' Order by Sort DESC", bllMall.WebsiteOwner); var fieldList = bllMall.GetList <TableFieldMapping>(sbWhere.ToString()); if (fieldList != null && fieldList.Count > 0) { Type type = orderInfo.GetType(); fieldList = fieldList.Where(p => p.FieldIsNull == 0).ToList(); foreach (var field in fieldList) { System.Reflection.PropertyInfo propertyInfo = type.GetProperty(field.Field); //获取指定名称的属性 var value = propertyInfo.GetValue(orderInfo, null); //获取属性值 if (value == null || string.IsNullOrEmpty(value.ToString())) { switch (field.FieldType) { case "text": apiResp.msg = "请填写 " + field.MappingName; break; case "combox": //下拉框 apiResp.msg = "请选择 " + field.MappingName; break; case "checkbox": //下拉框 apiResp.msg = "请选择 " + field.MappingName; break; default: break; } return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } } } orderInfo.OrderID = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder); orderInfo.WebsiteOwner = bllMall.WebsiteOwner; orderInfo.InsertDate = DateTime.Now; orderInfo.OrderUserID = "defualt"; orderInfo.Status = "未确认"; if (bllMall.IsLogin) { orderInfo.OrderUserID = bllUser.GetCurrUserID(); } if (!string.IsNullOrEmpty(orderInfo.Ex6))//科系 { //推荐 int categoryId; if (int.TryParse(orderInfo.Ex6, out categoryId)) { WXMallCategory category = bllMall.Get <WXMallCategory>(string.Format(" AutoId={0}", categoryId)); if (category != null) { orderInfo.Ex6 = category.CategoryName; } } } else { //正常预约 if (ids.Length == 1) { productInfo = bllMall.GetProduct(ids[0]); if (productInfo != null) { if (!string.IsNullOrEmpty(productInfo.CategoryId)) { WXMallCategory category = bllMall.Get <WXMallCategory>(string.Format(" AutoId={0}", productInfo.CategoryId)); if (category != null) { orderInfo.Ex6 = category.CategoryName; } } } } } if (!string.IsNullOrEmpty(orderInfo.Ex5))//医生 名字或多个Id { orderInfo.Ex5 = orderInfo.Ex5.TrimStart(',').TrimEnd(','); string names = ""; foreach (var item in orderInfo.Ex5.Split(',')) { int pId; if (int.TryParse(item, out pId)) { productInfo = bllMall.GetProduct(pId.ToString()); if (productInfo != null) { names += productInfo.PName + ","; if (productInfo.Stock <= 0) { apiResp.msg = string.Format("专家{0}的预约已满", productInfo.PName); return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } } } } if (orderInfo.Ex5.Split(',').Length >= 1 && (!string.IsNullOrEmpty(names))) { orderInfo.Ex5 = names.TrimEnd(','); } } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); if (!bllMall.Add(orderInfo, tran)) { apiResp.msg = "操作失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (ids.Length > 0) { if (bllMall.Update(productInfo, string.Format("Stock-=1,SaleCount+=1"), string.Format("PID in({0})", id)) < ids.Length) { tran.Rollback(); apiResp.msg = "操作失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } } tran.Commit(); apiResp.status = true; bllWeixin.SendTemplateMessageToKefu("有新的预约", string.Format("姓名:{0}\\n手机:{1}", orderInfo.Consignee, orderInfo.Phone)); } catch (Exception ex) { apiResp.msg = ex.Message; } return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); }
public virtual void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; context.Response.Expires = 0; string keyWord = context.Request["KeyWord"]; string fromDate = context.Request["FromDate"]; string toDate = context.Request["ToDate"]; string type = context.Request["type"]; string status = context.Request["status"]; string orderType = context.Request["orderType"]; StringBuilder sbSql = new StringBuilder(); sbSql.AppendFormat("Select (Case When OrderType =5 Then '预约' When OrderType=6 Then '推荐' When OrderType=7 Then '预约' When OrderType=8 Then '推荐' Else '' End) as 类型,"); sbSql.AppendFormat(" Status as 确认状态,"); sbSql.AppendFormat(" Consignee as 姓名,"); sbSql.AppendFormat(" Phone as 手机号,"); sbSql.AppendFormat(" Ex1 as 年龄,"); sbSql.AppendFormat(" Ex2 as 性别,"); sbSql.AppendFormat(" Ex3 as 症状描述,"); sbSql.AppendFormat(" Ex5 as 专家,"); sbSql.AppendFormat(" '' as 身份,"); sbSql.AppendFormat(" Ex6 as 科室,"); sbSql.AppendFormat(" InsertDate as 提交时间 "); var fieldList = bllMall.GetList <TableFieldMapping>(string.Format("WebsiteOwner='{0}' And TableName ='ZCJ_WXMallOrderInfo' Order by Sort DESC", bllMall.WebsiteOwner)); if (fieldList.Count > 0) { for (int i = 0; i < fieldList.Count; i++) { sbSql.AppendFormat(" ,{0} as {1}", fieldList[i].Field, fieldList[i].MappingName); } } sbSql.AppendFormat(" from ZCJ_WXMallOrderInfo Where WebsiteOwner='{0}' ", bllMall.WebsiteOwner); if (string.IsNullOrEmpty(orderType)) { sbSql.AppendFormat(" And OrderType in(5,6)", type); } else { sbSql.AppendFormat(" And OrderType in(7,8)", type); } if (!string.IsNullOrEmpty(type)) { sbSql.AppendFormat("And OrderType={0}", type); } if (!string.IsNullOrEmpty(status)) { sbSql.AppendFormat("And Status='{0}'", status); } if (!string.IsNullOrEmpty(keyWord)) { sbSql.AppendFormat("And ( Consignee like'%{0}%' Or Ex5 like'%{0}%' Or Ex6 like'%{0}%')", keyWord); } if ((!string.IsNullOrEmpty(fromDate)))//大于开始时间 { sbSql.AppendFormat("And InsertDate>='{0}'", Convert.ToDateTime(fromDate)); } if ((!string.IsNullOrEmpty(toDate)))//小于结束时间 { sbSql.AppendFormat("And InsertDate<'{0}'", Convert.ToDateTime(toDate).AddDays(1)); } sbSql.AppendFormat(" Order By InsertDate DESC"); var dataTable = ZentCloud.ZCBLLEngine.BLLBase.Query(sbSql.ToString()).Tables[0]; foreach (System.Data.DataRow item in dataTable.Rows) { try { if (!string.IsNullOrEmpty(item["专家"].ToString())) { string result = ""; var doctorNameList = item["专家"].ToString(); foreach (var doctorName in doctorNameList.Split(',')) { WXMallProductInfo doctorInfo = bllMall.Get <WXMallProductInfo>(string.Format(" WebsiteOwner='{0}' And PName='{1}'", bllMall.WebsiteOwner, doctorName)); if (doctorInfo != null) { result += doctorInfo.ExArticleTitle_2 + ","; } } result = result.TrimEnd(','); item["身份"] = result; } } catch (Exception) { continue; } } DataLoadTool.ExportDataTable(dataTable, string.Format("{0}_{1}_data.xls", "预约", DateTime.Now.ToString())); }
public void ProcessRequest(HttpContext context) { try { Tolog("京东支付通知start"); var payConfig = bllPay.GetPayConfig(); byte[] byts = new byte[context.Request.InputStream.Length]; context.Request.InputStream.Read(byts, 0, byts.Length); string req = Encoding.UTF8.GetString(byts); Tolog("通知参数" + req); //var jdPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKE5N2xm3NIrXON8Zj19GNtLZ8xwEQ6uDIyrS3S03UhgBJMkGl4msfq4Xuxv6XUAN7oU1XhV3/xtabr9rXto4Ke3d6WwNbxwXnK5LSgsQc1BhT5NcXHXpGBdt7P8NMez5qGieOKqHGvT0qvjyYnYA29a8Z4wzNR7vAVHp36uD5RwIDAQAB"; //req = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><jdpay><version>V2.0</version><merchant>110226843002</merchant><result><code>000000</code><desc>success</desc></result><encrypt>MDIxZjNkNjI1YjU1NzQ4MWE5N2ExMTg3YjkxNmQ4NzkxYzQyMmFjZjM4YTM1MjZjY2JjNzM1ZDkxY2Q5ZDNmMTMzMGFjYTBkNTI0MzYzNjc3MTVhODI3OWUzZTAxMmY5ODEyOTVmNDNiNWY5MDZhZGJiYTcwYTYyOTFlYzVmYTU2Y2EyN2U1YzhkNzllMGE3ZTUyNDE4NWU4OWMxNjIwNDFkODcyYzJiZDA4ZWY4YWEyMmY5ZWUxNDk3YTg3MTI3YmU1NTMxNjc5NWJiOTlmN2ZmNGU1MTc1YWJhNjNkYjUzYWUwZDQzOTk4ZjIzMjBiYmVkNGJkMDcxOWUzOThjZjU1ODUwNzM4Y2RiNzM2Njc1N2U2ZTcxN2Q0N2ZiYTZmN2M1YzBiYzRmMjc4ZThiZDNhYTkxZTExNzBiYjg2ZDNjNmQ3OWUyZTBlYjUzZWNlZjFjODQ2MzdiN2E5MTQxN2Y3NmRhZmNkNDdiMzMwNjc1MGRhYjhiYzg0NTFkOWNiY2QyMDZhOTJiYzU2YTFiOWEwMjRmNTZhMWZhNTVhNjlmYTA1ZDFlMmI0YTI4MGE1YTU0N2NlMjc3ZWMwM2QyNWE4ODdlOTA0ZGM3YTY2MDViY2I1OTI5MDBlYWU4MGU0Mzc4MmEwOWY3ZjEwZTk5MGZkOGUzYTA4MzNkNGMyZGZkNWM3MDhkOGU4N2NhMmQyZGM1MDgwYzUyOTg3OGNkMzFhZWRkMTE1NDM5ZjExYTM2OGM2OGE4MGZjZTYyMjJkNzlmODcwNGYyNDMzMTYyZThhZTBkODM2ODBjYzg5ZGRjMWY3ZGVmYzQzYjc4MDZiMDNhMTBmZTc2YjI3MThjYjQ0YjQwZDkyY2E3OGUzYmYzZmFlNjBlOTI4OGU1ODVkNjBjMWZiNDBmMjFjNzVmNDkxYmRkYWFlNzQ0YjZkYmU1ODNkOWQ4OGYwN2EyMDViOWQ5MGNjMzViMTE3MDQ4NWVlNTdlN2Y5MTRhZDM3YzFlODY1NDFiZmQyNDg1MzhlZGZiNDNiZWZmZjY3YmE3NWQ5YjI0MzE4ZDMzMDE5NTE3YWM4ZTJiMDZhZWYyM2NhNjMwODc3MDhkNTdkZWI3MWVhMmY2MzA2ZDliZjBmZGFlNzQ3ODgzODg0ZjVhOWFkODIxYWM0NGQ1ZDlmMGRlNDhkMjBiYTJjYmQ4NTlkMmU3NDMxZDExZmRjMzkxMDU3ZmE3NGE0Yzg2OThkMmY0ZWQ1ZjE3MjIwOWQ1ZTBmZGIzZjFhNGYwOTllZWY5YzRiMWYyZDAxZjlhNzhlYWY5ZjU0YmIyZjczNmUxMjJkNWY2NzhlMDFmYjU0YjY3NWRlYTc1ZWZkNmMwNTJhZmY3ZGVhMGM5NjAyMWQwMGQyMjI2NzdhM2RlNDdhMTdkMWI4ZWQxYmEyYWZlZDg1ZjI4NDk2ZmI2MGVjOTc5OTc4MjgzZTEyNzY2ZmI1OWUzZjY1MWI4OTVlMmQ4OGNlNGRhODg0NzJiNTFiN2RmZDc5NzdkNDk4NTY0NGU4ZjBmNGZjMTM3MmUzMGNhMTUwOTFkNDFhODIzMjZiODU0YjMzNmI1N2EwZDVjMjZjOWNjMzBlMjFjZjNkMDA0NjQ4Zjk0NjQzZWRhOTU1MmIyZjJkYzZjNGJmOTU5MDIzNTBlODlmOTNhZDRhYmEyMzZiY2E1OWE4NzY5Mjc0ZTcwN2MyNGFjNGJmOTU5MDIzNTBlODlmNDNlZGE5NTUyYjJmMmRjNjU0MTNlZjYxZTNlODc4MDk3MmNiYjg3NTVjNmU1NWNlZDljNWU0ZDE5ZTRmZjJjZTAxNmJiMGIzYWFlOTdlYTQzYmM5NWVmMGU0ZjUyNzY4NDNlZGE5NTUyYjJmMmRjNmMyOWRiYWZkYTNjYzQ1M2E3ZGJhZWNjZWJmNGIxZmQ5MTMxMmRiMzliOTU2YzBmNmNiODMxMDQ1ZDBiYjM1ZTNmMzlmMGE0ODNiN2M3ODYyZjNjMTFiN2ZiODljNDNkMjE4NGFlNzU5M2JhMmQ2YTJkOWMwMmYxYTBlNTg2MzhkYzU0NzE0NjExNzkyNGU4ZjQ4NDgzMTAyNDY5OGRlNGZiMDVmNGQzNzE3NGMwOGI2NGU2NjkxMmU2NGY5M2I0YjNiMThmMzZiZmY0NTgwN2FjMDAxOWRlY2ZkYTcyOGFmNzIyZTQwNjhlMTViM2UwMmQzMmRiYjJkOTE2MmQzNWMzZWM2OGRkZjJjMjdmOTRhZGNmYzEzOTdlOWY0NjQwODFiYWU0Y2E3Y2NjZDY0NjQzNGFmZWU4ODExYWRiZTBlY2MwY2JlOThmNDliMDZkYjE2YjNjNTZhOTRiOGZkMDU=</encrypt></jdpay>"; //req = Regex.Replace(req, @"[\t\n\r]", "", RegexOptions.IgnoreCase); req = req.Replace("\r", "").Replace("\n", "").Replace("\t", ""); AsynNotifyResponse anyResponse = Payment.JDPay.XMLUtil.decryptResXml <AsynNotifyResponse>(Payment.JDPay.Config.JDPubKey, payConfig.JDPayDESKey, req); // System.Diagnostics.Debug.WriteLine("异步通知订单号:" + anyResponse.tradeNum + ",状态:" + anyResponse.status); Tolog("异步通知订单号:" + anyResponse.tradeNum + ",状态:" + anyResponse.status); var orderId = anyResponse.tradeNum; var orderInfo = bllMall.GetOrderInfo(orderId); if (orderInfo == null) { //context.Response.Write("订单未找到"); context.Response.StatusCode = 500; context.Response.Write(failStr); return; } if (orderInfo.PaymentStatus.Equals(1)) { //Tolog("已支付"); // context.Response.Write("订单已支付"); context.Response.StatusCode = 200; context.Response.Write(successStr); return; } if (anyResponse.status == "2") { orderInfo.PaymentType = 3; //支付成功 WXMallProductInfo tProductInfo = new WXMallProductInfo(); UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, orderInfo.WebsiteOwner);//下单用户信息 string hasOrderIDs = ""; int maxCount = 1; //Tolog("准备检查更新订单状态"); if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType)) { //Tolog("预订类型"); #region 预约订单修改状态 orderInfo.PaymentStatus = 1; orderInfo.PayTime = DateTime.Now; orderInfo.Status = "预约成功"; #region 检查是否有预约成功的订单 List <WXMallOrderDetailsInfo> tDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID, null, orderInfo.ArticleCategoryType, null, null); List <WXMallOrderDetailsInfo> oDetailList = bllMall.GetOrderDetailsList(null, tDetailList[0].PID, orderInfo.ArticleCategoryType, tDetailList.Min(p => p.StartDate), tDetailList.Max(p => p.EndDate)); tProductInfo = bllMall.GetByKey <WXMallProductInfo>("PID", tDetailList[0].PID); maxCount = tProductInfo.Stock; List <string> hasOrderIDList = new List <string>(); foreach (var item in tDetailList) { List <WXMallOrderDetailsInfo> hasOrderDetailList = oDetailList.Where(p => !((item.StartDate >= p.EndDate && item.EndDate > p.EndDate) || (item.StartDate < p.StartDate && item.EndDate <= p.StartDate))).ToList(); if (hasOrderDetailList.Count >= maxCount) { hasOrderIDList.AddRange(hasOrderDetailList.Select(p => p.OrderID).Distinct()); } } hasOrderIDList = hasOrderIDList.Where(p => !p.Contains(orderInfo.OrderID)).ToList(); if (hasOrderIDList.Count > 0) { hasOrderIDList = hasOrderIDList.Distinct().ToList(); hasOrderIDs = MyStringHelper.ListToStr(hasOrderIDList, "'", ","); } #endregion 检查是否有预约成功的订单 #endregion 预约订单修改状态 } else { //Tolog("普通类型"); #region 原订单修改状态 orderInfo.PaymentStatus = 1; orderInfo.Status = "待发货"; orderInfo.PayTime = DateTime.Now; Tolog("更改状态start"); //if (bllMall.GetWebsiteInfoModelFromDataBase().IsDistributionMall.Equals(1)) //{ orderInfo.GroupBuyStatus = "0"; orderInfo.DistributionStatus = 1; #region 拼团订单 if (orderInfo.OrderType == 2) { try { if (!string.IsNullOrEmpty(orderInfo.GroupBuyParentOrderId)) { var parentOrderInfo = bllMall.GetOrderInfo(orderInfo.GroupBuyParentOrderId); if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And GroupBuyParentOrderId='{0}' Or OrderId='{0}'", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount) { bllMall.Update(new WXMallOrderInfo(), string.Format("Status='已取消'"), string.Format(" GroupBuyParentOrderId='{0}' And PaymentStatus=0", parentOrderInfo.OrderID)); parentOrderInfo.GroupBuyStatus = "1"; bllMall.Update(parentOrderInfo); } } } catch (Exception) { } } #endregion #region 活动订单 if (orderInfo.OrderType == 4) { ActivityDataInfo data = bllMall.Get <ActivityDataInfo>(string.Format(" OrderId='{0}'", orderInfo.OrderID)); if (data != null) { bllMall.Update(data, string.Format(" PaymentStatus=1"), string.Format(" OrderId='{0}'", orderInfo.OrderID)); } } #endregion bllMall.Update(orderInfo, string.Format("PaymentStatus=1,Status='待发货',PayTime=GETDATE(),DistributionStatus=1"), string.Format("ParentOrderId='{0}'", orderInfo.OrderID)); //} #endregion 原订单修改状态 //orderInfo.PayTranNo = tradeNo; } bool result = false; if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType)) { if (string.IsNullOrWhiteSpace(hasOrderIDs)) { hasOrderIDs = "'0'"; } result = bllMall.Update(new WXMallOrderInfo(), string.Format("PaymentStatus={0},PayTime=GetDate(),Status='{1}'", 1, "预约成功"), string.Format("OrderID='{0}' and WebsiteOwner='{4}' AND (select count(1) from [ZCJ_WXMallOrderInfo] where Status='{3}' and WebsiteOwner='{4}' and OrderID IN({1}))<{2}", orderInfo.OrderID, hasOrderIDs, maxCount, "预约成功", bllMall.WebsiteOwner) ) > 0; if (result) { // #region 交易成功加积分 //增加积分 (慧聚不需要) //if (orderInfo.TotalAmount > 0) //{ // ScoreConfig scoreConfig = bllScore.GetScoreConfig(); // int addScore = 0; // if (scoreConfig != null && scoreConfig.OrderAmount > 0 && scoreConfig.OrderScore > 0) // { // addScore = (int)(orderInfo.PayableAmount / (scoreConfig.OrderAmount / scoreConfig.OrderScore)); // } // if (addScore > 0) // { // if (bllUser.Update(new UserInfo(), // string.Format(" TotalScore+={0},HistoryTotalScore+={0}", addScore), // string.Format(" UserID='{0}'", orderInfo.OrderUserID)) > 0) // { // UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); // scoreRecord.AddTime = DateTime.Now; // scoreRecord.Score = addScore; // scoreRecord.ScoreType = "OrderSuccess"; // scoreRecord.UserID = orderInfo.OrderUserID; // scoreRecord.AddNote = "预约-交易成功获得积分"; // bllMall.Add(scoreRecord); // } // } //} // #endregion #region 修改其他预约订单为预约失败 返还积分 if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType) && !string.IsNullOrWhiteSpace(hasOrderIDs)) { int tempCount = 0; List <WXMallOrderInfo> tempList = bllMall.GetOrderList(0, 1, "", out tempCount, "预约成功", null, null, null, null, null, null, null, null, null, null, orderInfo.ArticleCategoryType, hasOrderIDs); tempCount = tempCount + 1; //加上当前订单的数量 if (tempCount >= maxCount) { tempList = bllMall.GetColOrderListInStatus("'待付款','待审核'", hasOrderIDs, "OrderID,OrderUserID,UseScore", bllMall.WebsiteOwner); if (tempList.Count > 0) { string stopOrderIds = MyStringHelper.ListToStr(tempList.Select(p => p.OrderID).ToList(), "'", ","); tempList = tempList.Where(p => p.UseScore > 0).ToList(); foreach (var item in tempList) { orderUserInfo.TotalScore += item.UseScore; if (bllUser.Update(new UserInfo(), string.Format(" TotalScore+={0}", item.UseScore), string.Format(" UserID='{0}'", item.OrderUserID)) > 0) { UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = item.UseScore; scoreRecord.TotalScore = orderUserInfo.TotalScore; scoreRecord.ScoreType = "OrderCancel"; scoreRecord.UserID = item.OrderUserID; scoreRecord.RelationID = item.OrderID; scoreRecord.AddNote = "预约-订单失败返还积分"; scoreRecord.WebSiteOwner = item.WebsiteOwner; bllMall.Add(scoreRecord); } } bllMall.Update(new WXMallOrderInfo(), string.Format("Status='{0}'", "预约失败"), string.Format("OrderID In ({0}) and WebsiteOwner='{1}'", stopOrderIds, bllMall.WebsiteOwner)); } } //Tolog("更改修改其他预约为预约失败"); } #endregion } } else { result = bllMall.Update(orderInfo); } if (result) { Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(orderInfo.WebsiteOwner); //Tolog("更改状态true"); #region Efast同步 //判读当前站点是否需要同步到驿氪和efast if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncEfast, bllCommRelation.WebsiteOwner, "")) { try { Tolog("开始同步efast"); string outOrderId = string.Empty, msg = string.Empty; var syncResult = bllEfast.CreateOrder(orderInfo.OrderID, out outOrderId, out msg); if (syncResult) { orderInfo.OutOrderId = outOrderId; bllMall.Update(orderInfo); } Tolog(string.Format("efast订单同步结果:{0},订单号:{1},提示信息:{2}", syncResult, outOrderId, msg)); } catch (Exception ex) { Tolog("efast订单同步异常:" + ex.Message); } } #endregion #region 驿氪同步 if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, bllCommRelation.WebsiteOwner, "")) { try { Tolog("开始同步驿氪"); //同步成功订单到驿氪 //UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID); //if ((!string.IsNullOrEmpty(orderUserInfo.Ex1)) && (!string.IsNullOrEmpty(orderUserInfo.Ex2)) && (!string.IsNullOrEmpty(orderUserInfo.Phone))) //{ // client.BonusUpdate(orderUserInfo.Ex2, -(orderInfo.UseScore), "商城下单使用积分" + orderInfo.UseScore); //} var uploadOrderResult = yikeClient.OrderUpload(orderInfo); Tolog(string.Format("驿氪订单同步结果:{0}", Common.JSONHelper.ObjectToJson(uploadOrderResult))); } catch (Exception ex) { Tolog("驿氪订单同步异常:" + ex.Message); } } #endregion #region 付款加积分 try { bllUser.AddUserScoreDetail(orderInfo.OrderUserID, CommonPlatform.Helper.EnumStringHelper.ToString(ZentCloud.BLLJIMP.Enums.ScoreDefineType.OrderPay), bllMall.WebsiteOwner, null, null); } catch (Exception) { } #endregion #region 消息通知 if (!BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType)) { try { var productName = bllMall.GetOrderDetailsList(orderInfo.OrderID)[0].ProductName; string remark = ""; if (!string.IsNullOrEmpty(orderInfo.OrderMemo)) { remark = string.Format("客户留言:{0}", orderInfo.OrderMemo); } bllWeiXin.SendTemplateMessageToKefu("有新的订单", string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}\\n商品:{4}\\n{5}", orderInfo.OrderID, orderInfo.TotalAmount, orderInfo.Consignee, orderInfo.Phone, productName, remark)); if (orderInfo.OrderType != 4)//付费的活动不发消息 { if (orderInfo.WebsiteOwner != "jikuwifi") { string url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/orderDetail/{1}#/orderDetail/{1}", context.Request.Url.Host, orderInfo.OrderID); bllWeiXin.SendTemplateMessageNotifyComm(orderUserInfo, "订单已成功支付,我们将尽快发货,请保持手机畅通等待物流送达!", string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}\\n商品:{4}...\\n查看详情", orderInfo.OrderID, orderInfo.TotalAmount, orderInfo.Consignee, orderInfo.Phone, productName), url); } } } catch (Exception) { } } else { try { bllWeiXin.SendTemplateMessageToKefu(orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元\\n预约人:{3}\\n预约人手机:{4}", orderInfo.OrderID, orderInfo.TotalAmount, tProductInfo.PName, orderUserInfo.TrueName, orderUserInfo.Phone)); bllWeiXin.SendTemplateMessageNotifyComm(orderUserInfo, orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元", orderInfo.OrderID, orderInfo.TotalAmount, tProductInfo.PName)); } catch (Exception) { } } #endregion WebsiteInfo websiteInfo = bllMall.Get <WebsiteInfo>(string.Format(" WebsiteOwner='{0}'", orderInfo.WebsiteOwner)); #region 分销相关 try { if (bllMenuPermission.CheckUserAndPmsKey(websiteInfo.WebsiteOwner, BLLPermission.Enums.PermissionSysKey.OnlineDistribution, websiteInfo.WebsiteOwner)) { if (string.IsNullOrWhiteSpace(orderUserInfo.DistributionOwner)) { if (websiteInfo.DistributionRelationBuildMallOrder == 1) { orderUserInfo.DistributionOwner = bllMall.WebsiteOwner; bllMall.Update(orderUserInfo); } } bllDis.AutoUpdateLevel(orderInfo); bllDis.TransfersEstimate(orderInfo); bllDis.SendMessageToUser(orderInfo); bllDis.UpdateDistributionSaleAmountUp(orderInfo); } } catch (Exception ex) { Tolog("设置分销员异常:" + ex.Message + " 用户id:" + orderUserInfo.UserID); } #endregion #region 宏巍通知 try { if (websiteInfo.IsUnionHongware == 1) { hongWareClient.OrderNotice(orderUserInfo.WXOpenId, orderInfo.OrderID); } } catch (Exception) { } #endregion bllCard.Give(orderInfo.TotalAmount, orderUserInfo); string v1ProductId = Common.ConfigHelper.GetConfigString("YGBV1ProductId"); string v2ProductId = Common.ConfigHelper.GetConfigString("YGBV2ProductId"); string v1CouponId = Common.ConfigHelper.GetConfigString("YGBV1CouponId"); string v2CouponId = Common.ConfigHelper.GetConfigString("YGBV2CouponId"); List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID); foreach (var item in orderDetailList) { item.IsComplete = 1; bllMall.Update(item); #region 购买指定商品发送指定的优惠券 if (!string.IsNullOrEmpty(v1ProductId) && !string.IsNullOrEmpty(v1CouponId) && item.PID == v1ProductId) { bllCard.SendCardCouponsByCurrUserInfo(orderUserInfo, v1CouponId); } if (!string.IsNullOrEmpty(v2ProductId) && !string.IsNullOrEmpty(v2CouponId) && item.PID == v2ProductId) { bllCard.SendCardCouponsByCurrUserInfo(orderUserInfo, v2CouponId); } #endregion } //更新销量 bllMall.UpdateProductSaleCount(orderInfo); context.Response.StatusCode = 200; context.Response.Write(successStr); Tolog("支付成功" + orderInfo.OrderID); return; } else { Tolog("更改状态false"); context.Response.StatusCode = 500; context.Response.Write(failStr); return; } } } catch (Exception ex) { //error = "fail"; Tolog("京东支付异常:" + ex.ToString()); } context.Response.ContentType = "text/plain"; context.Response.StatusCode = 500; context.Response.Write(failStr); }
public void ProcessRequest(HttpContext context) { try { string data = context.Request["data"]; decimal productFee = 0; //商品总价格 不包含邮费 decimal deviceFee = 0; //租金总金额,不包含押金 OrderModel orderRequestModel; //订单模型 try { orderRequestModel = ZentCloud.Common.JSONHelper.JsonToModel <OrderModel>(data); } catch (Exception ex) { resp.errcode = 1; resp.errmsg = "JSON格式错误,请检查.错误信息:" + ex.Message; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.departure_date)) { resp.errcode = 1; resp.errmsg = "请选择出发日期"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.backhome_date)) { resp.errcode = 1; resp.errmsg = "请选择回国日期"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } WXMallOrderInfo orderInfo = new WXMallOrderInfo(); //订单表 string orderId = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder); orderInfo.OrderID = CreateOrderId(orderId); //内部订单号 orderInfo.OutOrderId = CreateOrderId(orderId); //外部订单号 orderInfo.Consignee = orderRequestModel.receiver_name; orderInfo.InsertDate = DateTime.Now; orderInfo.OrderUserID = CurrentUserInfo.UserID; orderInfo.Phone = orderRequestModel.receiver_phone; orderInfo.WebsiteOwner = bllMall.WebsiteOwner; orderInfo.Transport_Fee = 0; orderInfo.OrderMemo = orderRequestModel.buyer_memo; orderInfo.ZipCode = orderRequestModel.receiver_zip; orderInfo.MyCouponCardId = orderRequestModel.cardcoupon_id.ToString(); orderInfo.UseScore = orderRequestModel.use_score; orderInfo.Status = "待付款"; orderInfo.Email = orderRequestModel.email; orderInfo.Tel = orderRequestModel.receiver_tel; orderInfo.DeliveryType = orderRequestModel.delivery_type; orderInfo.Ex1 = bllMall.GetTime(long.Parse(orderRequestModel.departure_date)).ToString(); //出国时间 orderInfo.Ex2 = bllMall.GetTime(long.Parse(orderRequestModel.backhome_date)).ToString(); //回国时间 orderInfo.LastUpdateTime = DateTime.Now; if (!string.IsNullOrEmpty(orderRequestModel.sale_id)) //分销ID { long saleId = 0; if (long.TryParse(orderRequestModel.sale_id, out saleId)) { orderInfo.SellerId = saleId; } } if (orderRequestModel.pay_type == "WEIXIN")//微信支付 { orderInfo.PaymentType = 2; } else if (orderRequestModel.pay_type == "ALIPAY")//支付宝支付 { orderInfo.PaymentType = 1; } #region 格式检查 if (string.IsNullOrEmpty(orderInfo.Consignee)) { resp.errcode = 1; resp.errmsg = "收货人姓名不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.receiver_phone)) { resp.errcode = 1; resp.errmsg = "收货人联系手机号不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } #region 快递 if (orderRequestModel.delivery_type == 0)//快递 { //相关检查 if (string.IsNullOrEmpty(orderRequestModel.receiver_province)) { resp.errcode = 1; resp.errmsg = "省份名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.receiver_province_code)) { resp.errcode = 1; resp.errmsg = "省份代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.receiver_city)) { resp.errcode = 1; resp.errmsg = "城市名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.receiver_city_code)) { resp.errcode = 1; resp.errmsg = "城市代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.receiver_dist)) { resp.errcode = 1; resp.errmsg = "城市区域名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.receiver_dist_code)) { resp.errcode = 1; resp.errmsg = "城市区域代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.receiver_address)) { resp.errcode = 1; resp.errmsg = "街道地址不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } orderInfo.ReceiverProvince = orderRequestModel.receiver_province; orderInfo.ReceiverProvinceCode = orderRequestModel.receiver_province_code; orderInfo.ReceiverCity = orderRequestModel.receiver_city; orderInfo.ReceiverCityCode = orderRequestModel.receiver_city_code; orderInfo.ReceiverDist = orderRequestModel.receiver_dist; orderInfo.ReceiverDistCode = orderRequestModel.receiver_dist_code; orderInfo.Address = orderRequestModel.receiver_address; orderInfo.ZipCode = orderRequestModel.receiver_zip; } #endregion #region 门自提 if (orderRequestModel.delivery_type == 1)//自提点 { if (string.IsNullOrEmpty(orderRequestModel.get_address_id)) { resp.errcode = 1; resp.errmsg = "自提点ID为必填项,请检查"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(orderRequestModel.get_address_name)) { resp.errcode = 1; resp.errmsg = "自提点名称为必填项,请检查"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } //if (string.IsNullOrEmpty(orderRequestModel.ex7)) //{ // resp.errcode = 1; // resp.errmsg = "自提时间为必填项,请检查"; // context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); // return; //} orderInfo.Ex3 = orderRequestModel.get_address_id; orderInfo.Ex4 = orderRequestModel.get_address_name; orderInfo.Ex5 = bllMall.GetGetAddress(orderRequestModel.get_address_id).GetAddressLocation; //orderInfo.Ex7 = orderRequestModel.ex7;//自提时间 } #endregion if (orderRequestModel.skus == null) { resp.errcode = 1; resp.errmsg = "skus 参数不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } DateTime startTime = DateTime.Parse(bllMall.GetTime(long.Parse(orderRequestModel.departure_date)).ToString("yyyy/MM/dd")); DateTime returnTime = bllMall.GetTime(long.Parse(orderRequestModel.backhome_date)); if (returnTime <= startTime) { resp.errcode = 1; resp.errmsg = "回国日期不能晚于或等于出发日期"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } int day = (int)(returnTime - startTime).TotalDays + 1; if (day < 3) { resp.errcode = (int)BLLJIMP.Enums.APIErrCode.OperateFail; resp.errmsg = "起租最低为3天"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } //相关检查 #endregion #region 商品检查 订单详情生成 ///订单详情 List <WXMallOrderDetailsInfo> detailList = new List <WXMallOrderDetailsInfo>();//订单详情 //orderRequestModel.skus = orderRequestModel.skus.Distinct().ToList(); #region 购买的商品 List <WXMallProductInfo> productList = new List <WXMallProductInfo>(); foreach (var sku in orderRequestModel.skus) { ProductSku productSku = bllMall.GetProductSku(sku.sku_id); WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); productList.Add(productInfo); } productList = productList.Distinct().ToList(); #endregion #region 检查优惠券是否可用 if (orderRequestModel.cardcoupon_id > 0) { var mycardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, CurrentUserInfo.UserID); if (mycardCoupon == null) { resp.errcode = 1; resp.errmsg = "无效的优惠券"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } var cardCoupon = bllCardCoupon.GetCardCoupon(mycardCoupon.CardId); if (cardCoupon == null) { resp.errcode = 1; resp.errmsg = "无效的优惠券"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } #region 需要购买指定商品 if ((!string.IsNullOrEmpty(cardCoupon.Ex2)) && (cardCoupon.Ex2 != "0")) { if (productList.Count(p => p.PID == cardCoupon.Ex2) == 0) { var productInfo = bllMall.GetProduct(cardCoupon.Ex2); resp.errcode = 1; resp.errmsg = string.Format("此优惠券需要购买{0}时才可以使用", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion #region 需要购买指定标签商品 if (!string.IsNullOrEmpty(cardCoupon.Ex8)) { if (productList.Where(p => p.Tags == "" || p.Tags == null).Count() == productList.Count)//全部商品都没有标签 { resp.errcode = 1; resp.errmsg = string.Format("使用此优惠券需要购买标签为{0}的商品", cardCoupon.Ex8); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } bool checkResult = false; foreach (var product in productList) { if (!string.IsNullOrEmpty(product.Tags)) { foreach (string tag in product.Tags.Split(',')) { if (cardCoupon.Ex8.Contains(tag)) { checkResult = true; break; } } } } if (!checkResult) { resp.errcode = 1; resp.errmsg = string.Format("使用此优惠券需要购买标签为{0}的商品", cardCoupon.Ex8); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion } #endregion List <int> relationSkuList = new List <int>();//关联的SKU foreach (var sku in orderRequestModel.skus) { //先检查库存 ProductSku productSku = bllMall.GetProductSku(sku.sku_id); if (productSku == null) { resp.errcode = 1; resp.errmsg = "SKU不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); if (productInfo.IsDelete == 1) { resp.errcode = 1; resp.errmsg = string.Format("{0}已下架", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (productInfo.IsOnSale == "0") { resp.errcode = 1; resp.errmsg = string.Format("{0}已下架", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (bllMall.GetSkuCount(productSku) < sku.count) { resp.errcode = 1; resp.errmsg = string.Format("{0}{1}库存余量为{2},库存不足,请减少购买数量", productInfo.PName, bllMall.GetProductShowProperties(productSku.SkuId), productSku.Stock); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (!string.IsNullOrEmpty(productInfo.RelationProductId)) { WXMallProductInfo relationProductInfo = bllMall.GetProduct(productInfo.RelationProductId); var relationProductSkuList = bllMall.GetProductSkuList(int.Parse(relationProductInfo.PID)); if (orderRequestModel.skus.Where(p => p.sku_id == relationProductSkuList[0].SkuId).Count() == 0) { resp.errcode = 1; resp.errmsg = string.Format("{0}必须有关联商品下单", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } else { relationSkuList.Add(relationProductSkuList[0].SkuId);//关联的Sku商品不参与运费计算 } } //if (bllMall.IsLimitProductTime(productInfo, orderInfo.Ex1, orderInfo.Ex2)) //{ // resp.errcode = 1; // resp.errmsg = string.Format("{0} 暂时不能购买", productInfo.PName); // context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); // return; //} WXMallOrderDetailsInfo detailModel = new WXMallOrderDetailsInfo(); detailModel.OrderID = orderInfo.OrderID; detailModel.PID = productInfo.PID; detailModel.TotalCount = sku.count; if (!string.IsNullOrEmpty(productInfo.RelationProductId))// { //detailModel.OrderPrice = bllMall.GetSkuPrice(productSku) * day; //List<string> dateRange = new List<string>();//时间范围 //startTime = DateTime.Parse(startTime.ToString("yyyy/MM/dd")); //returnTime = DateTime.Parse(returnTime.ToString("yyyy/MM/dd")); //for (int i = 1; i < (returnTime - startTime).TotalDays; i++) //{ // dateRange.Add(startTime.AddDays(i).ToString("yyyy/MM/dd")); //} //dateRange.Add(startTime.ToString("yyyy/MM/dd")); //dateRange.Add(returnTime.ToString("yyyy/MM/dd")); //dateRange = dateRange.Distinct().ToList(); //detailModel.OrderPrice = 0; //foreach (var date in dateRange)// //{ detailModel.OrderPrice = bllMall.GetSkuPriceByDate(productSku, startTime.ToString("yyyy/MM/dd")) * day; //} deviceFee += (decimal)detailModel.OrderPrice * detailModel.TotalCount; } else//设备租金 { detailModel.OrderPrice = bllMall.GetSkuPrice(productSku); } detailModel.ProductName = productInfo.PName; detailModel.SkuId = productSku.SkuId; detailModel.ParentProductId = sku.parent_product_id; detailList.Add(detailModel); } #endregion productFee = detailList.Sum(p => p.OrderPrice * p.TotalCount).Value; //商品费用 #region 运费计算 List <ZentCloud.BLLJIMP.Model.API.Mall.SkuModel> skuList = new List <ZentCloud.BLLJIMP.Model.API.Mall.SkuModel>(); foreach (var item in orderRequestModel.skus) { ZentCloud.BLLJIMP.Model.API.Mall.SkuModel sku = new BLLJIMP.Model.API.Mall.SkuModel(); sku.sku_id = item.sku_id; sku.count = item.count; skuList.Add(sku); } decimal freight = 0; //运费 string freightMsg = ""; if (orderRequestModel.delivery_type == 0) //配送方式为快递时才计算运费 { FreightModel freightModel = new FreightModel(); freightModel.receiver_province_code = int.Parse(orderRequestModel.receiver_province_code); freightModel.receiver_city_code = int.Parse(orderRequestModel.receiver_city_code); freightModel.receiver_dist_code = int.Parse(orderRequestModel.receiver_dist_code); freightModel.skus = skuList; foreach (int relationSku in relationSkuList) { //关联SKU不参与运费计算 freightModel.skus = freightModel.skus.Where(p => p.sku_id != relationSku).ToList(); } if (!bllMall.CalcFreight(freightModel, out freight, out freightMsg)) { resp.errcode = 1; resp.errmsg = freightMsg; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } orderInfo.Transport_Fee = freight; #endregion orderInfo.Product_Fee = productFee; orderInfo.TotalAmount = orderInfo.Product_Fee + orderInfo.Transport_Fee; #region 优惠券计算 decimal discountAmount = 0;//优惠金额 bool canUseCardCoupon = false; string msg = ""; if (orderRequestModel.cardcoupon_id > 0)//有优惠券 { discountAmount = bllMall.CalcDiscountAmountWifi(orderRequestModel.cardcoupon_id.ToString(), data, CurrentUserInfo.UserID, out canUseCardCoupon, deviceFee, out msg); if (!canUseCardCoupon) { resp.errcode = 1; resp.errmsg = msg; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (discountAmount > productFee + orderInfo.Transport_Fee) { resp.errcode = 1; resp.errmsg = "优惠券可优惠金额超过了订单总金额"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } orderInfo.CardcouponDisAmount = discountAmount; } #endregion #region 积分计算 decimal scoreExchangeAmount = 0;///积分抵扣的金额 //积分计算 if (orderRequestModel.use_score > 0) { if (CurrentUserInfo.TotalScore < orderRequestModel.use_score) { resp.errcode = 1; resp.errmsg = "积分不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } ScoreConfig scoreConfig = bllScore.GetScoreConfig(); scoreExchangeAmount = Math.Round(orderRequestModel.use_score / (scoreConfig.ExchangeScore / scoreConfig.ExchangeAmount), 2); } //积分计算 #endregion #region 合计计算 orderInfo.TotalAmount -= discountAmount; //优惠券优惠金额 orderInfo.TotalAmount -= scoreExchangeAmount; //积分优惠金额 orderInfo.PayableAmount = orderInfo.TotalAmount - freight; //应付金额 if ((productFee + orderInfo.Transport_Fee - discountAmount - scoreExchangeAmount) < orderInfo.TotalAmount) { resp.errcode = 1; resp.errmsg = "积分兑换金额不能大于订单总金额,请减少积分兑换"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } #endregion if (orderInfo.TotalAmount <= 0) { //resp.errcode = 1; //resp.errmsg = "付款金额不能小于0"; //context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); //return; orderInfo.TotalAmount = 0; orderInfo.PaymentStatus = 1; orderInfo.PayTime = DateTime.Now; orderInfo.Status = "待发货"; } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { if (!this.bllMall.Add(orderInfo, tran)) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "提交失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } #region 更新优惠券使用状态 //优惠券 if (orderRequestModel.cardcoupon_id > 0 && (canUseCardCoupon == true))//有优惠券且已经成功使用 { MyCardCoupons myCardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, CurrentUserInfo.UserID); myCardCoupon.UseDate = DateTime.Now; myCardCoupon.Status = 1; if (!bllCardCoupon.Update(myCardCoupon, tran)) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "更新优惠券状态失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } //优惠券 #endregion #region 积分抵扣 //积分扣除 if (orderRequestModel.use_score > 0) { CurrentUserInfo.TotalScore -= orderRequestModel.use_score; if (bllMall.Update(CurrentUserInfo, string.Format(" TotalScore-={0}", orderRequestModel.use_score), string.Format(" AutoID={0}", CurrentUserInfo.AutoID)) < 0) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "更新用户积分失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } //积分记录 UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = -orderRequestModel.use_score; scoreRecord.TotalScore = CurrentUserInfo.TotalScore; scoreRecord.ScoreType = "OrderSubmit"; scoreRecord.UserID = CurrentUserInfo.UserID; scoreRecord.AddNote = "微商城-下单使用积分"; if (!bllMall.Add(scoreRecord)) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "插入积分记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } //积分记录 } //积分扣除 #endregion #region 插入订单详情页及更新库存 foreach (var item in detailList) { ProductSku productSku = bllMall.GetProductSku((int)(item.SkuId)); WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); if (!this.bllMall.Add(item, tran)) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "提交失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } //更新 SKU库存 if (ZentCloud.ZCBLLEngine.BLLBase.ExecuteSql(string.Format("update ZCJ_ProductSku set Stock-={0} where SkuId={1} And Stock>0", item.TotalCount, productSku.SkuId), tran) <= 0) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "提交订单失败,库存不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion bllMall.DeleteShoppingCart(CurrentUserInfo.UserID, skuList); bllLog.Add(BLLJIMP.Enums.EnumLogType.Mall, BLLJIMP.Enums.EnumLogTypeAction.Add, bllLog.GetCurrUserID(), "提交订单", orderInfo.OrderID); tran.Commit();//提交订单事务 } catch (Exception ex) { //回滚事物 tran.Rollback(); resp.errcode = 1; resp.errmsg = "提交订单失败,内部错误"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(new { errcode = 0, errmsg = "ok", order_id = orderInfo.OrderID, total_amount = orderInfo.TotalAmount })); } catch (Exception ex) { resp.errcode = 1; resp.errmsg = ex.ToString(); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } }
public void ProcessRequest(HttpContext context) { string ids = context.Request["ids"]; string order_status = context.Request["order_status"]; bool actionStatus = false; if (order_status == "预约成功") { List <string> successIds = new List <string>(); List <string> failIds = new List <string>(); List <string> orderIds = ids.Split(',').ToList(); string hasOrderIDs = ""; int maxCount = 1; foreach (string orderId in orderIds) { //已有订单详情 WXMallOrderInfo tOrder = bllMall.GetByKey <WXMallOrderInfo>("OrderID", orderId); List <WXMallOrderDetailsInfo> tDetailList = bllMall.GetOrderDetailsList(orderId, null, tOrder.ArticleCategoryType, null, null); List <WXMallOrderDetailsInfo> oDetailList = bllMall.GetOrderDetailsList(null, tDetailList[0].PID, tOrder.ArticleCategoryType, tDetailList.Min(p => p.StartDate), tDetailList.Max(p => p.EndDate)); WXMallProductInfo tProductInfo = bllMall.GetByKey <WXMallProductInfo>("PID", tDetailList[0].PID); maxCount = tProductInfo.Stock; List <string> hasOrderID_List = new List <string>(); foreach (var item in tDetailList) { List <WXMallOrderDetailsInfo> hasOrderDetailList = oDetailList.Where(p => !((item.StartDate >= p.EndDate && item.EndDate > p.EndDate) || (item.StartDate < p.StartDate && item.EndDate <= p.StartDate))).ToList(); if (hasOrderDetailList.Count > 0) { hasOrderID_List.AddRange(hasOrderDetailList.Select(p => p.OrderID).Distinct()); } } hasOrderID_List = hasOrderID_List.Where(p => !p.Contains(orderId)).ToList(); if (hasOrderID_List.Count > 0) { hasOrderID_List = hasOrderID_List.Distinct().ToList(); hasOrderIDs = MyStringHelper.ListToStr(hasOrderID_List, "'", ","); int tempCount = 0; List <WXMallOrderInfo> tempList = bllMall.GetOrderList(0, 1, "", out tempCount, "预约成功", null, null, null, null, null, null, null, null, null, null, tOrder.ArticleCategoryType, hasOrderIDs); if (tempCount >= maxCount) { failIds.Add(orderId); continue; } if (string.IsNullOrWhiteSpace(hasOrderIDs)) { hasOrderIDs = "'0'"; } if (bllMall.Update(new WXMallOrderInfo(), string.Format("PaymentStatus={0},PayTime=GetDate(),Status='{1}'", 1, "预约成功"), string.Format("OrderID={0} AND WebsiteOwner='{4}' and (select count(1) from [ZCJ_WXMallOrderInfo] where Status='{3}' and WebsiteOwner='{4}' and OrderID IN({1}))<{2}", tOrder.OrderID, hasOrderIDs, maxCount, "预约成功", bllMall.WebsiteOwner) ) > 0) { hasOrderIDs = string.Format("{0},'{1}'", hasOrderIDs, tOrder.OrderID); successIds.Add(orderId); #region 修改其他预约订单为预约失败 bllMall.Update(new WXMallOrderInfo(), string.Format("Status='{0}'", "预约失败"), string.Format("OrderID In ({0}) AND Status Not In ({1}) and WebsiteOwner='{4}' AND (select count(1) from [ZCJ_WXMallOrderInfo] where Status='{5}' and OrderID IN({2}) and WebsiteOwner='{4}' )>={3}", hasOrderIDs, "'预约失败','预约成功','已取消'", hasOrderIDs, maxCount, bllMall.WebsiteOwner, "预约成功")); #endregion } else { failIds.Add(orderId); } } else { tOrder.Status = order_status; if (bllMall.Update(tOrder)) { successIds.Add(orderId); } else { failIds.Add(orderId); } } } if (orderIds.Count == 0) { apiResp.msg = "修改完成"; } else { if (failIds.Count == 0) { apiResp.msg = "全部修改成功"; } else if (successIds.Count == 0) { apiResp.msg = "全部订单所选时间已有预约成功的订单"; } else { apiResp.msg = "订单[" + MyStringHelper.ListToStr(successIds, "", ",") + "]修改成功,订单[" + MyStringHelper.ListToStr(failIds, "", ",") + "]所选时间已有预约成功的订单"; } } apiResp.status = true; apiResp.code = (int)APIErrCode.IsSuccess; bllMall.ContextResponse(context, apiResp); } else { List <string> orderIds = ids.Split(',').ToList(); ids = MyStringHelper.ListToStr(orderIds, "'", ","); if (bllMall.UpdateMultByKey <WXMallOrderInfo>("OrderID", ids, "Status", order_status, null, true) > 0) { apiResp.status = true; apiResp.msg = "修改完成"; apiResp.code = (int)APIErrCode.IsSuccess; } else { apiResp.msg = "修改失败"; apiResp.code = (int)APIErrCode.OperateFail; } } bllMall.ContextResponse(context, apiResp); }
public void ProcessRequest(HttpContext context) { string orderSn = context.Request["order_sn"]; if (string.IsNullOrEmpty(orderSn)) { resp.msg = "order_sn 参数必传"; resp.code = (int)BLLJIMP.Enums.APIErrCode.IsNotFound; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } var orderInfo = bllMall.GetOrderInfoByOutOrderId(orderSn); if (orderInfo == null) { resp.msg = "order_sn 不存在"; resp.code = (int)BLLJIMP.Enums.APIErrCode.IsNotFound; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } OrderListModel model = new OrderListModel(); model.order_sn = orderInfo.OutOrderId; var orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, orderInfo.WebsiteOwner); if (orderUserInfo != null) { model.wx_openid = orderUserInfo.WXOpenId; } model.user_id = orderInfo.OrderUserID; model.user_name = orderInfo.Consignee; if (!string.IsNullOrEmpty(orderInfo.MyCouponCardId)) { var myCardCoupon = bllCardCoupon.GetMyCardCoupon(int.Parse(orderInfo.MyCouponCardId), orderInfo.OrderUserID); if (myCardCoupon != null) { var cardCoupon = bllCardCoupon.GetCardCoupon(myCardCoupon.CardId); if (cardCoupon != null) { model.cardcoupon_main_id = myCardCoupon.CardId; model.cardcoupon_no = myCardCoupon.CardCouponNumber; model.cardcoupon_name = cardCoupon.Name; model.cardcoupon_amount = orderInfo.CardcouponDisAmount; } } } model.use_score = orderInfo.UseScore; model.score_exchang_amount = orderInfo.ScoreExchangAmount; model.use_amount = orderInfo.UseAmount; model.payable_amount = orderInfo.PayableAmount; model.total_amount = orderInfo.TotalAmount; model.is_appeal = orderInfo.Ex8 == "1" ? 1 : 0; model.appeal_content = orderInfo.Ex9; model.is_apply_deposit = orderInfo.Ex10 == "1" ? 1 : 0; model.is_apply_refund = orderInfo.Ex11 == "1" ? 1 : 0; if (orderInfo.IsRefund == 1) { model.is_apply_refund = 1; } model.order_status = orderInfo.Status; model.shipping_type = orderInfo.DeliveryType; model.get_address_id = orderInfo.Ex3; model.get_address_name = orderInfo.Ex4; model.get_address = orderInfo.Ex5; model.departure_date = orderInfo.Ex1; model.backhome_date = orderInfo.Ex2; model.order_time = orderInfo.InsertDate.ToString(); model.receiver_name = orderInfo.Consignee; model.receiver_phone = orderInfo.Phone; model.receiver_tel = orderInfo.Tel; model.receiver_email = orderInfo.Email; model.receiver_province = orderInfo.ReceiverProvince; model.receiver_city = orderInfo.ReceiverCity; model.receiver_dist = orderInfo.ReceiverDist; model.receiver_address = orderInfo.Address; model.receiver_zip = orderInfo.ZipCode; model.is_pay = orderInfo.PaymentStatus; model.express_company_code = orderInfo.ExpressCompanyCode; model.express_company_name = orderInfo.ExpressCompanyName; model.express_number = orderInfo.ExpressNumber; model.delivery_time = (orderInfo.DeliveryTime != null) ? ((DateTime)orderInfo.DeliveryTime).ToString("yyyy-MM-dd HH:mm:ss") : ""; model.last_update_time = (orderInfo.LastUpdateTime != null) ? ((DateTime)orderInfo.LastUpdateTime).ToString("yyyy-MM-dd HH:mm:ss") : ""; model.pay_time = (orderInfo.PayTime != null) ? ((DateTime)orderInfo.PayTime).ToString("yyyy-MM-dd HH:mm:ss") : ""; model.order_type = orderInfo.OrderType; switch (model.order_type) { case 1: //礼品订单 model.parent_order_sn = orderInfo.ParentOrderId; break; case 2: //拼团订单 model.parent_order_sn = orderInfo.GroupBuyParentOrderId; break; default: break; } model.freight = orderInfo.Transport_Fee; model.pay_tran_number = orderInfo.PayTranNo; model.store_name = !string.IsNullOrEmpty(orderInfo.SupplierName) ? orderInfo.SupplierName : ""; model.store_address = orderInfo.StoreAddress; model.claim_arrival_time = !string.IsNullOrEmpty(orderInfo.ClaimArrivalTime) ? orderInfo.ClaimArrivalTime : ""; model.product_list = new List <OrderProductModel>(); var orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID); foreach (var orderDetail in orderDetailList) { WXMallProductInfo productInfo = bllMall.GetProduct(orderDetail.PID); OrderProductModel myProductModel = new OrderProductModel(); myProductModel.product_id = productInfo.PID; myProductModel.product_sn = productInfo.ProductCode; myProductModel.product_name = productInfo.PName; myProductModel.count = orderDetail.TotalCount; myProductModel.price = (decimal)orderDetail.OrderPrice; myProductModel.quote_price = productInfo.PreviousPrice; try { if ((!string.IsNullOrEmpty(orderInfo.Ex2)) && (!string.IsNullOrEmpty(orderInfo.Ex1))) { myProductModel.day = (DateTime.Parse(orderInfo.Ex2) - DateTime.Parse(orderInfo.Ex1)).TotalDays + 1; } } catch (Exception) { break; } myProductModel.total_price = myProductModel.price * myProductModel.count; myProductModel.sku_id = orderDetail.SkuId; myProductModel.show_property = orderDetail.SkuShowProp; myProductModel.refund_status = bllMall.GetRefundStatus(orderDetail); model.product_list.Add(myProductModel); } var userInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, orderInfo.WebsiteOwner); if (userInfo != null) { model.weixin_open_id = userInfo.WXOpenId; } resp.status = true; resp.msg = "ok"; resp.result = model; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }
/// <summary> /// 更新 /// </summary> /// <param name="context"></param> /// <returns></returns> private string Update(HttpContext context) { string data = context.Request["data"]; ProcuctModel productRequestModel; try { productRequestModel = ZentCloud.Common.JSONHelper.JsonToModel <ProcuctModel>(data); } catch (Exception ex) { resp.errcode = 1; resp.errmsg = "JSON格式错误,请检查。错误信息:" + ex.Message; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } #region 检查 foreach (var sku in productRequestModel.skus) { ProductSku productSku = bllMall.GetProductSku(sku.sku_id); if (productSku.ProductId != productRequestModel.product_id) { resp.errcode = 1; resp.errmsg = "sku product_id不匹配,请检查"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (sku.promotion_sale_count > productSku.Stock) { resp.errcode = 1; resp.errmsg = "特卖总库存不能大于" + productSku.Stock; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (sku.promotion_count > sku.promotion_sale_count) { resp.errcode = 1; resp.errmsg = "特卖剩余库存不能大于" + sku.promotion_sale_count; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (sku.promotion_sale_count > 0 && sku.promotion_price <= 0) { resp.errcode = 1; resp.errmsg = "有特卖总数量的特卖价格需大于0"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } //if (sku.promotion_price<=0) //{ // resp.errcode = 1; // resp.errmsg = "特卖价格需大于0"; // return ZentCloud.Common.JSONHelper.ObjectToJson(resp); //} if (sku.promotion_price > productSku.Price) { resp.errcode = 1; resp.errmsg = "特卖价格不能大于原价格"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } //检查 #endregion ProductSku temproductSku = bllMall.GetProductSku(productRequestModel.skus[0].sku_id); WXMallProductInfo tempProductInfo = bllMall.GetProduct(temproductSku.ProductId.ToString()); BLLJIMP.Model.PromotionActivity promotionActivity = bllMall.GetPromotionActivity(tempProductInfo.PromotionActivityId); ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { foreach (var sku in productRequestModel.skus) { ProductSku productSku = bllMall.GetProductSku(sku.sku_id); productSku.PromotionPrice = sku.promotion_price; productSku.PromotionStock = sku.promotion_count; productSku.PromotionSaleStock = sku.promotion_sale_count; if (productSku.PromotionSaleStock == 0) { productSku.PromotionSaleStock = sku.promotion_count; } if (sku.promotion_sale_count > 0) { productSku.PromotionSaleStock = sku.promotion_sale_count; } if (productSku.PromotionStartTime == 0 || productSku.PromotionStopTime == 0) { productSku.PromotionStartTime = promotionActivity.StartTime; productSku.PromotionStopTime = promotionActivity.StopTime; } if (!bllMall.Update(productSku)) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "修改失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } WXMallProductInfo productInfo = bllMall.GetProduct(productRequestModel.product_id.ToString()); productInfo.PromotionPrice = productRequestModel.skus.Min(p => p.promotion_price); if (!bllMall.Update(productInfo, tran)) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "操作失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } tran.Commit(); resp.errmsg = "ok"; } catch (Exception ex) { tran.Rollback(); resp.errcode = -1; resp.errmsg = ex.Message; } bllMall.ClearProductListCacheByWhere(string.Format(" PID='{0}' ", productRequestModel.product_id.ToString())); return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }
public void ProcessRequest(HttpContext context) { WebsiteInfo websiteInfo = bllMall.GetWebsiteInfoModelFromDataBase(); Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(websiteInfo.WebsiteOwner); Open.HongWareSDK.MemberInfo hongWeiWareMemberInfo = null; if (websiteInfo.IsUnionHongware == 1) { hongWeiWareMemberInfo = hongWareClient.GetMemberInfo(CurrentUserInfo.WXOpenId); if (hongWeiWareMemberInfo.member == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "您尚未绑定宏巍账号,请先绑定"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } string data = context.Request["data"]; if (string.IsNullOrEmpty(data)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "data 参数必传"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } decimal productFee = 0; //商品总价格 不包含邮费 OrderModel orderRequestModel; //订单模型 try { orderRequestModel = ZentCloud.Common.JSONHelper.JsonToModel <OrderModel>(data); } catch (Exception ex) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "JSON格式错误,请检查。错误信息:" + ex.Message; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } WXMallOrderInfo orderInfo = new WXMallOrderInfo();//订单表 orderInfo.Address = orderRequestModel.receiver_address; orderInfo.Consignee = orderRequestModel.receiver_name; //orderInfo.ExpressCompanyName = orderRequestModel.express_company; orderInfo.InsertDate = DateTime.Now; orderInfo.OrderUserID = CurrentUserInfo.UserID; orderInfo.Phone = orderRequestModel.receiver_phone; orderInfo.WebsiteOwner = bllMall.WebsiteOwner; orderInfo.Transport_Fee = 0; orderInfo.OrderID = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder); if (bllMall.WebsiteOwner != "mixblu") { orderInfo.OutOrderId = orderInfo.OrderID; } orderInfo.OrderMemo = orderRequestModel.buyer_memo; orderInfo.ReceiverProvince = orderRequestModel.receiver_province; orderInfo.ReceiverProvinceCode = orderRequestModel.receiver_province_code.ToString(); orderInfo.ReceiverCity = orderRequestModel.receiver_city; orderInfo.ReceiverCityCode = orderRequestModel.receiver_city_code.ToString(); orderInfo.ReceiverDist = orderRequestModel.receiver_dist; orderInfo.ReceiverDistCode = orderRequestModel.receiver_dist_code.ToString(); orderInfo.ZipCode = orderRequestModel.receiver_zip; orderInfo.MyCouponCardId = orderRequestModel.cardcoupon_id.ToString(); orderInfo.UseScore = orderRequestModel.use_score; orderInfo.UseAmount = orderRequestModel.use_amount; orderInfo.Status = "待付款"; orderInfo.OrderType = 2; orderInfo.LastUpdateTime = DateTime.Now; //if (!string.IsNullOrEmpty(orderRequestModel.sale_id)) //{ // long saleId = 0; // if (long.TryParse(orderRequestModel.sale_id, out saleId)) // { // orderInfo.SellerId = saleId; // } // else // { // } //} if (orderRequestModel.pay_type == "WEIXIN")//微信支付 { orderInfo.PaymentType = 2; } else if (orderRequestModel.pay_type == "ALIPAY")//支付宝支付 { orderInfo.PaymentType = 1; } #region 格式检查 //相关检查 if (string.IsNullOrEmpty(orderRequestModel.rule_id)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "rule_id 必传"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.Consignee)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "收货人姓名不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.Phone)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "收货人联系电话不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverProvince)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "省份名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverProvinceCode)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "省份代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverCity)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "城市名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverCityCode)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "城市代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverDist)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "城市区域名称不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.ReceiverCityCode)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "城市区域代码不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (string.IsNullOrEmpty(orderInfo.Address)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "收货地址不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (orderRequestModel.skus == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "参数skus 不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //相关检查 #endregion #region 分销关系建立 if (websiteInfo.DistributionRelationBuildMallOrder == 1) { if (!string.IsNullOrEmpty(orderRequestModel.sale_id)) { int saleId = 0; if (int.TryParse(orderRequestModel.sale_id, out saleId)) { orderInfo.SellerId = saleId; if (string.IsNullOrEmpty(CurrentUserInfo.DistributionOwner)) { var recommendUserInfo = bllUser.GetUserInfoByAutoID(saleId); if (recommendUserInfo != null) { var setUserDistributionOwnerResult = bllDis.SetUserDistributionOwner(CurrentUserInfo.UserID, recommendUserInfo.UserID, CurrentUserInfo.WebsiteOwner); if (setUserDistributionOwnerResult) { CurrentUserInfo.DistributionOwner = recommendUserInfo.UserID; CurrentUserInfo.Channel = recommendUserInfo.Channel; } } } } else { } } else { if (string.IsNullOrEmpty(CurrentUserInfo.DistributionOwner)) { CurrentUserInfo.DistributionOwner = bllUser.WebsiteOwner; bllUser.Update(CurrentUserInfo); } } } #endregion if (orderRequestModel.skus.Count > 1) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "只能购买一种商品"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (orderRequestModel.skus.Sum(p => p.count) > 1) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "团购商品只能购买一件"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } List <ProductGroupBuyRule> groupBuyList = new List <ProductGroupBuyRule>();//此商品的团购规则列表 #region 购买的商品 List <WXMallProductInfo> productList = new List <WXMallProductInfo>(); foreach (var sku in orderRequestModel.skus) { ProductSku productSku = bllMall.GetProductSku(sku.sku_id); if (productSku == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "sku_id 无效"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } // WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); //productList.Add(productInfo); //ProductSku productSku = bllMall.GetProductSku(sku.sku_id); //if (productSku == null) continue; if (productList.Count(p => p.PID == productSku.ProductId.ToString()) > 0) { continue; } WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); productList.Add(productInfo); groupBuyList = bllMall.GetProductGroupBuyRuleList(productSku.ProductId.ToString()); } if (groupBuyList.Count == 0) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "此商品不能团购"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (groupBuyList.SingleOrDefault(p => p.RuleId == int.Parse(orderRequestModel.rule_id)) == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "rule_id 错误,请检查"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } ProductGroupBuyRule groupBuyRule = groupBuyList.SingleOrDefault(p => p.RuleId == int.Parse(orderRequestModel.rule_id));//团购规则 // productList = productList.Distinct().ToList(); #endregion string cardCouponType = "";//优惠券类型 #region 检查优惠券是否可用 if (orderRequestModel.cardcoupon_id > 0) { var mycardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, CurrentUserInfo.UserID); if (mycardCoupon == null) { apiResp.code = 1; apiResp.msg = "无效的优惠券"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } var cardCoupon = bllCardCoupon.GetCardCoupon(mycardCoupon.CardId); if (cardCoupon == null) { apiResp.code = 1; apiResp.msg = "无效的优惠券"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } cardCouponType = cardCoupon.CardCouponType; #region 需要购买指定商品 if ((!string.IsNullOrEmpty(cardCoupon.Ex2)) && (cardCoupon.Ex2 != "0")) { if (productList.Count(p => p.PID == cardCoupon.Ex2) == 0) { var productInfo = bllMall.GetProduct(cardCoupon.Ex2); apiResp.code = 1; apiResp.msg = string.Format("此优惠券需要购买{0}时才可以使用", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion #region 需要购买指定标签商品 if (!string.IsNullOrEmpty(cardCoupon.Ex8)) { if (productList.Where(p => p.Tags == "" || p.Tags == null).Count() == productList.Count)//全部商品都没有标签 { apiResp.code = 1; apiResp.msg = string.Format("使用此优惠券需要购买标签为{0}的商品", cardCoupon.Ex8); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } bool checkResult = true; foreach (var product in productList) { if (!string.IsNullOrEmpty(product.Tags)) { bool tempResult = false; foreach (string tag in product.Tags.Split(',')) { if (cardCoupon.Ex8.Contains(tag)) { tempResult = true; break; } } if (!tempResult) { checkResult = false; break; } } else//商品不包含标签 { checkResult = false; break; } } if (!checkResult) { apiResp.code = 1; apiResp.msg = string.Format("使用此优惠券需要购买标签为{0}的商品", cardCoupon.Ex8); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion } #endregion var needUseScore = 0; //必须使用的积分 decimal needUseCash = 0; //必须使用的现金 #region 商品检查 订单详情生成 ///订单详情 List <WXMallOrderDetailsInfo> detailList = new List <WXMallOrderDetailsInfo>();//订单详情 orderRequestModel.skus = orderRequestModel.skus.Distinct().ToList(); foreach (var sku in orderRequestModel.skus) { //先检查库存 ProductSku productSku = bllMall.GetProductSku(sku.sku_id); if (productSku == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "SKU不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } WXMallProductInfo productInfo = productList.Single(p => p.PID == productSku.ProductId.ToString()); if (productInfo.IsOnSale == "0") { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}已下架", productInfo.PName); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (productSku.Stock < sku.count) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}{1}库存余量为{2},库存不足,请减少购买数量", productInfo.PName, bllMall.GetProductShowProperties(productSku.SkuId), productSku.Stock); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (productInfo.Score > 0)//必须使用的积分 { needUseScore += sku.count * productInfo.Score; } if (productInfo.IsCashPayOnly == 1)//必须使用的现金 { needUseCash += (Math.Round((decimal)(productSku.Price * (decimal)(groupBuyRule.HeadDiscount / 10)), 2)) * sku.count; } WXMallOrderDetailsInfo detailModel = new WXMallOrderDetailsInfo(); detailModel.OrderID = orderInfo.OrderID; detailModel.PID = productInfo.PID; detailModel.TotalCount = sku.count; detailModel.OrderPrice = Math.Round((decimal)(productSku.Price * (decimal)(groupBuyRule.HeadDiscount / 10)), 2);//四舍五入 detailModel.ProductName = productInfo.PName; detailModel.SkuId = productSku.SkuId; detailModel.SkuShowProp = bllMall.GetProductShowProperties(productSku.SkuId); detailModel.IsComplete = 1;//拼团的只要下单就算销量 detailList.Add(detailModel); } #endregion #region 纯积分购买 if (needUseScore > 0) { if ((CurrentUserInfo.TotalScore < needUseScore) || (orderRequestModel.use_score < needUseScore)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("您需要使用{0}积分来兑换, 可用积分不足", needUseScore); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion productFee = detailList.Sum(p => p.OrderPrice * p.TotalCount).Value;//商品费用 //物流费用 #region 运费计算 FreightModel freightModel = new FreightModel(); freightModel.receiver_province_code = orderRequestModel.receiver_province_code; freightModel.receiver_city_code = orderRequestModel.receiver_city_code; freightModel.receiver_dist_code = orderRequestModel.receiver_dist_code; freightModel.skus = orderRequestModel.skus; decimal freight = 0;//运费 string freightMsg = ""; if (!bllMall.CalcFreight(freightModel, out freight, out freightMsg)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = freightMsg; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } orderInfo.Transport_Fee = freight; #endregion #region 优惠券计算 decimal discountAmount = 0;//优惠金额 bool canUseCardCoupon = false; string msg = ""; if (orderRequestModel.cardcoupon_id > 0)//有优惠券 { discountAmount = bllMall.CalcDiscountAmount(orderRequestModel.cardcoupon_id.ToString(), data, CurrentUserInfo.UserID, out canUseCardCoupon, out msg); if (!canUseCardCoupon) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = msg; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (cardCouponType == "MallCardCoupon_FreeFreight")//免邮券 { orderInfo.Transport_Fee = 0; } } //优惠券计算 #endregion #region 积分计算 decimal scoreExchangeAmount = 0;///积分抵扣的金额 //积分计算 if (orderRequestModel.use_score > 0) { #region 使用宏巍积分 if (websiteInfo.IsUnionHongware == 1) { CurrentUserInfo.TotalScore = hongWeiWareMemberInfo.member.point; } #endregion if (CurrentUserInfo.TotalScore < orderRequestModel.use_score) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "积分不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } ScoreConfig scoreConfig = bllScore.GetScoreConfig(); if (scoreConfig != null && scoreConfig.ExchangeAmount > 0) { scoreExchangeAmount = Math.Round(orderRequestModel.use_score / (scoreConfig.ExchangeScore / scoreConfig.ExchangeAmount), 2); } //scoreExchangeAmount = Math.Round(orderRequestModel.use_score / (scoreConfig.ExchangeScore / scoreConfig.ExchangeAmount), 2); } //积分计算 #endregion #region 使用账户余额 if (orderRequestModel.use_amount > 0) { if (!bllMall.IsEnableAccountAmountPay()) { apiResp.msg = "尚未启用余额支付功能"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 使用宏巍余额 if (websiteInfo.IsUnionHongware == 1) { CurrentUserInfo.AccountAmount = (decimal)hongWeiWareMemberInfo.member.balance; } #endregion if (CurrentUserInfo.AccountAmount < orderRequestModel.use_amount) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "您的账户余额不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion //合计计算 orderInfo.Product_Fee = productFee; orderInfo.TotalAmount = orderInfo.Product_Fee + orderInfo.Transport_Fee; orderInfo.TotalAmount -= discountAmount; //优惠券优惠金额 orderInfo.TotalAmount -= scoreExchangeAmount; //积分优惠金额 orderInfo.TotalAmount -= orderRequestModel.use_amount; //余额 orderInfo.PayableAmount = orderInfo.TotalAmount - freight; //应付金额 orderInfo.ScoreExchangAmount = scoreExchangeAmount; //优惠券抵扣金额 orderInfo.CardcouponDisAmount = discountAmount; //卡券抵扣金额 if ((productFee + orderInfo.Transport_Fee - discountAmount - scoreExchangeAmount) < orderInfo.TotalAmount) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "积分兑换金额不能大于订单总金额,请减少积分兑换"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (orderInfo.TotalAmount < 0) { orderInfo.TotalAmount = 0; } if (orderInfo.TotalAmount == 0) { orderInfo.PaymentStatus = 1; orderInfo.PayTime = DateTime.Now; orderInfo.Status = "待发货"; } orderInfo.HeadDiscount = groupBuyRule.HeadDiscount; orderInfo.MemberDiscount = groupBuyRule.MemberDiscount; orderInfo.PeopleCount = groupBuyRule.PeopleCount; orderInfo.ExpireDay = groupBuyRule.ExpireDay; if (orderInfo.TotalAmount < needUseCash) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("最少需要支付{0}元" + needUseCash); context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { if (!this.bllMall.Add(orderInfo, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 更新优惠券使用状态 //优惠券 if (orderRequestModel.cardcoupon_id > 0 && (canUseCardCoupon == true))//有优惠券且已经成功使用 { MyCardCoupons myCardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, CurrentUserInfo.UserID); myCardCoupon.UseDate = DateTime.Now; myCardCoupon.Status = 1; if (!bllCardCoupon.Update(myCardCoupon, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新优惠券状态失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } //优惠券 #endregion #region 积分抵扣 //积分扣除 if (orderRequestModel.use_score > 0) { CurrentUserInfo.TotalScore -= orderRequestModel.use_score; if (bllMall.Update(CurrentUserInfo, string.Format(" TotalScore-={0}", orderRequestModel.use_score), string.Format(" AutoID={0}", CurrentUserInfo.AutoID), tran) < 0) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新用户积分失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //积分记录 UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = -orderRequestModel.use_score; scoreRecord.TotalScore = CurrentUserInfo.TotalScore; scoreRecord.ScoreType = "OrderSubmit"; scoreRecord.UserID = CurrentUserInfo.UserID; scoreRecord.AddNote = "微商城-开团使用积分"; scoreRecord.WebSiteOwner = CurrentUserInfo.WebsiteOwner; if (!bllMall.Add(scoreRecord, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "插入积分记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 更新宏巍积分 if (websiteInfo.IsUnionHongware == 1) { if (!hongWareClient.UpdateMemberScore(hongWeiWareMemberInfo.member.mobile, CurrentUserInfo.WXOpenId, -orderRequestModel.use_score)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新宏巍积分失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion } //积分扣除 #endregion #region 余额抵扣 if (orderRequestModel.use_amount > 0 && bllMall.IsEnableAccountAmountPay()) { CurrentUserInfo.AccountAmount -= orderRequestModel.use_amount; if (bllMall.Update(CurrentUserInfo, string.Format(" AccountAmount={0}", CurrentUserInfo.AccountAmount), string.Format(" AutoID={0}", CurrentUserInfo.AutoID)) < 0) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新用户余额失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = -(double)orderRequestModel.use_amount; scoreRecord.TotalScore = (double)CurrentUserInfo.AccountAmount; scoreRecord.UserID = CurrentUserInfo.UserID; scoreRecord.AddNote = "拼团-开团使用余额"; scoreRecord.RelationID = orderInfo.OrderID; scoreRecord.WebSiteOwner = bllUser.WebsiteOwner; scoreRecord.ScoreType = "AccountAmount"; if (!bllMall.Add(scoreRecord)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "插入余额记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } UserCreditAcountDetails record = new UserCreditAcountDetails(); record.WebsiteOwner = bllUser.WebsiteOwner; record.Operator = CurrentUserInfo.UserID; record.UserID = CurrentUserInfo.UserID; record.CreditAcount = -orderRequestModel.use_amount; record.SysType = "AccountAmount"; record.AddTime = DateTime.Now; record.AddNote = "账户余额变动-" + orderRequestModel.use_amount; if (!bllMall.Add(record)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "插入余额记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } #region 更新宏巍余额 if (websiteInfo.IsUnionHongware == 1) { if (!hongWareClient.UpdateMemberBlance(hongWeiWareMemberInfo.member.mobile, CurrentUserInfo.WXOpenId, -(float)orderRequestModel.use_amount)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "更新宏巍余额失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion } #endregion #region 插入订单详情表及更新库存 foreach (var item in detailList) { ProductSku productSku = bllMall.GetProductSku((int)(item.SkuId)); WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); if (!this.bllMall.Add(item, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } //更新 SKU库存 System.Text.StringBuilder sbUpdateStock = new StringBuilder();//更新库存sql sbUpdateStock.AppendFormat(" Update ZCJ_ProductSku Set Stock-={0} ", item.TotalCount); sbUpdateStock.AppendFormat(" Where SkuId={0} And Stock>0 ", productSku.SkuId); if (ZentCloud.ZCBLLEngine.BLLBase.ExecuteSql(sbUpdateStock.ToString(), tran) <= 0) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交订单失败,库存不足"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } } #endregion bllMall.DeleteShoppingCart(CurrentUserInfo.UserID, orderRequestModel.skus); tran.Commit();//提交订单事务 #region 宏巍通知 if (websiteInfo.IsUnionHongware == 1) { hongWareClient.OrderNotice(CurrentUserInfo.WXOpenId, orderInfo.OrderID); } #endregion #region 微信模板消息 try { string title = "订单已成功提交"; if (orderInfo.TotalAmount > 0) { title += ",请尽快付款"; } bllWeiXin.SendTemplateMessageNotifyComm(CurrentUserInfo, title, string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}", orderInfo.OrderID, orderInfo.TotalAmount, orderInfo.Consignee, orderInfo.Phone)); } catch { } #endregion } catch (Exception ex) { //回滚事物 tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交订单失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } apiResp.status = true; apiResp.msg = "ok"; apiResp.result = new { order_id = orderInfo.OrderID }; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); }
public void ProcessRequest(HttpContext context) { Add.ProductModel productRequestModel = new Add.ProductModel();//订单模型 try { productRequestModel = bllMall.ConvertRequestToModel <Add.ProductModel>(productRequestModel); } catch (Exception ex) { apiResp.msg = "提交格式错误"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } //数据检查 if (string.IsNullOrEmpty(productRequestModel.product_title)) { apiResp.msg = "商品名称必填"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } //if (productRequestModel.price == 0) //{ // apiResp.msg = "商品价格必填"; // apiResp.code = (int)APIErrCode.OperateFail; // bllMall.ContextResponse(context, apiResp); // return; //} //if (string.IsNullOrWhiteSpace(productRequestModel.show_imgs) && !productRequestModel.article_category_type.Contains("Added")) //{ // apiResp.msg = "请上传商品图片"; // apiResp.code = (int)APIErrCode.OperateFail; // bllMall.ContextResponse(context, apiResp); // return; //} WXMallProductInfo productInfo = bllMall.GetByKey <WXMallProductInfo>("PID", productRequestModel.product_id, true); if (productInfo == null) { apiResp.msg = "数据未找到"; apiResp.code = (int)APIErrCode.IsNotFound; bllMall.ContextResponse(context, apiResp); return; } productInfo.PName = productRequestModel.product_title; productInfo.PDescription = productRequestModel.product_desc; productInfo.Price = productRequestModel.price; productInfo.CategoryId = productRequestModel.category_id; productInfo.IsOnSale = productRequestModel.is_onsale.ToString(); productInfo.Stock = productRequestModel.totalcount;//(容纳人数) productInfo.Sort = productRequestModel.sort; //productInfo.UserID = currentUserInfo.UserID; productInfo.PreviousPrice = productRequestModel.price; productInfo.Summary = productRequestModel.product_summary; productInfo.LastUpdate = DateTime.Now; productInfo.RelationProductId = productRequestModel.relation_product_id; productInfo.AccessLevel = productRequestModel.access_Level; productInfo.Unit = productRequestModel.unit; if (!string.IsNullOrWhiteSpace(productRequestModel.show_imgs)) { productInfo.ShowImage = productRequestModel.show_imgs; List <string> imgs = productRequestModel.show_imgs.Split(',').Where(p => !string.IsNullOrWhiteSpace(p)).ToList(); productInfo.RecommendImg = imgs[0]; int max = imgs.Count > 5 ? 5 : imgs.Count; for (int i = 0; i < max; i++) { if (i == 0) { productInfo.ShowImage1 = imgs[0]; } else if (i == 1) { productInfo.ShowImage2 = imgs[1]; } else if (i == 2) { productInfo.ShowImage3 = imgs[2]; } else if (i == 3) { productInfo.ShowImage4 = imgs[3]; } else if (i == 4) { productInfo.ShowImage5 = imgs[4]; } } } string dSkuIds = ""; //默认第一条sku ProductSku productSku = bllMall.GetProductSku(productRequestModel.product_id); if (productSku == null) { //增加系统默认sku productSku = new ProductSku();// productSku.InsertDate = DateTime.Now; productSku.Stock = 1; productSku.WebSiteOwner = bllMall.WebsiteOwner; productSku.ArticleCategoryType = productInfo.ArticleCategoryType; } List <ProductSku> addSkuList = new List <ProductSku>(); List <ProductSku> updateSkuList = new List <ProductSku>(); if (productRequestModel.time_set_method == 0) { productSku.Price = productInfo.Price; updateSkuList.Add(productSku); List <ProductSku> dSkuList = bllMall.GetColList <ProductSku>(int.MaxValue, 1, string.Format("ProductId={0} AND SkuId!={1} ", productInfo.PID, productSku.SkuId), "SkuId"); if (dSkuList.Count > 0) { dSkuIds = ZentCloud.Common.MyStringHelper.ListToStr(dSkuList.Select(p => p.SkuId).ToList(), "", ","); } } else if (productRequestModel.time_set_method == 1 || productRequestModel.time_set_method == 2) { List <Add.timeModel> skuModelList = JSONHelper.JsonToModel <List <Add.timeModel> >(productRequestModel.time_data); string pSkuIds = ZentCloud.Common.MyStringHelper.ListToStr(skuModelList.Select(p => p.sku_id).ToList(), "", ","); if (string.IsNullOrWhiteSpace(pSkuIds)) { pSkuIds = "0"; } List <ProductSku> dSkuList = bllMall.GetColList <ProductSku>(int.MaxValue, 1, string.Format("ProductId={0} AND SkuId Not In ({1}) ", productInfo.PID, pSkuIds), "SkuId"); if (dSkuList.Count > 0) { dSkuIds = ZentCloud.Common.MyStringHelper.ListToStr(dSkuList.Select(p => p.SkuId).ToList(), "", ","); } foreach (Add.timeModel item in skuModelList) { ProductSku nSku = (ProductSku)productSku.Clone(); if (item.sku_id != 0) { nSku = bllMall.GetByKey <ProductSku>("SkuId", item.sku_id.ToString()); } nSku.PropValueIdEx1 = item.ex1; nSku.PropValueIdEx2 = item.ex2; nSku.PropValueIdEx3 = item.ex3; nSku.Price = item.price; if (item.sku_id != 0) { updateSkuList.Add(nSku); } else { addSkuList.Add(nSku); } } } BLLTransaction tran = new BLLTransaction(); bool result = bllMall.Update(productInfo, tran); if (!result) { tran.Rollback(); apiResp.msg = "更新失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } if (!string.IsNullOrWhiteSpace(dSkuIds)) { result = bllMall.DeleteMultByKey <ProductSku>("SkuId", dSkuIds, tran) >= 0; if (!result) { tran.Rollback(); apiResp.msg = "删除旧时间段失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } } foreach (ProductSku item in updateSkuList) { result = bllMall.Update(item, tran); if (!result) { tran.Rollback(); apiResp.msg = "修改Sku失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } } int productId = int.Parse(productInfo.PID); foreach (ProductSku item in addSkuList) { item.ProductId = productId; item.SkuId = int.Parse(bllMall.GetGUID(BLLJIMP.TransacType.AddProductSku)); result = bllMall.Add(item, tran); if (!result) { tran.Rollback(); apiResp.msg = "新增Sku失败"; apiResp.code = (int)APIErrCode.OperateFail; bllMall.ContextResponse(context, apiResp); return; } } tran.Commit(); apiResp.status = true; apiResp.msg = "更新完成"; apiResp.code = (int)APIErrCode.IsSuccess; bllMall.ContextResponse(context, apiResp); }
/// <summary> /// 获取商品列表 一般商品 /// </summary> /// <param name="context"></param> /// <returns></returns> private string List(HttpContext context) { int accessLevel = 0; int totalCount = 0; var sourceData = bllMall.GetProductList(context, out totalCount, accessLevel, false); var hasCateName = context.Request["has_cate_name"]; if (string.IsNullOrEmpty(hasCateName)) { hasCateName = ""; } string productIds = context.Request["product_ids"]; //商品IDs string sortIds = context.Request["sort_ids"]; //商品IDs排序 string canRepeat = context.Request["can_repeat"]; //商品IDs重复 dynamic list; if (!string.IsNullOrWhiteSpace(productIds) && sortIds == "1") { List <dynamic> relist = new List <dynamic>(); List <string> productIdList = productIds.Split(',').ToList(); List <string> productInIdList = new List <string>(); foreach (string productId in productIdList) { if (canRepeat != "1" && productInIdList.Contains(productId)) { continue; } WXMallProductInfo p = sourceData.FirstOrDefault(pi => pi.PID == productId); if (p == null) { continue; } productInIdList.Add(productId); relist.Add(new { product_id = p.PID, category_id = p.CategoryId, category_name = hasCateName == "1" ? bllMall.GetWXMallCategoryName(p.CategoryId) : "", title = p.PName, summary = p.Summary, access_level = p.AccessLevel, quote_price = p.PreviousPrice, price = bllMall.GetShowPrice(p), score = p.Score, img_url = bllMall.GetImgUrl(p.RecommendImg), is_onsale = (!string.IsNullOrEmpty(p.IsOnSale) && p.IsOnSale == "1") ? 1 : 0, tags = p.Tags, product_code = p.ProductCode, sale_count = p.SaleCount, review_count = p.ReviewCount, totalcount = bllMall.GetProductTotalStock(int.Parse(p.PID)), buy_time = p.LimitBuyTime, is_no_express = p.IsNoExpress, min_price = p.MinPrice, max_price = p.MaxPrice, is_appointment = p.IsAppointment, province = p.Province, city = p.City, district = p.District, ex1 = p.Ex1, group_buy_rule_list = string.IsNullOrWhiteSpace(p.GroupBuyRuleIds) ? null : from r in bllMall.GetProductGroupBuyRuleList(p.PID) select new { rule_id = r.RuleId, rule_name = r.RuleName, head_discount = r.HeadDiscount, head_price = Math.Round((decimal)p.Price * (decimal)(r.HeadDiscount / 10), 2), member_discount = r.MemberDiscount, member_price = Math.Round((decimal)p.Price * (decimal)(r.MemberDiscount / 10), 2), people_count = r.PeopleCount, expire_day = r.ExpireDay } }); } list = relist; totalCount = relist.Count; } else { list = from p in sourceData select new { product_id = p.PID, category_id = p.CategoryId, category_name = hasCateName == "1" ? bllMall.GetWXMallCategoryName(p.CategoryId) : "", title = p.PName, summary = p.Summary, access_level = p.AccessLevel, quote_price = p.PreviousPrice, price = bllMall.GetShowPrice(p), score = p.Score, img_url = bllMall.GetImgUrl(p.RecommendImg), is_onsale = (!string.IsNullOrEmpty(p.IsOnSale) && p.IsOnSale == "1") ? 1 : 0, tags = p.Tags, product_code = p.ProductCode, sale_count = p.SaleCount, review_count = p.ReviewCount, totalcount = bllMall.GetProductTotalStock(int.Parse(p.PID)), buy_time = p.LimitBuyTime, is_no_express = p.IsNoExpress, min_price = p.MinPrice, max_price = p.MaxPrice, is_appointment = p.IsAppointment, province = p.Province, city = p.City, district = p.District, ex1 = p.Ex1, group_buy_rule_list = string.IsNullOrWhiteSpace(p.GroupBuyRuleIds) ? null : from r in bllMall.GetProductGroupBuyRuleList(p.PID) select new { rule_id = r.RuleId, rule_name = r.RuleName, head_discount = r.HeadDiscount, head_price = Math.Round((decimal)p.Price * (decimal)(r.HeadDiscount / 10), 2), member_discount = r.MemberDiscount, member_price = Math.Round((decimal)p.Price * (decimal)(r.MemberDiscount / 10), 2), people_count = r.PeopleCount, expire_day = r.ExpireDay } }; } var data = new { totalcount = totalCount, list = list//列表 }; //return ZentCloud.Common.JSONHelper.ObjectToJson(data); return(JsonConvert.SerializeObject(data)); }
public void ProcessRequest(HttpContext context) { string orderId = context.Request["order_id"]; if (string.IsNullOrEmpty(orderId)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "order_id 必传"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(orderId); if (orderInfo == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "订单号不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (orderInfo.OrderType != 2) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "不是拼团订单"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } if (!string.IsNullOrEmpty(orderInfo.GroupBuyParentOrderId)) { orderInfo = bllMall.GetOrderInfo(orderInfo.GroupBuyParentOrderId); } if (orderInfo.PaymentStatus == 0) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "团长订单未付款"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); return; } WXMallOrderDetailsInfo orderDetail = bllMall.GetOrderDetail(orderInfo.OrderID).First(); WXMallProductInfo productInfo = bllMall.GetProduct(orderDetail.PID); ProductSku skuInfo = bllMall.GetProductSku((int)orderDetail.SkuId); decimal kk = Math.Round((decimal)productInfo.Price * (decimal)(orderInfo.MemberDiscount / 10), 2); apiResp.result = new { order_id = orderInfo.OrderID, product_id = productInfo.PID, product_name = productInfo.PName, summary = productInfo.Summary, priduct_price = productInfo.Price, product_price = productInfo.Price, product_img_url = bllMall.GetImgUrl(productInfo.RecommendImg), product_properties = bllMall.GetProductProperties(skuInfo.SkuId), product_desc = productInfo.PDescription, is_join = IsJoin(orderInfo), people_list = GetPeopleList(orderInfo), head_discount = orderInfo.HeadDiscount, head_price = Math.Round((decimal)productInfo.Price * (decimal)(orderInfo.HeadDiscount / 10), 2), member_discount = orderInfo.MemberDiscount, member_price = Math.Round((decimal)productInfo.Price * (decimal)(orderInfo.MemberDiscount / 10), 2), people_count = orderInfo.PeopleCount, pay_people_count = GetPayPeopleCount(orderInfo), expire_day = orderInfo.ExpireDay, is_head = IsHead(orderInfo), group_buy_status = GetGroupBuyStatus(orderInfo), end_time = bllMall.GetTimeStamp(((DateTime)orderInfo.PayTime).AddDays(orderInfo.ExpireDay)), pay_order_id = GetNeedPayOrderId(orderInfo), score = productInfo.Score, is_cashpay_only = productInfo.IsCashPayOnly, is_no_express = productInfo.IsNoExpress, sku_id = skuInfo.SkuId, ex10 = orderInfo.Ex10 }; apiResp.status = true; apiResp.msg = "ok"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); }
public void ProcessRequest(HttpContext context) { string productId = context.Request["product_id"]; WXMallProductInfo productInfo = bllMall.GetByKey <WXMallProductInfo>("PID", productId, true); if (productInfo == null) { apiResp.msg = "数据未找到"; apiResp.code = (int)APIErrCode.IsNotFound; bllMall.ContextResponse(context, apiResp); return; } List <WXMallProductInfo> relList = new List <WXMallProductInfo>(); if (!string.IsNullOrWhiteSpace(productInfo.RelationProductId)) { string pIDStrings = "'" + productInfo.RelationProductId.Replace(",", "','") + "'"; relList = bllMall.GetColMultListByKey <WXMallProductInfo>(int.MaxValue, 1, "PID", pIDStrings, "PID,PName,Price,Unit", true); } if (relList.Count == 0) { productInfo.RelationProductId = ""; } else { relList = relList.Distinct().ToList(); productInfo.RelationProductId = ZentCloud.Common.MyStringHelper.ListToStr(relList.Select(p => p.PID).ToList(), "", ","); } List <ProductSku> skuList = bllMall.GetColList <ProductSku>(int.MaxValue, 1, string.Format("ProductId={0}", productInfo.PID), "SkuId,ProductId,PropValueIdEx1,PropValueIdEx2,PropValueIdEx3,Price"); apiResp.result = new { product_id = productInfo.PID, product_title = productInfo.PName, category_id = productInfo.CategoryId, product_summary = productInfo.Summary, product_desc = productInfo.PDescription, price = productInfo.Price, unit = productInfo.Unit, is_onsale = productInfo.IsOnSale, totalcount = productInfo.Stock, sort = productInfo.Sort, access_Level = productInfo.AccessLevel, show_imgs = productInfo.ShowImage, relation_products = from p in relList select new { product_id = p.PID, title = p.PName, price = p.Price, unit = p.Unit }, sku_list = from p in skuList select new { id = p.SkuId, price = p.Price, start = p.PropValueIdEx1, end = p.PropValueIdEx2, week = p.PropValueIdEx3 } }; apiResp.status = true; apiResp.msg = "查询完成"; apiResp.code = (int)APIErrCode.IsSuccess; bllMall.ContextResponse(context, apiResp); }