1022 lines
50 KiB
C#
1022 lines
50 KiB
C#
using Api.Framework;
|
||
using Api.Framework.Cps;
|
||
using Api.Framework.Enums;
|
||
using Api.Framework.Model;
|
||
using Api.Framework.Tools;
|
||
using CsharpHttpHelper;
|
||
using DevExpress.XtraEditors;
|
||
using FLSystem.Properties;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using UI.Framework.Forms;
|
||
|
||
namespace FLSystem.Forms
|
||
{
|
||
public partial class convert_tool_control : XtraUserControl
|
||
{
|
||
public convert_tool_control()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void convert_tool_control_Load(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.Disposed += Control_Disposed;
|
||
this.comboBox1.SelectedIndex = this.comboBox2.SelectedIndex = this.comboBox3.SelectedIndex = 0;
|
||
|
||
var session = ApiClient.GetSession();
|
||
#region 阿里妈妈转链基础数据加载
|
||
var tbadzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.阿里妈妈 && f.custom_type == Resources.ConvertToolSoftwareType);
|
||
if (tbadzone != null)//数据库中存在的情况
|
||
{
|
||
hyperlinkLabelControl1.Text = tbadzone.adzone_name;
|
||
hyperlinkLabelControl1.Tag = tbadzone;
|
||
}
|
||
#endregion
|
||
|
||
#region 淘礼金
|
||
|
||
var cpsmembers = CpsClient.Members.Where(f => f.cpstype == CpsType.阿里妈妈 && f.is_valid).ToList();
|
||
List<object> cpsList = new List<object>();
|
||
cpsList.Add("手动填写数据");
|
||
for (int i = 0; i < cpsmembers.Count; i++)
|
||
{
|
||
cpsList.Add($"{cpsmembers[i].username}({cpsmembers[i].usernick})");
|
||
}
|
||
this.comboBoxEdit1.Properties.Items.AddRange(cpsList);
|
||
|
||
comboBoxEdit1.SelectedIndex = 0;
|
||
|
||
dateTimePicker2.Value = DateTime.Now;
|
||
dateTimePicker2.Value = DateTime.Now.AddDays(1);
|
||
|
||
#endregion
|
||
|
||
#region 京东
|
||
var jdadzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.京东联盟 && f.custom_type == Resources.ConvertToolSoftwareType);
|
||
if (jdadzone != null)//数据库中存在的情况
|
||
{
|
||
hyperlinkLabelControl2.Text = jdadzone.adzone_name;
|
||
hyperlinkLabelControl2.Tag = jdadzone;
|
||
}
|
||
#endregion
|
||
|
||
#region 拼多多
|
||
var pddadzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.多多进宝 && f.custom_type == Resources.ConvertToolSoftwareType);
|
||
if (pddadzone != null)//数据库中存在的情况
|
||
{
|
||
hyperlinkLabelControl3.Text = pddadzone.adzone_name;
|
||
hyperlinkLabelControl3.Tag = pddadzone;
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBox.Show($"{ex.Message}", "系统异常", MessageBoxButtons.OK);
|
||
}
|
||
}
|
||
private void Control_Disposed(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void textEdit1_Click(object sender, EventArgs e)
|
||
{
|
||
if (sender is TextEdit)
|
||
{
|
||
var edit = sender as TextEdit;
|
||
edit.SelectAll();
|
||
if (!string.IsNullOrWhiteSpace(edit.Text))
|
||
Clipboard.SetDataObject(edit.Text);
|
||
}
|
||
}
|
||
|
||
private void textEdit1_Click_1(object sender, EventArgs e)
|
||
{
|
||
if (sender is TextEdit)
|
||
{
|
||
var edit = sender as TextEdit;
|
||
edit.SelectAll();
|
||
}
|
||
}
|
||
|
||
private async void simpleButton1_Click(object sender, EventArgs e)
|
||
{
|
||
_ControlEnabled();
|
||
var t1 = Task.Run(() =>
|
||
{
|
||
if (hyperlinkLabelControl1.Tag == null) throw new Exception("请设置推广位");
|
||
if (string.IsNullOrWhiteSpace(textEdit1.Text)) throw new Exception("请填写要解析链接或者淘口令");
|
||
|
||
var twg = hyperlinkLabelControl1.Tag as fl_adzone_info;
|
||
|
||
var tb_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.阿里妈妈 && f.username == twg.adzone_pid_cps_name);
|
||
if (tb_cps == null) throw new Exception("推广位异常");
|
||
AlimamaApi api = CpsClient.CreateAlimamaRequest(tb_cps);
|
||
|
||
var tbAnalysis = new TBHelper.TbAnalysis();
|
||
var pid_split = twg.adzone_pid.Split('_');
|
||
|
||
var item_id = string.Empty;
|
||
try
|
||
{
|
||
item_id = tbAnalysis.FindItemIdByUrlAndTklAndMkl(textEdit1.Text, api, pid_split);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw new Exception("无法解析宝贝信息!");
|
||
}
|
||
if (string.IsNullOrWhiteSpace(item_id)) throw new Exception("无法解析宝贝信息!");
|
||
|
||
var turnItem = api.TurnItemId(item_id, tbAnalysis.activityId, pid_split[3], pid_split[2], "2");
|
||
|
||
//淘口令的前/后符号有没有设置.有设置将替换掉
|
||
var tkl = tbAnalysis.ReplaceTklModifier(turnItem.BuyPass);
|
||
|
||
//coupon_click_url = tbAnalysis.FindShortUrlBySrcUrl(coupon_click_url, api);
|
||
|
||
//var temp_url = api.ComposeTbClick(item_id, pict_url, tkl, tklInfo.isoUrl, true, twg.adzone_pid, ApiClient.Setting.SystemConfig.ZjyComposeType == ComposeType.有推荐商品);//中间页地址
|
||
|
||
#region 将内容填写到控件中
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
try
|
||
{
|
||
textEdit2.Text = turnItem.ItemUrl;//商品链接
|
||
textEdit3.Text = turnItem.ItemTitle;//商品标题
|
||
textEdit4.Text = turnItem.Price.ToString("0.00");//商品单价
|
||
textEdit5.Text = turnItem.CouponPrice.ToString("0.00");//优惠券金额
|
||
textEdit6.Text = (turnItem.CommissionRatio * 100m).ToString("0.00");//返利比例
|
||
textEdit8.Text = turnItem.CommissionUseCouponMoney.ToString("0.00");//券后返利
|
||
textEdit9.Text = turnItem.CommissionUnUseCouponMoney.ToString("0.00");//弃券返利
|
||
textEdit11.Text = tkl;//生成淘口令
|
||
textEdit37.Text = turnItem.BuyUrl;//短连接
|
||
textEdit10.Text = ApiClient.GetQRImage(turnItem.ItemTitle, turnItem.Price.ToString("0.00"), turnItem.CouponPrice.ToString(), turnItem.UseCouponPrice.ToString("0.00"), turnItem.ImageUrl, turnItem.ZJYUrl, comboBox1.SelectedIndex == 0 ? ApiClient.QrImageType.模板A : ApiClient.QrImageType.模板B);//合成优惠券图
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "操作异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}));
|
||
|
||
#region 获取预览图
|
||
StringBuilder strb = new StringBuilder();
|
||
int num = 0;
|
||
Next:
|
||
HttpItem httpItem = new HttpItem()
|
||
{
|
||
URL = @"https://item.taobao.com/item.htm?id=" + item_id,//宝贝的链接
|
||
Method = "get",
|
||
IsToLower = false,
|
||
Timeout = 10000,
|
||
ReadWriteTimeout = 10000,
|
||
Allowautoredirect = true,
|
||
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",
|
||
ContentType = "application/x-www-form-urlencoded"
|
||
};
|
||
HttpHelper http = new HttpHelper();
|
||
var result = http.GetHtml(httpItem);
|
||
|
||
if (result != null && result.Html == "操作超时" && num <= 3)
|
||
{
|
||
num++;
|
||
goto Next;
|
||
}
|
||
var regs = Regex.Matches(result.Html, @"<a href=""#""><img ([^=]+?)=""(?<商品预览图>.+?.jpg)_([^""]*?)""");
|
||
|
||
if (regs.Count != 0)
|
||
{
|
||
strb.Length = 0;
|
||
var shopIcon = string.Empty;
|
||
var QRCodeUrl = string.Empty;//获取其中一张图片用于合成二维码
|
||
for (int i = 0; i < regs.Count; i++)
|
||
{
|
||
var previewPic = regs[i].Groups["商品预览图"].Value;
|
||
if (!previewPic.StartsWith("http"))
|
||
{
|
||
previewPic = $"http:{previewPic}";
|
||
if (string.IsNullOrEmpty(shopIcon)) shopIcon = previewPic;
|
||
}
|
||
strb.AppendLine(previewPic);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
memoEdit1.Text = strb.ToString();//商品预览图
|
||
}));
|
||
#endregion
|
||
|
||
});
|
||
|
||
try
|
||
{
|
||
await t1;
|
||
}
|
||
catch (global::System.Exception ex)
|
||
{
|
||
XtraMessageBox.Show($"{ex.Message}", "系统异常", MessageBoxButtons.OK);
|
||
}
|
||
|
||
_ControlEnabled(true);
|
||
}
|
||
|
||
private void _ControlEnabled(bool flag = false)
|
||
{
|
||
simpleButton1.Enabled = hyperlinkLabelControl1.Enabled = comboBox1.Enabled = flag;
|
||
}
|
||
|
||
private void hyperlinkLabelControl1_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.阿里妈妈);
|
||
if (tgwObj != null)
|
||
{
|
||
var tgw = tgwObj as Tuiguangwei;
|
||
var session = ApiClient.GetSession();
|
||
|
||
var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.阿里妈妈 && f.custom_type == Resources.ConvertToolSoftwareType);
|
||
if (adzone != null)//数据库中存在的情况
|
||
{
|
||
adzone.adzone_pid_cps_name = tgw.Member.username;
|
||
adzone.adzone_pid = tgw.Pid;
|
||
adzone.adzone_name = tgw.Name;
|
||
|
||
session.SaveOrUpdate(adzone);
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
adzone = new fl_adzone_info()
|
||
{
|
||
custom_type = Resources.ConvertToolSoftwareType, //自定义类型
|
||
adzone_name = tgw.Name, //推广位名称
|
||
adzone_pid = tgw.Pid, //推广位pid
|
||
adzone_pid_cps_name = tgw.Member.username, //推广位cps名称
|
||
alliance_id = (int)CpsType.阿里妈妈, //联盟id
|
||
robot_id = 0, //机器人id
|
||
group_id = string.Empty, //群id
|
||
member_id = 0, //私人id
|
||
is_download = false, //不下载
|
||
onoff = false //不禁用
|
||
};
|
||
session.SaveOrUpdate(adzone);
|
||
if (0 == adzone.id)
|
||
throw new Exception("对不起,推广位设置异常,请稍后重试!");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
hyperlinkLabelControl1.Text = adzone.adzone_name;
|
||
hyperlinkLabelControl1.Tag = adzone;
|
||
session.FindAdzoneInfos(true);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBox.Show($"{ex.Message}", "系统异常", MessageBoxButtons.OK);
|
||
}
|
||
}
|
||
|
||
private void hyperlinkLabelControl2_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.京东联盟);
|
||
if (tgwObj != null)
|
||
{
|
||
var tgw = tgwObj as Tuiguangwei;
|
||
var session = ApiClient.GetSession();
|
||
|
||
var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.京东联盟 && f.custom_type == Resources.ConvertToolSoftwareType);
|
||
if (adzone != null)//数据库中存在的情况
|
||
{
|
||
adzone.adzone_pid_cps_name = tgw.Member.username;
|
||
adzone.adzone_pid = tgw.Pid;
|
||
adzone.adzone_name = tgw.Name;
|
||
|
||
session.SaveOrUpdate(adzone);
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
adzone = new fl_adzone_info()
|
||
{
|
||
custom_type = Resources.ConvertToolSoftwareType, //自定义类型
|
||
adzone_name = tgw.Name, //推广位名称
|
||
adzone_pid = tgw.Pid, //推广位pid
|
||
adzone_pid_cps_name = tgw.Member.username, //推广位cps名称
|
||
alliance_id = (int)CpsType.京东联盟, //联盟id
|
||
robot_id = 0, //机器人id
|
||
group_id = string.Empty, //群id
|
||
member_id = 0, //私人id
|
||
is_download = false, //不下载
|
||
onoff = false //不禁用
|
||
};
|
||
session.SaveOrUpdate(adzone);
|
||
if (0 == adzone.id)
|
||
throw new Exception("对不起,推广位设置异常,请稍后重试!");
|
||
}
|
||
catch (Exception ex)
|
||
{ }
|
||
}
|
||
hyperlinkLabelControl2.Text = adzone.adzone_name;
|
||
hyperlinkLabelControl2.Tag = adzone;
|
||
session.FindAdzoneInfos(true);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBox.Show($"{ex.Message}", "系统异常", MessageBoxButtons.OK);
|
||
}
|
||
}
|
||
|
||
private void hyperlinkLabelControl3_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.多多进宝);
|
||
if (tgwObj != null)
|
||
{
|
||
var tgw = tgwObj as Tuiguangwei;
|
||
var session = ApiClient.GetSession();
|
||
|
||
var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.多多进宝 && f.custom_type == Resources.ConvertToolSoftwareType);
|
||
if (adzone != null)//数据库中存在的情况
|
||
{
|
||
adzone.adzone_pid_cps_name = tgw.Member.username;
|
||
adzone.adzone_pid = tgw.Pid;
|
||
adzone.adzone_name = tgw.Name;
|
||
|
||
session.SaveOrUpdate(adzone);
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
adzone = new fl_adzone_info()
|
||
{
|
||
custom_type = Resources.ConvertToolSoftwareType, //自定义类型
|
||
adzone_name = tgw.Name, //推广位名称
|
||
adzone_pid = tgw.Pid, //推广位pid
|
||
adzone_pid_cps_name = tgw.Member.username, //推广位cps名称
|
||
alliance_id = (int)CpsType.多多进宝, //联盟id
|
||
robot_id = 0, //机器人id
|
||
group_id = string.Empty, //群id
|
||
member_id = 0, //私人id
|
||
is_download = false, //不下载
|
||
onoff = false //不禁用
|
||
};
|
||
session.SaveOrUpdate(adzone);
|
||
if (0 == adzone.id)
|
||
throw new Exception("对不起,推广位设置异常,请稍后重试!");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
hyperlinkLabelControl3.Text = adzone.adzone_name;
|
||
hyperlinkLabelControl3.Tag = adzone;
|
||
session.FindAdzoneInfos(true);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBox.Show($"{ex.Message}", "系统异常", MessageBoxButtons.OK);
|
||
}
|
||
}
|
||
|
||
private async void simpleButton2_Click(object sender, EventArgs e)
|
||
{
|
||
hyperlinkLabelControl2.Enabled = simpleButton2.Enabled = comboBox2.Enabled = false;
|
||
var t1 = Task.Run(() =>
|
||
{
|
||
if (hyperlinkLabelControl2.Tag == null) throw new Exception("请设置推广位");
|
||
if (string.IsNullOrWhiteSpace(textEdit24.Text)) throw new Exception("请填写要解析的京东链接");
|
||
|
||
var itemId = JDHelper.GetJingdongItemId(textEdit24.Text);//匹配京东链接获取京东宝贝ID
|
||
if (!string.IsNullOrEmpty(itemId))
|
||
{
|
||
var twg = hyperlinkLabelControl2.Tag as fl_adzone_info;
|
||
JingdongApi api = null;
|
||
var session = ApiClient.GetSession();
|
||
var jd_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.京东联盟 && f.username == twg.adzone_pid_cps_name);
|
||
if (jd_cps == null) throw new Exception("京东联盟推广位异常,请检测后重试!");
|
||
|
||
api = new JingdongApi(jd_cps);
|
||
|
||
var goodInfoResult = api.SendJingdong("jd.union.open.goods.query", new { goodsReqDTO = new { skuIds = new string[] { itemId } } });
|
||
|
||
var goodData = goodInfoResult.ConvertToObj<goodInfo_temp>();
|
||
var goodDatas = goodData.data;
|
||
if (goodDatas == null) throw new Exception("京东无返利信息");
|
||
|
||
foreach (Dictionary<string, object> _goodinfo in goodDatas)
|
||
{
|
||
var goodinfo = _goodinfo.ConvertToObj<GoodsResp>();
|
||
goodinfo.skuName = goodinfo.skuName.Replace("", "").Replace("<", "<").Replace(">", ">").Replace("&", "&").Replace(""", "\"").Replace(" ©", "©");
|
||
|
||
if (goodinfo.commissionInfo.Count != 0)//有佣金
|
||
{
|
||
var isJdSale = goodinfo.isJdSale == 0 ? false : true;//是否已是京东自营
|
||
|
||
double price = double.Parse(goodinfo.priceInfo["price"].ToString()); //商品价格
|
||
|
||
//var commission = goodinfo.commissionInfo["commission"].ToString(); //佣金
|
||
|
||
var commissionshare = decimal.Parse(goodinfo.commissionInfo["commissionShare"].ToString()) / 100m;//普通用户佣金比例 ,通用接口中的佣金比例
|
||
|
||
#region 这里主要是获取改商品的实际佣金比例,上面的佣金比例是通用的佣金比例,会不准一些
|
||
try
|
||
{
|
||
var goodResult = api.SendJingdong("jd.union.open.goods.promotiongoodsinfo.query", new { skuIds = itemId });
|
||
if (goodResult != null && goodResult.ContainsKey("data"))
|
||
{
|
||
var _goodData = goodResult["data"] as ArrayList;
|
||
if (_goodData != null && _goodData.Count != 0)
|
||
{
|
||
foreach (Dictionary<string, object> data in _goodData)
|
||
{
|
||
if (data.ContainsKey("commisionRatioWl"))
|
||
{
|
||
commissionshare = decimal.Parse(data["commisionRatioWl"].ToString()) / 100m; //接口中该商品的实际佣金,比较准一些,
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{ }
|
||
#endregion
|
||
|
||
string couponlike = string.Empty; //优惠券链接
|
||
double discount = -1; //优惠券金额
|
||
decimal usecoupon_totalcommfee = 0;
|
||
if (goodinfo.couponInfo.Count != 0)
|
||
{
|
||
var couponList = goodinfo.couponInfo["couponList"] as ArrayList;
|
||
if (couponList.Count != 0)//有优惠券
|
||
{
|
||
foreach (Dictionary<string, object> coupon in couponList)
|
||
{
|
||
var quota = double.Parse(coupon["quota"].ToString()); //券消费限额
|
||
if (quota > price) break;//优惠券面额大于商品单价时终止
|
||
discount = double.Parse(coupon["discount"].ToString());
|
||
#region 普通用户
|
||
usecoupon_totalcommfee = usecoupon_totalcommfee = decimal.Round(((decimal)price - (decimal)discount) * commissionshare, 2);//券后 总佣金(自营)
|
||
if (!isJdSale)
|
||
usecoupon_totalcommfee = decimal.Round(usecoupon_totalcommfee * 0.9m, 2);//券后 总佣金(非自营)
|
||
#endregion
|
||
|
||
couponlike = coupon["link"].ToString(); //优惠券链接
|
||
break;//TODO 这里难道有多个优惠券?先不管,直接获取第一个
|
||
}
|
||
}
|
||
}
|
||
#region 普通用户
|
||
//不用券 佣金
|
||
var unusecoupon_totalcommfee = decimal.Round((decimal)price * commissionshare, 2);//券后 总佣金(自营)
|
||
if (!isJdSale)
|
||
unusecoupon_totalcommfee = decimal.Round(unusecoupon_totalcommfee * 0.9m, 2);//券后 总佣金(非自营)
|
||
#endregion
|
||
|
||
var buyshorturl = string.Empty; //转连后的地址
|
||
#region 转连(生成自己推广的链接 [有券链接(二合一)或无券链接])
|
||
Dictionary<string, object> conversionlinkresult = null; //查询到的转换链接对象
|
||
var positionId = twg.adzone_pid.Substring(twg.adzone_pid.LastIndexOf("_") + 1);
|
||
if (string.IsNullOrWhiteSpace(couponlike))
|
||
{
|
||
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = jd_cps.usernick } });//宝贝id 和 用户的目标推客的联盟id
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = jd_cps.usernick, couponUrl = couponlike } });
|
||
}
|
||
catch (Exception)
|
||
{
|
||
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = jd_cps.usernick } });//宝贝id 和 用户的目标推客的联盟id
|
||
couponlike = string.Empty;
|
||
discount = -1;
|
||
}
|
||
}
|
||
if (conversionlinkresult != null)
|
||
{
|
||
if (conversionlinkresult["code"].ToString() != "200") throw new Exception($"京东查询接口调用失败:{conversionlinkresult["message"].ToString()}");//抛出错误信息
|
||
if (conversionlinkresult.ContainsKey("data"))
|
||
{
|
||
var data = conversionlinkresult["data"] as Dictionary<string, object>;
|
||
if (data.ContainsKey("shortURL")) buyshorturl = data["shortURL"].ToString();//购买短连接
|
||
}
|
||
if (string.IsNullOrWhiteSpace(buyshorturl)) throw new Exception("京东转链失败,请稍后重试");
|
||
}
|
||
#endregion
|
||
|
||
var imageList = goodinfo.imageInfo["imageList"] as ArrayList;
|
||
string imageUrl = string.Empty;
|
||
StringBuilder strb = new StringBuilder();
|
||
for (int i = 0; i < imageList.Count; i++)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(imageUrl))
|
||
imageUrl = (imageList[i] as Dictionary<string, object>)["url"].ToString();
|
||
|
||
strb.AppendLine((imageList[i] as Dictionary<string, object>)["url"].ToString());
|
||
}
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
try
|
||
{
|
||
textEdit21.Text = $"https://item.jd.com/{itemId}.html";//商品链接
|
||
textEdit20.Text = goodinfo.skuName;//商品标题
|
||
textEdit19.Text = goodinfo.priceInfo["price"].ToString();//商品单价
|
||
textEdit18.Text = discount.ToString("0.00");//优惠券金额
|
||
textEdit17.Text = commissionshare.ToString("0.00");//返利比例
|
||
textEdit16.Text = usecoupon_totalcommfee.ToString("0.00");//券后返利
|
||
textEdit15.Text = unusecoupon_totalcommfee.ToString("0.00");//弃权返利
|
||
textEdit7.Text = ApiClient.GetQRImage(goodinfo.skuName, price.ToString(), discount.ToString(), ((decimal)price - (decimal)discount).ToString(), imageUrl, buyshorturl, comboBox2.SelectedIndex == 0 ? ApiClient.QrImageType.模板A : ApiClient.QrImageType.模板B, CpsType.京东联盟);//合成优惠券图
|
||
textEdit14.Text = buyshorturl;//转换后的链接
|
||
memoEdit2.Text = imageUrl;//商品图片
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
MessageBox.Show(ex.Message, "操作异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
});
|
||
|
||
try
|
||
{
|
||
await t1;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBox.Show($"{ex.Message}", "系统异常", MessageBoxButtons.OK);
|
||
}
|
||
|
||
hyperlinkLabelControl2.Enabled = simpleButton2.Enabled = comboBox2.Enabled = true;
|
||
}
|
||
|
||
private async void simpleButton3_Click(object sender, EventArgs e)
|
||
{
|
||
hyperlinkLabelControl3.Enabled = simpleButton3.Enabled = comboBox3.Enabled = false;
|
||
var t1 = Task.Run(() =>
|
||
{
|
||
if (hyperlinkLabelControl3.Tag == null) throw new Exception("请设置推广位");
|
||
if (string.IsNullOrWhiteSpace(textEdit36.Text)) throw new Exception("请填写要解析的拼多多链接");
|
||
|
||
var goods_id = PDDHelper.GetPddGoodsID(textEdit36.Text);
|
||
if (!string.IsNullOrEmpty(goods_id))
|
||
{
|
||
var twg = hyperlinkLabelControl3.Tag as fl_adzone_info;
|
||
|
||
var session = ApiClient.GetSession();
|
||
|
||
fl_cps_member pdd_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.多多进宝 && f.username == twg.adzone_pid_cps_name);
|
||
|
||
if (pdd_cps == null) throw new Exception("拼多多推广位设置异常,请检测后重试!");
|
||
|
||
PinduoduoApi api = CpsClient.CreatePinduoduoRequest(pdd_cps);
|
||
var data = new { goods_id_list = $"[{goods_id}]" };
|
||
|
||
ArrayList goods_details = null;
|
||
|
||
var isBind = api.IsAuthority(twg.adzone_pid);
|
||
if (!isBind)
|
||
{
|
||
//授权地址
|
||
var authUrl = api.AuthorityUrl(twg.adzone_pid);
|
||
Clipboard.SetDataObject(authUrl);
|
||
throw new Exception("推广位未授权,授权地址已经复制到粘贴板,点击链接授权一次后才能使用推广位");
|
||
}
|
||
|
||
goods_details = PDDHelper.FindSendGuideGoodsInfo(api, twg.adzone_pid, goods_id, isBind);
|
||
|
||
//没有查到返利提示
|
||
if (goods_details == null || goods_details.Count == 0)
|
||
throw new Exception("无法解析该商品");
|
||
|
||
foreach (var item in goods_details)
|
||
{
|
||
var temp = item as Dictionary<string, object>;
|
||
var goods_name = (temp["goods_name"] ?? string.Empty).ToString().Replace("", "").Replace("<", "<").Replace(">", ">").Replace("&", "&").Replace(""", "\"").Replace(" ©", "©"); //获取商品标签
|
||
var goods_desc = (temp["goods_desc"] ?? string.Empty).ToString(); //商品描述
|
||
var goods_thumbnail_url = (temp["goods_thumbnail_url"] ?? string.Empty).ToString(); //商品主图
|
||
|
||
var goods_sign = temp["goods_sign"].ToString();
|
||
|
||
StringBuilder strb = new StringBuilder();
|
||
if (temp.ContainsKey("goods_gallery_urls"))
|
||
{
|
||
var images = temp["goods_gallery_urls"] as ArrayList;
|
||
foreach (var image in images)
|
||
{
|
||
strb.AppendLine(image.ToString());
|
||
}
|
||
}
|
||
var min_group_price = Math.Round(temp["min_group_price"] == null ? 0 : (double.Parse(temp["min_group_price"].ToString()) / 100.00), 2); //最低价sku的拼团价,单位为分
|
||
var min_normal_price = Math.Round(temp["min_normal_price"] == null ? 0 : (double.Parse(temp["min_normal_price"].ToString()) / 100.00), 2); //最低价sku的单买价,单位为
|
||
var _coupon_discount = double.Parse((temp["coupon_discount"] ?? 0).ToString());
|
||
var coupon_discount = _coupon_discount == 0 ? 0 : Math.Round(_coupon_discount / 100.00, 2); //优惠券面额,单位为分
|
||
double promotion_rate = 0d;//佣金比例,千分比
|
||
if (temp["promotion_rate"] != null)
|
||
promotion_rate = double.Parse(temp["promotion_rate"].ToString()) / 1000.00;
|
||
promotion_rate = Math.Round(promotion_rate, 3);
|
||
|
||
var pdd_api = new PDDHelper();
|
||
var manyShoppingUrl = pdd_api.GetShoppingUrl(api, new { p_id = twg.adzone_pid, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = true, generate_short_url = true, generate_weapp_webview = true, force_duo_id = true, generate_authority_url = !isBind, generate_schema_url = true });
|
||
|
||
var oneShoppingUrl = pdd_api.GetShoppingUrl(api, new { p_id = twg.adzone_pid, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = false, generate_short_url = true, generate_weapp_webview = true, force_duo_id = true, generate_authority_url = !isBind, generate_schema_url = true });
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
try
|
||
{
|
||
textEdit33.Text = @"https://mobile.yangkeduo.com/goods.html?goods_id=" + goods_id;//商品连接
|
||
textEdit32.Text = goods_name;//商品标题
|
||
textEdit31.Text = min_normal_price.ToString("0.00");//商品单价
|
||
textEdit30.Text = coupon_discount.ToString("0.00");//优惠券金额
|
||
textEdit29.Text = ((decimal)promotion_rate * 100m).ToString("0.00");//返利比例
|
||
textEdit28.Text = ((min_normal_price - coupon_discount) * promotion_rate).ToString("0.00");//单买券后返利
|
||
textEdit27.Text = (min_normal_price * promotion_rate).ToString("0.00");//单买弃券返利
|
||
textEdit23.Text = min_group_price.ToString("0.00");//商品拼团价
|
||
textEdit34.Text = ((min_group_price - coupon_discount) * promotion_rate).ToString("0.00");//拼团券后返利
|
||
textEdit35.Text = (min_group_price * promotion_rate).ToString("0.00");//拼团价弃权返利
|
||
|
||
textEdit25.Text = ApiClient.GetQRImage(goods_name, min_normal_price.ToString(), coupon_discount.ToString(), ((decimal)min_normal_price - (decimal)coupon_discount).ToString(), goods_thumbnail_url, manyShoppingUrl, comboBox3.SelectedIndex == 0 ? ApiClient.QrImageType.模板A : ApiClient.QrImageType.模板B, CpsType.多多进宝);//合成优惠券图
|
||
textEdit26.Text = manyShoppingUrl;//生成拼团链接
|
||
textEdit22.Text = oneShoppingUrl;//生成单买链接
|
||
memoEdit3.Text = strb.ToString();//商品详情图
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "操作异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
try
|
||
{
|
||
await t1;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBox.Show($"{ex.Message}", "系统异常", MessageBoxButtons.OK);
|
||
}
|
||
|
||
hyperlinkLabelControl3.Enabled = simpleButton3.Enabled = comboBox3.Enabled = true;
|
||
}
|
||
|
||
private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
fl_alimama_tlj_info tlj = null;
|
||
if (comboBoxEdit1.SelectedIndex != 0)
|
||
{
|
||
tlj = GetTlj(comboBoxEdit1.SelectedText);
|
||
if (tlj == null) throw new Exception($"淘宝账号:{comboBoxEdit1.SelectedText},还没有设置对应的淘礼金");
|
||
textEdit40.Text = tlj.appkey;
|
||
textEdit39.Text = tlj.appsecret;
|
||
textEdit47.Text = tlj.adzone_pid;
|
||
}
|
||
simpleButton5.Enabled = comboBoxEdit1.SelectedIndex != 0;
|
||
textEdit40.Text = tlj == null ? string.Empty : tlj.appkey;
|
||
textEdit39.Text = tlj == null ? string.Empty : tlj.appsecret;
|
||
textEdit47.Text = tlj == null ? string.Empty : tlj.adzone_pid;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
BaseForm.ShowErrorAutoClose(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取选中的阿里妈妈账号信息(第一个值为 账号,第二个值为 昵称)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private List<string> GetSelectCpsInfo()
|
||
{
|
||
var reg = Regex.Match(comboBoxEdit1.SelectedText, "^(?<账号>[^(]+?)((?<昵称>.*?))$");
|
||
if (reg.Success)
|
||
{
|
||
return new List<string>() { reg.Groups["账号"].Value, reg.Groups["昵称"].Value };
|
||
}
|
||
return null;
|
||
}
|
||
|
||
private fl_alimama_tlj_info GetTlj(string text)
|
||
{
|
||
var cpsInfo = GetSelectCpsInfo();
|
||
if (cpsInfo != null)
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
var tljs = session.FindTljInfos(true);
|
||
return tljs.FirstOrDefault(f => f.username == cpsInfo[0]);
|
||
}
|
||
return null;
|
||
}
|
||
|
||
private void simpleButton5_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
var cpsInfo = GetSelectCpsInfo();
|
||
if (cpsInfo != null)
|
||
{
|
||
var tljform = new tlj_form(cpsInfo[1], cpsInfo[0]);
|
||
tljform.ShowDialog();
|
||
comboBoxEdit1_SelectedIndexChanged(null, null);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
BaseForm.ShowErrorAutoClose(ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成淘礼金与短链接
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void simpleButton4_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
var tljUrl = textEdit38.Text.Trim();
|
||
var tljPid = textEdit47.Text.Trim();
|
||
var appSecret = textEdit39.Text.Trim();
|
||
var appKey = textEdit40.Text.Trim();
|
||
var tljName = textEdit41.Text.Trim();
|
||
var user_total_win_num_limit = (int)numericUpDown3.Value; //每人限领礼金个数
|
||
var per_face = (double)numericUpDown1.Value; //单个淘礼金金额
|
||
var total_num = (int)numericUpDown2.Value; //淘礼金总个数
|
||
var send_start_time = dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
||
var send_end_time = dateTimePicker2.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
if (string.IsNullOrWhiteSpace(appKey)) throw new Exception("淘礼金AppKey不能为空");
|
||
if (string.IsNullOrWhiteSpace(appSecret)) throw new Exception("淘礼金AppSecret不能为空");
|
||
if (string.IsNullOrWhiteSpace(tljPid)) throw new Exception("淘礼金推广位PID不能为空");
|
||
if (string.IsNullOrWhiteSpace(tljUrl)) throw new Exception("商品链接不能为空");
|
||
if (string.IsNullOrWhiteSpace(tljName)) throw new Exception("淘礼金领取名称不能为空");
|
||
|
||
var reg = Regex.Match(tljPid, @"mm_(?<cpsname>\d+)_(?<pid1>\d+)_(?<pid2>\d+)");
|
||
if (!reg.Success) throw new Exception($"淘宝推广位格式不正确");
|
||
var cpsname = reg.Groups["cpsname"].Value;
|
||
var pid1 = reg.Groups["pid1"].Value;
|
||
var pid2 = reg.Groups["pid2"].Value;
|
||
|
||
var tb_cps = new fl_cps_member() { username = cpsname, cpstype = CpsType.阿里妈妈, cookies = string.Empty, is_download = SwitchType.关闭, abnormal_tip = SwitchType.关闭, online = true, usernick = string.Empty };
|
||
AlimamaApi api = CpsClient.CreateAlimamaRequest(tb_cps);
|
||
if (api == null) throw new Exception("创建淘宝API请求失败");
|
||
|
||
//获取商品的id
|
||
var tbAnalysis = new TBHelper.TbAnalysis();
|
||
var item_id = string.Empty;
|
||
try
|
||
{
|
||
item_id = tbAnalysis.FindItemIdByUrlAndTklAndMkl(tljUrl, api, tljPid.Split('_'));
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw new Exception("无法解析商品链接");
|
||
}
|
||
if (string.IsNullOrWhiteSpace(item_id)) throw new Exception("无法解析商品链接");
|
||
|
||
var result = api.GetItemInfo(item_id, "2");
|
||
if (result == null)
|
||
{
|
||
throw new Exception("商品基础信息查询失败");
|
||
}
|
||
|
||
if (result.n_tbk_item == null || result.n_tbk_item.Count == 0)
|
||
{
|
||
throw new Exception("获取商品信息失败,请稍后重试");
|
||
}
|
||
|
||
|
||
var queryItemData = result.n_tbk_item[0];
|
||
|
||
if (queryItemData == null)
|
||
{
|
||
throw new Exception("商品基础信息查询失败");
|
||
}
|
||
|
||
//商品主图
|
||
var pict_url = queryItemData.pict_url;
|
||
|
||
var session = ApiClient.GetSession();
|
||
if (!session.FindTljCreateNum(cpsname))
|
||
throw new Exception("该淘宝账号ID今日创建淘礼金次数已耗尽");
|
||
|
||
var tljResult = api.SendTaobao("taobao.tbk.dg.vegas.tlj.create", new { adzone_id = pid2, item_id = item_id, security_switch = "true", total_num = total_num, name = tljName, user_total_win_num_limit = user_total_win_num_limit, per_face = per_face, send_start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), send_end_time = send_end_time }, appKey, appSecret);
|
||
|
||
if (tljResult != null && tljResult.ContainsKey("success"))
|
||
{
|
||
if (tljResult["success"].ToString().ToLower() == "false")
|
||
{
|
||
if (tljResult.ContainsKey("msg_info"))
|
||
{
|
||
var msg = tljResult["msg_info"].ToString();
|
||
if (msg == "您创建的淘礼金商品数目已达上限")
|
||
session.ExcuteSQL("update fl_alimama_tlj_create_record set number = 30 where cpsname = @cpsname", new { cpsname = cpsname });
|
||
throw new Exception("该淘宝账号ID今日创建淘礼金次数已耗尽");
|
||
}
|
||
throw new Exception(tljResult.ContainsKey("msg_info") ? tljResult["msg_info"].ToString() : $"生成淘礼金失败,{HttpHelper.ObjectToJson(tljResult)}");
|
||
}
|
||
|
||
if (tljResult.ContainsKey("model"))
|
||
{
|
||
var model = tljResult["model"] as Dictionary<string, object>;
|
||
if (model.ContainsKey("send_url"))
|
||
{
|
||
var send_url = model["send_url"].ToString();
|
||
|
||
if (!string.IsNullOrWhiteSpace(tbAnalysis.activityId))
|
||
send_url = send_url + "&activityId=" + tbAnalysis.activityId;
|
||
|
||
var tklInfo = tbAnalysis.FindTKL(send_url, api);
|
||
|
||
if (tklInfo != null)
|
||
{
|
||
textEdit43.Text = tklInfo.tkl;
|
||
textEdit42.Text = api.ComposeTbClick(item_id, pict_url, tklInfo.tkl, tklInfo.isoUrl, true, tljPid, ApiClient.Setting.SystemConfig.ZjyComposeType == ComposeType.有推荐商品);
|
||
textEdit44.Text = tbAnalysis.FindShortUrlBySrcUrl(send_url, api); ;
|
||
|
||
#region 统计次数
|
||
session.AddTljCreateNum(cpsname);
|
||
#endregion
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
BaseForm.ShowErrorAutoClose(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
if (dateTimePicker1.Value >= dateTimePicker2.Value)
|
||
dateTimePicker2.Value = dateTimePicker1.Value.AddDays(1);
|
||
}
|
||
}
|
||
|
||
#region 京东类
|
||
public class goodInfo_temp
|
||
{
|
||
/// <summary>
|
||
/// 返回码
|
||
/// </summary>
|
||
public int code { get; set; }
|
||
/// <summary>
|
||
/// 数据明细
|
||
/// </summary>
|
||
//public List<GoodsResp> data { get; set; }
|
||
public ArrayList data { get; set; }
|
||
/// <summary>
|
||
/// 返回消息
|
||
/// </summary>
|
||
public string message { get; set; }
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string requestId { get; set; }
|
||
/// <summary>
|
||
/// 有效商品总数量,上限10w
|
||
/// </summary>
|
||
public long totalCount { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 数据明细
|
||
/// </summary>
|
||
public class GoodsResp
|
||
{
|
||
/// <summary>
|
||
/// 品牌code
|
||
/// </summary>
|
||
public string brandCode { get; set; }
|
||
/// <summary>
|
||
/// 品牌名
|
||
/// </summary>
|
||
public string brandName { get; set; }
|
||
/// <summary>
|
||
/// 类目信息
|
||
/// </summary>
|
||
//public List<CategoryInfo> categoryInfo { get; set; }
|
||
public Dictionary<string, object> categoryInfo { get; set; }
|
||
/// <summary>
|
||
/// 评论数
|
||
/// </summary>
|
||
public long comments { get; set; }
|
||
/// <summary>
|
||
/// 佣金信息
|
||
/// </summary>
|
||
//public List<CommissionInfo> commissionInfo { get; set; }
|
||
public Dictionary<string, object> commissionInfo { get; set; }
|
||
/// <summary>
|
||
/// 优惠券信息,返回内容为空说明该SKU无可用优惠券
|
||
/// </summary>
|
||
//public List<CouponInfo> couponInfo { get; set; }
|
||
public Dictionary<string, object> couponInfo { get; set; }
|
||
/// <summary>
|
||
/// 商品好评率
|
||
/// </summary>
|
||
public double goodCommentsShare { get; set; }
|
||
/// <summary>
|
||
/// 图片信息
|
||
/// </summary>
|
||
//public List<ImageInfo> imageInfo { get; set; }
|
||
public Dictionary<string, object> imageInfo { get; set; }
|
||
/// <summary>
|
||
/// 30天支出佣金
|
||
/// </summary>
|
||
public double inOrderComm30Days { get; set; }
|
||
/// <summary>
|
||
/// 30天引单量
|
||
/// </summary>
|
||
public long inOrderCount30Days { get; set; }
|
||
/// <summary>
|
||
/// 是否爆款,1:是,0:否
|
||
/// </summary>
|
||
public int isHot { get; set; }
|
||
/// <summary>
|
||
/// 是否自营 (1 : 是, 0 : 否),后续会废弃,请用owner
|
||
/// </summary>
|
||
public int isJdSale { get; set; }
|
||
/// <summary>
|
||
/// 商品落地页
|
||
/// </summary>
|
||
public string materialUrl { get; set; }
|
||
/// <summary>
|
||
/// g=自营,p=pop
|
||
/// </summary>
|
||
public string owner { get; set; }
|
||
/// <summary>
|
||
/// 拼购信息
|
||
/// </summary>
|
||
//public List<PinGouInfo> pinGouInfo { get; set; }
|
||
public Dictionary<string, object> pinGouInfo { get; set; }
|
||
/// <summary>
|
||
/// 已废弃,请使用pinGouInfo
|
||
/// </summary>
|
||
//public List<PingGouInfo> pingGouInfo { get; set; }
|
||
public Dictionary<string, object> pingGouInfo { get; set; }
|
||
/// <summary>
|
||
/// 价格信息
|
||
/// </summary>
|
||
//public List<PriceInfo> priceInfo { get; set; }
|
||
public Dictionary<string, object> priceInfo { get; set; }
|
||
/// <summary>
|
||
/// 店铺信息
|
||
/// </summary>
|
||
//public List<ShopInfo> shopInfo { get; set; }
|
||
public Dictionary<string, object> shopInfo { get; set; }
|
||
/// <summary>
|
||
/// 商品ID
|
||
/// </summary>
|
||
public long skuId { get; set; }
|
||
/// <summary>
|
||
/// 商品名称
|
||
/// </summary>
|
||
public string skuName { get; set; }
|
||
/// <summary>
|
||
/// spuid,其值为同款商品的主skuid
|
||
/// </summary>
|
||
public long spuid { get; set; }
|
||
}
|
||
|
||
#endregion
|
||
}
|