/// <summary>
 /// 根据查询条件获取产品库优惠券数据列表
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public IEnumerable <QueryProductsModel> QueryProductsForProductLibrary(SeachProducts model, out int totalCount)
 {
     totalCount = 0;
     try
     {
         List <QueryProductsModel> result = handler.QueryProductsForProductLibrary(model).ToList();
         totalCount = handler.QueryProductsForProductLibraryCount(model);
         if (!result.Any())
         {
             return(result ?? new List <QueryProductsModel>());
         }
         var pids      = new List <string>(result.Count);
         var rulePkIds = new Dictionary <int, bool>(result.Count);
         result.ForEach(r =>
         {
             pids.Add(r.PID);
             r.CouponIds?.Split(',')?.ToList().ForEach(t =>
             {
                 int.TryParse(t, out int id);
                 if (id > 0 && !rulePkIds.ContainsKey(id))
                 {
                     rulePkIds.Add(id, true);
                 }
             });
         });
         var data     = QueryProductSalesInfo(pids);
         var rulesDic = ActivityManager.GetPCodeModelByRulePKIDS(rulePkIds.Keys);
         if (data == null)
         {
             data = new Dictionary <string, ProductSalesPredic>();
         }
         foreach (var x in result)
         {
             data.TryGetValue(x.PID, out ProductSalesPredic p);
             x.cy_list_price = p?.OfficialWebsitePrice ?? 0;
             x.cy_cost       = p?.Cost ?? 0;
             x.Maoli         = x.cy_list_price - x.cy_cost;
             var useCouponEffects = new List <UseCouponEffect>();
             x.CouponIds?.Split(',')?.ToList().ForEach(t =>
             {
                 int.TryParse(t, out int id);
                 if (id > 0 && rulesDic.TryGetValue(id, out GetPCodeModel rule))
                 {
                     if (rule != null)
                     {
                         var useCouponEffect = CalculateUseCouponEffect(x, rule);
                         if (useCouponEffect != null)
                         {
                             useCouponEffects.Add(useCouponEffect);
                         }
                     }
                 }
             });
             if (useCouponEffects.Any())
             {
                 x.UseCouponEffects = useCouponEffects;
                 x.PriceAfterCoupon = useCouponEffects.Min(t => t.PriceAfterCoupon.GetValueOrDefault());
                 x.GrossProfit      = useCouponEffects.Min(t => t.GrossProfit.GetValueOrDefault());
             }
         }
         ;
         return(result);
     }
     catch (Exception ex)
     {
         logger.Log(Level.Error, ex.ToString());
         return(new List <QueryProductsModel>());
     }
 }