85 lines
4.0 KiB
C#
85 lines
4.0 KiB
C#
|
using AllRebatesActivity.Entitys;
|
|||
|
using Api.Framework;
|
|||
|
using Api.Framework.Enums;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using Api.Framework.Tools;
|
|||
|
|
|||
|
namespace AllRebatesActivity
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 解析商品
|
|||
|
/// </summary>
|
|||
|
class AnalyzeGoods
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 通过商品的id查询返回获取到自己返利商品信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="goods_id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public goodsinfos FindGoodsInfoToItemId(string goods_id, string pid_cps_name = "", string pid = "", string biz_scene_id = "2")
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (!string.IsNullOrEmpty(goods_id))//符合搜索宝贝id的条件
|
|||
|
{
|
|||
|
biz_scene_id = TBHelper.TbAnalysis.BizSceneId(goods_id);
|
|||
|
|
|||
|
var member = (string.IsNullOrEmpty(pid_cps_name) ? CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.阿里妈妈) : CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.阿里妈妈 && f.username == pid_cps_name));
|
|||
|
if (member == null) { return null; }
|
|||
|
var api = CpsClient.CreateAlimamaRequest(member);
|
|||
|
|
|||
|
var itemInfo = api.GetItemInfo(goods_id, biz_scene_id);
|
|||
|
if (itemInfo != null && itemInfo.n_tbk_item != null && itemInfo.n_tbk_item.Count > 0)
|
|||
|
{
|
|||
|
var tbk_item = itemInfo.n_tbk_item[0];
|
|||
|
//店铺名称
|
|||
|
var nick = tbk_item.nick;
|
|||
|
//商品主图
|
|||
|
var pict_url = tbk_item.pict_url;
|
|||
|
//商品id
|
|||
|
goods_id = tbk_item.num_iid;
|
|||
|
//商品标题
|
|||
|
var title = tbk_item.title;
|
|||
|
//商品折扣价格(当前售价)
|
|||
|
var zk_final_price = double.Parse(tbk_item.zk_final_price);
|
|||
|
//30天销量
|
|||
|
var volume = tbk_item.volume;
|
|||
|
var goods_desc = string.Empty;
|
|||
|
|
|||
|
var coupon_remain_quantity = string.Empty;
|
|||
|
|
|||
|
var pids = pid.Split('_');
|
|||
|
var privilege = api.SendTaobao("taobao.tbk.privilege.get", new { item_id = goods_id, site_id = pids[2], adzone_id = pids[3], biz_scene_id = biz_scene_id });
|
|||
|
var privilege_data = privilege["data"] as Dictionary<string, object>;
|
|||
|
//最高佣金率
|
|||
|
var max_commission_rate = double.Parse(privilege_data["max_commission_rate"].ToString());
|
|||
|
//优惠券地址
|
|||
|
var coupon_click_url = string.Empty;
|
|||
|
var coupon_price = 0.00d;
|
|||
|
if (privilege_data.ContainsKey("coupon_info"))
|
|||
|
{
|
|||
|
var quan_reg = Regex.Match(privilege_data["coupon_info"].ToString(), @"满\d+元减(\d+)元");
|
|||
|
if (quan_reg.Success) coupon_price = double.Parse(quan_reg.Groups[1].Value);
|
|||
|
coupon_click_url = privilege_data["coupon_click_url"].ToString();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
coupon_price = 0.00d;
|
|||
|
coupon_click_url = privilege_data["coupon_click_url"].ToString();
|
|||
|
}
|
|||
|
return new goodsinfos() { cur_time = DateTime.Today, goods_id = goods_id, goods_name = title, mall_name = nick, goods_thumbnail_url = pict_url, sold_quantity = volume, normal_price = zk_final_price, coupon_discount = coupon_price, promotion_rate = max_commission_rate, shopping_url = coupon_click_url, goods_desc = goods_desc, coupon_remain_quantity = coupon_remain_quantity };
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{ }
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|