示例#1
0
文件: Get.ashx.cs 项目: uvbs/mmp
        /// <summary>
        /// 获取成员列表
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public List <object> GetPeopleList(WXMallOrderInfo orderInfo)
        {
            List <object>          list      = new List <object>();
            List <WXMallOrderInfo> orderList = new List <WXMallOrderInfo>();

            if (orderInfo != null && orderInfo.Ex10 == "1")//系统开团
            {
                orderList = bllMall.GetList <WXMallOrderInfo>(string.Format("GroupBuyParentOrderId='{0}'  And OrderType=2 And WebsiteOwner='{1}'  And PaymentStatus=1 order by InsertDate ASC", orderInfo.OrderID, bllMall.WebsiteOwner));
            }
            else
            {
                orderList = bllMall.GetList <WXMallOrderInfo>(string.Format("GroupBuyParentOrderId='{0}'  And OrderType=2 And WebsiteOwner='{1}'  And PaymentStatus=1 Or OrderId='{0}' order by InsertDate ASC", orderInfo.OrderID, bllMall.WebsiteOwner));
            }

            foreach (var order in orderList)
            {
                UserInfo userInfo = bllUser.GetUserInfo(order.OrderUserID);
                list.Add(new
                {
                    head_img_url = bllUser.GetUserDispalyAvatar(userInfo),
                    show_name    = userInfo.WXNickname != null?userInfo.WXNickname:"",
                    pay_time     = bllMall.GetTimeStamp((DateTime)order.PayTime),
                    user_id      = userInfo.UserID,
                });
            }
            return(list);
        }
示例#2
0
文件: Get.ashx.cs 项目: uvbs/mmp
        /// <summary>
        /// 获取拼团状态
        /// 0 拼团中
        /// 1 拼团成功
        /// 2 拼团过期失败
        /// </summary>
        /// <param name="orderInfo">团长订单</param>
        /// <returns></returns>
        public int GetGroupBuyStatus(WXMallOrderInfo orderInfo)
        {
            if (orderInfo.GroupBuyStatus == "1")
            {
                return(1);
            }
            int           status = -1;
            StringBuilder sbSql  = new StringBuilder();

            sbSql.AppendFormat("  PaymentStatus=1  ");
            if (orderInfo.Ex10 == "1")
            {
                sbSql.AppendFormat(" And GroupBuyParentOrderId='{0}' ", orderInfo.OrderID);
            }
            else
            {
                sbSql.AppendFormat(" And (GroupBuyParentOrderId='{0}' Or OrderId='{0}') ", orderInfo.OrderID);
            }
            if ((bllMall.GetCount <WXMallOrderInfo>(sbSql.ToString()) < orderInfo.PeopleCount) && (DateTime.Now < ((DateTime)orderInfo.PayTime).AddDays(orderInfo.ExpireDay)))
            {
                return(0);//拼团中
            }
            else if (bllMall.GetCount <WXMallOrderInfo>(sbSql.ToString()) >= orderInfo.PeopleCount)
            {
                return(1);//拼团成功
            }
            if (DateTime.Now >= ((DateTime)orderInfo.PayTime).AddDays(orderInfo.ExpireDay))
            {
                return(2);//拼团过期失败
            }
            return(status);
        }
示例#3
0
        /// <summary>
        /// 商户同意取消申请 type=23
        /// </summary>
        public void MerchantAgreeCencel(ElemeRequset reqEleme, WebsiteInfo websiteModel)
        {
            ToLog("商户同意取消申请=" + reqEleme.message);
            var sign  = reqEleme.signature;
            var value = GetSign(reqEleme, websiteModel);

            if (sign == value)
            {
                RespApplyCencel oorder    = ZentCloud.Common.JSONHelper.JsonToModel <RespApplyCencel>(reqEleme.message);
                WXMallOrderInfo mallOrder = bllMall.Get <WXMallOrderInfo>(string.Format(" WebsiteOwner='{0}' AND OutOrderId='{1}'", websiteModel.WebsiteOwner, oorder.orderId));
                if (mallOrder != null)
                {
                    mallOrder.Status         = "已取消";
                    mallOrder.IsRefund       = 0;
                    mallOrder.OutOrderStatus = GetRefStatus(oorder.refundStatus);
                    bllMall.Update(mallOrder);
                }
                resp.msg = "ok";
            }
            else
            {
                resp.msg = "验签错误";
            }
            Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
示例#4
0
文件: Get.ashx.cs 项目: uvbs/mmp
 /// <summary>
 /// 是否团长
 /// </summary>
 /// <param name="orderInfo"></param>
 /// <returns></returns>
 public int IsHead(WXMallOrderInfo orderInfo)
 {
     if (CurrentUserInfo.UserID == orderInfo.OrderUserID)
     {
         return(1);
     }
     return(0);
 }
示例#5
0
        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)
            }));
        }
示例#6
0
文件: Get.ashx.cs 项目: uvbs/mmp
 /// <summary>
 /// 获取已经参加拼团的人数
 /// </summary>
 /// <param name="orderId"></param>
 /// <returns></returns>
 public int GetPayPeopleCount(WXMallOrderInfo order)
 {
     if (order.Ex10 == "1")
     {
         return(bllMall.GetCount <WXMallOrderInfo>(string.Format("GroupBuyParentOrderId='{0}'  And OrderType=2 And WebsiteOwner='{1}'  And PaymentStatus=1  ", order.OrderID, bllMall.WebsiteOwner)));
     }
     else
     {
         return(bllMall.GetCount <WXMallOrderInfo>(string.Format("GroupBuyParentOrderId='{0}'  And OrderType=2 And WebsiteOwner='{1}'  And PaymentStatus=1 Or (OrderId='{0}' And PaymentStatus=1) ", order.OrderID, bllMall.WebsiteOwner)));
     }
 }
