Beispiel #1
0
        internal static object SetOrderInfo(Base.APIRequest request)
        {
            var    para = request.GetParameters <SetOrderInfoReqPara>();
            string msg;

            if (!para.IsValid(out msg))
            {
                throw new APIException(msg)
                      {
                          ErrorCode = 350
                      };
            }
            if (string.IsNullOrEmpty(para.storeId))
            {
                UnitService unitServer = new UnitService(request.GetUserInfo());
                para.storeId = unitServer.GetUnitByUnitTypeForWX("OnlineShopping", null).Id; //获取在线商城的门店标识
            }
            #region BLL用到common的参数,所以要赋一下值
            para.customerId = request.common.customerId;
            para.userId     = request.common.userId;
            para.openId     = request.common.openId;
            #endregion
            var bll     = new T_InoutBLL(request.GetUserInfo());
            var orderID = bll.SetOrderInfo(para);
            return(new { orderId = orderID });
        }
        protected override OrderOperationRD ProcessRequest(DTO.Base.APIRequest <BatchInvalidShipRP> pRequest)
        {
            var rd   = new OrderOperationRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var T_Iount            = new T_InoutBLL(loggingSessionInfo);

            var OrderList = new List <InoutInfo>();

            foreach (var item in para.OrderList)
            {
                if (item.Status.Equals("500"))
                {
                    var Entity = new InoutInfo()
                    {
                        order_id   = item.OrderID,
                        Field2     = item.DeliverOrder,
                        carrier_id = item.DeliverCompanyID,
                        Field9     = item.Field9
                    };
                    OrderList.Add(Entity);
                }
            }

            int num = T_Iount.BatchInvalidShip(OrderList, para.Remark, loggingSessionInfo);

            rd.Message = "操作成功" + num + "条!";
            return(rd);
        }
        protected override OrderOperationRD ProcessRequest(DTO.Base.APIRequest <BatchInvalidOrderRP> pRequest)
        {
            var rd   = new OrderOperationRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var T_Iount            = new T_InoutBLL(loggingSessionInfo);

            //审核不通过:900
            //未发货:500
            //待提货:510
            //备货中:410
            //未审核:100
            var OrderList = new List <InoutInfo>();

            foreach (var item in para.OrderList)
            {
                if (item.Status.Equals("900") || item.Status.Equals("500") || item.Status.Equals("510") || item.Status.Equals("410") || item.Status.Equals("100"))
                {
                    var Entity = new InoutInfo()
                    {
                        order_id      = item.OrderID,
                        OldStatusDesc = item.StatusDesc
                    };
                    OrderList.Add(Entity);
                }
            }

            int num = T_Iount.BatchInvalidOrder(OrderList, para.Remark, loggingSessionInfo);

            rd.Message = "操作成功" + num + "条!";
            return(rd);
        }
Beispiel #4
0
        /// <summary>
        /// 订单审核
        /// </summary>
        /// <param name="rParams"></param>
        /// <returns></returns>
        public string Complete(NameValueCollection rParams)
        {
            string res = "{success:false,msg:'操作失败'}";
            string pOrdersID = "", pStatus = "";

            if (!string.IsNullOrEmpty(rParams["id"]))
            {
                pOrdersID = rParams["id"].ToString();
            }
            if (!string.IsNullOrEmpty(rParams["status"]))
            {
                pStatus = rParams["status"];
            }

            new TInoutBLL(CurrentUserInfo).Complete(pOrdersID, pStatus);

            //订单完成,调用方法给积分  Updated by Willie Yan on 2014-05-29
            T_InoutBLL inoutBLL = new T_InoutBLL(CurrentUserInfo);
            string     userId   = inoutBLL.GetByID(pOrdersID).vip_no;

            new VipIntegralBLL(CurrentUserInfo).OrderReturnMoneyAndIntegral(pOrdersID, userId, null);

            res = "{success:true,msg:'保存成功'}";
            return(res);
        }
Beispiel #5
0
 protected override UpdateOrderDeliveryInfoRD ProcessRequest(APIRequest <UpdateOrderDeliveryInfoRP> pRequest)
 {
     #region 错误码
     const int ERROR_ORDERID_NOEXISTS = 301;
     #endregion
     UpdateOrderDeliveryInfoRD rddata = new UpdateOrderDeliveryInfoRD();
     string     OrderID             = pRequest.Parameters.OrderID;           //订单ID
     int        DeliveryTypeID      = pRequest.Parameters.DeliveryTypeID;    //配送方式
     string     StoreID             = pRequest.Parameters.StoreID;           //自提的门店ID
     string     PickupBeginDateTime = pRequest.Parameters.PickupUpDateRange; //自提时间范围
     string     Mobile          = pRequest.Parameters.Mobile;                //手机号码
     string     Email           = pRequest.Parameters.Email;                 //邮箱
     string     ReceiverAddress = pRequest.Parameters.ReceiverAddress;       //收货人地址
     string     ReceiverName    = pRequest.Parameters.ReceiverName;          //收货人姓名
     string     reserveDay      = pRequest.Parameters.PickingDate;
     string     reserveQuantum  = pRequest.Parameters.PickingTime;
     T_InoutBLL _TInoutbll      = new T_InoutBLL(this.CurrentUserInfo); //订单表
     var        pTran           = _TInoutbll.GetTran();
     #region 更新配送方式
     using (pTran.Connection)
     {
         try
         {
             //根据订单ID获取实例
             var entity = _TInoutbll.GetByID(OrderID);
             if (entity == null)
             {
                 throw new APIException(string.Format("未找到对应OrderID:{0}订单", OrderID))
                       {
                           ErrorCode = ERROR_ORDERID_NOEXISTS
                       };
             }
             entity.Field8           = DeliveryTypeID.ToString().Trim(); //订单配送方式 1.送货到家。2到店提货
             entity.carrier_id       = StoreID;                          //自提的门店ID
             entity.purchase_unit_id = StoreID;                          //自提的门店ID
             entity.Field9           = PickupBeginDateTime;              //自提时间范围
             entity.Field6           = Mobile;                           //联系电话
             entity.Field5           = Email;                            //邮箱
             entity.Field4           = ReceiverAddress;                  //配送地址
             entity.Field14          = ReceiverName;                     //收件人姓名
             entity.reserveDay       = string.IsNullOrEmpty(reserveDay) ? "" : Convert.ToDateTime(reserveDay).ToString("yyyy-MM-dd");
             entity.reserveQuantum   = reserveQuantum;
             #region  更新时候更新时间和更新人同时更新
             entity.modify_time    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //更新时间
             entity.modify_user_id = CurrentUserInfo.UserID;                       //更新人
             #endregion
             _TInoutbll.Update(entity, pTran);                                     //用事物更新订单表(T_Inout)表中信息
             pTran.Commit();                                                       //提交事物
         }
         catch (Exception ex)
         {
             pTran.Rollback();
             throw new APIException(ex.Message);
         }
         #endregion
     }
     return(rddata);
 }
        protected override ReturnOrderToHeadRD ProcessRequest(APIRequest <ReturnOrderToHeadRP> pRequest)
        {
            var rd = new ReturnOrderToHeadRD();

            #region 错误码

            const int ERROR_ORDERID_NOEXISTS = 301;

            #endregion

            var orderId    = pRequest.Parameters.OrderID;                //订单ID
            var returnUnit = pRequest.Parameters.UnitID;                 //退回部门经

            T_InoutBLL tInoutbll = new T_InoutBLL(this.CurrentUserInfo); //订单表
            var        pTran     = tInoutbll.GetTran();

            #region 更新订单门店编号

            using (pTran.Connection)
            {
                try
                {
                    //根据订单ID获取实例
                    var entity = tInoutbll.GetByID(orderId);
                    if (entity == null)
                    {
                        throw new APIException(string.Format("未找到对应OrderID:{0}订单", orderId))
                              {
                                  ErrorCode = ERROR_ORDERID_NOEXISTS
                              };
                    }
                    entity.sales_unit_id = returnUnit;
#warning 更新操作user_id

                    #region

                    entity.modify_time    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //更新时间
                    entity.modify_user_id = CurrentUserInfo.UserID;                       //更新人

                    #endregion

                    tInoutbll.Update(entity, pTran); //用事物更新订单表(T_Inout)表中信息
                    pTran.Commit();                  //提交事物
                }
                catch (Exception ex)
                {
                    pTran.Rollback();
                    throw new APIException(ex.Message);
                }

                #endregion

                return(rd);
            }
        }
        protected override GetOrderListByUserIdRD ProcessRequest(DTO.Base.APIRequest <GetOrderListByUserIdRP> pRequest)
        {
            GetOrderListByUserIdRD rd = new GetOrderListByUserIdRD();

            string orderId    = pRequest.Parameters.OrderID;
            string userId     = pRequest.Parameters.UserID;
            string customerId = this.CurrentUserInfo.ClientID;
            int    pageSize   = pRequest.Parameters.PageSize;
            int    pageIndex  = pRequest.Parameters.PageIndex;
            string isPayment  = pRequest.Parameters.IsPayment;

            string orderNo = pRequest.Parameters.OrderNo;

            var orderStatusInfo = pRequest.Parameters.OrderStatus;

            string orderStatusList = "";

            if (orderStatusInfo != null)
            {
                foreach (var item in orderStatusInfo)
                {
                    orderStatusList += item.Status + ",";
                }
            }
            orderStatusList = orderStatusList.Trim(',');


            T_InoutBLL bll = new T_InoutBLL(this.CurrentUserInfo);
            var        ds  = bll.GetOrdersList(orderId, userId, orderStatusList, isPayment, orderNo, customerId, pageSize, pageIndex, pRequest.Parameters.OrderChannelID);

            var tmp = ds.Tables[0].AsEnumerable().Select(t => new OrdersInfo()
            {
                OrderID         = Convert.ToString(t["order_id"]),
                OrderNO         = Convert.ToString(t["order_no"]),
                DeliveryTypeID  = Convert.ToString(t["DeliveryTypeId"]),
                OrderDate       = Convert.ToString(t["OrderDate"]),
                VipName         = Convert.ToString(t["vipName"]),
                OrderStatusDesc = Convert.ToString(t["OrderStatusDesc"]),
                OrderStatus     = Convert.ToInt32(Utils.GetIntVal(FormatParamValue(t["OrderStatus"].ToString()))),
                //  TotalAmount = Convert.ToDecimal(t["TotalAmount"]),
                TotalAmount      = Convert.ToDecimal(t["total_amount"]),
                TotalQty         = Convert.ToDecimal(t["TotalQty"]),
                RetailTraderName = Convert.ToString(t["RetailTraderName"]),
                ServiceMan       = Convert.ToString(t["ServiceMan"]),
                CollectIncome    = Convert.ToDecimal(t["CollectIncome"])
            });


            rd.OrderList = tmp.ToArray();

            return(rd);
        }
Beispiel #8
0
        protected override GetOrderListRD ProcessRequest(APIRequest <GetOrderListRP> pRequest)
        {
            GetOrderListRD rd       = new GetOrderListRD();
            var            orderBLL = new T_InoutBLL(this.CurrentUserInfo);
            bool           pIsIncludeOrderDetails = pRequest.Parameters.IsIncludeOrderDetails;

            int[]  pOrderStatuses = pRequest.Parameters.OrderStatuses;
            string pOrderID       = pRequest.Parameters.OrderID;
            int    pPageSize      = pRequest.Parameters.PageSize;
            int    pPageIndex     = pRequest.Parameters.PageIndex;

            //返回订单列表
            rd = orderBLL.GetOrderList(pIsIncludeOrderDetails, pOrderStatuses, pOrderID, pPageSize, pPageIndex);
            return(rd);
        }
        /// <summary>
        /// 入队列
        /// </summary>
        /// <param name="loggingSessionInfo"></param>
        /// <param name="orderInfo"></param>
        public void SetRedisSalesVipCardOrder(LoggingSessionInfo loggingSessionInfo, T_InoutEntity orderInfo)
        {
            var response = RedisOpenAPI.Instance.CCSalesCardOrder().SetSalesCardOrder(new CC_Order
            {
                CustomerID = loggingSessionInfo.ClientID,
                OrderId    = orderInfo.order_id.ToString(),
                OrderInfo  = orderInfo.JsonSerialize()
            });

            if (response.Code == ResponseCode.Fail)
            {
                //直接计算
                T_InoutBLL inoutBLL = new T_InoutBLL(loggingSessionInfo);
                inoutBLL.CalculateSalesVipCardOrder(loggingSessionInfo, orderInfo);
            }
        }
Beispiel #10
0
        protected override GetOrdersRD ProcessRequest(DTO.Base.APIRequest <GetOrdersRP> pRequest)
        {
            GetOrdersRD rd        = new GetOrdersRD();
            var         detailBll = new T_Inout_DetailBLL(CurrentUserInfo);
            var         orderBll  = new T_InoutBLL(CurrentUserInfo);

            string vipno        = pRequest.UserID;
            string customer_id  = pRequest.CustomerID;
            int    pageindex    = pRequest.Parameters.PageIndex;
            int    PageSize     = pRequest.Parameters.PageSize;
            string ChannelId    = pRequest.ChannelId; // add by donal 2014-9-26 13:34:55
            string UserId       = pRequest.UserID;    // add by donal 2014-9-26 17:46:46
            int    showUnitName = pRequest.Parameters.IsShowUnitName;
            //switch (pRequest.Parameters.GroupingType)
            //{
            //    case 1:
            //    //待付款
            //        rd = orderBll.GetOrder(vipno, pageindex, PageSize, customer_id, pRequest.Parameters.GroupingType);
            //        break;
            //    case 2:
            //    //待收货,提货
            //        rd = orderBll.GetOrder(vipno, pageindex, PageSize, customer_id, pRequest.Parameters.GroupingType);
            //        break;
            //    case 3:
            //        //已完成
            //        rd = orderBll.GetOrder(vipno, pageindex, PageSize, customer_id, pRequest.Parameters.GroupingType);
            //        break;
            //    default:
            //        break;
            //}
            bool isShowUnitName = showUnitName == 1;

            rd = orderBll.GetOrder(vipno, pageindex, PageSize, customer_id, pRequest.Parameters.GroupingType, ChannelId, UserId, isShowUnitName);

            if (!string.IsNullOrEmpty(pRequest.Parameters.UnitID))
            {
                UnitService unitServer = new UnitService(CurrentUserInfo);
                var         unitId     = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识
                if (rd.Orders != null && pRequest.Parameters.UnitID != unitId)
                {
                    rd.Orders = rd.Orders.Where(p => p.purchase_unit_id == pRequest.Parameters.UnitID).ToArray();
                }
            }
            return(rd);
        }
Beispiel #11
0
        protected override EmptyResponseData ProcessRequest(APIRequest <CancelPosOrderRP> pRequest)
        {
            var rp             = pRequest.Parameters;
            var rd             = new EmptyResponseData();
            var vipBll         = new VipBLL(CurrentUserInfo);            //会员业务实例化
            var inoutBLL       = new T_InoutBLL(CurrentUserInfo);
            var vipIntegralBLL = new VipIntegralBLL(CurrentUserInfo);    //积分BLL实例化



            var count = RedisOpenAPI.Instance.CCOrderReward().GetOrderRewardLength(new CC_OrderReward
            {
                CustomerID = CurrentUserInfo.ClientID,
            });

            if (count.Result > 0)
            {
                throw new APIException("队列正在运行,请稍后再试。。")
                      {
                          ErrorCode = 100
                      };
            }


            //获取订单信息
            var inoutInfo = inoutBLL.GetInoutInfo(rp.OrderId, CurrentUserInfo);

            if (inoutInfo == null)
            {
                throw new APIException("未找到该订单信息")
                      {
                          ErrorCode = 101
                      };
            }
            //获取会员信息
            var vipInfo = vipBll.GetByID(inoutInfo.vip_no);

            //处理积分、余额、返现和优惠券
            vipBll.ProcSetCancelOrder(CurrentUserInfo.ClientID, rp.OrderId, pRequest.UserID);
            //取消订单奖励
            vipIntegralBLL.CancelReward(inoutInfo, vipInfo, null);

            return(rd);
        }
Beispiel #12
0
        protected override OrderOperationRD ProcessRequest(DTO.Base.APIRequest <BatchCheckOrderRP> pRequest)
        {
            var rd   = new OrderOperationRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var T_Iount            = new T_InoutBLL(loggingSessionInfo);
            var OrderIdList        = new List <string>();

            foreach (var item in para.OrderList)
            {
                if (item.Status.Equals("100"))
                {
                    OrderIdList.Add(item.OrderID);
                }
            }
            int num = T_Iount.BatchCheckOrder(OrderIdList, para.Remark, loggingSessionInfo);

            rd.Message = "操作成功" + num + "条!";
            return(rd);
        }
Beispiel #13
0
        /// <summary>
        /// 在队列失效的情况下,直接计算
        /// </summary>
        /// <param name="loggingSessionInfo"></param>
        /// <param name="orderInfo"></param>
        public void CalculateVipConsumeForUpgrade(LoggingSessionInfo loggingSessionInfo, T_InoutEntity orderInfo)
        {
            VipCardUpgradeRuleBLL bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo);
            VipCardVipMappingBLL  vipCardVipMappingBLL  = new VipCardVipMappingBLL(loggingSessionInfo);
            T_InoutBLL            bllInout = new T_InoutBLL(loggingSessionInfo);
            var entityVipCardUpgradeRule   = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
            {
                IsBuyUpgrade = 1, CustomerID = loggingSessionInfo.ClientID
            }, null);

            if (entityVipCardUpgradeRule != null)
            {
                decimal vipSumAmount = bllInout.GetVipSumAmount(orderInfo.vip_no);
                bool    isUpdate     = false;
                foreach (var rule in entityVipCardUpgradeRule.OrderByDescending(a => a.VipCardTypeID))
                {
                    if (rule.BuyAmount > 0)
                    {
                        if (vipSumAmount >= rule.BuyAmount)
                        {
                            if (!isUpdate)
                            {
                                vipCardVipMappingBLL.BindVirtualItem(orderInfo.vip_no, orderInfo.VipCardCode, "", (int)rule.VipCardTypeID, "TotalSales", 2, orderInfo.order_id);
                                isUpdate = true;
                            }
                        }
                    }
                    if (rule.OnceBuyAmount > 0)
                    {
                        if (orderInfo.actual_amount >= rule.OnceBuyAmount)
                        {
                            if (!isUpdate)
                            {
                                vipCardVipMappingBLL.BindVirtualItem(orderInfo.vip_no, orderInfo.VipCardCode, "", (int)rule.VipCardTypeID, "OneSales", 2, orderInfo.order_id);
                                isUpdate = true;
                            }
                        }
                    }
                }
            }
        }
