Browse Source

完成自动获取商品信息更新

master
feng 3 years ago
parent
commit
5b70243727
  1. 4
      src/Coldairarrow.Api/Controllers/HuiYan/teamitemsController.cs
  2. 4
      src/Coldairarrow.Business/HuiYan/teamitemsBusiness.cs
  3. 2
      src/Coldairarrow.IBusiness/HuiYan/IteamitemsBusiness.cs
  4. 126
      客户端/齐越慧眼/齐越慧眼/ApiHelper.cs
  5. 1
      客户端/齐越慧眼/齐越慧眼/UserControls/BrowerTabPanelControl.xaml.cs
  6. 42
      客户端/齐越慧眼/齐越慧眼/UserControls/ItemControl.xaml.cs
  7. 7
      客户端/齐越慧眼/齐越慧眼/vuepage/client/src/api/http.js
  8. 78
      客户端/齐越慧眼/齐越慧眼/vuepage/client/src/views/items/Index.vue
  9. 2
      客户端/齐越慧眼/齐越慧眼/vuepage/dist/js/app.js
  10. 2
      客户端/齐越慧眼/齐越慧眼/vuepage/dist/js/app.js.map
  11. 18
      客户端/齐越慧眼/齐越慧眼/齐越慧眼.csproj

4
src/Coldairarrow.Api/Controllers/HuiYan/teamitemsController.cs

@ -70,9 +70,9 @@ namespace Coldairarrow.Api.Controllers.HuiYan
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public PageResult<TeamitemDto> GetItems(PageInput<ConditionDTO> input) public PageResult<TeamitemDto> GetItems([FromBody]PageInput<ConditionDTO> input,string keyWord)
{ {
return _teamitemsBus.GetItems(input); return _teamitemsBus.GetItems(input,keyWord);
} }
/// <summary> /// <summary>

4
src/Coldairarrow.Business/HuiYan/teamitemsBusiness.cs

@ -77,7 +77,7 @@ namespace Coldairarrow.Business.HuiYan
return Success(list); return Success(list);
} }
public PageResult<TeamitemDto> GetItems(PageInput<ConditionDTO> input) public PageResult<TeamitemDto> GetItems(PageInput<ConditionDTO> input, string keyWord)
{ {
Expression<Func<teamitems, items, TeamitemDto>> select = (a, b) => new TeamitemDto Expression<Func<teamitems, items, TeamitemDto>> select = (a, b) => new TeamitemDto
{ {
@ -116,6 +116,8 @@ namespace Coldairarrow.Business.HuiYan
} }
} }
where = where.AndIf(!string.IsNullOrEmpty(keyWord), d => d.Title.Contains(keyWord));
where = where.And(c => c.TeamId == _operator.TeamId); where = where.And(c => c.TeamId == _operator.TeamId);
input.SortField = "CreateTime"; input.SortField = "CreateTime";

2
src/Coldairarrow.IBusiness/HuiYan/IteamitemsBusiness.cs

@ -14,7 +14,7 @@ namespace Coldairarrow.Business.HuiYan
Task UpdateDataAsync(teamitems data); Task UpdateDataAsync(teamitems data);
Task DeleteDataAsync(List<string> ids); Task DeleteDataAsync(List<string> ids);
PageResult<TeamitemDto> GetItems(PageInput<ConditionDTO> input); PageResult<TeamitemDto> GetItems(PageInput<ConditionDTO> input, string keyWord);
AjaxResult AddItem(TeamitemDto model); AjaxResult AddItem(TeamitemDto model);

126
客户端/齐越慧眼/齐越慧眼/ApiHelper.cs

@ -33,7 +33,7 @@ namespace 齐越慧眼
if (string.IsNullOrEmpty(jwtToken)) if (string.IsNullOrEmpty(jwtToken))
{ {
jwtToken = GetMemoryToken().Replace("\r\n", ""); jwtToken = GetMemoryToken().Replace("\r\n", "");
} }
@ -142,8 +142,8 @@ namespace 齐越慧眼
if (isSuccess) if (isSuccess)
{ {
string json=data.Data.ToString(); string json = data.Data.ToString();
UserInfo u= Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(json); UserInfo u = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(json);
return (true, u); return (true, u);
} }
@ -155,9 +155,9 @@ namespace 齐越慧眼
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
public static (bool isOk,bool isCanel,string msg) SetItemLabel(ItemLabelDto model) public static (bool isOk, bool isCanel, string msg) SetItemLabel(ItemLabelDto model)
{ {
var result= Http("/HuiYan/itemlabels/SetItemLabel", Newtonsoft.Json.JsonConvert.SerializeObject(model)); var result = Http("/HuiYan/itemlabels/SetItemLabel", Newtonsoft.Json.JsonConvert.SerializeObject(model));
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(result); var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(result);
@ -171,7 +171,7 @@ namespace 齐越慧眼
/// </summary> /// </summary>
/// <param name="shopId"></param> /// <param name="shopId"></param>
/// <returns></returns> /// <returns></returns>
public static (bool isOk, bool isCanel, string msg) SetAlbbCooperation(string shopId) public static (bool isOk, bool isCanel, string msg) SetAlbbCooperation(string shopId)
{ {
var result = Http($"/HuiYan/itemlabels/SetAlbbCooperation?shopId={shopId}", ""); var result = Http($"/HuiYan/itemlabels/SetAlbbCooperation?shopId={shopId}", "");
@ -218,7 +218,7 @@ namespace 齐越慧眼
/// <param name="ids"></param> /// <param name="ids"></param>
/// <param name="platform"></param> /// <param name="platform"></param>
/// <returns></returns> /// <returns></returns>
public static (bool isOk,List<ItemlabelInfoDto> datas) GetLabelByItemIds(List<string>ids,ItemPlatform platform) public static (bool isOk, List<ItemlabelInfoDto> datas) GetLabelByItemIds(List<string> ids, ItemPlatform platform)
{ {
try try
{ {
@ -257,11 +257,11 @@ namespace 齐越慧眼
bool isSuccess = data.Success; bool isSuccess = data.Success;
return (isSuccess, data.Msg??"操作失败"); return (isSuccess, data.Msg ?? "操作失败");
} }
catch catch
{ {
return (false,"系统异常"); return (false, "系统异常");
} }
} }
@ -286,7 +286,7 @@ namespace 齐越慧眼
HttpClient http = new HttpClient(); HttpClient http = new HttpClient();
http.Timeout = new TimeSpan(0, 0, 35); http.Timeout = new TimeSpan(0, 0, 35);
http.DefaultRequestHeaders.Add("Authorization", "Bearer " + JwtToken); http.DefaultRequestHeaders.Add("Authorization", "Bearer " + JwtToken);
if (postData!=null) if (postData != null)
{ {
StringContent content = new StringContent(postData); StringContent content = new StringContent(postData);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
@ -330,5 +330,111 @@ namespace 齐越慧眼
return null; return null;
} }
} }
/// <summary>
/// 根据Sku获取详情
/// </summary>
/// <param name="skuId"></param>
/// <returns></returns>
public static (int status, dynamic result) GetItemDetail(string skuId)
{
try
{
HttpClient http = new HttpClient();
http.DefaultRequestHeaders.Add("Cookie", App.JdCookie);
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 SE 2.X MetaSr 1.0");
string html = http.GetStringAsync($"https://item.jd.com/{skuId}.html").Result;
if (html.Contains("passport.jd.com/new/login.aspx") || html.Contains("//item.jd.com/html/token.html?returnUrl="))
{
return (2, null);
}
int start = html.IndexOf("var pageConfig");
int end = html.IndexOf("};", start);
string json = html.Substring(start, end - start);
start = json.IndexOf("{");
json = json.Substring(start, json.Length - start);
json += "}";
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json);
return (0, data);
}
catch (Exception ex)
{
return (1, ex.Message);
}
}
/// <summary>
/// 获取价格
/// </summary>
/// <param name="skuId"></param>
/// <returns></returns>
public static (string price, string commont) GetItemPrice(string skuId)
{
try
{
HttpClient http = new HttpClient();
http.DefaultRequestHeaders.Add("Cookie", App.JdCookie);
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 SE 2.X MetaSr 1.0");
string html = http.GetStringAsync($"https://item-soa.jd.com/getWareBusiness?skuId={skuId}").Result;
if (!string.IsNullOrEmpty(html))
{
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(html);
string price = data.price.p.ToString();
string commont = GetItemCommentCount(skuId);
return (price, commont);
}
}
catch (Exception ex)
{
return (string.Empty, string.Empty);
}
return (string.Empty, string.Empty);
}
public static string GetItemCommentCount(string skuId)
{
try
{
HttpClient http = new HttpClient();
http.DefaultRequestHeaders.Add("Cookie", App.JdCookie);
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 SE 2.X MetaSr 1.0");
string html = http.GetStringAsync($"https://club.jd.com/comment/productCommentSummaries.action?referenceIds={skuId}").Result;
if (!string.IsNullOrEmpty(html))
{
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(html);
string count = data.CommentsCount[0].CommentCountStr.ToString();
return count;
}
}
catch (Exception ex)
{
return "";
}
return "";
}
} }
} }