示例#7
0
        /// <summary>
        /// 增加冻结积分记录:
        /// 真正返积分是确认收货7天退货期过后
        /// 返积分按冻结记录去返,以解决:如果用户7天后升级,防止下单的时候冻结的数量跟真正分的数量不一样
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public bool AddLockScoreByOrder(WXMallOrderInfo orderInfo)
        {
            ToLog("into AddLockScoreByOrder");
            BLLWeixin bllWeiXin = new BLLWeixin();
            bool      result    = false;

            //获取是否已经存有的冻结积分
            var lockModel = GetLockScoreByOrder(orderInfo.OrderID);

            if (lockModel != null)
            {
                return(true);
            }

            ToLog("AddLockScoreByOrder 计算获得积分");
            //计算获得积分
            var addScore = CalcOrderRebateScore(orderInfo);

            ToLog("AddLockScoreByOrder addScore:" + addScore);
            //如获得积分则存入冻结表
            if (addScore > 0)
            {
                ToLog("AddLockScoreByOrder 存入冻结表");
                ScoreLockInfo scoreLockInfo = new ScoreLockInfo()
                {
                    ForeignkeyId = orderInfo.OrderID,
                    LockStatus   = 0,
                    LockTime     = DateTime.Now,
                    LockType     = 1,
                    Score        = addScore,
                    UserId       = orderInfo.OrderUserID,
                    WebsiteOwner = orderInfo.WebsiteOwner
                };

                if (Add(scoreLockInfo))
                {
                    ToLog("AddLockScoreByOrder 存入冻结表成功");
                    result = true;

                    //发送通知;
                    string url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/lockscores#/lockscores", HttpContext.Current.Request.Url.Host);
                    bllWeiXin.SendTemplateMessageNotifyComm(GetCurrentUserInfo(), "您有一笔即将到账积分",
                                                            string.Format("下单获得 {0} 积分,点击查看", addScore),
                                                            url);
                }
                else
                {
                    ToLog("AddLockScoreByOrder 存入冻结表失败");
                }
            }

            return(result);
        }
示例#8
0
文件: Get.ashx.cs 项目: uvbs/mmp
 /// <summary>
 /// 是否需要继续支付
 /// </summary>
 /// <param name="orderInfo">团长订单</param>
 /// <returns>需要支付的订单号</returns>
 private string GetNeedPayOrderId(WXMallOrderInfo orderInfo)
 {
     if (GetGroupBuyStatus(orderInfo) == 0)//拼团中
     {
         var myOrderInfo = bllMall.Get <WXMallOrderInfo>(string.Format(" WebsiteOwner='{0}' And PaymentStatus=0 And GroupBuyParentOrderId='{1}' And OrderUserId='{2}'", bllMall.WebsiteOwner, orderInfo.OrderID, CurrentUserInfo.UserID));
         if (myOrderInfo != null)
         {
             return(myOrderInfo.OrderID);
         }
     }
     return("");
 }
示例#9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string orderid = null;

            orderid = Request["oid"];
            if (string.IsNullOrEmpty(orderid))
            {
                Response.End();
            }

            if (bll.IsLogin)
            {
                userInfo  = bll.GetCurrentUserInfo();
                OrderInfo = bll.GetOrderInfo(orderid);
                if (OrderInfo == null)
                {
                    Response.End();
                }

                bool CanAccess = false;
                if (!OrderInfo.OrderUserID.Equals(userInfo.UserID))
                {
                    try
                    {
                        if (bll.GetWebsiteInfoModel().IsDistributionMall.Equals(1))
                        {
                            //检查是否是上下级关系
                            BLLJIMP.BLLDistribution bllDis  = new BLLJIMP.BLLDistribution();
                            BLLJIMP.BLLUser         bllUser = new BLLJIMP.BLLUser("");
                            if (bllDis.GetUserBetweenLevel(userInfo, bllUser.GetUserInfo(OrderInfo.OrderUserID)) > 0)
                            {
                                CanAccess = true;
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    CanAccess = true;
                }
                if (!CanAccess)
                {
                    Response.End();
                }
            }
            else
            {
                Response.Redirect("/App/Cation/Wap/Login.aspx?redirecturl=/App/Cation/Wap/Mall/Index.aspx");
            }
        }
示例#10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     currentWebsiteInfo = bllMall.GetWebsiteInfoModel();
     if (Request["gopage"] != null)
     {
         GoPage = Request["gopage"];
     }
     if (Request["orderdetailpage"] != null)
     {
         OrderDetailPage = Request["orderdetailpage"];
     }
     Order = bllMall.GetOrderInfo(Request["oid"].ToString());
 }
示例#11
0
文件: Get.ashx.cs 项目: uvbs/mmp
 /// <summary>
 /// 是否已经参加
 /// </summary>
 /// <param name="orderId"></param>
 /// <returns></returns>
 public int IsJoin(WXMallOrderInfo orderInfo)
 {
     if (IsHead(orderInfo) == 1)
     {
         return(1);
     }
     else
     {
         if (bllMall.GetCount <WXMallOrderInfo>(string.Format(" OrderUserID='{0}' And GroupBuyParentOrderId='{1}'", CurrentUserInfo.UserID, orderInfo.OrderID)) > 0)
         {
             return(1);
         }
     }
     return(0);
 }
示例#12
0
文件: Get.ashx.cs 项目: uvbs/mmp
        public void ProcessRequest(HttpContext context)
        {
            string order_id = context.Request["order_id"];//订单状态 中文字符串
            WXMallOrderInfo orderInfo = bllMall.GetByKey<WXMallOrderInfo>("OrderID", order_id, true);
            var orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID);
            var orderMainDetailList = orderDetailList.Where(p => p.ArticleCategoryType == orderInfo.ArticleCategoryType).ToList();
            var orderAddedDetailList = orderDetailList.Where(p => p.ArticleCategoryType != orderInfo.ArticleCategoryType).ToList();
            var mainProduct = bllMall.GetByKey<WXMallProductInfo>("PID", orderMainDetailList[0].PID, true);
            apiResp.result = new
            {
                order_id = orderInfo.OrderID,
                order_time = orderInfo.InsertDate.ToString("yyyy-MM-dd HH:mm:ss"),
                product_name = orderMainDetailList[0].ProductName,
                price = orderMainDetailList[0].OrderPrice,
                unit = orderMainDetailList[0].Unit,
                img = mainProduct.RecommendImg,
                show_imgs = mainProduct.ShowImage,
                total_amount = orderInfo.TotalAmount,
                order_status = orderInfo.Status,
                is_pay = orderInfo.PaymentStatus,
                pay_type = orderInfo.PaymentType == 2 ? "WEIXIN" : "ALIPAY",
                use_score=orderInfo.UseScore,
                use_amount=orderInfo.UseAmount,
                order_details = from p in orderMainDetailList
                                select new
                                {
                                    start_date = p.StartDate.ToString("yyyy-MM-dd HH:mm:ss"),
                                    end_date = p.EndDate.ToString("yyyy-MM-dd HH:mm:ss")
                                },
                added_details = from p in orderAddedDetailList
                                select new
                                {
                                    product_name = p.ProductName,
                                    price = p.OrderPrice,
                                    count = p.TotalCount,
                                    unit = p.Unit
                                }

            };
            apiResp.status = true;
            apiResp.code = (int)APIErrCode.IsSuccess;
            bllMall.ContextResponse(context, apiResp);
        }