Beispiel #14
0
        //<summary>
        //Pos订单入库
        //</summary>
        //<param name="pRequest"></param>
        //<returns></returns>
        protected override SetPosOrderRD ProcessRequest(APIRequest <SetPosOrderRP> pRequest)
        {
            //请求参数
            var rp = pRequest.Parameters;
            //返回参数
            var rd = new SetPosOrderRD();

            //订单
            var inoutBll    = new T_InoutBLL(CurrentUserInfo);
            var inoutDetail = new T_Inout_DetailBLL(CurrentUserInfo);
            //商品
            var itemCategoryBll = new T_Item_CategoryBLL(CurrentUserInfo);
            var itemBll         = new T_ItemBLL(CurrentUserInfo);
            var porpBll         = new T_PropBLL(CurrentUserInfo);
            var itemSkuPropBll  = new T_ItemSkuPropBLL(CurrentUserInfo);
            var skuBll          = new T_SkuBLL(CurrentUserInfo);
            var skuPriceBll     = new T_Sku_PriceBLL(CurrentUserInfo);
            var skuProperty     = new T_Sku_PropertyBLL(CurrentUserInfo);
            //获取会员信息
            var vipBll  = new VipBLL(CurrentUserInfo);
            var vipInfo = vipBll.GetByID(pRequest.UserID);
            var vipCardVipMappingBll    = new VipCardVipMappingBLL(CurrentUserInfo);
            var vipCardBll              = new VipCardBLL(CurrentUserInfo);
            var vipCardVipMappingEntity = vipCardVipMappingBll.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = vipInfo.VIPID, CustomerID = CurrentUserInfo.ClientID
            }, null).FirstOrDefault();
            string VipCardTypeID = ""; //卡类型Id

            if (vipCardVipMappingEntity != null)
            {
                var vipCardEntity = vipCardBll.GetByID(vipCardVipMappingEntity.VipCardID);
                VipCardTypeID = vipCardEntity.VipCardTypeID.ToString();
            }
            //员工
            var userBll = new T_UserBLL(CurrentUserInfo);

            //获取门店信息
            var          unitBll  = new t_unitBLL(CurrentUserInfo);
            t_unitEntity unitInfo = null;

            if (!string.IsNullOrEmpty(rp.UnitCode))
            {
                unitInfo = unitBll.QueryByEntity(new t_unitEntity()
                {
                    unit_code = rp.UnitCode, customer_id = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                if (unitInfo == null)
                {
                    throw new APIException("请在正念商户后台录入相应门店")
                          {
                              ErrorCode = 100
                          };
                }
            }
            else
            {
                throw new APIException("缺少请求参数:门店编码")
                      {
                          ErrorCode = 102
                      };
            }

            //获取员工信息
            T_UserEntity userEntity = null;

            if (!string.IsNullOrEmpty(rp.MobliePhone))
            {
                userEntity = userBll.QueryByEntity(new T_UserEntity()
                {
                    user_telephone = rp.MobliePhone, customer_id = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                //没有员工,新增默认员工(店员APP)
                if (userEntity == null)
                {
                    var roleBll    = new T_RoleBLL(CurrentUserInfo);
                    var roleEntity = roleBll.QueryByEntity(new T_RoleEntity()
                    {
                        role_code = "clerkAPP", customer_id = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    if (roleEntity == null)
                    {
                        throw new APIException("请在正念商户后台录入相应角色")
                              {
                                  ErrorCode = 100
                              };
                    }
                    userEntity = new T_UserEntity();
                    userEntity.user_telephone = rp.MobliePhone;
                    userEntity.user_code      = rp.UserCode;
                    userEntity.user_name      = rp.UserCode;
                    userEntity.user_birthday  = rp.Birthday;
                    userEntity.user_email     = rp.EmailAddress;
                    userEntity.user_address   = rp.Address;
                    userEntity.user_postcode  = rp.Zip;
                    userBll.AddUser(ref userEntity, unitInfo, roleEntity);
                }
            }
            else
            {
                throw new APIException("缺少请求参数:员工手机号")
                      {
                          ErrorCode = 102
                      };
            }
            //获取会员折扣
            var     sysVipCardGradeBLL = new SysVipCardGradeBLL(CurrentUserInfo);
            decimal vipDiscount        = sysVipCardGradeBLL.GetVipDiscount() * 10;


            //订单号
            string        orderId      = BaseService.NewGuidPub();
            T_InoutEntity tInoutEntity = new T_InoutEntity();

            tInoutEntity.order_id = orderId;
            tInoutEntity.order_no = rp.OrderNo;

            //拼接ItemCodes
            //StringBuilder ItemCodes = new StringBuilder();
            //for (int j = 0; j < pRequest.Parameters.OrderDetailList.Count(); j++)
            //{
            //    if (j != 0)
            //    {
            //        ItemCodes.Append(",");
            //    }
            //    ItemCodes.Append(string.Format("{0}", pRequest.Parameters.OrderDetailList[j].ItemCode));
            //}

            ////通过itemCodes取出商品价格
            //SkuPriceService skuPriceService = new SkuPriceService(CurrentUserInfo);
            //List<SkuPrice> skuPriceList = skuPriceService.GetPriceListByItemCodes(ItemCodes.ToString(), CurrentUserInfo.ClientID);
            //if(skuPriceList.Count == 0)
            //{
            //    throw new APIException("未找到商品") { ErrorCode = 100 };
            //}

            //订单总金额
            decimal totalAmount = rp.TotalAmount;
            //订单实付金额
            decimal ActualAmount = rp.DiscountAmount;
            //订单折扣后金额
            decimal DiscountAmount = rp.DiscountAmount;
            //订单明细显示顺序
            int i = 1;

            //商品价格重新计算
            foreach (var item in pRequest.Parameters.OrderDetailList)
            {
                T_ItemEntity itemEntity = null; //商品
                T_SkuEntity  skuEntity  = null; //sku
                if (!string.IsNullOrEmpty(item.ItemCode))
                {
                    itemEntity = itemBll.QueryByEntity(new T_ItemEntity()
                    {
                        item_code = item.ItemCode, CustomerId = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    if (itemEntity == null)
                    {
                        if (string.IsNullOrEmpty(item.ItemCategoryCode))
                        {
                            throw new APIException("缺少参数:商品类别名称")
                                  {
                                      ErrorCode = 200
                                  };
                        }
                        itemEntity           = new T_ItemEntity();
                        itemEntity.item_code = item.ItemCode;
                        itemEntity.item_name = item.ItemName;

                        itemBll.AddItem(itemEntity, out skuEntity, item.ItemCategoryName, item.ItemCategoryCode, item.SkuOriginPrice, item.SkuSalesPrice);
                    }
                    else
                    {
                        skuEntity = skuBll.QueryByEntity(new T_SkuEntity()
                        {
                            item_id = itemEntity.item_id
                        }, null).FirstOrDefault();
                    }
                }
                else
                {
                    throw new APIException("缺少参数:商品编码")
                          {
                              ErrorCode = 300
                          };
                }

                //订单明细相关处理
                T_Inout_DetailBLL    inoutDetailBll    = new T_Inout_DetailBLL(CurrentUserInfo);
                T_Inout_DetailEntity inoutDetailEntity = new T_Inout_DetailEntity()
                {
                    order_detail_id     = BaseService.NewGuidPub(),
                    order_id            = orderId,               //订单Id
                    sku_id              = skuEntity.sku_id,      //skuId
                    unit_id             = unitInfo.unit_id,      //门店Id
                    order_qty           = item.Qty,              //订单qty
                    enter_qty           = item.Qty,              //实际qty
                    enter_price         = item.price,            //折扣价
                    enter_amount        = item.price * item.Qty, //折扣价
                    std_price           = item.price,            //原价
                    discount_rate       = vipDiscount,           //折扣
                    retail_price        = item.price * item.Qty, //零售价
                    retail_amount       = item.price * item.Qty, //零售价
                    order_detail_status = "1",
                    display_index       = i,
                    if_flag             = 0
                };
                inoutDetailBll.Create(inoutDetailEntity);
                i++;
            }

            //优惠券使用
            if (!string.IsNullOrEmpty(rp.CouponId))
            {
                #region 判断优惠券是否是该会员的

                var vipcouponMappingBll = new VipCouponMappingBLL(CurrentUserInfo);

                var vipcouponmappingList = vipcouponMappingBll.QueryByEntity(new VipCouponMappingEntity()
                {
                    VIPID    = pRequest.UserID,
                    CouponID = rp.CouponId
                }, null);

                if (vipcouponmappingList == null || vipcouponmappingList.Length == 0)
                {
                    throw new APIException("此张优惠券不是该会员的")
                          {
                              ErrorCode = 103
                          };
                }

                #endregion

                #region 判断优惠券是否有效

                var couponBll = new CouponBLL(CurrentUserInfo);

                var couponEntity = couponBll.GetByID(rp.CouponId);

                if (couponEntity == null)
                {
                    throw new APIException("无效的优惠券")
                          {
                              ErrorCode = 103
                          };
                }

                if (couponEntity.Status == 1)
                {
                    throw new APIException("优惠券已使用")
                          {
                              ErrorCode = 103
                          };
                }

                if (couponEntity.EndDate < DateTime.Now)
                {
                    throw new APIException("优惠券已过期")
                          {
                              ErrorCode = 103
                          };
                }
                var couponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                var couponTypeEntity = couponTypeBll.GetByID(couponEntity.CouponTypeID);

                if (couponTypeEntity == null)
                {
                    throw new APIException("无效的优惠券类型")
                          {
                              ErrorCode = 103
                          };
                }

                #endregion

                #region 优惠券核销
                var couponUseBll    = new CouponUseBLL(CurrentUserInfo);
                var couponUseEntity = new CouponUseEntity()
                {
                    CouponUseID    = Guid.NewGuid(),
                    CouponID       = rp.CouponId,
                    VipID          = pRequest.UserID,
                    UnitID         = unitInfo.unit_id,
                    OrderID        = orderId,
                    Comment        = "商城使用电子券",
                    CustomerID     = pRequest.CustomerID,
                    CreateBy       = pRequest.UserID,
                    CreateTime     = DateTime.Now,
                    LastUpdateBy   = pRequest.UserID,
                    LastUpdateTime = DateTime.Now,
                    IsDelete       = 0
                };
                couponUseBll.Create(couponUseEntity);
                #endregion

                #region 更新CouponType数量
                var conponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity()
                {
                    CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = pRequest.CustomerID
                }, null).FirstOrDefault();
                conponTypeEntity.IsVoucher += 1;
                conponTypeBll.Update(conponTypeEntity);

                #endregion

                #region 更新优惠券状态

                couponEntity.Status = 1;
                couponBll.Update(couponEntity);

                #endregion

                ActualAmount -= couponTypeEntity.ParValue ?? 0;
            }

            #region 使用积分
            //使用积分
            if (rp.IntegralFlag == 1)
            {
                var vipIntegralBll = new VipIntegralBLL(CurrentUserInfo);

                string sourceId       = "20"; //积分抵扣
                var    IntegralDetail = new VipIntegralDetailEntity()
                {
                    Integral         = -Convert.ToInt32(rp.Integral),
                    IntegralSourceID = sourceId,
                    ObjectId         = orderId
                };
                if (IntegralDetail.Integral != 0)
                {
                    //变动前积分
                    string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                    //变动积分
                    string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                    var    vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, CurrentUserInfo);
                    //发送微信积分变动通知模板消息
                    if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                    {
                        var CommonBLL = new CommonBLL();
                        CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, CurrentUserInfo);
                    }
                }
                tInoutEntity.pay_points     = rp.Integral;
                tInoutEntity.receive_points = rp.Integral;
                ActualAmount -= rp.IntegralAmount;
            }
            #endregion

            #region 余额和返现修改

            var vipAmountBll       = new VipAmountBLL(CurrentUserInfo);
            var vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo);

            var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
            {
                VipId = pRequest.UserID, VipCardCode = vipInfo.VipCode
            }, null).FirstOrDefault();
            if (vipAmountEntity != null)
            {
                //判断该会员账户是否被冻结
                if (vipAmountEntity.IsLocking == 1)
                {
                    throw new APIException("账户已被冻结,请先解冻")
                          {
                              ErrorCode = 103
                          }
                }
                ;

                //判断该会员的账户余额是否大于本次使用的余额
                if (vipAmountEntity.EndAmount < rp.EndAmount)
                {
                    throw new APIException(string.Format("账户余额不足,当前余额为【{0}】", vipAmountEntity.EndAmount))
                          {
                              ErrorCode = 103
                          }
                }
                ;
            }

            //使用余额
            if (rp.EndAmountFlag == 1)
            {
                var detailInfo = new VipAmountDetailEntity()
                {
                    Amount         = -rp.EndAmount,
                    AmountSourceId = "1",
                    ObjectId       = orderId
                };
                var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, CurrentUserInfo);
                if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                {//发送微信账户余额变动模板消息
                    var CommonBLL = new CommonBLL();
                    CommonBLL.BalanceChangedMessage(tInoutEntity.order_no, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, CurrentUserInfo);
                }
                tInoutEntity.Field3 = rp.EndAmount.ToString();
            }

            #endregion
            //订单主表更新
            tInoutEntity.VipCardCode      = vipInfo.VipCardCode;//会员卡号
            tInoutEntity.order_reason_id  = "2F6891A2194A4BBAB6F17B4C99A6C6F5";
            tInoutEntity.order_type_id    = "1F0A100C42484454BAEA211D4C14B80F";
            tInoutEntity.warehouse_id     = "67bb4c12785c42d4912aff7d34606592";
            tInoutEntity.data_from_id     = "";
            tInoutEntity.red_flag         = "1";
            tInoutEntity.order_date       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //订单时间
            tInoutEntity.create_unit_id   = unitInfo.unit_id;                             //门店
            tInoutEntity.unit_id          = unitInfo.unit_id;                             //门店
            tInoutEntity.sales_unit_id    = unitInfo.unit_id;                             //门店
            tInoutEntity.purchase_unit_id = unitInfo.unit_id;
            tInoutEntity.sales_user       = userEntity.user_id;
            tInoutEntity.total_amount     = totalAmount;  //订单金额
            tInoutEntity.discount_rate    = vipDiscount;  //会员折扣
            tInoutEntity.actual_amount    = ActualAmount; //实付金额
            tInoutEntity.total_qty        = rp.qty;
            tInoutEntity.total_retail     = totalAmount;  //订单金额
            tInoutEntity.vip_no           = vipInfo.VIPID;
            tInoutEntity.Field6           = vipInfo.Phone;
            tInoutEntity.Field14          = vipInfo.VipName;
            tInoutEntity.Field17          = VipCardTypeID;
            tInoutEntity.Field12          = DiscountAmount.ToString();
            tInoutEntity.Field11          = "知行易";
            tInoutEntity.customer_id      = CurrentUserInfo.ClientID;

            tInoutEntity.Field1      = "1";   //支付完成
            tInoutEntity.Field7      = "700"; //已完成
            tInoutEntity.status      = "700"; //已完成
            tInoutEntity.status_desc = "已完成";
            tInoutEntity.Field10     = "已完成";
            rd.Amount = ActualAmount - rp.EndAmount;

            inoutBll.Create(tInoutEntity);

            //订单奖励
            new SendOrderRewardMsgBLL().OrderReward(tInoutEntity, this.CurrentUserInfo, null);//存入到缓存
            rd.orderId = orderId;
            return(rd);
        }
    }
}
        /// <summary>
        /// 种植 角色菜单 缓存
        /// </summary>
        public void AutoSetOrderNotPayCache()
        {
            _CustomerIDList = CustomerBLL.Instance.GetCustomerList();
            foreach (var customer in _CustomerIDList)
            {
                //
                _T_loggingSessionInfo.ClientID = customer.Key;
                _T_loggingSessionInfo.CurrentLoggingManager.Connection_String = customer.Value;

                //
                _T_InoutBLL    = new T_InoutBLL(_T_loggingSessionInfo);
                _Inout3Service = new Inout3Service(_T_loggingSessionInfo);
                _VipBLL        = new VipBLL(_T_loggingSessionInfo);

                //
                // var t_InoutList = new List<string>();
                try
                {
                    var t_InoutEntitys = _T_InoutBLL.QueryByEntity(new T_InoutEntity
                    {
                        customer_id = customer.Key,
                        Field1      = "0",  //未支付
                        status      = "100" //已经正式提交
                    }, null);
                    if (t_InoutEntitys == null || t_InoutEntitys.Count() <= 0)
                    {
                        continue;
                    }
                    //
                    //   roleList = roleEntities.Select(it => it.role_id).ToList();

                    string productNames = "";
                    foreach (var t_InoutInfo in t_InoutEntitys)
                    {
                        //每次都重新设置
                        productNames = "";
                        var _T_Inout_DetailList = _Inout3Service.GetInoutDetailInfoByOrderId(t_InoutInfo.order_id, _T_loggingSessionInfo.ClientID);

                        if (_T_Inout_DetailList != null && _T_Inout_DetailList.Count > 0)//获取商品信息
                        {
                            foreach (var _T_Inout_DetailInfo in _T_Inout_DetailList)
                            {
                                if (productNames == "")
                                {
                                    productNames += _T_Inout_DetailInfo.item_name + "*" + _T_Inout_DetailInfo.order_qty;
                                }
                                else
                                {
                                    productNames += "," + _T_Inout_DetailInfo.item_name + "*" + _T_Inout_DetailInfo.order_qty;
                                }
                            }
                        }
                        try
                        {
                            //获取会员的信息
                            var vip = _VipBLL.GetByID(t_InoutInfo.vip_no);

                            new SendOrderNotPayMsgBLL().NotPayMessage(t_InoutInfo.actual_amount.ToString(), productNames, t_InoutInfo.Field4, t_InoutInfo.order_no, vip.WeiXinUserId, _T_loggingSessionInfo);
                        }
                        catch { continue; }
                    }
                }
                catch
                {
                    continue;
                }
            }
        }
        protected override GetSalesReturnDetailRD ProcessRequest(DTO.Base.APIRequest <GetSalesReturnDetailRP> pRequest)
        {
            var rd   = new GetSalesReturnDetailRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var salesReturnBLL     = new T_SalesReturnBLL(loggingSessionInfo);
            var historyBLL         = new T_SalesReturnHistoryBLL(loggingSessionInfo);

            var inoutService      = new InoutService(loggingSessionInfo);
            var tInoutDetailBll   = new TInoutDetailBLL(loggingSessionInfo);
            var inoutBLL          = new T_InoutBLL(CurrentUserInfo);
            var salesReturnEntity = salesReturnBLL.GetByID(para.SalesReturnID);
            var PaymentTtpeBLL    = new T_Payment_TypeBLL(loggingSessionInfo);

            if (salesReturnEntity != null)
            {
                var orderInfo = inoutBLL.GetByID(salesReturnEntity.OrderID);

                rd.SalesReturnID = salesReturnEntity.SalesReturnID.ToString();
                rd.SalesReturnNo = salesReturnEntity.SalesReturnNo;
                rd.OrderID       = salesReturnEntity.OrderID;

                rd.OrderNo = orderInfo.order_no;

                rd.Status       = salesReturnEntity.Status;
                rd.DeliveryType = salesReturnEntity.DeliveryType;
                rd.Reason       = salesReturnEntity.Reason;
                rd.Qty          = salesReturnEntity.Qty;
                rd.ActualQty    = salesReturnEntity.ActualQty;
                rd.Contacts     = salesReturnEntity.Contacts;
                rd.Phone        = salesReturnEntity.Phone;
                rd.Address      = string.Empty;

                if (orderInfo != null)
                {
                    rd.Address = orderInfo.Field4;
                }
                rd.ServicesType = salesReturnEntity.ServicesType;

                //根据订单ID获取订单明细[复用]
                DataRow drItem = inoutService.GetOrderDetailByOrderId(salesReturnEntity.OrderID).Tables[0].Select(" item_id= '" + salesReturnEntity.ItemID + "'").FirstOrDefault();
                //获取商品的图片[复用]
                //string itemImage = tInoutDetailBll.GetOrderDetailImageList("'" + salesReturnEntity.ItemID + "'").Tables[0].Rows[0]["imageUrl"].ToString();
                string  itemImage = string.Empty;
                DataSet ds        = tInoutDetailBll.GetOrderDetailImageList("'" + salesReturnEntity.ItemID + "'");
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    itemImage = ds.Tables[0].Rows[0]["imageUrl"].ToString();
                }

                //获取订单详细列表中的商品规格[复用]
                DataRow[] drSku = inoutService.GetInoutDetailGgByOrderId(salesReturnEntity.OrderID).Tables[0].Select(" sku_id='" + salesReturnEntity.SkuID + "'");

                //订单的商品信息
                var orderDetail = new OrderInfoDetail();

                orderDetail.ItemName   = drItem["item_name"].ToString();
                orderDetail.SalesPrice = Convert.ToDecimal(drItem["enter_price"]);
                orderDetail.Qty        = Convert.ToInt32(drItem["enter_qty"]);
                if (!string.IsNullOrEmpty(itemImage))
                {
                    orderDetail.ImageUrl = ImagePathUtil.GetImagePathStr(itemImage, "240");
                }

                orderDetail.PayTypeName = salesReturnEntity.PayTypeName;
                //支付方式名称
                var    OrderData     = inoutBLL.GetByID(salesReturnEntity.OrderID);
                string m_PayTypeName = "";
                if (OrderData != null)
                {
                    var PayTypeData = PaymentTtpeBLL.GetByID(OrderData.pay_id);
                    if (PayTypeData != null)
                    {
                        m_PayTypeName = PayTypeData.Payment_Type_Name;
                    }
                }
                orderDetail.PayTypeName = m_PayTypeName;


                orderDetail.RefundAmount  = salesReturnEntity.RefundAmount == null ? 0 : salesReturnEntity.RefundAmount.Value;
                orderDetail.ConfirmAmount = salesReturnEntity.ConfirmAmount == null ? 0 : salesReturnEntity.ConfirmAmount.Value;
                rd.OrderDetail            = orderDetail;
                //订单的商品规格
                if (drSku.Count() > 0)
                {
                    SkuDetailInfo skuDetail = new SkuDetailInfo();
                    skuDetail.PropName1       = drSku[0]["prop_1_name"].ToString();
                    skuDetail.PropDetailName1 = drSku[0]["prop_1_detail_name"].ToString();
                    skuDetail.PropName2       = drSku[0]["prop_2_name"].ToString();
                    skuDetail.PropDetailName2 = drSku[0]["prop_2_detail_name"].ToString();
                    skuDetail.PropName3       = drSku[0]["prop_3_name"].ToString();
                    skuDetail.PropDetailName3 = drSku[0]["prop_3_detail_name"].ToString();
                    rd.OrderDetail.SkuDetail  = skuDetail;
                }
                var history = historyBLL.QueryByEntity(new T_SalesReturnHistoryEntity()
                {
                    SalesReturnID = salesReturnEntity.SalesReturnID
                }, new[] { new OrderBy {
                               FieldName = "CreateTime", Direction = OrderByDirections.Desc
                           } });
                rd.HistoryList = history.Select(t => new HistoryInfo()
                {
                    HistoryID = t.HistoryID.ToString(), OperationDesc = t.OperationDesc, HisRemark = t.HisRemark, OperatorName = t.OperatorName, CreateTime = t.CreateTime.Value.ToString("yyyy-MM-dd HH:mm")
                }).ToArray();
            }
            return(rd);
        }
