Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            /// <summary>
            /// 卡券BLL
            /// </summary>
            BLLJIMP.BLLCardCoupon bllCardCoupon = new BLLJIMP.BLLCardCoupon();
            /// <summary>
            /// 商城BLL
            /// </summary>
            BLLJIMP.BLLMall bllMall = new BLLJIMP.BLLMall();
            /// <summary>
            /// 用户BLL
            /// </summary>
            BLLJIMP.BLLUser bllUser = new BLLJIMP.BLLUser();
            /// <summary>
            /// 微信BLL
            /// </summary>
            BLLJIMP.BLLWeixin bllWeixin = new BLLJIMP.BLLWeixin();
            /// <summary>
            ///
            /// </summary>
            BLLJIMP.BLLStoredValueCard bllStoredValue = new BLLJIMP.BLLStoredValueCard();
            /// <summary>
            ///
            /// </summary>
            BLLJIMP.BLLWeixinCard bllWeixinCard = new BLLJIMP.BLLWeixinCard();

            string cardCouponId   = context.Request["cardcoupon_id"];    //主卡券ID
            string myCardCouponId = context.Request["my_cardcoupon_id"]; //我的卡券ID

            if (string.IsNullOrEmpty(cardCouponId))
            {
                resp.status = false;
                resp.msg    = "cardcoupon_id 参数必传";
                context.Response.Write(JsonConvert.SerializeObject(resp));
                return;
            }
            CardCoupons cardCoupon = bllCardCoupon.GetCardCouponByWXCardId(cardCouponId);

            if (cardCoupon == null)
            {
                cardCoupon = bllCardCoupon.GetCardCoupon(int.Parse(cardCouponId));
                if (cardCoupon == null)
                {
                    resp.status = false;
                    resp.msg    = "cardcoupon_id 不存在";
                    context.Response.Write(JsonConvert.SerializeObject(resp));
                    return;
                }
            }
            cardCoupon = bllCardCoupon.ConvertExpireTime(cardCoupon);

            MainCardModel model = new MainCardModel();

            model.cardcoupon_id      = cardCoupon.CardId;
            model.cardcoupon_name    = cardCoupon.Name;
            model.cardcoupon_type    = ConvertCardCouponType(cardCoupon.CardCouponType);
            model.valid_from         = cardCoupon.ValidFrom.ToString();
            model.valid_to           = cardCoupon.ValidTo.ToString();
            model.img_url            = bllMall.GetImgUrl(cardCoupon.Logo);
            model.discount           = string.IsNullOrEmpty(cardCoupon.Ex1) ? 0 : double.Parse(cardCoupon.Ex1);
            model.product_id         = string.IsNullOrEmpty(cardCoupon.Ex2) ? 0 : double.Parse(cardCoupon.Ex2);
            model.deductible_amount  = string.IsNullOrEmpty(cardCoupon.Ex3) ? 0 : double.Parse(cardCoupon.Ex3);
            model.freefreight_amount = string.IsNullOrEmpty(cardCoupon.Ex4) ? 0 : double.Parse(cardCoupon.Ex4);
            model.buckle_amount      = string.IsNullOrEmpty(cardCoupon.Ex5) ? 0 : double.Parse(cardCoupon.Ex5);
            model.buckle_sub_amount  = string.IsNullOrEmpty(cardCoupon.Ex6) ? 0 : double.Parse(cardCoupon.Ex6);
            model.max_count          = cardCoupon.MaxCount;
            model.send_count         = cardCoupon.SendCount;
            model.un_send_count      = cardCoupon.UnSendCount;
            //model.is_recivece = bllCardCoupon.IsReciveCoupon(cardCoupon.CardId, CurrentUserInfo.UserID);
            model.valid_to_timestamp  = bllCardCoupon.GetTimeStamp((DateTime)cardCoupon.ValidTo);
            model.limit_type          = cardCoupon.Ex7;
            model.product_tags        = cardCoupon.Ex8;
            model.user_get_limit_type = cardCoupon.GetLimitType;
            model.is_can_use_shop     = cardCoupon.IsCanUseShop;
            model.is_can_use_groupbuy = cardCoupon.IsCanUseGroupbuy;
            model.expire_time_type    = cardCoupon.ExpireTimeType;
            model.expire_day          = cardCoupon.ExpireDay;
            model.weixin_card_id      = cardCoupon.WeixinCardId == null ? "" : cardCoupon.WeixinCardId;
            if (!string.IsNullOrEmpty(myCardCouponId))
            {
                MyCardCoupons myCardCoupon = bllCardCoupon.GetMyCardCoupon(int.Parse(myCardCouponId));
                if (myCardCoupon != null)
                {
                    UserInfo fromUserInfo = bllUser.GetUserInfo(myCardCoupon.UserId);

                    if (fromUserInfo != null)
                    {
                        model.from_user_info = new UserInfoModel();
                        model.from_user_info.head_img_url = bllUser.GetUserDispalyAvatar(fromUserInfo);
                        model.from_user_info.nick_name    = bllUser.GetUserDispalyName(fromUserInfo);
                    }

                    if (!string.IsNullOrEmpty(myCardCoupon.ToUserId))
                    {
                        model.is_donation = true;
                    }
                }
            }

            resp.status = true;
            resp.result = model;

            context.Response.Write(JsonConvert.SerializeObject(resp));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取主卡券
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetMainCardCoupon(HttpContext context)
        {
            string cardCouponId   = context.Request["cardcoupon_id"];    //主卡券ID
            string myCardCouponId = context.Request["my_cardcoupon_id"]; //我的卡券ID

            if (string.IsNullOrEmpty(cardCouponId))
            {
                resp.errcode = 1;
                resp.errmsg  = "cardcoupon_id 参数必传";
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            CardCoupons cardCoupon = bllCardCoupon.GetCardCoupon(int.Parse(cardCouponId));

            if (cardCoupon == null)
            {
                resp.errcode = 1;
                resp.errmsg  = "cardcoupon_id 不存在";
                return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            cardCoupon = bllCardCoupon.ConvertExpireTime(cardCoupon);
            if (!string.IsNullOrEmpty(cardCoupon.BindChannelUserId))
            {
                if (string.IsNullOrEmpty(currentUserInfo.DistributionOwner))
                {
                    resp.errcode = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyChannel;
                    resp.errmsg  = "只有指定渠道才能领取";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
                BLLJIMP.BLLDistribution bllDis = new BLLJIMP.BLLDistribution();
                string channelUserId           = bllDis.GetUserChannel(currentUserInfo);
                if (cardCoupon.BindChannelUserId != channelUserId)
                {
                    resp.errcode = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyChannel;
                    resp.errmsg  = "只有指定渠道才能领取";
                    return(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                }
            }

            MainCardModel model = new MainCardModel();

            model.cardcoupon_id       = cardCoupon.CardId;
            model.cardcoupon_name     = cardCoupon.Name;
            model.cardcoupon_type     = ConvertCardCouponType(cardCoupon.CardCouponType);
            model.valid_from          = cardCoupon.ValidFrom.ToString();
            model.valid_to            = cardCoupon.ValidTo.ToString();
            model.img_url             = bllMall.GetImgUrl(cardCoupon.Logo);
            model.discount            = string.IsNullOrEmpty(cardCoupon.Ex1) ? 0 : double.Parse(cardCoupon.Ex1);
            model.product_id          = string.IsNullOrEmpty(cardCoupon.Ex2) ? 0 : double.Parse(cardCoupon.Ex2);
            model.deductible_amount   = string.IsNullOrEmpty(cardCoupon.Ex3) ? 0 : double.Parse(cardCoupon.Ex3);
            model.freefreight_amount  = string.IsNullOrEmpty(cardCoupon.Ex4) ? 0 : double.Parse(cardCoupon.Ex4);
            model.buckle_amount       = string.IsNullOrEmpty(cardCoupon.Ex5) ? 0 : double.Parse(cardCoupon.Ex5);
            model.buckle_sub_amount   = string.IsNullOrEmpty(cardCoupon.Ex6) ? 0 : double.Parse(cardCoupon.Ex6);
            model.max_count           = cardCoupon.MaxCount;
            model.send_count          = cardCoupon.SendCount;
            model.un_send_count       = cardCoupon.UnSendCount;
            model.is_recivece         = bllCardCoupon.IsReciveCoupon(cardCoupon.CardId, currentUserInfo.UserID);
            model.valid_to_timestamp  = bllCardCoupon.GetTimeStamp((DateTime)cardCoupon.ValidTo);
            model.limit_type          = cardCoupon.Ex7;
            model.product_tags        = cardCoupon.Ex8;
            model.user_get_limit_type = cardCoupon.GetLimitType;
            model.is_can_use_shop     = cardCoupon.IsCanUseShop;
            model.is_can_use_groupbuy = cardCoupon.IsCanUseGroupbuy;
            model.expire_time_type    = cardCoupon.ExpireTimeType;
            model.expire_day          = cardCoupon.ExpireDay;
            model.weixin_card_id      = cardCoupon.WeixinCardId == null?"":cardCoupon.WeixinCardId;
            if (!string.IsNullOrEmpty(myCardCouponId))
            {
                MyCardCoupons myCardCoupon = bllCardCoupon.GetMyCardCoupon(int.Parse(myCardCouponId));
                if (myCardCoupon != null)
                {
                    UserInfo fromUserInfo = bllUser.GetUserInfo(myCardCoupon.UserId);
                    if (fromUserInfo != null)
                    {
                        model.from_user_info = new UserInfoModel();
                        model.from_user_info.head_img_url = bllUser.GetUserDispalyAvatar(fromUserInfo);
                        model.from_user_info.nick_name    = bllUser.GetUserDispalyName(fromUserInfo);
                    }
                    if (!string.IsNullOrEmpty(myCardCoupon.ToUserId))
                    {
                        model.is_donation = true;
                    }
                    model.cardcoupon_number = myCardCoupon.CardCouponNumber;
                }
            }

            return(ZentCloud.Common.JSONHelper.ObjectToJson(model));
        }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            StringBuilder sbWhere = new StringBuilder();

            sbWhere.AppendFormat(" WebsiteOwner= '{0}' And IsNull(IsMain,0)=0", bllMall.WebsiteOwner);
            string fromDate       = context.Request["from_date"];       //开始日期
            string toDate         = context.Request["to_date"];         //结束日期
            string status         = context.Request["status"];          //订单状态
            string orderIds       = context.Request["oids"];            //订单号
            string userAutoIds    = context.Request["user_aids"];       //用户自动编号
            string userTags       = context.Request["user_tags"];       //用户标签
            string isYuYueOrder   = context.Request["is_yuyue"];        //是否是会议室预约和资源预约订单
            string supplierUserId = context.Request["supplier_userid"]; //供应商账号
            //订单类型
            //0 商城订单
            //1 礼品订单
            //2 团购订单
            //3 无
            //4 活动订单
            //5 会议室预订
            //6 导师预约
            string orderType = context.Request["order_type"];

            if (!string.IsNullOrEmpty(orderType))
            {
                if (orderType == "5")
                {
                    sbWhere.AppendFormat(" And ArticleCategoryType='MeetingRoom'");
                }
                else if (orderType == "6")
                {
                    sbWhere.AppendFormat(" And ArticleCategoryType='BookingTutor'");
                }
                else
                {
                    sbWhere.AppendFormat(" And OrderType={0}", orderType);
                }
            }
            if (!string.IsNullOrEmpty(fromDate))
            {
                sbWhere.AppendFormat(" And InsertDate>='{0}'", fromDate);
            }
            if (!string.IsNullOrEmpty(toDate))
            {
                sbWhere.AppendFormat(" And InsertDate<='{0}'", toDate);
            }
            if (orderType == "2" && !string.IsNullOrEmpty(status))
            {
                status = ConvertGroupbuyStatus(status);
                sbWhere.AppendFormat(" And GroupBuyStatus in({0})", status);
            }
            if (orderType == "2")
            {
                sbWhere.AppendFormat(" And PaymentStatus=1 ", status);
            }
            if ((!string.IsNullOrEmpty(status)) && (status != "退款退货") && orderType != "2")
            {
                status = "'" + status.Replace(",", "','") + "'";
                sbWhere.AppendFormat(" And Status in({0})", status);
            }
            if (status == "退款退货")
            {
                sbWhere.AppendFormat(" And IsRefund=1 ");
            }
            if (!string.IsNullOrEmpty(orderIds))
            {
                orderIds = "'" + orderIds.Replace(",", "','") + "'";
                sbWhere.AppendFormat(" And OrderID in({0})  ", orderIds);
            }
            if (bllUser.IsSupplier(currentUserInfo))
            {
                sbWhere.AppendFormat(" And SupplierUserId ='{0}'  ", currentUserInfo.UserID);
            }
            if ((!string.IsNullOrEmpty(userAutoIds)) || (!string.IsNullOrEmpty(userTags)))
            {
                string userIds = "";
                if (!string.IsNullOrEmpty(userAutoIds))
                {
                    foreach (var userAutoId in userAutoIds.Split(','))
                    {
                        var userInfo = bllUser.GetUserInfoByAutoID(int.Parse(userAutoId));
                        if (userInfo != null)
                        {
                            userIds += string.Format("'{0}',", userInfo.UserID);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(userTags))
                {
                    foreach (string tag in userTags.Split(','))
                    {
                        List <UserInfo> userList = bllUser.GetList <UserInfo>(string.Format(" Websiteowner='{0}' And TagName like '%{1}%'", bllUser.WebsiteOwner, tag));
                        foreach (var userInfo in userList)
                        {
                            userIds += string.Format("'{0}',", userInfo.UserID);
                        }
                    }
                }
                userIds = userIds.TrimEnd(',');
                sbWhere.AppendFormat(" And OrderUserId in({0})  ", userIds);
            }
            if (!string.IsNullOrEmpty(supplierUserId))
            {
                if (supplierUserId == "none")
                {
                    sbWhere.AppendFormat("  And (SupplierUserId='' Or SupplierUserId IS NULL)", "");
                }
                else
                {
                    sbWhere.AppendFormat(" And SupplierUserId ='{0}' ", supplierUserId);
                }
            }

            sbWhere.AppendFormat(" Order by InsertDate Desc ");

            List <WXMallOrderInfo> orderList = bllMall.GetList <WXMallOrderInfo>(sbWhere.ToString());
            //sbExport.Append("会员ID\t");
            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();

            dt1.Columns.Add("会员ID");
            dt1.Columns.Add("线上卡号");
            dt1.Columns.Add("OpenId");
            dt1.Columns.Add("订单时间");
            dt1.Columns.Add("父订单编号");
            dt1.Columns.Add("订单号");
            dt1.Columns.Add("订单状态");
            dt1.Columns.Add("商品编号");
            dt1.Columns.Add("商品编码");
            dt1.Columns.Add("商品名称");
            if (!string.IsNullOrEmpty(isYuYueOrder))
            {
                dt1.Columns.Add("预约时间");
            }
            dt1.Columns.Add("商品原价");
            dt1.Columns.Add("商品均摊价格");
            dt1.Columns.Add("商品单价");
            dt1.Columns.Add("商品规格");
            dt1.Columns.Add("商品条码");
            dt1.Columns.Add("商品数量");
            dt1.Columns.Add("商品总金额");
            dt1.Columns.Add("运费");
            dt1.Columns.Add("实付金额");
            dt1.Columns.Add("收货人姓名");
            dt1.Columns.Add("电话");
            dt1.Columns.Add("收货地址");
            dt1.Columns.Add("留言");
            dt1.Columns.Add("支付状态");
            dt1.Columns.Add("基础价");
            dt1.Columns.Add("使用积分");
            dt1.Columns.Add("使用余额");
            dt1.Columns.Add("优惠券名称");
            dt1.Columns.Add("优惠券ID");
            dt1.Columns.Add("退款");
            dt1.Columns.Add("主订单号");
            dt1.Columns.Add("商户名称");
            dt1.Columns.Add("商家备注");
            dt1.Columns.Add("快递公司");
            dt1.Columns.Add("快递单号");

            dt2.Columns.Add("订单时间");
            dt2.Columns.Add("订单号");
            dt2.Columns.Add("订单状态");
            dt2.Columns.Add("商品编号");
            dt2.Columns.Add("商品名称");
            dt2.Columns.Add("商品规格");
            dt2.Columns.Add("商品数量");
            dt2.Columns.Add("实付金额");
            dt2.Columns.Add("收货人姓名");
            dt2.Columns.Add("电话");
            dt2.Columns.Add("收货地址");
            dt2.Columns.Add("支付状态");
            dt2.Columns.Add("退款");
            dt2.Columns.Add("主订单号");
            dt2.Columns.Add("商户名称");
            dt2.Columns.Add("商家备注");
            dt2.Columns.Add("快递公司");
            dt2.Columns.Add("快递单号");

            for (int i = 0; i < orderList.Count; i++)
            {
                var userInfo = bllUser.GetUserInfo(orderList[i].OrderUserID);
                if (userInfo == null)
                {
                    userInfo = new UserInfo();
                }


                string cardId   = string.Empty;
                string cardName = string.Empty;

                if (!string.IsNullOrEmpty(orderList[i].MyCouponCardId))
                {
                    switch (orderList[i].CouponType)
                    {
                    case 0:
                        MyCardCoupons myCardModel = bllCardcoupon.GetMyCardCoupon(Convert.ToInt32(orderList[i].MyCouponCardId));
                        if (myCardModel != null)
                        {
                            CardCoupons coupns = bllCardcoupon.GetCardCoupon(myCardModel.CardId);
                            cardId   = coupns.CardId.ToString();
                            cardName = coupns.Name;
                        }
                        break;

                    case 1:
                        int cardIdInt = Convert.ToInt32(orderList[i].MyCouponCardId);

                        StoredValueCardRecord storedCard = bllStoredValueCard.GetStoredValueCardRecord(cardIdInt);

                        if (storedCard != null)
                        {
                            StoredValueCard cardModel = bllStoredValueCard.GetStoredValueCard(storedCard.CardId);
                            cardId   = cardModel.AutoId.ToString();
                            cardName = cardModel.Name;
                        }
                        break;

                    default:
                        break;
                    }
                }
                foreach (var item in bllMall.GetOrderDetailsList(orderList[i].OrderID))
                {
                    if (orderList[i].IsRefund == 1 && string.IsNullOrEmpty(item.RefundStatus) && status == "退款退货")
                    {
                        continue;
                    }
                    DataRow newRow  = dt1.NewRow();
                    DataRow newRow1 = dt2.NewRow();
                    newRow["会员ID"]   = userInfo.AutoID.ToString();
                    newRow["OpenId"] = userInfo.WXOpenId;
                    newRow["订单时间"]   = orderList[i].InsertDate.ToString();
                    newRow1["订单时间"]  = orderList[i].InsertDate.ToString();
                    WXMallProductInfo product = bllMall.GetProduct(item.PID);

                    switch (orderList[i].OrderType)
                    {
                    case 0:
                        newRow["父订单编号"] = "";
                        break;

                    case 1:
                        newRow["父订单编号"] = orderList[i].ParentOrderId;

                        break;

                    case 2:
                        newRow["父订单编号"] = orderList[i].GroupBuyParentOrderId;


                        break;

                    default:
                        break;
                    }

                    newRow["订单号"]  = orderList[i].OrderID;
                    newRow1["订单号"] = orderList[i].OrderID;

                    newRow["订单状态"]  = orderList[i].Status;
                    newRow1["订单状态"] = orderList[i].Status;

                    newRow["商品编号"]  = product == null ? "" : product.PID;
                    newRow1["商品编号"] = product == null ? "" : product.PID;
                    newRow["商品编码"]  = product == null ? "" : product.ProductCode;
                    newRow["商品名称"]  = product == null ? item.SkuShowProp : product.PName;
                    newRow1["商品名称"] = product == null ? item.SkuShowProp : product.PName;
                    if (!string.IsNullOrEmpty(isYuYueOrder))
                    {
                        if (isYuYueOrder == "MeetingRoom")
                        {
                            if (!string.IsNullOrEmpty(product.RelationProductId))
                            {
                                newRow["预约时间"] = item.StartDate.ToString("yyyy-MM-dd HH:mm") + "-" + item.EndDate.ToString("HH:mm");
                            }
                            else
                            {
                                newRow["预约时间"] = "";
                            }
                        }
                        else
                        {
                            newRow["预约时间"] = item.StartDate.ToString("yyyy-MM-dd HH:mm") + "-" + item.EndDate.ToString("HH:mm");
                        }
                    }
                    newRow["商品原价"]   = product.PreviousPrice;
                    newRow["商品均摊价格"] = item.PaymentFt;
                    newRow["商品单价"]   = item.OrderPrice;

                    if (item.SkuId.HasValue)
                    {
                        newRow["商品规格"]  = item.SkuShowProp;
                        newRow1["商品规格"] = item.SkuShowProp;
                        newRow["商品条码"]  = item.SkuId;
                    }
                    else
                    {
                        newRow["商品规格"]  = "";
                        newRow1["商品规格"] = "";
                        newRow["商品条码"]  = "";
                    }

                    newRow["商品数量"]   = item.TotalCount;
                    newRow1["商品数量"]  = item.TotalCount;
                    newRow["商品总金额"]  = item.TotalCount * item.OrderPrice;
                    newRow["运费"]     = orderList[i].Transport_Fee;
                    newRow["实付金额"]   = orderList[i].TotalAmount;
                    newRow1["实付金额"]  = orderList[i].TotalAmount;
                    newRow["收货人姓名"]  = orderList[i].Consignee;
                    newRow1["收货人姓名"] = orderList[i].Consignee;
                    newRow["电话"]     = orderList[i].Phone;
                    newRow1["电话"]    = orderList[i].Phone;
                    newRow["收货地址"]   = orderList[i].ReceiverProvince + orderList[i].ReceiverCity + orderList[i].ReceiverDist + orderList[i].Address;
                    newRow1["收货地址"]  = orderList[i].ReceiverProvince + orderList[i].ReceiverCity + orderList[i].ReceiverDist + orderList[i].Address;
                    newRow["留言"]     = orderList[i].OrderMemo;
                    newRow["支付状态"]   = ConvertPaymentStatus(orderList[i].PaymentStatus);
                    newRow1["支付状态"]  = ConvertPaymentStatus(orderList[i].PaymentStatus);
                    newRow["基础价"]    = item.BasePrice;
                    newRow["使用积分"]   = orderList[i].UseScore;
                    newRow["使用余额"]   = orderList[i].UseAmount;
                    newRow["优惠券名称"]  = cardName;
                    newRow["优惠券ID"]  = cardId;

                    newRow["退款"]  = ConvertRefundStatus(item.RefundStatus);
                    newRow1["退款"] = ConvertRefundStatus(item.RefundStatus);


                    newRow["主订单号"]  = orderList[i].ParentOrderId;
                    newRow1["主订单号"] = orderList[i].ParentOrderId;


                    newRow["商户名称"]  = orderList[i].SupplierName;
                    newRow1["商户名称"] = orderList[i].SupplierName;


                    newRow["商家备注"]  = orderList[i].Ex21;
                    newRow1["商家备注"] = orderList[i].Ex21;

                    newRow["快递公司"]  = orderList[i].ExpressCompanyName;
                    newRow1["快递公司"] = orderList[i].ExpressCompanyName;

                    newRow["快递单号"]  = orderList[i].ExpressNumber;
                    newRow1["快递单号"] = orderList[i].ExpressNumber;

                    newRow["线上卡号"] = userInfo.Ex2;

                    dt1.Rows.Add(newRow);
                    dt2.Rows.Add(newRow1);
                }
                //if (orderList[i].OrderType == 2)//团购订单
                //{
                //    foreach (var item in bllMall.GetList<WXMallOrderInfo>(string.Format(" GroupBuyParentOrderId='{0}' And PaymentStatus=1", orderList[i].OrderID)))
                //    {
                //        foreach (var detail in bllMall.GetOrderDetailsList(item.OrderID))
                //        {
                //            DataRow nowRow1 = dt1.NewRow();
                //            DataRow nowRow2 = dt2.NewRow();
                //            WXMallProductInfo product = bllMall.GetProduct(detail.PID);
                //            nowRow1["订单时间"] = item.InsertDate.ToString();
                //            nowRow2["订单时间"] = item.InsertDate.ToString();
                //            nowRow1["父订单编号"] = item.GroupBuyParentOrderId;
                //            nowRow1["订单号"] = item.OrderID;
                //            nowRow2["订单号"] = item.OrderID;

                //            nowRow1["订单状态"] = item.Status;
                //            nowRow2["订单状态"] = item.Status;
                //            nowRow1["商品编号"] = product == null ? "" : product.PID;
                //            nowRow2["商品编号"] = product == null ? "" : product.PID;
                //            nowRow1["商品编码"] = product == null ? "" : product.ProductCode;
                //            nowRow1["商品名称"] = product == null ? "" : product.PName;
                //            nowRow2["商品名称"] = product == null ? "" : product.PName;

                //            nowRow1["商品原价"] = product.PreviousPrice;
                //            nowRow1["商品均摊价格"] = detail.PaymentFt;
                //            nowRow1["商品单价"] = detail.OrderPrice;
                //            if (detail.SkuId.HasValue)
                //            {
                //                nowRow1["商品规格"] = detail.SkuShowProp;
                //                nowRow2["商品规格"] = detail.SkuShowProp;
                //                nowRow1["商品条码"] = detail.SkuId;
                //            }
                //            else
                //            {
                //                nowRow1["商品规格"] = "";
                //                nowRow2["商品规格"] = "";
                //                nowRow1["商品条码"] = "";
                //            }
                //            nowRow1["商品数量"] = detail.TotalCount;
                //            nowRow2["商品数量"] = detail.TotalCount;
                //            nowRow1["商品总金额"] = detail.TotalCount * detail.OrderPrice;
                //            nowRow1["运费"] = item.Transport_Fee;
                //            nowRow1["实付金额"] = item.TotalAmount;
                //            nowRow2["实付金额"] = item.TotalAmount;
                //            nowRow1["收货人姓名"] = item.Consignee;
                //            nowRow2["收货人姓名"] = item.Consignee;
                //            nowRow1["电话"] = item.Phone;
                //            nowRow2["电话"] = item.Phone;
                //            nowRow1["收货地址"] = item.ReceiverProvince + item.ReceiverCity + item.ReceiverDist + item.Address;
                //            nowRow2["收货地址"] = item.ReceiverProvince + item.ReceiverCity + item.ReceiverDist + item.Address;
                //            nowRow1["留言"] = item.OrderMemo;
                //            nowRow1["支付状态"] = ConvertPaymentStatus(item.PaymentStatus);
                //            nowRow2["支付状态"] = ConvertPaymentStatus(item.PaymentStatus);

                //            nowRow1["基础价"] =detail.BasePrice;
                //            nowRow1["使用积分"] = orderList[i].UseScore;
                //            nowRow1["使用余额"] = orderList[i].UseAmount;
                //            nowRow1["优惠券名称"] = cardName;
                //            nowRow1["优惠券ID"] = cardId;
                //            nowRow1["退款"] =ConvertRefundStatus(detail.RefundStatus);
                //            nowRow2["退款"] = ConvertRefundStatus(detail.RefundStatus);
                //            dt1.Rows.Add(nowRow1);
                //            dt2.Rows.Add(nowRow2);
                //        }
                //    }
                //}
            }
            dt1.TableName = "订单列表";
            dt2.TableName = "精简订单列表";
            DataTable[] dt3 = { dt1, dt2 };
            DataLoadTool.ExportDataTable(dt3, string.Format("{0}_data.xls", DateTime.Now.ToString()));
        }
Exemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            currentUserInfo = bllUser.GetCurrentUserInfo();
            string            data              = context.Request["data"];
            decimal           productFee        = 0;                       //商品总价格 不包含邮费
            OrderRequestModel orderRequestModel = new OrderRequestModel(); //订单模型

            try
            {
                orderRequestModel = ZentCloud.Common.JSONHelper.JsonToModel <OrderRequestModel>(data);
            }
            catch (Exception ex)
            {
                resp.errcode = 1;
                resp.errmsg  = "JSON格式错误,请检查。错误信息:" + ex.Message;
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
            }
            WXMallOrderInfo orderInfo = new WXMallOrderInfo();//订单表

            orderInfo.InsertDate     = DateTime.Now;
            orderInfo.OrderUserID    = currentUserInfo.UserID;
            orderInfo.WebsiteOwner   = bllMall.WebsiteOwner;
            orderInfo.Transport_Fee  = 0;
            orderInfo.OrderID        = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder);
            orderInfo.OrderMemo      = orderRequestModel.buyer_memo;
            orderInfo.MyCouponCardId = orderRequestModel.cardcoupon_id.ToString();
            orderInfo.UseScore       = orderRequestModel.use_score;
            orderInfo.Status         = "待付款";
            orderInfo.OrderType      = 1;
            if (orderRequestModel.pay_type == "WEIXIN")//微信支付
            {
                orderInfo.PaymentType = 2;
            }
            else if (orderRequestModel.pay_type == "ALIPAY")//支付宝支付
            {
                orderInfo.PaymentType = 1;
            }

            #region 格式检查
            //相关检查
            if (orderRequestModel.skus == null)
            {
                resp.errcode = 1;
                resp.errmsg  = "参数skus 不能为空";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            //相关检查
            #endregion


            #region 商品检查 订单详情生成
            ///订单详情
            List <WXMallOrderDetailsInfo> detailList = new List <WXMallOrderDetailsInfo>();//订单详情
            orderRequestModel.skus = orderRequestModel.skus.Distinct().ToList();
            foreach (var sku in orderRequestModel.skus)
            {
                //先检查库存
                ProductSku productSku = bllMall.GetProductSku(sku.sku_id);
                if (productSku == null)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "SKU不存在";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }

                WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString());
                if (productInfo.IsOnSale == "0")
                {
                    resp.errcode = 1;
                    resp.errmsg  = string.Format("{0}已下架", productInfo.PName);
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                if (bllMall.GetSkuCount(productSku) < sku.count)
                {
                    resp.errcode = 1;
                    resp.errmsg  = string.Format("{0}{1}库存余量为{2},库存不足,请减少购买数量", productInfo.PName, bllMall.GetProductShowProperties(productSku.SkuId), productSku.Stock);
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                if (bllMall.IsPromotionTime(productSku))
                {
                    if (sku.count > productSku.PromotionStock)
                    {
                        resp.errcode = 1;
                        resp.errmsg  = string.Format("{0}{1}特卖库存余量为{2},库存不足,请减少购买数量", productInfo.PName, bllMall.GetProductShowProperties(productSku.SkuId), productSku.PromotionStock);
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
                WXMallOrderDetailsInfo detailModel = new WXMallOrderDetailsInfo();
                detailModel.OrderID     = orderInfo.OrderID;
                detailModel.PID         = productInfo.PID;
                detailModel.TotalCount  = sku.count;
                detailModel.OrderPrice  = bllMall.GetSkuPrice(productSku);
                detailModel.ProductName = productInfo.PName;
                detailModel.SkuId       = productSku.SkuId;
                detailModel.SkuShowProp = bllMall.GetProductShowProperties(productSku.SkuId);
                detailList.Add(detailModel);
            }
            #endregion

            productFee = detailList.Sum(p => p.OrderPrice * p.TotalCount).Value;//商品费用

            //物流费用
            #region 运费计算
            FreightModel freightModel = new FreightModel();
            freightModel.skus = orderRequestModel.skus;
            decimal freight    = 0;//运费
            string  freightMsg = "";
            if (!bllMall.CalcFreight(freightModel, out freight, out freightMsg))
            {
                resp.errcode = 1;
                resp.errmsg  = freightMsg;
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            orderInfo.Transport_Fee = freight;
            #endregion
            #region 优惠券计算
            decimal discountAmount   = 0;//优惠金额
            bool    canUseCardCoupon = false;
            string  msg = "";
            if (orderRequestModel.cardcoupon_id > 0)//有优惠券
            {
                discountAmount = bllMall.CalcDiscountAmount(orderRequestModel.cardcoupon_id.ToString(), data, currentUserInfo.UserID, out canUseCardCoupon, out msg);
                if (!canUseCardCoupon)
                {
                    resp.errcode = 1;
                    resp.errmsg  = msg;
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                if (discountAmount > productFee + orderInfo.Transport_Fee)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "优惠券可优惠金额超过了订单总金额";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
            }
            //优惠券计算
            #endregion


            #region 积分计算
            decimal scoreExchangeAmount = 0;///积分抵扣的金额
            //积分计算
            if (orderRequestModel.use_score > 0)
            {
                if (currentUserInfo.TotalScore < orderRequestModel.use_score)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "积分不足";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                ScoreConfig scoreConfig = bllScore.GetScoreConfig();
                scoreExchangeAmount = Math.Round(orderRequestModel.use_score / (scoreConfig.ExchangeScore / scoreConfig.ExchangeAmount), 2);
            }
            #region 驿氪积分同步



            #endregion


            //积分计算
            #endregion


            //合计计算
            orderInfo.Product_Fee   = productFee;
            orderInfo.TotalAmount   = orderInfo.Product_Fee + orderInfo.Transport_Fee;
            orderInfo.TotalAmount  -= discountAmount;                  //优惠券优惠金额
            orderInfo.TotalAmount  -= scoreExchangeAmount;             //积分优惠金额
            orderInfo.PayableAmount = orderInfo.TotalAmount - freight; //应付金额
            if ((productFee + orderInfo.Transport_Fee - discountAmount - scoreExchangeAmount) < orderInfo.TotalAmount)
            {
                resp.errcode = 1;
                resp.errmsg  = "积分兑换金额不能大于订单总金额,请减少积分兑换";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }



            ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction();
            try
            {
                if (!this.bllMall.Add(orderInfo, tran))
                {
                    tran.Rollback();
                    resp.errcode = 1;
                    resp.errmsg  = "提交失败";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }

                #region 更新优惠券使用状态
                //优惠券
                if (orderRequestModel.cardcoupon_id > 0 && (canUseCardCoupon == true))//有优惠券且已经成功使用
                {
                    MyCardCoupons myCardCoupon = bllCardCoupon.GetMyCardCoupon(orderRequestModel.cardcoupon_id, currentUserInfo.UserID);
                    myCardCoupon.UseDate = DateTime.Now;
                    myCardCoupon.Status  = 1;
                    if (!bllCardCoupon.Update(myCardCoupon, tran))
                    {
                        tran.Rollback();
                        resp.errcode = 1;
                        resp.errmsg  = "更新优惠券状态失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
                //优惠券
                #endregion

                #region 积分抵扣
                //积分扣除
                if (orderRequestModel.use_score > 0)
                {
                    currentUserInfo.TotalScore -= orderRequestModel.use_score;
                    if (

                        bllMall.Update(currentUserInfo, string.Format(" TotalScore-={0}", orderRequestModel.use_score), string.Format(" AutoID={0}", currentUserInfo.AutoID)) < 0)
                    {
                        tran.Rollback();
                        resp.errcode = 1;
                        resp.errmsg  = "更新用户积分失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }

                    //积分记录
                    WXMallScoreRecord scoreRecord = new WXMallScoreRecord();
                    scoreRecord.InsertDate   = DateTime.Now;
                    scoreRecord.OrderID      = orderInfo.OrderID;
                    scoreRecord.Score        = orderRequestModel.use_score;
                    scoreRecord.Type         = 1;
                    scoreRecord.UserId       = currentUserInfo.UserID;
                    scoreRecord.WebsiteOwner = bllMall.WebsiteOwner;
                    scoreRecord.Remark       = "积分抵扣";
                    if (!bllMall.Add(scoreRecord))
                    {
                        tran.Rollback();
                        resp.errcode = 1;
                        resp.errmsg  = "插入积分记录失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }

                    //积分记录
                }

                //积分扣除
                #endregion

                #region 插入订单详情页及更新库存
                foreach (var item in detailList)
                {
                    ProductSku        productSku  = bllMall.GetProductSku((int)(item.SkuId));
                    WXMallProductInfo productInfo = bllMall.GetProduct(productSku.ProductId.ToString());
                    if (!this.bllMall.Add(item, tran))
                    {
                        tran.Rollback();
                        resp.errcode = 1;
                        resp.errmsg  = "提交失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                    //更新 SKU库存
                    productSku.Stock -= item.TotalCount;
                    if (bllMall.IsPromotionTime(productSku))
                    {
                        productSku.PromotionStock -= item.TotalCount;
                    }
                    if (!bllMall.Update(productSku, tran))
                    {
                        tran.Rollback();
                        resp.errcode = 1;
                        resp.errmsg  = "更新SKU失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
                #endregion
                tran.Commit();//提交订单事务
            }
            catch (Exception ex)
            {
                //回滚事物
                tran.Rollback();
                resp.errcode = 1;
                resp.errmsg  = ex.Message;
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(new
            {
                errcode  = 0,
                errmsg   = "ok",
                order_id = orderInfo.OrderID
            }));
        }
Exemplo n.º 6
0
        public void ProcessRequest(HttpContext context)
        {
            string orderSn = context.Request["order_sn"]; //订单号
            string status  = context.Request["status"];   //订单状态 1001 确认收货 1002取消订单

            if (string.IsNullOrEmpty(orderSn))
            {
                resp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                resp.msg  = "order_sn 参数必传";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            if (string.IsNullOrEmpty(status))
            {
                resp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                resp.msg  = "status 参数必传";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            var orderInfo = bllMall.GetOrderInfoByOutOrderId(orderSn);

            if (orderInfo == null)
            {
                resp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                resp.msg  = "order_sn 不存在,请检查";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, bllUser.WebsiteOwner);

            switch (status)
            {
                #region 确认收货

            case "1001":    //确认收货
                if (orderInfo.Status == "交易成功")
                {
                    resp.code = (int)APIErrCode.OperateFail;
                    resp.msg  = "重复操作";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                if (orderInfo.PaymentStatus == 0)
                {
                    resp.code = (int)APIErrCode.OperateFail;
                    resp.msg  = "订单未付款";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                if (orderInfo.Status == "已取消")
                {
                    resp.code = (int)APIErrCode.OperateFail;
                    resp.msg  = "订单已取消";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction();
                //交易成功处理
                try
                {
                    orderInfo.Status        = "交易成功";
                    orderInfo.ReceivingTime = DateTime.Now;
                    if (!bllMall.Update(orderInfo, tran))
                    {
                        tran.Rollback();
                        resp.code = (int)APIErrCode.OperateFail;
                        resp.msg  = "更新订单状态失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }

                    #region 交易成功加积分
                    //增加积分
                    ScoreConfig scoreConfig = bllScore.GetScoreConfig();
                    int         addScore    = 0;
                    if (scoreConfig != null && scoreConfig.OrderAmount > 0 && scoreConfig.OrderScore > 0)
                    {
                        addScore = (int)(orderInfo.PayableAmount / (scoreConfig.OrderAmount / scoreConfig.OrderScore));
                    }
                    if (addScore > 0)
                    {
                        orderUserInfo.TotalScore += addScore;

                        UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo();
                        scoreRecord.AddTime      = DateTime.Now;
                        scoreRecord.Score        = addScore;
                        scoreRecord.TotalScore   = orderUserInfo.TotalScore;
                        scoreRecord.ScoreType    = "OrderSuccess";
                        scoreRecord.UserID       = orderUserInfo.UserID;
                        scoreRecord.AddNote      = "微商城-交易成功获得积分";
                        scoreRecord.WebSiteOwner = bllMall.WebsiteOwner;
                        if (!bllMall.Add(scoreRecord, tran))
                        {
                            tran.Rollback();
                            resp.code = (int)APIErrCode.OperateFail;
                            resp.msg  = "插入积分记录表失败";
                            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            return;
                        }
                        if (bllUser.Update(orderUserInfo, string.Format(" TotalScore+={0},HistoryTotalScore+={0}", addScore), string.Format(" AutoID={0}", orderUserInfo.AutoID), tran) < 1)
                        {
                            tran.Rollback();
                            resp.code = (int)APIErrCode.OperateFail;
                            resp.msg  = "更新用户积分失败";
                            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            return;
                        }
                    }
                    #endregion

                    //

                    #region 更新订单明细表状态
                    List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID);
                    foreach (var orderDetail in orderDetailList)
                    {
                        orderDetail.IsComplete = 1;
                        if (!bllMall.Update(orderDetail))
                        {
                            tran.Rollback();
                            resp.code = (int)APIErrCode.OperateFail;
                            resp.msg  = "更新订单明细表失败";
                            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            return;
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    resp.code = (int)APIErrCode.OperateFail;
                    resp.msg  = ex.Message;
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }

                tran.Commit();
                resp.code   = 0;
                resp.msg    = "ok";
                resp.status = true;
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;

                //交易成功处理
                #endregion

                #region 取消订单
            case "1002":    //取消订单
                if (orderInfo.Status == "已取消")
                {
                    resp.code = (int)APIErrCode.OperateFail;
                    resp.msg  = "重复操作";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                ZentCloud.ZCBLLEngine.BLLTransaction tranCancel = new ZCBLLEngine.BLLTransaction();
                try
                {
                    orderInfo.Status = "已取消";
                    if (!bllMall.Update(orderInfo, tranCancel))
                    {
                        tranCancel.Rollback();
                        resp.code = (int)APIErrCode.OperateFail;;
                        resp.msg  = "更新订单状态失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }

                    List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID);
                    foreach (var orderDetail in orderDetailList)
                    {
                        if (orderDetail.SkuId != null)
                        {
                            ProductSku sku = bllMall.GetProductSku((int)orderDetail.SkuId);
                            if (sku != null)
                            {
                                if (bllMall.Update(sku, string.Format(" Stock+={0}", orderDetail.TotalCount), string.Format(" SkuId={0}", sku.SkuId), tranCancel) == 0)
                                {
                                    tranCancel.Rollback();
                                    resp.code = (int)APIErrCode.OperateFail;;
                                    resp.msg  = "修改sku库存失败";
                                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                                    return;
                                }
                            }
                        }
                    }
                    if (bllMall.Update(new WXMallOrderDetailsInfo(), "IsComplete=0", string.Format(" OrderId='{0}'", orderInfo.OrderID), tranCancel) <= 0)
                    {
                        tranCancel.Rollback();
                        resp.code = (int)APIErrCode.OperateFail;;
                        resp.msg  = "更新订单详情失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }



                    #region 积分返还
                    if (orderInfo.UseScore > 0)    //使用积分 积分返还
                    {
                        orderUserInfo.TotalScore += orderInfo.UseScore;
                        if (bllUser.Update(orderUserInfo,
                                           string.Format(" TotalScore+={0}", orderInfo.UseScore),
                                           string.Format(" AutoID={0}", orderUserInfo.AutoID)) < 0)

                        {
                            tranCancel.Rollback();
                            resp.code = (int)APIErrCode.OperateFail;;
                            resp.msg  = "积分返还失败";
                            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            return;
                        }
                        UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo();
                        scoreRecord.AddTime      = DateTime.Now;
                        scoreRecord.Score        = orderInfo.UseScore;
                        scoreRecord.TotalScore   = orderUserInfo.TotalScore;
                        scoreRecord.ScoreType    = "OrderCancel";
                        scoreRecord.UserID       = orderUserInfo.UserID;
                        scoreRecord.RelationID   = orderInfo.OrderID;
                        scoreRecord.WebSiteOwner = bllMall.WebsiteOwner;
                        scoreRecord.AddNote      = "微商城-订单取消返还积分";
                        if (!bllMall.Add(scoreRecord))
                        {
                            tranCancel.Rollback();
                            resp.code = (int)APIErrCode.OperateFail;;
                            resp.msg  = "插入积分记录失败";
                            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            return;
                        }
                    }
                    #endregion

                    #region 优惠券返还
                    if (!string.IsNullOrEmpty(orderInfo.MyCouponCardId))
                    {
                        var myCardCoupon = bllCardCoupon.GetMyCardCoupon(int.Parse(orderInfo.MyCouponCardId), orderUserInfo.UserID);
                        if (myCardCoupon != null && myCardCoupon.Status == 1)
                        {
                            myCardCoupon.Status = 0;
                            if (!bllCardCoupon.Update(myCardCoupon))
                            {
                                tranCancel.Rollback();
                                resp.code = (int)APIErrCode.OperateFail;;
                                resp.msg  = "优惠券更新失败";
                                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            }
                        }
                    }
                    #endregion

                    #region 账户余额返还

                    if (orderInfo.UseAmount > 0)
                    {
                        orderUserInfo.AccountAmount += orderInfo.UseAmount;
                        if (bllMall.Update(orderUserInfo, string.Format(" AccountAmount={0}", orderUserInfo.AccountAmount), string.Format(" AutoID={0}", orderUserInfo.AutoID)) < 0)
                        {
                            tranCancel.Rollback();
                            resp.code = (int)APIErrCode.OperateFail;;
                            resp.msg  = "更新用户余额失败";
                            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            return;
                        }

                        UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo();
                        scoreRecord.AddTime      = DateTime.Now;
                        scoreRecord.Score        = (double)orderInfo.UseAmount;
                        scoreRecord.TotalScore   = (double)orderUserInfo.AccountAmount;
                        scoreRecord.ScoreType    = "AccountAmount";
                        scoreRecord.UserID       = orderUserInfo.UserID;
                        scoreRecord.RelationID   = orderInfo.OrderID;
                        scoreRecord.WebSiteOwner = bllMall.WebsiteOwner;
                        scoreRecord.AddNote      = "微商城-订单取消返还余额";
                        if (!bllMall.Add(scoreRecord))
                        {
                            tranCancel.Rollback();
                            resp.code = (int)APIErrCode.OperateFail;;
                            resp.msg  = "插入余额记录失败";
                            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            return;
                        }
                    }


                    #endregion

                    tranCancel.Commit();
                    resp.code   = 0;
                    resp.msg    = "ok";
                    resp.status = true;
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                catch (Exception ex)
                {
                    tranCancel.Rollback();
                    resp.code = (int)APIErrCode.OperateFail;;
                    resp.msg  = ex.Message;
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }

                #endregion

            default:
                resp.code = (int)APIErrCode.OperateFail;
                resp.msg  = "不合法的 status 值";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
        }