Files
KJD_WebService/KJDService/KJD_WebService/BLL/KJD/OrderManage.cs
T
2025-12-04 20:45:18 +08:00

259 lines
13 KiB
C#

using KJD_Web.Model;
using KJD_Web.Utils;
using NaiBa.Util.Extension;
using NaiBa.Util.Helper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
namespace KJD_Web.BLL
{
public class OrderManage
{
public string AddOrder(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
var time = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time);
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name");
if (string.IsNullOrEmpty(user_name))
{
return "{\"code\":500,\"msg\":\"没有用户名\"}";
}
var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'");
if (string.IsNullOrEmpty(shop_id))
return "{\"code\":500,\"msg\":\"请输入店铺\"}";
string order_data = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_data"))?.Replace("'", "\\'");
if (string.IsNullOrEmpty(order_data))
return "{\"code\":500,\"msg\":\"请输入订单\"}";
JObject jObj = null;
try
{
jObj = JObject.Parse(order_data);
}
catch
{
return "{\"code\":500,\"msg\":\"数据格式错误\"}";
}
long table_id = shop_id.ParseToLong() % 128;
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "";
sql = "insert into kjd_order.order_" + table_id + " (";
foreach (var item in jObj)
{
if (item.Key.ParseToString() != "id" && JsonConvert.SerializeObject(item.Value) != "null" &&
item.Key.ParseToString() != "add_time" && item.Key.ParseToString() != "mdy_time")
sql += item.Key + ",";
}
sql = sql.Trim(',');
sql += ")";
sql += "values (";
foreach (var item in jObj)
{
if (item.Key.ParseToString() != "id" && JsonConvert.SerializeObject(item.Value) != "null" &&
item.Key.ParseToString() != "add_time" && item.Key.ParseToString() != "mdy_time")
sql += "'" + item.Value.ParseToString().Replace("\\'", "'").Replace("'", "\\'") + "',";
}
sql = sql.Trim(',');
sql += ");";
var rst = mySql.ExecuteInsertId(sql);
mySql.Close();
if (rst > 0)
{
return "{\"code\":200,\"msg\":\"success\"}";
}
else
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string GetOrderList(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 user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'");
var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'");
if (string.IsNullOrEmpty(shop_id))
return "{\"code\":500,\"msg\":\"请输入查询店铺\",\"data\":[],\"count\":" + 0 + "}";
//var start_time = RegexUtils.GetStringQuery(ref inputData, "start_time")?.Replace("'", "\\'");
var start_time = TimeUtils.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-45));
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);
long table_id = shop_id.ParseToLong() % 128;
string sql = "select count(id) from kjd_order.order_" + table_id + " o where 1=1";
string where = "";
if (start_time > 0)
where += " and o.purchaseTime > " + start_time;
if (!string.IsNullOrWhiteSpace(shop_id))
where += " and o.supplierId = '" + shop_id + "'";
sql += where;
var count = mySql.ExecuteRowCount(sql);
DataTable dt;
if (count == 0)
{
dt = new DataTable();
}
else
{
sql = "SELECT * from kjd_order.order_" + table_id + " o where 1=1"; // p.is_del=0
//where子句
sql += where;
sql += " ORDER BY o.purchaseTime";
//sql += " ORDER BY o.select_total_count desc, p.id desc";
sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size;
dt = mySql.ExecuteDataTable(sql);
}
mySql.Close();
if (dt != null)
{
try
{
List<TemuDBOrderInfo> orderLst = new List<TemuDBOrderInfo>();
foreach (DataRow row in dt.Rows)
{
TemuDBOrderInfo prod = new TemuDBOrderInfo
{
id = Convert.ToInt32(row["id"]),
add_time = Convert.ToDateTime(row["add_time"]),
mdy_time = Convert.ToDateTime(row["mdy_time"]),
notes = row["notes"].ToString(),
availableSaleDays = row["availableSaleDays"].ParseToNullableDecimal(),
barCodeMd5 = row["barCodeMd5"].ParseToString(),
category = row["category"].ParseToString(),
className = row["className"].ParseToString(),
costPrice = row["costPrice"].ParseToNullableInt(),
currencyType = row["currencyType"].ParseToString(),
deliverQuantity = row["deliverQuantity"].ParseToInt(),
deliverTime = row["deliverTime"].ParseToNullableLong(),
deliveryFee = row["deliveryFee"].ParseToNullableInt(),
deliveryOrderSn = row["deliveryOrderSn"].ParseToString(),
expectLatestArrivalTimeOrDefault = row["expectLatestArrivalTimeOrDefault"].ParseToLong(),
expectLatestDeliverTimeOrDefault = row["expectLatestDeliverTimeOrDefault"].ParseToLong(),
extCode = row["extCode"].ParseToString(),
jiaTongCode = row["jiaTongCode"].ParseToString(),
markFee = row["markFee"].ParseToNullableInt(),
originalPurchaseOrderSn = row["originalPurchaseOrderSn"].ParseToString(),
productId = row["productId"].ParseToString(),
productName = row["productName"].ParseToString(),
productSkcPicture = row["productSkcPicture"].ParseToString(),
productSkcId = row["productSkcId"].ParseToString(),
productSkuId = row["productSkuId"].ParseToString(),
productSn = row["productSn"].ParseToString(),
purchaseQuantity = row["purchaseQuantity"].ParseToInt(),
purchaseTime = row["purchaseTime"].ParseToLong(),
qcResult = row["qcResult"].ParseToNullableInt(),
realReceiveAuthenticQuantity = row["realReceiveAuthenticQuantity"].ParseToInt(),
receiveTime = row["receiveTime"].ParseToNullableLong(),
receiveWarehouseId = row["receiveWarehouseId"].ParseToString(),
receiveWarehouseName = row["receiveWarehouseName"].ParseToString(),
shippingMarkMd5 = row["shippingMarkMd5"].ParseToString(),
status = row["status"].ParseToInt(),
subPurchaseOrderSn = row["subPurchaseOrderSn"].ParseToString(),
supplierId = row["supplierId"].ParseToString(),
supplierName = row["supplierName"].ParseToString(),
supplierPrice = row["supplierPrice"].ParseToInt(),
thumbUrlList = row["thumbUrlList"].ParseToString(),
upLoadStatus = row["upLoadStatus"].ParseToInt(),
upProductId = row["upProductId"].ParseToString(),
warehouseGroupId = row["warehouseGroupId"].ParseToString(),
};
orderLst.Add(prod);
}
var data = JsonUtils.SerializerObjectToString(orderLst);
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 UpdateOrderStatus1(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 user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'");
var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'");
if (string.IsNullOrEmpty(shop_id))
return "{\"code\":500,\"msg\":\"请输入查询店铺\"}";
var product_id = RegexUtils.GetStringQuery(ref inputData, "product_id")?.Replace("'", "\\'");
if (string.IsNullOrEmpty(product_id))
return "{\"code\":500,\"msg\":\"请输入商品编号\"}";
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);
long table_id = shop_id.ParseToLong() % 128;
string sql = "update kjd_order.order_" + table_id + " o set o.upLoadStatus=1";
string where = "";
where += " and o.supplierId = '" + shop_id + "'";
where += " and o.productId = '" + product_id + "'";
where += " and o.upLoadStatus < 1";
sql += where;
var rst = mySql.ExecuteNonQuery(sql);
if (rst)
{
return "{\"code\":200,\"msg\":\"success\"}";
}
else
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
}
}