Commit bddc637c by 陈宁

# dev 请求资源->码券商品信息

parent 2d276183
......@@ -36,9 +36,11 @@ namespace Freemud.BE.Toolbox.Testing
Console.WriteLine("obj is: " + JsonConvert.SerializeObject(obj));
Console.WriteLine(obj.name);
Console.WriteLine(obj.Name);
Console.WriteLine(obj.Sex);
Console.WriteLine(obj.Sex.toString());
Console.WriteLine(obj.address);
Console.WriteLine(obj.address.home);
Console.WriteLine(obj.address.work);
//Console.WriteLine(obj.Sex.toString());
}
......@@ -48,11 +50,16 @@ namespace Freemud.BE.Toolbox.Testing
obj.name = "张三丰";
obj.age = 10;
obj.birthday = DateTime.Now;
//obj.address = "---- address ----";
//obj.address.home = "西安";
//obj.address.work = "上海";
obj.address = new ExpandoObject();
obj.address.home = "西安";
obj.address.work = "上海";
return obj;
}
[TestMethod]
public void asdasdasdasd()
{
......
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RestSharp;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Freemud.BE.Toolbox.Testing
{
[TestClass]
public class JsonOpertionTest
{
[TestMethod]
public void MyTestMethod()
{
var json = "{\"statusCode\":100,\"couponlist\":[{\"code\":\"385438604009450\",\"couponType\":0,\"codeInfo\":{\"act_id\":\"P120520200522102932\",\"code\":\"385438604009450\",\"ebcode\":\"0000000559\",\"vdata\":\"2020-06-30\",\"act_name\":\"麦乐鸡买一送一[剩1]\",\"act_desc\":\"\",\"ebname\":\"趋佳\",\"products\":[{\"pid\":\"900250\",\"number\":1,\"payment\":{\"paid\":0,\"remaining\":1150},\"price_act\":1150,\"price_original\":2300,\"name\":\"麦乐鸡买一送一\",\"mcd_productCode\":\"123470777\"}],\"availableTimes\":1},\"statusCode\":100},{\"code\":\"385438604009450aq\",\"couponType\":0,\"msg\":\"码不存在\",\"statusCode\":11}]}";
Console.WriteLine(json);
var jo = JObject.Parse(json);
var coupons = JArray.Parse(jo["couponlist"].ToString());
var pids = new List<string>();
foreach (var c in coupons)
{
if (c["codeInfo"] != null)
{
pids.Add(c["codeInfo"]["products"][0]["mcd_productCode"].ToString());
}
}
Console.WriteLine(JsonConvert.SerializeObject(pids));
}
}
}
......@@ -15,6 +15,7 @@
<ItemGroup>
<Folder Include="Infrastructure\Http\" />
<Folder Include="logs\" />
</ItemGroup>
</Project>
......@@ -10,70 +10,36 @@ namespace Freemud.BE.Toolbox.WebApi.Infrastructure.Helpers
{
public static class HttpHeper
{
public static async Task<IRestResponse<TResult>> Get<TResult>(string url, Dictionary<string, object> headers = null, Dictionary<string, object> queries = null)
{
var client = new RestClient();
var request = new RestRequest(url, Method.GET);
if (headers?.Any() ?? false)
{
foreach (var h in headers)
{
request.AddHeader(h.Key, h.Value.ToString().Trim());
}
}
if (queries?.Any() ?? false)
{
foreach (var p in queries)
{
request.AddQueryParameter(p.Key, p.Value.ToString().Trim());
}
}
Log.Information($"url: {url}");
Log.Information($"header: {JsonConvert.SerializeObject(headers)}");
Log.Information($"query: {JsonConvert.SerializeObject(queries)}");
public static async Task<IRestResponse> Get(string url, Dictionary<string, object> headers = null, Dictionary<string, object> queries = null)
=> await ExecuteAsync(url, Method.GET, headers, queries, null);
var response = await client.ExecuteAsync<TResult>(request);
Log.Information($"response: {response.Content}");
public static async Task<IRestResponse> Post(string url, Dictionary<string, object> headers = null, Dictionary<string, object> queries = null, object jsonBody = null)
=> await ExecuteAsync(url, Method.POST, headers, queries, jsonBody);
return null;
}
public static async Task<IRestResponse<TResult>> Post<TResult>(string url, Dictionary<string, object> headers = null, Dictionary<string, object> queries = null, object jsonBody = null)
private static async Task<IRestResponse> ExecuteAsync(string url, Method method, Dictionary<string, object> headers = null, Dictionary<string, object> queries = null, object jsonBody = null)
{
var client = new RestClient();
var request = new RestRequest(url, Method.POST);
var request = new RestRequest(url, method);
if (headers?.Any() ?? false)
foreach (var h in headers ?? new Dictionary<string, object>())
{
foreach (var h in headers)
{
request.AddHeader(h.Key, h.Value.ToString().Trim());
}
request.AddHeader(h.Key, h.Value.ToString().Trim());
}
if (queries?.Any() ?? false)
foreach (var p in queries ?? new Dictionary<string, object>())
{
foreach (var p in queries)
{
request.AddQueryParameter(p.Key, p.Value.ToString().Trim());
}
request.AddQueryParameter(p.Key, p.Value.ToString().Trim());
}
if (jsonBody != null)
{
request.AddJsonBody(jsonBody);
}
Log.Information($"url: {url}");
Log.Information($"header: {JsonConvert.SerializeObject(headers)}");
Log.Information($"query: {JsonConvert.SerializeObject(queries)}");
Log.Information($"data: {JsonConvert.SerializeObject(jsonBody)}");
var response = await client.ExecuteAsync<TResult>(request);
var response = await client.ExecuteAsync(request);
Log.Information($"response: {response.Content}");
......
......@@ -15,10 +15,10 @@ namespace Freemud.BE.Toolbox.WebApi.Model.Response
public dynamic RequestBody { get; set; }
public dynamic ResponseHeaders { get; set; }
// public dynamic ResponseHeaders { get; set; }
public dynamic ResponseBody { get; set; }
public string ResponseContent { get; set; }
public dynamic ResponseError { get; set; }
public string ResponseError { get; set; }
}
}
......@@ -12,9 +12,9 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
{
private readonly List<RequestResourceConfiguration> requestResources;
protected BaseProxy(List<RequestResourceConfiguration> requestResources)
protected BaseProxy(ToolboxConfiguration toolboxConfiguration)
{
this.requestResources = requestResources;
requestResources = toolboxConfiguration.RequestResources;
}
/// <summary>
......@@ -62,7 +62,7 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
/// <param name="responseBody"></param>
/// <param name="responseError"></param>
/// <returns></returns>
protected RequestResourceResponse Response(string name, string url, object requestHeaders = null, object requestBody = null, object responseHeaders = null, object responseBody = null, string responseError = "")
protected RequestResourceResponse Response(string name, string url, object requestHeaders = null, object requestBody = null, object responseHeaders = null, string responseContent = "", string responseError = "")
{
return new RequestResourceResponse
{
......@@ -70,8 +70,8 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
Url = url,
RequestHeaders = requestHeaders,
RequestBody = requestBody,
ResponseHeaders = responseHeaders,
ResponseBody = responseBody,
// ResponseHeaders = responseHeaders,
ResponseContent = responseContent,
ResponseError = responseError
};
}
......
......@@ -12,7 +12,7 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
{
public class FmCouponProxy : BaseProxy
{
public FmCouponProxy(List<RequestResourceConfiguration> requestResources) : base(requestResources) { }
public FmCouponProxy(ToolboxConfiguration toolboxConfiguration) : base(toolboxConfiguration) { }
/// <summary>
/// 获取券码核销渠道
......@@ -47,16 +47,18 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
{ "pi", GetChannelPartnerId(request.Channel) }
};
var codes = request.CouponCode.Split(",").Select(code => new { coupon = code }).ToList();
var body = new
{
reqtype = 88, // 操作类型; 0(卡券查询), 2(卡券交易查询), 3(卡券冲正), 71(卡券核销), 88(批量查询)
station_id = "999", // POS机编号
operator_id = "999", // 营业员编号
store_id = request.StoreId, // 门店编号
couponlist = request.CouponCode.Split(",").ToList(), // 优惠券编号
channel = GetFreemudCouponChannel(request.Channel) // 核销渠道; 0(Unknown), 1(POS), 2(Online), 3(Pickup), 4(Delivery), 5(McCofe), 6(Kiosk)
reqtype = 88, // 操作类型; 0(卡券查询), 2(卡券交易查询), 3(卡券冲正), 71(卡券核销), 88(批量查询)
station_id = "999", // POS机编号
operator_id = "999", // 营业员编号
store_id = request.StoreId, // 门店编号
couponlist = codes, // 优惠券编号
channel = GetFreemudCouponChannel(request.Channel) // 核销渠道; 0(Unknown), 1(POS), 2(Online), 3(Pickup), 4(Delivery), 5(McCofe), 6(Kiosk)
};
var response = await HttpHeper.Post<dynamic>(url, headers, jsonBody: body);
var response = await HttpHeper.Post(url, headers, jsonBody: body);
return new RequestResourceResponse
{
......@@ -64,7 +66,7 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
Url = url,
RequestHeaders = headers,
RequestBody = body,
ResponseBody = response.Data,
ResponseContent = response.Content,
ResponseError = response.ErrorMessage
};
}
......
......@@ -11,7 +11,7 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
{
public class FmProductProxy : BaseProxy
{
public FmProductProxy(List<RequestResourceConfiguration> requestResources) : base(requestResources) { }
public FmProductProxy(ToolboxConfiguration toolboxConfiguration) : base(toolboxConfiguration) { }
/// <summary>
/// 获取商品基本信息
......@@ -23,13 +23,13 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
var url = GetUrl(request.Env, "FreemudProduct", "listBaseInfosByTimeV2");
url = string.Format(url, string.Join(',', request.ProductId), $"{GetChannelUnifyId(request.Channel, request.Env)}_{request.StoreId}", request.Time.ToString("HH:mm:ss"), true);
var response = await HttpHeper.Get<dynamic>(url);
var response = await HttpHeper.Get(url);
return new RequestResourceResponse
{
Name = "获取商品信息",
Url = url,
ResponseBody = response.Data,
ResponseContent = response.Content,
ResponseError = response.ErrorMessage
};
}
......@@ -45,13 +45,13 @@ namespace Freemud.BE.Toolbox.WebApi.Proxy
var url = GetUrl(env, "FreemudProduct", "getProductExtensionInfo");
url = string.Format(url, productId);
var response = await HttpHeper.Get<dynamic>(url);
var response = await HttpHeper.Get(url);
return new RequestResourceResponse
{
Name = "获取商品扩展信息",
Url = url,
ResponseBody = response.Data,
ResponseContent = response.Content,
ResponseError = response.ErrorMessage
};
}
......
using System;
using Freemud.BE.Toolbox.WebApi.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Freemud.BE.Toolbox.WebApi.Proxy
{
public class FmStoreProxy
public class FmStoreProxy : BaseProxy
{
public FmStoreProxy(ToolboxConfiguration toolboxConfiguration) : base(toolboxConfiguration)
{
}
}
}
......@@ -17,15 +17,13 @@ namespace Freemud.BE.Toolbox.WebApi.Services
public class RequestResourceService : IRequestResourceService
{
private readonly ILogger<RequestResourceService> logger;
private readonly List<RequestResourceConfiguration> requestResources;
private readonly FmCouponProxy fmCouponProxy;
private readonly FmProductProxy fmProductProxy;
private readonly FmStoreProxy fmStoreProxy;
public RequestResourceService(ILogger<RequestResourceService> logger, List<RequestResourceConfiguration> requestResources, FmCouponProxy fmCouponProxy, FmProductProxy fmProductProxy, FmStoreProxy fmStoreProxy)
public RequestResourceService(ILogger<RequestResourceService> logger, FmCouponProxy fmCouponProxy, FmProductProxy fmProductProxy, FmStoreProxy fmStoreProxy)
{
this.logger = logger;
this.requestResources = requestResources;
this.fmCouponProxy = fmCouponProxy;
this.fmProductProxy = fmProductProxy;
this.fmStoreProxy = fmStoreProxy;
......@@ -46,19 +44,19 @@ namespace Freemud.BE.Toolbox.WebApi.Services
var coupons = await fmCouponProxy.GetCouponInfos(request);
// 查询券码对应商品信息
var couponPIds = (coupons.ResponseBody as List<dynamic>).Select(d => d.codeInfo.products[0].mcd_productCode) as List<string>;
var jo = JObject.Parse(coupons.ResponseContent);
var jCoupons = JArray.Parse(jo["couponlist"].ToString());
var jCouponsPids = jCoupons.Where(d => d["codeInfo"] != null).Select(d => d["codeInfo"]["products"][0]["mcd_productCode"].ToString()).ToList();
var getProductInfoRequest = new GetProductInfoRequest
{
Env = request.Env,
Channel = request.Channel,
StoreId = request.StoreId,
Time = request.Time,
ProductId = couponPIds,
ProductId = jCouponsPids,
};
var couponProducts = await fmProductProxy.GetProductBaseInfos(getProductInfoRequest);
return new List<RequestResourceResponse> { coupons, couponProducts };
}
......@@ -130,4 +128,4 @@ namespace Freemud.BE.Toolbox.WebApi.Services
}
#endregion
}
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ using Freemud.BE.Toolbox.WebApi.Infrastructure.Caching;
using Freemud.BE.Toolbox.WebApi.Middlewares;
using Freemud.BE.Toolbox.WebApi.Model;
using Freemud.BE.Toolbox.WebApi.Model.Request;
using Freemud.BE.Toolbox.WebApi.Proxy;
using Freemud.BE.Toolbox.WebApi.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
......@@ -42,6 +43,9 @@ namespace Freemud.BE.Toolbox.WebApi
services.AddScoped<IAccessManagementAppService, AccessManagementAppService>();
services.AddScoped<IEnvironmentConfigureService, EnvironmentConfigureService>();
services.AddScoped<IRequestResourceService, RequestResourceService>();
services.AddSingleton<FmCouponProxy>();
services.AddSingleton<FmProductProxy>();
services.AddSingleton<FmStoreProxy>();
// Caching
services.AddEasyCaching(options => options.UseInMemory(Configuration, "default", "EasyCaching:InMemory"));
......
......@@ -27,7 +27,11 @@
</Col>
<Col span="12">
<FormItem label="门店号">
<AutoComplete v-model="storeId" :data="[1450026, 99998, 99995]" placeholder="门店编号"></AutoComplete>
<AutoComplete
v-model="storeId"
:data="[1450026, 1450217, 99998, 99995, 99992]"
placeholder="门店编号"
></AutoComplete>
</FormItem>
</Col>
<Col span="12">
......@@ -49,19 +53,69 @@
<div class="resource-result">
<Tabs :animated="false">
<TabPane label="结果" icon="md-list-box">
<List border>
<ListItem>暂无</ListItem>
</List>
<Row v-for="item in vData" :key="item.coupon.code" class="coupon-line" :gutter="16">
<Col span="12">
<Card dis-hover>
<p slot="title">
<a href="javascript:;" slot="title">
<Icon type="md-return-right" />
</a>
<span>{{item.coupon.couponName}}({{item.coupon.couponCode}})</span>
</p>
<Table
v-if="item.coupon.ret"
border
size="small"
:columns="colCoupons"
:data="item.coupon.data"
:show-header="false"
>
<template slot-scope="{ row }" slot="name">
<div class="xxx">
<strong>{{ row.name }}</strong>
<Tag color="geekblue">{{row.field}}</Tag>
</div>
</template>
</Table>
<strong v-else>{{ item.coupon.data }}</strong>
</Card>
</Col>
<Col span="12">
<div v-if="item.product">
<Card dis-hover>
<p slot="title">
<a href="javascript:;" slot="title">
商品
<Icon type="md-return-right" />
</a>
<span>{{item.product.name}}({{item.product.id}})</span>
</p>
<Table
border
size="small"
:columns="colCoupons"
:data="item.product.data"
:show-header="false"
>
<template slot-scope="{ row }" slot="name">
<div class="xxx">
<strong>{{ row.name }}</strong>
<Tag color="geekblue">{{row.field}}</Tag>
</div>
</template>
</Table>
</Card>
</div>
<div v-else>无数据</div>
</Col>
</Row>
</TabPane>
<TabPane label="元信息" icon="md-bug">
<TabPane label="元信息" icon="md-code">
<div class="resource-result-metadata-panel">
<div class="resource-result-metadata-item">
<span class="resource-result-metadata-item-title">Request</span>
<codemirror v-model="metaDataRequestUrl" :options="cmOptions"></codemirror>
</div>
<div class="resource-result-metadata-item">
<span class="resource-result-metadata-item-title">Response</span>
<codemirror v-model="metaDataResponseBody" :options="cmOptions"></codemirror>
<div v-for="item in metaData" :key="item.name" class="resource-result-metadata-item">
<span class="resource-result-metadata-item-title">{{item.name}}</span>
<codemirror :value="mergeMetaData(item)" :options="cmOptions"></codemirror>
</div>
</div>
</TabPane>
......@@ -86,18 +140,25 @@ export default {
loadingSearch: false,
channel: 'delivery',
env: 'dev',
couponCode: '',
couponCode: '385438604009450,QQQ',
storeId: '',
viewData: '',
metaDataRequestUrl: '',
metaDataResponseBody: '',
metaData: [],
vData: [],
retCoupons: [],
retProducts: [],
cmOptions: {
lineNumbers: true,
readOnly: true,
tabSize: 2,
model: 'text/javascript',
theme: 'the-matrix'
}
},
colCoupons: [{
slot: 'name'
},
{
key: 'val'
}]
}
},
created () {
......@@ -121,20 +182,102 @@ export default {
if (response.code !== 200) {
this.$Message.error(response.message)
} else {
this.metaDataRequestUrl =
'================ URL ================\r\n' +
response.data.url + '\n\n' +
'================ HEADERS ============\r\n' +
JSON.stringify(response.data.requestHeaders, null, '\t') + '\r\n' +
'================ DATA ===============\r\n' +
JSON.stringify(response.data.requestBody, null, '\t')
// this.metaDataRequestUrl =
// '================ URL ================\r\n' +
// response.data.url + '\n\n' +
// '================ HEADERS ============\r\n' +
// JSON.stringify(response.data.requestHeaders, null, '\t') + '\r\n' +
// '================ DATA ===============\r\n' +
// JSON.stringify(response.data.requestBody, null, '\t')
this.metaDataResponseBody = JSON.stringify(response.data.responseBody, null, '\t')
// this.metaDataResponseBody = JSON.stringify(response.data.responseBody, null, '\t')
this.$Message.success('查询成功')
// this.$Message.success('查询成功')
this.metaData = response.data
this.bindData(response.data)
}
this.loadingSearch = false
},
bindData (data) {
const coupons = []
const responseCoupon = JSON.parse(data[0].responseContent)
responseCoupon.couponlist.forEach(c => {
if (c.statusCode === 100 && c.codeInfo != null) {
const data = [
{ name: '券号', field: 'code', val: c.codeInfo.code },
{ name: '电子凭证码类型', field: 'couponType', val: c.couponType },
{ name: '优惠券过期时间', field: 'vdata', val: c.codeInfo.vdata },
{ name: '活动号', field: 'act_id', val: c.codeInfo.act_id },
{ name: '活动名称', field: 'act_name', val: c.codeInfo.act_name },
{ name: '活动描述', field: 'act_desc', val: c.codeInfo.act_desc },
{ name: '代金券优惠(非代金券不返回)', field: 'amount ', val: c.codeInfo.amount },
{ name: '代金券门槛(非代金券不返回)', field: 'minamount', val: c.codeInfo.minamount },
{ name: '绑定商品编号', field: 'mcd_productCode', val: c.codeInfo.products[0].mcd_productCode },
{ name: '绑定商品金额', field: 'mcd_tenderCode', val: c.codeInfo.products[0].mcd_tenderCode }
]
coupons.push({ ret: true, couponCode: c.code, couponName: c.codeInfo.act_name, productId: c.codeInfo.products[0].mcd_productCode, data: data })
} else {
coupons.push({ ret: false, couponCode: c.code, data: c.msg })
}
})
this.retCoupons = coupons
const products = []
const responseProducts = JSON.parse(data[1].responseContent)
responseProducts.data.products.forEach(p => {
const data = [
{ name: '编号', field: 'pid', val: p.pid },
{ name: '名称', field: 'name', val: p.name },
{ name: 'customerCode', field: 'customerCode', val: p.customerCode },
{ name: '业务类型', field: 'businessType', val: p.businessType },
{ name: '价格', field: 'finalPrice', val: p.finalPrice },
{ name: '外带价格', field: 'finalPriceTakeout', val: p.finalPriceTakeout },
{ name: '原价', field: 'originalPrice', val: p.originalPrice },
{ name: '外带原价', field: 'originalPriceTakeout', val: p.originalPriceTakeout },
{ name: '状态', field: 'status', val: p.status },
{ name: '类型', field: 'type', val: p.type }
]
products.push({ id: p.pid, name: p.name, data: data })
})
this.retProducts = products
// 组装数据
const vdata = []
coupons.forEach(coup => {
if (coup.ret) {
const p = this._.find(products, { id: 123470777 })
vdata.push({ coupon: coup, product: p })
} else {
vdata.push({ coupon: coup, product: null })
}
})
this.vData = vdata
},
mergeMetaData (data) {
return '================ URL ================\r\n' +
data.url + '\n\n' +
'================ HEADERS ============\r\n' +
JSON.stringify(data.requestHeaders, null, '\t') + '\r\n' +
'================ DATA ===============\r\n' +
JSON.stringify(data.requestBody, null, '\t') + '\r\n' +
'================ RESPONSE ===============\r\n' +
JSON.stringify(JSON.parse(data.responseContent), null, '\t')
}
}
}
</script>
<style lang="less" scope>
.coupon-line {
margin-bottom: 15px;
.xxx {
display: flex;
justify-content: space-between;
align-items: center;
}
.ivu-table-cell {
padding-right: 0px;
}
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment