Exemple #1
0
        public RSModel setStep1(SupplierLoginRSModel supplierLoginRSModel, long prodOid, RezdyProductModel rezdyProductModel, SCMProductModel scmModel, ref string timezoneString)
        {
            try
            {
                //Startup startup = new Startup();
                //startup.Initial();
                RSModel              rsModel = new RSModel();
                JObject              scmRSModel;
                JObject              countryList;
                JObject              cityList;
                JObject              countryModifyRSModel;
                JObject              setCostMethodRSModel;
                JObject              timezone;
                AreaRQModel          areaModel;
                CountryModifyRQModel countryModifyRQModelModel;
                SetCostMethodRQModel setCostMethodRQModel;

                areaModel                       = new AreaRQModel();
                areaModel.json                  = new AreaJson();
                areaModel.json.supplierOid      = supplierLoginRSModel.supplierOid;
                areaModel.json.supplierUserUuid = supplierLoginRSModel.supplierUserUuid;
                areaModel.json.deviceId         = supplierLoginRSModel.deviceId;
                areaModel.json.tokenKey         = supplierLoginRSModel.tokenKey;

                countryModifyRQModelModel                       = new CountryModifyRQModel();
                countryModifyRQModelModel.json                  = new CountryModifyJson();
                countryModifyRQModelModel.json.supplierOid      = supplierLoginRSModel.supplierOid;
                countryModifyRQModelModel.json.supplierUserUuid = supplierLoginRSModel.supplierUserUuid;
                countryModifyRQModelModel.json.deviceId         = supplierLoginRSModel.deviceId;
                countryModifyRQModelModel.json.tokenKey         = supplierLoginRSModel.tokenKey;

                scmModel.Currency         = rezdyProductModel.Product.currency;
                scmModel.json.productName = rezdyProductModel.Product.name; // 商品名稱

                string country = null;
                string city    = null;
                if (rezdyProductModel.Product.timezone != null)
                {
                    foreach (var i in rezdyProductModel.Product.timezone.Split('/'))
                    {
                        if (country == null)
                        {
                            country = i;
                        }
                        else
                        {
                            city = i;
                        }
                    }
                }


                foreach (var i in new string[] { "A01", "A03", "A04", "A04", "A05", "A06", "A07", "A08", "A09" })
                {
                    areaModel.json.parentAreaCd = i;
                    countryList = CommonTool.GetDataPost(Startup.Instance.GetParameter(PMSSourse.KKday, ParameterType.KKdayApi_area), JsonConvert.SerializeObject(areaModel));
                    foreach (var j in countryList["content"]["areaList"])
                    {
                        if (country == j["areaShortName"].ToString())
                        {
                            areaModel.json.parentAreaCd = j["areaCd"].ToString();
                            cityList = CommonTool.GetDataPost(Startup.Instance.GetParameter(PMSSourse.KKday, ParameterType.KKdayApi_area), JsonConvert.SerializeObject(areaModel));
                            foreach (var k in cityList["content"]["areaList"])
                            {
                                if (city == k["areaShortName"].ToString())
                                {
                                    countryModifyRQModelModel.json.opType = "UPDATE";
                                    countryModifyRQModelModel.json.cityCd = k["areaCd"].ToString(); // 區域(城巿)
                                    countryModifyRSModel = CommonTool.GetDataPost(string.Format(Startup.Instance.GetParameter(PMSSourse.KKday, ParameterType.KKdayApi_countrymodify), prodOid), JsonConvert.SerializeObject(countryModifyRQModelModel));
                                    if (countryModifyRSModel["content"]["result"].ToString() != "0000")
                                    {
                                        rsModel.result = countryModifyRSModel["content"]["result"].ToString();
                                        rsModel.msg    = countryModifyRSModel["content"]["msg"].ToString();
                                        return(rsModel);
                                    }

                                    break;
                                }
                            }

                            break;
                        }
                    }
                }


                timezone = CommonTool.GetDataPost(Startup.Instance.GetParameter(PMSSourse.KKday, ParameterType.KKdayApi_timezone), JsonConvert.SerializeObject(scmModel));
                foreach (var i in timezone["content"]["codeList"])
                {
                    if (i["code"]["dataName"].ToString().StartsWith(rezdyProductModel.Product.timezone) == true)
                    {
                        scmModel.json.timezone = i["code"]["dataCd"].ToString(); // 商品時區
                        timezoneString         = scmModel.json.timezone;
                        break;
                    }
                }

                setCostMethodRQModel                       = new SetCostMethodRQModel();
                setCostMethodRQModel.json                  = new SetCostMethodJson();
                setCostMethodRQModel.json.supplierOid      = supplierLoginRSModel.supplierOid;
                setCostMethodRQModel.json.supplierUserUuid = supplierLoginRSModel.supplierUserUuid;
                setCostMethodRQModel.json.deviceId         = supplierLoginRSModel.deviceId;
                setCostMethodRQModel.json.tokenKey         = supplierLoginRSModel.tokenKey;
                setCostMethodRQModel.json.costCalcMethod   = "NET";                              //成本計算方式
                setCostMethodRQModel.json.prodCurrCd       = rezdyProductModel.Product.currency; //成本計算方式 幣別
                setCostMethodRSModel                       = CommonTool.GetDataPost(string.Format(Startup.Instance.GetParameter(PMSSourse.KKday, ParameterType.KKdayApi_setCostMethod), prodOid), JsonConvert.SerializeObject(setCostMethodRQModel));
                if (setCostMethodRSModel["content"]["result"].ToString() != "0000")
                {
                    rsModel.result = setCostMethodRSModel["content"]["result"].ToString();
                    rsModel.msg    = setCostMethodRSModel["content"]["msg"].ToString();
                    return(rsModel);
                }

                // 有可能是 en-au 但是scm均為en 所以要作轉換
                //for (int i = 0; i < rezdyProductModel.Product.Languages.Count; i++)
                //{
                //    if (rezdyProductModel.Product.Languages[i].StartsWith("en") == true)
                //        rezdyProductModel.Product.Languages[i] = "en";
                //}

                //scmModel.json.guideLang = rezdyProductModel.Product.Languages; // 提供解說服務
                scmModel.json.keyWord      = "";                                    // 自訂關鍵字 用逗號分隔 共三格 11,22,33
                scmModel.json.orderEmail   = supplierLoginRSModel.email;            // 訂單通知 email
                scmModel.json.supplierNote = rezdyProductModel.Product.productCode; // 備註(店家內部使用) 對應到對方的productCode

                //後面參數為model有null時 不顯示在model內
                scmRSModel = CommonTool.GetDataPost(string.Format(Startup.Instance.GetParameter(PMSSourse.KKday, ParameterType.KKdayApi_productmodify), prodOid), JsonConvert.SerializeObject(scmModel,
                                                                                                                                                                                              Newtonsoft.Json.Formatting.None,
                                                                                                                                                                                              new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                }));
                if (scmRSModel["content"]["result"].ToString() != "0000")
                {
                    rsModel.result = scmRSModel["content"]["result"].ToString();
                    rsModel.msg    = scmRSModel["content"]["msg"].ToString();
                    return(rsModel);
                }

                rsModel.result = scmRSModel["content"]["result"].ToString();
                rsModel.msg    = scmRSModel["content"]["msg"].ToString();


                return(rsModel);
            }
            catch (Exception ex)
            {
                _log.Debug(ex.ToString());
                throw ex;
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                //Startup startup = new Startup();
                //startup.Initial();
                //Website.Instance.Init(configuration);

                Startup.Instance.Initial();

                //initial log4net
                CommonTool.LoadLog4netConfig();
                Console.WriteLine("Log4net initial..");

                //待補
                long prodOid = 20451;
                SupplierLoginRSModel  supplierLoginRSModel  = new SupplierLoginRSModel();
                RezdyProductListModel rezdyProductListModel = new RezdyProductListModel();
                RezdyProductModel     rezdyProductModel     = new RezdyProductModel();
                PackageRepository     packageRepository     = new PackageRepository();
                RSModel getProductRSModel     = new RSModel();
                RSModel getProductListRSModel = new RSModel();
                RSModel createProductRSModel  = new RSModel();
                RSModel setScmProductRSModel  = new RSModel();
                int     offset = 0; // 抓取productList會限定一次只抓一筆 故 offset從0開始抓

                var accounts = new[] { new { id = 1, name = "thisisname" } };
                var pmsList  = new[] { new { id = 1, pmsname = "Rezdy" } };
                //var suppliers  ;

                foreach (var account in accounts)
                {
                    foreach (var pms in pmsList)
                    {
                        //prodOid = 0;
                        //抓取所有supplier清單
                        var supplierList = SupplierDAL.GetSupplierList(pms.pmsname);


                        foreach (var supplier in supplierList["Table"])
                        {
                            // 設定參數

                            supplierLoginRSModel = product.setParameters(PMSSourse.Rezdy, supplier["pms_supplier_name"].ToString(), supplier["kkday_supplier_oid"].ToString(), supplier["scm_account"].ToString(), supplier["scm_password"].ToString());
                            if (supplierLoginRSModel.result == "0000")
                            {
                                offset = 0;
                                getProductListRSModel = product.getProductList(PMSSourse.Rezdy, ref rezdyProductListModel, supplier["pms_supplier_id"].ToString(), offset);
                                //foreach (var prod in productList)
                                while (getProductListRSModel.result == "0000" && rezdyProductListModel.Products.Count > 0)
                                {
                                    rezdyProductModel.RequestStatus = rezdyProductListModel.RequestStatus;
                                    rezdyProductModel.Product       = rezdyProductListModel.Products[0]; // rezdyProductListModel.Product 每次只取一筆 把取到資料給 rezdyProductModel.Product

                                    //抓取商品
                                    //getProductRSModel = product.getProduct(PMSSourse.Rezdy, ref rezdyProductModel, "PSSPVU");
                                    if (rezdyProductModel.Product != null)
                                    {
                                        //建立SCM商品
                                        //createProductRSModel = product.createProduct(supplierLoginRSModel, ref prodOid, rezdyProductModel);
                                        //if (createProductRSModel.result == "0000")
                                        {
                                            //商品明細
                                            setScmProductRSModel = product.setScmProduct(supplierLoginRSModel, prodOid, rezdyProductModel);

                                            //套餐
                                            //PackageRepository packageRepository = new PackageRepository();
                                            packageRepository.Main(
                                                Models.Shared.Enum.PMSSourse.Rezdy,
                                                prodOid,
                                                supplierLoginRSModel.supplierOid,
                                                rezdyProductModel.Product.productCode,
                                                rezdyProductModel.Product.currency,
                                                supplierLoginRSModel.supplierUserUuid,
                                                supplierLoginRSModel.deviceId,
                                                supplierLoginRSModel.tokenKey);

                                            //旅規
                                            //module.Main();
                                        }
                                        //else
                                        //{
                                        //    Console.WriteLine("建立商品錯誤:" + createProductRSModel.result);
                                        //}
                                    }
                                    else
                                    {
                                        Console.WriteLine("抓取商品錯誤:" + getProductRSModel.result);
                                    }

                                    offset++;
                                    getProductListRSModel = product.getProductList(PMSSourse.Rezdy, ref rezdyProductListModel, supplier["pms_supplier_id"].ToString(), offset);
                                }
                            }
                            else
                            {
                                Console.WriteLine("設定參數錯誤:" + supplierLoginRSModel.result);
                            }
                        }
                    }
                }

                Console.WriteLine("Done!");
            }
            catch (Exception ex)
            {
                //error log
                _log.Error(ex.ToString());
                throw ex;
            }
        }