Beispiel #17
0
        /// <summary>
        /// 销售升级job
        /// </summary>
        public void CalculateVipConsumeForUpgradeJob()
        {
            var numCount    = 50;
            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                string connString = customer.Value;
                var    count      = RedisOpenAPI.Instance.CCAllOrder().GetOrderLength(new CC_Order
                {
                    CustomerID = customer.Key
                });
                if (count.Code != ResponseCode.Success)
                {
                    BaseService.WriteLog("从redis获取充值订单数据失败");
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }
                var loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "RedisSystem");
                VipCardUpgradeRuleBLL bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo);
                VipCardVipMappingBLL  vipCardVipMappingBLL  = new VipCardVipMappingBLL(loggingSessionInfo);
                T_InoutBLL            bllInout = new T_InoutBLL(loggingSessionInfo);
                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCAllOrder().GetOrder(new CC_Order
                    {
                        CustomerID = customer.Key
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var orderInfo = response.Result.OrderInfo.JsonDeserialize <T_InoutEntity>();
                        var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                        {
                            IsBuyUpgrade = 1, CustomerID = loggingSessionInfo.ClientID
                        }, null);
                        if (entityVipCardUpgradeRule != null)
                        {
                            decimal vipSumAmount = bllInout.GetVipSumAmount(orderInfo.vip_no);
                            bool    isUpdate     = false;
                            foreach (var rule in entityVipCardUpgradeRule.OrderByDescending(a => a.VipCardTypeID))
                            {
                                if (rule.BuyAmount > 0)
                                {
                                    if (vipSumAmount >= rule.BuyAmount)
                                    {
                                        if (!isUpdate)
                                        {
                                            vipCardVipMappingBLL.BindVirtualItem(orderInfo.vip_no, orderInfo.VipCardCode, "", (int)rule.VipCardTypeID, "TotalSales", 2, orderInfo.order_id);
                                            isUpdate = true;
                                        }
                                    }
                                }
                                if (rule.OnceBuyAmount > 0)
                                {
                                    if (orderInfo.actual_amount >= rule.OnceBuyAmount)
                                    {
                                        if (!isUpdate)
                                        {
                                            vipCardVipMappingBLL.BindVirtualItem(orderInfo.vip_no, orderInfo.VipCardCode, "", (int)rule.VipCardTypeID, "OneSales", 2, orderInfo.order_id);
                                            isUpdate = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <SetSalesReturnRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var salesReturnBLL     = new T_SalesReturnBLL(loggingSessionInfo);
            var historyBLL         = new T_SalesReturnHistoryBLL(loggingSessionInfo);
            var refundOrderBLL     = new T_RefundOrderBLL(loggingSessionInfo);

            var inoutBLL     = new T_InoutBLL(loggingSessionInfo);
            var inoutService = new InoutService(loggingSessionInfo);

            var vipAmountBLL   = new VipAmountBLL(loggingSessionInfo);   //余额返现BLL实例化
            var vipIntegralBLL = new VipIntegralBLL(loggingSessionInfo); //积分BLL实例化

            var pTran = salesReturnBLL.GetTran();                        //事务
            T_SalesReturnEntity        salesReturnEntity = null;
            T_SalesReturnHistoryEntity historyEntity     = null;

            T_RefundOrderEntity refundEntity = null;

            var          vipBll     = new VipBLL(loggingSessionInfo);    //会员BLL实例化
            var          userBll    = new T_UserBLL(loggingSessionInfo); //店员BLL实例化
            T_UserEntity userEntity = null;                              //店员信息
            var          unitBLL    = new t_unitBLL(loggingSessionInfo);

            salesReturnEntity = salesReturnBLL.GetByID(para.SalesReturnID);
            //获取订单信息
            var inoutInfo = inoutBLL.GetInoutInfo(salesReturnEntity.OrderID, loggingSessionInfo);
            //获取会员信息
            var vipInfo = vipBll.GetByID(inoutInfo.vip_no);
            //获取门店信息
            t_unitEntity unitInfo = null;

            if (!string.IsNullOrEmpty(inoutInfo.sales_unit_id))
            {
                unitInfo = unitBLL.GetByID(inoutInfo.sales_unit_id);
            }
            userEntity = userBll.GetByID(loggingSessionInfo.UserID);
            using (pTran.Connection)
            {
                try
                {
                    switch (para.OperationType)
                    {
                    case 1:
                        #region 审核通过
                        salesReturnEntity.Status = 4;    //审核通过

                        #region 计算应退金额
                        decimal payable = 0;       //计算后应退金额

                        //根据订单ID获取订单明细[复用]
                        DataRow drItem     = inoutService.GetOrderDetailByOrderId(salesReturnEntity.OrderID).Tables[0].Select(" item_id= '" + salesReturnEntity.ItemID + "'").FirstOrDefault();
                        decimal salesPrice = Convert.ToDecimal(drItem["enter_price"]);
                        if (inoutInfo != null)
                        {
                            //订单总金额-运费
                            decimal tempAmount = inoutInfo.total_amount.Value - inoutInfo.DeliveryAmount;
                            //计算会员折扣
                            decimal discount = 1;
                            if (inoutInfo.discount_rate.Value > 0)
                            {
                                discount = inoutInfo.discount_rate.Value / 100;
                            }
                            //计算后应退金额
                            //payable = (((tempAmount - inoutInfo.CouponAmount) * discount) / tempAmount) * (salesPrice * salesReturnEntity.ActualQty.Value);
                            //公式:比例 =(应付金额 * 会员折扣 - 优惠券)/ 应付金额
                            //      应退金额 = 退货数量 * 销售价 * 比例
                            payable = ((tempAmount * discount - inoutInfo.CouponAmount) / tempAmount) * (salesPrice * salesReturnEntity.ActualQty.Value);
                        }
                        salesReturnEntity.RefundAmount  = payable;      //应退金额
                        salesReturnEntity.ConfirmAmount = payable;      //实退金额,默认为应退金额,可支持修改
                        #endregion

                        salesReturnBLL.Update(salesReturnEntity, pTran);

                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 4,
                            OperationDesc = "审核",
                            OperatorID    = loggingSessionInfo.UserID,
                            HisRemark     = "您的服务单已审核通过,请将商品寄回",
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 1
                        };
                        historyBLL.Create(historyEntity, pTran);

                        #endregion
                        break;

                    case 2:
                        #region 审核不通过
                        salesReturnEntity.Status = 3;    //审核不通过
                        salesReturnBLL.Update(salesReturnEntity, pTran);

                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 3,
                            OperationDesc = "审核",
                            OperatorID    = loggingSessionInfo.UserID,
                            HisRemark     = para.Desc,
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 1
                        };
                        historyBLL.Create(historyEntity, pTran);
                        break;

                        #endregion
                    case 3:
                        #region 确认收货
                        salesReturnEntity.Status = 6;    //确认收货
                        salesReturnBLL.Update(salesReturnEntity, pTran);

                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 6,
                            OperationDesc = "收货",
                            OperatorID    = loggingSessionInfo.UserID,
                            HisRemark     = "您的服务单" + salesReturnEntity.SalesReturnNo + "的商品已经收到",
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 1
                        };
                        historyBLL.Create(historyEntity, pTran);
                        //退货时生成退款单
                        if (salesReturnEntity.ServicesType == 1)
                        {
                            refundEntity = new T_RefundOrderEntity();
                            refundEntity.SalesReturnID = salesReturnEntity.SalesReturnID;
                            refundEntity.RefundNo      = DateTime.Now.ToString("yyyyMMddhhmmfff");
                            refundEntity.VipID         = salesReturnEntity.VipID;
                            refundEntity.DeliveryType  = salesReturnEntity.DeliveryType;
                            refundEntity.OrderID       = salesReturnEntity.OrderID;
                            refundEntity.ItemID        = salesReturnEntity.ItemID;
                            refundEntity.SkuID         = salesReturnEntity.SkuID;
                            refundEntity.Qty           = salesReturnEntity.Qty;
                            refundEntity.ActualQty     = salesReturnEntity.ActualQty;
                            refundEntity.UnitID        = salesReturnEntity.UnitID;
                            refundEntity.UnitName      = salesReturnEntity.UnitName;
                            refundEntity.UnitTel       = salesReturnEntity.UnitTel;
                            refundEntity.Address       = salesReturnEntity.Address;
                            refundEntity.Contacts      = salesReturnEntity.Contacts;
                            refundEntity.Phone         = salesReturnEntity.Phone;
                            refundEntity.RefundAmount  = salesReturnEntity.RefundAmount;        //退款金额
                            refundEntity.ConfirmAmount = salesReturnEntity.ConfirmAmount;       //确认退款金额

                            #region 计算应退现金金额、余额、积分、返现
                            var inoutDetail = inoutBLL.GetInoutInfo(salesReturnEntity.OrderID, loggingSessionInfo);
                            if (inoutDetail != null)
                            {
                                //订单实付金额-运费 >= 应退金额
                                if (inoutDetail.actual_amount - inoutDetail.DeliveryAmount >= salesReturnEntity.ConfirmAmount)
                                {
                                    refundEntity.ActualRefundAmount = salesReturnEntity.ConfirmAmount;
                                }
                                //订单实付金额-运费+余额抵扣 >= 应退金额
                                else if (inoutDetail.actual_amount - inoutDetail.DeliveryAmount + inoutDetail.VipEndAmount >= salesReturnEntity.ConfirmAmount)
                                {
                                    refundEntity.ActualRefundAmount = inoutDetail.actual_amount - inoutDetail.DeliveryAmount;     //实付金额
                                    //refundEntity.Amount = salesReturnEntity.ConfirmAmount - inoutDetail.actual_amount;  //退回余额
                                    refundEntity.Amount = salesReturnEntity.ConfirmAmount - refundEntity.ActualRefundAmount;      //退回余额
                                }
                                //订单实付金额-运费+余额抵扣+积分抵扣 >= 应退金额
                                else if (inoutDetail.actual_amount - inoutDetail.DeliveryAmount + inoutDetail.VipEndAmount + inoutDetail.IntegralAmount >= salesReturnEntity.ConfirmAmount)
                                {
                                    refundEntity.ActualRefundAmount = inoutDetail.actual_amount - inoutDetail.DeliveryAmount; //实付金额
                                    refundEntity.Amount             = inoutDetail.VipEndAmount;                               //退回余额
                                    //退回积分抵扣金额
                                    refundEntity.PointsAmount = salesReturnEntity.ConfirmAmount.Value - (inoutDetail.actual_amount.Value - inoutDetail.DeliveryAmount) - inoutDetail.VipEndAmount;
                                    //退回积分
                                    refundEntity.Points = (int)Math.Round(refundEntity.PointsAmount.Value * (inoutDetail.pay_points.Value / inoutDetail.IntegralAmount), 1);
                                }
                                else                                                                                    //订单实付金额-运费+余额抵扣+积分抵扣 < 应退金额
                                {
                                    refundEntity.Points             = (int)Math.Round(inoutDetail.pay_points.Value, 1); //退回积分
                                    refundEntity.PointsAmount       = inoutDetail.IntegralAmount;                       //退回积分抵扣金额
                                    refundEntity.Amount             = inoutDetail.VipEndAmount;                         //退回余额
                                    refundEntity.ActualRefundAmount = salesReturnEntity.ConfirmAmount;                  //实付金额
                                }
                                //订单实付金额-运费+余额抵扣+积分抵扣 >= 应退金额
                                //取消返现
                                //else if (inoutDetail.actual_amount - inoutDetail.DeliveryAmount + inoutDetail.VipEndAmount + inoutDetail.IntegralAmount + inoutDetail.ReturnAmount >= salesReturnEntity.ConfirmAmount)
                                //{
                                //    refundEntity.ActualRefundAmount = inoutDetail.actual_amount - inoutDetail.DeliveryAmount;//实付金额
                                //    refundEntity.Amount = inoutDetail.VipEndAmount;             //退回余额
                                //    refundEntity.Points = (int)Math.Round(inoutDetail.pay_points.Value, 1);//退回积分
                                //    refundEntity.PointsAmount = inoutDetail.IntegralAmount;       //退回积分抵扣金额
                                //    //退回的返现
                                //    refundEntity.ReturnAmount = salesReturnEntity.ConfirmAmount.Value - (inoutDetail.actual_amount.Value - inoutDetail.DeliveryAmount) - inoutDetail.VipEndAmount - inoutDetail.IntegralAmount;
                                //}
                            }
                            #endregion

                            refundEntity.Status     = 1;      //待退款
                            refundEntity.CustomerID = loggingSessionInfo.ClientID;
                            refundOrderBLL.Create(refundEntity, pTran);

                            var vipAmountEntity = vipAmountBLL.QueryByEntity(new VipAmountEntity()
                            {
                                VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
                            }, null).FirstOrDefault();

                            //退货返回余额
                            if (refundEntity.Amount > 0)
                            {
                                //变更余额和余额记录
                                var detailInfo = new VipAmountDetailEntity()
                                {
                                    Amount         = refundEntity.Amount.Value,
                                    AmountSourceId = "21",
                                    ObjectId       = refundEntity.RefundID.ToString()
                                };
                                var vipAmountDetailId = vipAmountBLL.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, pTran, loggingSessionInfo);
                                if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                                {    //发送微信账户余额变动模板消息
                                    var CommonBLL = new CommonBLL();
                                    CommonBLL.BalanceChangedMessage(inoutInfo.order_no, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                }
                            }
                            //退货返回返现
                            if (refundEntity.ReturnAmount > 0)
                            {
                                var detailInfo = new VipAmountDetailEntity()
                                {
                                    Amount         = refundEntity.ReturnAmount.Value,
                                    ObjectId       = refundEntity.RefundID.ToString(),
                                    AmountSourceId = "22"
                                };
                                var vipAmountDetailId = vipAmountBLL.AddReturnAmount(vipInfo, unitInfo, vipAmountEntity, ref detailInfo, pTran, loggingSessionInfo);
                                if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                                {    //发送返现到账通知微信模板消息
                                    var CommonBLL = new CommonBLL();
                                    CommonBLL.CashBackMessage(salesReturnEntity.OrderNo, detailInfo.Amount, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                }
                            }
                            //退货返回积分
                            if (refundEntity.Points > 0)
                            {
                                var IntegralDetail = new VipIntegralDetailEntity()
                                {
                                    Integral         = refundEntity.Points.Value,
                                    IntegralSourceID = "26",
                                    ObjectId         = refundEntity.RefundID.ToString()
                                };

                                if (IntegralDetail.Integral != 0)
                                {
                                    //变动前积分
                                    string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                                    //变动积分
                                    string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                                    var    vipIntegralDetailId = vipIntegralBLL.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, pTran, loggingSessionInfo);
                                    //发送微信积分变动通知模板消息
                                    if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                                    {
                                        var CommonBLL = new CommonBLL();
                                        CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, loggingSessionInfo);
                                    }
                                }
                            }
                            //确认收货时退回订单奖励积分、返现和佣金
                            vipIntegralBLL.CancelReward(inoutInfo, vipInfo, pTran);
                        }
                        #endregion
                        break;

                    case 4:
                        #region 拒绝收货
                        salesReturnEntity.Status = 5;    //拒绝收货
                        salesReturnBLL.Update(salesReturnEntity, pTran);

                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 5,
                            OperationDesc = "收货",
                            OperatorID    = loggingSessionInfo.UserID,
                            HisRemark     = para.Desc,
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 1
                        };
                        historyBLL.Create(historyEntity, pTran);
                        #endregion
                        break;

                    case 5:
                        #region 修改信息
                        if (para.ServicesType > 0)     //修改服务方式
                        {
                            salesReturnEntity.ServicesType = para.ServicesType;
                            string servicesTypeDesc = para.ServicesType == 1 ? "退货" : "换货";
                            historyEntity = new T_SalesReturnHistoryEntity()
                            {
                                SalesReturnID = salesReturnEntity.SalesReturnID,
                                OperationType = 11,
                                OperationDesc = "修改信息",
                                OperatorID    = loggingSessionInfo.UserID,
                                HisRemark     = "修改服务方式为" + servicesTypeDesc,
                                OperatorName  = userEntity.user_name,
                                OperatorType  = 1,
                                IsDelete      = 1
                            };
                            historyBLL.Create(historyEntity, pTran);
                        }
                        if (para.ActualQty > 0)    //修改申请数量
                        {
                            salesReturnEntity.ActualQty = para.ActualQty;
                            historyEntity = new T_SalesReturnHistoryEntity()
                            {
                                SalesReturnID = salesReturnEntity.SalesReturnID,
                                OperationType = 11,
                                OperationDesc = "修改信息",
                                OperatorID    = loggingSessionInfo.UserID,
                                HisRemark     = "修改确认退货数量为" + para.ActualQty,
                                OperatorName  = userEntity.user_name,
                                OperatorType  = 1,
                                IsDelete      = 1
                            };
                            historyBLL.Create(historyEntity, pTran);
                        }
                        if (para.ConfirmAmount >= 0)    //处理实退金额
                        {
                            salesReturnEntity.ConfirmAmount = para.ConfirmAmount;

                            historyEntity = new T_SalesReturnHistoryEntity()
                            {
                                SalesReturnID = salesReturnEntity.SalesReturnID,
                                OperationType = 13,
                                OperationDesc = "修改信息",
                                OperatorID    = loggingSessionInfo.UserID,
                                HisRemark     = "修改实退金额为" + para.ConfirmAmount,
                                OperatorName  = userEntity.user_name,
                                OperatorType  = 1,
                                IsDelete      = 1
                            };
                            historyBLL.Create(historyEntity, pTran);
                        }
                        salesReturnBLL.Update(salesReturnEntity, pTran);
                        #endregion
                        break;

                    case 6:
                        #region 取消
                        salesReturnEntity.Status = 2;    //取消申请
                        salesReturnBLL.Update(salesReturnEntity, pTran);
                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 2,
                            OperationDesc = "取消申请",
                            OperatorID    = CurrentUserInfo.UserID,
                            HisRemark     = para.Desc,
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 0
                        };
                        historyBLL.Create(historyEntity, pTran);
                        #endregion
                        break;

                    default:
                        break;
                    }
                    pTran.Commit();  //提交事物
                }
                catch (Exception ex)
                {
                    pTran.Rollback();//回滚事务
                    throw new APIException(ex.Message);
                }
            }
            return(rd);
        }
Beispiel #19
0
        protected override ProcessActionRD ProcessRequest(APIRequest <ProcessActionRP> pRequest)
        {
            #region 错误码
            const int ERROR_ORDER_NOTEXISTS = 301;
            const int ERROR_ORDER_PROCESSED = 302;
            #endregion
            ProcessActionRD rd               = new ProcessActionRD();
            T_InoutBLL      _TInoutbll       = new T_InoutBLL(this.CurrentUserInfo);      //订单表
            TInoutStatusBLL _TInoutStatusBLL = new TInoutStatusBLL(this.CurrentUserInfo); //日志表
            VipIntegralBLL  vipIntegralBLL   = new VipIntegralBLL(this.CurrentUserInfo);  //会员业务对象实例化
            var             UserBLL          = new T_UserBLL(this.CurrentUserInfo);       //员工实例

            string OrderID         = pRequest.Parameters.OrderID;                         //订单ID
            string ActionCode      = pRequest.Parameters.ActionCode;                      //订单操作码(当前订单状态码作为操作码)
            string ActionParameter = pRequest.Parameters.ActionParameter;                 //订单操作参数,可为空
            string DeliverCompany  = pRequest.Parameters.DeliverCompany;                  //快递公司
            string DeliverOrder    = pRequest.Parameters.DeliverOrder;                    //快递单号

            string VipID = pRequest.UserID;
            if (pRequest.ChannelId != "2")
            {
                VipID = pRequest.Parameters.VipID;
            }

            var tran = _TInoutbll.GetTran();
            using (tran.Connection)//事物
            {
                try
                {
                    #region 1.根据订单ID,订单操作码更新订单表中订单状态和状态描述

                    var entity = _TInoutbll.GetInoutInfo(OrderID, this.CurrentUserInfo); //根据标识获取新的实例

                    if (entity.status == ActionCode)                                     //判断是否重复操作
                    {
                        throw new APIException("操作已处理")
                              {
                                  ErrorCode = ERROR_ORDER_PROCESSED
                              }
                    }
                    ;

                    #region 当状态为完成时,返现,返积分
                    if (ActionCode == "700" && entity.status != "700")
                    {
                        //确认收货时处理积分、返现、佣金[完成订单]
                        // vipIntegralBLL.OrderReward(entity, tran);
                        new SendOrderRewardMsgBLL().OrderReward(entity, this.CurrentUserInfo, tran);//存入到缓存
                    }

                    #endregion
                    if (entity == null)
                    {
                        throw new APIException(string.Format("未找到OrderID:{0}订单", pRequest.Parameters.OrderID))
                              {
                                  ErrorCode = ERROR_ORDER_NOTEXISTS
                              }
                    }
                    ;

                    if (entity.status == ActionCode) //如果状态以及国内是要提交的状态了,就不要再提交了
                    {
                        return(rd);
                    }

                    string Updatebeforestatus = entity.status_desc;                       //更新之前的订单状态描述
                    entity.status         = ActionCode;                                   //输入的状态码
                    entity.Field7         = ActionCode;
                    entity.status_desc    = GetStatusDesc(ActionCode);                    //输入的状态码对应的状态描述
                    entity.Field10        = GetStatusDesc(ActionCode);                    //Field10=status_desc状态描述
                    entity.modify_time    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //修改时间
                    entity.modify_user_id = pRequest.UserID;                              //修改人

                    if (ActionCode == "600" || !string.IsNullOrEmpty(DeliverOrder) || !string.IsNullOrEmpty(DeliverCompany))
                    {
                        entity.Field9     = DateTime.Now.ToSQLFormatString();
                        entity.Field2     = DeliverOrder;   //快递单号
                        entity.carrier_id = DeliverCompany; //快递单号
                        //更新订单配送商及配送单号
                    }

                    if (ActionCode == "700" && pRequest.ChannelId != "2")
                    {
                        if (string.IsNullOrEmpty(entity.sales_user))
                        {
                            entity.sales_user = pRequest.UserID;//把当前用户作为服务人员。****!!
                        }
                        //更新订单支付状态
                        entity.Field1       = "1";
                        entity.accpect_time = DateTime.Now.ToString();

                        #region 提货,订单明细修改

                        T_Inout_DetailBLL  inoutDetailBll     = new T_Inout_DetailBLL(CurrentUserInfo);
                        VipAmountDetailBLL vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo);
                        if (pRequest.Parameters.OrderItemInfoList != null)
                        {
                            foreach (var item in pRequest.Parameters.OrderItemInfoList)
                            {
                                T_Inout_DetailEntity inoutDetailEntity = inoutDetailBll.QueryByEntity(new T_Inout_DetailEntity()
                                {
                                    order_id = OrderID, sku_id = item.SkuId
                                }, null).FirstOrDefault();
                                var vipAmountDetailEntity = vipAmountDetailBll.QueryByEntity(new VipAmountDetailEntity()
                                {
                                    ObjectId = OrderID, AmountSourceId = "1"
                                }, null).FirstOrDefault();
                                //将提货金额 + 余额 = SumPrice
                                if (vipAmountDetailEntity != null)
                                {
                                    item.SumPrice += Math.Abs(Convert.ToDecimal(vipAmountDetailEntity.Amount));
                                }
                                inoutDetailEntity.enter_qty    = item.EnterQty;
                                inoutDetailEntity.Field9       = "kg";
                                inoutDetailEntity.enter_amount = item.SumPrice;
                                inoutDetailEntity.enter_price  = Convert.ToDecimal(Math.Round(item.SumPrice / item.EnterQty, 2));
                                entity.total_amount            = entity.total_amount + Math.Round(Convert.ToDecimal(item.SumPrice / (entity.discount_rate / 100)), 2) - inoutDetailEntity.retail_amount;
                                entity.total_retail            = entity.total_amount;
                                entity.actual_amount           = entity.actual_amount + Math.Round(Convert.ToDecimal(item.SumPrice / (entity.discount_rate / 100)), 2) - inoutDetailEntity.retail_amount;
                                inoutDetailBll.Update(inoutDetailEntity, tran);
                            }
                        }
                        #endregion
                    }
                    entity.accpect_time = DateTime.Now.ToString();
                    _TInoutbll.Update(entity, tran); //用事物更新订单表(T_Inout)
                    #endregion



                    #region 2.根据订单ID更新订单日志表中数据

                    string CreateName = "";
                    if (pRequest.ChannelId != "2")
                    {
                        var UserData = UserBLL.GetByID(this.CurrentUserInfo.CurrentUser.User_Id);
                        CreateName = string.Format("[操作人:{0}]", (UserData == null ? "" : UserData.user_name));
                    }
                    else
                    {
                        CreateName = "[操作人:客户]";
                    }



                    var _TInoutStatusEntity = new TInoutStatusEntity()
                    {
                        InoutStatusID = Guid.NewGuid(),
                        OrderID       = OrderID,                                                                     //订单ID
                        OrderStatus   = Convert.ToInt32(ActionCode),                                                 //状态码
                        //StatusRemark = "订单状态从" + Updatebeforestatus + "变为" + GetStatusDesc(ActionCode) + "[操作人:" + CurrentUserInfo.CurrentUser.User_Name + "]",               //状态更新描述
                        StatusRemark = "订单状态从" + Updatebeforestatus + "变为" + GetStatusDesc(ActionCode) + CreateName, //状态更新描述
                        CustomerID   = CurrentUserInfo.ClientID                                                      //客户ID
                    };
                    _TInoutStatusBLL.Create(_TInoutStatusEntity, tran);                                              //用事物更新,向日志表(TInoutStatus)中插入一条数据
                    #endregion

                    tran.Commit();

                    if (ActionCode == "600")
                    {
                        #region 处理订单发货发送微信模板消息
                        //获取会员信息
                        var vipBll       = new VipBLL(CurrentUserInfo);
                        var vipInfo      = vipBll.GetByID(entity.vip_no);
                        var inoutService = new Inout3Service(CurrentUserInfo);
                        //物流公司
                        string LogisticsName = inoutService.GetCompanyName(entity.carrier_id);

                        var InoutInfo = new InoutInfo()
                        {
                            order_no     = entity.order_no,
                            carrier_name = LogisticsName,
                            vipId        = entity.vip_no,
                            Field2       = entity.Field2
                        };

                        //  var CommonBLL = new CommonBLL();
                        //   CommonBLL.SentShipMessage(InoutInfo, vipInfo.WeiXinUserId, InoutInfo.vip_no, CurrentUserInfo);
                        new SendOrderSendMsgBLL().SentShipMessage(InoutInfo, vipInfo.WeiXinUserId, InoutInfo.vip_no, CurrentUserInfo);
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw new APIException(ex.Message)
                          {
                              ErrorCode = ERROR_ORDER_NOTEXISTS
                          };
                }
            }
            return(rd);
        }