示例#13
0
 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));
     }
 }
示例#14
0
        public void ProcessRequest(HttpContext context)
        {
            int    pageIndex = !string.IsNullOrEmpty(context.Request["pageindex"]) ? int.Parse(context.Request["pageindex"]) : 1;
            int    pageSize  = !string.IsNullOrEmpty(context.Request["pagesize"]) ? int.Parse(context.Request["pagesize"]) : 10;
            string orderID   = context.Request["order_id"];

            if (string.IsNullOrEmpty(orderID))
            {
                apiResp.msg  = "订单号为空";
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.IsNotFound;
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                return;
            }
            WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(orderID);

            if (orderInfo == null)
            {
                apiResp.msg  = "订单号不存在";
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.IsNotFound;
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
                return;
            }
            int totalCount = 0;
            var sourceData = bllLog.List(pageIndex, pageSize, null, null, null, null, out totalCount, orderID);
            var list       = from p in sourceData
                             select new
            {
                remark      = p.Remark,
                insert_time = bllLog.GetTimeStamp(p.InsertDate)
            };

            apiResp.status = true;
            apiResp.msg    = "ok";
            apiResp.result = new
            {
                totalcount = totalCount,
                list       = list,//列表
            };
            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp));
        }
示例#15
0
        /// <summary>
        ///修改退款状态为重新打开
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string ReOpen(HttpContext context)
        {
            string orderDetailId = context.Request["order_detail_id"];

            if (string.IsNullOrEmpty(orderDetailId))
            {
                resp.errcode = 1;
                resp.errmsg  = "order_detail_id 参数不能为空";
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            WXMallRefund model = bllMall.GetRefundInfoByOrderDetailId(int.Parse(orderDetailId));

            model.Status = 0;
            if (bllMall.Update(model))
            {
                resp.errmsg = "ok";
                WXMallRefundLog log = new WXMallRefundLog();
                log.OrderDetailId = model.OrderDetailId;
                log.Role          = "商家";
                log.Title         = "修改退款状态为重新打开";
                log.LogContent    = string.Format("修改退款状态为重新打开");
                log.InsertDate    = DateTime.Now;
                log.WebSiteOwner  = model.WebSiteOwner;
                bllMall.Add(log);
                WXMallOrderDetailsInfo orderDetail = bllMall.GetOrderDetail(model.OrderDetailId);
                orderDetail.RefundStatus = "0";
                bllMall.Update(orderDetail);
                WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(orderDetail.OrderID);
                if (orderInfo.IsRefund == 0)
                {
                    bllMall.Update(orderInfo, string.Format(" IsRefund=1"), string.Format(" OrderID='{0}'", orderInfo.OrderID));
                }
            }
            else
            {
                resp.errcode = 1;
                resp.errmsg  = "操作失败";
            }
            return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
示例#16
0
        /// <summary>
        /// 批量设置交易完成状态
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string UpdateDealStatus(HttpContext context)
        {
            string activityId = context.Request["ActivityID"];
            string uId        = context.Request["UID"];

            string[]         ids   = uId.Split(',');
            ActivityDataInfo model = new ActivityDataInfo();

            foreach (var item in ids)
            {
                model = bllActivity.GetActivityDataInfo(activityId, int.Parse(item));
                if (model.Status == 1)
                {
                    continue;
                }
                model.Status = 1;
                if (!bllActivity.Update(model))
                {
                    continue;
                }
                else
                {
                    WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(model.OrderId);
                    if (orderInfo != null)
                    {
                        orderInfo.Status             = "交易成功";
                        orderInfo.DistributionStatus = 2;
                        string msg = "";
                        if (bllDis.Transfers(orderInfo, out msg))
                        {
                            orderInfo.DistributionStatus = 3;
                        }
                        bllMall.Update(orderInfo);
                    }
                }
            }
            resp.Status = 1;
            return(Common.JSONHelper.ObjectToJson(resp));
        }
示例#17
0
文件: Refund.ashx.cs 项目: uvbs/mmp
        /// <summary>
        /// 处理最后一件运费退款情况
        /// </summary>
        /// <param name="model"></param>
        /// <param name="orderInfo"></param>
        /// <param name="refundList"></param>
        /// <param name="overTransportFee"></param>
        /// <param name="canRefundAmount"></param>
        /// <param name="canRefundAccountAmount"></param>
        private void DealTransportFeeRefund(
            ref MaxRefundInfo model,
            WXMallOrderInfo orderInfo,
            List <WXMallRefund> refundList

            )
        {
            var overTransportFee       = orderInfo.Transport_Fee;                                            //当前已计算抵掉的运费
            var canRefundAmount        = orderInfo.TotalAmount - refundList.Sum(p => p.RefundAmount);        //当前可退最大金额
            var canRefundAccountAmount = orderInfo.UseAmount - (refundList.Sum(p => p.RefundAccountAmount)); //当前可退最大余额

            //把金额、余额、积分都退掉,并且保证可退金额跟余额不大于邮费,剩余的积分则可以全部都退掉
            if (overTransportFee > 0)
            {
                if (canRefundAmount >= overTransportFee)
                {
                    model.max_refund_amount += overTransportFee;
                    overTransportFee         = 0;
                }
                else
                {
                    model.max_refund_amount += canRefundAmount;
                    overTransportFee        -= canRefundAmount;
                }
            }
            if (overTransportFee > 0)
            {
                if (canRefundAccountAmount >= overTransportFee)
                {
                    model.max_refund_account_amount += overTransportFee;
                    overTransportFee = 0;
                }
                else
                {
                    model.max_refund_account_amount += canRefundAccountAmount;
                    overTransportFee -= canRefundAccountAmount;
                }
            }
        }
示例#18
0
        /// <summary>
        /// 订单用户信息
        /// </summary>
        //public UserInfo OrderUserInfo;
        protected void Page_Load(object sender, EventArgs e)
        {
            orderId = Request["oid"];
            if (string.IsNullOrEmpty(orderId))
            {
                Response.End();
            }
            orderInfo = bllMall.GetOrderInfo(orderId);
            if (orderInfo == null)
            {
                Response.End();
            }
            orderDetailList = bllMall.GetOrderDetailsList(orderId);
            foreach (var item in bllMall.GetOrderStatuList())
            {
                sbOrderStatuList.AppendFormat("<option  value=\"{0}\" >{1}</option>", item.OrderStatu, item.OrderStatu);
            }
            //foreach (var item in bll.GetWXMallDeliveryStaff())
            //{
            //    sbDeliveryStaffList.AppendFormat("<option  value=\"{0}\" >{1}</option>", item.AutoID, item.StaffName);

            //}
            //OrderUserInfo = new BLLJIMP.BLLUser("").GetUserInfo(orderInfo.OrderUserID,bllMall.WebsiteOwner);
        }
示例#19
0
        /// <summary>
        /// 订单已完成 type=18
        /// </summary>
        /// <param name="oorderInfo"></param>
        /// <param name="websiteOwner"></param>
        public void ReceiptConfirm(ElemeRequset reqEleme, WebsiteInfo websiteModel)
        {
            var sign  = reqEleme.signature;
            var value = GetSign(reqEleme, websiteModel);

            if (sign == value)
            {
                RespApplyCencel oorder    = ZentCloud.Common.JSONHelper.JsonToModel <RespApplyCencel>(reqEleme.message);
                WXMallOrderInfo mallOrder = bllMall.Get <WXMallOrderInfo>(string.Format(" WebsiteOwner='{0}' AND OutOrderId='{1}'", websiteModel.WebsiteOwner, oorder.orderId));
                if (mallOrder != null)
                {
                    mallOrder.Status         = "交易成功";
                    mallOrder.ReceivingTime  = DateTime.Now;
                    mallOrder.OutOrderStatus = GetRefStatus(oorder.refundStatus);
                    bllMall.Update(mallOrder);
                }
                resp.msg = "ok";
            }
            else
            {
                resp.msg = "验签错误";
            }
            Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
示例#20
0
文件: Refund.ashx.cs 项目: uvbs/mmp
        /// <summary>
        /// 获取最多的退款信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private MaxRefundInfo GetMaxRefundInfoModel(string orderDetailId)
        {
            MaxRefundInfo                 model           = new MaxRefundInfo();
            WXMallOrderDetailsInfo        orderDetail     = bllMall.GetOrderDetail(int.Parse(orderDetailId));
            WXMallOrderInfo               orderInfo       = bllMall.GetOrderInfo(orderDetail.OrderID);
            List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID);
            List <WXMallRefund>           refundList      = bllMall.GetList <WXMallRefund>(string.Format(" OrderId='{0}'", orderInfo.OrderID));

            var     productTotalProce = ((decimal)orderDetailList.Sum(p => p.OrderPrice * p.TotalCount));
            decimal rate = 0;

            if (productTotalProce > 0)
            {
                rate = ((decimal)orderDetail.OrderPrice * orderDetail.TotalCount) / ((decimal)orderDetailList.Sum(p => p.OrderPrice * p.TotalCount));//此商品所占的比例
            }
            model.max_refund_amount = orderDetail.MaxRefundAmount;

            //商品单独需要的积分不在均摊计算范围内
            int singelProductTotalScore = orderDetail.OrderScore * orderDetail.TotalCount,
                allProductTotalScore    = orderDetailList.Sum(p => p.OrderScore * p.TotalCount);

            //foreach (var item in orderDetailList)
            //{
            //    allProductTotalScore += item.OrderScore * item.TotalCount;
            //}

            orderInfo.UseScore -= allProductTotalScore;

            if (orderInfo.UseScore > 0)
            {
                model.max_refund_score = (int)(orderInfo.UseScore * rate);//可退积分
            }
            else
            {
                orderInfo.UseScore = 0;
            }

            if (orderInfo.UseAmount > 0)
            {
                model.max_refund_account_amount = Math.Round(orderInfo.UseAmount * rate, 2, MidpointRounding.AwayFromZero); //可退余额
            }
            if (orderDetailList.Count == 1 && (string.IsNullOrEmpty(orderInfo.ExpressNumber)))                              //只买了一种商品且未发货
            {
                //model.max_refund_amount += orderInfo.Transport_Fee;
                DealTransportFeeRefund(ref model, orderInfo, refundList);

                model.max_refund_score = orderInfo.UseScore;

                //if (orderInfo.UseScore > 0)
                //{
                //    if (refundList != null && refundList.Count > 0)
                //    {
                //        model.max_refund_score = orderInfo.UseScore - (refundList.Sum(p => p.RefundScore));
                //        if (model.max_refund_score < 0)
                //        {
                //            model.max_refund_score = 0;
                //        }
                //    }
                //}

                if ((bllMall.GetCount <WXMallRefund>(string.Format(" OrderId='{0}'", orderInfo.OrderID)) == orderDetailList.Count - 1) && (string.IsNullOrEmpty(orderInfo.ExpressNumber)))//只有一种商品且未发货
                {
                    model.is_contain_transport_fee = 1;
                }
            }
            else
            {
                #region 处理最后一种商品的情况
                if ((refundList != null) && (refundList.Count == (orderDetailList.Count - 1))) //最后一种商品
                {
                    if (string.IsNullOrEmpty(orderInfo.ExpressNumber))                         //最后一件商品未发货
                    {
                        //model.max_refund_amount += orderInfo.Transport_Fee;
                        DealTransportFeeRefund(ref model, orderInfo, refundList);

                        model.is_contain_transport_fee = 1;
                    }

                    #region 最后一种商品的退还积分
                    if (orderInfo.UseScore > 0)
                    {
                        if (refundList != null && refundList.Count > 0)
                        {
                            model.max_refund_score = orderInfo.UseScore - (refundList.Sum(p => p.RefundScore));
                            if (model.max_refund_score < 0)
                            {
                                model.max_refund_score = 0;
                            }
                        }
                    }
                    #endregion

                    #region 最后一种商品的余额退款
                    if (orderInfo.UseAmount > 0)
                    {
                        if (refundList != null && refundList.Count > 0)
                        {
                            model.max_refund_account_amount = orderInfo.UseAmount - (refundList.Sum(p => p.RefundAccountAmount));
                            if (model.max_refund_account_amount < 0)
                            {
                                model.max_refund_account_amount = 0;
                            }
                        }
                    }
                    #endregion
                }
                #endregion
            }

            if (singelProductTotalScore > 0)
            {
                model.max_refund_score += singelProductTotalScore;
            }

            //如果最大退款金额比实付金额还大,则说明有问题,最大退款金额重置为 0,在处理老的订单运费逻辑,重置为0是正确的,其他情况如有不对根据具体情况再分析

            if (model.max_refund_amount > orderInfo.TotalAmount + orderInfo.Transport_Fee)
            {
                model.max_refund_amount = 0;
            }

            return(model);
        }
示例#21
0
文件: Refund.ashx.cs 项目: uvbs/mmp
        /// <summary>
        /// 关闭退款申请
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Close(HttpContext context)
        {
            string       orderDetailId = context.Request["order_detail_id"];
            WXMallRefund model         = bllMall.GetRefundInfoByOrderDetailId(int.Parse(orderDetailId));

            model.Status = 7;
            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("买家已经关闭退款申请");
                log.InsertDate    = DateTime.Now;
                log.WebSiteOwner  = bllMall.WebsiteOwner;
                bllMall.Add(log);
                //插入维权记录
                try
                {
                    if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, bllCommRelation.WebsiteOwner, ""))
                    {
                        var result = yikeClient.UpdateRefundStatus(model);
                    }
                }
                catch (Exception)
                {
                }

                WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(model.OrderId);
                orderInfo.IsRefund = 0;
                bllMall.Update(orderInfo);

                //查询订单是否还有退款,如果没有退款了,而且还有暂时取消的冻结积分记录,则反取消积分
                var lockScoreModel = bllScore.GetLockScoreByOrder(orderInfo.OrderID);
                if (lockScoreModel != null)
                {
                    if (lockScoreModel.LockStatus == 2 && bllOrder.GetOrderHasRefundCount(orderInfo.OrderID) == 0)
                    {
                        bllScore.UnCancelLockScoreByOrder(orderInfo.OrderID, DateTime.Now.ToString() + " 订单退款已全部关闭,恢复取消的即将到账积分 ");
                    }
                }
            }
            else
            {
                resp.errcode = 1;
                resp.errmsg  = "";
            }


            return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
