Esempio n. 1
0
 /// <summary>
 /// 根据原优惠券,创建新优惠券,并且插入日志
 /// </summary>
 /// <param name="promotionId"></param>
 /// <param name="operation"></param>
 /// <returns></returns>
 private string CreateNewPromotionByOldPromotion(int promotionId, string operation = "部分取消")
 {
     if (promotionId > 0)
     {
         var oldPromotionCode = dbManager.Execute(connection => DalPromotionJob.FetchPromotionCodeByPromotionCode(connection, promotionId));
         oldPromotionCode.RuleName = oldPromotionCode.PromtionName;
         if (oldPromotionCode != null)
         {
             oldPromotionCode.Status      = 0;
             oldPromotionCode.CodeChannel = oldPromotionCode.CodeChannel + "(取消订单)";
             CreatePromotionModel createPromotionModel = new CreatePromotionModel()
             {
                 Author        = ThreadIdentity.Operator.Name,
                 Channel       = "取消订单",
                 Operation     = "原优惠券生成新优惠券",
                 PromotionPKID = oldPromotionCode.PkId
             };
             using (var client = new PromotionClient())
             {
                 var result = client.CopyPromotionCode(createPromotionModel);
                 if (result.Success)
                 {
                     new OprLogManager().AddOprLog <BizPromotionCode>("Order", oldPromotionCode.OrderId, operation + "原优惠券不释放,生成一张一样的优惠券,优惠券PKID:" + result.Result, null, null);
                 }
                 else
                 {
                     throw new Exception("根据原优惠券生成新优惠券失败,订单号:" + oldPromotionCode.OrderId);
                 }
             }
             //var newPromotionCode = dbManager.Execute(connection => DalPromotionJob.CreatePromotionCode(connection, oldPromotionCode));
             //new OprLogManager().AddOprLog<BizPromotionCode>("Order", oldPromotionCode.OrderId, operation + "原优惠券不释放,生成一张一样的优惠券,优惠券PKID:" + newPromotionCode, null, null);
         }
     }
     return(string.Empty);
 }