Beispiel #20
0
        protected override GetMemberInfoRD ProcessRequest(DTO.Base.APIRequest <GetMemberInfoRP> pRequest)
        {
            GetMemberInfoRD rd = new GetMemberInfoRD();

            rd.MemberInfo = new MemberInfo();
            var vipLoginBLL = new VipBLL(base.CurrentUserInfo);

            //如果有一个查询标识非空,就用查询标识查,发现没有会员就报错
            if (!string.IsNullOrEmpty(pRequest.Parameters.SearchFlag))
            {
                List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                };
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "ClientID", Value = CurrentUserInfo.ClientID
                });
                var cond1 = new LikeCondition()
                {
                    FieldName = "VipName", Value = "%" + pRequest.Parameters.SearchFlag + "%"
                };
                var cond2 = new LikeCondition()
                {
                    FieldName = "VipRealName", Value = "%" + pRequest.Parameters.SearchFlag + "%"
                };
                var com1 = new ComplexCondition()
                {
                    Left = cond1, Right = cond2, Operator = LogicalOperators.Or
                };

                var cond3 = new EqualsCondition()
                {
                    FieldName = "Phone", Value = pRequest.Parameters.SearchFlag
                };
                var com2 = new ComplexCondition()
                {
                    Left = com1, Right = cond3, Operator = LogicalOperators.Or
                };
                complexCondition.Add(com2);
                complexCondition.Add(new DirectCondition("(WeiXinUserId!='' Or WeiXinUserId IS NOT NULL)"));
                var tempVipList = vipLoginBLL.Query(complexCondition.ToArray(), null);
                if (tempVipList != null && tempVipList.Length != 0)
                {
                    pRequest.UserID = pRequest.Parameters.MemberID = tempVipList[0].VIPID;
                }
            }

            string m_MemberID = "";

            if (!string.IsNullOrWhiteSpace(pRequest.Parameters.OwnerVipID))
            {
                m_MemberID = string.IsNullOrWhiteSpace(pRequest.Parameters.OwnerVipID) ? pRequest.UserID : pRequest.Parameters.OwnerVipID;
            }
            else
            {
                m_MemberID = string.IsNullOrWhiteSpace(pRequest.Parameters.MemberID) ? pRequest.UserID : pRequest.Parameters.MemberID;
            }

            string UserID       = m_MemberID;
            var    VipLoginInfo = vipLoginBLL.GetByID(UserID);

            if (VipLoginInfo == null)
            {
                throw new APIException("用户不存在")
                      {
                          ErrorCode = 330
                      }
            }
            ;
            #region 20140909 kun.zou 发现状态为0,改为1
            if (VipLoginInfo.Status.HasValue && VipLoginInfo.Status == 0)
            {
                VipLoginInfo.Status = 1;
                vipLoginBLL.Update(VipLoginInfo, false);
                var log = new VipLogEntity()
                {
                    Action       = "更新",
                    ActionRemark = "vip状态为0的改为1.",
                    CreateBy     = UserID,
                    CreateTime   = DateTime.Now,
                    VipID        = VipLoginInfo.VIPID,
                    LogID        = Guid.NewGuid().ToString("N")
                };
                var logBll = new VipLogBLL(base.CurrentUserInfo);
                logBll.Create(log);
            }
            #endregion
            int couponCount = vipLoginBLL.GetVipCoupon(UserID);

            rd.MemberInfo.Mobile      = VipLoginInfo.Phone;      //手机号码
            rd.MemberInfo.Name        = VipLoginInfo.UserName;   //姓名
            rd.MemberInfo.VipID       = VipLoginInfo.VIPID;      //组标识
            rd.MemberInfo.VipName     = VipLoginInfo.VipName;    //会员名
            rd.MemberInfo.ImageUrl    = VipLoginInfo.HeadImgUrl; //会员头像  add by Henry 2014-12-5
            rd.MemberInfo.VipRealName = VipLoginInfo.VipRealName;
            rd.MemberInfo.VipNo       = VipLoginInfo.VipCode;
            rd.MemberInfo.IsDealer    = VipLoginInfo.Col48 != null?int.Parse(VipLoginInfo.Col48) : 0;

            //超级分销体系配置表 为判断是否存在分销体系使用
            var T_SuperRetailTraderConfigbll = new T_SuperRetailTraderConfigBLL(CurrentUserInfo);
            //获取分销体系信息
            var T_SuperRetailTraderConfigInfo = T_SuperRetailTraderConfigbll.QueryByEntity(new T_SuperRetailTraderConfigEntity()
            {
                IsDelete = 0, CustomerId = CurrentUserInfo.CurrentUser.customer_id
            }, null).FirstOrDefault();
            if (T_SuperRetailTraderConfigInfo != null)
            {
                rd.MemberInfo.CanBeSuperRetailTrader = 1;
            }
            else
            {
                rd.MemberInfo.CanBeSuperRetailTrader = 0;
            }
            rd.MemberInfo.SuperRetailTraderID = VipLoginInfo.Col26;
            //rd.MemberInfo.Integration = VipLoginInfo.Integration ?? 0;//会员积分

            #region 会员有效积分
            var vipIntegralBLL  = new VipIntegralBLL(CurrentUserInfo);
            var vipIntegralInfo = vipIntegralBLL.QueryByEntity(new VipIntegralEntity()
            {
                VipID = UserID, VipCardCode = VipLoginInfo.VipCode
            }, null).FirstOrDefault();
            if (vipIntegralInfo != null)
            {
                rd.MemberInfo.Integration = vipIntegralInfo.ValidIntegral != null ? vipIntegralInfo.ValidIntegral.Value : 0;
            }
            #endregion

            //会员等级
            //rd.MemberInfo.VipLevelName = string.IsNullOrEmpty(vipLoginBLL.GetVipLeave(UserID)) ? null : vipLoginBLL.GetVipLeave(UserID);
            #region 会员卡名称
            var                vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo);
            var                vipCardBLL           = new VipCardBLL(CurrentUserInfo);
            var                vipCardTypeBLL       = new SysVipCardTypeBLL(CurrentUserInfo);
            var                vipCardRuleBLL       = new VipCardRuleBLL(CurrentUserInfo);
            var                vipT_InoutBLL        = new T_InoutBLL(CurrentUserInfo);
            VipAmountBLL       vipAmountBLL         = new VipAmountBLL(CurrentUserInfo);
            ShoppingCartBLL    service     = new ShoppingCartBLL(CurrentUserInfo);
            ShoppingCartEntity queryEntity = new ShoppingCartEntity();
            queryEntity.VipId = UserID;
            int totalQty = service.GetListQty(queryEntity);
            rd.MemberInfo.ShopCartCount = totalQty;
            //定义当前自定义等级
            int?CurVipLevel        = 0;
            var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = UserID, CustomerID = CurrentUserInfo.ClientID
            },
                                                                        new OrderBy[] { new OrderBy()
                                                                                        {
                                                                                            FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                                        } }).FirstOrDefault();
            if (vipCardMappingInfo != null)
            {
                var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardID = vipCardMappingInfo.VipCardID, VipCardStatusId = 1
                }, null).FirstOrDefault();
                if (vipCardInfo != null)
                {
                    var vipCardTypeInfo = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        VipCardTypeID = vipCardInfo.VipCardTypeID
                    }, null).FirstOrDefault();
                    if (vipCardTypeInfo != null)
                    {
                        rd.MemberInfo.VipLevelName     = vipCardTypeInfo.VipCardTypeName != null ? vipCardTypeInfo.VipCardTypeName : "";
                        rd.MemberInfo.CardTypeImageUrl = vipCardTypeInfo.PicUrl != null ? vipCardTypeInfo.PicUrl : "";
                        rd.MemberInfo.CardTypePrice    = vipCardTypeInfo.Prices != null ? vipCardTypeInfo.Prices.Value : 0;
                        rd.MemberInfo.IsExtraMoney     = vipCardTypeInfo.IsExtraMoney != null ? vipCardTypeInfo.IsExtraMoney : 0;
                        CurVipLevel             = vipCardTypeInfo.VipCardLevel;
                        rd.MemberInfo.IsPrepaid = vipCardTypeInfo.Isprepaid;
                        if (CurVipLevel > 1)
                        {
                            var VipCardTypeSysInfo = vipCardTypeBLL.GetBindVipCardTypeInfo(CurrentUserInfo.ClientID, VipLoginInfo.Phone, pRequest.UserID, CurVipLevel);
                            if (VipCardTypeSysInfo == null || VipCardTypeSysInfo.Tables[0].Rows.Count == 0)
                            {
                                rd.MemberInfo.IsNeedCard = 2;
                            }
                        }
                        else
                        {
                            rd.MemberInfo.IsNeedCard = 1;
                        }
                        //因为卡等级不能重复,知道当前等级后查找相应的下一级是否是自动升级(消费升级)
                        var NextVipCardTypeInfo = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                        {
                            VipCardLevel = CurVipLevel + 1, CustomerID = CurrentUserInfo.ClientID
                        }, null).FirstOrDefault();
                        if (NextVipCardTypeInfo != null)
                        {
                            //获取当前会员的消费金额信息
                            decimal CurVipConsumptionAmount = 0;
                            decimal VipConsumptionInfo      = vipT_InoutBLL.GetVipSumAmount(UserID);
                            if (VipConsumptionInfo > 0)
                            {
                                CurVipConsumptionAmount = Convert.ToDecimal(Convert.ToDecimal(VipConsumptionInfo).ToString("0.00"));
                            }
                            //知道下一等级后要判断,升级条件是否是消费升级
                            //定义累积消费金额
                            decimal AccumulatedAmount      = 0;
                            var     vipCardTypeUpGradeInfo = vipCardTypeBLL.GetVipCardTypeUpGradeInfo(CurrentUserInfo.ClientID, CurVipLevel);
                            if (vipCardTypeUpGradeInfo != null && vipCardTypeUpGradeInfo.Tables[0].Rows.Count > 0)
                            {
                                //判断拉取的所有卡等级里的最近的一级满足条件即可返回提示所需的值
                                int flag = 0;
                                foreach (DataRow dr in vipCardTypeUpGradeInfo.Tables[0].Rows)
                                {
                                    AccumulatedAmount = Convert.ToDecimal(Convert.ToDecimal(dr["BuyAmount"].ToString()).ToString("0.00"));
                                    //获取消费升级还需多少钱
                                    if (AccumulatedAmount > CurVipConsumptionAmount && flag == 0)
                                    {
                                        flag = 1;
                                        rd.MemberInfo.UpGradeNeedMoney = AccumulatedAmount - CurVipConsumptionAmount;
                                        if (rd.MemberInfo.UpGradeNeedMoney > 0)
                                        {
                                            rd.MemberInfo.UpgradePrompt = "还需要消费" + rd.MemberInfo.UpGradeNeedMoney + "元可以升级啦,快点通知会员!";
                                        }
                                    }
                                }
                            }
                        }

                        var VipCardRuleInfo = vipCardRuleBLL.QueryByEntity(new VipCardRuleEntity()
                        {
                            CustomerID = CurrentUserInfo.ClientID, VipCardTypeID = vipCardTypeInfo.VipCardTypeID
                        }, null).FirstOrDefault();
                        if (VipCardRuleInfo != null)
                        {
                            rd.MemberInfo.CardDiscount = Convert.ToDecimal(Convert.ToDecimal((VipCardRuleInfo.CardDiscount / 10)).ToString("0.00"));
                        }
                    }
                }
            }
            else
            {
                //表示需要领卡,并展示等级为1的默认卡
                rd.MemberInfo.IsNeedCard = 0;
                var VipCardTypeData = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                {
                    VipCardLevel = 1, CustomerID = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                if (VipCardTypeData != null)
                {
                    rd.MemberInfo.CardTypeImageUrl = VipCardTypeData.PicUrl != null ? VipCardTypeData.PicUrl : "";
                }
            }
            //获取红利/// decimal[0]=总收入(红利) decimal[2]=支出余额 decimal[1]=总提现金额
            decimal[] array = vipAmountBLL.GetVipSumAmountByCondition(UserID, CurrentUserInfo.ClientID, true);
            if (array[0] != null)
            {
                rd.MemberInfo.ProfitAmount = array[0];
            }
            //是否有付费的会员卡
            List <IWhereCondition> freeCardCon = new List <IWhereCondition> {
            };
            freeCardCon.Add(new EqualsCondition()
            {
                FieldName = "CustomerID", Value = CurrentUserInfo.ClientID
            });
            freeCardCon.Add(new DirectCondition("Prices>0"));
            var freeCardTypeInfo = vipCardTypeBLL.Query(freeCardCon.ToArray(), null).FirstOrDefault();
            if (freeCardTypeInfo != null)
            {
                rd.MemberInfo.IsCostCardType = 1;
            }
            else
            {
                rd.MemberInfo.IsCostCardType = 0;
            }

            #endregion

            rd.MemberInfo.Status       = VipLoginInfo.Status.HasValue ? VipLoginInfo.Status.Value : 1;
            rd.MemberInfo.CouponsCount = couponCount;
            rd.MemberInfo.IsActivate   = (VipLoginInfo.IsActivate.HasValue && VipLoginInfo.IsActivate.Value == 1 ? true : false);
            var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo);
            rd.MemberInfo.MemberBenefits = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID);



            //获取标签信息
            TagsBLL TagsBLL = new TagsBLL(base.CurrentUserInfo);


            var dsIdentity = TagsBLL.GetVipTagsList("", UserID);//“车主标签”  传7
            if (dsIdentity != null && dsIdentity.Tables.Count > 0 && dsIdentity.Tables[0].Rows.Count > 0)
            {
                rd.IdentityTagsList = DataTableToObject.ConvertToList <TagsInfo>(dsIdentity.Tables[0]).ToArray(); //“年龄段”  传8
            }


            #region 获取注册表单的列明和值

            var vipEntity = vipLoginBLL.QueryByEntity(new VipEntity()
            {
                VIPID = UserID
            }, null);

            if (vipEntity == null || vipEntity.Length == 0)
            {
                return(rd);
            }
            else
            {
                var ds = vipLoginBLL.GetVipColumnInfo(CurrentUserInfo.ClientID, "online005");

                var vipDs = vipLoginBLL.GetVipInfo(UserID);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    var temp = ds.Tables[0].AsEnumerable().Select(t => new MemberControlInfo()
                    {
                        ColumnName  = t["ColumnName"].ToString(),
                        ControlType = Convert.ToInt32(t["ControlType"]),
                        ColumnValue = vipDs.Tables[0].Rows[0][t["ColumnName"].ToString()].ToString(),
                        ColumnDesc  = t["columnDesc"].ToString()
                    });

                    rd.MemberControlList = temp.ToArray();
                }
            }

            //var vipamountBll = new VipAmountBLL(this.CurrentUserInfo);

            //var vipAmountEntity = vipamountBll.GetByID(UserID);


            var unitBll = new UnitBLL(this.CurrentUserInfo);
            //Hashtable htPara = new Hashtable();
            //htPara["MemberID"] = UserID;
            //htPara["CustomerID"] = CurrentUserInfo.ClientID;
            //htPara["PageIndex"] = 1;
            //htPara["PageSize"] = 10;
            //DataSet dsMyAccount = unitBll.GetMyAccount(htPara);

            //if (dsMyAccount.Tables[0].Rows.Count > 0)
            //{
            //    //rd.AccountList = DataTableToObject.ConvertToList<AccountInfo>(dsMyAccount.Tables[0]);
            //    //rd.MemberInfo.Balance = Convert.ToDecimal(dsMyAccount.Tables[0].Rows[0]["Total"].ToString());
            //    //rd.TotalPageCount = int.Parse(dsMyAccount.Tables[0].Rows[0]["PageCount"].ToString());

            //}
            //else
            //    rd.MemberInfo.Balance = 0;

            //返现 add by Henry 2015-4-15
            var vipAmountBll = new VipAmountBLL(CurrentUserInfo);
            //var vipAmountInfo = vipAmountBll.GetByID(UserID);
            var vipAmountInfo = vipAmountBll.QueryByEntity(new VipAmountEntity()
            {
                VipId = UserID, VipCardCode = VipLoginInfo.VipCode
            }, null).FirstOrDefault();
            decimal returnAmount = 0;
            decimal amount       = 0;
            if (vipAmountInfo != null)
            {
                returnAmount = vipAmountInfo.ValidReturnAmount == null ? 0 : vipAmountInfo.ValidReturnAmount.Value;
                amount       = vipAmountInfo.EndAmount == null ? 0 : vipAmountInfo.EndAmount.Value;
            }
            rd.MemberInfo.ReturnAmount = returnAmount; //返现
            rd.MemberInfo.Balance      = amount;       //余额
            #endregion


            //获取订单的日期和订单的里的商品名称、商品单价、商品数量
            //先获取订单列表,再获取订单详细信息
            int?         pageSize     = 3; //rp.Parameters.PageSize;,只取三条记录
            int?         pageIndex    = 1; //rp.Parameters.PageIndex;
            string       OrderBy      = "";
            string       OrderType    = "";
            T_InoutBLL   T_InoutBLL   = new T_InoutBLL(CurrentUserInfo);
            InoutService InoutService = new InoutService(CurrentUserInfo);
            //只取状态为700的
            //根据订单列表取订单详情
            DataSet dsOrder = T_InoutBLL.GetOrdersByVipID(rd.MemberInfo.VipID, pageIndex ?? 1, pageSize ?? 15, OrderBy, OrderType);//获取会员信息
            if (dsOrder != null && dsOrder.Tables.Count != 0 && dsOrder.Tables[0].Rows.Count != 0)
            {
                List <JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo> orderList = DataTableToObject.ConvertToList <JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo>(dsOrder.Tables[1]);
                foreach (JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo oi in orderList)
                {
                    IList <InoutDetailInfo> detailList = InoutService.GetInoutDetailInfoByOrderId(oi.order_id);
                    oi.DetailList = detailList;
                }
                rd.OrderList = orderList;
            }

            MessageInfo message = new MessageInfo();


            InnerGroupNewsBLL InnerGroupNewsService = new InnerGroupNewsBLL(CurrentUserInfo);
            SetoffToolsBLL    setofftoolsService    = new SetoffToolsBLL(CurrentUserInfo);

            //1=微信用户 2=APP员工
            int UnReadInnerMessageCount = InnerGroupNewsService.GetVipInnerGroupNewsUnReadCount(CurrentUserInfo.UserID, pRequest.CustomerID, 1, null, Convert.ToDateTime(VipLoginInfo.CreateTime));
            var setofftoolsMessageCount = setofftoolsService.GetUnReadSetoffToolsCount(CurrentUserInfo.UserID, pRequest.CustomerID, 1, 1);
            message.InnerGroupNewsCount = UnReadInnerMessageCount;
            message.SetoffToolsCount    = setofftoolsMessageCount;
            var VipUpNewsInfo = InnerGroupNewsService.GetVipInnerNewsInfo(CurrentUserInfo.ClientID, 2, 1, 3, 0);
            if (VipUpNewsInfo != null && VipUpNewsInfo.Tables[0].Rows.Count > 0)
            {
                message.UpGradeSucess = VipUpNewsInfo.Tables[0].Rows[0]["Text"] != null ? VipUpNewsInfo.Tables[0].Rows[0]["Text"].ToString() : "";
                //获取通知信息 并更新已读状态 数据如果不是一条进行更新所有数据
                var newsUserMappingBLL = new NewsUserMappingBLL(CurrentUserInfo);
                if (VipUpNewsInfo.Tables[0].Rows.Count > 1)//数据如果不是一条进行更新所有数据
                {
                    foreach (DataRow VipNewsdr in VipUpNewsInfo.Tables[0].Rows)
                    {
                        var vipNewsInfo = newsUserMappingBLL.QueryByEntity(new NewsUserMappingEntity()
                        {
                            CustomerId = CurrentUserInfo.ClientID, MappingID = VipNewsdr["MappingID"].ToString()
                        }, null).FirstOrDefault();
                        if (vipNewsInfo != null)
                        {
                            vipNewsInfo.HasRead = 1;
                            newsUserMappingBLL.Update(vipNewsInfo);
                        }
                    }
                }
                else
                {
                    var vipNewsInfo = newsUserMappingBLL.QueryByEntity(new NewsUserMappingEntity()
                    {
                        CustomerId = CurrentUserInfo.ClientID, MappingID = VipUpNewsInfo.Tables[0].Rows[0]["MappingID"].ToString()
                    }, null).FirstOrDefault();
                    if (vipNewsInfo != null)
                    {
                        vipNewsInfo.HasRead = 1;
                        newsUserMappingBLL.Update(vipNewsInfo);
                    }
                }
            }
            else
            {
                message.UpGradeSucess = "";
            }
            rd.MessageInfo = message;
            return(rd);
        }
    }
        /// <summary>
        /// 计算超级分销商佣金,分润用到的批处理
        /// </summary>
        public void CalculateSuperRetailTraderOrderJob()
        {
            var numCount = 50;

            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                string connString = customer.Value;
                var    count      = RedisOpenAPI.Instance.CCSuperRetailTraderOrder().GetSuperRetailTraderOrderLength(new CC_Order
                {
                    CustomerID = customer.Key
                });
                if (count.Code != ResponseCode.Success)
                {
                    BaseService.WriteLog("从redis获取待绑定优惠券数量失败");
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }

                DataTable dtProfitDetail = CreateTableProfitDetail();
                DataTable dtAmountDetail = CreateTableAmountDetail();
                DataTable dtAmount       = CreateTableAmount();

                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCSuperRetailTraderOrder().GetSuperRetailTraderOrder(new CC_Order
                    {
                        CustomerID = customer.Key
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var orderInfo = response.Result.OrderInfo.JsonDeserialize <T_InoutEntity>();
                        //var loggingSessionInfo = response.Result.LogSession.JsonDeserialize<LoggingSessionInfo>();
                        var        loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "1");
                        T_InoutBLL inoutBLL           = new T_InoutBLL(loggingSessionInfo);
                        //inoutBLL.CalculateSuperRetailTraderOrder(loggingSessionInfo, orderInfo);
                        if (orderInfo != null)
                        {
                            if (orderInfo.data_from_id == "35" || orderInfo.data_from_id == "36")
                            {
                                T_SuperRetailTraderBLL bllSuperRetailTrader = new T_SuperRetailTraderBLL(loggingSessionInfo);
                                DataSet dsAllFather = bllSuperRetailTrader.GetAllFather(orderInfo.sales_user);
                                if (dsAllFather != null && dsAllFather.Tables.Count > 0 && dsAllFather.Tables[0].Rows.Count > 0)
                                {
                                    T_SuperRetailTraderProfitConfigBLL bllSuperRetailTraderProfitConfig = new T_SuperRetailTraderProfitConfigBLL(loggingSessionInfo);
                                    T_SuperRetailTraderConfigBLL       bllSuperRetailTraderConfig       = new T_SuperRetailTraderConfigBLL(loggingSessionInfo);
                                    T_SuperRetailTraderProfitDetailBLL bllSuperRetailTraderProfitDetail = new T_SuperRetailTraderProfitDetailBLL(loggingSessionInfo);

                                    VipAmountBLL       bllVipAmount       = new VipAmountBLL(loggingSessionInfo);
                                    VipAmountDetailBLL bllVipAmountDetail = new VipAmountDetailBLL(loggingSessionInfo);

                                    var entitySuperRetailTraderProfitConfig = bllSuperRetailTraderProfitConfig.QueryByEntity(new T_SuperRetailTraderProfitConfigEntity()
                                    {
                                        CustomerId = loggingSessionInfo.ClientID, IsDelete = 0, Status = "10"
                                    }, null);
                                    var entityConfig = bllSuperRetailTraderConfig.QueryByEntity(new T_SuperRetailTraderConfigEntity()
                                    {
                                        CustomerId = loggingSessionInfo.ClientID, IsDelete = 0
                                    }, null).SingleOrDefault();
                                    if (entityConfig != null && entitySuperRetailTraderProfitConfig != null)
                                    {
                                        //佣金比列
                                        decimal SkuCommission = Convert.ToDecimal(entityConfig.SkuCommission) * Convert.ToDecimal(0.01);
                                        //商品分润比列
                                        decimal DistributionProfit = Convert.ToDecimal(entityConfig.DistributionProfit) * Convert.ToDecimal(0.01);


                                        foreach (DataRow dr in dsAllFather.Tables[0].Rows)
                                        {
                                            decimal amount            = 0;
                                            string  strAmountSourceId = string.Empty;
                                            T_SuperRetailTraderProfitConfigEntity singlProfitConfig = new T_SuperRetailTraderProfitConfigEntity();
                                            if (dr["level"].ToString() == "1")      //佣金
                                            {
                                                strAmountSourceId = "34";
                                                singlProfitConfig = entitySuperRetailTraderProfitConfig.Where(a => a.Level == Convert.ToInt16(dr["level"].ToString())).SingleOrDefault();
                                                if (singlProfitConfig != null)
                                                {
                                                    if (singlProfitConfig.ProfitType == "Percent")
                                                    {
                                                        amount = Convert.ToDecimal(orderInfo.actual_amount) * SkuCommission;
                                                    }
                                                }
                                            }
                                            else      //分润
                                            {
                                                strAmountSourceId = "33";
                                                singlProfitConfig = entitySuperRetailTraderProfitConfig.Where(a => a.Level == Convert.ToInt16(dr["level"].ToString())).SingleOrDefault();
                                                if (singlProfitConfig != null)
                                                {
                                                    if (singlProfitConfig.ProfitType == "Percent")
                                                    {
                                                        //amount = Convert.ToDecimal(orderInfo.actual_amount) * DistributionProfit * Convert.ToDecimal(singlProfitConfig.Profit) * Convert.ToDecimal(0.01);
                                                        amount = Convert.ToDecimal(orderInfo.actual_amount) * Convert.ToDecimal(singlProfitConfig.Profit) * Convert.ToDecimal(0.01);
                                                    }
                                                }
                                            }
                                            var vipAmountDetail = bllVipAmountDetail.QueryByEntity(new VipAmountDetailEntity()
                                            {
                                                ObjectId = orderInfo.order_id, AmountSourceId = strAmountSourceId
                                            }, null);
                                            if (vipAmountDetail != null && vipAmountDetail.Length > 0)
                                            {
                                                continue;
                                            }
                                            if (amount > 0)
                                            {
                                                IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();
                                                try
                                                {
                                                    T_SuperRetailTraderProfitDetailEntity entitySuperRetailTraderProfitDetail = new T_SuperRetailTraderProfitDetailEntity()
                                                    {
                                                        SuperRetailTraderProfitConfigId = singlProfitConfig.SuperRetailTraderProfitConfigId,
                                                        SuperRetailTraderID             = new Guid(dr["SuperRetailTraderID"].ToString()),
                                                        Level             = Convert.ToInt16(dr["level"].ToString()),
                                                        ProfitType        = "Cash",
                                                        Profit            = amount,
                                                        OrderType         = "Order",
                                                        OrderId           = orderInfo.order_id,
                                                        OrderDate         = Convert.ToDateTime(orderInfo.order_date),
                                                        VipId             = orderInfo.vip_no,
                                                        OrderActualAmount = orderInfo.actual_amount,
                                                        SalesId           = new Guid(orderInfo.sales_user),
                                                        OrderNo           = orderInfo.order_no,
                                                        CustomerId        = loggingSessionInfo.ClientID
                                                    };
                                                    bllSuperRetailTraderProfitDetail.Create(entitySuperRetailTraderProfitDetail, (SqlTransaction)tran);

                                                    VipAmountEntity       entityVipAmount       = new VipAmountEntity();
                                                    VipAmountDetailEntity entityVipAmountDetail = new VipAmountDetailEntity();
                                                    entityVipAmountDetail = new VipAmountDetailEntity {
                                                        VipAmountDetailId = Guid.NewGuid(),
                                                        VipId             = dr["SuperRetailTraderID"].ToString(),
                                                        Amount            = amount,
                                                        UsedReturnAmount  = 0,
                                                        EffectiveDate     = DateTime.Now,
                                                        DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                                        AmountSourceId    = strAmountSourceId,
                                                        ObjectId          = orderInfo.order_id,
                                                        CustomerID        = loggingSessionInfo.ClientID,
                                                        Reason            = "超级分销商",
                                                        IsWithdrawCash    = 0
                                                    };
                                                    bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);
                                                    //DataRow dr_ProfitDetail = dtProfitDetail.NewRow();
                                                    //dr_ProfitDetail["Id"] = Guid.NewGuid();
                                                    //dr_ProfitDetail["SuperRetailTraderProfitConfigId"] = new Guid(singlProfitConfig.SuperRetailTraderProfitConfigId.ToString());
                                                    //dr_ProfitDetail["SuperRetailTraderID"] = new Guid(dr["SuperRetailTraderID"].ToString());
                                                    //dr_ProfitDetail["Level"] = Convert.ToInt16(dr["level"].ToString());
                                                    //dr_ProfitDetail["ProfitType"] = "Cash";
                                                    //dr_ProfitDetail["Profit"] = amount;
                                                    //dr_ProfitDetail["OrderType"] = "Order";
                                                    //dr_ProfitDetail["OrderId"] = orderInfo.order_id;
                                                    //dr_ProfitDetail["OrderNo"] = orderInfo.order_no;
                                                    //dr_ProfitDetail["OrderDate"] = Convert.ToDateTime(orderInfo.order_date);
                                                    //dr_ProfitDetail["OrderActualAmount"] = orderInfo.actual_amount;
                                                    //dr_ProfitDetail["SalesId"] = new Guid(orderInfo.sales_user);
                                                    //dr_ProfitDetail["VipId"] = orderInfo.vip_no;
                                                    //dr_ProfitDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_ProfitDetail["CreateTime"] = DateTime.Now;
                                                    //dr_ProfitDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_ProfitDetail["LastUpdateTime"] = DateTime.Now;
                                                    //dr_ProfitDetail["CustomerId"] = loggingSessionInfo.ClientID;
                                                    //dr_ProfitDetail["IsDelete"] = 0;

                                                    //dtProfitDetail.Rows.Add(dr_ProfitDetail);

                                                    //DataRow dr_AmountDetail = dtAmountDetail.NewRow();
                                                    //dr_AmountDetail["VipAmountDetailId"] = Guid.NewGuid();
                                                    //dr_AmountDetail["VipId"] = dr["SuperRetailTraderID"].ToString();
                                                    //dr_AmountDetail["VipCardCode"] = "";
                                                    //dr_AmountDetail["UnitID"] = "";
                                                    //dr_AmountDetail["UnitName"] = "";
                                                    //dr_AmountDetail["SalesAmount"] = 0;
                                                    //dr_AmountDetail["Amount"] = amount;
                                                    //dr_AmountDetail["UsedReturnAmount"] = 0;
                                                    //dr_AmountDetail["Reason"] = "超级分销商";
                                                    //dr_AmountDetail["EffectiveDate"] = DateTime.Now;
                                                    //dr_AmountDetail["DeadlineDate"] = Convert.ToDateTime("9999-12-31 23:59:59");
                                                    //dr_AmountDetail["AmountSourceId"] = strAmountSourceId;
                                                    //dr_AmountDetail["ObjectId"] = orderInfo.order_id;
                                                    //dr_AmountDetail["Remark"] = "超级分销商";
                                                    //dr_AmountDetail["IsValid"] = 0;
                                                    //dr_AmountDetail["IsWithdrawCash"] = 0;
                                                    //dr_AmountDetail["CustomerID"] = loggingSessionInfo.ClientID;
                                                    //dr_AmountDetail["CreateTime"] = DateTime.Now;
                                                    //dr_AmountDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_AmountDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_AmountDetail["LastUpdateTime"] = DateTime.Now;
                                                    //dr_AmountDetail["IsDelete"] = 0;
                                                    ////dr_AmountDetail["IsCalculated"] = 1;

                                                    //dtAmountDetail.Rows.Add(dr_AmountDetail);

                                                    entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                                                    {
                                                        VipId = dr["SuperRetailTraderID"].ToString(), IsDelete = 0
                                                    }, null).SingleOrDefault();
                                                    if (entityVipAmount == null)
                                                    {
                                                        entityVipAmount = new VipAmountEntity {
                                                            VipId                  = dr["SuperRetailTraderID"].ToString(),
                                                            BeginAmount            = 0,
                                                            InAmount               = amount,
                                                            OutAmount              = 0,
                                                            EndAmount              = amount,
                                                            TotalAmount            = amount,
                                                            BeginReturnAmount      = 0,
                                                            InReturnAmount         = 0,
                                                            OutReturnAmount        = 0,
                                                            ReturnAmount           = 0,
                                                            ImminentInvalidRAmount = 0,
                                                            InvalidReturnAmount    = 0,
                                                            ValidReturnAmount      = 0,
                                                            TotalReturnAmount      = 0,
                                                            IsLocking              = 0,
                                                            CustomerID             = loggingSessionInfo.ClientID,
                                                            VipCardCode            = ""
                                                        };
                                                        bllVipAmount.Create(entityVipAmount, tran);
                                                        //DataRow dr_Amount = dtAmount.NewRow();
                                                        //dr_Amount["VipId"] = dr["SuperRetailTraderID"].ToString();
                                                        //dr_Amount["VipCardCode"] = "";
                                                        //dr_Amount["BeginAmount"] = 0;
                                                        //dr_Amount["InAmount"] = amount;
                                                        //dr_Amount["OutAmount"] = 0;
                                                        //dr_Amount["EndAmount"] = amount;
                                                        //dr_Amount["TotalAmount"] = amount;
                                                        //dr_Amount["BeginReturnAmount"] = 0;
                                                        //dr_Amount["InReturnAmount"] = 0;
                                                        //dr_Amount["OutReturnAmount"] = 0;
                                                        //dr_Amount["ReturnAmount"] = 0;
                                                        //dr_Amount["ImminentInvalidRAmount"] = 0;
                                                        //dr_Amount["InvalidReturnAmount"] = 0;
                                                        //dr_Amount["ValidReturnAmount"] = 0;
                                                        //dr_Amount["TotalReturnAmount"] = 0;
                                                        //dr_Amount["PayPassword"] = "";
                                                        //dr_Amount["IsLocking"] = 0;
                                                        //dr_Amount["CustomerID"] = loggingSessionInfo.ClientID;
                                                        //dr_Amount["CreateTime"] = DateTime.Now;
                                                        //dr_Amount["CreateBy"] = loggingSessionInfo.ClientID;
                                                        //dr_Amount["LastUpdateBy"] =loggingSessionInfo.ClientID;
                                                        //dr_Amount["LastUpdateTime"] = DateTime.Now;
                                                        //dr_Amount["IsDelete"] = 0;
                                                        //dtAmount.Rows.Add(dr_Amount);
                                                    }
                                                    else
                                                    {
                                                        entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                                                        entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                                                        entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                                                        entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;

                                                        bllVipAmount.Update(entityVipAmount);
                                                    }
                                                    tran.Commit();
                                                }
                                                catch (Exception)
                                                {
                                                    tran.Rollback();
                                                    throw;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //if (dtAmount.Rows.Count > 0)
                //{
                //    Utils.SqlBulkCopy(connString, dtAmount, "VipAmount");
                //}
                //if (dtAmountDetail.Rows.Count>0 && dtProfitDetail.Rows.Count>0)
                //{
                //    Utils.SqlBulkCopy(connString, dtProfitDetail, "T_SuperRetailTraderProfitDetail");
                //    Utils.SqlBulkCopy(connString, dtAmountDetail, "VipAmountDetail");

                //}
            }
        }
Beispiel #22
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var OrderID     = context.Request["OrderID"];
            var OrderStatus = context.Request["OrderStatus"];
            var CustomerID  = context.Request["CustomerID"];
            var UserID      = context.Request["UserID"];
            var ChannelID   = context.Request["ChannelID"];
            var SerialPay   = context.Request["SerialPay"];

            try
            {
                if (string.IsNullOrEmpty(OrderID) || string.IsNullOrEmpty(OrderStatus) || string.IsNullOrEmpty(CustomerID) || string.IsNullOrEmpty(UserID) || string.IsNullOrEmpty(ChannelID))
                {
                    throw new Exception("参数不全:OrderID,OrderStatus,CustomerID,UserID");
                }
                else
                {
                    if (OrderStatus == "2")
                    {
                        //支付成功,更新卡的支付状态
                        //OrderID就是VIPCardID
                        //
                        //var rp = pRequest.DeserializeJSONTo<APIRequest<SetVipCardRP>>();

                        //if (string.IsNullOrEmpty(rp.Parameters.PayID))
                        //{
                        //    throw new APIException("缺少参数【PayID】或参数值为空") { ErrorCode = 135 };
                        //}
                        var loggingSessionInfo = Default.GetBSLoggingSession(CustomerID, UserID);
                        //会员
                        var vipBll               = new VipBLL(loggingSessionInfo);
                        var vipAmountBll         = new VipAmountBLL(loggingSessionInfo);
                        var vipCardVipMappingBll = new VipCardVipMappingBLL(loggingSessionInfo);
                        //支付
                        var tPaymentTypeCustomerMappingBll = new TPaymentTypeCustomerMappingBLL(loggingSessionInfo);
                        var tPaymentTypeBll  = new T_Payment_TypeBLL(loggingSessionInfo);
                        var paymentDetailBll = new T_Payment_detailBLL(loggingSessionInfo);
                        //门店
                        var unitBLL = new t_unitBLL(loggingSessionInfo);
                        //商品订单支付
                        //更新积分和状态
                        //var loggingSessionInfo = Default.GetBSLoggingSession(CustomerID, "1");
                        var inoutBll = new T_InoutBLL(loggingSessionInfo);//订单业务对象实例化

                        var trrBll = new T_RewardRecordBLL(loggingSessionInfo);
                        //辨别打赏订单
                        var rewardOrderPrefix = "REWARD|";
                        if (OrderID.Contains(rewardOrderPrefix))
                        {
                            OrderID = OrderID.Substring(rewardOrderPrefix.Length, OrderID.Length - rewardOrderPrefix.Length);
                            var trrEntity = trrBll.GetByID(OrderID);
                            trrEntity.PayStatus      = 2;
                            trrEntity.LastUpdateTime = DateTime.Now;
                            trrEntity.LastUpdateBy   = loggingSessionInfo.UserID;
                            trrBll.Update(trrEntity);

                            #region 员工余额变更--需要独立出来处理
                            var userAmountBll = new VipAmountBLL(loggingSessionInfo);                                 //作为员工余额使用
                            var employeeId    = trrEntity.RewardedOP;
                            var rewardAmount  = trrEntity.RewardAmount == null ? 0 : (decimal)trrEntity.RewardAmount; //转为非null的decimal类型
                            //门店
                            var unitService = new UnitService(loggingSessionInfo);
                            var unitInfo    = unitService.GetUnitByUser(CustomerID, employeeId).FirstOrDefault();//获取员工所属门店

                            var tran = userAmountBll.GetTran();
                            using (tran.Connection)//事务
                            {
                                try
                                {
                                    var userAmountEntity = userAmountBll.GetByID(trrEntity.RewardedOP);
                                    if (userAmountEntity == null)
                                    {
                                        //创建
                                        userAmountEntity = new VipAmountEntity
                                        {
                                            VipId                  = employeeId,//员工ID
                                            VipCardCode            = string.Empty,
                                            BeginAmount            = 0,
                                            InAmount               = rewardAmount,
                                            OutAmount              = 0,
                                            EndAmount              = rewardAmount,
                                            TotalAmount            = rewardAmount,
                                            BeginReturnAmount      = 0,
                                            InReturnAmount         = 0,
                                            OutReturnAmount        = 0,
                                            ReturnAmount           = 0,
                                            ImminentInvalidRAmount = 0,
                                            InvalidReturnAmount    = 0,
                                            ValidReturnAmount      = 0,
                                            TotalReturnAmount      = 0,
                                            IsLocking              = 0,
                                            CustomerID             = CustomerID
                                        };
                                        userAmountBll.Create(userAmountEntity, tran);//创建员工余额表
                                    }
                                    else
                                    {
                                        //修改
                                        if (rewardAmount > 0)
                                        {
                                            userAmountEntity.InAmount    = (userAmountEntity.InAmount == null ? 0 : userAmountEntity.InAmount.Value) + rewardAmount;
                                            userAmountEntity.TotalAmount = (userAmountEntity.TotalAmount == null ? 0 : userAmountEntity.TotalAmount.Value) + rewardAmount;
                                        }
                                        else
                                        {
                                            userAmountEntity.OutAmount = (userAmountEntity.OutAmount == null ? 0 : userAmountEntity.OutAmount.Value) + Math.Abs(rewardAmount);
                                        }
                                        userAmountEntity.EndAmount = (userAmountEntity.EndAmount == null ? 0 : userAmountEntity.EndAmount.Value) + rewardAmount;

                                        userAmountBll.Update(userAmountEntity, tran);//更新余额
                                    }

                                    var vipamountDetailBll    = new VipAmountDetailBLL(loggingSessionInfo);
                                    var vipAmountDetailEntity = new VipAmountDetailEntity
                                    {
                                        VipAmountDetailId = Guid.NewGuid(),
                                        VipCardCode       = string.Empty,
                                        VipId             = employeeId,//员工ID
                                        UnitID            = unitInfo != null ? unitInfo.unit_id : string.Empty,
                                        UnitName          = unitInfo != null ? unitInfo.Name : string.Empty,
                                        Amount            = rewardAmount,
                                        UsedReturnAmount  = 0,
                                        EffectiveDate     = DateTime.Now,
                                        DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                        AmountSourceId    = "26",
                                        Reason            = "Reward",
                                        CustomerID        = CustomerID
                                    };
                                    vipamountDetailBll.Create(vipAmountDetailEntity, tran); //创建余额详情

                                    tran.Commit();                                          //提交事务
                                }
                                catch (Exception ex)
                                {
                                    tran.Rollback();
                                    Loggers.Debug(new DebugLogInfo()
                                    {
                                        Message = "异常-->支付成功回调时更新会员打赏金额出错(PayNotify.ashx):" + ex
                                    });
                                }
                            }
                            #endregion

                            if (trrEntity != null)
                            {
                                context.Response.Write("SUCCESS");
                            }
                            else
                            {
                                context.Response.Write("FAIL");
                            }
                            return;
                        }
                        //获取会员信息
                        var vipInfo = vipBll.GetByID(loggingSessionInfo.UserID);
                        //支付信息 Bear
                        //var tPaymentTypeCustomerMappingEntity = tPaymentTypeCustomerMappingBll.QueryByEntity(new TPaymentTypeCustomerMappingEntity(){ChannelId = ChannelID,CustomerId = loggingSessionInfo.ClientID },null).FirstOrDefault();
                        var paymentTypeList = tPaymentTypeBll.GetAll();
                        var tPaymentType    =
                            paymentTypeList.ToList()
                            .Find(t => t.Payment_Type_Code == "WXJS");

                        //var tPaymentType = tPaymentTypeBll.GetByID(tPaymentTypeCustomerMappingEntity.PaymentTypeID);
                        //获取订单信息
                        var inoutInfo = inoutBll.GetByID(OrderID);
                        if (inoutInfo != null)
                        {
                            var    bll = new TInOutStatusNodeBLL(loggingSessionInfo);
                            string msg;
                            if (!bll.SetOrderPayment(OrderID, out msg, ChannelID, SerialPay))
                            //if (!bll.SetOrderPayment(OrderID, out msg, ChannelID))
                            {
                                throw new Exception(msg);
                            }
                            else if (string.IsNullOrEmpty(inoutInfo.Field17) && string.IsNullOrEmpty(inoutInfo.Field18))
                            {
                                #region 发送订单支付成功微信模板消息
                                var SuccessCommonBLL = new CommonBLL();
                                //SuccessCommonBLL.SentPaymentMessage(inoutInfo, vipInfo.WeiXinUserId,vipInfo.VIPID, loggingSessionInfo);
                                new SendOrderPaySuccessMsgBLL().SentPaymentMessage(inoutInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                #endregion
                                Loggers.Debug(new DebugLogInfo()
                                {
                                    Message = "调用SetOrderPayment方法更新订单成功"
                                });
                            }
                            //获取订单信息,根据Field3==1判断,如果是ALD订单,则调用ALD接口更新ALD订单的状态
                            #region 更新ALD状态
                            //var orderbll = new InoutService(loggingSessionInfo);
                            //var orderInfo = orderbll.GetInoutInfoById(OrderID);
                            //if (orderInfo.Field3 == "1")
                            //{
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("更新O2OMarketing订单状态成功[OrderID={0}].", OrderID) });
                            //    //更新阿拉丁的订单状态
                            //    JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDChangeOrderStatus aldChangeOrder = new data.DataOnlineShoppingHandler.ALDChangeOrderStatus();
                            //    if (string.IsNullOrEmpty(orderInfo.vip_no))
                            //        throw new Exception("会员ID不能为空,OrderID:" + OrderID);
                            //    aldChangeOrder.MemberID = new Guid(orderInfo.vip_no);
                            //    aldChangeOrder.SourceOrdersID = OrderID;
                            //    aldChangeOrder.Status = int.Parse(orderInfo.status);
                            //    aldChangeOrder.IsPaid = true;
                            //    JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDChangeOrderStatusRequest aldRequest = new data.DataOnlineShoppingHandler.ALDChangeOrderStatusRequest();
                            //    aldRequest.BusinessZoneID = 1;//写死
                            //    aldRequest.Locale = 1;

                            //    aldRequest.UserID = new Guid(orderInfo.vip_no);
                            //    aldRequest.Parameters = aldChangeOrder;
                            //    var url = ConfigurationManager.AppSettings["ALDGatewayURL"];
                            //    var postContent = string.Format("Action=ChangeOrderStatus&ReqContent={0}", aldRequest.ToJSON());
                            //    Loggers.Debug(new DebugLogInfo() { Message = "通知ALD更改状态:" + postContent });
                            //    var strAldRsp = HttpWebClient.DoHttpRequest(url, postContent);
                            //    var aldRsp = strAldRsp.DeserializeJSONTo<JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDResponse>();
                            //    if (!aldRsp.IsSuccess())
                            //    {
                            //        Loggers.Debug(new DebugLogInfo() { Message = string.Format("更新阿拉丁订单状态失败[Request ={0}][Response={1}]", aldRequest.ToJSON(), strAldRsp) });
                            //    }
                            //}
                            #endregion

                            #region 格力推送通知
                            //try
                            //{
                            //    GLServiceOrderBLL glsobll = new GLServiceOrderBLL(loggingSessionInfo);
                            //    if (glsobll.ValidateGree(CustomerID, "cpos_bs_lj"))//先写死
                            //        glsobll.GreePushPaymentOorder(CustomerID, OrderID, loggingSessionInfo);
                            //}
                            //catch (Exception ex)
                            //{
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("付款推送评价师傅链接失败[OrderID={0}].", OrderID) });
                            //}
                            #endregion

                            #region ALD生活服务处理
                            //var rechargeBll = new RechargeStrategyBLL(loggingSessionInfo);
                            //var vipAmountBll = new VipAmountBLL(loggingSessionInfo);
                            //var couponBll = new CouponBLL(loggingSessionInfo);
                            //var vipCouponMappingBll = new VipCouponMappingBLL(loggingSessionInfo);
                            //var unitBll = new UnitBLL(loggingSessionInfo);
                            //DataSet dsOrderInfo = rechargeBll.GetInoutOrderItems(OrderID);
                            //int itemSort = 0;            //商品业务分类
                            //string skuId = string.Empty; //商品SkuId
                            //string vipId = string.Empty; //会员ID
                            //string itemId = string.Empty;//商品ID
                            //string couponId = string.Empty;//优惠券ID
                            //if (dsOrderInfo.Tables[0].Rows.Count > 0)
                            //{
                            //    //if (dsOrderInfo.Tables[0].Rows[0]["ItemSort"] != DBNull.Value && Convert.ToString(dsOrderInfo.Tables[0].Rows[0]["ItemSort"]) != "0")
                            //    itemSort = int.Parse(dsOrderInfo.Tables[0].Rows[0]["ItemSort"].ToString());
                            //    switch (itemSort)
                            //    {
                            //        case 2://充
                            //            #region 充值金额处理

                            //            VipAmountDetailBLL vipAmountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);

                            //            List<IWhereCondition> complexCondition = new List<IWhereCondition> { };
                            //            complexCondition.Add(new EqualsCondition() { FieldName = "ObjectId", Value = OrderID });

                            //            var vipAmountDetal = vipAmountDetailBll.Query(complexCondition.ToArray(), null);
                            //            if (vipAmountDetal.Count() == 0)//确认没有多次执行回调
                            //            {
                            //                ////查询
                            //                //RechargeStrategyEntity[] rechargeList = rechargeBll.Query(complexCondition.ToArray(), lstOrder.ToArray());

                            //                skuId = dsOrderInfo.Tables[0].Rows[0]["SkuId"].ToString();
                            //                //RechargeStrategyEntity rechargeEntity = rechargeBll.GetByID(skuId);
                            //                DataSet dsSkuPirce = unitBll.GetSkuPirce(skuId);
                            //                decimal salePrice = 0;//购买金额
                            //                decimal returnCash = 0;//奖励金额
                            //                if (dsSkuPirce.Tables[0].Rows.Count > 0)
                            //                {
                            //                    salePrice = Convert.ToDecimal(dsSkuPirce.Tables[0].Rows[0]["SalesPrice"].ToString());
                            //                    returnCash = Convert.ToDecimal(dsSkuPirce.Tables[0].Rows[0]["ReturnCash"].ToString());
                            //                    InoutService server = new InoutService(loggingSessionInfo);
                            //                    #region 充值金额
                            //                    var tran = server.GetTran();
                            //                    using (tran.Connection)//事物
                            //                    {
                            //                        try
                            //                        {
                            //                            //充值金额
                            //                            vipAmountBll.AddVipEndAmount(UserID, salePrice, tran, "4", OrderID, loggingSessionInfo);//4=充值
                            //                            tran.Commit();
                            //                        }
                            //                        catch (Exception)
                            //                        {
                            //                            tran.Rollback();
                            //                            throw;
                            //                        }
                            //                    }
                            //                    #endregion

                            //                    #region 奖励金额
                            //                    var tran2 = server.GetTran();
                            //                    using (tran2.Connection)//事物
                            //                    {
                            //                        try
                            //                        {
                            //                            //奖励金额
                            //                            vipAmountBll.AddVipEndAmount(UserID, returnCash, tran2, "6", OrderID, loggingSessionInfo);//6=奖励金额
                            //                            tran2.Commit();
                            //                        }
                            //                        catch (Exception)
                            //                        {
                            //                            tran2.Rollback();
                            //                            throw;
                            //                        }
                            //                    }
                            //                    #endregion
                            //                }
                            //            }
                            //            #endregion
                            //            break;
                            //        case 3://券
                            //            #region 券类商品绑定到会员
                            //            itemId = dsOrderInfo.Tables[0].Rows[0]["ItemId"].ToString();
                            //            vipId = dsOrderInfo.Tables[0].Rows[0]["VipId"].ToString();
                            //            couponId = couponBll.GetCouponByItemId(itemId);
                            //            if (!string.IsNullOrEmpty(couponId))
                            //            {
                            //                VipCouponMappingEntity coupon = new VipCouponMappingEntity
                            //                {
                            //                    VIPID = vipId,
                            //                    CouponID = couponId,
                            //                };
                            //                vipCouponMappingBll.Create(coupon);
                            //            }
                            //            #endregion
                            //            break;
                            //        default:
                            //            break;
                            //    }
                            //}

                            #endregion

                            #region 订单与分润关系处理 add by Henry 2014-10-10
                            //var orderSubBll = new OrderOrderSubRunObjectMappingBLL(loggingSessionInfo);
                            //dynamic o = orderSubBll.SetOrderSub(CustomerID, OrderID);
                            //Type t = o.GetType();
                            //var Desc = t.GetProperty("Desc").GetValue(o, null).ToString();
                            //var IsSuccess = t.GetProperty("IsSuccess").GetValue(o, null).ToString();
                            //if (int.Parse(IsSuccess.ToString()) == 0) //失败
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("订单与分润关系处理失败:{0}", Desc) });
                            #endregion

                            CustomerBasicSettingBLL customerBasicSettingBll = new CustomerBasicSettingBLL(loggingSessionInfo);
                            string AfterPaySetStock = customerBasicSettingBll.GetSettingValueByCode("AfterPaySetStock");
                            if (AfterPaySetStock == "1")
                            {
                                var inoutServiceBLL = new InoutService(loggingSessionInfo);
                                var inoutDetailList = inoutServiceBLL.GetInoutDetailInfoByOrderId(OrderID);
                                inoutBll.SetStock(OrderID, inoutDetailList, 1, loggingSessionInfo);
                            }
                            ///超级分销商订单入队列
                            if (inoutInfo.data_from_id == "35" || inoutInfo.data_from_id == "36")
                            {
                                BS.BLL.RedisOperationBLL.Order.SuperRetailTraderOrderBLL bllSuperRetailTraderOrder = new BS.BLL.RedisOperationBLL.Order.SuperRetailTraderOrderBLL();
                                bllSuperRetailTraderOrder.SetRedisToSuperRetailTraderOrder(loggingSessionInfo, inoutInfo);
                            }

                            //购卡
                            if (!string.IsNullOrEmpty(inoutInfo.Field17) && !string.IsNullOrEmpty(inoutInfo.Field18))
                            {
                                //更新订单状态
                                inoutInfo             = inoutBll.GetByID(OrderID);
                                inoutInfo.Field7      = "700";
                                inoutInfo.status      = "700";
                                inoutInfo.status_desc = "已完成";
                                inoutInfo.Field10     = "已完成";
                                inoutBll.Update(inoutInfo);
                                //会员卡升级
                                vipCardVipMappingBll.BindVirtualItem(vipInfo.VIPID, vipInfo.VipCode, inoutInfo.sales_unit_id, Convert.ToInt32(inoutInfo.Field18), orderId: inoutInfo.order_id);

                                //分润计算
                                RedisSalesVipCardOrderBLL redisSalesVipCardOrderBll = new RedisSalesVipCardOrderBLL();
                                redisSalesVipCardOrderBll.SetRedisSalesVipCardOrder(loggingSessionInfo, inoutInfo);

                                //售卡处理积分、返现、佣金[完成订单]
                                new SendOrderRewardMsgBLL().OrderReward(inoutInfo, loggingSessionInfo, null);//存入到缓存
                            }
                            else
                            {
                                //订单入队列
                                RedisCalculateVipConsumeForUpgrade redisCalculateVipConsumeForUpgrade = new RedisCalculateVipConsumeForUpgrade();
                                redisCalculateVipConsumeForUpgrade.SetVipConsumeForUpgradeList(loggingSessionInfo, inoutInfo);
                            }

                            // add by liangx 2016-09-27 获取订单中的虚拟商品 start
                            CouponTypeBLL            couponTypeBLL            = new CouponTypeBLL(loggingSessionInfo);
                            RedisVipMappingCouponBLL redisVipMappingCouponBLL = new RedisVipMappingCouponBLL();

                            var couponTypes = couponTypeBLL.GetVirtualItemCouponTypes(inoutInfo.order_id);

                            if (couponTypes.Any())
                            {
                                redisVipMappingCouponBLL.SetVipMappingCoupon(couponTypes, "", couponTypes.FirstOrDefault().VipId, "PayVirtualItem");
                            }

                            // add by liangx 2016-09-27 获取订单中的虚拟商品 end

                            //获取门店信息
                            t_unitEntity unitInfo = null;
                            if (!string.IsNullOrEmpty(inoutInfo.sales_unit_id))
                            {
                                unitInfo = unitBLL.GetByID(inoutInfo.sales_unit_id);
                            }
                            //入支付明细表
                            var paymentDetail = new T_Payment_detailEntity()
                            {
                                Payment_Id        = Guid.NewGuid().ToString(),
                                Inout_Id          = inoutInfo.order_id,
                                UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                Price             = inoutInfo.actual_amount,
                                Total_Amount      = inoutInfo.total_amount,
                                Pay_Points        = inoutInfo.pay_points,
                                CustomerId        = loggingSessionInfo.ClientID
                            };
                            paymentDetailBll.Create(paymentDetail);

                            List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                            };
                            complexCondition.Add(new EqualsCondition()
                            {
                                FieldName = "Inout_Id", Value = inoutInfo.order_id
                            });
                            var paymentDetailList = paymentDetailBll.Query(complexCondition.ToArray(), null);

                            try
                            {
                                var msgRabbitMQ = new EventContract
                                {
                                    Operation  = OptEnum.Create,
                                    EntityType = EntityTypeEnum.Order,
                                    Id         = inoutInfo.order_id
                                };
                                var service = new EventService();
                                service.PublishMsg(msgRabbitMQ);

                                foreach (var detail in paymentDetailList)
                                {
                                    var paymentMQ = new EventContract
                                    {
                                        Operation  = OptEnum.Create,
                                        EntityType = EntityTypeEnum.OrderPayment,
                                        Id         = detail.Payment_Id
                                    };
                                    service.PublishMsg(paymentMQ);
                                }
                            }
                            catch (Exception)
                            {
                                throw new Exception("RabbitMQ Error");
                            }
                        }
                        else//充值订单
                        {
                            var rechargeOrderBll   = new RechargeOrderBLL(loggingSessionInfo);
                            var vipamountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);
                            var rechargeOrderInfo  = rechargeOrderBll.GetByID(OrderID);
                            if (rechargeOrderInfo != null)
                            {
                                //获取门店信息
                                t_unitEntity unitInfo = null;
                                if (!string.IsNullOrEmpty(rechargeOrderInfo.UnitId))
                                {
                                    unitInfo = unitBLL.GetByID(rechargeOrderInfo.UnitId);
                                }
                                //充值
                                rechargeOrderBll.Recharge(rechargeOrderInfo, vipInfo, unitInfo, tPaymentType.Payment_Type_Id);
                                //入支付明细表
                                var paymentDetail = new T_Payment_detailEntity()
                                {
                                    Payment_Id        = Guid.NewGuid().ToString(),
                                    Inout_Id          = rechargeOrderInfo.OrderID.ToString(),
                                    UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                    Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                    Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                    Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                    Price             = rechargeOrderInfo.ActuallyPaid,
                                    Total_Amount      = rechargeOrderInfo.TotalAmount,
                                    Pay_Points        = rechargeOrderInfo.PayPoints,
                                    CustomerId        = loggingSessionInfo.ClientID
                                };
                                paymentDetailBll.Create(paymentDetail);
                            }
                            else
                            {
                                var receiveAmountOrderBll    = new ReceiveAmountOrderBLL(loggingSessionInfo);
                                var receiveAmountOrderEntity = receiveAmountOrderBll.GetByID(OrderID);



                                //更新订单状态
                                if (receiveAmountOrderEntity != null)
                                {
                                    VipIntegralBLL vipIntegralBll = new VipIntegralBLL(loggingSessionInfo);
                                    //更新订单
                                    receiveAmountOrderEntity.PayStatus = "10";
                                    // Bear
                                    //receiveAmountOrderEntity.PayTypeId = tPaymentTypeCustomerMappingEntity.PaymentTypeID;
                                    receiveAmountOrderEntity.PayTypeId    = tPaymentType.Payment_Type_Id;
                                    receiveAmountOrderEntity.PayDatetTime = DateTime.Now;
                                    receiveAmountOrderBll.Update(receiveAmountOrderEntity);

                                    //获取门店信息
                                    t_unitEntity unitInfo = null;
                                    if (!string.IsNullOrEmpty(receiveAmountOrderEntity.ServiceUnitId))
                                    {
                                        unitInfo = unitBLL.GetByID(receiveAmountOrderEntity.ServiceUnitId);
                                    }


                                    //使用过积分,处理积分
                                    if (receiveAmountOrderEntity.PayPoints != 0 && receiveAmountOrderEntity.PayPoints != null)
                                    {
                                        string sourceId       = "20"; //积分抵扣
                                        var    IntegralDetail = new VipIntegralDetailEntity()
                                        {
                                            Integral         = -Convert.ToInt32(receiveAmountOrderEntity.PayPoints),
                                            IntegralSourceID = sourceId,
                                            ObjectId         = receiveAmountOrderEntity.OrderId.ToString()
                                        };
                                        if (IntegralDetail.Integral != 0)
                                        {
                                            //变动前积分
                                            string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                                            //变动积分
                                            string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                                            var    vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, loggingSessionInfo);
                                            //发送微信积分变动通知模板消息
                                            if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                                            {
                                                var CommonBLL = new CommonBLL();
                                                CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, loggingSessionInfo);
                                            }
                                        }
                                    }
                                    //if (receiveAmountOrderEntity.CouponUsePay != 0 || receiveAmountOrderEntity.CouponUsePay != null)
                                    //{
                                    //    //更新使用记录
                                    //    var couponUseBll = new CouponUseBLL(loggingSessionInfo);
                                    //    var couponUseEntity = new CouponUseEntity()
                                    //    {
                                    //        CouponUseID = Guid.NewGuid(),
                                    //        CouponID = rp.CouponId,
                                    //        VipID = vipInfo.VIPID,
                                    //        UnitID = rp.UnitId,
                                    //        OrderID = orderId.ToString(),
                                    //        Comment = "商城使用电子券",
                                    //        CustomerID = CurrentUserInfo.ClientID,
                                    //        CreateBy = CurrentUserInfo.UserID,
                                    //        CreateTime = DateTime.Now,
                                    //        LastUpdateBy = CurrentUserInfo.UserID,
                                    //        LastUpdateTime = DateTime.Now,
                                    //        IsDelete = 0
                                    //    };
                                    //    couponUseBll.Create(couponUseEntity);

                                    //    var couponBll = new CouponBLL(CurrentUserInfo);
                                    //    var couponEntity = couponBll.GetByID(rp.CouponId);

                                    //    //更新CouponType数量
                                    //    var conponTypeBll = new CouponTypeBLL(CurrentUserInfo);
                                    //    var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity() { CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = CurrentUserInfo.ClientID }, null).FirstOrDefault();
                                    //    conponTypeEntity.IsVoucher += 1;
                                    //    conponTypeBll.Update(conponTypeEntity);

                                    //    //停用该优惠券
                                    //    couponEntity.Status = 1;
                                    //    couponBll.Update(couponEntity);
                                    //}

                                    //处理余额
                                    if (receiveAmountOrderEntity.AmountAcctPay != null && receiveAmountOrderEntity.AmountAcctPay != 0)
                                    {
                                        var vipAmountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);

                                        var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
                                        {
                                            VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
                                        }, null).FirstOrDefault();
                                        if (vipAmountEntity != null)
                                        {
                                            var detailInfo = new VipAmountDetailEntity()
                                            {
                                                Amount         = -receiveAmountOrderEntity.AmountAcctPay,
                                                AmountSourceId = "1",
                                                ObjectId       = receiveAmountOrderEntity.OrderId.ToString()
                                            };
                                            var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, loggingSessionInfo);
                                            if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                                            {//发送微信账户余额变动模板消息
                                                var CommonBLL = new CommonBLL();
                                                CommonBLL.BalanceChangedMessage(receiveAmountOrderEntity.OrderNo, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                            }
                                        }
                                    }


                                    //收款订单积分奖励

                                    vipIntegralBll.OrderReward(receiveAmountOrderEntity, null);


                                    var paymentDetail = new T_Payment_detailEntity()
                                    {
                                        Payment_Id        = Guid.NewGuid().ToString(),
                                        Inout_Id          = receiveAmountOrderEntity.OrderId.ToString(),
                                        UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                        Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                        Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                        Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                        Price             = receiveAmountOrderEntity.TransAmount,
                                        Total_Amount      = receiveAmountOrderEntity.TotalAmount,
                                        Pay_Points        = receiveAmountOrderEntity.PayPoints,
                                        CustomerId        = loggingSessionInfo.ClientID
                                    };
                                    paymentDetailBll.Create(paymentDetail);
                                }
                            }
                        }
                        context.Response.Write("SUCCESS");
                    }
                }
            }
            catch (Exception ex)
            {
                Loggers.Exception(new ExceptionLogInfo(ex));
                context.Response.Write("ERROR:" + ex.Message);
            }
        }
        /// <summary>
        /// 计算购卡分润
        /// </summary>
        public void CalculateSalesVipCardOrderJob()
        {
            var numCount = 50;

            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                string connString = customer.Value;
                var    count      = RedisOpenAPI.Instance.CCSalesCardOrder().GetSalesCardOrderLength(new CC_Order
                {
                    CustomerID = customer.Key
                });
                if (count.Code != ResponseCode.Success)
                {
                    BaseService.WriteLog("从redis获取vipcard订单数据失败");
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }
                //DataTable dtAmountDetail = CreateTableAmountDetail();
                //DataTable dtAmount = CreateTableAmount();
                //DataTable dtSplitProfitRecord = CreateTableSplitProfitRecord();

                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCSalesCardOrder().GetSalesCardOrder(new CC_Order
                    {
                        CustomerID = customer.Key
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var        orderInfo          = response.Result.OrderInfo.JsonDeserialize <T_InoutEntity>();
                        var        loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "RedisSystem");
                        T_InoutBLL inoutBLL           = new T_InoutBLL(loggingSessionInfo);
                        if (orderInfo != null)
                        {
                            VipBLL                      bllVip                    = new VipBLL(loggingSessionInfo);
                            T_Inout_DetailBLL           bllInoutDetail            = new T_Inout_DetailBLL(loggingSessionInfo);
                            T_VirtualItemTypeSettingBLL bllVirtualItemTypeSetting = new T_VirtualItemTypeSettingBLL(loggingSessionInfo);
                            VipCardUpgradeRuleBLL       bllVipCardUpgradeRule     = new VipCardUpgradeRuleBLL(loggingSessionInfo);
                            VipAmountBLL                bllVipAmount              = new VipAmountBLL(loggingSessionInfo);
                            VipAmountDetailBLL          bllVipAmountDetail        = new VipAmountDetailBLL(loggingSessionInfo);
                            T_SplitProfitRecordBLL      bllSplitProfitRecord      = new T_SplitProfitRecordBLL(loggingSessionInfo);

                            VipAmountEntity           entityVipAmount         = new VipAmountEntity();
                            VipAmountDetailEntity     entityVipAmountDetail   = new VipAmountDetailEntity();
                            T_SplitProfitRecordEntity entitySplitProfitRecord = new T_SplitProfitRecordEntity();

                            DataSet dsVipCardLevel    = bllVip.GetVipCardLevel(orderInfo.vip_no, loggingSessionInfo.ClientID);
                            var     entityInoutDetail = bllInoutDetail.QueryByEntity(new T_Inout_DetailEntity()
                            {
                                order_id = orderInfo.order_id
                            }, null).FirstOrDefault();
                            if (entityInoutDetail == null)
                            {
                                continue;
                            }
                            var vipCardType = bllVirtualItemTypeSetting.QueryByEntity(new T_VirtualItemTypeSettingEntity()
                            {
                                SkuId = entityInoutDetail.sku_id, IsDelete = 0
                            }, null).FirstOrDefault();
                            if (vipCardType != null)
                            {
                                int intVipCardTypeID         = Convert.ToInt32(vipCardType.ObjecetTypeId);
                                var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                                {
                                    VipCardTypeID = intVipCardTypeID, IsPurchaseUpgrade = 1, IsDelete = 0
                                }, null).SingleOrDefault();
                                if (entityVipCardUpgradeRule != null)
                                {
                                    VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
                                    var entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                                    {
                                        VipCardTypeID = intVipCardTypeID, IsDelete = 0
                                    }, null);
                                    foreach (var ProfitRule in entityVipCardProfitRule)
                                    {
                                        if (ProfitRule.IsApplyAllUnits == 0)
                                        {
                                            VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
                                            var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity()
                                            {
                                                CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = orderInfo.sales_unit_id, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                                            }, null).SingleOrDefault();
                                            if (vipCardProfitRuleUnitMapping == null)
                                            {
                                                continue;
                                            }
                                        }
                                        decimal amount            = 0;
                                        string  strAmountSourceId = string.Empty;
                                        string  strVipId          = string.Empty;
                                        string  strUserType       = string.Empty;
                                        if (ProfitRule.ProfitOwner == "Employee")
                                        {
                                            strAmountSourceId = "37";
                                            strVipId          = orderInfo.sales_user;
                                            strUserType       = "User";
                                        }
                                        if (ProfitRule.ProfitOwner == "Unit")
                                        {
                                            strAmountSourceId = "40";
                                            strVipId          = orderInfo.sales_unit_id;
                                            strUserType       = "Unit";
                                        }
                                        amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                        var vipAmountDetail = bllVipAmountDetail.QueryByEntity(new VipAmountDetailEntity()
                                        {
                                            ObjectId = orderInfo.order_id, AmountSourceId = strAmountSourceId
                                        }, null);
                                        if (vipAmountDetail != null && vipAmountDetail.Length > 0)
                                        {
                                            continue;
                                        }
                                        if (amount > 0)
                                        {
                                            IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();
                                            try {
                                                //                                 DataRow dr_SplitProfitRecord = dtSplitProfitRecord.NewRow();
                                                //                                 dr_SplitProfitRecord["Id"] = Guid.NewGuid();
                                                //                                 dr_SplitProfitRecord["SourceType"] = "Amount";
                                                //                                 dr_SplitProfitRecord["SourceId"] = strAmountSourceId;
                                                //                                 dr_SplitProfitRecord["ObjectId"] = orderInfo.order_id;
                                                //dr_SplitProfitRecord["UserType"] = strUserType;
                                                //                                 dr_SplitProfitRecord["UserId"] = orderInfo.sales_user;
                                                //                                 dr_SplitProfitRecord["SplitAmount"] = amount;
                                                //                                 dr_SplitProfitRecord["SplitSattus"] = "10";
                                                //                                 dr_SplitProfitRecord["CustomerId"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["CreateTime"] = DateTime.Now;
                                                //                                 dr_SplitProfitRecord["CreateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["LastUpdateTime"] = DateTime.Now;
                                                //                                 dr_SplitProfitRecord["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["IsDelete"] = 0;
                                                //                                 dtSplitProfitRecord.Rows.Add(dr_SplitProfitRecord);

                                                //                                 DataRow dr_AmountDetail = dtAmountDetail.NewRow();
                                                //                                 dr_AmountDetail["VipAmountDetailId"] = Guid.NewGuid();
                                                //dr_AmountDetail["VipId"] = strVipId;
                                                //                                 dr_AmountDetail["VipCardCode"] = "";
                                                //                                 dr_AmountDetail["UnitID"] = "";
                                                //                                 dr_AmountDetail["UnitName"] = "";
                                                //                                 dr_AmountDetail["SalesAmount"] = 0;
                                                //                                 dr_AmountDetail["Amount"] = amount;
                                                //                                 dr_AmountDetail["UsedReturnAmount"] = 0;
                                                //                                 dr_AmountDetail["Reason"] = "首次售卡分润";
                                                //                                 dr_AmountDetail["EffectiveDate"] = DateTime.Now;
                                                //                                 dr_AmountDetail["DeadlineDate"] = Convert.ToDateTime("9999-12-31 23:59:59");
                                                //                                 dr_AmountDetail["AmountSourceId"] = strAmountSourceId;
                                                //                                 dr_AmountDetail["ObjectId"] = orderInfo.order_id;
                                                //                                 dr_AmountDetail["Remark"] = "首次售卡分润";
                                                //                                 dr_AmountDetail["IsValid"] = 0;
                                                //                                 dr_AmountDetail["IsWithdrawCash"] = 0;
                                                //                                 dr_AmountDetail["CustomerID"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["CreateTime"] = DateTime.Now;
                                                //                                 dr_AmountDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["LastUpdateTime"] = DateTime.Now;
                                                //                                 dr_AmountDetail["IsDelete"] = 0;
                                                //                                 //dr_AmountDetail["IsCalculated"] = 1;
                                                //                                 dtAmountDetail.Rows.Add(dr_AmountDetail);

                                                entitySplitProfitRecord = new T_SplitProfitRecordEntity()
                                                {
                                                    ID          = Guid.NewGuid().ToString(),
                                                    SourceType  = "Amount",
                                                    SourceId    = strAmountSourceId,
                                                    ObjectId    = orderInfo.order_id,
                                                    UserType    = strUserType,
                                                    UserId      = orderInfo.sales_user,
                                                    SplitAmount = amount,
                                                    SplitSattus = "10",
                                                    CustomerID  = loggingSessionInfo.ClientID
                                                };
                                                bllSplitProfitRecord.Create(entitySplitProfitRecord, tran);


                                                entityVipAmountDetail = new VipAmountDetailEntity {
                                                    VipAmountDetailId = Guid.NewGuid(),
                                                    VipId             = strVipId,
                                                    Amount            = amount,
                                                    UsedReturnAmount  = 0,
                                                    EffectiveDate     = DateTime.Now,
                                                    DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                                    AmountSourceId    = strAmountSourceId,
                                                    ObjectId          = orderInfo.order_id,
                                                    CustomerID        = loggingSessionInfo.ClientID,
                                                    Reason            = "首次售卡分润",
                                                    Remark            = "首次售卡分润",
                                                    IsWithdrawCash    = 0
                                                };
                                                bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);

                                                entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                                                {
                                                    VipId = orderInfo.sales_user, IsDelete = 0
                                                }, null).SingleOrDefault();
                                                if (entityVipAmount == null)
                                                {
                                                    //DataRow dr_Amount = dtAmount.NewRow();
                                                    //dr_Amount["VipId"] = orderInfo.sales_user;
                                                    //dr_Amount["VipCardCode"] = "";
                                                    //dr_Amount["BeginAmount"] = 0;
                                                    //dr_Amount["InAmount"] = amount;
                                                    //dr_Amount["OutAmount"] = 0;
                                                    //dr_Amount["EndAmount"] = amount;
                                                    //dr_Amount["TotalAmount"] = amount;
                                                    //dr_Amount["BeginReturnAmount"] = 0;
                                                    //dr_Amount["InReturnAmount"] = 0;
                                                    //dr_Amount["OutReturnAmount"] = 0;
                                                    //dr_Amount["ReturnAmount"] = 0;
                                                    //dr_Amount["ImminentInvalidRAmount"] = 0;
                                                    //dr_Amount["InvalidReturnAmount"] = 0;
                                                    //dr_Amount["ValidReturnAmount"] = 0;
                                                    //dr_Amount["TotalReturnAmount"] = 0;
                                                    //dr_Amount["PayPassword"] = "";
                                                    //dr_Amount["IsLocking"] = 0;
                                                    //dr_Amount["CustomerID"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["CreateTime"] = DateTime.Now;
                                                    //dr_Amount["CreateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["LastUpdateTime"] = DateTime.Now;
                                                    //dr_Amount["IsDelete"] = 0;
                                                    //dtAmount.Rows.Add(dr_Amount);
                                                    entityVipAmount = new VipAmountEntity {
                                                        VipId                  = strVipId,
                                                        BeginAmount            = 0,
                                                        InAmount               = amount,
                                                        OutAmount              = 0,
                                                        EndAmount              = amount,
                                                        TotalAmount            = amount,
                                                        BeginReturnAmount      = 0,
                                                        InReturnAmount         = 0,
                                                        OutReturnAmount        = 0,
                                                        ReturnAmount           = 0,
                                                        ImminentInvalidRAmount = 0,
                                                        InvalidReturnAmount    = 0,
                                                        ValidReturnAmount      = 0,
                                                        TotalReturnAmount      = 0,
                                                        IsLocking              = 0,
                                                        CustomerID             = loggingSessionInfo.ClientID,
                                                        VipCardCode            = ""
                                                    };
                                                    bllVipAmount.Create(entityVipAmount, tran);
                                                }
                                                else
                                                {
                                                    entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                                                    entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                                                    entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                                                    entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;

                                                    bllVipAmount.Update(entityVipAmount);
                                                }
                                                tran.Commit();
                                            }
                                            catch (Exception) {
                                                tran.Rollback();
                                                throw;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //if (dtAmount.Rows.Count > 0)
                //{
                //    Utils.SqlBulkCopy(connString, dtAmount, "VipAmount");
                //}
                //if (dtAmountDetail.Rows.Count > 0 && dtSplitProfitRecord.Rows.Count > 0)
                //{
                //    Utils.SqlBulkCopy(connString, dtSplitProfitRecord, "T_SplitProfitRecord");
                //    Utils.SqlBulkCopy(connString, dtAmountDetail, "VipAmountDetail");

                //}
            }
        }
Beispiel #24
0
        /// <summary>
        /// 微信扫码支付
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        protected override ScanWxPayRD ProcessRequest(DTO.Base.APIRequest <ScanWxPayRP> pRequest)
        {
            var rd  = new ScanWxPayRD();
            var par = pRequest.Parameters;

            try
            {
                //获取登录信息,数据库的一些链接与基础信息
                LoggingSessionInfo loggingSessionInfo = Default.GetBSLoggingSession(pRequest.CustomerID, pRequest.OpenID);

                var     rechargeOrderBLL = new RechargeOrderBLL(loggingSessionInfo);
                decimal appOrderAmount   = 0;  //实际支付金额

                if (par.PaymentScenarios == 1) //根据支付场景区分对应的订单表获取实际支付金额
                {
                    //直充订单支付金额
                    var rechargeOrderInfo = rechargeOrderBLL.GetByID(par.OrderId);
                    if (rechargeOrderInfo != null)
                    {
                        appOrderAmount = rechargeOrderInfo.ActuallyPaid.Value;
                    }
                }
                else
                {
                    var inout = new T_InoutBLL(loggingSessionInfo);

                    //售卡订单支付金额
                    var inoutOrderInfo = inout.GetByID(par.OrderId);
                    if (inoutOrderInfo != null)
                    {
                        appOrderAmount = inoutOrderInfo.actual_amount.Value;
                    }
                }

                //交易中心请求参数
                var para = new
                {
                    PayChannelID   = par.ChannelID,
                    AppOrderID     = par.OrderId,
                    AppOrderTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
                    AppOrderAmount = ToInt(appOrderAmount * 100),
                    AppOrderDesc   = par.OrderDesc,
                    Currency       = 1,
                    MobileNO       = par.Mobile,
                    ReturnUrl      = string.Empty,
                    DynamicID      = string.Empty,
                    DynamicIDType  = string.Empty,
                    Paras          = new Dictionary <string, object>(),
                    OpenId         = pRequest.OpenID,
                    ClientIP       = Utils.GetHostAddress(),
                    PaymentMode    = par.PaymentMode
                };

                var request = new
                {
                    AppID      = 1,
                    ClientID   = pRequest.CustomerID,
                    UserID     = pRequest.UserID,
                    Parameters = para
                };

                //Json参数准备
                string pUrlPath   = ConfigurationManager.AppSettings["paymentcenterUrl"];
                string jsonString = string.Format("action=CreateOrder&request={0}", request.ToJSON());

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "创建订单到交易中心,请求地址:" + pUrlPath + ",请求参数:" + jsonString
                });

                string httpResponse = HttpHelper.SendHttpRequest(pUrlPath, jsonString);

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("交易中心返回结果:{0}", httpResponse.ToJSON())
                });

                //反序列化
                var payres = httpResponse.DeserializeJSONTo <RespCreateOrder>();

                if (payres.ResultCode == 0)
                {
                    //根据微信返回的CodeUrl生成二维码
                    string currentDomain = ConfigurationManager.AppSettings["website_WWW"].ToString();
                    string sourcePath    = HttpContext.Current.Server.MapPath("/Images/qrcode2.jpg");
                    string targetPath    = HttpContext.Current.Server.MapPath("/file/images/");

                    var payQrCodeUrl = Utils.GenerateQRCodeWx(payres.Datas.QrCodeUrl,
                                                              currentDomain, sourcePath, targetPath); //生成二维码方法
                    rd.QrCodeUrl = payQrCodeUrl;
                }
            }
            catch (Exception ex)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("交易中心代码异常信息:{0}", ex.Message + ";堆栈信息:" + ex.StackTrace)
                });
            }

            return(rd);
        }
        protected override GetVipCardTypeVirtualItemRD ProcessRequest(DTO.Base.APIRequest <GetVipCardTypeVirtualItemRP> pRequest)
        {
            var rd   = new GetVipCardTypeVirtualItemRD();
            var para = pRequest.Parameters;
            LoggingSessionInfo loggingSessionInfo = Default.GetBSLoggingSession(pRequest.CustomerID, pRequest.UserID);
            var vipBLL               = new VipBLL(loggingSessionInfo);
            var vipIntegralBLL       = new VipIntegralBLL(loggingSessionInfo);
            var sysVipCardTypeBLL    = new SysVipCardTypeBLL(loggingSessionInfo);
            var vipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);
            var vipCardBLL           = new VipCardBLL(loggingSessionInfo);
            var vipCardRuleBLL       = new VipCardRuleBLL(loggingSessionInfo);
            var vipT_InoutBLL        = new T_InoutBLL(loggingSessionInfo);
            List <VipCardUpgradeRewardInfo> VipCardUpgradeRewardList = new List <VipCardUpgradeRewardInfo>();
            List <VipCardTypeRelateInfo>    VipCardTypeRelateList    = new List <VipCardTypeRelateInfo>();
            //获取当前会员卡等级
            VipEntity VipInfo         = null;
            int?      CurVipCardLevel = 0;
            //处理会员开卡礼信息
            var VipCardUpgradeRewardInfoList = sysVipCardTypeBLL.GetCardUpgradeRewardList(loggingSessionInfo.ClientID);
            //定义卡体系信息
            DataSet VipCardTypeSystemInfoList = null;
            string  strVipID = string.Empty;

            switch (para.ApplicationType)
            {
            //为1是微信,为2时表示APP请求
            case "1":    //微信
                strVipID = pRequest.UserID;
                break;

            case "2":                  //APP
                strVipID = para.VipID; //获取会员信息
                break;
            }

            VipInfo = vipBLL.GetByID(strVipID);//获取会员信息
            if (VipInfo != null)
            {
                rd.HeadImgUrl = VipInfo.HeadImgUrl == null ? "" : VipInfo.HeadImgUrl;
                var vipIntegralInfo = vipIntegralBLL.QueryByEntity(new VipIntegralEntity()
                {
                    VipID = strVipID, VipCardCode = VipInfo.VipCode
                }, null).FirstOrDefault();
                if (vipIntegralInfo != null)//获取当前会员积分
                {
                    rd.Integration = vipIntegralInfo.ValidIntegral != null ? vipIntegralInfo.ValidIntegral.Value : 0;
                }
                //获取会员卡等级相关信息
                var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                {
                    VIPID = strVipID, CustomerID = loggingSessionInfo.ClientID
                },
                                                                            new OrderBy[] { new OrderBy()
                                                                                            {
                                                                                                FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                                            } }).FirstOrDefault();
                if (vipCardMappingInfo != null)
                {
                    var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                    {
                        VipCardID = vipCardMappingInfo.VipCardID, VipCardStatusId = 1
                    }, null).FirstOrDefault();
                    if (vipCardInfo != null)
                    {
                        var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                        {
                            VipCardTypeID = vipCardInfo.VipCardTypeID
                        }, null).FirstOrDefault();
                        if (vipCardTypeInfo != null)//获取当前会员卡等级信息
                        {
                            rd.VipCardTypeName = vipCardTypeInfo.VipCardTypeName != null ? vipCardTypeInfo.VipCardTypeName : "";
                            rd.VipCardLevel    = vipCardTypeInfo.VipCardLevel;
                            CurVipCardLevel    = vipCardTypeInfo.VipCardLevel;
                        }
                    }
                }
                else
                {
                    var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        VipCardLevel = 1, CustomerID = loggingSessionInfo.ClientID
                    }, null).FirstOrDefault();
                    if (vipCardTypeInfo != null)
                    {
                        rd.VipCardTypeName = vipCardTypeInfo.VipCardTypeName != null ? vipCardTypeInfo.VipCardTypeName : "";
                        rd.VipCardLevel    = vipCardTypeInfo.VipCardLevel != null ? vipCardTypeInfo.VipCardLevel : 1;
                        CurVipCardLevel    = vipCardTypeInfo.VipCardLevel != null ? vipCardTypeInfo.VipCardLevel : 1;
                    }
                }
                //获取会员消费金额
                decimal VipConsumptionInfo = vipT_InoutBLL.GetVipSumAmount(strVipID);
                if (VipConsumptionInfo > 0)
                {
                    rd.VipConsumptionAmount = Convert.ToDecimal(VipConsumptionInfo).ToString("0.00");
                }
                else
                {
                    rd.VipConsumptionAmount = "0";
                }
                //获取卡等级相关信息(会员卡等级信息、升级条件、基本权益关联虚拟商品)
                VipCardTypeSystemInfoList = sysVipCardTypeBLL.GetVipCardTypeVirtualItemList(loggingSessionInfo.ClientID, CurVipCardLevel, para.ApplicationType, VipInfo.VIPID);
            }


            if (VipCardTypeSystemInfoList != null && VipCardTypeSystemInfoList.Tables[0].Rows.Count > 0)
            {
                int flag = 0;//定义下面开卡礼能否进行展示(0=不进,1=进)
                if (VipCardUpgradeRewardInfoList != null && VipCardUpgradeRewardInfoList.Tables[0].Rows.Count > 0)
                {
                    flag = 1;
                    //获取开卡礼信息 为之后筛选数据使用
                    VipCardUpgradeRewardList = DataTableToObject.ConvertToList <VipCardUpgradeRewardInfo>(VipCardUpgradeRewardInfoList.Tables[0]);
                }
                var dt = VipCardTypeSystemInfoList.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    var DataInfo = new VipCardTypeRelateInfo();
                    //VipCardTypeRelateList = new List<VipCardTypeRelateInfo>();
                    DataInfo.VipCardType              = new VipCardTypeInfo();        //会员卡体系
                    DataInfo.VipCardUpgradeRule       = new VipCardUpgradeRuleInfo(); //会员卡升级规则
                    DataInfo.VipCardRule              = new VipCardRuleInfo();        //会员卡基本体系
                    DataInfo.VipCardUpgradeRewardList = new List <VipCardUpgradeRewardInfo>();
                    //var VipCardTypeData = new VipCardTypeInfo();
                    //给会员卡等级赋值
                    DataInfo.VipCardType.VipCardTypeID   = Convert.ToInt32(dr["VipCardTypeID"]);
                    DataInfo.VipCardType.VipCardLevel    = Convert.ToInt32(dr["VipCardLevel"]);
                    DataInfo.VipCardType.VipCardTypeName = dr["VipCardTypeName"].ToString();
                    DataInfo.VipCardType.PicUrl          = dr["PicUrl"].ToString();
                    DataInfo.VipCardType.IsPrepaid       = Convert.ToInt32(dr["IsPrepaid"]);
                    DataInfo.VipCardType.IsOnlineSales   = Convert.ToInt32(dr["IsOnlineSales"]);
                    DataInfo.VipCardType.ItemID          = dr["ItemID"].ToString();
                    DataInfo.VipCardType.SkuID           = dr["SkuID"].ToString();
                    int cardStatus = 0;
                    //获取卡状态购买信息 0=没购买,1=已购买 pRequest.UserID
                    if (DataInfo.VipCardType.IsPrepaid != 1)//非可储值类型关联订单
                    {
                        cardStatus = vipT_InoutBLL.GetVirtualItemStatus(loggingSessionInfo.ClientID, strVipID, DataInfo.VipCardType.SkuID);
                    }
                    else//可储值类型关联充值订单
                    {
                        var RechargeOrderBll  = new RechargeOrderBLL(loggingSessionInfo);
                        var RechargeOrderInfo = RechargeOrderBll.QueryByEntity(new RechargeOrderEntity()
                        {
                            OrderDesc = "Upgrade", VipID = strVipID, VipCardTypeId = DataInfo.VipCardType.VipCardTypeID, Status = 1
                        }, null).FirstOrDefault();
                        if (RechargeOrderInfo != null)//如果为空需要在订单表里查找下记录
                        {
                            cardStatus = 1;
                        }
                        else
                        {
                            cardStatus = vipT_InoutBLL.GetVirtualItemStatus(loggingSessionInfo.ClientID, strVipID, DataInfo.VipCardType.SkuID);
                        }
                    }

                    DataInfo.VipCardType.Status = cardStatus;
                    //var VipCardUpgradeRuleData = new VipCardUpgradeRuleInfo();
                    DataInfo.VipCardUpgradeRule.VipCardTypeID        = Convert.ToInt32(dr["VipCardTypeID"]);
                    DataInfo.VipCardUpgradeRule.VipCardUpgradeRuleId = dr["VipCardUpgradeRuleId"].ToString();
                    DataInfo.VipCardUpgradeRule.IsPurchaseUpgrade    = Convert.ToInt32(dr["IsPurchaseUpgrade"]);
                    DataInfo.VipCardUpgradeRule.IsExtraMoney         = Convert.ToInt32(dr["IsExtraMoney"]);
                    DataInfo.VipCardUpgradeRule.Prices             = Convert.ToDecimal(dr["Prices"]);
                    DataInfo.VipCardUpgradeRule.ExchangeIntegral   = Convert.ToInt32(dr["ExchangeIntegral"]);
                    DataInfo.VipCardUpgradeRule.IsRecharge         = Convert.ToInt32(dr["IsRecharge"]);
                    DataInfo.VipCardUpgradeRule.OnceRechargeAmount = Convert.ToDecimal(dr["OnceRechargeAmount"]);
                    DataInfo.VipCardUpgradeRule.IsBuyUpgrade       = Convert.ToInt32(dr["IsBuyUpgrade"]);
                    DataInfo.VipCardUpgradeRule.BuyAmount          = Convert.ToDecimal(dr["BuyAmount"]);
                    DataInfo.VipCardUpgradeRule.OnceBuyAmount      = Convert.ToDecimal(dr["OnceBuyAmount"]);

                    //var VipCardRuleData = new VipCardUpgradeRuleInfo();
                    DataInfo.VipCardRule.VipCardTypeID        = Convert.ToInt32(dr["VipCardTypeID"]);
                    DataInfo.VipCardRule.RuleID               = Convert.ToInt32(dr["RuleID"]);
                    DataInfo.VipCardRule.CardDiscount         = Convert.ToDecimal(dr["CardDiscount"]);
                    DataInfo.VipCardRule.PaidGivePercetPoints = Convert.ToDecimal(dr["PaidGivePercetPoints"]);
                    DataInfo.VipCardRule.PaidGivePoints       = Convert.ToDecimal(dr["PaidGivePoints"]);
                    if (flag == 1)//当flag=1的时候进行开卡礼的展示
                    {
                        DataInfo.VipCardUpgradeRewardList = VipCardUpgradeRewardList.Where(m => m.VipCardTypeID == Convert.ToInt32(dr["VipCardTypeID"])).Select(
                            t => new VipCardUpgradeRewardInfo()
                        {
                            CardUpgradeRewardId = t.CardUpgradeRewardId,
                            VipCardTypeID       = t.VipCardTypeID,
                            CouponTypeID        = t.CouponTypeID,
                            CouponNum           = t.CouponNum,
                            CouponName          = t.CouponName,
                            ValidityPeriod      = t.BeginTime == null ? ("领取后" + (t.ServiceLife == 0 ? "1天内有效" : t.ServiceLife.ToString() + "天内有效")) : (t.BeginTime.Value.ToString("yyyy-MM-dd") + "至" + t.EndTime.Value.ToString("yyyy-MM-dd")),
                            BeginTime           = t.BeginTime,
                            EndTime             = t.EndTime,
                            BeginTimeDate       = t.BeginTime == null ? "" : t.BeginTime.Value.ToString("yyyy年MM月dd日"),
                            EndTimeDate         = t.EndTime == null ? "" : t.EndTime.Value.ToString("yyyy年MM月dd日"),
                            ServiceLife         = t.ServiceLife,
                            CouponDesc          = t.CouponDesc,
                            ParValue            = t.ParValue
                        }).ToList();
                    }
                    VipCardTypeRelateList.Add(DataInfo);
                }
                rd.VipCardTypeItemList = VipCardTypeRelateList;
            }
            return(rd);
        }
        public void AutoSetOrderNotPayCache()
        {
            foreach (var customer in _CustomerIDList)
            {
                _T_loggingSessionInfo.ClientID = customer.Key;
                _T_loggingSessionInfo.CurrentLoggingManager.Connection_String = customer.Value;

                //
                _T_InoutBLL    = new T_InoutBLL(_T_loggingSessionInfo);
                _Inout3Service = new InoutService(_T_loggingSessionInfo);
                var inoutStatus = new TInoutStatusBLL(_T_loggingSessionInfo);
                _VipBLL = new VipBLL(_T_loggingSessionInfo);

                //
                // var t_InoutList = new List<string>();
                try
                {
                    List <IWhereCondition> complexCondition = new List <IWhereCondition>();
                    string[] statusArr = { "620", "610", "600" };
                    complexCondition.Add(new InCondition <string>()
                    {
                        FieldName = "Field7", Values = statusArr
                    });
                    complexCondition.Add(
                        new DirectCondition(
                            " CONVERT(NVARCHAR(10),complete_date,120) = CONVERT(NVARCHAR(10),DATEADD(day, -1, GETDATE()),120)"));

                    var t_InoutEntitys = _T_InoutBLL.Query(complexCondition.ToArray(), null);
                    if (t_InoutEntitys == null || t_InoutEntitys.Count() <= 0)
                    {
                    }
                    //
                    //   roleList = roleEntities.Select(it => it.role_id).ToList();

                    foreach (var t_InoutInfo in t_InoutEntitys)
                    {
                        TInoutStatusEntity info = new TInoutStatusEntity();
                        info.InoutStatusID = Guid.Parse(Utils.NewGuid());
                        info.OrderID       = t_InoutInfo.order_id;
                        info.CustomerID    = _T_loggingSessionInfo.ClientID;
                        info.Remark        = string.Empty;
                        info.OrderStatus   = 700;

                        string statusDesc = GetStatusDesc("700");//变更后的状态名称

                        try
                        {
                            info.StatusRemark = "订单状态从" + t_InoutInfo.status_desc + "变为" + statusDesc + "[操作人:自动]";
                            _Inout3Service.UpdateOrderDeliveryStatus(t_InoutInfo.order_id, "700", Utils.GetNow());
                        }
                        catch
                        {
                            continue;
                        }

                        inoutStatus.Create(info);

                        #region 支付成功,调用RabbitMQ发送给ERP

                        try
                        {
                            var msg = new EventContract
                            {
                                Operation  = OptEnum.Update,
                                EntityType = EntityTypeEnum.Order,
                                Id         = t_InoutInfo.order_id
                            };
                            var eventService = new EventService();
                            eventService.PublishMsg(msg);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message);
                        }

                        #endregion
                    }
                }
                catch
                {
                    // ignored
                }
            }
        }