1
客户端/齐越慧眼/齐越慧眼/UserControls/BrowerTabPanelControl.xaml.cs

@ -65,6 +65,7 @@ namespace 齐越慧眼.UserControls
} }
/// <summary> /// <summary>
/// 阿里巴巴以图搜索 /// 阿里巴巴以图搜索
/// </summary> /// </summary>

42
客户端/齐越慧眼/齐越慧眼/UserControls/ItemControl.xaml.cs

@ -7,6 +7,7 @@ using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
@ -102,6 +103,47 @@ namespace 齐越慧眼.UserControls
return ApiHelper.JwtToken; return ApiHelper.JwtToken;
} }
public string getItemInfoByUrl(string url)
{
// https://item.jd.com/10030884795783.html
var match= Regex.Match(url, "jd.com/(.*?).html");
if (!match.Success)
{
return "{msg:'链接输入错误!',success:false}";
}
string itemId = match.Groups[1].Value;
var result = ApiHelper.GetItemDetail(itemId);
if (result.status == 1)
{
return "{msg:'获取详情信息失败!',success:false}";
}
if (result.status == 2)
{
return "{msg:'未登录京东,请先登录!',success:false}";
}
string title = result.result.product.name;
string src = "http://img11.360buyimg.com/n1/" + result.result.product.src;
var data= ApiHelper.GetItemPrice(itemId);
string price = data.price;
string comment = data.commont;
return Newtonsoft.Json.JsonConvert.SerializeObject(new { success=true,data=new {
commont=comment,
price= price,
title= title,
src=src
} });
// return $"{{success:true,data:{{commont:'{comment}',price:'{price}',title:'{title}',img:'{src}'}}}}";
}
public string getImgBase64(string url,string type) public string getImgBase64(string url,string type)
{ {

7
客户端/齐越慧眼/齐越慧眼/vuepage/client/src/api/http.js

@ -6,9 +6,11 @@ axios.defaults.timeout = 50000;
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
let $httpVue = null, currentToken = '';
//'application/json;charset=utf-8';// //'application/json;charset=utf-8';//
if (process.env.NODE_ENV == 'development') { if (process.env.NODE_ENV == 'development') {
axios.defaults.baseURL = 'http://hyapi.qiyue666.com/'; axios.defaults.baseURL = 'http://hyapi.qiyue666.com/';
currentToken='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNDM5OTA3NDY1MDMzNDIwODAwIiwidGVhbUlkIjoiMTQzNjI4ODUwMDIzNTI0MzUyMCIsImV4cCI6MTY3MTAwOTkyM30.p3yLjbeUilDZxkfRv4GaCvIYJ_jFoe_8Sw8hY18swdA'
} }
else if (process.env.NODE_ENV == 'production') { else if (process.env.NODE_ENV == 'production') {
axios.defaults.baseURL = 'http://hyapi.qiyue666.com/'; axios.defaults.baseURL = 'http://hyapi.qiyue666.com/';
@ -16,8 +18,8 @@ else if (process.env.NODE_ENV == 'production') {
let ipAddress = axios.defaults.baseURL; let ipAddress = axios.defaults.baseURL;
axios.defaults.baseURL = 'http://localhost:5000/'; //axios.defaults.baseURL = 'http://localhost:5000/';
axios.defaults.baseURL = 'http://hyapi.qiyue666.com/'; //axios.defaults.baseURL = 'http://hyapi.qiyue666.com/';
axios.interceptors.request.use((config) => { axios.interceptors.request.use((config) => {
//axios.defaults.headers[_Authorization] = $httpVue.$store.getters.getToken(); //axios.defaults.headers[_Authorization] = $httpVue.$store.getters.getToken();
@ -57,7 +59,6 @@ axios.interceptors.response.use((res) => {
return Promise.reject(error.response); return Promise.reject(error.response);
}); });
let $httpVue = null, currentToken = '';
const _Authorization = 'Authorization', _Bearer = 'Bearer '; const _Authorization = 'Authorization', _Bearer = 'Bearer ';
function init(vue) { function init(vue) {

78
客户端/齐越慧眼/齐越慧眼/vuepage/client/src/views/items/Index.vue

@ -33,6 +33,21 @@
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
<a-row :gutter="10" style="margin-bottom:10px">
<a-col :span="5">
<a-input
v-model="catKeyWord"
placeholder="搜索品类词"
>
</a-input>
</a-col>
<a-col :span="5">
<a-button @click="searchDatas">搜索</a-button>
</a-col>
</a-row>
<div class="border"> <div class="border">
<a-row> <a-row>
<a-col :span="4"> <a-col :span="4">
@ -147,13 +162,11 @@
:autoClearSearchValue="false" :autoClearSearchValue="false"
> >
<a-select-option v-for="item in platformList" :key="item.id"> <a-select-option v-for="item in platformList" :key="item.id">
{{ item.name }}</a-select-option <span style="font-size:12px"> {{ item.name }}</span></a-select-option
> >
</a-select> </a-select>
<span class="spanValue" v-else> <span class="spanValue" v-else>
<span v-if="ext.Platform == 0">淘宝</span> {{platformList.filter(c=>c.id==ext.Platform)[0].name}}
<span v-if="ext.Platform == 1">京东</span>
<span v-if="ext.Platform == 2">阿里巴巴</span>
</span> </span>
</div> </div>
</a-col> </a-col>
@ -165,7 +178,16 @@
:key="index" :key="index"
> >
<a-input v-if="item.isEdit" v-model="ext.BuyUrl"></a-input> <a-input v-if="item.isEdit" v-model="ext.BuyUrl"></a-input>
<span class="spanValue" v-else>{{ ext.BuyUrl }}</span>
<a-popover title="操作网址" trigger="hover" v-else>
<template #content>
<a-button type="primary" block>复制</a-button>
<a target="_black" :href="ext.BuyUrl" class="spanValue" style="margin-top:5px" >
<a-button block>打开</a-button>
</a>
</template>
<a target="_black" :href="ext.BuyUrl" class="spanValue">{{ ext.BuyUrl }}</a>
</a-popover>
</div> </div>
</a-col> </a-col>
<!--SKU名称--> <!--SKU名称-->
@ -288,8 +310,9 @@
" "
> >
<a target="_black" :href="item.RivalGoodsId"> <a target="_black" :href="item.RivalGoodsId">
<img src="/jp.png" width="200" height="165" <img v-if="item.RivalGoodsImg" :src="item.RivalGoodsImg" width="200" height="165"/>
/></a> <img v-else src="/jp.png" width="200" height="165"/>
</a>
<a-row> <a-row>
<a-col :span="12" style="text-align: left" <a-col :span="12" style="text-align: left"
>¥{{ item.RivalPrice }}</a-col >¥{{ item.RivalPrice }}</a-col
@ -427,9 +450,12 @@
</a-row> </a-row>
</a-col> </a-col>
<a-col :span="4"> <a-col :span="4">
<a class="borderNoTop itemtitle" :title="item.RivalTitle">{{
<a v-if="item.RivalTitle&&!item.isEdit" class="borderNoTop itemtitle" :title="item.RivalTitle">{{
item.RivalTitle item.RivalTitle
}}</a> }}</a>
<a-button v-else-if="item.isEdit" @click="openItemInfoWeb(item)">自动获取对标信息</a-button>
</a-col> </a-col>
</a-row> </a-row>
</a-col> </a-col>
@ -467,6 +493,7 @@ export default {
queryParam: { condition: "State", keyword: 0 }, queryParam: { condition: "State", keyword: 0 },
selectedRowKeys: [], selectedRowKeys: [],
currentTab: "0", currentTab: "0",
catKeyWord:undefined,
lastEditData: undefined, lastEditData: undefined,
extFormList: ["以图搜款"], extFormList: ["以图搜款"],
stateList: [], stateList: [],
@ -474,6 +501,7 @@ export default {
{ id: 0, name: "淘宝" }, { id: 0, name: "淘宝" },
{ id: 1, name: "京东" }, { id: 1, name: "京东" },
{ id: 2, name: "1688" }, { id: 2, name: "1688" },
{ id: 3, name: "拼多多" },
], ],
}; };
}, },
@ -520,6 +548,29 @@ export default {
this.extFormList.push(value); this.extFormList.push(value);
} }
}, },
openItemInfoWeb(item){
if(item==undefined||item.RivalGoodsId==undefined||item.RivalGoodsId==null)
{
this.$message.error("请先输入竞品链接!");
return
}
hyCoreModel.getItemInfoByUrl(item.RivalGoodsId).then(res=>{
var result= JSON.parse(res)
if(result.success)
{
var data=result.data
item.RivalTitle=data.title
item.RivalPrice=data.price
item.RivalPLCount=data.commont
item.RivalGoodsImg=data.img
this.$message.success("获取成功");
}else{
this.$message.error(result.msg);
}
})
},
changeTab(e) { changeTab(e) {
this.getDatas(e); this.getDatas(e);
this.currentTab = e; this.currentTab = e;
@ -529,10 +580,19 @@ export default {
this.pagination.current = page; this.pagination.current = page;
this.getDatas(this.currentTab); this.getDatas(this.currentTab);
}, },
searchDatas(){
this.pagination.current = 1;
this.getDatas(this.currentTab);
},
getDatas(type) { getDatas(type) {
var that = this; var that = this;
var url='/HuiYan/teamitems/GetItems'
if(this.catKeyWord&&this.catKeyWord.length>0)
{
url="/HuiYan/teamitems/GetItems?keyword="+this.catKeyWord
}
this.http this.http
.post("/HuiYan/teamitems/GetItems", { .post(url, {
PageIndex: this.pagination.current, PageIndex: this.pagination.current,
PageRows: this.pagination.pageSize, PageRows: this.pagination.pageSize,
SortField: this.sorter.field || "Id", SortField: this.sorter.field || "Id",

2
客户端/齐越慧眼/齐越慧眼/vuepage/dist/js/app.js

File diff suppressed because one or more lines are too long

2
客户端/齐越慧眼/齐越慧眼/vuepage/dist/js/app.js.map

File diff suppressed because one or more lines are too long

18
客户端/齐越慧眼/齐越慧眼/齐越慧眼.csproj

@ -65,6 +65,15 @@
<ItemGroup> <ItemGroup>
<Content Include="icon.ico" /> <Content Include="icon.ico" />
<EmbeddedResource Include="vuepage\dist\css\app.030d4c2f.css" />
<EmbeddedResource Include="vuepage\dist\css\app.css" />
<EmbeddedResource Include="vuepage\dist\css\chunk-vendors.09af4a6b.css" />
<EmbeddedResource Include="vuepage\dist\css\chunk-vendors.css" />
<EmbeddedResource Include="vuepage\dist\jp.png" />
<EmbeddedResource Include="vuepage\dist\js\app.js" />
<EmbeddedResource Include="vuepage\dist\js\app.js.map" />
<EmbeddedResource Include="vuepage\dist\js\chunk-vendors.js" />
<EmbeddedResource Include="vuepage\dist\js\chunk-vendors.js.map" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -80,10 +89,6 @@
<EmbeddedResource Include="icon.ico"> <EmbeddedResource Include="icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="vuepage\dist\css\app.030d4c2f.css" />
<EmbeddedResource Include="vuepage\dist\css\app.css" />
<EmbeddedResource Include="vuepage\dist\css\chunk-vendors.09af4a6b.css" />
<EmbeddedResource Include="vuepage\dist\css\chunk-vendors.css" />
<EmbeddedResource Include="vuepage\dist\img\close.png" /> <EmbeddedResource Include="vuepage\dist\img\close.png" />
<EmbeddedResource Include="vuepage\dist\img\pop.png" /> <EmbeddedResource Include="vuepage\dist\img\pop.png" />
<EmbeddedResource Include="vuepage\dist\img\true.png" /> <EmbeddedResource Include="vuepage\dist\img\true.png" />
@ -92,11 +97,6 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="vuepage\dist\favicon.ico" /> <EmbeddedResource Include="vuepage\dist\favicon.ico" />
<EmbeddedResource Include="vuepage\dist\index.html" /> <EmbeddedResource Include="vuepage\dist\index.html" />
<EmbeddedResource Include="vuepage\dist\jp.png" />
<EmbeddedResource Include="vuepage\dist\js\app.js" />
<EmbeddedResource Include="vuepage\dist\js\app.js.map" />
<EmbeddedResource Include="vuepage\dist\js\chunk-vendors.js" />
<EmbeddedResource Include="vuepage\dist\js\chunk-vendors.js.map" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save