/// <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)); }
/// <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)); }
/// <summary> /// 短信提醒 /// </summary> /// <param name="context"></param> /// <returns></returns> private string SmsRemind(HttpContext context) { string promotionActivityId = context.Request["promotion_activity_id"];//限时特卖活动ID string phone = context.Request["phone"]; string smsContent = context.Request["sms_content"]; string sendTime = context.Request["send_time"]; if (!bllMall.IsLogin) { resp.errcode = 1; resp.errmsg = "请先登录"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } var currentUserInfo = bllMall.GetCurrentUserInfo(); if (string.IsNullOrEmpty(promotionActivityId)) { resp.errcode = 1; resp.errmsg = "promotion_activity_id 参数不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (string.IsNullOrEmpty(phone)) { resp.errcode = 1; resp.errmsg = "phone 参数不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if ((!phone.StartsWith("1")) || (!phone.Length.Equals(11))) { resp.errcode = 2; resp.errmsg = "手机号格式不正确"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (string.IsNullOrEmpty(smsContent)) { resp.errcode = 1; resp.errmsg = "sms_content 不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (string.IsNullOrEmpty(sendTime)) { resp.errcode = 1; resp.errmsg = "send_time 参数不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } //检查是否已经有记录提醒 if (IsRemind(promotionActivityId, currentUserInfo.UserID) > 0) { resp.errcode = 1; resp.errmsg = "已经添加提醒"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } bool isSuccess = false; string msg = ""; string smsSignature = bllSms.GetWebsiteInfoModelFromDataBase().SmsSignature;//短信签名 if (string.IsNullOrEmpty(smsSignature)) { smsSignature = "至云"; } bllSms.SendSmsMisson(phone, smsContent, sendTime, smsSignature, out isSuccess, out msg); if (isSuccess) { CommRelationInfo model = new CommRelationInfo(); model.MainId = promotionActivityId; model.RelationId = currentUserInfo.UserID; model.RelationTime = DateTime.Now; model.RelationType = "PromotionSmsRemind"; if (bllMall.Add(model)) { resp.errcode = 0; resp.errmsg = "ok"; } else { resp.errcode = 4; resp.errmsg = string.Format("提交提醒失败", msg); } } else { resp.errcode = 4; resp.errmsg = string.Format("提交失败,错误码{0}", msg); } return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }
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) { 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); }
/// <summary> /// 同意退款申请,提交退货地址接口 /// </summary> /// <param name="context"></param> /// <returns></returns> private string AgreeAndSubmitRefundAddress(HttpContext context) { string orderDetailId = context.Request["order_detail_id"]; string refundAddress = context.Request["refund_address"]; if (string.IsNullOrEmpty(orderDetailId)) { resp.errcode = 1; resp.errmsg = "order_detail_id 参数不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (string.IsNullOrEmpty(refundAddress)) { resp.errcode = 1; resp.errmsg = "退货地址不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } WXMallRefund model = bllMall.GetRefundInfoByOrderDetailId(int.Parse(orderDetailId)); model.Status = 1; model.RefundAddress = refundAddress; WXMallOrderDetailsInfo orderDetail = bllMall.GetOrderDetail(model.OrderDetailId); orderDetail.RefundStatus = model.Status.ToString(); if (!bllMall.Update(orderDetail)) { resp.errcode = 1; resp.errmsg = "操作失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (bllMall.Update(model)) { resp.errmsg = "ok"; //插入维权记录 WXMallRefundLog log = new WXMallRefundLog(); log.OrderDetailId = model.OrderDetailId; log.Role = "商家"; log.Title = "同意退款申请"; log.LogContent = string.Format("退货地址:{0}", model.RefundAddress); log.InsertDate = DateTime.Now; log.WebSiteOwner = bllMall.WebsiteOwner; bllMall.Add(log); //插入维权记录 try { var result = yikeClient.UpdateRefundStatus(model); } catch (Exception) { } //if (bllPer.CheckPermissionKey(bllMall.WebsiteOwner, ZentCloud.BLLPermission.Enums.PermissionSysKey.PMS_TRANSFERSAUDIT)) //{ // string tranInfo = string.Format("订单号:{0}<br/>退款金额:{1}<br/>{2}", model.OrderId, model.RefundAmount, log.LogContent); // if (bllTran.Add("MallRefund", model.RefundId, tranInfo, model.RefundAmount)) // { // string title = string.Format("收到退款申请"); // string content = string.Format("订单号:{0}退款金额:{1}", model.OrderId, model.RefundAmount); // string url = string.Format("http://{0}/app/transfersaudit/list.aspx", System.Web.HttpContext.Current.Request.Url.Host); // //发送微信模板消息 // bllWeixin.SendTemplateMessageToKefuTranAuditPer(title, content, url); // } // else // { // resp.errcode = 1; // resp.errmsg = "操作失败"; // return ZentCloud.Common.JSONHelper.ObjectToJson(resp); // } //} } else { resp.errcode = 1; resp.errmsg = "操作失败"; } return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; currentUserInfo = bllUser.GetCurrentUserInfo(); string data = context.Request["data"]; decimal productFee = 0; //商品总价格 不包含邮费 OrderRequestModel orderRequestModel = new OrderRequestModel(); //订单模型 try { orderRequestModel = ZentCloud.Common.JSONHelper.JsonToModel <OrderRequestModel>(data); } catch (Exception ex) { resp.errcode = 1; resp.errmsg = "JSON格式错误,请检查。错误信息:" + ex.Message; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } WXMallOrderInfo orderInfo = new WXMallOrderInfo();//订单表 orderInfo.InsertDate = DateTime.Now; orderInfo.OrderUserID = currentUserInfo.UserID; orderInfo.WebsiteOwner = bllMall.WebsiteOwner; orderInfo.Transport_Fee = 0; orderInfo.OrderID = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder); orderInfo.OrderMemo = orderRequestModel.buyer_memo; orderInfo.MyCouponCardId = orderRequestModel.cardcoupon_id.ToString(); orderInfo.UseScore = orderRequestModel.use_score; orderInfo.Status = "待付款"; orderInfo.OrderType = 1; if (orderRequestModel.pay_type == "WEIXIN")//微信支付 { orderInfo.PaymentType = 2; } else if (orderRequestModel.pay_type == "ALIPAY")//支付宝支付 { orderInfo.PaymentType = 1; } #region 格式检查 //相关检查 if (orderRequestModel.skus == null) { resp.errcode = 1; resp.errmsg = "参数skus 不能为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } //相关检查 #endregion #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) { resp.errcode = 1; resp.errmsg = "SKU不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString()); 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 (bllMall.IsPromotionTime(productSku)) { if (sku.count > productSku.PromotionStock) { resp.errcode = 1; resp.errmsg = string.Format("{0}{1}特卖库存余量为{2},库存不足,请减少购买数量", productInfo.PName, bllMall.GetProductShowProperties(productSku.SkuId), productSku.PromotionStock); 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; detailModel.OrderPrice = bllMall.GetSkuPrice(productSku); detailModel.ProductName = productInfo.PName; detailModel.SkuId = productSku.SkuId; detailModel.SkuShowProp = bllMall.GetProductShowProperties(productSku.SkuId); detailList.Add(detailModel); } #endregion productFee = detailList.Sum(p => p.OrderPrice * p.TotalCount).Value;//商品费用 //物流费用 #region 运费计算 FreightModel freightModel = new FreightModel(); freightModel.skus = orderRequestModel.skus; decimal freight = 0;//运费 string freightMsg = ""; 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 #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) { 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; } } //优惠券计算 #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); } #region 驿氪积分同步 #endregion //积分计算 #endregion //合计计算 orderInfo.Product_Fee = productFee; orderInfo.TotalAmount = orderInfo.Product_Fee + orderInfo.Transport_Fee; 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; } 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; } //积分记录 WXMallScoreRecord scoreRecord = new WXMallScoreRecord(); scoreRecord.InsertDate = DateTime.Now; scoreRecord.OrderID = orderInfo.OrderID; scoreRecord.Score = orderRequestModel.use_score; scoreRecord.Type = 1; scoreRecord.UserId = currentUserInfo.UserID; scoreRecord.WebsiteOwner = bllMall.WebsiteOwner; scoreRecord.Remark = "积分抵扣"; 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库存 productSku.Stock -= item.TotalCount; if (bllMall.IsPromotionTime(productSku)) { productSku.PromotionStock -= item.TotalCount; } if (!bllMall.Update(productSku, tran)) { tran.Rollback(); resp.errcode = 1; resp.errmsg = "更新SKU失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion tran.Commit();//提交订单事务 } catch (Exception ex) { //回滚事物 tran.Rollback(); resp.errcode = 1; resp.errmsg = ex.Message; 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 })); }
/// <summary> /// 接收活动转赠 /// </summary> /// <param name="context"></param> /// <returns></returns> private string ReceiveActivity(HttpContext context) { if (currentUserInfo==null) { resp.Msg = "请在微信中打开"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } string activityId = context.Request["ActivityId"];//活动ID string fromUserAutoId = context.Request["FromUserAutoId"];//赠送用户ID JuActivityInfo juActivityInfo = bllJuactivity.GetJuActivityByActivityID(activityId); //检查 if (juActivityInfo == null) { resp.Msg = "转赠活动不存在"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } UserInfo fromUserInfo = bllUser.GetUserInfoByAutoID(int.Parse(fromUserAutoId)); if (fromUserInfo == null) { resp.Msg = "转赠用户不存在"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } WXSignInInfo signInfo = bllActivity.Get<WXSignInInfo>(string.Format(" JuActivityID='{0}' And SignInUserID='{1}'", juActivityInfo.JuActivityID, fromUserInfo.UserID)); if (signInfo!=null) { resp.Msg = "不能接受此转赠"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } ActivityDataInfo dataInfo = bllActivity.Get<ActivityDataInfo>(string.Format(" ActivityID='{0}' And UserId='{1}' And IsDelete=0 And OrderId!='' And PaymentStatus=1", activityId, fromUserInfo.UserID)); if (dataInfo == null) { resp.Msg = " 不能接受此转赠"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } if (fromUserInfo.UserID==currentUserInfo.UserID) { resp.Msg = "不能接收自己的转赠"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } if (!string.IsNullOrEmpty(dataInfo.ToUserId)) { if (dataInfo.ToUserId == currentUserInfo.UserID) { resp.Msg = " 您已经接收过转赠"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } else { resp.Msg = " 此活动已经转赠过了"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } } ActivityDataInfo dataCurrentInfo = bllActivity.Get<ActivityDataInfo>(string.Format(" ActivityID='{0}' And UserId='{1}' And IsDelete=0", activityId,currentUserInfo.UserID)); if (dataCurrentInfo!=null) { resp.Msg = " 您已经报名过此活动,不能再接受转赠"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } WXMallOrderInfo fromUserOrderInfo = bllMall.GetOrderInfo(dataInfo.OrderId); ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { //订单 WXMallOrderInfo orderInfo = new WXMallOrderInfo();//订单表 orderInfo.Consignee = bllUser.GetUserDispalyName(currentUserInfo); orderInfo.InsertDate = DateTime.Now; orderInfo.OrderUserID = currentUserInfo.UserID; orderInfo.Phone = currentUserInfo.Phone; orderInfo.WebsiteOwner = bllMall.WebsiteOwner; orderInfo.OrderID = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder); orderInfo.MyCouponCardId = fromUserOrderInfo.MyCouponCardId; orderInfo.UseScore = fromUserOrderInfo.UseScore; orderInfo.Status = "待发货"; orderInfo.ArticleCategoryType = "Mall"; orderInfo.OrderType = 4; orderInfo.Ex1 = juActivityInfo.ActivityName; orderInfo.Ex2 = orderInfo.Ex2; orderInfo.Ex3 = orderInfo.Ex3; orderInfo.OrderMemo = orderInfo.OrderMemo; orderInfo.TotalAmount = fromUserOrderInfo.TotalAmount; orderInfo.PaymentStatus = 1; orderInfo.PayTime = DateTime.Now; //订单 if (!bllMall.Add(orderInfo,tran)) { tran.Rollback(); resp.Msg = " 插入订单表失败"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } ActivityDataInfo newData = new ActivityDataInfo(); newData.ActivityID = dataInfo.ActivityID; newData.UserId = currentUserInfo.UserID; newData.WebsiteOwner = bllUser.WebsiteOwner; newData.OrderId =orderInfo.OrderID; newData.PaymentStatus = 1; newData.Name = bllUser.GetUserDispalyName(currentUserInfo); newData.Phone = currentUserInfo.Phone; newData.FromUserId = fromUserInfo.UserID; newData.InsertDate = DateTime.Now; newData.UID = bllJuactivity.Get<ActivityDataInfo>(string.Format(" ActivityID='{0}' Order By UID DESC",activityId)).UID + 1; if (!bllJuactivity.Add(newData, tran)) { tran.Rollback(); resp.Msg = " 插入报名表失败"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } dataInfo.ToUserId = currentUserInfo.UserID; if (!bllJuactivity.Update(dataInfo,tran)) { tran.Rollback(); resp.Msg = " 转赠失败"; return ZentCloud.Common.JSONHelper.ObjectToJson(resp); } string showName = "活动"; var config = bllActivity.Get<BLLJIMP.Model.ActivityConfig>(string.Format(" WebsiteOwner='{0}'", bllActivity.WebsiteOwner)); if (config!=null) { if (!string.IsNullOrEmpty(config.ShowName)) { showName = config.ShowName; } } bllWeixin.SendTemplateMessageNotifyComm(fromUserInfo, string.Format("{0}转赠通知",showName), string.Format(" {0}已接收你转赠的{1}{2}", bllUser.GetUserDispalyName(currentUserInfo),showName,juActivityInfo.ActivityName)); bllWeixin.SendTemplateMessageNotifyComm(currentUserInfo, string.Format("{0}接收通知",showName), string.Format(" 您已接收了{0}转赠的{1}{2}", bllUser.GetUserDispalyName(fromUserInfo), showName,juActivityInfo.ActivityName)); tran.Commit(); resp.Status = 1; resp.Msg = "ok"; } catch (Exception ex) { resp.Msg = ex.Message; tran.Rollback(); } return ZentCloud.Common.JSONHelper.ObjectToJson(resp); }
public void ProcessRequest(HttpContext context) { string orderSn = context.Request["order_sn"]; //订单号 string status = context.Request["status"]; //订单状态 1001 确认收货 1002取消订单 if (string.IsNullOrEmpty(orderSn)) { resp.code = (int)APIErrCode.PrimaryKeyIncomplete; resp.msg = "order_sn 参数必传"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(status)) { resp.code = (int)APIErrCode.PrimaryKeyIncomplete; resp.msg = "status 参数必传"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } var orderInfo = bllMall.GetOrderInfoByOutOrderId(orderSn); if (orderInfo == null) { resp.code = (int)APIErrCode.PrimaryKeyIncomplete; resp.msg = "order_sn 不存在,请检查"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, bllUser.WebsiteOwner); switch (status) { #region 确认收货 case "1001": //确认收货 if (orderInfo.Status == "交易成功") { resp.code = (int)APIErrCode.OperateFail; resp.msg = "重复操作"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (orderInfo.PaymentStatus == 0) { resp.code = (int)APIErrCode.OperateFail; resp.msg = "订单未付款"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (orderInfo.Status == "已取消") { resp.code = (int)APIErrCode.OperateFail; resp.msg = "订单已取消"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); //交易成功处理 try { orderInfo.Status = "交易成功"; orderInfo.ReceivingTime = DateTime.Now; if (!bllMall.Update(orderInfo, tran)) { tran.Rollback(); resp.code = (int)APIErrCode.OperateFail; resp.msg = "更新订单状态失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } #region 交易成功加积分 //增加积分 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) { orderUserInfo.TotalScore += addScore; UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = addScore; scoreRecord.TotalScore = orderUserInfo.TotalScore; scoreRecord.ScoreType = "OrderSuccess"; scoreRecord.UserID = orderUserInfo.UserID; scoreRecord.AddNote = "微商城-交易成功获得积分"; scoreRecord.WebSiteOwner = bllMall.WebsiteOwner; if (!bllMall.Add(scoreRecord, tran)) { tran.Rollback(); resp.code = (int)APIErrCode.OperateFail; resp.msg = "插入积分记录表失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (bllUser.Update(orderUserInfo, string.Format(" TotalScore+={0},HistoryTotalScore+={0}", addScore), string.Format(" AutoID={0}", orderUserInfo.AutoID), tran) < 1) { tran.Rollback(); resp.code = (int)APIErrCode.OperateFail; resp.msg = "更新用户积分失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion // #region 更新订单明细表状态 List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID); foreach (var orderDetail in orderDetailList) { orderDetail.IsComplete = 1; if (!bllMall.Update(orderDetail)) { tran.Rollback(); resp.code = (int)APIErrCode.OperateFail; resp.msg = "更新订单明细表失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion } catch (Exception ex) { tran.Rollback(); resp.code = (int)APIErrCode.OperateFail; resp.msg = ex.Message; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } tran.Commit(); resp.code = 0; resp.msg = "ok"; resp.status = true; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; //交易成功处理 #endregion #region 取消订单 case "1002": //取消订单 if (orderInfo.Status == "已取消") { resp.code = (int)APIErrCode.OperateFail; resp.msg = "重复操作"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } ZentCloud.ZCBLLEngine.BLLTransaction tranCancel = new ZCBLLEngine.BLLTransaction(); try { orderInfo.Status = "已取消"; if (!bllMall.Update(orderInfo, tranCancel)) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = "更新订单状态失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID); foreach (var orderDetail in orderDetailList) { if (orderDetail.SkuId != null) { ProductSku sku = bllMall.GetProductSku((int)orderDetail.SkuId); if (sku != null) { if (bllMall.Update(sku, string.Format(" Stock+={0}", orderDetail.TotalCount), string.Format(" SkuId={0}", sku.SkuId), tranCancel) == 0) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = "修改sku库存失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } } } if (bllMall.Update(new WXMallOrderDetailsInfo(), "IsComplete=0", string.Format(" OrderId='{0}'", orderInfo.OrderID), tranCancel) <= 0) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = "更新订单详情失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } #region 积分返还 if (orderInfo.UseScore > 0) //使用积分 积分返还 { orderUserInfo.TotalScore += orderInfo.UseScore; if (bllUser.Update(orderUserInfo, string.Format(" TotalScore+={0}", orderInfo.UseScore), string.Format(" AutoID={0}", orderUserInfo.AutoID)) < 0) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = "积分返还失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = orderInfo.UseScore; scoreRecord.TotalScore = orderUserInfo.TotalScore; scoreRecord.ScoreType = "OrderCancel"; scoreRecord.UserID = orderUserInfo.UserID; scoreRecord.RelationID = orderInfo.OrderID; scoreRecord.WebSiteOwner = bllMall.WebsiteOwner; scoreRecord.AddNote = "微商城-订单取消返还积分"; if (!bllMall.Add(scoreRecord)) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = "插入积分记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion #region 优惠券返还 if (!string.IsNullOrEmpty(orderInfo.MyCouponCardId)) { var myCardCoupon = bllCardCoupon.GetMyCardCoupon(int.Parse(orderInfo.MyCouponCardId), orderUserInfo.UserID); if (myCardCoupon != null && myCardCoupon.Status == 1) { myCardCoupon.Status = 0; if (!bllCardCoupon.Update(myCardCoupon)) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = "优惠券更新失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } } #endregion #region 账户余额返还 if (orderInfo.UseAmount > 0) { orderUserInfo.AccountAmount += orderInfo.UseAmount; if (bllMall.Update(orderUserInfo, string.Format(" AccountAmount={0}", orderUserInfo.AccountAmount), string.Format(" AutoID={0}", orderUserInfo.AutoID)) < 0) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = "更新用户余额失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo(); scoreRecord.AddTime = DateTime.Now; scoreRecord.Score = (double)orderInfo.UseAmount; scoreRecord.TotalScore = (double)orderUserInfo.AccountAmount; scoreRecord.ScoreType = "AccountAmount"; scoreRecord.UserID = orderUserInfo.UserID; scoreRecord.RelationID = orderInfo.OrderID; scoreRecord.WebSiteOwner = bllMall.WebsiteOwner; scoreRecord.AddNote = "微商城-订单取消返还余额"; if (!bllMall.Add(scoreRecord)) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = "插入余额记录失败"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } } #endregion tranCancel.Commit(); resp.code = 0; resp.msg = "ok"; resp.status = true; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } catch (Exception ex) { tranCancel.Rollback(); resp.code = (int)APIErrCode.OperateFail;; resp.msg = ex.Message; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } #endregion default: resp.code = (int)APIErrCode.OperateFail; resp.msg = "不合法的 status 值"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } }