自动拍单逻辑优化
This commit is contained in:
1 parent
107bf82f97
commit
ec02e2a0e4
6 files changed
+107
-17
No files matched your search
@@ -28,9 +28,11 @@ namespace _29WxOrderWpf
|
||||
GlobalConfig.lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
|
||||
|
||||
// 自动拍单支付宝密码
|
||||
GlobalConfig.AlipayPassword = ConfigHelper.LoadConfig<List<string>>("ali_pay_password")?.FirstOrDefault();
|
||||
if (GlobalConfig.AlipayPassword == null)
|
||||
GlobalConfig.AlipayPassword = "";
|
||||
var alipayPassword = ConfigHelper.LoadConfig<List<string>>("ali_pay_password")?.FirstOrDefault() ?? "";
|
||||
|
||||
GlobalConfig.AutoBuyConfig = ConfigHelper.LoadConfig<AutoBuyConfig>("auto_buy_config");
|
||||
if (GlobalConfig.AutoBuyConfig == null)
|
||||
GlobalConfig.AutoBuyConfig = new AutoBuyConfig() { AlipayPassword = alipayPassword, IsLimitMinProfit = false, MinProfit = 0 };
|
||||
|
||||
new WxOrder.Framework.Startup();
|
||||
}
|
||||
|
||||
@@ -92,10 +92,45 @@
|
||||
FontSize="12"
|
||||
Style="{StaticResource BasePageButtonLightStyle}"
|
||||
Visibility="Visible" />
|
||||
<TextBlock
|
||||
Margin="70,128,70,128"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
TextWrapping="Wrap"><Run Text="说明:"/><Run Text="自动拍单支持已创建sku关联的商品"/><Run Language="zh-cn" Text="。"/><LineBreak/><Run Text=" "/><Run Text="请保存支付宝支付密码(仅记录在本地)供自动拍单支付,首次自动拍单前请手动拍单一次以缓存支付宝Cookie。"/></TextBlock>
|
||||
<WrapPanel Margin="70,120,70,70" VerticalAlignment="Top">
|
||||
<CheckBox
|
||||
x:Name="chkMinProfitAutoBuy"
|
||||
Margin="2,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
BorderBrush="{StaticResource mainColorBrush}"
|
||||
Click="chkMinProfitAutoBuy_Click"
|
||||
Content="当利润低于如下金额时跳过自动拍单:"
|
||||
FontSize="12" />
|
||||
<TextBox
|
||||
x:Name="txtMinProfitAutoBuy"
|
||||
Width="54"
|
||||
Height="22"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
d:Text="0.0"
|
||||
d:Visibility="Visible"
|
||||
TextChanged="txtMinProfitAutoBuy_TextChanged" />
|
||||
<TextBlock Margin="3,0,0,0" VerticalAlignment="Center">
|
||||
元
|
||||
</TextBlock>
|
||||
<Button
|
||||
x:Name="btnSaveMinProfitAutoBuy"
|
||||
Width="Auto"
|
||||
Height="22"
|
||||
MinWidth="48"
|
||||
Margin="5,0"
|
||||
Padding="4,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Click="btnSaveMinProfitAutoBuy_Click"
|
||||
Content="确定修改"
|
||||
FontSize="12"
|
||||
Style="{StaticResource BasePageButtonStyle}"
|
||||
Visibility="Visible" />
|
||||
|
||||
</WrapPanel>
|
||||
<TextBlock Margin="70,160,70,70" TextWrapping="Wrap"><Run Text="说明:" /><Run Text="自动拍单支持已创建sku关联的商品" /><Run Language="zh-cn" Text="。" /><LineBreak /><Run Text=" " /><Run Text="请保存支付宝支付密码(仅记录在本地)供自动拍单支付,首次自动拍单前请手动拍单一次以缓存支付宝Cookie。" /></TextBlock>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -2,6 +2,7 @@
|
||||
using AllBase.Helper;
|
||||
using AllBase.Model.DBModel;
|
||||
using NaiBa.Util;
|
||||
using NaiBa.Util.Extension;
|
||||
using NaiBa.Util.Helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -33,21 +34,23 @@ namespace _29WxOrderWpf.Views
|
||||
|
||||
private void AutoBuyInstructionView_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.pbxPassWord.Password = DataOpenSSL.DecryptString(GlobalConfig.AlipayPassword);
|
||||
this.pbxPassWord.Password = DataOpenSSL.DecryptString(GlobalConfig.AutoBuyConfig.AlipayPassword);
|
||||
this.chkMinProfitAutoBuy.IsChecked = GlobalConfig.AutoBuyConfig.IsLimitMinProfit;
|
||||
this.txtMinProfitAutoBuy.Text = "" + GlobalConfig.AutoBuyConfig.MinProfit * 0.01m;
|
||||
}
|
||||
|
||||
private void btnSaveAliPass_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GlobalConfig.AlipayPassword = DataOpenSSL.EncryptString(this.pbxPassWord.Password);
|
||||
ConfigHelper.SaveConfig("ali_pay_password", new List<string>() { GlobalConfig.AlipayPassword });
|
||||
GlobalConfig.AutoBuyConfig.AlipayPassword = DataOpenSSL.EncryptString(this.pbxPassWord.Password);
|
||||
ConfigHelper.SaveConfig("auto_buy_config", GlobalConfig.AutoBuyConfig);
|
||||
BaseMsgWindow.ShowInfo("密码保存成功!");
|
||||
}
|
||||
|
||||
private void btnClear_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.pbxPassWord.Password = "";
|
||||
GlobalConfig.AlipayPassword = "";
|
||||
ConfigHelper.SaveConfig("ali_pay_password", new List<string>() { GlobalConfig.AlipayPassword });
|
||||
GlobalConfig.AutoBuyConfig.AlipayPassword = "";
|
||||
ConfigHelper.SaveConfig("auto_buy_config", GlobalConfig.AutoBuyConfig);
|
||||
BaseMsgWindow.ShowInfo("密码已清除!");
|
||||
}
|
||||
|
||||
@@ -70,5 +73,23 @@ namespace _29WxOrderWpf.Views
|
||||
if (txtPassWord.Text != pbxPassWord.Password)
|
||||
pbxPassWord.Password = txtPassWord.Text;
|
||||
}
|
||||
|
||||
private void txtMinProfitAutoBuy_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void chkMinProfitAutoBuy_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnSaveMinProfitAutoBuy_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GlobalConfig.AutoBuyConfig.IsLimitMinProfit = chkMinProfitAutoBuy.IsChecked ?? false;
|
||||
GlobalConfig.AutoBuyConfig.MinProfit = (txtMinProfitAutoBuy.Text.ParseToDecimal() * 100).ParseToInt();
|
||||
ConfigHelper.SaveConfig("auto_buy_config", GlobalConfig.AutoBuyConfig);
|
||||
BaseMsgWindow.ShowInfo("自动拍单最低利润配置成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,8 @@ namespace AllBase.Helper
|
||||
/// <summary>
|
||||
/// 支付宝密码
|
||||
/// </summary>
|
||||
public static string AlipayPassword { get; set; }
|
||||
//public static string AlipayPassword { get; set; }
|
||||
public static AutoBuyConfig AutoBuyConfig { get; set; }
|
||||
/// <summary>
|
||||
/// 默认退货详细地址
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AllBase.Model.Config
|
||||
{
|
||||
public class AutoBuyConfig
|
||||
{
|
||||
public string AlipayPassword { get; set; } = "";
|
||||
/// <summary>
|
||||
/// 是否限制自动拍单最小利润
|
||||
/// </summary>
|
||||
public bool IsLimitMinProfit { get; set; }
|
||||
public int MinProfit { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -217,7 +217,7 @@ namespace TemuKJD.ToolForms
|
||||
this.txtShopGoodsName.Text = orderItem.title;
|
||||
this.txtShopSpecName.Text = orderItem.sku_attr_str;
|
||||
this.txtShopOrderItemCnt.Text = orderItem.sku_cnt.ParseToString();
|
||||
this.txtShopOrderItemPrice.Text = (orderItem.real_price * 0.01m).ParseToString();
|
||||
this.txtShopOrderItemPrice.Text = (orderItem.real_price * 0.01m + orderItem.ItemOrder?.postage_price * 0.01m / orderItem.ItemOrder?.orderItems?.Count).ParseToString();
|
||||
|
||||
this.txtOrderId.Text = orderItem.order_id;
|
||||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ErpShopId == orderItem.shop_id.ParseToString());
|
||||
@@ -420,7 +420,7 @@ namespace TemuKJD.ToolForms
|
||||
{
|
||||
await (Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
Thread.Sleep(6000);
|
||||
if (!this.IsClose && this.Created)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
@@ -535,6 +535,17 @@ namespace TemuKJD.ToolForms
|
||||
var buyCnt = BaseRegex.GetIntJson(ref data, "goods_number");
|
||||
var buyPrice = BaseRegex.GetIntJson(ref data, "pay_price");
|
||||
|
||||
if (IsAutoBuy && GlobalConfig.AutoBuyConfig.IsLimitMinProfit)
|
||||
{
|
||||
var salePrice = orderItem.real_price * 0.01m + orderItem.ItemOrder?.postage_price * 0.01m / orderItem.ItemOrder?.orderItems?.Count;
|
||||
var profit = salePrice - buyPrice * 0.01m;
|
||||
var limitProfit = GlobalConfig.AutoBuyConfig.MinProfit * 0.01m;
|
||||
if (profit < limitProfit)
|
||||
{
|
||||
throw new Exception("拍单利润" + profit + "小于设定的数值 " + limitProfit + ",跳过当前订单");
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.Created)
|
||||
return;
|
||||
Invoke(new Action(() =>
|
||||
@@ -709,7 +720,7 @@ namespace TemuKJD.ToolForms
|
||||
ts2 = await EvaluateJsBuyTagNameAndInnerHtml("div", "输入支付密码");
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(500, 1000));
|
||||
foreach (var c in DataOpenSSL.DecryptString(GlobalConfig.AlipayPassword))
|
||||
foreach (var c in DataOpenSSL.DecryptString(GlobalConfig.AutoBuyConfig.AlipayPassword))
|
||||
{
|
||||
CEFBrowser.SimulateInputChar(host, c);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user