示例#22
0
文件: Refund.ashx.cs 项目: uvbs/mmp
        /// <summary>
        /// 申请退款
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Add(HttpContext context)
        {
            string             data = context.Request["data"];
            RefundRequestModel refundRequest;//订单模型

            try
            {
                refundRequest = ZentCloud.Common.JSONHelper.JsonToModel <RefundRequestModel>(data);


                //检查
                if (refundRequest.order_detail_id == 0)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "order_detail_id 参数不能为空";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                if (string.IsNullOrEmpty(refundRequest.refund_reason))
                {
                    resp.errcode = 1;
                    resp.errmsg  = "请填写理由";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                //if (refundRequest.refund_amount <= 0)
                //{
                //    resp.errcode = 1;
                //    resp.errmsg = "refund_amount 参数不能小于等于0";
                //    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);

                //}
                if (string.IsNullOrEmpty(refundRequest.phone))
                {
                    resp.errcode = 1;
                    resp.errmsg  = "请填写手机号";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                if (bllMall.GetRefundInfoByOrderDetailId(refundRequest.order_detail_id) != null)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "重复提交";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                //检查
                WXMallOrderDetailsInfo orderDetail = bllMall.GetOrderDetail(refundRequest.order_detail_id);
                if (orderDetail == null)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "订单详情不存在";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }


                var maxRefundInfo = GetMaxRefundInfoModel(refundRequest.order_detail_id.ToString());
                if (refundRequest.refund_amount > maxRefundInfo.max_refund_amount)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "最大退款金额不能大于" + maxRefundInfo.max_refund_amount + "元";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }

                WXMallOrderInfo orderInfo = bllMall.GetOrderInfo(orderDetail.OrderID);

                if (orderInfo.Status == "已取消" || orderInfo.Status == "待付款")
                {
                    resp.errcode = 1;
                    resp.errmsg  = "无权访问";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }

                if (orderInfo.OrderUserID != currentUserInfo.UserID)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "无权访问";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }

                if (bllMall.GetCount <WXMallOrderInfo>(string.Format("OrderType=0 And ParentOrderId='{0}'", orderInfo.OrderID)) > 0)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "主订单不能申请退款";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }

                //判断是否已参与分佣金,已分佣的订单不能申请退款
                if (bllMall.HasOrderCommission(orderInfo.OrderID))
                {
                    resp.errcode = 1;
                    resp.errmsg  = "订单已参与分佣,不能退款";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }

                //判断是否已经分积分,已经分积分的不能申请退款
                var lockScoreModel = bllScore.GetLockScoreByOrder(orderInfo.OrderID);
                if (lockScoreModel != null)
                {
                    if (lockScoreModel.LockStatus == 1)
                    {
                        resp.errcode = 1;
                        resp.errmsg  = "订单已返积分到账,不能退款";
                        return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    }
                }

                //拆单的判断父订单是否已经分积分,已经分积分的不能申请退款

                if (!string.IsNullOrWhiteSpace(orderInfo.ParentOrderId))
                {
                    var lockScoreParentModel = bllScore.GetLockScoreByOrder(orderInfo.ParentOrderId);
                    if (lockScoreParentModel != null)
                    {
                        if (lockScoreParentModel.LockStatus == 1)
                        {
                            resp.errcode = 1;
                            resp.errmsg  = "订单已返积分到账,不能退款";
                            return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        }
                    }
                }

                #region 礼品订单
                if (orderInfo.OrderType == 1)
                {
                    if (string.IsNullOrEmpty(orderInfo.ParentOrderId))
                    {
                        //子订单已经发货,不能退款
                        if (bllMall.GetCount <WXMallOrderInfo>(string.Format(" ParentOrderId='{0}' And ExpressNumber!=''", orderInfo.OrderID)) > 0)
                        {
                            resp.errcode = 1;
                            resp.errmsg  = "礼品已经发货,不能退款";
                            return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        }
                    }
                    else//子订单不能退款
                    {
                        resp.errcode = 1;
                        resp.errmsg  = "礼品订单不能退款";
                        return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    }
                }
                #endregion



                WXMallRefund model = new BLLJIMP.Model.WXMallRefund();
                model.RefundId        = string.Format("{0}{1}", DateTime.Now.ToString("yyyyMMddHHmm"), bllMall.GetGUID(BLLJIMP.TransacType.CommAdd));
                model.OrderDetailId   = refundRequest.order_detail_id;
                model.UserId          = currentUserInfo.UserID;
                model.RefundReason    = refundRequest.refund_reason;
                model.RefundAmount    = refundRequest.refund_amount;
                model.Phone           = refundRequest.phone;
                model.Remark          = refundRequest.remark;
                model.IsReturnProduct = refundRequest.is_return_product;
                model.ProductStatus   = refundRequest.product_status;
                model.ProductName     = orderDetail.ProductName;
                model.UpdateTime      = DateTime.Now;
                //ProductSku productSku = bllMall.GetProductSku((int)orderDetail.SkuId);
                //if (productSku == null)
                //{
                //    resp.errcode = 1;
                //    resp.errmsg = "sku已被删除";
                //    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
                //}
                //model.SkuSn = productSku.SkuSN;
                if (refundRequest.imagelist != null && refundRequest.imagelist.Length > 0)
                {
                    model.ImageList = string.Join(",", refundRequest.imagelist);
                }
                model.Status              = 0;
                model.InsertDate          = DateTime.Now;
                model.WebSiteOwner        = bllMall.WebsiteOwner;
                model.OrderId             = orderDetail.OrderID;
                model.OpenId              = currentUserInfo.WXOpenId;
                model.RefundScore         = refundRequest.refund_score;
                model.RefundAccountAmount = refundRequest.refund_account_amount;
                orderDetail.RefundStatus  = model.Status.ToString();

                if (refundRequest.refund_score > 0 || refundRequest.refund_account_amount > 0)
                {
                    if (refundRequest.refund_score > maxRefundInfo.max_refund_score)
                    {
                        resp.errcode = 1;
                        resp.errmsg  = "最多退还积分不能大于" + maxRefundInfo.max_refund_score;
                        return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    }
                    if (refundRequest.refund_account_amount > maxRefundInfo.max_refund_account_amount)
                    {
                        resp.errcode = 1;
                        resp.errmsg  = "最多退还余额不能大于" + maxRefundInfo.max_refund_account_amount;
                        return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    }
                }
                model.IsContainTransportFee = maxRefundInfo.is_contain_transport_fee;
                if (!bllMall.Update(orderDetail))
                {
                    resp.errcode = 1;
                    resp.errmsg  = "申请失败";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                if (bllMall.Add(model))
                {
                    string isReturnProduct = "并退货";
                    if (model.IsReturnProduct == 0)
                    {
                        isReturnProduct = "不退货";
                    }
                    resp.errmsg = "ok";
                    //插入维权记录
                    WXMallRefundLog log = new WXMallRefundLog();
                    log.OrderDetailId = model.OrderDetailId;
                    log.Role          = "买家";
                    log.Title         = "发起了退款申请,等待商家处理";
                    log.LogContent    = string.Format("退款原因:{0}<br/>期望结果:我要退款,{1}<br/>退款金额:{2}元<br/>退还积分:{3}<br/>退还余额:{4}<br/>退款说明:{5}<br/>联系电话:{6},货物状态:{7}", model.RefundReason, isReturnProduct, model.RefundAmount, model.RefundScore, model.RefundAccountAmount, model.Remark, model.Phone, model.ProductStatus);
                    log.InsertDate    = DateTime.Now;
                    log.WebSiteOwner  = bllMall.WebsiteOwner;
                    bllMall.Add(log);
                    //插入维权记录

                    if (orderInfo.IsRefund == 0)
                    {
                        bllMall.Update(orderInfo, string.Format(" IsRefund=1"), string.Format(" OrderID='{0}'", orderInfo.OrderID));
                    }
                    var websiteInfo = bllMall.GetWebsiteInfoModelFromDataBase();
                    if (websiteInfo.IsHaveUnReadRefundOrder == 0)
                    {
                        websiteInfo.IsHaveUnReadRefundOrder = 1;
                        bllMall.Update(websiteInfo);
                    }
                    try
                    {
                        if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, bllCommRelation.WebsiteOwner, ""))
                        {
                            var result = yikeClient.Refund(model);
                        }
                    }
                    catch (Exception)
                    {
                    }


                    //暂时取消积分
                    if (lockScoreModel != null)
                    {
                        if (lockScoreModel.LockStatus == 0)
                        {
                            bllScore.CancelLockScoreByOrder(orderInfo.OrderID, DateTime.Now.ToString() + " 申请退款暂时取消积分");
                        }
                    }

                    if (model.IsReturnProduct == 0)//不退货
                    {
                        if (bllPer.CheckPermissionKey(orderInfo.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  = "申请失败";
                }
            }
            catch (Exception ex)
            {
                resp.errcode = 1;
                resp.errmsg  = "JSON格式错误,请检查。错误信息:" + ex.Message;
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }

            return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
示例#23
0
文件: Refund.ashx.cs 项目: uvbs/mmp
        /// <summary>
        /// 修改退款信息(重新提交退款申请)
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Update(HttpContext context)
        {
            string             data = context.Request["data"];
            RefundRequestModel refundRequest;//订单模型

            try
            {
                refundRequest = ZentCloud.Common.JSONHelper.JsonToModel <RefundRequestModel>(data);


                //检查
                if (refundRequest.order_detail_id == 0)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "order_detail_id 参数不能为空";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                if (string.IsNullOrEmpty(refundRequest.refund_reason))
                {
                    resp.errcode = 1;
                    resp.errmsg  = "请填写理由";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                //if (refundRequest.refund_amount <= 0)
                //{
                //    resp.errcode = 1;
                //    resp.errmsg = "refund_amount 参数不能小于等于0";
                //    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);

                //}
                if (string.IsNullOrEmpty(refundRequest.phone))
                {
                    resp.errcode = 1;
                    resp.errmsg  = "请填写手机号";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                var maxRefundInfo = GetMaxRefundInfoModel(refundRequest.order_detail_id.ToString());
                if (refundRequest.refund_amount > maxRefundInfo.max_refund_amount)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "最大退款金额不能大于" + maxRefundInfo.max_refund_amount + "元";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                if (refundRequest.refund_score > 0 || refundRequest.refund_account_amount > 0)
                {
                    if (refundRequest.refund_score > maxRefundInfo.max_refund_score)
                    {
                        resp.errcode = 1;
                        resp.errmsg  = "最多退还积分不能大于" + maxRefundInfo.max_refund_score;
                        return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    }
                    if (refundRequest.refund_account_amount > maxRefundInfo.max_refund_account_amount)
                    {
                        resp.errcode = 1;
                        resp.errmsg  = "最多退还余额不能大于" + maxRefundInfo.max_refund_account_amount;
                        return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    }
                }

                //检查
                WXMallRefund model = bllMall.GetRefundInfoByOrderDetailId(refundRequest.order_detail_id);
                model.OrderDetailId       = refundRequest.order_detail_id;
                model.UserId              = currentUserInfo.UserID;
                model.RefundReason        = refundRequest.refund_reason;
                model.RefundAmount        = refundRequest.refund_amount;
                model.RefundScore         = refundRequest.refund_score;
                model.RefundAccountAmount = refundRequest.refund_account_amount;
                model.Phone           = refundRequest.phone;
                model.Remark          = refundRequest.remark;
                model.IsReturnProduct = refundRequest.is_return_product;
                if (refundRequest.imagelist != null && refundRequest.imagelist.Length > 0)
                {
                    model.ImageList = string.Join(",", refundRequest.imagelist);
                }

                model.Status             = 0;
                model.InsertDate         = DateTime.Now;
                model.RefundAddress      = "";
                model.RefuseReason       = "";
                model.ExpressCompanyCode = "";
                model.ExpressCompanyName = "";
                model.ExpressNumber      = "";
                model.ProductStatus      = refundRequest.product_status;
                model.UpdateTime         = DateTime.Now;
                WXMallOrderDetailsInfo orderDetail = bllMall.GetOrderDetail(model.OrderDetailId);
                WXMallOrderInfo        orderInfo   = bllMall.GetOrderInfo(orderDetail.OrderID);
                orderDetail.RefundStatus = model.Status.ToString();
                if (!bllMall.Update(orderDetail))
                {
                    resp.errcode = 1;
                    resp.errmsg  = "操作失败";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                if (bllMall.Update(model))
                {
                    string isReturnProduct = "并退货";
                    if (model.IsReturnProduct == 0)
                    {
                        isReturnProduct = "不退货";
                    }
                    resp.errmsg = "ok";
                    //插入维权记录
                    WXMallRefundLog log = new WXMallRefundLog();
                    log.OrderDetailId = model.OrderDetailId;
                    log.Role          = "买家";
                    log.Title         = "修改了退款申请,等待商家处理";
                    log.LogContent    = string.Format("退款原因:{0}<br/>期望结果:我要退款,{1}<br/>退款金额:{2}元<br/>退还积分:{3}<br/>退还余额:{4}<br/>退款说明:{5}<br/>联系电话:{6},货物状态:{7}", model.RefundReason, isReturnProduct, model.RefundAmount, model.RefundScore, model.RefundAccountAmount, model.Remark, model.Phone, model.ProductStatus);
                    log.InsertDate    = DateTime.Now;
                    log.WebSiteOwner  = bllMall.WebsiteOwner;
                    bllMall.Add(log);
                    if (orderInfo.IsRefund == 0)
                    {
                        bllMall.Update(orderInfo, string.Format(" IsRefund=1"), string.Format(" OrderID='{0}'", orderInfo.OrderID));
                    }
                    var websiteInfo = bllMall.GetWebsiteInfoModelFromDataBase();
                    if (websiteInfo.IsHaveUnReadRefundOrder == 0)
                    {
                        websiteInfo.IsHaveUnReadRefundOrder = 1;
                        bllMall.Update(websiteInfo);
                    }
                    //插入维权记录
                    try
                    {
                        if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, bllCommRelation.WebsiteOwner, ""))
                        {
                            var result = yikeClient.UpdateRefundStatus(model);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    resp.errcode = 1;
                    resp.errmsg  = "申请失败";
                }
            }
            catch (Exception ex)
            {
                resp.errcode = 1;
                resp.errmsg  = "JSON格式错误,请检查。错误信息:" + ex.Message;
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }

            return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
示例#24
0
        /// <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));
        }
示例#25
0
        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));
        }
示例#26
0
文件: Get.ashx.cs 项目: uvbs/mmp
        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));
        }
