Files
KJD/TEMUKJD/KJDForms/ShopForms/FreightTemplateAddForm.cs
T

338 lines
13 KiB
C#

using AllBase;
using AllBase.Helper;
using AllBase.Model.Result;
using TemuKJD.Extension;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using Work;
namespace TemuKJD.KJDForms.ShopForms
{
/// <summary>
/// 运费模板管理窗口
/// </summary>
public partial class FreightTemplateAddForm : Form
{
public static List<string> ids = new List<string>();
public FreightTemplateAddForm()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
string template_name = txtTemplate.Text.ToString();
int num =0;
decimal price = 0;
int addnum = 0;
decimal addPrcie = 0;
if (rbcost0.Checked)
{
num = Convert.ToInt32(txtNum.Text);
price = Convert.ToDecimal(txtPrice.Text);
addnum = Convert.ToInt32(txtAddNum.Text);
addPrcie = Convert.ToDecimal(txtAddPrcie.Text);
}
var prov = cobProvince.SelectedItem as ListItem;
int pid = int.Parse(prov.Value);
var city = cobCity.SelectedItem as ListItem;
int cid = int.Parse(city.Value);
ids = dgvShop.Rows.Cast<DataGridViewRow>()
.Where(r1 => r1.Cells["colSelect"].Value.ToString().ToLower() == "true")
.Select(r2 => r2.Cells["colShopId"].Value?.ToString()).ToList();
Task.Run(()=> {
for (int i = 0; i < GlobalConfig.ShopLoginList.Count; i++)
{
var shop = GlobalConfig.ShopLoginList[i];
if (!ids.Any(id => id == shop.ShopId) || shop.LoginStatus != "登录成功")
continue;
string data = "template_name=" + template_name + "&product_province=" + pid + "&product_city=" + cid;
//固定运费
if (rbcost1.Checked)
{
decimal fix = Convert.ToDecimal(txtFixCost.Text);
data += "&rule_type=1&calculate_type=2&fixed_amount=" + fix * 100 + "&appid=1&__token=" + shop.ShopToken + "&_bid=ffa_order&aid=4272&_lid=478386445810";
}
//卖家包邮
if (rbcost2.Checked)
{
data += "&rule_type=2&calculate_type=2&fixed_amount=0&appid=1&__token=" + shop.ShopToken + "&_bid=ffa_order&aid=4272&_lid=478386445810";
}
// 阶梯计价
if (rbcost0.Checked)
{
if (rbtype1.Checked)
{
data += "&rule_type=0&calculate_type=2&fixed_amount=0&columns[0][calculate_type]=2&columns[0][first_weight]=&columns[0][first_weight_price]=&columns[0][first_num]=" + num
+ "&columns[0][first_num_price]=" + price
+ "&columns[0][add_weight]=&columns[0][add_weight_price]=&columns[0][add_num]=" + addnum
+ "&columns[0][add_num_price]=" + addPrcie
+ "&columns[0][is_default]=1&columns[0][is_limited]=0&columns[0][is_over_free]=0&appid=1&__token=" + shop.ShopToken
+ "&_bid=ffa_order&aid=4272&_lid=390305557852";
}
else
{
data += "&rule_type=0&calculate_type=1&fixed_amount=0&columns[0][calculate_type]=1&columns[0][first_weight]=" + num
+ "&columns[0][first_weight_price]=" + price
+ "&columns[0][first_num]=&columns[0][first_num_price]=&columns[0][add_weight]=" + addnum
+ "&columns[0][add_weight_price]=" + addPrcie + "&columns[0][add_num]=&columns[0][add_num_price]=&columns[0][is_default]=1&columns[0][is_limited]=0&columns[0][is_over_free]=0&appid=1&__token=" + shop.ShopToken
+ "&_bid=ffa_order&aid=4272&_lid=482676755100";
}
}
//提交
string url = "https://fxg.jinritemai.com/freight/template/createShopFreightTemplate?appid=1&__token=" + shop.ShopToken
+ "&_bid=ffa_order&aid=4272&_lid=390305621361&_signature=" + shop.Signature + "";
string refere = "https://fxg.jinritemai.com/ffa/morder/logistics/freight-edit";
data = HttpUtility.UrlEncode(data, Encoding.UTF8).Replace("%3d", "=").Replace("%26", "&");
string html = GetPostTaobaoHtml.UploadFxgPost(url, refere, true, data, shop.Cookies);
long template_id = BaseRegex.GetLongJson(ref html, "template_id");
if (template_id>0)
{
RefreshDataGridView(shop, "运费模板设置成功");
RefreshLog(shop.ShopAccount+"运费模板设置成功");
}
else
{
RefreshDataGridView(shop, "运费模板设置失败");
RefreshLog(shop.ShopAccount + "运费模板设置失败");
}
}
});
}
int count = 0;
public void RefreshDataGridView(DouShopLoginInfo shop,string message)
{
this.Invoke(new Action(() =>
{
count++;
for (int i = 0; i < dgvShop.Rows.Count; i++)
{
if (shop.ShopId== dgvShop.Rows[i].Cells["colShopId"].Value.ToString())
{
dgvShop.Rows[i].Cells["colStatus"].Value = message;
break;
}
}
}));
}
public void RefreshLog(string message)
{
Task.Run(() =>
{
if (this.Created)
{
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = message;
this.statusBar.pgbTaskProgress.Maximum = ids.Count;
this.statusBar.pgbTaskProgress.Value = count;
this.statusBar.pgbTaskProgress.Text = count + "/" + ids.Count;
}));
}
});
}
private void rbcost1_CheckedChanged(object sender, EventArgs e)
{
if (rbcost1.Checked)
{
panel1.Visible = true;
}
else
{
panel1.Visible = false;
}
}
private void rbcost0_CheckedChanged(object sender, EventArgs e)
{
if (rbcost0.Checked)
{
groupTemplate.Visible = true;
}
else
{
groupTemplate.Visible = false;
}
}
private void rbcost2_CheckedChanged(object sender, EventArgs e)
{
if (rbcost2.Checked)
{
groupTemplate.Visible = false;
panel1.Visible = false;
}
}
private void rbtype1_CheckedChanged(object sender, EventArgs e)
{
if (rbtype1.Checked)
{
label5.Text= "件以内,";
label7.Text = "件,增加运费";
}
}
private void rbtype2_CheckedChanged(object sender, EventArgs e)
{
if (rbtype2.Checked)
{
label5.Text = "kg以内,";
label7.Text = "kg,增加运费";
}
}
private void cobProvince_SelectedIndexChanged(object sender, EventArgs e)
{
var area = cobProvince.SelectedItem as ListItem;
int id = int.Parse(area.Value);
var shop = GlobalConfig.ShopLoginList.Where(s=>s.LoginStatus=="登录成功").FirstOrDefault();
if (shop == null)
return;
List<ListItem> list = new List<ListItem>();
//获取市区
string url = "https://fxg.jinritemai.com/common/index/getCity?version=1&id=" + id + "&appid=1&__token=" + shop?.ShopToken
+ "&_bid=ffa_order&aid=4272&_lid=368236870254&_signature=" + shop?.Signature + "";
string refere = "https://fxg.jinritemai.com/ffa/morder/logistics/freight-edit";
string html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, shop?.Cookies);
long catId = BaseRegex.GetLongJson(ref html, "id");
var m = BaseRegex.GetMatchRegex(ref html, @"{""city_id""[\w\W]+?}");
for (int i = 0; m != null && i < m.Count; i++)
{
string temp = m[i].Groups[0].Value;
long pid = BaseRegex.GetLongJson(ref temp, "city_id");
string pname = BaseRegex.GetStringJson(ref temp, "city");
list.Add(new ListItem(pname,pid.ToString()));
}
cobCity.DisplayMember = "Text";
cobCity.ValueMember = "Value";
cobCity.DataSource = list;
}
private void ShopFreightTemplateForm_Load(object sender, EventArgs e)
{
this.dgvShop.AddSelectorColumn("colSelect");
ReadLoad();
loadArea();
}
string temp = "";
public void loadArea()
{
//var shop = GlobalConfig.DouShopLoginList[0];
//List<ListItem> list = new List<ListItem>();
//cobProvince.Items.Clear();
//string url = "https://fxg.jinritemai.com/common/index/getProvince?version=1&only_mainland=1&appid=1&__token=" + shop.ShopToken
// + "&_bid=ffa_order&aid=4272&_lid=468369728881&_signature=" + shop.Signature;
//string refere = "https://fxg.jinritemai.com/ffa/morder/logistics/freight-edit";
//string html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, shop.Cookies);
//var m = BaseRegex.GetMatchRegex(ref html, @"{""province_id""[\w\W]+?}");
//for (int i = 0; m != null && i < m.Count; i++)
//{
// string item = m[i].Groups[0].Value;
// long pid = BaseRegex.GetLongJson(ref item, "province_id");
// string pname = BaseRegex.GetStringJson(ref item, "province");
// list.Add(new ListItem(pname, pid.ToString()));
// temp += pname+":"+pid+"\r\n";
//}
List<ListItem> list = new List<ListItem>();
List<string> striparr = prov.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
for (int i = 0; i < striparr.Count; i++)
{
string item = striparr[i];
string pname = item.Split(':')[0];
string pid= item.Split(':')[1];
list.Add(new ListItem(pname, pid));
}
cobProvince.DisplayMember = "Text";
cobProvince.ValueMember = "Value";
cobProvince.DataSource = list;
}
public void ReadLoad()
{
for (int i = 0; i < GlobalConfig.ShopLoginList.Count; i++)
{
var shop = GlobalConfig.ShopLoginList[i];
dgvShop.Rows.Add(false, shop.ShopId, shop.ShopAccount, 0, shop.LoginStatus);
}
}
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
//string name = dgvShop.Columns[e.ColumnIndex].HeaderText;
string colId = dgvShop.Columns[e.ColumnIndex].Name;
if (colId == "colSelect")
{
bool ok = !bool.Parse(dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value.ToString());
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = ok;
}
//if (name == "全选")
//{
// bool ok = !bool.Parse(dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value.ToString());
// string shopName = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ToString();
// dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = ok;
// if (ok)
// {
// ids.Add(shopName);
// }
// else
// {
// if (ids.Select(id => id == shopName).FirstOrDefault())
// {
// ids.Remove(shopName);
// }
// }
//}
}
string prov = @"安徽省:34
北京市:11
重庆市:50
福建省:35
广东省:44
甘肃省:62
广西壮族自治区:45
贵州省:52
河北省:13
湖北省:42
黑龙江省:23
河南省:41
湖南省:43
海南省:46
吉林省:22
江苏省:32
江西省:36
辽宁省:21
内蒙古自治区:15
宁夏回族自治区:64
青海省:63
四川省:51
山东省:37
上海市:31
山西省:14
陕西省:61
天津市:12
新疆维吾尔自治区:65
西藏自治区:54
云南省:53
浙江省:33";
}
}