Beispiel #27
0
        /// <summary>
        /// APP/后台订单发货-发送微信模板消息
        /// </summary>
        public void ProcessOrderRewardMsg()
        {
            //
            var numCount  = 100;
            var commonBLL = new CommonBLL();

            //
            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                //
                var count = RedisOpenAPI.Instance.CCOrderReward().GetOrderRewardLength(new CC_OrderReward
                {
                    CustomerID = customer.Key,
                });
                if (count.Code != ResponseCode.Success)
                {
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }

                //
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }

                //
                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCOrderReward().GetOrderReward(new CC_OrderReward
                    {
                        CustomerID = customer.Key,
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var        loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "1");// response.Result.LogSession.JsonDeserialize<LoggingSessionInfo>();
                        T_InoutBLL _TInoutbll         = new T_InoutBLL(loggingSessionInfo);

                        var orderInfo = _TInoutbll.GetInoutInfo(response.Result.OrderID, loggingSessionInfo);//response.Result.OrderInfo.JsonDeserialize<T_InoutEntity>();

                        IDbTransaction tran = new TransactionHelper(loggingSessionInfo).CreateTransaction();
                        using (tran.Connection)
                        {
                            try
                            {
                                new VipIntegralBLL(loggingSessionInfo).OrderReward(orderInfo, (SqlTransaction)tran);//还是把原来的事务传进去
                                tran.Commit();
                            }
                            catch (Exception ex)
                            {
                                tran.Rollback();
                            }
                        }
                    }
                }
            }
        }
        protected override GetRefundOrderDetailRD ProcessRequest(DTO.Base.APIRequest <GetRefundOrderDetailRP> pRequest)
        {
            var rd   = new GetRefundOrderDetailRD();
            var para = pRequest.Parameters;

            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var refundOrderBLL     = new T_RefundOrderBLL(loggingSessionInfo);

            var inoutService    = new InoutService(loggingSessionInfo);
            var tInoutDetailBll = new TInoutDetailBLL(loggingSessionInfo);
            var t_InoutBLL      = new T_InoutBLL(loggingSessionInfo);
            var PaymentTtpeBLL  = new T_Payment_TypeBLL(loggingSessionInfo);
            var refundEntity    = refundOrderBLL.GetByID(para.RefundID);

            if (refundEntity != null)
            {
                rd.RefundID           = refundEntity.RefundID;
                rd.RefundNo           = refundEntity.RefundNo;
                rd.Status             = refundEntity.Status;
                rd.OrderNo            = refundEntity.OrderNo;
                rd.Contacts           = refundEntity.Contacts;
                rd.Phone              = refundEntity.Phone;
                rd.ConfirmAmount      = refundEntity.ConfirmAmount;
                rd.ActualRefundAmount = refundEntity.ActualRefundAmount;
                rd.Points             = refundEntity.Points == null ? 0 : refundEntity.Points;
                rd.PointsAmount       = refundEntity.PointsAmount == null ? 0 : refundEntity.PointsAmount;
                rd.ReturnAmount       = refundEntity.ReturnAmount == null ? 0 : refundEntity.RefundAmount;
                rd.Amount             = refundEntity.Amount == null ? 0 : refundEntity.Amount;

                //支付方式名称
                var    OrderData     = t_InoutBLL.GetByID(refundEntity.OrderID);
                string m_PayTypeName = "";
                if (OrderData != null)
                {
                    var PayTypeData = PaymentTtpeBLL.GetByID(OrderData.pay_id);
                    if (PayTypeData != null)
                    {
                        m_PayTypeName = PayTypeData.Payment_Type_Name;
                    }
                }
                rd.PayTypeName = m_PayTypeName;


                rd.PayOrderID = refundEntity.PayOrderID;
                rd.OrderID    = refundEntity.OrderID;
                rd.ItemID     = refundEntity.ItemID;

                if (!string.IsNullOrEmpty(refundEntity.ItemID)) //取消订单时,直接跳转到订单详情
                {
                    //根据订单ID获取订单明细[复用]
                    DataRow drItem = inoutService.GetOrderDetailByOrderId(refundEntity.OrderID).Tables[0].Select(" item_id= '" + refundEntity.ItemID + "'").FirstOrDefault();
                    //获取商品的图片[复用]
                    string  itemImage = string.Empty;
                    DataSet ds        = tInoutDetailBll.GetOrderDetailImageList("'" + refundEntity.ItemID + "'");
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        itemImage = ds.Tables[0].Rows[0]["imageUrl"].ToString();
                    }
                    //获取订单详细列表中的商品规格[复用]
                    DataRow[] drSku = inoutService.GetInoutDetailGgByOrderId(refundEntity.OrderID).Tables[0].Select(" sku_id='" + refundEntity.SkuID + "'");

                    //订单的商品信息
                    var orderDetail = new OrderInfoDetail();

                    orderDetail.ItemName   = drItem["item_name"].ToString();
                    orderDetail.SalesPrice = Convert.ToDecimal(drItem["enter_price"]);
                    orderDetail.Qty        = Convert.ToInt32(drItem["enter_qty"]);
                    if (!string.IsNullOrEmpty(itemImage))
                    {
                        orderDetail.ImageUrl = ImagePathUtil.GetImagePathStr(itemImage, "240");
                    }
                    rd.OrderDetail = orderDetail;
                    //订单的商品规格
                    if (drSku.Count() > 0)
                    {
                        SkuDetailInfo skuDetail = new SkuDetailInfo();
                        skuDetail.PropName1       = drSku[0]["prop_1_name"].ToString();
                        skuDetail.PropDetailName1 = drSku[0]["prop_1_detail_name"].ToString();
                        skuDetail.PropName2       = drSku[0]["prop_2_name"].ToString();
                        skuDetail.PropDetailName2 = drSku[0]["prop_2_detail_name"].ToString();
                        skuDetail.PropName3       = drSku[0]["prop_3_name"].ToString();
                        skuDetail.PropDetailName3 = drSku[0]["prop_3_detail_name"].ToString();
                        rd.OrderDetail.SkuDetail  = skuDetail;
                    }
                }
            }
            return(rd);
        }
