Пример #1
0
        private T_Inout_DetailEntity ConvertToT_InoutDetial(string orderid, OrderDetail detail)
        {
            var result = new T_Inout_DetailEntity
            {
                order_detail_id = detail.OrderDetailId,
                order_id        = orderid,
                sku_id          = detail.SKUID,
                unit_id         = detail.UnitId,
                order_qty       = detail.OrderQty,
                enter_qty       = detail.EnterQty,
                enter_price     = detail.EnterPrice,
                enter_amount    = detail.EnterAmount,
                std_price       = detail.StdPrice,
                retail_price    = detail.RetailPrice,
                retail_amount   = detail.RetailAmount,
                plan_price      = detail.PlanPrice,
                receive_points  = detail.ReceiverPoints,
                pay_points      = detail.PayPoints,
                remark          = detail.Remark,
                pos_order_code  = detail.PosOrderCode,
                display_index   = detail.DisplayIndex,
                create_time     = detail.CreateTime,
                create_user_id  = detail.CreateUserId,
                modify_time     = detail.ModifyTime,
                modify_user_id  = detail.ModifyUser,
                ReturnCash      = detail.ReturnCash ?? 0.00m
            };

            return(result);
        }
Пример #2
0
 internal void Delete(T_Inout_DetailEntity dbEntity)
 {
     using (var conn = new SqlConnection(ConnectionString.XgxInsert))
     {
         conn.Open();
         conn.Delete(dbEntity);
     }
 }
Пример #3
0
        internal void Update(T_Inout_DetailEntity dbEntity)
        {
            using (var conn = new SqlConnection(ConnectionString.XgxInsert))
            {
                dbEntity.modify_time = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                conn.Open();
                conn.Update(dbEntity);
            }
        }
Пример #4
0
        /// <summary>
        /// 支付回调/收款处理虚拟商品订单
        /// </summary>
        public void SetVirtualItem(LoggingSessionInfo loggingSessionInfo, string orderId)
        {
            var inoutBLL  = new T_InoutBLL(loggingSessionInfo);
            var inoutInfo = this._currentDAO.GetByID(orderId);

            if (inoutInfo != null)
            {
                //如果是经销商订单,付款完成后,订单状态修改成完成状态
                if (inoutInfo.data_from_id == "21")
                {
                    inoutInfo.Field7 = "700";
                    inoutInfo.status = "700";
                    inoutBLL.Update(inoutInfo);
                    InoutService inoutService = new InoutService(loggingSessionInfo);
                    T_VirtualItemTypeSettingBLL virtualItemTypeSettingBLL = new T_VirtualItemTypeSettingBLL(loggingSessionInfo);
                    VipCardVipMappingBLL        vipCardVipMappingBLL      = new VipCardVipMappingBLL(loggingSessionInfo);
                    T_Inout_DetailBLL           inoutDetailBLL            = new T_Inout_DetailBLL(loggingSessionInfo);
                    var    VipBLL      = new VipBLL(loggingSessionInfo);
                    var    inoutDetail = inoutService.GetInoutDetailInfoByOrderId(orderId).FirstOrDefault();
                    string itemId      = inoutDetail.item_id;

                    var virtualItemTypeSettingInfo = virtualItemTypeSettingBLL.QueryByEntity(new T_VirtualItemTypeSettingEntity()
                    {
                        ItemId = itemId
                    }, null).FirstOrDefault();
                    if (virtualItemTypeSettingInfo != null)
                    {
                        int    objectTypeId = int.Parse(virtualItemTypeSettingInfo.ObjecetTypeId);
                        string objectNo     = vipCardVipMappingBLL.BindVirtualItem(inoutInfo.vip_no, inoutInfo.VipCardCode, "", objectTypeId);
                        //将卡/券的编号保存到订单明细
                        T_Inout_DetailEntity inoutDetailEntity = inoutDetailBLL.GetByID(inoutDetail.order_detail_id);
                        if (inoutDetailEntity != null)
                        {
                            inoutDetailEntity.Field10 = objectNo;
                            inoutDetailBLL.Update(inoutDetailEntity);
                        }
                    }
                    //将Col48至为1
                    var VipData = VipBLL.GetByID(inoutInfo.vip_no);
                    if (VipData != null)
                    {
                        VipData.Col48 = "1";
                        VipBLL.Update(VipData);
                    }
                    // 判断客户是否是符合潜在经销商条件
                    var isCan = VipBLL.IsSetVipDealer(inoutInfo.vip_no);

                    if (isCan)
                    {
                        new RetailTraderBLL(loggingSessionInfo).CreatePrepRetailTrader(loggingSessionInfo, inoutInfo.vip_no); // 创建潜在经销商
                    }
                }
            }
        }
