Esempio n. 1
0
 public void Fill(System.Data.IDataReader dr)
 {
     _couponID             = Convert.ToInt32(dr["CouponID"]);
     _portalID             = Convert.ToInt32(dr["PortalID"]);
     _code                 = Convert.ToString(dr["Code"]);
     _description          = Convert.ToString(dr["Description"]);
     _ruleType             = (CouponRule)(dr["RuleType"]);
     _ruleAmount           = Convert.ToDecimal(Null.SetNull(dr["RuleAmount"], _ruleAmount));
     _discountType         = (CouponDiscount)(dr["DiscountType"]);
     _discountPercentage   = Convert.ToInt32((Null.SetNull(dr["DiscountPercentage"], _discountPercentage)));
     _discountAmount       = Convert.ToDecimal((Null.SetNull(dr["DiscountAmount"], _discountAmount)));
     _applyTo              = (CouponApplyTo)(dr["ApplyTo"]);
     _itemID               = Convert.ToInt32(Null.SetNull(dr["ItemID"], _itemID));
     _includeSubCategories = Convert.ToBoolean(Null.SetNull(dr["IncludeSubCategories"], _includeSubCategories));
     _startDate            = Convert.ToDateTime(dr["StartDate"]);
     _endDate              = Convert.ToDateTime(dr["EndDate"]);
     _validity             = (CouponValidity)(dr["Validity"]);
     _createdByUserID      = Convert.ToInt32(dr["CreatedByUserID"]);
     _createdDate          = Convert.ToDateTime(dr["CreatedDate"]);
 }
