Beispiel #1
0
        /// <summary>
        /// Gets the prod list.
        /// </summary>
        /// <returns>The prod list.</returns>
        /// <param name="rq">Rq.</param>
        //1.取得商品列表
        public static SearchProductModel GetProdList(SearchRQModel rq)
        {
            SearchProductModel      prod = new SearchProductModel();
            List <ProductBaseModel> pLst = new List <ProductBaseModel>();

            try {
                JObject obj = SearchProxy.GetProdList(rq);

                Metadata md = new Metadata();

                DataModel.Discount.DiscountRuleModel disc = null;

                #region --1.取回傳資料是否成功的訊息、統計用資訊--

                md.result     = obj["metadata"]["status"].ToString();
                md.result_msg = obj["metadata"]["desc"].ToString();

                prod.metadata = md;
                #endregion

                //如果狀態為0000  表示搜尋沒問題  才繼續滿足商品欄位
                if (md.result == "0000")
                {
                    #region --2.從傑森物件取『商品列表』--
                    JArray jsonPlst = (JArray)obj["data"]["prods"];

                    int countBlackProd = 0;//計算黑名單筆數

                    for (int i = 0; i < jsonPlst.Count; i++)
                    {
                        var model = new ProductBaseModel();

                        string prod_no = jsonPlst[i]["id"].ToString();

                        //抓商品是否為黑名單
                        bool isBlack = DiscountRepository.GetProdBlackWhite(prod_no);

                        //表示該商品為白名單 需要綁入列表中 (黑名單的就不綁了)
                        if (isBlack != true)
                        {
                            model.prod_no           = Convert.ToInt32(prod_no);
                            model.prod_name         = jsonPlst[i]["name"].ToString();
                            model.b2d_price         = DiscountRepository.GetCompanyDiscPrice(Int64.Parse(rq.company_xid), (double)jsonPlst[i]["price"], prod_no, jsonPlst[i]["main_cat_key"].ToString(), ref disc); //分銷價
                            model.b2c_price         = (double)jsonPlst[i]["sale_price"];                                                                                                                            //直客價
                            model.display_ref_price = jsonPlst[i]["display_price"].ToString();

                            model.prod_currency   = jsonPlst[i]["currency"].ToString();
                            model.prod_img_url    = jsonPlst[i]["img_url"].ToString();
                            model.rating_count    = (int)jsonPlst[i]["rating_count"];
                            model.avg_rating_star = (double)jsonPlst[i]["rating_star"];
                            model.instant_booking = (bool)jsonPlst[i]["instant_booking"];
                            model.order_count     = (int)jsonPlst[i]["order_count"];
                            model.days            = (int)jsonPlst[i]["days"];
                            model.hours           = (int)jsonPlst[i]["hours"];
                            model.introduction    = jsonPlst[i]["introduction"].ToString();
                            model.duration        = (int)jsonPlst[i]["duration"];
                            //model.display_price_usd = jsonPlst[i]["display_price_usd"].ToString();
                            //model.price_usd = (double)jsonPlst[i]["price_usd"];
                            model.prod_type = jsonPlst[i]["main_cat_key"].ToString();
                            model.tag       = jsonPlst[i]["cat_key"].ToObject <string[]>();//把傑森物件轉成字串陣列


                            //取國家,城市
                            List <Country> country =
                                ((JArray)jsonPlst[i]["countries"])
                                .Select(x => new Country {
                                id     = (string)x["id"],
                                name   = (string)x["name"],
                                cities = x["cities"].ToObject <List <City> >()
                            }).ToList();

                            model.countries = country;

                            pLst.Add(model);
                        }
                        else
                        {
                            countBlackProd++;
                        }

                        //頁數、筆數統計
                        md.total_count = (int)obj["metadata"]["pagination"]["total_count"] - countBlackProd; //商品總筆數 扣掉黑名單筆數
                        md.start       = (int)obj["metadata"]["pagination"]["start"];                        //從第?筆開始
                        md.count       = (int)obj["metadata"]["pagination"]["count"];                        //一頁?筆商品

                        prod.metadata = md;

                        //stats 金額統計
                        if (rq.stats != null)
                        {
                            Stats s = new Stats();
                            s.price = new Price()
                            {
                                min      = (int)obj["data"]["stats"]["price"]["min"],
                                max      = (int)obj["data"]["stats"]["price"]["max"],
                                count    = (int)obj["data"]["stats"]["price"]["count"],
                                currency = obj["data"]["stats"]["price"]["currency"].ToString()
                            };
                            prod.stats = s;
                        }

                        //facets 大分類 小分類 ...的統計
                        if (rq.facets != null)
                        {
                            Facets f = new Facets();

                            //大分
                            if (rq.facets.Where(x => x.Equals("cat_main")).Count() == 1)
                            {
                                List <CatMain> cm =
                                    ((JArray)obj["data"]["facets"]["cat_main"])
                                    .Select(x => new CatMain {
                                    id    = (string)x["id"],
                                    name  = (string)x["name"],
                                    sort  = (string)x["sort"],
                                    count = (int)x["count"]
                                }).ToList();

                                f.cat_main = cm;
                            }

                            //小分
                            if (rq.facets.Where(x => x.Equals("cat")).Count() == 1)
                            {
                                List <Cat> ca =
                                    ((JArray)obj["data"]["facets"]["cat"])
                                    .Select(x => new Cat {
                                    id    = (string)x["id"],
                                    name  = (string)x["name"],
                                    sort  = (string)x["sort"],
                                    count = (int)x["count"]
                                }).ToList();

                                f.cat = ca;
                            }


                            if (rq.facets.Where(x => x.Equals("total_time")).Count() == 1)
                            {
                                List <TotalTime> tt =
                                    ((JArray)obj["data"]["facets"]["total_time"])
                                    .Select(x => new TotalTime {
                                    time  = (int)x["time"],
                                    count = (int)x["count"]
                                }).ToList();

                                f.total_time = tt;
                            }

                            if (rq.facets.Where(x => x.Equals("guide_lang")).Count() == 1)
                            {
                                List <GuideLang> gl =
                                    ((JArray)obj["data"]["facets"]["guide_lang"])
                                    .Select(x => new GuideLang {
                                    id    = (string)x["id"],
                                    name  = (string)x["name"],
                                    count = (int)x["count"]
                                }).ToList();

                                f.guide_lang = gl;
                            }

                            //可販售日期
                            if (rq.facets.Where(x => x.Equals("sale_dt")).Count() == 1)
                            {
                                List <SaleDt> sd =
                                    ((JArray)obj["data"]["facets"]["sale_dt"])
                                    .Select(x => new SaleDt {
                                    id    = (int)x["id"],
                                    count = (int)x["count"]
                                }).ToList();

                                f.sale_dt = sd;
                            }

                            prod.facets = f;
                        }
                    }

                    prod.prods = pLst;
                    #endregion
                }
            } catch (Exception ex) {
                Website.Instance.logger.FatalFormat($"getProdLst  Error :{ex.Message},{ex.StackTrace}");

                throw ex;
            }

            return(prod);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the package lst.
        /// </summary>
        /// <returns>The package lst.</returns>
        /// <param name="rq">Rq.</param>
        //取得套餐列表
        public static PackageModel GetPkgLst(QueryProductModel rq)
        {
            PackageModel          pkg    = new PackageModel();
            List <PkgDetailModel> pkgLst = new List <PkgDetailModel>();

            DataModel.Discount.DiscountRuleModel disc = null;
            PkgPriceModel pkg_price = new PkgPriceModel();

            try {
                //商品黑名單過濾
                //抓商品是否為黑名單
                bool isBlack = DiscountRepository.GetProdBlackWhite(rq.prod_no);

                if (isBlack)
                {
                    pkg.result     = "10";
                    pkg.result_msg = $"Bad Request:Product-{rq.prod_no} is not available";
                    return(pkg);
                }


                JObject obj     = PackageProxy.getPkgLst(rq);
                JObject objProd = ProdProxy.getProd(rq);

                if (obj["content"]["result"].ToString() != "0000")
                {
                    pkg.result     = obj["content"]["result"].ToString();
                    pkg.result_msg = $"kkday package api response msg is not correct! {obj["content"]["msg"].ToString()}";
                    throw new Exception($"kkday package api response msg is not correct! {obj["content"]["msg"].ToString()}");
                }

                if (objProd["content"]["result"].ToString() != "0000")
                {
                    pkg.result     = obj["content"]["result"].ToString();
                    pkg.result_msg = $"kkday product api response msg is not correct! {objProd["content"]["msg"].ToString()}";
                    throw new Exception($"kkday product api response msg is not correct! {objProd["content"]["msg"].ToString()}");
                }

                #region --1.取回傳資料是否成功的訊息、一般資訊--

                pkg.result         = obj["content"]["result"].ToString();
                pkg.result_msg     = obj["content"]["msg"].ToString();
                pkg.cost_calc_type = obj["content"]["costCalcMethod"].ToString();

                #endregion

                #region --2.從傑森物件取『套餐列表』--
                JArray jPkglst = (JArray)obj["content"]["packageList"];

                pkg_price.pkgs     = new List <pkgs>(); // 初始化陣列
                pkg_price.currency = rq.current_currency;

                for (int i = 0; i < jPkglst.Count; i++)
                {
                    var model       = new PkgDetailModel();
                    var price_model = new pkgs(); // pkg_price 用

                    model.pkg_no        = jPkglst[i]["productPkg"]["pkgOid"].ToString();
                    model.pkg_name      = jPkglst[i]["productPkg"]["pkgName"].ToString();
                    model.online_s_date = jPkglst[i]["productPkg"]["begValidDt"].ToString();
                    model.online_e_date = jPkglst[i]["productPkg"]["endValidDt"].ToString();
                    model.weekDays      = jPkglst[i]["productPkg"]["weekDays"].ToString();

                    model.is_unit_pirce = jPkglst[i]["productPkg"]["priceType"].ToString();

                    model.price1             = DiscountRepository.GetCompanyDiscPrice(Int64.Parse(rq.company_xid), (double)jPkglst[i]["productPkg"]["price1"], rq.prod_no, objProd["content"]["product"]["mainCat"].ToString(), ref disc);//分銷價
                    model.price1_org         = (double?)jPkglst[i]["productPkg"]["price1Org"] ?? 0;
                    model.price1_org_net     = (double?)jPkglst[i]["productPkg"]["price1NetOrg"] ?? 0;
                    model.price1_profit_rate = (double?)jPkglst[i]["productPkg"]["price1GrossRate"] ?? 0;
                    model.price1_comm_rate   = (double?)jPkglst[i]["productPkg"]["price1CommRate"] ?? 0;
                    model.price1_age_range   = jPkglst[i]["productPkg"]["price1BegOld"].ToString() + "~" +
                                               jPkglst[i]["productPkg"]["price1EndOld"].ToString();
                    model.price1_b2c = (double?)jPkglst[i]["productPkg"]["price1Sale"] ?? 0;
                    // model.price1_net = (double)jPkglst[i]["productPkg"][""];
                    //  model.price1_list = (double)jPkglst[i]["productPkg"][""];

                    model.price2             = (double?)jPkglst[i]["productPkg"]["price2"] == null ? 0 : DiscountRepository.GetCompanyDiscPrice(Int64.Parse(rq.company_xid), (double)jPkglst[i]["productPkg"]["price2"], rq.prod_no, objProd["content"]["product"]["mainCat"].ToString(), ref disc);//分銷價
                    model.price2_org         = (double?)jPkglst[i]["productPkg"]["price2Org"] ?? 0;
                    model.price2_org_net     = (double?)jPkglst[i]["productPkg"]["price2NetOrg"] ?? 0;
                    model.price2_profit_rate = (double?)jPkglst[i]["productPkg"]["price2GrossRate"] ?? 0;
                    model.price2_comm_rate   = (double?)jPkglst[i]["productPkg"]["price2CommRate"] ?? 0;
                    model.price2_age_range   = jPkglst[i]["productPkg"]["price2BegOld"].ToString() + "~" +
                                               jPkglst[i]["productPkg"]["price2EndOld"].ToString();
                    model.price2_b2c = (double?)jPkglst[i]["productPkg"]["price2Sale"] ?? 0;
                    // model.price2_net = (double)jPkglst[i]["productPkg"][""];
                    //  model.price2_list = (double)jPkglst[i]["productPkg"][""];

                    model.price3             = (double?)jPkglst[i]["productPkg"]["price3"] == null ? 0 : DiscountRepository.GetCompanyDiscPrice(Int64.Parse(rq.company_xid), (double)jPkglst[i]["productPkg"]["price3"], rq.prod_no, objProd["content"]["product"]["mainCat"].ToString(), ref disc);//分銷價
                    model.price3_org         = (double?)jPkglst[i]["productPkg"]["price3Org"] ?? 0;
                    model.price3_org_net     = (double?)jPkglst[i]["productPkg"]["price3NetOrg"] ?? 0;
                    model.price3_profit_rate = (double?)jPkglst[i]["productPkg"]["price3GrossRate"] ?? 0;
                    model.price3_comm_rate   = (double?)jPkglst[i]["productPkg"]["price3CommRate"] ?? 0;
                    model.price3_age_range   = jPkglst[i]["productPkg"]["price3BegOld"].ToString() + "~" +
                                               jPkglst[i]["productPkg"]["price3EndOld"].ToString();
                    model.price3_b2c = (double?)jPkglst[i]["productPkg"]["price3Sale"] ?? 0;
                    // model.price3_net = (double)jPkglst[i]["productPkg"][""];
                    //  model.price3_list = (double)jPkglst[i]["productPkg"][""];

                    model.price4             = (double?)jPkglst[i]["productPkg"]["price4"] == null ? 0 : DiscountRepository.GetCompanyDiscPrice(Int64.Parse(rq.company_xid), (double)jPkglst[i]["productPkg"]["price4"], rq.prod_no, objProd["content"]["product"]["mainCat"].ToString(), ref disc);//分銷價
                    model.price4_org         = (double?)jPkglst[i]["productPkg"]["price4Org"] ?? 0;
                    model.price4_org_net     = (double?)jPkglst[i]["productPkg"]["price4NetOrg"] ?? 0;
                    model.price4_profit_rate = (double?)jPkglst[i]["productPkg"]["price4GrossRate"] ?? 0;
                    model.price4_comm_rate   = (double?)jPkglst[i]["productPkg"]["price4CommRate"] ?? 0;
                    model.price4_age_range   = jPkglst[i]["productPkg"]["price4BegOld"].ToString() + "~" +
                                               jPkglst[i]["productPkg"]["price4EndOld"].ToString();
                    model.price4_b2c = (double?)jPkglst[i]["productPkg"]["price4Sale"] ?? 0;
                    // model.price4_net = (double)jPkglst[i]["productPkg"][""];
                    //  model.price4_list = (double)jPkglst[i]["productPkg"][""];

                    model.status = jPkglst[i]["productPkg"]["status"].ToString();
                    model.norank_min_book_qty = (int)jPkglst[i]["productPkg"]["minOrderNum"];
                    model.norank_max_book_qty = (int)jPkglst[i]["productPkg"]["maxOrderNum"];
                    model.rank_min_book_qty   = (int)jPkglst[i]["productPkg"]["minOrderQty"];
                    model.min_orverage_qty    = (int)jPkglst[i]["productPkg"]["minOrderAdultQty"];
                    model.isMultiple          = jPkglst[i]["productPkg"]["isMultiple"].ToString();
                    model.book_qty            = jPkglst[i]["productPkg"]["orderQty"].ToString();
                    model.unit = jPkglst[i]["productPkg"]["unit"].ToString();

                    model.unit_txt    = jPkglst[i]["productPkg"]["unitTxt"].ToString();
                    model.unit_qty    = (int)jPkglst[i]["productPkg"]["unitQty"];
                    model.pickupTp    = jPkglst[i]["productPkg"]["pickupTp"].ToString();
                    model.pickupTpTxt = jPkglst[i]["productPkg"]["pickupTpTxt"].ToString();
                    model.is_hl       = jPkglst[i]["productPkg"]["isBackUp"].ToString();
                    model.is_event    = jPkglst[i]["productPkg"]["hasEvent"].ToString();

                    var d = jPkglst[i]["productPkg"]["pkgDesc"];
                    if (d.FirstOrDefault() != null)
                    {
                        //取各套餐內的各個敘述
                        List <DescItem> desc = (d["descItems"][0]["content"])
                                               .Select(x => new DescItem {
                            id   = (string)x["id"],
                            desc = (string)x["desc"]
                        }).ToList();
                        model.desc_items = desc;
                    }

                    //組moduleSetting
                    var moduleSet = jPkglst[i]["productPkg"]["moduleSetting"];

                    if (moduleSet.FirstOrDefault() != null)
                    {
                        FlightInfoType fit = new FlightInfoType()
                        {
                            value =
                                moduleSet["flightInfoType"]["value"].ToString()
                        };

                        SendInfoType sit = new SendInfoType()
                        {
                            value =
                                moduleSet["sendInfoType"]["value"].ToString(),
                            country_code =
                                moduleSet["sendInfoType"]["countryCode"].ToString()
                        };

                        VoucherValidInfo vi = new VoucherValidInfo();

                        if (moduleSet["voucherValidInfo"] != null && moduleSet["voucherValidInfo"].Any())
                        {
                            vi.valid_period_type =
                                moduleSet["voucherValidInfo"]["validPeriodType"].ToString();

                            vi.before_specific_date =
                                moduleSet["voucherValidInfo"]["beforeSpecificDate"].ToString();

                            if (moduleSet["voucherValidInfo"]["afterOrderDate"] != null && moduleSet["voucherValidInfo"]["afterOrderDate"].Any())
                            {
                                AfterOrderDate aod = new AfterOrderDate()
                                {
                                    qty  = (int?)moduleSet["voucherValidInfo"]["afterOrderDate"]["qty"],
                                    unit = moduleSet["voucherValidInfo"]["afterOrderDate"]["unit"].ToString()
                                };

                                vi.after_order_date = aod;
                            }
                        }

                        ModuleSetting ms = new ModuleSetting()
                        {
                            flight_info_type   = fit,
                            send_info_type     = sit,
                            voucher_valid_info = vi
                        };

                        model.module_setting = ms;
                    }

                    pkgLst.Add(model);


                    price_model.pkg_no     = model.pkg_no;
                    price_model.price1     = model.price1;
                    price_model.price1_b2c = model.price1_b2c;
                    price_model.price2     = model.price2;
                    price_model.price2_b2c = model.price2_b2c;
                    price_model.price3     = model.price3;
                    price_model.price3_b2c = model.price3_b2c;
                    price_model.price4     = model.price4;
                    price_model.price4_b2c = model.price4_b2c;
                    pkg_price.pkgs.Add(price_model);
                }

                pkg.pkgs          = pkgLst;
                pkg.discount_rule = disc;
                pkg.guid          = Guid.NewGuid().ToString();
                rds.SetProdInfotoRedis(JsonConvert.SerializeObject(pkg_price), "b2d:pkgsPrice:" + pkg.guid, 1440); // 將 pkg_price 存入redis

                //依套餐取回『可售日期』
                pkg.sale_dates = (PkgSaleDateModel)GetPkgSaleDate(rq);;

                #endregion
            } catch (Exception ex) {
                pkg.result     = "10001";
                pkg.result_msg = $"Package ERROR :{ex.Message},{ex.StackTrace}";
                Website.Instance.logger.FatalFormat($"Package ERROR :{ex.Message},{ex.StackTrace}");
            }

            return(pkg);
        }