示例#27
0
文件: Join.ashx.cs 项目: uvbs/mmp
        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));
        }
示例#28
0
        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);
        }
示例#29
0
        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);
            }
        }
示例#30
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Request["oid"] == null)
                {
                    Response.Write("订单无效");
                    Response.End();
                }
                int OrderId;
                if (!int.TryParse(Request["oid"], out OrderId))
                {
                    Response.Write("订单无效");
                    Response.End();
                }
                Order = bllMall.GetOrderInfo(Request["oid"]);
                if (Order == null)
                {
                    Response.Write("订单无效");
                    Response.End();
                }
                if (!Order.PaymentStatus.Equals(0))
                {
                    Response.Write("订单不是未付款状态");
                    Response.End();
                }
                if (!Order.PaymentType.Equals(1))
                {
                    Response.Write("订单不属于支付宝支付");
                    Response.End();
                }
                if (string.IsNullOrEmpty(Order.PaymentTypeAutoId))
                {
                    Response.Write("无效支付方式");
                    Response.End();
                }
                WXMallPaymentType paymentType = bllMall.GetPaymentType(int.Parse(Order.PaymentTypeAutoId));
                if (paymentType == null)
                {
                    Response.Write("无效支付方式");
                    Response.End();
                }


                //支付宝网关地址
                string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?";

                ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token////////////////////////////////////////////

                //返回格式
                string format = "xml";
                //必填,不需要修改

                //返回格式
                string v = "2.0";
                //必填,不需要修改

                //请求号
                string req_id = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(0, 99999);
                //必填,须保证每次请求都是唯一

                //req_data详细信息

                //服务器异步通知页面路径
                string notify_url = string.Format("http://{0}/alipay/mallnotifyurl.aspx", Request.Url.Host);
                //需http://格式的完整路径,不允许加?id=123这类自定义参数

                //页面跳转同步通知页面路径
                string call_back_url = string.Format("http://{0}/alipay/mallcall_back_url.aspx", Request.Url.Host);
                //需http://格式的完整路径,不允许加?id=123这类自定义参数

                //操作中断返回地址
                string merchant_url = string.Format("http://{0}/alipay/merchanturl.aspx", Request.Url.Host);
                //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数

                //卖家支付宝帐户
                //string seller_email = "*****@*****.**";

                string seller_email = paymentType.AlipaySeller_Account_Name;
                //必填

                //商户订单号
                string out_trade_no = Order.OrderID;
                //商户网站订单系统中唯一订单号,必填

                //订单名称
                string subject = string.Format("订单{0}", Order.OrderID);
                //必填

                //付款金额
                string total_fee = Order.TotalAmount.ToString();
                //必填

                //请求业务参数详细
                string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>";
                //必填

                //把请求参数打包成数组
                Dictionary <string, string> sParaTempToken = new Dictionary <string, string>();
                sParaTempToken.Add("partner", paymentType.AlipayPartner);
                sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower());
                sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper());
                sParaTempToken.Add("service", "alipay.wap.trade.create.direct");
                sParaTempToken.Add("format", format);
                sParaTempToken.Add("v", v);
                sParaTempToken.Add("req_id", req_id);
                sParaTempToken.Add("req_data", req_dataToken);

                //建立请求
                string sHtmlTextToken = Submit.BuildRequestMall(GATEWAY_NEW, sParaTempToken, paymentType.AlipayPartnerKey);
                //URLDECODE返回的信息
                Encoding code = Encoding.GetEncoding("utf-8");
                sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code);
                //using (System.IO.StreamWriter sr = new StreamWriter("D:\\MonitorHandlerException.txt"))
                //{
                //    sr.Write(sHtmlTextToken);
                //}
                //解析远程模拟提交后返回的信息
                Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken);

                //获取token
                string request_token = dicHtmlTextToken["request_token"];

                ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute////////////////////////////////////////////


                //业务详细
                string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>";
                //必填

                //把请求参数打包成数组
                Dictionary <string, string> sParaTemp = new Dictionary <string, string>();
                sParaTemp.Add("partner", paymentType.AlipayPartner);
                sParaTemp.Add("_input_charset", Config.Input_charset.ToLower());
                sParaTemp.Add("sec_id", Config.Sign_type.ToUpper());
                sParaTemp.Add("service", "alipay.wap.auth.authAndExecute");
                sParaTemp.Add("format", format);
                sParaTemp.Add("v", v);
                sParaTemp.Add("req_data", req_data);

                //建立请求
                string sHtmlText = Submit.BuildRequestMall(GATEWAY_NEW, sParaTemp, "get", "确认", paymentType.AlipayPartnerKey);
                Response.Write(sHtmlText);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                Response.End();
            }
        }