using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using CoreEntity.DAL;
using CoreEntity.Entity;
using CoreEntity.ESEntity;
using JCSoft.WX.Framework.Api;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
using PublicLibrary.Model;
using SupplierWeb.Commonss;
namespace SupplierWeb.Controllers
{
[Route("web/mem_order")]
public class mem_OrderController : BaseController
{
public mem_OrderController(IMemoryCache cache, IApiClient client) : base(cache, client)
{
}
public IActionResult Index()
{
return View();
}
///
/// 会员中心列表
///
///
///
///
[HttpPost]
[Route("OrderByCode")]
public ActionResult OrderByCode([FromBody]dynamic data, QueryFilter[] filters)
{
int start = 0;
string OrdersCode = "";
if (data != null)
{
OrdersCode = data.query[0];
data = new { query = "select * from mem_order where OrdersCode = '"+ OrdersCode + "'" };
}
//将参数转换成JSON数据
var json = JsonConvert.SerializeObject(data);
//通过传来的SQL语句,转换成DSL语句
string sql = Util.ElasticQuery("_sql/translate?format=json", "POST", json);
string from = "\"from\":" + start + ",";
sql = sql.Insert(1, from);
//通过转换的DSL语句,获取数据
var str = Util.ElasticQuery("mem_order/_search?format=json", "POST", sql);
//JSON转Root对象
//Root stobj = FromJSON(str);
Root<_source> stobj = EsCommon.FromJSON>(str);
//将Root对象中的子对象取出来
List<_source> _source = new List<_source>();
IList terms = TerminalDAL.getTerms();
IList payterms = PayPlatFormDAL.getPayTerms();
IList SourcePlatForms = Mem_DataDictoryDAL.getDatas(" and parentid= '783' ");
Dictionary temsMap = new Dictionary(terms.Count);
Dictionary payTermsMap = new Dictionary(payterms.Count);
Dictionary sourcePlatFormsMap = new Dictionary(SourcePlatForms.Count);
foreach (var term in terms)
{
var label = term.TerminalName;
var value = term.TerminalCode.ToString();
temsMap.Add(value, label);
}
foreach (var term in payterms)
{
var label = term.PayPlatFormName;
var value = term.PayPlatFormCode;
payTermsMap.Add(value, label);
}
foreach (var term in SourcePlatForms)
{
var label = term.Text;
var value = term.Value;
sourcePlatFormsMap.Add(value, label);
}
//给filed额外的属性赋值
stobj.hits.hits.ForEach(x =>
{
x._source._id = x._id;
x.fields.OriginType[0] = x.fields.OriginType[0] != 0 ?
temsMap[x.fields.OriginType[0].ToString()] : "";
x.fields.InitSum[0] = x.fields.InitSum[0] > 0 ?
x.fields.InitSum[0] / 100 : 0;
x.fields.OrderStatus[0] = x.fields.OrderStatus[0].ToString();
x.fields.PaymentType[0] = x.fields.PaymentType[0] != 0 ?
payTermsMap[x.fields.PaymentType[0].ToString()] : "";
x.fields.SourcePlatforms[0] = x.fields.SourcePlatforms[0] != 0 ?
sourcePlatFormsMap[x.fields.SourcePlatforms[0].ToString()] : "";
x.fields.Sum[0] = x.fields.Sum[0] > 0 ?
x.fields.Sum[0] / 100 : 0;
});
//_source = stobj.hits.hits.Select(x => x._source).ToList();
_source = stobj.hits.hits.Select(x => x.entity()).ToList();
foreach (var item in _source)
{
string[] phones = new string[1];
phones[0] = item.MemPhone;
var phones1 = CommonDAL.getPhoneDecrypt(phones);
string phoneStars = phones1[0];
if (phoneStars != null && phoneStars.Length > 8)
{
string replaced = phoneStars.Substring(3, 4);
phoneStars = phoneStars.Replace(replaced, "****");
}
item.MemPhone = phoneStars;
}
var jsonData = JsonConvert.SerializeObject(_source);
return Json(
new
{
items = JsonConvert.DeserializeObject(jsonData),
success = true
});
}
/////
///// JSON转对象
/////
/////
/////
/////
//public static T FromJSON(string input)
//{
// try
// {
// return JsonConvert.DeserializeObject(input);
// }
// catch (Exception ex)
// {
// string a = ex.Message;
// return default(T);
// }
//}
//#region
//public class _shards
//{
// ///
// ///
// ///
// public int total { get; set; }
// ///
// ///
// ///
// public int successful { get; set; }
// ///
// ///
// ///
// public int skipped { get; set; }
// ///
// ///
// ///
// public int failed { get; set; }
//}
//public class Total
//{
// ///
// ///
// ///
// public int value { get; set; }
// ///
// ///
// ///
// public string relation { get; set; }
//}
public class _source
{
public string _id { get; set; }//id
public string OriginType { get; set; }//下单平台终端
public string InitSum { get; set; }//下单金额
public string OrderStatus { get; set; }//订单状态
public string PaymentType { get; set; }//支付方式
public string SourcePlatforms { get; set; }//下单平台
///
///
///
public DateTime? OrderTime { get; set; }
///
///
///
public DateTime? InventoryAuditDate { get; set; }
///
///
///
public DateTime? CreationDate { get; set; }
///
///
///
public string AccountId { get; set; }
///
///
///
public string Invoice { get; set; }
///
///
///
public string VerificationCode { get; set; }
///
///
///
public string RegionCode { get; set; }
///
///
///
public string OrderNotes { get; set; }
///
///
///
public string Sex { get; set; }
///
///
///
public string CustomerDataId { get; set; }
///
///
///
public string IsToERP { get; set; }
///
///
///
public string SubProductLine { get; set; }
///
/// 吉林省吉林市磐石市河南街牛心综合楼一单元601室
///
public string ADeliveryAddress { get; set; }
///
///
///
public DateTime? LastModified { get; set; }
///
///
///
public string MemPhone { get; set; }
///
/// 赵海霞
///
public string Consignee { get; set; }
///
///
///
public string ReceiverPhone { get; set; }
///
///
///
public string LeverNumber { get; set; }
///
///
///
public string AConsigneePhone1 { get; set; }
///
///
///
public string DeliveryZipCode { get; set; }
///
///
///
public string Height { get; set; }
///
///
///
public string AConsigneePhone2 { get; set; }
///
///
///
public string CustomerName { get; set; }
///
///
///
public string ProductLine { get; set; }
///
///
///
public string BusinessId { get; set; }
///
///
///
public string InvoiceContent { get; set; }
///
///
///
public string ConfirmId { get; set; }
///
///
///
public string CashCouponCode { get; set; }
///
///
///
public string ShippingNo { get; set; }
///
///
///
public string DiseaseClassCode { get; set; }
///
///
///
public string AuditorId { get; set; }
///
///
///
public string ReceivingTime { get; set; }
///
///
///
public string CustomerCode { get; set; }
///
///
///
public string SyncStatus { get; set; }
///
///
///
public string InvoiceNo { get; set; }
///
///
///
public string DeptId { get; set; }
///
///
///
public string Weight { get; set; }
///
///
///
public DateTime? ShippingTime { get; set; }
///
///
///
public DateTime? AllocationTime { get; set; }
///
///
///
public string OtherNote { get; set; }
///
///
///
public string OrderProcessDate { get; set; }
///
///
///
public string MerchantNote { get; set; }
///
///
///
public string OperateID { get; set; }
///
///
///
public string DeptCode { get; set; }
///
///
///
public string OrdersCode { get; set; }
///
///
///
public string BuyUserId { get; set; }
///
///
///
public string AccountName { get; set; }
}
public class Fields
{
///
///
///
public List IsPayByCard { get; set; }
///
///
///
public List IntegralValue { get; set; }
///
///
///
public List IsDrug { get; set; }
///
///
///
public List HealthPrice { get; set; }
///
///
///
public List WarehouseCode { get; set; }
///
///
///
public List IsNeedReceipt { get; set; }
///
///
///
public List AllocationFlag { get; set; }
///
///
///
public List TransportCosts { get; set; }
///
///
///
public List BonusDate { get; set; }
///
///
///
public List DeliveryType { get; set; }
///
///
///
public List InitSum { get; set; }
///
///
///
public List OriginType { get; set; }
///
///
///
public List CouponValue { get; set; }
///
///
///
public List Discountprice { get; set; }
///
///
///
public List IsEmailmark { get; set; }
///
///
///
public List Sum { get; set; }
///
///
///
public List OrdersType { get; set; }
///
///
///
public List DeviceType { get; set; }
///
///
///
public List AdvanceSum { get; set; }
///
///
///
public List InvoiceSum { get; set; }
///
///
///
public List IsRxDrug { get; set; }
///
///
///
public List Ispayment { get; set; }
///
///
///
public List ProductCost { get; set; }
///
///
///
public List IsNewOrder { get; set; }
///
///
///
public List IsDealWith { get; set; }
///
///
///
public List ErrorCount { get; set; }
///
///
///
public List MemKey { get; set; }
///
///
///
public List IsReturn { get; set; }
///
///
///
public List IsReward { get; set; }
///
///
///
public List HuaWuOriginType { get; set; }
///
///
///
public List OrderStatus { get; set; }
///
///
///
public List AgainOrderCount { get; set; }
///
///
///
public List IsO2O { get; set; }
///
///
///
public List IsAutomaticSigned { get; set; }
///
///
///
public List PaymentType { get; set; }
///
///
///
public List PreferentialRate { get; set; }
///
///
///
public List Age { get; set; }
///
///
///
public List InvoiceContentType { get; set; }
///
///
///
public List OrdersIntegral { get; set; }
///
///
///
public List ConfimLevel { get; set; }
///
///
///
public List ConsigneeType { get; set; }
///
///
///
public List AdvancePayType { get; set; }
///
///
///
public List CouponCode { get; set; }
///
///
///
public List CashCouponValue { get; set; }
///
///
///
public List Reducing { get; set; }
///
///
///
public List IsVisible { get; set; }
///
///
///
public List SourcePlatforms { get; set; }
}
//public class HitsItem
//{
// ///
// ///
// ///
// public string _index { get; set; }
// ///
// ///
// ///
// public string _type { get; set; }
// ///
// ///
// ///
// public string _id { get; set; }
// ///
// ///
// ///
// public string _score { get; set; }
// ///
// ///
// ///
// public string _routing { get; set; }
// ///
// ///
// ///
// public _source _source { get; set; }
// ///
// ///
// ///
// public Fields fields { get; set; }
// ///
// ///
// ///
// public List sort { get; set; }
//}
//public class Hits
//{
// ///
// ///
// ///
// public Total total { get; set; }
// ///
// ///
// ///
// public string max_score { get; set; }
// ///
// ///
// ///
// public List hits { get; set; }
//}
//public class Root
//{
// ///
// ///
// ///
// public int took { get; set; }
// ///
// ///
// ///
// public string timed_out { get; set; }
// ///
// ///
// ///
// public _shards _shards { get; set; }
// ///
// ///
// ///
// public Hits hits { get; set; }
//}
//#endregion
}
}