Exemplo n.º 1
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(VipIntegralDetailEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(VipIntegralDetailEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
Exemplo n.º 3
0
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public VipIntegralDetailEntity[] QueryByEntity(VipIntegralDetailEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <VipIntegralDetailEntity> PagedQueryByEntity(VipIntegralDetailEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
Exemplo n.º 5
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Update(VipIntegralDetailEntity pEntity)
 {
     _currentDAO.Update(pEntity);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(VipIntegralDetailEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
Exemplo n.º 7
0
        /// <summary>
        /// 获取个人积分列表
        /// </summary>
        /// <param name="CustomerId">商户编号</param>
        /// <param name="wherecondition">条件汇总</param>
        /// <param name="PageIndex">当前页码</param>
        /// <param name="PageSize">每页显示条数</param>
        /// <returns></returns>
        public PagedQueryResult <VipIntegralDetailEntity> GetMyIntegral(IWhereCondition[] wherecondition, int PageIndex, int PageSize)
        {
            StringBuilder pagedSql      = new StringBuilder();
            StringBuilder totalCountSql = new StringBuilder();

            pagedSql.Append(@"SELECT *
                                FROM   (
                                           SELECT ROW_NUMBER() OVER(ORDER BY L.CreateTime DESC) AS RowNumber,
                                                  S.IntegralSourceName    AS UpdateReason,
                                                  CONVERT(INT, Integral)  AS UpdateCount,
                                                  L.CreateTime            AS UpdateTime,
                                                  L.VipCardCode,
                                                   Integral
                                           FROM   VipIntegralDetail       AS L
                                                  INNER JOIN SysIntegralSource AS S
                                                       ON  S.IntegralSourceID = L.IntegralSourceID
                                           WHERE  L.IsDelete = 0 ");


            totalCountSql.Append(@"select count(1) from VipIntegralDetail       AS L
                                                  INNER JOIN SysIntegralSource AS S
                                                       ON  S.IntegralSourceID = L.IntegralSourceID
                                           WHERE  L.IsDelete = 0");

            foreach (var item in wherecondition)
            {
                pagedSql.AppendFormat(" and {0}", item.GetExpression());
                totalCountSql.AppendFormat(" and {0}", item.GetExpression());
            }
            pagedSql.Append(@" ) AS Temp
                                WHERE  Temp.RowNumber > " + (PageIndex) * PageSize + @"
                                       AND Temp.RowNumber <= " + (PageIndex + 1) * PageSize);



            PagedQueryResult <VipIntegralDetailEntity> result = new PagedQueryResult <VipIntegralDetailEntity>();
            List <VipIntegralDetailEntity>             list   = new List <VipIntegralDetailEntity>();

            using (SqlDataReader rdr = this.SQLHelper.ExecuteReader(pagedSql.ToString()))
            {
                while (rdr.Read())
                {
                    VipIntegralDetailEntity m = new VipIntegralDetailEntity();

                    if (rdr["UpdateReason"] != DBNull.Value)
                    {
                        m.UpdateReason = Convert.ToString(rdr["UpdateReason"]);
                    }

                    if (rdr["UpdateCount"] != DBNull.Value)
                    {
                        m.UpdateCount = Convert.ToInt32(rdr["UpdateCount"]);
                    }

                    if (rdr["UpdateTime"] != DBNull.Value)
                    {
                        m.UpdateTime = Convert.ToDateTime(rdr["UpdateTime"]);
                    }
                    list.Add(m);
                }
            }

            result.Entities = list.ToArray();

            int totalCount = Convert.ToInt32(this.SQLHelper.ExecuteScalar(totalCountSql.ToString()));    //计算总行数

            result.RowCount = totalCount;
            int remainder = 0;

            result.PageCount = Math.DivRem(totalCount, PageSize, out remainder);
            if (remainder > 0)
            {
                result.PageCount++;
            }

            return(result);
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 验证真伪得积分
        /// </summary>
        public string SetCheckReal()
        {
            string content  = string.Empty;
            var    respData = new SetCheckRealRespData();

            try
            {
                string openId = Request["openID"];
                //openId = "o8Y7Ejl1zl5RHXDvPONCNqoC5Md8";

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format(
                        "OpenID:{0}", openId)
                });

                var currentUser = Default.GetLoggingSession();

                VipBLL               vipBLL               = new VipBLL(currentUser);
                IntegralRuleBLL      integralRuleBLL      = new IntegralRuleBLL(currentUser);
                VipIntegralDetailBLL vipIntegralDetailBLL = new VipIntegralDetailBLL(currentUser);
                VipIntegralBLL       vipIntegralBLL       = new VipIntegralBLL(currentUser);

                string vipId = null;
                if (true)
                {
                    VipEntity vipIdData     = null;
                    var       vipIdDataList = vipBLL.QueryByEntity(new VipEntity()
                    {
                        WeiXinUserId = openId
                    }, null);
                    if (vipIdDataList == null || vipIdDataList.Length == 0 || vipIdDataList[0] == null ||
                        vipIdDataList[0].VIPID == null)
                    {
                        respData.Code        = "103";
                        respData.Description = "数据库操作错误";
                        respData.Exception   = "未查询到Vip会员";
                        return(respData.ToJSON());
                    }
                    else
                    {
                        vipIdData = vipIdDataList[0];
                        vipId     = vipIdData.VIPID;
                    }
                }

                // SysIntegralSource: 10
                string integralSourceId = "10";
                int    integralValue    = 0;
                if (true)
                {
                    IntegralRuleEntity integralRuleData = null;
                    var integralRuleDataList            = integralRuleBLL.QueryByEntity(new IntegralRuleEntity()
                    {
                        IntegralSourceID = integralSourceId
                    }, null);
                    if (integralRuleDataList == null || integralRuleDataList.Length == 0 || integralRuleDataList[0] == null)
                    {
                        respData.Code        = "103";
                        respData.Description = "数据库操作错误";
                        respData.Exception   = "未查询到积分规则";
                        return(respData.ToJSON());
                    }
                    else
                    {
                        integralRuleData = integralRuleDataList[0];
                        integralValue    = int.Parse(integralRuleData.Integral);
                    }
                }

                #region 保存积分
                if (true)
                {
                    string tmpVipId            = vipId;
                    int    tmpIntegralValue    = integralValue;
                    string tmpIntegralSourceId = integralSourceId;
                    string tmpOpenId           = openId;
                    string msgModel            = "【验真品,送积分】活动,您本次验证赢得{0}点积分。您当前的总积分是{1}点。";

                    // 插入积分明细
                    VipIntegralDetailEntity vipIntegralDetailEntity = new VipIntegralDetailEntity();
                    vipIntegralDetailEntity.VipIntegralDetailID = CPOS.Common.Utils.NewGuid();
                    vipIntegralDetailEntity.VIPID            = tmpVipId;
                    vipIntegralDetailEntity.FromVipID        = tmpVipId;
                    vipIntegralDetailEntity.SalesAmount      = 0;
                    vipIntegralDetailEntity.Integral         = tmpIntegralValue;
                    vipIntegralDetailEntity.IntegralSourceID = tmpIntegralSourceId;
                    vipIntegralDetailEntity.IsAdd            = 1;
                    //vipIntegralDetailBLL.Create(vipIntegralDetailEntity);

                    // 更新积分
                    VipIntegralEntity vipIntegralEntity = new VipIntegralEntity();
                    var vipIntegralDataList             = vipIntegralBLL.QueryByEntity(
                        new VipIntegralEntity()
                    {
                        VipID = vipId
                    }, null);
                    if (vipIntegralDataList == null || vipIntegralDataList.Length == 0 || vipIntegralDataList[0] == null)
                    {
                        vipIntegralEntity.VipID           = tmpVipId;
                        vipIntegralEntity.BeginIntegral   = 0;                // 期初积分
                        vipIntegralEntity.InIntegral      = tmpIntegralValue; // 增加积分
                        vipIntegralEntity.OutIntegral     = 0;                //消费积分
                        vipIntegralEntity.EndIntegral     = tmpIntegralValue; //积分余额
                        vipIntegralEntity.InvalidIntegral = 0;                // 累计失效积分
                        vipIntegralEntity.ValidIntegral   = tmpIntegralValue; // 当前有效积分
                        //vipIntegralBLL.Create(vipIntegralEntity);
                    }
                    else
                    {
                        vipIntegralEntity.VipID      = tmpVipId;
                        vipIntegralEntity.InIntegral = vipIntegralDataList[0].InIntegral + tmpIntegralValue;;      // 增加积分
                        //vipIntegralEntity.OutIntegral = 0; //消费积分
                        vipIntegralEntity.EndIntegral = vipIntegralDataList[0].EndIntegral + tmpIntegralValue;     //积分余额
                        //vipIntegralEntity.InvalidIntegral = 0; // 累计失效积分
                        vipIntegralEntity.ValidIntegral = vipIntegralDataList[0].ValidIntegral + tmpIntegralValue; // 当前有效积分
                        //vipIntegralBLL.Update(vipIntegralEntity, false);
                    }

                    // 更新VIP
                    VipEntity vipEntity         = new VipEntity();
                    var       vipEntityDataList = vipBLL.QueryByEntity(
                        new VipEntity()
                    {
                        VIPID = tmpVipId
                    }, null);
                    if (vipEntityDataList == null || vipEntityDataList.Length == 0 || vipEntityDataList[0] == null)
                    {
                        vipEntity.VIPID       = tmpVipId;
                        vipEntity.Integration = vipIntegralEntity.ValidIntegral;
                        //vipEntity.HigherVipID = highOpenId;
                        vipEntity.ClientID = currentUser.CurrentUser.customer_id;
                        vipEntity.Status   = 1;
                        vipBLL.Create(vipEntity);
                    }
                    else
                    {
                        vipEntity.VIPID       = tmpVipId;
                        vipEntity.Integration = vipIntegralEntity.ValidIntegral;
                        //vipEntity.HigherVipID = highOpenId;
                        vipEntity.ClientID = currentUser.CurrentUser.customer_id;
                        vipBLL.Update(vipEntity, false);
                    }

                    // 推送消息
                    string msgUrl  = ConfigurationManager.AppSettings["push_weixin_msg_url"].Trim();
                    string msgText = string.Format(msgModel, tmpIntegralValue, vipEntity.Integration);
                    string msgData = "<xml><OpenID><![CDATA[" + tmpOpenId + "]]></OpenID><Content><![CDATA[" + msgText + "]]></Content></xml>";

                    var msgResult = Common.Utils.GetRemoteData(msgUrl, "POST", msgData);
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = string.Format("PushMsgResult:{0}", msgResult)
                    });

                    respData.Data = tmpIntegralValue.ToString();
                }
                #endregion
            }
            catch (Exception ex)
            {
                respData.Code        = "103";
                respData.Description = "数据库操作错误";
                respData.Exception   = ex.ToString();
            }
            content = respData.ToJSON();
            return(content);
        }
Exemplo n.º 10
0
 /// <summary>
 /// GetVipIntegralDetailListCount
 /// </summary>
 /// <param name="entity">entity</param>
 public int GetVipIntegralDetailListCount(VipIntegralDetailEntity entity)
 {
     return(_currentDAO.GetVipIntegralDetailListCount(entity));
 }
Exemplo n.º 11
0
        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);
        }