Esempio n. 2
0
        /// <summary>
        /// 获取当前批次相关信息及对应套餐配置
        /// </summary>
        /// <param name="batchCode"></param>
        /// <returns></returns>
        public VipPaintPackageConfigForDetail GetPromotionConfigForDetail(string batchCode)
        {
            var result = null as VipPaintPackageConfigForDetail;

            try
            {
                result = dbScopeManagerConfigurationRead.Execute(conn =>
                                                                 DalVipPaintPackage.GetPackageConfigByBatchCode(conn, batchCode));
                if (result != null)
                {
                    using (var client = new PromotionClient())
                    {
                        var clientResult = client.GetCouponRule(result.RuleGUID);
                        clientResult.ThrowIfException(true);
                        if (clientResult.Result != null)
                        {
                            result.RuleId        = clientResult.Result.RuleID;
                            result.PromotionName = clientResult.Result.PromotionName;
                            result.Description   = clientResult.Result.Description;
                        }
                    }
                    result.VipUserName = new VipBaoYangPackageManager().GetAllBaoYangPackageUser()
                                         ?.FirstOrDefault(s => string.Equals(s.VipUserId, result.VipUserId.ToString()))?.VipUserName;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetPromotionConfigForDetail", ex);
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 调用服务,查询优惠券
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public PromotionCodeModel FetchPromotionCodeByOrderIdForService(int orderId)
        {
            //订单取消,不释放优惠券
            using (var client = new PromotionClient())
            {
                var result = client.FetchPromotionCodeByOrderId(orderId);

                if (!result.Success)
                {
                    throw result.Exception;
                }
                return(result.Result);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 释放优惠券券(根据优惠券PKID),清空订单的PromotionMoney,清空OrderList PromotionCode.PromotionMoney
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="codePkid"></param>
        public void ReleasePromtionByPromotionId(int orderId, int codePkid)
        {
            using (var client = new PromotionClient())
            {
                var result = client.ReleasePromtionByOrderId(orderId, ThreadIdentity.Operator.Name);
                if (!result.Success)
                {
                    ExceptionMonitor.AddNewMonitor("Order", orderId.ToString(), result.Exception.ToString(),
                                                   ThreadIdentity.Operator.Name, "调用ReleasePromtionByPromotionId方法报错", MonitorLevel.Critial, MonitorModule.Order);
                }
            }

            new OprLogManager().AddOprLog("Order", orderId, codePkid + "已使用", codePkid + "未使用", "释放优惠卷,优惠券PKID为:" + codePkid);
        }
Esempio n. 5
0
        /// <summary>
        /// 根据车品的oid 获取 所有可用的优惠券
        /// </summary>
        /// <param name="price"></param>
        /// <returns></returns>
        private async Task <List <PromotionCouponRulesModel> > SelectProductPromotionGetRuleByOidsAsyn(CarProductPriceModel _CarProductPriceModel)
        {
            List <PromotionCouponRulesModel> models = new List <PromotionCouponRulesModel>();

            using (PromotionClient client = new PromotionClient())
            {
                OperationResult <IEnumerable <PromotionCouponRulesModel> > res = await client.SelectPromotionCouponRulesByProducrIDAsync(new string[] { _CarProductPriceModel.PID }, null);

                if (res.Success)
                {
                    models = res.Result.ToList();
                }
                return(models);
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     创建优惠券
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static async Task <OperationResult <CreatePromotionCodeResult> > CreatePromotionNewAsync(
            CreatePromotionModel model)
        {
            using (var client = new PromotionClient())
            {
                var result = await client.CreatePromotionNewAsync(model);

                if (!result.Success)
                {
                    Logger.Error(
                        $"PromotionClient CreatePromotionNewAsync fail => ErrorCode ={result.ErrorCode} & ErrorMessage ={result.ErrorMessage} ");
                }

                return(result);
            }
        }
        public async Task <JsonResult> CreateCoupon(Dictionary <string, List <string> > products,
                                                    InsertOrUpdateCouponRulePara parentCoupon, InsertOrUpdateGetCouponRulePara childCoupon,
                                                    List <InsertOrUpdateGetCouponRulePara> rules)
        {
            var result = new Dictionary <string, int>();

            if (rules != null && rules.Any())
            {
                using (var memClient = new PromotionClient())
                {
                    var mark = 1;
                    foreach (var rule in rules)
                    {
                        var key = rule.Minmoney + "/" + rule.Discount;
                        if (products.ContainsKey(key) && products[key].Any())
                        {
                            parentCoupon.ProductID = products[key];
                            if (rules.Count > 1)
                            {
                                parentCoupon.Name += "-" + mark;
                            }
                            var createParentResult = await memClient.InsertOrUpdateCouponRulesAsync(parentCoupon);

                            var ruleId = createParentResult.Success ? createParentResult.Result : -1;
                            if (ruleId > 0)
                            {
                                childCoupon.RuleID       = ruleId;
                                childCoupon.Minmoney     = rule.Minmoney;
                                childCoupon.Discount     = rule.Discount;
                                childCoupon.PromtionName = rule.PromtionName;
                                childCoupon.Description  = rule.Description;
                                var createChildResult = await memClient.InsertOrUpdateGetCouponRuleAsync(childCoupon);

                                var getRulePkid = createChildResult.Success ? createChildResult.Result.Item1 : -1;
                                if (getRulePkid > 0)
                                {
                                    result[rule.Minmoney + "/" + rule.Discount] = getRulePkid;
                                }
                            }
                            mark++;
                        }
                    }
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
        public List <BaoYangPackagePromotionDetailSimpleModel> GetPromotionDetailsByBatchCode(string batchCode, int index, int size)
        {
            var result = null as List <BaoYangPackagePromotionDetailSimpleModel>;

            if (!string.IsNullOrEmpty(batchCode))
            {
                try
                {
                    result = dbScopeReadManager.Execute(conn => DALVipBaoYangPackage.SelectPromotionDetailsByBatchCode(conn,
                                                                                                                       batchCode, index, size));
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message, ex);
                }
            }

            if (result != null && result.Any())
            {
                GetPromotionCodesRequest request = new GetPromotionCodesRequest()
                {
                    PKIDList = result.Where(o => o.PromotionId.HasValue && o.PromotionId.Value > 0).Select(o => (int)o.PromotionId).ToList()
                };
                using (var client = new PromotionClient())
                {
                    var serviceResult = client.GetPromotionCodeByIDs(request);
                    if (serviceResult.Success && serviceResult.Result != null)
                    {
                        foreach (var detail in result)
                        {
                            if (detail.PromotionId > 0)
                            {
                                var code = serviceResult.Result.FirstOrDefault(o => o.Pkid == detail.PromotionId);
                                detail.PromotionStatus = code != null ? code.Status : 2;
                                if (!string.IsNullOrEmpty(code.UsedTime))
                                {
                                    detail.PromotionUsedTime = DateTime.Parse(code.UsedTime);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
 public ActionResult PromotionTest(string parm, string host, int port)
 {
     try
     {
         using (var client = new PromotionClient())
         {
             client.Endpoint.Address = GetUThost(client.Endpoint.Address, host, port);
             var result = client.SelectUserPromotion(new Guid(parm));
             result.ThrowIfException();
             return(Json(result.Success ? new { Status = 1, Message = "成功" } : new { Status = 0, Message = result.Exception + result.ErrorMessage }));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { Status = 0, Message = ex.Message + ex.InnerException }));
     }
 }
Esempio n. 10
0
        public Dictionary <int, bool> InvalidCodes(List <int> codes, string user)
        {
            Dictionary <int, bool>    result         = new Dictionary <int, bool>();
            List <PromotionCodeModel> promotionCodes = new List <PromotionCodeModel>();

            using (var client = new PromotionClient())
            {
                var serviceResult = client.GetPromotionCodeByIDs(new GetPromotionCodesRequest()
                {
                    PKIDList = codes
                });
                if (serviceResult.Success)
                {
                    promotionCodes = serviceResult.Result.ToList();
                }
            }
            foreach (var code in promotionCodes)
            {
                using (var client = new PromotionClient())
                {
                    var serviceResult = client.UpdateUserPromotionCodeStatus(new UpdateUserPromotionCodeStatusRequest()
                    {
                        Status          = 3,
                        PromotionCodeId = code.Pkid,
                        OperationAuthor = user,
                        Channel         = "setting.tuhu.cn",
                        UserID          = Guid.Parse(code.UserId)
                    });
                    if (serviceResult.Exception != null)
                    {
                        logger.Error(serviceResult.Exception);
                    }
                    result[code.Pkid] = serviceResult.Success && serviceResult.Result;
                }
            }

            foreach (var item in result)
            {
                if (item.Value)
                {
                    dbScopeManager.Execute(conn => DALVipBaoYangPackage.UpdatePromotionRemarks(conn, item.Key, $"{user}于{DateTime.Now.ToString("yyyy年MM月dd日 hh:mm")}作废此券"));
                }
            }

            return(result);
        }
 public static LotteryCouponModel GetCouponDetail(Guid couponId, string productGroupId = "")
 {
     using (var client = new PromotionClient())
     {
         var result = client.GetCouponRule(couponId);
         if (result.Success && result.Result != null)
         {
             return(new LotteryCouponModel
             {
                 ProductGroupId = productGroupId,
                 CouponId = couponId,
                 CouponDesc = result.Result.Description,
                 CouponCondition = $"满{result.Result.MinMoney}减{result.Result.Discount}",
                 UsefulLife = result.Result.Term == null ? $"{result.Result.ValiStartDate}到{result.Result.ValiEndDate}" : $"自领取之后{result.Result.Term}天有效"
             });
         }
     }
     return(null);
 }
Esempio n. 12
0
        public bool IsAllUnUsed(List <int> codes)
        {
            bool result = false;
            GetPromotionCodesRequest request = new GetPromotionCodesRequest()
            {
                PKIDList = codes
            };

            using (var client = new PromotionClient())
            {
                var serviceResult = client.GetPromotionCodeByIDs(request);
                if (serviceResult.Success && serviceResult.Result != null)
                {
                    result = serviceResult.Result.All(o => o.Status == 0);
                }
            }

            return(result);
        }
        /// <summary>
        /// 更新用户优惠券使用状态(主要改为已作废)(0.未使用,1.已使用,2.已作废
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task <bool> UpdateUserPromotionCodeStatus(UpdateUserPromotionCodeStatusRequest request)
        {
            bool result = false;

            try
            {
                using (var client = new PromotionClient())
                {
                    var serviceResult = await client.UpdateUserPromotionCodeStatusAsync(request);

                    serviceResult.ThrowIfException(true);
                    result = serviceResult.Result;
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"更新优惠券状态出错,request:{JsonConvert.SerializeObject(request)}", ex);
            }

            return(result);
        }
        /// <summary>
        /// 查询优惠券
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static async Task <PromotionCodeModel> FetchPromotionByPromotionCode(string promotionId)
        {
            PromotionCodeModel result = null;

            try
            {
                using (var client = new PromotionClient())
                {
                    var serviceResult = await client.FetchPromotionByPromotionCodeAsync(promotionId);

                    serviceResult.ThrowIfException(true);
                    result = serviceResult.Result;
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"查询优惠券出错,promotionId:{promotionId}", ex);
            }

            return(result);
        }
        /// <summary>
        /// 发券(批量)
        /// </summary>
        /// <param name="models"></param>
        /// <param name="throwException"></param>
        /// <returns></returns>
        public static async Task <CreatePromotionCodeResult> CreatePromotions(IEnumerable <CreatePromotionModel> models)
        {
            CreatePromotionCodeResult result = null;

            try
            {
                using (var client = new PromotionClient())
                {
                    var serviceResult = await client.CreatePromotionsNewAsync(models);

                    serviceResult.ThrowIfException(true);
                    result = serviceResult.Result;
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"赛券服务报错,Request:{JsonConvert.SerializeObject(models)}", ex);
            }

            return(result);
        }
Esempio n. 16
0
        public bool RefreshRandomCouponCache(Guid activityId)
        {
            var result = false;

            try
            {
                using (var client = new PromotionClient())
                {
                    var getResult = client.RefreshRandomPromotionCacheByKey(activityId);
                    if (!getResult.Success && getResult.Exception != null)
                    {
                        throw getResult.Exception;
                    }
                    result = getResult.Result;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(result);
        }
Esempio n. 17
0
        /// <summary>
        /// 填充订单信息至塞券详情记录
        /// </summary>
        /// <param name="models"></param>
        /// <param name="batchCode"></param>
        /// <returns></returns>
        private List <VipPaintPromotionDetailViewModel> FillOrderForPromotionDetail(List <VipPaintPromotionDetailViewModel> models, string batchCode)
        {
            var package = dbScopeManagerProductcatalogRead.Execute(conn =>
                                                                   DalVipPaintPackage.GetPackageConfigByBatchCode(conn, batchCode));
            var promotions   = null as List <PromotionCodeModel>;
            var promotionIds = models?.Where(w => w.PromotionId > 0).Select(s => s.PromotionId).ToList();

            if (promotionIds != null && promotionIds.Any())
            {
                using (var client = new PromotionClient())
                {
                    promotions = client.GetPromotionCodeByIDs(new GetPromotionCodesRequest()
                    {
                        PKIDList = promotionIds
                    }).Result?.ToList();
                }
            }
            if (package != null && string.Equals(package.SettlementMethod, SettlementMethod.ByPeriod.ToString()))
            {
                if (promotions != null && promotions.Any())
                {
                    promotions.ForEach(f =>
                    {
                        var detail = models.FirstOrDefault(s => s.PromotionId == f.Pkid);
                        var status = GetPromotionStatus(f.Status);
                        if (detail != null)
                        {
                            detail.ToCOrder = f.OrderId > 0 ? Convert.ToString(f.OrderId) : string.Empty;
                            if (f.OrderId > 0)
                            {
                                using (var orderClient = new Service.Order.OrderQueryClient())
                                {
                                    var orderResult = orderClient.GetOrderRelationShip(f.OrderId);
                                    if (orderResult.Success && orderResult.Result != null && orderResult.Result.Any())
                                    {
                                        var toBOrder    = orderResult.Result.FirstOrDefault().Value?.FirstOrDefault();
                                        detail.ToBOrder = string.IsNullOrEmpty(toBOrder) ? detail.ToBOrder : toBOrder;
                                    }
                                }
                            }
                            detail.Status = string.IsNullOrEmpty(status) ? detail.Status : status;
                        }
                    });
                }
            }
            else if (package != null && string.Equals(package.SettlementMethod, SettlementMethod.PreSettled.ToString()))
            {
                var record = dbScopeManagerConfigurationRead.Execute(conn =>
                                                                     DalVipPaintPackage.GetPromotionRecord(conn, batchCode));
                if (promotions != null && promotions.Any())
                {
                    promotions.ForEach(f =>
                    {
                        var detail = models.FirstOrDefault(s => s.PromotionId == f.Pkid);
                        var status = GetPromotionStatus(f.Status);
                        if (detail != null)
                        {
                            detail.ToCOrder = f.OrderId > 0 ? Convert.ToString(f.OrderId) : string.Empty;
                            detail.Status   = string.IsNullOrEmpty(status) ? detail.Status : status;
                        }
                    });
                }
                if (record != null && !string.IsNullOrWhiteSpace(record.ToBOrder))
                {
                    models?.ForEach(s => s.ToBOrder = record.ToBOrder);
                }
            }
            return(models);
        }
Esempio n. 18
0
 public MarketingHelper(PromotionClient client)
 {
     _client = client;
 }
Esempio n. 19
0
        /// <summary>
        /// 作废券
        /// </summary>
        /// <param name="promotionIds"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Dictionary <int, bool> InvalidCodes(List <int> promotionIds, string user)
        {
            Dictionary <int, bool> result = new Dictionary <int, bool>();

            try
            {
                List <PromotionCodeModel> promotionCodes = new List <PromotionCodeModel>();
                using (var client = new PromotionClient())
                {
                    var serviceResult = client.GetPromotionCodeByIDs(new GetPromotionCodesRequest()
                    {
                        PKIDList = promotionIds
                    });
                    if (serviceResult.Success)
                    {
                        promotionCodes = serviceResult.Result.ToList();
                    }
                }
                foreach (var code in promotionCodes)
                {
                    using (var client = new PromotionClient())
                    {
                        var serviceResult = client.UpdateUserPromotionCodeStatus(new UpdateUserPromotionCodeStatusRequest()
                        {
                            Status          = 3,
                            PromotionCodeId = code.Pkid,
                            OperationAuthor = user,
                            Channel         = "setting.tuhu.cn",
                            UserID          = Guid.Parse(code.UserId)
                        });
                        if (serviceResult.Exception != null)
                        {
                            Logger.Error(serviceResult.Exception);
                        }
                        result[code.Pkid] = serviceResult.Success && serviceResult.Result;
                    }
                }

                foreach (var item in result)
                {
                    if (item.Value)
                    {
                        var log = new
                        {
                            ObjectId    = $"PromotionDetail_{item.Key}",
                            ObjectType  = "VipPaintPackage",
                            BeforeValue = JsonConvert.SerializeObject(item),
                            AfterValue  = "",
                            Remark      = $"喷漆大客户作废券:{user}于{DateTime.Now.ToString("yyyy年MM月dd日 hh:mm")}作废券Id{item.Key}",
                            Creator     = user
                        };
                        LoggerManager.InsertLog("CommonConfigLog", log);
                        dbScopeManagerConfiguration.Execute(conn =>
                                                            DalVipPaintPackage.UpdatePromotionDetailRemark(conn, item.Key, $"{user}于{DateTime.Now.ToString("yyyy年MM月dd日 hh:mm")}作废此券"));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("InvalidCodes", ex);
            }
            return(result);
        }