protected void btnSave_Click(object sender, EventArgs e)
        {
            SiteSettings masterSettings = SettingsManager.GetMasterSettings();

            masterSettings.DadaAppKey    = this.txtAppKey.Text;
            masterSettings.DadaAppSecret = this.txtAppSecret.Text;
            masterSettings.DadaSourceID  = this.txtSourceID.Text;
            if (this.ooEnableHtmRewrite.SelectedValue)
            {
                if (string.IsNullOrEmpty(this.txtAppKey.Text))
                {
                    this.ShowMsg("app_key不能为空!", false);
                    return;
                }
                if (string.IsNullOrEmpty(this.txtAppSecret.Text))
                {
                    this.ShowMsg("app_secret不能为空!", false);
                    return;
                }
                if (string.IsNullOrEmpty(this.txtSourceID.Text))
                {
                    this.ShowMsg("source_id不能为空!", false);
                    return;
                }
                DataTable dataTable = DepotHelper.SynchroDadaStoreList(0);
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        string  station_name    = dataTable.Rows[i]["StoreName"].ToNullString();
                        int     business        = 5;
                        string  city_name       = dataTable.Rows[i]["CityName"].ToNullString().Replace("市", "");
                        string  area_name       = dataTable.Rows[i]["RegionName"].ToNullString();
                        string  station_address = dataTable.Rows[i]["Address"].ToNullString();
                        double  lng             = dataTable.Rows[i]["Longitude"].ToDouble(0);
                        double  lat             = dataTable.Rows[i]["Latitude"].ToDouble(0);
                        string  contact_name    = dataTable.Rows[i]["ContactMan"].ToNullString();
                        string  phone           = dataTable.Rows[i]["Tel"].ToNullString();
                        string  origin_shop_id  = dataTable.Rows[i]["StoreId"].ToNullString();
                        string  value           = DadaHelper.shopAdd(this.txtSourceID.Text, station_name, business, city_name, area_name, station_address, lng, lat, contact_name, phone, origin_shop_id, "", "", "");
                        JObject jObject         = JsonConvert.DeserializeObject(value) as JObject;
                        string  a   = jObject["status"].ToNullString();
                        int     num = jObject["code"].ToInt(0);
                        if (a == "fail" && num != 7718)
                        {
                            this.ShowMsg(jObject["msg"].ToNullString(), false);
                            return;
                        }
                    }
                }
            }
            masterSettings.OpenDadaLogistics = this.ooEnableHtmRewrite.SelectedValue;
            SettingsManager.Save(masterSettings);
            this.ShowMsg("设置成功", true, "DadaLogistics");
        }