Пример #5
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(T_Inout_DetailEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
Пример #6
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(T_Inout_DetailEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
Пример #7
0
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <T_Inout_DetailEntity> PagedQueryByEntity(T_Inout_DetailEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
Пример #8
0
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public T_Inout_DetailEntity[] QueryByEntity(T_Inout_DetailEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
Пример #9
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(T_Inout_DetailEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
Пример #10
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Update(T_Inout_DetailEntity pEntity)
 {
     _currentDAO.Update(pEntity);
 }
Пример #11
0
 public void Delete(T_Inout_DetailEntity dbEntity)
 {
     _cmd.Delete(dbEntity);
 }
Пример #12
0
 public void Update(T_Inout_DetailEntity dbEntity)
 {
     _cmd.Update(dbEntity);
 }
Пример #13
0
 public void Create(T_Inout_DetailEntity dbEntity)
 {
     _cmd.Create(dbEntity);
 }
Пример #14
0
        public string SetOrderInfo(SetOrderInfoReqPara para)
        {
            var loggingSessionInfo = this.CurrentUserInfo as LoggingSessionInfo;
            //获取订单号
            TUnitExpandBLL serviceUnitExpand = new TUnitExpandBLL(loggingSessionInfo);
            string         OrderCode         = serviceUnitExpand.GetUnitOrderNo();

            ////如果StoreID为空,是在线商城订单,重复的逻辑
            //if (string.IsNullOrEmpty(para.storeId.Trim()))
            //{
            //    UnitService unitServer = new UnitService(loggingSessionInfo);
            //    para.storeId = unitServer.GetUnitByUnitType("OnlineShopping", null).Id; //获取在线商城的门店标识
            //}

            //判断活动的有效性

            #region 活动有效性


            decimal salesPrice = 0;                         //活动销售价
            decimal qty        = Convert.ToInt32(para.qty); //所购数量
            //砍价活动
            if (para.isBargain == "1")
            {
                var eventBll = new PanicbuyingEventBLL(loggingSessionInfo);
                var detail   = eventBll.GetKJEventWithSkuDetail(para.eventId.ToString(), para.orderDetailList[0].skuId.ToString());
                if (detail == null)
                {
                    throw new Exception("未找到相关活动商品信息");
                }
                //1.需要判断,该订单的商品是否还有盈余
                if (detail.RemainingQty <= 0)
                {
                    throw new Exception("活动商品数量不足,当前数量:0");
                }
                //2.判断,该商品活动是否已经终止
                if (!string.IsNullOrEmpty(detail.StopReason))
                {
                    throw new Exception("活动已停止,停止原因:" + detail.StopReason);
                }
                //3.判断购买个数是否小于等于剩余个数
                if (int.Parse(para.qty) > detail.RemainingQty)
                {
                    throw new Exception("活动商品数量不足,当前数量:" + detail.RemainingQty);
                }

                //获取当前会员购买个数
                if (detail.SinglePurchaseQty > 0)//限购
                {
                    List <IWhereCondition> buyCondition = new List <IWhereCondition> {
                    };
                    buyCondition.Add(new EqualsCondition()
                    {
                        FieldName = "VipId", Value = para.userId
                    });
                    buyCondition.Add(new EqualsCondition()
                    {
                        FieldName = "itemId", Value = detail.ItemId
                    });
                    //修改为商品与活动都筛选 xiaowen.qin 2016.5.21
                    buyCondition.Add(new EqualsCondition()
                    {
                        FieldName = "EventId", Value = para.eventId
                    });
                    buyCondition.Add(new DirectCondition(" EventOrderMappingId IS NOT NULL "));
                    var panicbuyingKJEventJoinBLL = new PanicbuyingKJEventJoinBLL(loggingSessionInfo);
                    int buyCount = panicbuyingKJEventJoinBLL.Query(buyCondition.ToArray(), null).Count();
                    if (buyCount + int.Parse(para.qty) > detail.SinglePurchaseQty)
                    {
                        throw new Exception("限购" + detail.SinglePurchaseQty + "件,你还能购买" + (detail.SinglePurchaseQty - buyCount) + "件,请修改购买数量");
                    }
                }
            }
            else //团购抢购
            {
                var eventBll = new vwItemPEventDetailBLL(loggingSessionInfo);
                var detail   = eventBll.GetByEventIDAndSkuID(para.eventId, para.orderDetailList[0].skuId.ToString());
                salesPrice       = detail.SalesPrice ?? 0;        //团购抢购销售价
                para.totalAmount = (salesPrice * qty).ToString(); //团购抢购总金额
                if (detail == null)
                {
                    throw new Exception("未找到相关活动商品信息");
                }
                //1.需要判断,该订单的商品是否还有盈余
                if (detail.RemainingQty <= 0)
                {
                    throw new Exception("活动商品数量不足,当前数量:0");
                }
                //2.判断,该商品活动是否已经终止
                if (!string.IsNullOrEmpty(detail.StopReason))
                {
                    throw new Exception("活动已停止,停止原因:" + detail.StopReason);
                }
                //3.判断购买个数是否小于等于剩余个数
                if (int.Parse(para.qty) > detail.RemainingQty)
                {
                    throw new Exception("活动商品数量不足,当前数量:" + detail.RemainingQty);
                }
            }

            if (string.IsNullOrEmpty(para.userId))
            {
                throw new Exception("会员信息不存在");
            }

            #endregion

            //订单类型

            #region 根据订单参数设置订单类型

            string order_reason_id = string.Empty;
            if (para.isGroupBy == "1") //团购
            {
                order_reason_id = "CB43DD7DD1C94853BE98C4396738E00C";
            }
            else if (para.isPanicbuying == "1") //抢购
            {
                order_reason_id = "671E724C85B847BDA1E96E0E5A62055A";
            }
            else if (para.isBargain == "1") //砍价
            {
                order_reason_id = "096419BFDF394F7FABFE0DFCA909537F";
            }
            else //普通
            {
                order_reason_id = "2F6891A2194A4BBAB6F17B4C99A6C6F5";
            }

            #endregion

            //创建事务
            var tran    = this._currentDAO.GetTran();
            var orderId = string.Empty;
            try
            {
                using (tran.Connection)
                {
                    T_InoutEntity entity = new T_InoutEntity()
                    {
                        #region 订单初始化
                        order_date       = DateTime.Now.ToString("yyyy-MM-dd"),
                        order_type_id    = "1F0A100C42484454BAEA211D4C14B80F",
                        create_time      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        customer_id      = para.customerId,
                        status           = "1",
                        total_qty        = Convert.ToDecimal(para.qty),
                        unit_id          = para.storeId,
                        order_no         = OrderCode,
                        order_id         = Guid.NewGuid().ToString("N"),
                        order_reason_id  = order_reason_id,                    //订单类型:普通,团购,抢购
                        red_flag         = "1",
                        warehouse_id     = "67bb4c12785c42d4912aff7d34606592", //???是否是这个??
                        create_unit_id   = para.storeId,
                        create_user_id   = para.userId,
                        total_amount     = Convert.ToDecimal(para.totalAmount),
                        actual_amount    = Convert.ToDecimal(para.actualAmount),
                        discount_rate    = para.Rate,
                        total_retail     = Convert.ToDecimal(para.totalAmount),
                        print_times      = Convert.ToInt32(para.joinNo),
                        vip_no           = para.userId,
                        data_from_id     = para.reqBy,
                        if_flag          = "0",
                        remark           = para.remark,
                        Field1           = "0",
                        Field3           = para.isALD,
                        Field7           = "-99",
                        Field8           = para.deliveryId,
                        send_time        = para.deliveryTime,
                        Field9           = para.deliveryTime,
                        Field4           = para.deliveryAddress,
                        Field6           = para.mobile,
                        Field12          = para.email,
                        Field13          = para.openId,
                        Field10          = "未审核",
                        Field14          = para.username,
                        Field20          = para.tableNumber,
                        Field16          = para.couponsPrompt,
                        Field15          = order_reason_id,
                        sales_unit_id    = para.storeId,
                        purchase_unit_id = para.storeId
                                           #endregion
                    };
                    //订单状态
                    if (loggingSessionInfo.CurrentLoggingManager.IsApprove == null ||
                        loggingSessionInfo.CurrentLoggingManager.IsApprove.Equals("0"))
                    {
                        entity.status      = "100";
                        entity.status_desc = "未审批";
                    }
                    //创建订单
                    this._currentDAO.Create(entity, tran);
                    orderId = entity.order_id;
                    //创建订单明细

                    #region 订单明细列表

                    var detailbll = new T_Inout_DetailBLL(loggingSessionInfo);
                    foreach (var item in para.orderDetailList)
                    {
                        var detailEntity = new T_Inout_DetailEntity()
                        {
                            create_time         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            create_user_id      = para.userId,
                            modify_time         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            modify_user_id      = para.userId,
                            unit_id             = para.storeId,
                            discount_rate       = para.Rate,
                            std_price           = Convert.ToDecimal(item.salesPrice),
                            enter_price         = Convert.ToDecimal(item.salesPrice),
                            sku_id              = item.skuId,
                            enter_qty           = Convert.ToDecimal(para.qty),
                            order_id            = entity.order_id,
                            order_detail_id     = Guid.NewGuid().ToString("N"),
                            order_qty           = entity.total_qty,
                            enter_amount        = item.Amount,
                            order_detail_status = "1",
                            retail_amount       = item.Amount,
                            retail_price        = item.Amount,
                            display_index       = 1,
                            if_flag             = 0
                        };
                        detailbll.Create(detailEntity, tran);
                    }

                    #endregion

                    //下订单,修改抢购商品的数量信息存储过程ProcPEventItemQty
                    //var eventbll = new vwItemPEventDetailBLL(loggingSessionInfo);
                    //eventbll.ExecProcPEventItemQty(para, entity, tran);
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            //
            return(orderId);
        }
Пример #15
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);
        }
    }
}
Пример #16
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);
        }