Files
KJD/KJDService/KJD_WebService/BLL/WXXD/WXOrderManage.cs
T

307 lines
18 KiB
C#

using KJD_Web.Model.WxModel;
using KJD_Web.Utils;
using NaiBa.Util.Extension;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
namespace KJD_Web.BLL.WXXD
{
public class WXOrderManage
{
public string WXGetErpOrderList(string inputData, bool isDetail = false)
{
if (!string.IsNullOrEmpty(inputData))
{
var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
var erp_shop_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_shop_id_in")?.Replace("'", "\\'");
if (erp_shop_id_in.IsNullOrEmpty())
{
return "{\"code\":500,\"msg\":\"未指定店铺\"}";
}
var query_status = RegexUtils.GetStringQuery(ref inputData, "query_status")?.Replace("'", "\\'");
var purchase_status = RegexUtils.GetStringQuery(ref inputData, "purchase_status")?.Replace("'", "\\'");
var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'");
var start_time = RegexUtils.GetStringQuery(ref inputData, "start_time").ParseToInt();
var end_time = RegexUtils.GetStringQuery(ref inputData, "end_time").ParseToInt();
var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") == "true";
int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "SELECT COUNT(id) FROM erp.oms_wei_order o WHERE 1=1 ";
string where = "";
if (!string.IsNullOrWhiteSpace(erp_shop_id_in))
where += " and o.shop_id in (" + erp_shop_id_in + ")";
if (!string.IsNullOrWhiteSpace(query_status))
where += " and o.status = " + query_status;
if (!string.IsNullOrWhiteSpace(purchase_status))
where += " and o.purchase_status = " + purchase_status;
if (start_time > 0)
where += " and o.create_time >= " + start_time;
if (end_time > 0)
where += " and o.create_time <= " + end_time;
sql += where;
var count = 0;
if (!is_not_count)
count = mySql.ExecuteRowCount(sql);
DataTable dt;
if (count == 0 && !is_not_count)
{
dt = new DataTable();
}
else
{
sql = "SELECT o.* FROM" +
" erp.oms_wei_order o " +
" WHERE 1=1";
//where子句
sql += where;
if (sort_type == "asc")
//sql += " ORDER BY o.create_time ASC, o.id desc";
sql += " ORDER BY o.create_time ASC";
else
sql += " ORDER BY o.create_time DESC";
sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size;
dt = mySql.ExecuteDataTable(sql);
}
mySql.Close();
if (dt != null)
{
try
{
List<oms_wei_order> orderList = new List<oms_wei_order>();
foreach (DataRow row in dt.Rows)
{
oms_wei_order order = new oms_wei_order
{
id = row["id"].ParseToLong(),
aftersale_detail = row["aftersale_detail"].ParseToString(),
audit_status = row["audit_status"].ParseToNullableInt(),
audit_time = row["audit_time"].ParseToString().ParseToDateTime(),
city_name = row["city_name"].ParseToString(),
colour_flag = row["colour_flag"].ParseToNullableInt(),
colour_flag_update_time = row["colour_flag_update_time"].ParseToString().ParseToDateTime(),
commission_amount = row["commission_amount"].ParseToNullableInt(),
county_name = row["county_name"].ParseToString(),
create_time = row["create_time"].ParseToInt(),
delivery_deadline = row["delivery_deadline"].ParseToNullableInt(),
delivery_product_info = row["delivery_product_info"].ParseToString(),
delivery_time = row["delivery_time"].ParseToNullableInt(),
detail_info = row["detail_info"].ParseToString(),
discounted_price = row["discounted_price"].ParseToNullableInt(),
erp_send_code = row["erp_send_code"].ParseToString(),
erp_send_company = row["erp_send_company"].ParseToString(),
erp_send_status = row["erp_send_status"].ParseToNullableInt(),
erp_send_time = row["erp_send_time"].ParseToString().ParseToDateTime(),
ewaybill_order_code = row["ewaybill_order_code"].ParseToString(),
external_gift = row["external_gift"].ParseToNullableInt(),
ext_info = row["ext_info"].ParseToString(),
freight = row["freight"].ParseToNullableInt(),
freight_insurance_amount = row["freight_insurance_amount"].ParseToNullableInt(),
gift_order_status = row["gift_order_status"].ParseToNullableInt(),
hash_code = row["hash_code"].ParseToString(),
has_freight_insurance = row["has_freight_insurance"].ParseToNullableInt(),
house_number = row["house_number"].ParseToString(),
is_express_no_used = row["is_express_no_used"].ParseToNullableInt(),
is_shipment_optimized = row["is_shipment_optimized"].ParseToNullableInt(),
merchant_id = row["merchant_id"].ParseToLong(),
openid = row["openid"].ParseToString(),
order_id = row["order_id"].ParseToString(),
order_price = row["order_price"].ParseToNullableInt(),
out_account = row["out_account"].ParseToString(),
out_after_sale_status = row["out_after_sale_status"].ParseToString(),
out_amount = row["out_amount"].ParseToNullableInt(),
out_express_company = row["out_express_company"].ParseToString(),
out_express_no = row["out_express_no"].ParseToString(),
out_order_no = row["out_order_no"].ParseToString(),
out_shipped = row["out_shipped"].ParseToNullableInt(),
pay_info = row["pay_info"].ParseToString(),
postal_code = row["postal_code"].ParseToString(),
predict_commission_fee = row["predict_commission_fee"].ParseToNullableInt(),
product_price = row["product_price"].ParseToNullableInt(),
province_name = row["province_name"].ParseToString(),
purchase_price = row["purchase_price"].ParseToNullableInt(),
purchase_status = row["purchase_status"].ParseToNullableInt(),
purchase_time = row["purchase_time"].ParseToNullableInt(),
settle_info = row["settle_info"].ParseToString(),
ship_done_time = row["ship_done_time"].ParseToNullableInt(),
shop_id = row["shop_id"].ParseToLong(),
shop_name = row["shop_name"].ParseToString(),
shop_remark = row["shop_remark"].ParseToString(),
soft_remark = row["soft_remark"].ParseToString(),
status = row["status"].ParseToNullableInt(),
supplier_remark_exception = row["supplier_remark_exception"].ParseToString(),
tel_number = row["tel_number"].ParseToString(),
tel_number_ext_info = row["tel_number_ext_info"].ParseToString(),
transfer_warehouse_status = row["transfer_warehouse_status"].ParseToNullableInt(),
unionid = row["unionid"].ParseToString(),
update_time = row["update_time"].ParseToInt(),
user_name = row["user_name"].ParseToString(),
use_tel_number = row["use_tel_number"].ParseToNullableInt(),
virtual_order_tel_number = row["virtual_order_tel_number"].ParseToString(),
};
orderList.Add(order);
}
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
var data = JsonUtils.SerializeObjectToString(orderList, jsonSetting);
return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}";
}
catch (Exception ex)
{
return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}";
}
}
else
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string WXGetErpOrderItemList(string inputData, bool isDetail = false)
{
if (!string.IsNullOrEmpty(inputData))
{
var timeCalc = DateTime.Now;
var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
var erp_order_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_order_id_in")?.Replace("'", "\\'");
if (erp_order_id_in.IsNullOrEmpty())
{
return "{\"code\":500,\"msg\":\"未指定订单\"}";
}
var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'");
var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") != "false";
int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(500);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "SELECT COUNT(id) FROM erp.oms_wei_order_item o WHERE 1=1 ";
string where = "";
if (!string.IsNullOrWhiteSpace(erp_order_id_in))
where += " and o.order_id in ('" + erp_order_id_in.Replace(",", "','") + "')";
sql += where;
var count = 0;
if (!is_not_count)
count = mySql.ExecuteRowCount(sql);
DataTable dt;
if (count == 0 && !is_not_count)
{
dt = new DataTable();
}
else
{
sql = "SELECT o.* FROM" +
" erp.oms_wei_order_item o " +
" WHERE 1=1";
//where子句
sql += where;
if (sort_type == "asc")
sql += " ORDER BY o.id ASC";
else
sql += " ORDER BY o.id DESC";
sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size;
dt = mySql.ExecuteDataTable(sql);
}
mySql.Close();
if (dt != null)
{
try
{
List<oms_wei_order_item> orderItemList = new List<oms_wei_order_item>();
foreach (DataRow row in dt.Rows)
{
oms_wei_order_item order = new oms_wei_order_item
{
id = row["id"].ParseToLong(),
commission_amount = row["commission_amount"].ParseToNullableInt(),
freight = row["freight"].ParseToNullableInt(),
merchant_id = row["merchant_id"].ParseToLong(),
order_id = row["order_id"].ParseToString(),
predict_commission_fee = row["predict_commission_fee"].ParseToNullableInt(),
purchase_price = row["purchase_price"].ParseToNullableInt(),
shop_id = row["shop_id"].ParseToLong(),
cash_coupon_discounted_price = row["cash_coupon_discounted_price"].ParseToNullableInt(),
change_price = row["change_price"].ParseToNullableInt(),
deduction_price = row["deduction_price"].ParseToNullableInt(),
erp_goods_id = row["erp_goods_id"].ParseToNullableLong(),
erp_goods_sku_id = row["erp_goods_sku_id"].ParseToNullableLong(),
estimate_price = row["estimate_price"].ParseToNullableInt(),
extra_service = row["extra_service"].ParseToString(),
finish_aftersale_sku_cnt = row["finish_aftersale_sku_cnt"].ParseToNullableInt(),
is_change_price = row["is_change_price"].ParseToString(),
is_discounted = row["is_discounted"].ParseToString(),
market_price = row["market_price"].ParseToNullableInt(),
on_aftersale_sku_cnt = row["on_aftersale_sku_cnt"].ParseToNullableInt(),
order_product_coupon_info_list = row["order_product_coupon_info_list"].ParseToString(),
out_product_id = row["out_product_id"].ParseToString(),
out_sku_id = row["out_sku_id"].ParseToString(),
out_warehouse_id = row["out_warehouse_id"].ParseToString(),
product_id = row["product_id"].ParseToString(),
real_price = row["real_price"].ParseToNullableInt(),
refund_status = row["refund_status"].ParseToNullableInt(),
return_address = row["return_address"].ParseToString(),
sale_price = row["sale_price"].ParseToNullableInt(),
sku_attrs = row["sale_price"].ParseToString(),
sku_cnt = row["sku_cnt"].ParseToNullableInt(),
sku_code = row["sku_code"].ParseToString(),
sku_deliver_info = row["sku_deliver_info"].ParseToString(),
sku_id = row["sku_id"].ParseToString(),
thumb_img = row["thumb_img"].ParseToString(),
title = row["title"].ParseToString(),
use_deduction = row["use_deduction"].ParseToString(),
};
orderItemList.Add(order);
}
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
var data = JsonUtils.SerializeObjectToString(orderItemList, jsonSetting);
var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000");
return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}";
}
catch (Exception ex)
{
return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}";
}
}
else
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
}
}