Exemple #2
0
        private void UpdateStores()
        {
            StoresInfo  storeById   = StoresHelper.GetStoreById(this.storeId);
            ManagerInfo managerInfo = ManagerHelper.FindManagerByStoreId(this.storeId, SystemRoles.StoreAdmin);

            if (storeById == null)
            {
                base.Response.Redirect("StoresList.aspx");
            }
            double  num     = 0.0;
            int     num2    = 0;
            int     num3    = 0;
            decimal num4    = default(decimal);
            string  text    = "";
            string  text2   = "";
            string  Address = "";
            string  text3   = Globals.StripAllTags(this.txtStoresName.Text.Trim());

            Address = Globals.StripAllTags(this.txtAddress.Text);
            string text4 = Globals.StripAllTags(this.txtRegionScop.Value.Trim());
            string text5 = Globals.StripAllTags(this.txtRegionScopName.Value.Trim());

            text  = this.txtTel.Text;
            text2 = this.txtContactMan.Text;
            string[] array  = text4.Split(',');
            string[] array2 = text5.Split(',');
            IDictionary <int, DeliveryScopeInfo> dictionary = new Dictionary <int, DeliveryScopeInfo>();

            for (int i = 0; i < array.Length; i++)
            {
                int num5 = 0;
                if (int.TryParse(array[i], out num5) && array2.Length >= i && dictionary != null && !dictionary.ContainsKey(num5))
                {
                    DeliveryScopeInfo deliveryScopeInfo = new DeliveryScopeInfo();
                    deliveryScopeInfo.RegionId       = num5;
                    deliveryScopeInfo.RegionName     = array2[i];
                    deliveryScopeInfo.FullRegionPath = RegionHelper.GetFullPath(num5, true);
                    dictionary.Add(num5, deliveryScopeInfo);
                }
            }
            if (storeById.StoreName != text3 && StoresHelper.ExistStoreName(text3))
            {
                this.ResetForm(storeById.StoreId);
                this.ShowMsg("门店名称已经存在,请重新输入!", false);
            }
            else if (string.Compare(this.txtUserPwd.Text, this.txtUserRePwd.Text) != 0)
            {
                this.ResetForm(storeById.StoreId);
                this.ShowMsg("请确保两次输入的密码相同", false);
            }
            else if (!this.dropRegion.GetSelectedRegionId().HasValue)
            {
                this.ResetForm(storeById.StoreId);
                this.ShowMsg("请选择店铺所在区域!", false);
            }
            else if (text2.Length > 8 || text2.Length < 2)
            {
                this.ResetForm(storeById.StoreId);
                this.ShowMsg("请输入联系人,联系人长度必须是2-8位!", false);
            }
            else if (string.IsNullOrEmpty(this.hfLatitude.Value) || string.IsNullOrEmpty(this.hfLongitude.Value))
            {
                this.ResetForm(storeById.StoreId);
                this.ShowMsg("请给门店标注定位!", false);
            }
            else if (text == "" || !DataHelper.IsTel(text))
            {
                this.ResetForm(storeById.StoreId);
                this.ShowMsg("请输入正确的联系电话(手机或者固定电话)!", false);
            }
            else
            {
                if (!string.IsNullOrEmpty(this.txtUserPwd.Text))
                {
                    if (this.txtUserPwd.Text.Length < 6 || this.txtUserPwd.Text.Length > 20)
                    {
                        this.ResetForm(storeById.StoreId);
                        this.ShowMsg("密码长度必须在6到20个字符之间!", false);
                        return;
                    }
                    managerInfo.Password = Users.EncodePassword(this.txtUserPwd.Text, managerInfo.PasswordSalt);
                }
                if (!this.chkIsSupportExpress.Checked && !this.chkIsAboveSelf.Checked && !this.chkIsStoreDelive.Checked)
                {
                    this.ResetForm(storeById.StoreId);
                    this.ShowMsg("请选择一种配送方式!", false);
                }
                else
                {
                    if (this.chkIsStoreDelive.Checked)
                    {
                        if (!double.TryParse(this.txtServeRadius.Text.Trim(), out num) || num > 10000.0 || num <= 0.0)
                        {
                            this.ResetForm(storeById.StoreId);
                            this.ShowMsg("请输入正确的配送半径,为大于0至10000之间的数字!", false);
                            return;
                        }
                        if (!int.TryParse(this.txtStoreFreight.Text.Trim(), out num2) || num2 > 99999999 || num2 < 0)
                        {
                            this.ResetForm(storeById.StoreId);
                            this.ShowMsg("请输入正确的配送费", false);
                            return;
                        }
                        if (!int.TryParse(this.txtMinOrderPrice.Text.Trim(), out num3) || num3 > 99999999 || num3 < 0)
                        {
                            this.ResetForm(storeById.StoreId);
                            this.ShowMsg("请输入正确的起送价", false);
                            return;
                        }
                    }
                    if (!decimal.TryParse(this.txtCommissionRate.Text.Trim(), out num4) || num4 > 100m || num4 < decimal.Zero)
                    {
                        this.ResetForm(storeById.StoreId);
                        this.ShowMsg("请输入正确的平台抽佣比例", false);
                    }
                    else if (!this.chkOfflinePay.Checked && !this.chkOnlinePay.Checked && !this.chkCashOnDelivery.Checked)
                    {
                        this.ResetForm(storeById.StoreId);
                        this.ShowMsg("支付方式请至少选择一种", false);
                    }
                    else
                    {
                        storeById.IsOfflinePay     = this.chkOfflinePay.Checked;
                        storeById.IsOnlinePay      = this.chkOnlinePay.Checked;
                        storeById.IsCashOnDelivery = this.chkCashOnDelivery.Checked;
                        if (string.IsNullOrEmpty(this.txtStoreOpenTimeStartH.Text) || this.txtStoreOpenTimeStartH.Text.ToInt(0) < 0 || this.txtStoreOpenTimeStartH.Text.ToInt(0) >= 24)
                        {
                            this.ResetForm(storeById.StoreId);
                            this.ShowMsg("请输入正确的营业起始小时", false);
                        }
                        else if (string.IsNullOrEmpty(this.txtStoreOpenTimeStartM.Text) || this.txtStoreOpenTimeStartM.Text.ToInt(0) < 0 || this.txtStoreOpenTimeStartM.Text.ToInt(0) >= 60)
                        {
                            this.ResetForm(storeById.StoreId);
                            this.ShowMsg("请输入正确的营业起始分钟", false);
                        }
                        else if (string.IsNullOrEmpty(this.txtStoreOpenTimeEndH.Text) || this.txtStoreOpenTimeEndH.Text.ToInt(0) < 0 || this.txtStoreOpenTimeEndH.Text.ToInt(0) >= 24)
                        {
                            this.ResetForm(storeById.StoreId);
                            this.ShowMsg("请输入正确的营业结束小时", false);
                        }
                        else if (string.IsNullOrEmpty(this.txtStoreOpenTimeEndM.Text) || this.txtStoreOpenTimeEndM.Text.ToInt(0) < 0 || this.txtStoreOpenTimeEndM.Text.ToInt(0) >= 60)
                        {
                            this.ResetForm(storeById.StoreId);
                            this.ShowMsg("请输入正确的营业结束分钟", false);
                        }
                        else
                        {
                            string   empty     = string.Empty;
                            DateTime dateTime  = DateTime.Now;
                            string   text6     = dateTime.ToString("yyyy-MM-dd");
                            DateTime?nullable  = (text6 + " " + this.txtStoreOpenTimeStartH.Text.ToInt(0) + ":" + this.txtStoreOpenTimeStartM.Text.ToInt(0)).ToDateTime();
                            DateTime?nullable2 = (text6 + " " + this.txtStoreOpenTimeEndH.Text.ToInt(0) + ":" + this.txtStoreOpenTimeEndM.Text.ToInt(0)).ToDateTime();
                            dateTime = nullable.Value;
                            string str = dateTime.ToString("HH:mm");
                            dateTime = nullable2.Value;
                            string text7 = dateTime.ToString("HH:mm");
                            if (text7 == "00:00")
                            {
                                nullable2 = (text6 + " 23:59").ToDateTime();
                                text7     = "23:59";
                            }
                            empty = (storeById.StoreOpenTime = str + "-" + text7);
                            storeById.OpenStartDate    = nullable.Value;
                            storeById.OpenEndDate      = nullable2.Value;
                            storeById.IsSupportExpress = (this.chkIsSupportExpress.Checked && true);
                            storeById.IsAboveSelf      = (this.chkIsAboveSelf.Checked && true);
                            storeById.IsStoreDelive    = (this.chkIsStoreDelive.Checked && true);
                            storeById.Introduce        = this.editDescription.Text;
                            if (this.chkIsStoreDelive.Checked)
                            {
                                storeById.ServeRadius   = num;
                                storeById.MinOrderPrice = num3;
                                storeById.StoreFreight  = num2;
                            }
                            else
                            {
                                storeById.ServeRadius   = 0.0;
                                storeById.MinOrderPrice = null;
                                storeById.StoreFreight  = null;
                            }
                            storeById.CommissionRate = num4;
                            List <string> list = RegionHelper.GetFullRegion(this.dropRegion.GetSelectedRegionId().Value, ",", true, 0).Split(',').Take(3)
                                                 .ToList();
                            list.ForEach(delegate(string c)
                            {
                                Address = Address.Replace(c, string.Empty);
                            });
                            IList <string> list2  = new List <string>();
                            string         text9  = this.hidUploadImages.Value.Trim();
                            string[]       array3 = text9.Split(',');
                            for (int j = 0; j < array3.Length; j++)
                            {
                                if (!string.IsNullOrEmpty(array3[j]))
                                {
                                    string text10      = Globals.SaveFile("depot", array3[j], "/Storage/master/", true, false, "");
                                    string text11      = base.Request.MapPath(text10);
                                    string virtualPath = HiContext.Current.GetStoragePath() + "/depot/thum_" + text10.Substring(text10.LastIndexOf("/") + 1);
                                    if (!File.Exists(text11))
                                    {
                                        this.ShowMsg("缩略图文件夹未创建,请联系管理员", false);
                                        return;
                                    }
                                    ResourcesHelper.CreateThumbnail(text11, base.Request.MapPath(virtualPath), 160, 160);
                                    list2.Add(text10);
                                }
                            }
                            if (list2.Count == 0)
                            {
                                this.ResetForm(storeById.StoreId);
                                this.ShowMsg("logo已失效或未上传,请上传门店logo", false);
                            }
                            else if (ManagerHelper.Update(managerInfo))
                            {
                                int value = this.dropRegion.GetSelectedRegionId().Value;
                                storeById.StoreName      = text3;
                                storeById.RegionId       = value;
                                storeById.TopRegionId    = RegionHelper.GetCityId(value);
                                storeById.Tel            = text;
                                storeById.Address        = Address;
                                storeById.ContactMan     = text2;
                                storeById.StoreImages    = ((list2.Count == 0) ? string.Empty : string.Join(",", list2.ToArray()));
                                storeById.Longitude      = Math.Round(double.Parse(string.IsNullOrEmpty(this.hfLongitude.Value) ? "0" : this.hfLongitude.Value), 6);
                                storeById.Latitude       = Math.Round(double.Parse(string.IsNullOrEmpty(this.hfLatitude.Value) ? "0" : this.hfLatitude.Value), 6);
                                storeById.FullRegionPath = RegionHelper.GetFullPath(value, true);
                                StoresHelper.UpdateStore(storeById);
                                HiCache.Remove("DataCache-StoreInfoDataKey");
                                if (dictionary.Count > 0 && this.chkIsStoreDelive.Checked)
                                {
                                    StoresHelper.AddDeliveryScope(this.storeId, dictionary);
                                }
                                else
                                {
                                    StoresHelper.DeleteDevlieryScope(this.storeId);
                                }
                                if (!string.IsNullOrEmpty(this.txtStoreTag.Text.Trim()))
                                {
                                    IList <int> list3  = new List <int>();
                                    string      text12 = this.txtStoreTag.Text.Trim();
                                    string[]    array4 = null;
                                    array4 = ((!text12.Contains(",")) ? new string[1]
                                    {
                                        text12
                                    } : text12.Split(','));
                                    string[] array5 = array4;
                                    foreach (string value2 in array5)
                                    {
                                        list3.Add(Convert.ToInt32(value2));
                                    }
                                    StoresHelper.DeleteStoreTags(this.storeId);
                                    StoresHelper.BindStoreTags(this.storeId, list3);
                                }
                                else
                                {
                                    StoresHelper.DeleteStoreTags(this.storeId);
                                }
                                HiCache.Remove($"DataCache-StoreStateCacheKey-{storeById.StoreId}");
                                SiteSettings masterSettings = SettingsManager.GetMasterSettings();
                                if (masterSettings.OpenDadaLogistics)
                                {
                                    DataTable dataTable = DepotHelper.SynchroDadaStoreList(this.storeId);
                                    if (dataTable != null && dataTable.Rows.Count > 0)
                                    {
                                        for (int l = 0; l < dataTable.Rows.Count; l++)
                                        {
                                            string station_name    = dataTable.Rows[l]["StoreName"].ToNullString();
                                            int    business        = 5;
                                            string city_name       = dataTable.Rows[l]["CityName"].ToNullString().Replace("市", "");
                                            string area_name       = dataTable.Rows[l]["RegionName"].ToNullString();
                                            string station_address = dataTable.Rows[l]["Address"].ToNullString();
                                            double lng             = dataTable.Rows[l]["Longitude"].ToDouble(0);
                                            double lat             = dataTable.Rows[l]["Latitude"].ToDouble(0);
                                            string contact_name    = dataTable.Rows[l]["ContactMan"].ToNullString();
                                            string phone           = dataTable.Rows[l]["Tel"].ToNullString();
                                            string text13          = dataTable.Rows[l]["StoreId"].ToNullString();
                                            string text14          = DadaHelper.shopUpdate(masterSettings.DadaSourceID, this.storeId.ToString(), "", station_name, business, city_name, area_name, station_address, lng, lat, contact_name, phone, -1);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private void QueryDeliverFee(HttpContext context)
        {
            StoresInfo   storeById      = StoresHelper.GetStoreById(HiContext.Current.Manager.StoreId);
            string       text           = context.Request["OrderId"].ToNullString();
            SiteSettings masterSettings = SettingsManager.GetMasterSettings();

            if (string.IsNullOrEmpty(text))
            {
                context.Response.Write(this.GetFailResultJson("订单号不能为空"));
            }
            else
            {
                OrderInfo orderInfo = TradeHelper.GetOrderInfo(text);
                if (orderInfo == null)
                {
                    context.Response.Write(this.GetFailResultJson("错误的订单号"));
                }
                else if (orderInfo.StoreId != HiContext.Current.Manager.StoreId)
                {
                    context.Response.Write(this.GetFailResultJson("订单不是此门店的"));
                }
                else if ((orderInfo.OrderStatus != OrderStatus.BuyerAlreadyPaid && (orderInfo.OrderStatus != OrderStatus.WaitBuyerPay || !(orderInfo.Gateway == EnumDescription.GetEnumDescription((Enum)(object)EnumPaymentType.CashOnDelivery, 1)))) || orderInfo.RealShippingModeId == -2)
                {
                    context.Response.Write(this.GetFailResultJson("错误的订单状态"));
                }
                else
                {
                    DataTable dataTable = DepotHelper.SynchroDadaStoreList(storeById.StoreId);
                    if (!orderInfo.ShippingRegion.Contains(dataTable.Rows[0]["CityName"].ToString()))
                    {
                        context.Response.Write(this.GetFailResultJson("配送范围超区,无法配送"));
                    }
                    else
                    {
                        string text2 = "";
                        try
                        {
                            string  value   = DadaHelper.cityCodeList(masterSettings.DadaSourceID);
                            JObject jObject = JsonConvert.DeserializeObject(value) as JObject;
                            JArray  jArray  = (JArray)jObject["result"];
                            foreach (JToken item in (IEnumerable <JToken>)jArray)
                            {
                                if (orderInfo.ShippingRegion.Contains(item["cityName"].ToString()))
                                {
                                    text2 = item["cityCode"].ToString();
                                    break;
                                }
                            }
                        }
                        catch
                        {
                        }
                        if (text2 == "")
                        {
                            context.Response.Write(this.GetFailResultJson("配送范围超区,无法配送"));
                        }
                        else
                        {
                            string shop_no             = orderInfo.StoreId.ToNullString();
                            string orderId             = orderInfo.OrderId;
                            string city_code           = text2;
                            double cargo_price         = orderInfo.GetTotal(false).F2ToString("f2").ToDouble(0);
                            int    is_prepay           = 0;
                            long   expected_fetch_time = Globals.DateTimeToUnixTimestamp(DateTime.Now.AddMinutes(15.0));
                            string shipTo  = orderInfo.ShipTo;
                            string address = orderInfo.Address;
                            string latLng  = orderInfo.LatLng;
                            if (string.IsNullOrWhiteSpace(latLng))
                            {
                                ShippingAddressInfo shippingAddress = MemberProcessor.GetShippingAddress(orderInfo.ShippingId);
                                latLng = shippingAddress.LatLng;
                            }
                            double  receiver_lat      = latLng.Split(',')[0].ToDouble(0);
                            double  receiver_lng      = latLng.Split(',')[1].ToDouble(0);
                            string  callback          = Globals.FullPath("/pay/dadaOrderNotify");
                            string  cellPhone         = orderInfo.CellPhone;
                            string  telPhone          = orderInfo.TelPhone;
                            bool    isQueryDeliverFee = true;
                            string  value2            = DadaHelper.addOrder(masterSettings.DadaSourceID, shop_no, orderId, city_code, cargo_price, is_prepay, expected_fetch_time, shipTo, address, receiver_lat, receiver_lng, callback, cellPhone, telPhone, -1.0, -1.0, -1.0, -1.0, -1L, "", -1, -1.0, -1, -1L, "", "", "", false, isQueryDeliverFee);
                            JObject jObject2          = JsonConvert.DeserializeObject(value2) as JObject;
                            string  a = jObject2["status"].ToString();
                            if (a == "success")
                            {
                                JObject jObject3 = JsonConvert.DeserializeObject(jObject2["result"].ToString()) as JObject;
                                string  s        = JsonConvert.SerializeObject(new
                                {
                                    Result = new
                                    {
                                        Status     = "SUCCESS",
                                        distance   = jObject3["distance"].ToNullString(),
                                        fee        = "预计运费:¥" + jObject3["fee"].ToNullString(),
                                        deliveryNo = jObject3["deliveryNo"].ToNullString()
                                    }
                                });
                                context.Response.Write(s);
                                context.Response.End();
                            }
                            else
                            {
                                context.Response.Write(this.GetFailResultJson(jObject2["msg"].ToNullString()));
                            }
                        }
                    }
                }
            }
        }