275 lines
15 KiB
C#
275 lines
15 KiB
C#
|
using Api.Framework;
|
|||
|
using Api.Framework.Cps;
|
|||
|
using Api.Framework.Tools;
|
|||
|
using CouponsSend.Entitys;
|
|||
|
using CouponsSend.Entitys1;
|
|||
|
using CouponsSend.Entitys2;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using static CouponsSend.Entitys.Enum;
|
|||
|
|
|||
|
namespace CouponsSend
|
|||
|
{
|
|||
|
public class AnalyzeGoods
|
|||
|
{
|
|||
|
#region 采集大淘客数据
|
|||
|
public void GatherFactory()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var html = string.Empty;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var dtk = DtkApi.GetDtkApi();
|
|||
|
|
|||
|
var par = new ApiParameters();
|
|||
|
par.Add("pageId", "1");
|
|||
|
par.Add("pageSize", "100");
|
|||
|
|
|||
|
var ver = "v1.0.0";
|
|||
|
var api = "https://openapi.dataoke.com/api/goods/exclusive-goods-list";
|
|||
|
|
|||
|
switch (Class1.Config.GatherType)
|
|||
|
{
|
|||
|
case Entitys.Enum.GatherType.独家券商品:
|
|||
|
api = "https://openapi.dataoke.com/api/goods/exclusive-goods-list";
|
|||
|
par.Add("sort", Class1.Config.ConditionType.ToString());
|
|||
|
|
|||
|
html = dtk.SendDtk(api, par, ver);
|
|||
|
|
|||
|
if (!string.IsNullOrWhiteSpace(html))
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var egList = JsonConvert.DeserializeObject<ExclusiveGoodsList>(html);
|
|||
|
if (egList != null)
|
|||
|
{
|
|||
|
|
|||
|
var existGoods = session.Find<fl_plugin_couponssend_goodsinfos>("select * from fl_plugin_couponssend_goodsinfos");
|
|||
|
|
|||
|
var goodsinfos = new List<fl_plugin_couponssend_goodsinfos>();
|
|||
|
foreach (var item in egList.data.list)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var goods = new fl_plugin_couponssend_goodsinfos();
|
|||
|
goods.goods_quan = item.couponId;
|
|||
|
goods.goods_id = item.goodsId;
|
|||
|
var gTemp = existGoods.FirstOrDefault(f => f.goods_id == goods.goods_id);
|
|||
|
if (gTemp != null)
|
|||
|
continue;
|
|||
|
gTemp = goodsinfos.FirstOrDefault(f => f.goods_id == goods.goods_id);
|
|||
|
if (gTemp != null)
|
|||
|
continue;
|
|||
|
|
|||
|
goods.goods_desc = item.desc;
|
|||
|
goods.coupon_discount = item.couponPrice;
|
|||
|
goods.normal_price = item.originalPrice;
|
|||
|
goods.actual_price = item.actualPrice;
|
|||
|
goods.goods_thumbnail_url = item.mainPic;
|
|||
|
goods.goods_name = item.title;
|
|||
|
goods.promotion_rate = item.commissionRate;
|
|||
|
|
|||
|
goods.state = StateType.未推广;
|
|||
|
goods.cur_time = DateTime.Now;
|
|||
|
goodsinfos.Add(goods);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{ }
|
|||
|
}
|
|||
|
if (goodsinfos.Count != 0)
|
|||
|
session.Insertable(goodsinfos.ToArray()).ExecuteCommand();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
//EventClient.OnEvent(this, $"群发优惠券采集异常.:{ex.Message}{ex.StackTrace}");
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case Entitys.Enum.GatherType.每日爆品推荐:
|
|||
|
api = "https://openapi.dataoke.com/api/goods/explosive-goods-list";
|
|||
|
par.Add("PriceCid", (Class1.Config.ConditionType + 1).ToString());
|
|||
|
|
|||
|
html = dtk.SendDtk(api, par, ver);
|
|||
|
|
|||
|
if (!string.IsNullOrWhiteSpace(html))
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var egList = JsonConvert.DeserializeObject<ExplosiveGoodsList>(html);
|
|||
|
if (egList != null)
|
|||
|
{
|
|||
|
var existGoods = session.Find<fl_plugin_couponssend_goodsinfos>("select * from fl_plugin_couponssend_goodsinfos");
|
|||
|
|
|||
|
var goodsinfos = new List<fl_plugin_couponssend_goodsinfos>();
|
|||
|
foreach (var item in egList.data.list)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var goods = new fl_plugin_couponssend_goodsinfos();
|
|||
|
goods.goods_quan = item.couponId;
|
|||
|
goods.goods_id = item.goodsId;
|
|||
|
var gTemp = existGoods.FirstOrDefault(f => f.goods_id == goods.goods_id);
|
|||
|
if (gTemp != null)
|
|||
|
continue;
|
|||
|
gTemp = goodsinfos.FirstOrDefault(f => f.goods_id == goods.goods_id);
|
|||
|
if (gTemp != null)
|
|||
|
continue;
|
|||
|
|
|||
|
goods.goods_desc = item.desc;
|
|||
|
goods.coupon_discount = item.couponPrice;
|
|||
|
goods.normal_price = item.originalPrice;
|
|||
|
goods.actual_price = item.actualPrice;
|
|||
|
goods.goods_thumbnail_url = item.mainPic;
|
|||
|
goods.goods_name = item.title;
|
|||
|
goods.promotion_rate = item.commissionRate;
|
|||
|
|
|||
|
goods.state = StateType.未推广;
|
|||
|
goods.cur_time = DateTime.Now;
|
|||
|
goodsinfos.Add(goods);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{ }
|
|||
|
}
|
|||
|
if (goodsinfos.Count != 0)
|
|||
|
session.Insertable(goodsinfos.ToArray()).ExecuteCommand();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
//EventClient.OnEvent(this, $"群发优惠券采集异常.:{ex.Message}{ex.StackTrace}");
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case Entitys.Enum.GatherType.各大榜单:
|
|||
|
api = "https://openapi.dataoke.com/api/goods/get-ranking-list";
|
|||
|
ver = "v1.3.0";
|
|||
|
par.Add("rankType", (Class1.Config.ConditionType + 1).ToString());
|
|||
|
|
|||
|
html = dtk.SendDtk(api, par, ver);
|
|||
|
if (!string.IsNullOrWhiteSpace(html))
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
var egList = JsonConvert.DeserializeObject<GetRankinglist>(html);
|
|||
|
if (egList != null)
|
|||
|
{
|
|||
|
var existGoods = session.Find<fl_plugin_couponssend_goodsinfos>("select * from fl_plugin_couponssend_goodsinfos");
|
|||
|
|
|||
|
var goodsinfos = new List<fl_plugin_couponssend_goodsinfos>();
|
|||
|
foreach (var item in egList.data)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var goods = new fl_plugin_couponssend_goodsinfos();
|
|||
|
|
|||
|
var reg = Regex.Match(item.couponLink, @"activityId=(?<activityid>[a-zA_Z0-9]+)");
|
|||
|
goods.goods_quan = reg.Success ? reg.Groups["activityid"].ToString() : string.Empty;
|
|||
|
goods.goods_id = item.goodsId;
|
|||
|
var gTemp = existGoods.FirstOrDefault(f => f.goods_id == goods.goods_id);
|
|||
|
if (gTemp != null)
|
|||
|
continue;
|
|||
|
gTemp = goodsinfos.FirstOrDefault(f => f.goods_id == goods.goods_id);
|
|||
|
if (gTemp != null)
|
|||
|
continue;
|
|||
|
|
|||
|
goods.goods_desc = item.desc;
|
|||
|
goods.coupon_discount = item.couponPrice;
|
|||
|
goods.normal_price = item.originalPrice;
|
|||
|
goods.actual_price = item.actualPrice;
|
|||
|
goods.goods_thumbnail_url = item.mainPic;
|
|||
|
goods.goods_name = item.title;
|
|||
|
goods.promotion_rate = item.commissionRate;
|
|||
|
|
|||
|
goods.state = StateType.未推广;
|
|||
|
goods.cur_time = DateTime.Now;
|
|||
|
goodsinfos.Add(goods);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{ }
|
|||
|
}
|
|||
|
if (goodsinfos.Count != 0)
|
|||
|
session.Insertable(goodsinfos.ToArray()).ExecuteCommand();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
//EventClient.OnEvent(this, $"群发优惠券采集异常.:{ex.Message}{ex.StackTrace}");
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case Entitys.Enum.GatherType.九块九包邮精选:
|
|||
|
api = "https://openapi.dataoke.com/api/goods/nine/op-goods-list";
|
|||
|
par.Add("nineCid", (Class1.Config.ConditionType + 1).ToString());
|
|||
|
ver = "v2.0.0";
|
|||
|
html = dtk.SendDtk(api, par, ver);
|
|||
|
|
|||
|
if (!string.IsNullOrWhiteSpace(html))
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var egList = JsonConvert.DeserializeObject<ExplosiveGoodsList>(html);
|
|||
|
if (egList != null)
|
|||
|
{
|
|||
|
|
|||
|
var existGoods = session.Find<fl_plugin_couponssend_goodsinfos>("select * from fl_plugin_couponssend_goodsinfos");
|
|||
|
|
|||
|
var goodsinfos = new List<fl_plugin_couponssend_goodsinfos>();
|
|||
|
foreach (var item in egList.data.list)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var goods = new fl_plugin_couponssend_goodsinfos();
|
|||
|
|
|||
|
var reg = Regex.Match(item.couponLink, @"activityId=(?<activityid>[a-zA_Z0-9]+)");
|
|||
|
goods.goods_quan = reg.Success ? reg.Groups["activityid"].ToString() : string.Empty;
|
|||
|
goods.goods_id = item.goodsId;
|
|||
|
var gTemp = existGoods.FirstOrDefault(f => f.goods_id == goods.goods_id);
|
|||
|
if (gTemp != null)
|
|||
|
continue;
|
|||
|
gTemp = goodsinfos.FirstOrDefault(f => f.goods_id == goods.goods_id);
|
|||
|
if (gTemp != null)
|
|||
|
continue;
|
|||
|
|
|||
|
goods.goods_desc = item.desc;
|
|||
|
goods.coupon_discount = item.couponPrice;
|
|||
|
goods.normal_price = item.originalPrice;
|
|||
|
goods.actual_price = item.actualPrice;
|
|||
|
goods.goods_thumbnail_url = item.mainPic;
|
|||
|
goods.goods_name = item.title;
|
|||
|
goods.promotion_rate = item.commissionRate;
|
|||
|
|
|||
|
goods.state = StateType.未推广;
|
|||
|
goods.cur_time = DateTime.Now;
|
|||
|
goodsinfos.Add(goods);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{ }
|
|||
|
}
|
|||
|
if (goodsinfos.Count != 0)
|
|||
|
session.Insertable(goodsinfos.ToArray()).ExecuteCommand();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
//EventClient.OnEvent(this, $"群发优惠券采集异常.:{ex.Message}{ex.StackTrace}");
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
EventClient.OnEvent(this, $"群发优惠券采集异常:{ex.Message}{ex.StackTrace}");
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|