Esempio n. 2
0
        public void CouponRule_CalculatePrice_WhenOrderIsFromCouponHolderCustomer_ShoulldReturnAppropriateValue()
        {
            var rule = new CouponRule(_customerRepo.Object);

            _customerRepo.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(new Customer
            {
                Id             = Guid.Parse("b4300366-25e6-406f-adf2-d97cc7c75dcb"),
                Name           = "Ashay",
                Rating         = 5,
                IsCouponHolder = true
            });
            var order = new Order
            {
                CustomerId   = Guid.Parse("b4300366-25e6-406f-adf2-d97cc7c75dcb"),
                FloorNumber  = 6,
                DeliveryDate = new DateTime(2018, 11, 18)
            };

            rule.CalculatePrice(order);

            Assert.AreEqual(799.2, order.Price);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取优惠券
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public MEMBER_COUPON GetCoupon(string account_id)
        {
            MEMBER_COUPON          coupon = new MEMBER_COUPON();
            dt_Dyn_PosCpSearch_req reqs   = new dt_Dyn_PosCpSearch_req();

            reqs.ACCOUNT_ID  = account_id;                //会员账号和MOB_NUMBER至少输入一个
            reqs.DATA_SOURCE = "0000";                    //0002为 佰草集

            reqs.LOYALTY_BRAND = AppConfig.LOYALTY_BRAND; //忠诚度品牌
            reqs.SOURCE_SYSTEM = AppConfig.SOURCE_SYSTEM; //来源系统
            reqs.VGROUP        = AppConfig.VGROUP;        //销售组织

            dt_Dyn_PosCpSearch_res resok = WebApiHelp.PosCpSearch(reqs);
            //已使用
            List <COUPONS> shiyong = new List <COUPONS>();

            //未使用
            List <COUPONS> meiyou = new List <COUPONS>();

            //已过期
            List <COUPONS> guoqi = new List <COUPONS>();

            if (resok != null)
            {
                if (resok.ZTYPE != "Y")
                {
                    return(null);
                }



                if (resok.ZPARTERN_CP2.Count() > 0)
                {
                    foreach (ZPARTERN_CP2 item in resok.ZPARTERN_CP2)
                    {
                        //查询另外一个集合的数据
                        dt_Dyn_PosCpSearch_resITEM resout = resok.ZCPQ_RESULT.Where(a => a.ZCP_NUM == item.ZCP_NUM).
                                                            ToList().FirstOrDefault();


                        string QrCode = resout.ZCP_PASSW + ".jpg";

                        GenerateCode(resout.ZCP_PASSW);


                        //RULE = {"type":"DJQ","value":"100"}  这个就解析成100元代金券
                        //RULE = {"type":"ZKQ","value":"5"} 解析成 5者折扣券
                        string RULE = "";
                        if (!string.IsNullOrWhiteSpace(resout.RULE))
                        {
                            CouponRule CouponRule = JsonHelper.DeserializeObject <CouponRule>(resout.RULE);
                            if (CouponRule != null)
                            {
                                if (CouponRule.type == "DJQ")
                                {
                                    RULE = CouponRule.value;
                                }
                                else if (CouponRule.type == "ZKQ")
                                {
                                    RULE = CouponRule.value;
                                }
                            }
                        }
                        COUPONS one = new COUPONS()
                        {
                            BPEXT        = item.BPEXT,
                            ZCP_EDATE    = resout.ZCP_EDATE,
                            ZCP_EDATE_EX = resout.ZCP_EDATE,
                            ZCP_JE       = resout.ZCP_JE,
                            ZCP_POINT    = resout.ZCP_POINT,
                            ZCP_PROD     = resout.ZCP_PROD,
                            ZCP_TYPE     = item.ZCP_TYPE,
                            ZCP_YHQDES   = resout.ZCP_YHQDES,
                            ZCP_ZK       = resout.ZCP_ZK,
                            ZCP_NUM      = resout.ZCP_NUM,
                            ZCP_YHQ      = resout.ZCP_YHQ,
                            ZCP_BDATE    = resout.ZCP_BDATE,
                            ZCP_PASSW    = resout.ZCP_PASSW,
                            IS_BOOK      = 0,
                            QrCode       = AppConfig.HmjWebApi_https + "/QrCode/" + QrCode,
                            CONTENT      = resout.CONTENT,
                            RULE         = RULE,
                            ZCP_USE_FLAG = item.ZCP_USE_FLAG
                        };

                        one.ZCPUDATE = item.ZCPUDATE;


                        //已使用
                        if (item.ZCP_USE_FLAG == "X")
                        {
                            shiyong.Add(one);
                        }

                        //未使用
                        if (string.IsNullOrEmpty(item.ZCP_USE_FLAG) || item.ZCP_USE_FLAG == "N") //item.ZCP_USE_FLAG="N" 未使用未激活
                        {
                            DateTime endTime = one.ZCP_EDATE;
                            if (endTime >= DateTime.Parse(DateTime.Now.ToShortDateString()))
                            {
                                //BCJ_BOOK_EX book = _book.GetBookByNo(one.ZCP_NUM);

                                //if (book != null)
                                //{
                                //    if (book.STATUS == 1)
                                //    {
                                //        shiyong.Add(one);
                                //    }
                                //    else if (book.STATUS == 0)
                                //    {
                                //        one.IS_BOOK = 1;
                                //        meiyou.Add(one);
                                //    }
                                //}
                                //else
                                //{
                                //    meiyou.Add(one);
                                //}
                                meiyou.Add(one);
                            }
                            else
                            {
                                guoqi.Add(one);
                            }
                        }
                    }
                }
            }
            coupon.ALREADY_USE = shiyong.OrderByDescending(a => a.ZCPUDATE).ToList();
            coupon.NOT_USE     = meiyou.OrderBy(a => a.ZCP_EDATE_EX).ToList();
            coupon.OBSOLETE    = guoqi.OrderByDescending(a => a.ZCP_EDATE_EX).ToList();
            return(coupon);
        }
        /// <summary>
        /// 根据礼包
        /// </summary>
        /// <param name="pkid"></param>
        /// <returns></returns>
        public async Task <IEnumerable <CouponRule> > GetCouponRuleItems(int pkid, DateTime logDateTime)
        {
            List <Guid> guids = new List <Guid>();

            foreach (var item in this.entity.ItemPools)
            {
                if (item?.PartItem?.Where(_ => _.PKID == pkid)?.Count() > 0)
                {
                    foreach (var coupon in item?.PartItem?.Where(_ => _.PKID == pkid)?.FirstOrDefault()?.PartItem)
                    {
                        if (!string.IsNullOrWhiteSpace(coupon.CouponGuid))
                        {
                            guids.Add(Guid.Parse(coupon.CouponGuid));
                        }
                    }

                    break;
                }
            }
            if (guids.Count > 0)
            {
                using (var client = new Tuhu.Service.Member.PromotionClient())
                {
                    var result = await client.GetCouponRulesAsync(guids);

                    result.ThrowIfException(true);
                    List <CouponRule> list = new List <CouponRule>();
                    foreach (var _ in result?.Result)
                    {
                        var model = new CouponRule()
                        {
                            DeadLineDate   = _.DeadLineDate,
                            Description    = _.Description,
                            Discount       = _.Discount,
                            MinMoney       = _.MinMoney,
                            PromotionName  = _.PromotionName,
                            Term           = _.Term,
                            ValiEndDate    = _.ValiEndDate,
                            ValiStartDate  = _.ValiStartDate,
                            CreateDateTime = logDateTime,
                        };
                        model.DateNumber = model.GetDateNumber();
                        #region 设置优惠券使用状态
                        if (this.PromotionCodes != null && this.PromotionCodes?.Length > 0)
                        {
                            using (var promotionClient = new Tuhu.Service.Member.PromotionClient())
                            {
                                var resultPromotion = await promotionClient.GetPromotionCodeForUserCenterAsync(new GetPromotionCodeRequest()
                                {
                                    UserID = this.UserId,
                                    Type   = PromotionStatus.AlreadyUsed
                                }, new Tuhu.Models.PagerModel()
                                {
                                    PageSize = 50
                                });

                                if (resultPromotion.Success && resultPromotion?.Result?.Where(p => p.Pkid == Convert.ToInt64(this.PromotionCodes[0].Split(',')[0]))?.Count() > 0)
                                {
                                    model.DateNumber = -2;
                                }
                            }
                        }
                        #endregion
                        list.Add(model);
                    }

                    return(list);
                }
            }
            else
            {
                return(null);
            }
        }