Beispiel #29
0
        protected override GetReceiveAmountOrderRD ProcessRequest(APIRequest <GetReceiveAmountOrderRP> pRequest)
        {
            GetReceiveAmountOrderRP rp = pRequest.Parameters;
            GetReceiveAmountOrderRD rd = new GetReceiveAmountOrderRD();
            ReceiveAmountOrderBLL   receiveAmountOrderBll = new ReceiveAmountOrderBLL(CurrentUserInfo);
            var couponUseBll = new CouponUseBLL(CurrentUserInfo);
            var couponBll    = new CouponBLL(CurrentUserInfo);
            var paymentBll   = new T_Payment_TypeBLL(CurrentUserInfo);


            //收款业务
            if (rp.Type == 1)
            {
                if (!string.IsNullOrEmpty(rp.TimeStamp))
                {
                    var receiveAmountOrderEntity = receiveAmountOrderBll.QueryByEntity(new ReceiveAmountOrderEntity()
                    {
                        TimeStamp = rp.TimeStamp
                    }, null).FirstOrDefault();
                    if (receiveAmountOrderEntity != null)
                    {
                        rd.TotalAmount   = receiveAmountOrderEntity.TotalAmount ?? 0;
                        rd.PayPoints     = receiveAmountOrderEntity.PayPoints ?? 0;
                        rd.AmountAcctPay = receiveAmountOrderEntity.AmountAcctPay ?? 0;
                        rd.PayStatus     = receiveAmountOrderEntity.PayStatus;
                        rd.VipId         = receiveAmountOrderEntity.VipId;
                        rd.TransAmount   = (receiveAmountOrderEntity.TransAmount ?? 0) - (receiveAmountOrderEntity.AmountAcctPay ?? 0);
                        rd.OrderNo       = receiveAmountOrderEntity.OrderNo;
                        rd.vipDiscount   = receiveAmountOrderEntity.VipDiscount ?? 100;
                        //优惠券使用
                        var couponUseEntity = couponUseBll.QueryByEntity(new CouponUseEntity()
                        {
                            OrderID = receiveAmountOrderEntity.OrderId.ToString()
                        }, null).FirstOrDefault();
                        if (couponUseEntity != null)
                        {
                            var couponEntity = couponBll.GetByID(couponUseEntity.CouponID);
                            if (couponEntity != null)
                            {
                                rd.CouponName = couponEntity.CoupnName;
                                var couponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                                var couponTypeEntity = couponTypeBll.GetByID(couponEntity.CouponTypeID);
                                rd.CouponAmount = couponTypeEntity.ParValue ?? 0;
                            }
                        }
                        //支付方式
                        var paymentEntity = paymentBll.GetByID(receiveAmountOrderEntity.PayTypeId);
                        if (paymentEntity != null)
                        {
                            rd.PayTypeName = paymentEntity.Payment_Type_Name;
                        }
                    }
                    else
                    {
                        throw new APIException("没有找到此订单")
                              {
                                  ErrorCode = 200
                              };
                    }
                }
                else
                {
                    //收款订单
                    if (!string.IsNullOrEmpty(rp.OrderId))
                    {
                        var receiveAmountOrderEntity = receiveAmountOrderBll.GetByID(rp.OrderId);
                        rd.TotalAmount   = receiveAmountOrderEntity.TotalAmount ?? 0;
                        rd.PayPoints     = receiveAmountOrderEntity.PayPoints ?? 0;
                        rd.AmountAcctPay = receiveAmountOrderEntity.AmountAcctPay ?? 0;
                        rd.PayStatus     = receiveAmountOrderEntity.PayStatus;
                        rd.TransAmount   = (receiveAmountOrderEntity.TransAmount ?? 0) - (receiveAmountOrderEntity.AmountAcctPay ?? 0);
                        rd.OrderNo       = receiveAmountOrderEntity.OrderNo;
                        rd.vipDiscount   = receiveAmountOrderEntity.VipDiscount ?? 100;
                        //优惠券使用
                        var couponUseEntity = couponUseBll.QueryByEntity(new CouponUseEntity()
                        {
                            OrderID = rp.OrderId
                        }, null).FirstOrDefault();
                        if (couponUseEntity != null)
                        {
                            var couponEntity = couponBll.GetByID(couponUseEntity.CouponID);
                            if (couponEntity != null)
                            {
                                rd.CouponName = couponEntity.CoupnName;
                                var couponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                                var couponTypeEntity = couponTypeBll.GetByID(couponEntity.CouponTypeID);
                                rd.CouponAmount = couponTypeEntity.ParValue ?? 0;
                            }
                        }
                        //支付方式
                        var paymentEntity = paymentBll.GetByID(receiveAmountOrderEntity.PayTypeId);
                        if (paymentEntity != null)
                        {
                            rd.PayTypeName = paymentEntity.Payment_Type_Name;
                        }
                    }
                }
            }

            //充值业务
            if (rp.Type == 2)
            {
                var rechargeOrderBll    = new RechargeOrderBLL(CurrentUserInfo);
                var rechargeOrderEntity = rechargeOrderBll.GetByID(rp.OrderId);
                if (rechargeOrderEntity != null)
                {
                    rd.PayStatus    = rechargeOrderEntity.Status.ToString();
                    rd.VipId        = rechargeOrderEntity.VipID;
                    rd.ReturnAmount = rechargeOrderEntity.ReturnAmount ?? 0;
                }
                else
                {
                    throw new APIException("没有找到此订单")
                          {
                              ErrorCode = 200
                          };
                }
            }
            //订单业务
            if (rp.Type == 3)
            {
                var inoutBll    = new T_InoutBLL(CurrentUserInfo);
                var inoutEntity = inoutBll.GetByID(rp.OrderId);
                if (inoutEntity != null)
                {
                    rd.PayStatus = inoutEntity.Field1;
                    rd.VipId     = inoutEntity.vip_no;
                }
                else
                {
                    throw new APIException("没有找到此订单")
                          {
                              ErrorCode = 200
                          };
                }
            }

            return(rd);
        }
        protected override GetSalesReturnListRD ProcessRequest(DTO.Base.APIRequest <GetSalesReturnListRP> pRequest)
        {
            var rd   = new GetSalesReturnListRD();
            var para = pRequest.Parameters;

            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var salesReturnBLL     = new T_SalesReturnBLL(loggingSessionInfo);
            var T_InoutBLL         = new T_InoutBLL(loggingSessionInfo);
            var inoutService       = new InoutService(loggingSessionInfo);
            var tInoutDetailBll    = new TInoutDetailBLL(loggingSessionInfo);

            //查询参数
            List <IWhereCondition> complexCondition = new List <IWhereCondition> {
            };

            complexCondition.Add(new EqualsCondition()
            {
                FieldName = "r.CustomerID", Value = loggingSessionInfo.ClientID
            });

            if (!string.IsNullOrEmpty(para.SalesReturnNo))
            {
                complexCondition.Add(new LikeCondition()
                {
                    FieldName = "r.SalesReturnNo", Value = "%" + para.SalesReturnNo + "%"
                });
            }
            if (para.DeliveryType > 0)
            {
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "r.DeliveryType", Value = para.DeliveryType
                });
            }
            if (para.Status > 0 && para.Status < 8)
            {
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "r.Status", Value = para.Status
                });
            }
            else if (para.Status == 8)//包含待退款和已退款
            {
                string[] statusArr = new string[] { "6", "7" };
                complexCondition.Add(new InCondition <string>()
                {
                    FieldName = "r.Status", Values = statusArr
                });
            }
            if (!string.IsNullOrEmpty(para.paymentcenterId))
            {
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "t.paymentcenter_id", Value = para.paymentcenterId
                });
            }
            if (!string.IsNullOrEmpty(para.payId))
            {
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "p.Payment_Type_Id", Value = para.payId
                });
            }
            //门店过滤处理


            //排序参数
            List <OrderBy> lstOrder = new List <OrderBy> {
            };

            lstOrder.Add(new OrderBy()
            {
                FieldName = "r.CreateTime", Direction = OrderByDirections.Desc
            });

            var tempList = salesReturnBLL.PagedQuery(complexCondition.ToArray(), lstOrder.ToArray(), para.PageSize, para.PageIndex);

            rd.TotalPageCount = tempList.PageCount;
            rd.TotalCount     = tempList.RowCount;

            List <SalesReturnInfo> salesReturnList = new List <SalesReturnInfo> {
            };
            SalesReturnInfo salesReturnInfo        = null;

            //SkuDetailInfo skuDetail = null;

            foreach (var item in tempList.Entities)
            {
                salesReturnInfo = new SalesReturnInfo();

                //根据订单ID获取订单明细[复用]
                DataRow drItem = inoutService.GetOrderDetailByOrderId(item.OrderID).Tables[0].Select(" item_id= '" + item.ItemID + "'").FirstOrDefault();
                if (drItem != null)
                {
                    //获取商品的图片[复用]
                    string  itemImage = string.Empty;
                    DataSet ds        = tInoutDetailBll.GetOrderDetailImageList("'" + item.ItemID + "'");
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        itemImage = ds.Tables[0].Rows[0]["imageUrl"].ToString();
                    }
                    //获取订单详细列表中的商品规格[复用]
                    //DataRow[] drSku = inoutService.GetInoutDetailGgByOrderId(item.OrderID).Tables[0].Select(" sku_id='" + item.SkuID + "'");

                    salesReturnInfo.SalesReturnID = item.SalesReturnID.ToString();
                    salesReturnInfo.SalesReturnNo = item.SalesReturnNo;
                    salesReturnInfo.ItemName      = drItem["item_name"].ToString();
                    salesReturnInfo.SalesPrice    = Convert.ToDecimal(drItem["enter_price"]);
                    salesReturnInfo.Qty           = item.Qty;
                    salesReturnInfo.Status        = item.Status;
                    if (!string.IsNullOrEmpty(itemImage))
                    {
                        salesReturnInfo.ImageUrl = ImagePathUtil.GetImagePathStr(itemImage, "240");
                    }
                    salesReturnInfo.VipName      = item.VipName;
                    salesReturnInfo.DeliveryType = item.DeliveryType;
                    salesReturnInfo.CreateTime   = item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm");
                    //商户单号,支付方式
                    salesReturnInfo.paymentcenterId = item.paymentcenterId;
                    salesReturnInfo.paymentName     = item.PayTypeName;
                    salesReturnInfo.ServicesType    = item.ServicesType;
                    //if (drSku.Count() > 0)
                    //{
                    //    skuDetail = new SkuDetailInfo();
                    //    skuDetail.PropName1 = drSku[0]["prop_1_name"].ToString();
                    //    skuDetail.PropDetailName1 = drSku[0]["prop_1_detail_name"].ToString();
                    //    skuDetail.PropName2 = drSku[0]["prop_2_name"].ToString();
                    //    skuDetail.PropDetailName2 = drSku[0]["prop_2_detail_name"].ToString();
                    //    skuDetail.PropName3 = drSku[0]["prop_3_name"].ToString();
                    //    skuDetail.PropDetailName3 = drSku[0]["prop_3_detail_name"].ToString();
                    //    salesReturnInfo.SkuDetail = skuDetail;
                    //
                    //}
                    salesReturnList.Add(salesReturnInfo);
                }
            }

            rd.SalesReturnList = salesReturnList.ToArray();
            rd.TotalCount      = tempList.RowCount;
            rd.TotalPageCount  = tempList.PageCount;
            return(rd);
        }