diff --git a/KJDService/KJD_WebService/App_Data/ApiLogs/.gitignore b/KJDService/KJD_WebService/App_Data/ApiLogs/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/KJDService/KJD_WebService/App_Data/ApiLogs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/KJDService/KJD_WebService/BLL/WXXD/WXOrderManage.cs b/KJDService/KJD_WebService/BLL/WXXD/WXOrderManage.cs index 26e8a33..bc48c85 100644 --- a/KJDService/KJD_WebService/BLL/WXXD/WXOrderManage.cs +++ b/KJDService/KJD_WebService/BLL/WXXD/WXOrderManage.cs @@ -1,1926 +1,1952 @@ using KJD_Web.Model.WxModel; using KJD_Web.Utils; using MySql.Data.MySqlClient; +using MySqlX.XDevAPI; using NaiBa.Util.Extension; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; +using System.Data.SqlClient; +using System.Drawing.Printing; 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)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - var erp_shop_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_shop_id_in")?.Replace("'", "\\'"); - var erp_order_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_order_id_in")?.Replace("'", "\\'"); - if (erp_shop_id_in.IsNullOrEmpty() && erp_order_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(erp_order_id_in)) - where += " and o.order_id in ('" + erp_order_id_in.Replace(",", "','") + "')"; - 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.update_time >= " + start_time; - if (end_time > 0) - where += " and o.update_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 - { - //tinyint(1)中存超过两个值,只返回true或false,无法直接取值解决办法 - //解决方法: - //1.强制修改mapResult中的映射,将po属性的类型由Boolean改为Byte - //2.查询 tinyint(1) 的sql 字段时,转为(status + 0) as status - //3.避免使用 tinyint(1) 作为字段的数据类型 - - sql = "SELECT o.*,(out_shipped+0) as out_shipped_int 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 orderList = new List(); - foreach (DataRow row in dt.Rows) - { - oms_wei_order order = new oms_wei_order - { - id = row["id"].ParseToLong(), - aftersale_detail = row["aftersale_detail"].ParseToNullableString(), - audit_status = row["audit_status"].ParseToNullableInt(), - audit_time = row["audit_time"].ParseToNullableString().ParseToDateTime(), - city_name = row["city_name"].ParseToNullableString(), - colour_flag = row["colour_flag"].ParseToNullableInt(), - colour_flag_update_time = row["colour_flag_update_time"].ParseToNullableString().ParseToDateTime(), - commission_amount = row["commission_amount"].ParseToNullableInt(), - county_name = row["county_name"].ParseToNullableString(), - create_time = row["create_time"].ParseToInt(), - delivery_deadline = row["delivery_deadline"].ParseToNullableInt(), - delivery_product_info = row["delivery_product_info"].ParseToNullableString(), - delivery_time = row["delivery_time"].ParseToNullableInt(), - detail_info = row["detail_info"].ParseToNullableString(), - discounted_price = row["discounted_price"].ParseToNullableInt(), - erp_send_code = row["erp_send_code"].ParseToNullableString(), - erp_send_company = row["erp_send_company"].ParseToNullableString(), - erp_send_status = row["erp_send_status"].ParseToNullableInt(), - erp_send_time = row["erp_send_time"].ParseToNullableString().ParseToDateTime(), - ewaybill_order_code = row["ewaybill_order_code"].ParseToNullableString(), - external_gift = row["external_gift"].ParseToNullableInt(), - ext_info = row["ext_info"].ParseToNullableString(), - 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"].ParseToNullableString(), - has_freight_insurance = row["has_freight_insurance"].ParseToNullableInt(), - house_number = row["house_number"].ParseToNullableString(), - 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"].ParseToNullableString(), - order_id = row["order_id"].ParseToNullableString(), - order_price = row["order_price"].ParseToNullableInt(), - out_account = row["out_account"].ParseToNullableString(), - out_after_sale_status = row["out_after_sale_status"].ParseToNullableString(), - out_amount = row["out_amount"].ParseToNullableInt(), - out_express_company = row["out_express_company"].ParseToNullableString(), - out_express_no = row["out_express_no"].ParseToNullableString(), - out_order_no = row["out_order_no"].ParseToNullableString(), - out_shipped = row["out_shipped_int"].ParseToNullableInt(), - pay_info = row["pay_info"].ParseToNullableString(), - postal_code = row["postal_code"].ParseToNullableString(), - predict_commission_fee = row["predict_commission_fee"].ParseToNullableInt(), - product_price = row["product_price"].ParseToNullableInt(), - profit = row["profit"].ParseToNullableInt(), - province_name = row["province_name"].ParseToNullableString(), - purchase_price = row["purchase_price"].ParseToNullableInt(), - purchase_status = row["purchase_status"].ParseToNullableInt(), - purchase_time = row["purchase_time"].ParseToNullableInt(), - settle_info = row["settle_info"].ParseToNullableString(), - ship_done_time = row["ship_done_time"].ParseToNullableInt(), - shop_id = row["shop_id"].ParseToLong(), - shop_name = row["shop_name"].ParseToNullableString(), - shop_remark = row["shop_remark"].ParseToNullableString(), - soft_remark = row["soft_remark"].ParseToNullableString(), - status = row["status"].ParseToNullableInt(), - supplier_remark_exception = row["supplier_remark_exception"].ParseToNullableString(), - tel_number = row["tel_number"].ParseToNullableString(), - tel_number_ext_info = row["tel_number_ext_info"].ParseToNullableString(), - transfer_warehouse_status = row["transfer_warehouse_status"].ParseToNullableInt(), - unionid = row["unionid"].ParseToNullableString(), - update_time = row["update_time"].ParseToInt(), - user_name = row["user_name"].ParseToNullableString(), - use_tel_number = row["use_tel_number"].ParseToNullableInt(), - virtual_order_tel_number = row["virtual_order_tel_number"].ParseToNullableString(), - }; - if (order.order_id == "3737914129536416512") - { - - } - orderList.Add(order); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(orderList, 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\":\"输入为空\"}"; - } - - - 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 orderItemList = new List(); - 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"].ParseToNullableString(), - 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"].ParseToNullableString(), - finish_aftersale_sku_cnt = row["finish_aftersale_sku_cnt"].ParseToNullableInt(), - is_change_price = row["is_change_price"].ParseToNullableString(), - is_discounted = row["is_discounted"].ParseToNullableString(), - 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"].ParseToNullableString(), - out_product_id = row["out_product_id"].ParseToNullableString(), - out_sku_id = row["out_sku_id"].ParseToNullableString(), - out_warehouse_id = row["out_warehouse_id"].ParseToNullableString(), - product_id = row["product_id"].ParseToNullableString(), - real_price = row["real_price"].ParseToNullableInt(), - refund_status = row["refund_status"].ParseToNullableInt(), - return_address = row["return_address"].ParseToNullableString(), - sale_price = row["sale_price"].ParseToNullableInt(), - sku_attrs = row["sku_attrs"].ParseToNullableString(), - sku_cnt = row["sku_cnt"].ParseToNullableInt(), - sku_code = row["sku_code"].ParseToNullableString(), - sku_deliver_info = row["sku_deliver_info"].ParseToNullableString(), - sku_id = row["sku_id"].ParseToNullableString(), - thumb_img = row["thumb_img"].ParseToNullableString(), - title = row["title"].ParseToNullableString(), - use_deduction = row["use_deduction"].ParseToNullableString(), - }; - 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\":\"输入为空\"}"; - } - - - public string WXGetErpRefundList(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_refund 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_refund 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 refundItemList = new List(); - foreach (DataRow row in dt.Rows) - { - oms_wei_refund order = new oms_wei_refund - { - id = row["id"].ParseToLong(), - merchant_id = row["merchant_id"].ParseToLong(), - order_id = row["order_id"].ParseToNullableString(), - shop_id = row["shop_id"].ParseToLong(), - erp_goods_id = row["erp_goods_id"].ParseToNullableLong(), - erp_goods_sku_id = row["erp_goods_sku_id"].ParseToNullableLong(), - product_id = row["product_id"].ParseToNullableString(), - sku_id = row["sku_id"].ParseToNullableString(), - after_sale_order_id = row["after_sale_order_id"].ParseToNullableString(), - complaint_id = row["complaint_id"].ParseToNullableString(), - count = row["count"].ParseToNullableInt(), - create_time = row["create_time"].ParseToNullableInt(), - details = row["details"].ParseToNullableString(), - fast_refund = row["fast_refund"].ParseToNullableString(), - merchant_upload_info = row["merchant_upload_info"].ParseToNullableString(), - openid = row["openid"].ParseToNullableString(), - pull_status = row["pull_status"].ParseToNullableInt(), - pull_time = row["pull_time"].ParseToNullableString().ParseToDateTime(), - reason = row["reason"].ParseToNullableString(), - reason_text = row["reason_text"].ParseToNullableString(), - refund_amount = row["refund_amount"].ParseToNullableInt(), - refund_reason = row["refund_reason"].ParseToNullableInt(), - refund_resp = row["refund_resp"].ParseToNullableString(), - return_delivery_id = row["return_delivery_id"].ParseToNullableString(), - return_delivery_name = row["return_delivery_name"].ParseToNullableString(), - return_waybill_id = row["return_waybill_id"].ParseToNullableString(), - status = row["status"].ParseToNullableString(), - type = row["type"].ParseToNullableString(), - unionid = row["unionid"].ParseToNullableString(), - update_time = row["update_time"].ParseToNullableInt(), - warehouse_status = row["warehouse_status"].ParseToNullableInt(), - return_city = row["return_city"].ParseToNullableString(), - return_county = row["return_county"].ParseToNullableString(), - return_detail = row["return_detail"].ParseToNullableString(), - return_province = row["return_province"].ParseToNullableString(), - return_tel = row["return_tel"].ParseToNullableString(), - return_user_name = row["return_user_name"].ParseToNullableString(), - }; - refundItemList.Add(order); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(refundItemList, 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\":\"输入为空\"}"; - } - - - - - /// - /// 微信添加修改采购映射商品(含sku映射和) - /// - /// - /// - public string WXAddMdyBuyProdMap(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - // 软件用户名 - string spu_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_code"))?.Replace("'", "\\'"); - string sku_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_code"))?.Replace("'", "\\'"); - string user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_user_name"))?.Replace("'", "\\'"); - string map_url = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_url"))?.Replace("'", "\\'"); - string map_goods_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_goods_name"))?.Replace("'", "\\'"); - string map_spec_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_spec_name"))?.Replace("'", "\\'"); - string map_goods_id = RegexUtils.GetStringQuery(ref inputData, "map_goods_id")?.Replace("'", "\\'"); - string map_sku_id = RegexUtils.GetStringQuery(ref inputData, "map_sku_id")?.Replace("'", "\\'"); - string map_send_address = RegexUtils.GetStringQuery(ref inputData, "map_send_address")?.Replace("'", "\\'"); - string transit_warehouse_id = RegexUtils.GetStringQuery(ref inputData, "transit_warehouse_id")?.Replace("'", "\\'"); - - if (string.IsNullOrEmpty(spu_code) || string.IsNullOrEmpty(sku_code)) - return "{\"code\":500,\"msg\":\"缺少系统商品或SKU编号\"}"; - if (string.IsNullOrEmpty(user_name)) - return "{\"code\":500,\"msg\":\"缺少用户名\"}"; - if (string.IsNullOrEmpty(map_url) && (string.IsNullOrEmpty(map_goods_id) || string.IsNullOrEmpty(map_sku_id))) - return "{\"code\":500,\"msg\":\"缺少采购商品信息\"}"; - if (string.IsNullOrEmpty(transit_warehouse_id)) - return "{\"code\":500,\"msg\":\"缺少中转仓信息\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = "SELECT 1 FROM `bxx`.`product_buy_map` where user_name='" + user_name + "' AND spu_code='" + spu_code + "' AND sku_code='" + sku_code + "'"; - string where = ""; - sql += where; - var exist = mySql.ExecuteFirstInt(sql); - if (!mySql.Message.IsNullOrEmpty()) - { - mySql.Close(); - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; - } - - if (exist == 0) - { - sql = " INSERT INTO `bxx`.`product_buy_map` (user_name,spu_code,sku_code,map_url,map_goods_name,map_spec_name,map_goods_id,map_sku_id,map_send_address,transit_warehouse_id)" + - " VALUES (@user_name,@spu_code,@sku_code,@map_url,@map_goods_name,@map_spec_name,@map_goods_id,@map_sku_id,@map_send_address,@transit_warehouse_id);"; - } - else - { - sql = "UPDATE `bxx`.`product_buy_map` SET "; - if (map_url != null) - sql += " map_url=@map_url,"; - if (map_goods_name != null) - sql += " map_goods_name=@map_goods_name,"; - if (map_spec_name != null) - sql += " map_spec_name=@map_spec_name,"; - if (map_goods_id != null) - sql += " map_goods_id=@map_goods_id,"; - if (map_sku_id != null) - sql += " map_sku_id=@map_sku_id,"; - if (map_send_address != null) - sql += " map_send_address=@map_send_address,"; - if (transit_warehouse_id != null) - sql += " transit_warehouse_id=@transit_warehouse_id,"; - sql = sql.TrimEnd(','); - sql += " WHERE user_name=@user_name and spu_code=@spu_code and sku_code=@sku_code;"; - } - - List paramLst = new List(); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "spu_code", Value = spu_code, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_code", Value = sku_code, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_url", Value = map_url, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_goods_name", Value = map_goods_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_spec_name", Value = map_spec_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_goods_id", Value = map_goods_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_sku_id", Value = map_sku_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_send_address", Value = map_send_address, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "transit_warehouse_id", Value = transit_warehouse_id, }); - mySql.ExecuteNonQuery(sql, paramLst.ToArray()); - mySql.Close(); - if (string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; - } - else - { - return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - /// - /// 微信获取采购映射商品 - /// - /// - /// - public string WXGetBuyPordMap(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); - string spu_codes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_codes"))?.Replace("'", "\\'"); - string sku_codes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_codes"))?.Replace("'", "\\'"); - string user_name = RegexUtils.GetStringQuery(ref inputData, "main_user_name")?.Replace("'", "\\'"); - string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(spu_codes)) - return "{\"code\":500,\"msg\":\"商品编码不能为空\"}"; - if (string.IsNullOrEmpty(user_name)) - return "{\"code\":500,\"msg\":\"用户名不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = "SELECT COUNT(*) FROM `bxx`.`product_buy_map` WHERE 1=1"; - string where = ""; - if (spu_codes != null) - where += " and spu_code IN ('" + spu_codes.Replace(",", "','") + "')"; - if (sku_codes != null) - where += " and sku_code IN ('" + sku_codes.Replace(",", "','") + "')"; - if (user_name != null) - where += " and user_name='" + user_name + "'"; - sql += where; - sql += ";"; - - if (not_count == "false") - count = mySql.ExecuteRowCount(sql); - - DataTable dt; - if (count == 0) - { - dt = new DataTable(); - } - else - { - sql = "SELECT * FROM `bxx`.`product_buy_map` WHERE 1=1"; - sql += where; - sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; - dt = mySql.ExecuteDataTable(sql); - } - mySql.Close(); - - if (dt != null) - { - try - { - List WXBuyMapInfoLst = new List(); - foreach (DataRow row in dt.Rows) - { - WXBuyMapInfoLst.Add(new WXBuyMapInfo() - { - id = row["id"].ParseToInt(), - user_name = row["user_name"].ParseToNullableString(), - spu_code = row["spu_code"].ParseToNullableString(), - sku_code = row["sku_code"].ParseToNullableString(), - map_url = row["map_url"].ParseToNullableString(), - map_goods_name = row["map_goods_name"].ParseToNullableString(), - map_spec_name = row["map_spec_name"].ParseToNullableString(), - map_goods_id = row["map_goods_id"].ParseToNullableString(), - map_sku_id = row["map_sku_id"].ParseToNullableString(), - map_send_address = row["map_send_address"].ParseToNullableString(), - transit_warehouse_id = row["transit_warehouse_id"].ParseToNullableString(), - add_time = Convert.ToDateTime(row["add_time"]), - mdy_time = Convert.ToDateTime(row["mdy_time"]), - }); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(WXBuyMapInfoLst, 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\":\"输入为空\"}"; - } - - /// - /// 获取中转仓订单信息 - /// - /// - /// - public string WXGetTransitOrder(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); - string order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_no"))?.Replace("'", "\\'"); - string order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_sku_id"))?.Replace("'", "\\'"); - string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); - string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); - string transfer_warehouse_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "transfer_warehouse_status"))?.Replace("'", "\\'"); - string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); - string is_admin = RegexUtils.GetStringQuery(ref inputData, "is_admin")?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(order_no) && string.IsNullOrEmpty(out_order_no) && string.IsNullOrEmpty(order_sku_id) && is_admin != "true") - return "{\"code\":500,\"msg\":\"中转订单查询信息不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = "SELECT COUNT(*) FROM `erp`.`oms_wei_external_procurement_log` WHERE 1=1"; - string where = ""; - if (order_no != null) - where += " and order_no IN ('" + order_no.Replace(",", "','") + "')"; - if (order_sku_id != null) - where += " and order_sku_id IN ('" + order_sku_id.Replace(",", "','") + "')"; - if (out_order_no != null) - where += " and out_order_no IN ('" + out_order_no.Replace(",", "','") + "')"; - // 取号状态 - if (pre_allocated_order_no != null) - where += " and pre_allocated_order_no IN (" + pre_allocated_order_no + ")"; - // 仓库状态 - if (transfer_warehouse_status != null) - where += " and transfer_warehouse_status IN (" + transfer_warehouse_status + ")"; - sql += where; - sql += ";"; - - if (not_count == "false") - count = mySql.ExecuteRowCount(sql); - - DataTable dt; - if (count == 0) - { - dt = new DataTable(); - } - else - { - sql = "SELECT * FROM `erp`.`oms_wei_external_procurement_log` WHERE 1=1"; - sql += where; - sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; - - // 客戶端查兩次 - //if (is_admin == "true") - //{ - // sql = "SELECT e.*,o.create_time as order_create_time FROM erp.oms_wei_external_procurement_log e LEFT JOIN erp.oms_wei_order ON e.order_no = o.order_id WHERE 1=1"; - // sql += where; - // sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; - //} - - dt = mySql.ExecuteDataTable(sql); - } - mySql.Close(); - - if (dt != null) - { - try - { - List oms_wei_external_procurement_log_list = new List(); - foreach (DataRow row in dt.Rows) - { - oms_wei_external_procurement_log_list.Add(new oms_wei_external_procurement_log() - { - id = row["id"].ParseToInt(), - buyer_account = row["buyer_account"].ParseToNullableString(), - order_no = row["order_no"].ParseToNullableString(), - order_sku_id = row["order_sku_id"].ParseToNullableString(), - out_amount = row["out_amount"].ParseToNullableInt(), - out_order_no = row["out_order_no"].ParseToNullableString(), - purchaser_note = row["purchaser_note"].ParseToNullableString(), - created_time = row["created_time"].ParseToNullableString().ParseToDateTime(), - express_1_company = row["express_1_company"].ParseToNullableString(), - express_1_waybill = row["express_1_waybill"].ParseToNullableString(), - express_2_company = row["express_2_company"].ParseToNullableString(), - express_2_waybill = row["express_2_waybill"].ParseToNullableString(), - order_code = row["order_code"].ParseToNullableString(), - order_platform_code = row["order_platform_code"].ParseToNullableString(), - pickup_time = row["pickup_time"].ParseToNullableString().ParseToDateTime(), - platform = row["platform"].ParseToNullableString(), - pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), - raw_message = row["raw_message"].ParseToNullableString(), - refund_status = row["refund_status"].ParseToNullableString(), - transfer_warehouse_status = row["transfer_warehouse_status"].ParseToNullableInt(), - updated_time = row["updated_time"].ParseToNullableString().ParseToDateTime(), - is_transfer_ship = row["is_transfer_ship"].ParseToNullableInt(), - random_code = row["random_code"].ParseToNullableString(), - transfer_refund_status = row["transfer_refund_status"].ParseToNullableInt(), - order_void_status = row["order_void_status"].ParseToNullableInt(), - warehouse_status = row["warehouse_status"].ParseToNullableInt(), - inbound_time = row["inbound_time"].ParseToNullableString().ParseToDateTimeNullable(), - outbound_time = row["outbound_time"].ParseToNullableString().ParseToDateTimeNullable(), - }); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(oms_wei_external_procurement_log_list, 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\":\"输入为空\"}"; - } - - /// - /// 修改中转仓订单信息(真实物流),临时补救 - /// - /// - /// - public string WXUpdateErpOrderExpress(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); - string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); - string express_1_company = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "express_1_company"))?.Replace("'", "\\'"); - string express_1_waybill = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "express_1_waybil"))?.Replace("'", "\\'"); - string refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refund_status"))?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(out_order_no)) - return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; - //if (string.IsNullOrEmpty(express_1_company)) - // return "{\"code\":500,\"msg\":\"物流公司不能为空\"}"; - //if (string.IsNullOrEmpty(express_1_waybill)) - // return "{\"code\":500,\"msg\":\"物流单号不能为空\"}"; - - if (string.IsNullOrEmpty(express_1_company) && string.IsNullOrEmpty(express_1_waybill) && string.IsNullOrEmpty(refund_status)) - return "{\"code\":500,\"msg\":\"修改信息不能为空\"}"; - - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = " update `erp`.`oms_wei_external_procurement_log` set "; - if (!string.IsNullOrEmpty(express_1_company)) - sql += " express_1_company='" + express_1_company + "',"; - if (!string.IsNullOrEmpty(express_1_waybill)) - sql += " express_1_waybill='" + express_1_waybill + "',"; - if (!string.IsNullOrEmpty(refund_status)) - sql += " refund_status='" + refund_status + "',"; - sql = sql.TrimEnd(','); - sql += " where out_order_no = '" + out_order_no + "';"; - - count = mySql.ExecuteAffectedRows(sql); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - /// - /// 修改中转仓订单信息(取号状态),临时补救 - /// - /// - /// - public string WXUpdateErpAllocatedOrderNo(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); - string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); - string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(out_order_no)) - return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = " update `erp`.`oms_wei_external_procurement_log` set "; - if (!string.IsNullOrEmpty(pre_allocated_order_no)) - sql += " pre_allocated_order_no=" + pre_allocated_order_no + ","; - sql = sql.TrimEnd(','); - sql += " where out_order_no = '" + out_order_no + "';"; - - count = mySql.ExecuteAffectedRows(sql); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - /// - /// 删除中转仓订单 临时补救,慎用 - /// - /// - /// - public string WXDelErpTransitWarehouseOrder(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(out_order_no)) - return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = " DELETE FROM `erp`.`oms_wei_external_procurement_log` WHERE out_order_no in ('" + out_order_no.Replace(",", "','") + "')"; - - count = mySql.ExecuteAffectedRows(sql); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - if (count == 0) - { - return "{\"code\":500,\"msg\":\"删除失败,订单不存在\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - /// - /// 修改订单软件备注 - /// - /// - /// - public string WXUpdateErpSoftRemark(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); - string soft_remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "soft_remark"))?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(order_id)) - return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = " update erp.oms_wei_order set "; - if (soft_remark != null) - sql += " soft_remark='" + soft_remark + "',"; - sql = sql.TrimEnd(','); - sql += " where order_id = '" + order_id + "';"; - - count = mySql.ExecuteAffectedRows(sql); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXUpdateErpOutAfterSaleStatus(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(order_id)) - return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; - string out_after_sale_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_after_sale_status"))?.Replace("'", "\\'"); - if (out_after_sale_status == null) - return "{\"code\":500,\"msg\":\"售后状态不能为NULL\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = " update erp.oms_wei_order set "; - if (out_after_sale_status != null) - { - if (out_after_sale_status == "" || out_after_sale_status == "NULL") - sql += " out_after_sale_status=NULL,"; - else - sql += " out_after_sale_status='" + out_after_sale_status + "',"; - } - sql = sql.TrimEnd(','); - sql += " where order_id = '" + order_id + "';"; - - count = mySql.ExecuteAffectedRows(sql); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXAddMdyBuyerOrder(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - string wx_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); - string wx_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); - string wx_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_send_type"))?.Replace("'", "\\'"); - if (wx_send_type.IsNullOrEmpty()) - wx_send_type = "0"; - string TransitCreateTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "TransitCreateTime"))?.Replace("'", "\\'"); - string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); - string buyerId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerId"))?.Replace("'", "\\'"); - string buyerName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerName"))?.Replace("'", "\\'"); - string pdd_order_sn = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pdd_order_sn"))?.Replace("'", "\\'"); - string order_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_amount"))?.Replace("'", "\\'"); - string order_time = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_time"))?.Replace("'", "\\'"); - string outExpressCompanyCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "outExpressCompanyCode"))?.Replace("'", "\\'"); - string tracking_number = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "tracking_number"))?.Replace("'", "\\'"); - string order_status_prompt = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_status_prompt"))?.Replace("'", "\\'"); - string after_sales_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sales_status"))?.Replace("'", "\\'"); - string order_detail = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_detail"))?.Replace("'", "\\'"); - string wx_order_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_send_type"))?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(wx_order_send_type)) - wx_order_send_type = "1"; - if (string.IsNullOrEmpty(wx_order_id) || string.IsNullOrEmpty(pdd_order_sn)) - return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = "select id from wxxd.order_pdd_buyer_order where order_sn='" + pdd_order_sn + "'"; - var id = mySql.ExecuteFirstInt(sql); - if (!string.IsNullOrEmpty(mySql.Message)) - { - mySql.Close(); - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - - //sql = "INSERT INTO wxxd.order_pdd_buyer_order (wx_order_id,wx_sku_id,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,order_sn,order_amount,order_time," + - // "outExpressCompanyCode,tracking_number,order_status_prompt,after_sales_status,order_detail)"; - //sql += "VALUES(@wx_order_id,@wx_sku_id,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@pdd_order_sn,@order_amount,@order_time," + - // "@outExpressCompanyCode,@tracking_number,@order_status_prompt,@after_sales_status,@order_detail)"; - //sql += " ON DUPLICATE KEY UPDATE wx_order_id=VALUES(@wx_order_id),wx_sku_id=VALUES(@wx_sku_id),TransitCreateTime=VALUES(@TransitCreateTime)," + - // "pre_allocated_order_no=VALUES(@pre_allocated_order_no),buyerId=VALUES(@buyerId),buyerName=VALUES(@buyerName),order_amount=VALUES(@order_amount)," + - // "order_time=VALUES(@order_time),outExpressCompanyCode=VALUES(@outExpressCompanyCode),tracking_number=VALUES(@tracking_number),order_status_prompt=VALUES(@order_status_prompt)," + - // "after_sales_status=VALUES(@after_sales_status),order_detail=VALUES(@order_detail)"; - - if (id == 0) - { - sql = "INSERT INTO wxxd.order_pdd_buyer_order (wx_order_id,wx_sku_id,wx_send_type,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,order_sn,order_amount,order_time," + - "outExpressCompanyCode,tracking_number,order_status_prompt,after_sales_status,order_detail,wx_order_send_type)"; - sql += "VALUES(@wx_order_id,@wx_sku_id,@wx_send_type,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@pdd_order_sn,@order_amount,@order_time," + - "@outExpressCompanyCode,@tracking_number,@order_status_prompt,@after_sales_status,@order_detail@wx_order_send_type);"; - } - else - { - sql = "UPDATE wxxd.order_pdd_buyer_order SET "; - if (!string.IsNullOrEmpty(wx_order_id)) - sql += " wx_order_id=@wx_order_id,"; - if (!string.IsNullOrEmpty(wx_sku_id)) - sql += " wx_sku_id=@wx_sku_id,"; - if (!string.IsNullOrEmpty(wx_send_type)) - sql += " wx_send_type=@wx_send_type,"; - if (!string.IsNullOrEmpty(TransitCreateTime)) - sql += " TransitCreateTime=@TransitCreateTime,"; - if (!string.IsNullOrEmpty(pre_allocated_order_no)) - sql += " pre_allocated_order_no=@pre_allocated_order_no,"; - if (!string.IsNullOrEmpty(buyerId)) - sql += " buyerId=@buyerId,"; - if (!string.IsNullOrEmpty(buyerName)) - sql += " buyerName=@buyerName,"; - if (!string.IsNullOrEmpty(order_amount)) - sql += " order_amount=@order_amount,"; - if (!string.IsNullOrEmpty(order_time)) - sql += " order_time=@order_time,"; - if (!string.IsNullOrEmpty(outExpressCompanyCode)) - sql += " outExpressCompanyCode=@outExpressCompanyCode,"; - if (!string.IsNullOrEmpty(tracking_number)) - sql += " tracking_number=@tracking_number,"; - if (!string.IsNullOrEmpty(order_status_prompt)) - sql += " order_status_prompt=@order_status_prompt,"; - if (!string.IsNullOrEmpty(after_sales_status)) - sql += " after_sales_status=@after_sales_status,"; - if (!string.IsNullOrEmpty(order_detail)) - sql += " order_detail=@order_detail,"; - if (!string.IsNullOrEmpty(wx_order_send_type)) - sql += " wx_order_send_type=@wx_order_send_type,"; - sql = sql.TrimEnd(','); - sql += " where order_sn=@pdd_order_sn"; - } - //260705-105706954352823 - - - List paramLst = new List(); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_order_id", Value = wx_order_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_sku_id", Value = wx_sku_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "wx_send_type", Value = wx_send_type.ParseToInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "TransitCreateTime", Value = TransitCreateTime.ParseToDateTime(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "pre_allocated_order_no", Value = pre_allocated_order_no.ParseToInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerId", Value = buyerId, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerName", Value = buyerName, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "pdd_order_sn", Value = pdd_order_sn, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "order_amount", Value = order_amount.ParseToNullableInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int64, ParameterName = "order_time", Value = order_time.ParseToLong(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "outExpressCompanyCode", Value = outExpressCompanyCode, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "tracking_number", Value = tracking_number, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_status_prompt", Value = order_status_prompt, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "after_sales_status", Value = after_sales_status.ParseToInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "wx_order_send_type", Value = wx_order_send_type.ParseToInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_detail", Value = order_detail, }); - //sql = " update `wxxd`.`order_pdd_buyer_order` set "; - //if (!string.IsNullOrEmpty(soft_remark)) - // sql += " soft_remark=" + soft_remark + ","; - //sql = sql.TrimEnd(','); - //sql += " where order_id = '" + wx_order_id + "';"; - - count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXGetBuyerOrderList(string inputData, bool isDetail = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); - var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); - if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) - { - 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 wxxd.order_pdd_buyer_order o WHERE 1=1 "; - - string where = ""; - if (!string.IsNullOrWhiteSpace(wx_order_id_in)) - where += " and o.wx_order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; - if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) - where += " and o.order_sn in ('" + buyer_order_sn_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" + - " wxxd.order_pdd_buyer_order 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 buyerOrderList = new List(); - foreach (DataRow row in dt.Rows) - { - order_pdd_buyer_order order = new order_pdd_buyer_order - { - id = row["id"].ParseToLong(), - add_time = row["add_time"].ParseToString().ParseToDateTime(), - after_sales_status = row["after_sales_status"].ParseToNullableInt(), - buyerId = row["buyerId"].ParseToString(), - buyerName = row["buyerName"].ParseToString(), - mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), - order_amount = row["order_amount"].ParseToNullableInt(), - order_detail = row["order_detail"].ParseToString(), - order_sn = row["order_sn"].ParseToString(), - order_status_prompt = row["order_status_prompt"].ParseToString(), - order_time = row["order_time"].ParseToNullableLong(), - outExpressCompanyCode = row["outExpressCompanyCode"].ParseToString(), - pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), - tracking_number = row["tracking_number"].ParseToString(), - TransitCreateTime = row["TransitCreateTime"].ParseToString().ParseToDateTime(), - wx_order_id = row["wx_order_id"].ParseToString(), - wx_sku_id = row["wx_sku_id"].ParseToString(), - wx_order_send_type = row["wx_order_send_type"].ParseToNullableInt(), - wx_send_type = row["wx_send_type"].ParseToInt(), - }; - buyerOrderList.Add(order); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(buyerOrderList, 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\":\"输入为空\"}"; - } - - - public string WXAddMdyBuyerAfterSale(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - string wx_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); - string wx_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); - string wx_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_send_type"))?.Replace("'", "\\'"); - if (wx_send_type.IsNullOrEmpty()) - wx_send_type = "0"; - string TransitCreateTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "TransitCreateTime"))?.Replace("'", "\\'"); - string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); - string buyerId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerId"))?.Replace("'", "\\'"); - string buyerName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerName"))?.Replace("'", "\\'"); - string orderSn = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderSn"))?.Replace("'", "\\'"); - string afterSalesId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "afterSalesId"))?.Replace("'", "\\'"); - string orderAmount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderAmount"))?.Replace("'", "\\'"); - string orderDate = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderDate"))?.Replace("'", "\\'"); - string order_detail = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_detail"))?.Replace("'", "\\'"); - string refundAmount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refundAmount"))?.Replace("'", "\\'"); - string statusText = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "statusText"))?.Replace("'", "\\'"); - string afterSaleAddress = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "afterSaleAddress"))?.Replace("'", "\\'"); - string is_mdy = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "is_mdy"))?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(wx_order_id) || string.IsNullOrEmpty(orderSn) || string.IsNullOrEmpty(afterSalesId)) - return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = "select id from wxxd.order_pdd_buyer_after_sale where afterSalesId='" + afterSalesId + "'"; - var id = mySql.ExecuteFirstInt(sql); - if (!string.IsNullOrEmpty(mySql.Message)) - { - mySql.Close(); - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - - if (id == 0 && is_mdy != "true") - { - sql = "INSERT INTO wxxd.order_pdd_buyer_after_sale (wx_order_id,wx_sku_id,wx_send_type,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,orderSn,afterSalesId,orderAmount,orderDate," + - "refundAmount,statusText,afterSaleAddress,order_detail)"; - sql += "VALUES(@wx_order_id,@wx_sku_id,@wx_send_type,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@orderSn,@afterSalesId,@orderAmount,@orderDate," + - "@refundAmount,@statusText,@afterSaleAddress,@order_detail);"; - } - else - { - sql = "UPDATE wxxd.order_pdd_buyer_after_sale SET "; - if (!string.IsNullOrEmpty(wx_order_id)) - sql += " wx_order_id=@wx_order_id,"; - if (!string.IsNullOrEmpty(wx_sku_id)) - sql += " wx_sku_id=@wx_sku_id,"; - if (!string.IsNullOrEmpty(wx_send_type)) - sql += " wx_send_type=@wx_send_type,"; - if (!string.IsNullOrEmpty(TransitCreateTime)) - sql += " TransitCreateTime=@TransitCreateTime,"; - if (!string.IsNullOrEmpty(pre_allocated_order_no)) - sql += " pre_allocated_order_no=@pre_allocated_order_no,"; - if (!string.IsNullOrEmpty(buyerId)) - sql += " buyerId=@buyerId,"; - if (!string.IsNullOrEmpty(buyerName)) - sql += " buyerName=@buyerName,"; - if (!string.IsNullOrEmpty(orderSn)) - sql += " orderSn=@orderSn,"; - if (!string.IsNullOrEmpty(orderAmount)) - sql += " orderAmount=@orderAmount,"; - if (!string.IsNullOrEmpty(refundAmount)) - sql += " refundAmount=@refundAmount,"; - if (!string.IsNullOrEmpty(statusText)) - sql += " statusText=@statusText,"; - if (!string.IsNullOrEmpty(orderDate)) - sql += " orderDate=@orderDate,"; - if (!string.IsNullOrEmpty(afterSaleAddress)) - sql += " afterSaleAddress=@afterSaleAddress,"; - - if (!string.IsNullOrEmpty(order_detail)) - sql += " order_detail=@order_detail,"; - sql = sql.TrimEnd(','); - sql += " where afterSalesId=@afterSalesId"; - } - - List paramLst = new List(); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_order_id", Value = wx_order_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_sku_id", Value = wx_sku_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "wx_send_type", Value = wx_send_type.ParseToInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "TransitCreateTime", Value = TransitCreateTime.ParseToDateTime(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "pre_allocated_order_no", Value = pre_allocated_order_no.ParseToInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerId", Value = buyerId, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerName", Value = buyerName, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "statusText", Value = statusText, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "orderSn", Value = orderSn, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "afterSalesId", Value = afterSalesId, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "refundAmount", Value = refundAmount.ParseToNullableInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "orderAmount", Value = orderAmount.ParseToNullableInt(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int64, ParameterName = "orderDate", Value = orderDate.ParseToLong(), }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "afterSaleAddress", Value = afterSaleAddress, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_detail", Value = order_detail, }); - - count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXGetBuyerAfterSaleList(string inputData, bool isDetail = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); - var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); - if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) - { - 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 wxxd.order_pdd_buyer_after_sale o WHERE 1=1 "; - - string where = ""; - if (!string.IsNullOrWhiteSpace(wx_order_id_in)) - where += " and o.wx_order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; - if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) - where += " and o.order_sn in ('" + buyer_order_sn_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" + - " wxxd.order_pdd_buyer_after_sale 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 buyerAfterSaleLst = new List(); - foreach (DataRow row in dt.Rows) - { - order_pdd_buyer_after_sale afterSale = new order_pdd_buyer_after_sale - { - id = row["id"].ParseToLong(), - add_time = row["add_time"].ParseToString().ParseToDateTime(), - afterSalesId = row["afterSalesId"].ParseToString(), - buyerId = row["buyerId"].ParseToString(), - buyerName = row["buyerName"].ParseToString(), - mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), - orderAmount = row["orderAmount"].ParseToNullableInt(), - order_detail = row["order_detail"].ParseToString(), - orderSn = row["orderSn"].ParseToString(), - orderDate = row["orderDate"].ParseToNullableInt(), - refundAmount = row["refundAmount"].ParseToNullableInt(), - statusText = row["statusText"].ParseToString(), - afterSaleAddress = row["afterSaleAddress"].ParseToString(), - pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), - TransitCreateTime = row["TransitCreateTime"].ParseToString().ParseToDateTime(), - wx_order_id = row["wx_order_id"].ParseToString(), - wx_sku_id = row["wx_sku_id"].ParseToString(), - wx_send_type = row["wx_send_type"].ParseToInt(), - }; - buyerAfterSaleLst.Add(afterSale); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(buyerAfterSaleLst, 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\":\"输入为空\"}"; - } - - - public string WXGetTransitWarehouseAfterSaleList(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); - var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); - if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) - { - 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(1000); - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = "SELECT COUNT(id) FROM erp.oms_wei_external_procurement_after_sale o WHERE 1=1 "; - - string where = ""; - if (!string.IsNullOrWhiteSpace(wx_order_id_in)) - where += " and o.order_no in ('" + wx_order_id_in.Replace(",", "','") + "')"; - if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) - where += " and o.order_code in ('" + buyer_order_sn_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_external_procurement_after_sale 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 refundItemList = new List(); - foreach (DataRow row in dt.Rows) - { - oms_wei_external_procurement_after_sale_info order = new oms_wei_external_procurement_after_sale_info - { - id = row["id"].ParseToLong(), - order_no = row["order_no"].ParseToString(), - order_code = row["order_code"].ParseToString(), - inbound_time = row["inbound_time"].ParseToString().ParseToDateTimeNullable(), - outbound_time = row["outbound_time"].ParseToString().ParseToDateTimeNullable(), - account_user = row["account_user"].ParseToString(), - after_sale_no = row["after_sale_no"].ParseToString(), - created_time = row["created_time"].ParseToString().ParseToDateTimeNullable(), - create_user = row["create_user"].ParseToString(), - downstream_express_code = row["downstream_express_code"].ParseToString(), - downstream_waybill = row["downstream_waybill"].ParseToString(), - external_order_no = row["external_order_no"].ParseToString(), - raw_message = row["raw_message"].ParseToString(), - recipient_name = row["recipient_name"].ParseToString(), - recipient_phone = row["recipient_phone"].ParseToString(), - refund_city = row["refund_city"].ParseToString(), - refund_county = row["refund_county"].ParseToString(), - refund_detail_address = row["refund_detail_address"].ParseToString(), - refund_province = row["refund_province"].ParseToString(), - refund_waybill = row["refund_waybill"].ParseToString(), - return_express_company = row["return_express_company"].ParseToString(), - return_or_exchange = row["return_or_exchange"].ParseToNullableInt(), - status = row["status"].ParseToNullableInt(), - updated_time = row["updated_time"].ParseToString().ParseToDateTimeNullable(), - update_user = row["update_user"].ParseToString(), - warehouse_status = row["warehouse_status"].ParseToNullableInt(), - }; - refundItemList.Add(order); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(refundItemList, 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\":\"输入为空\"}"; - } - - /// - /// 订单异常重拍 - /// - /// - /// - public string WXUpdateAbnormalTransitOrder(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - var out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); - var order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_no"))?.Replace("'", "\\'"); - var order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_sku_id"))?.Replace("'", "\\'"); - var buyer_account = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyer_account"))?.Replace("'", "\\'"); - var out_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_amount"))?.Replace("'", "\\'"); - var purchaser_note = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "purchaser_note"))?.Replace("'", "\\'"); - var refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refund_status"))?.Replace("'", "\\'"); - var old_out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_out_order_no"))?.Replace("'", "\\'"); - var old_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_order_no"))?.Replace("'", "\\'"); - var old_order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_order_sku_id"))?.Replace("'", "\\'"); - var old_buyer_account = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_buyer_account"))?.Replace("'", "\\'"); - var old_out_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_out_amount"))?.Replace("'", "\\'"); - var old_purchaser_note = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_purchaser_note"))?.Replace("'", "\\'"); - var old_refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_refund_status"))?.Replace("'", "\\'"); - var order_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_code"))?.Replace("'", "\\'"); - if(order_code.IsNullOrEmpty() || old_purchaser_note.IsNullOrEmpty() || old_out_amount.ParseToInt().IsNullOrZero() || old_buyer_account.IsNullOrEmpty() || old_order_no.IsNullOrEmpty() || old_out_order_no.IsNullOrEmpty() || - purchaser_note.IsNullOrEmpty() || out_amount.ParseToInt().IsNullOrZero() || buyer_account.IsNullOrEmpty() || order_no.IsNullOrEmpty() || out_order_no.IsNullOrEmpty()) - { - return "{\"code\":500,\"msg\":\"异常单记录信息不完整\",\"affected_rows\":" + 0 + "}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn, true); - - string sql; - - sql = "INSERT INTO wxxd.order_abnormal_transit_order_rebuy_record (out_order_no,order_no,order_sku_id,buyer_account,out_amount,purchaser_note,refund_status,order_code) "; - sql += " VALUES('" + old_out_order_no + "','" + old_order_no + "','" + old_order_sku_id + "','" + old_buyer_account + "'," + old_out_amount + ",'" + - old_purchaser_note + "','" + old_refund_status + "','" + order_code + "')"; - var rows = mySql.ExecuteAffectedRows(sql); - if (!mySql.Message.IsNullOrEmpty()) - { - mySql.RollBack(); - mySql.Close(); - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + rows + "}"; - } - if (rows == 0) - { - mySql.RollBack(); - mySql.Close(); - return "{\"code\":500,\"msg\":\"创建异常单重拍记录失败\",\"affected_rows\":" + rows + "}"; - } - - sql = "UPDATE erp.oms_wei_external_procurement_log SET "; - sql += " out_order_no='" + out_order_no + "',"; - sql += " order_no='" + order_no + "',"; - sql += " order_sku_id='" + order_sku_id + "',"; - sql += " buyer_account='" + buyer_account + "',"; - sql += " out_amount=" + out_amount + ","; - sql += " purchaser_note='" + purchaser_note + "',"; - sql += " refund_status='" + refund_status + "',"; - sql = sql.TrimEnd(','); - sql += " WHERE order_code='" + order_code + "' AND order_no='" + old_order_no + "';"; - rows = mySql.ExecuteAffectedRows(sql); - if (!mySql.Message.IsNullOrEmpty()) - { - mySql.RollBack(); - mySql.Close(); - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + rows + "}"; - } - if (rows == 0) - { - mySql.RollBack(); - mySql.Close(); - return "{\"code\":500,\"msg\":\"更新异常单拍单失败\",\"affected_rows\":" + rows + "}"; - } - mySql.Commit(); - mySql.Close(); - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rows + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - - public string WXAddOrderItemExtInfo(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); - string sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); - string out_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_id"))?.Replace("'", "\\'"); - string shop_app_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_app_id"))?.Replace("'", "\\'"); - string shop_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_name"))?.Replace("'", "\\'"); - string buy_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buy_type"))?.Replace("'", "\\'"); - string abnormal_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "abnormal_text"))?.Replace("'", "\\'"); - string flag = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "flag"))?.Replace("'", "\\'"); - string label = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "label"))?.Replace("'", "\\'"); - string remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "remark"))?.Replace("'", "\\'"); - string after_sale_user_delivery_address = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sale_user_delivery_address"))?.Replace("'", "\\'"); - - if (string.IsNullOrEmpty(order_id) || string.IsNullOrEmpty(sku_id)) - return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = "select id from wxxd.order_item_ext where order_id='" + order_id + "' and sku_id='" + sku_id + "'"; - var id = mySql.ExecuteFirstInt(sql); - if (!string.IsNullOrEmpty(mySql.Message)) - { - mySql.Close(); - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - if (id > 0) - { - mySql.Close(); - return "{\"code\":500,\"msg\":\"订单已存在\"}"; - } - - sql = "INSERT INTO wxxd.order_item_ext (order_id,sku_id,out_order_id,shop_app_id,shop_name,buy_type,abnormal_text,flag,label,remark,after_sale_user_delivery_address)"; - sql += "VALUES(@order_id,@sku_id,@out_order_id,@shop_app_id,@shop_name,@buy_type,@abnormal_text,@flag,@label,@remark,@after_sale_user_delivery_address);"; - - List paramLst = new List(); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_id", Value = order_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_id", Value = sku_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "out_order_id", Value = out_order_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_app_id", Value = shop_app_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_name", Value = shop_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buy_type", Value = buy_type, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "abnormal_text", Value = abnormal_text, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "flag", Value = flag, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "label", Value = label, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "remark", Value = remark, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "after_sale_user_delivery_address", Value = after_sale_user_delivery_address, }); - - count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXMdyOrderItemExtInfo(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); - string sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); - string out_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_id"))?.Replace("'", "\\'"); - string shop_app_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_app_id"))?.Replace("'", "\\'"); - string shop_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_name"))?.Replace("'", "\\'"); - string buy_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buy_type"))?.Replace("'", "\\'"); - string abnormal_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "abnormal_text"))?.Replace("'", "\\'"); - string flag = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "flag"))?.Replace("'", "\\'"); - string label = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "label"))?.Replace("'", "\\'"); - string remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "remark"))?.Replace("'", "\\'"); - string after_sale_user_delivery_address = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sale_user_delivery_address"))?.Replace("'", "\\'"); - - if (string.IsNullOrEmpty(order_id)) - return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = "UPDATE wxxd.order_item_ext SET "; - if (!string.IsNullOrEmpty(shop_app_id)) - sql += " shop_app_id=@shop_app_id,"; - if (!string.IsNullOrEmpty(out_order_id)) - sql += " out_order_id=@out_order_id,"; - if (!string.IsNullOrEmpty(shop_name)) - sql += " shop_name=@shop_name,"; - if (buy_type != null) - sql += " buy_type=@buy_type,"; - if (abnormal_text != null) - sql += " abnormal_text=@abnormal_text,"; - if (!string.IsNullOrEmpty(flag)) - sql += " flag=@flag,"; - if (label != null) - sql += " label=@label,"; - if (remark != null) - sql += " remark=@remark,"; - if (!string.IsNullOrEmpty(after_sale_user_delivery_address)) - sql += " after_sale_user_delivery_address=@after_sale_user_delivery_address,"; - sql = sql.TrimEnd(','); - sql += " where 1=1"; - if (!string.IsNullOrEmpty(order_id)) - sql += " and order_id=@order_id"; - if (!string.IsNullOrEmpty(sku_id)) - sql += " and sku_id=@sku_id"; - - List paramLst = new List(); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_id", Value = order_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_id", Value = sku_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "out_order_id", Value = out_order_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_app_id", Value = shop_app_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_name", Value = shop_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buy_type", Value = buy_type, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "abnormal_text", Value = abnormal_text, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "flag", Value = flag, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "label", Value = label, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "remark", Value = remark, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "after_sale_user_delivery_address", Value = after_sale_user_delivery_address, }); - - var count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXGetOrderItemExtInfoList(string inputData, bool isDetail = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - - var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); - var wx_sku_id = RegexUtils.GetStringQuery(ref inputData, "wx_sku_id_in")?.Replace("'", "\\'"); - var out_order_id_in = RegexUtils.GetStringQuery(ref inputData, "out_order_id_in")?.Replace("'", "\\'"); - if (wx_order_id_in.IsNullOrEmpty() && out_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 wxxd.order_item_ext o WHERE 1=1 "; - - string where = ""; - if (!string.IsNullOrWhiteSpace(wx_order_id_in)) - where += " and o.order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; - if (!string.IsNullOrWhiteSpace(wx_sku_id)) - where += " and o.sku_id in ('" + wx_sku_id.Replace(",", "','") + "')"; - if (!string.IsNullOrWhiteSpace(out_order_id_in)) - where += " and o.out_order_id in ('" + out_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" + - " wxxd.order_item_ext 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 buyerOrderList = new List(); - foreach (DataRow row in dt.Rows) - { - order_item_ext order = new order_item_ext - { - id = row["id"].ParseToLong(), - add_time = row["add_time"].ParseToString().ParseToDateTime(), - buy_type = row["buy_type"].ParseToString(), - abnormal_text = row["abnormal_text"].ParseToString(), - after_sale_user_delivery_address = row["after_sale_user_delivery_address"].ParseToString(), - flag = row["flag"].ParseToNullableInt(), - mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), - label = row["label"].ParseToString(), - order_id = row["order_id"].ParseToString(), - remark = row["remark"].ParseToString(), - shop_app_id = row["shop_app_id"].ParseToString(), - shop_name = row["shop_name"].ParseToString(), - sku_id = row["sku_id"].ParseToString(), - out_order_id = row["out_order_id"].ParseToString(), - }; - buyerOrderList.Add(order); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(buyerOrderList, 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\":\"输入为空\"}"; - } - } + public class WXOrderManage + { + public string WXGetErpOrderList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var erp_shop_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_shop_id_in")?.Replace("'", "\\'"); + var erp_order_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_order_id_in")?.Replace("'", "\\'"); + if (erp_shop_id_in.IsNullOrEmpty() && erp_order_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(erp_order_id_in)) + where += " and o.order_id in ('" + erp_order_id_in.Replace(",", "','") + "')"; + 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.update_time >= " + start_time; + if (end_time > 0) + where += " and o.update_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 + { + //tinyint(1)中存超过两个值,只返回true或false,无法直接取值解决办法 + //解决方法: + //1.强制修改mapResult中的映射,将po属性的类型由Boolean改为Byte + //2.查询 tinyint(1) 的sql 字段时,转为(status + 0) as status + //3.避免使用 tinyint(1) 作为字段的数据类型 + + sql = "SELECT o.*,(out_shipped+0) as out_shipped_int 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 orderList = new List(); + foreach (DataRow row in dt.Rows) + { + oms_wei_order order = new oms_wei_order + { + id = row["id"].ParseToLong(), + aftersale_detail = row["aftersale_detail"].ParseToNullableString(), + audit_status = row["audit_status"].ParseToNullableInt(), + audit_time = row["audit_time"].ParseToNullableString().ParseToDateTime(), + city_name = row["city_name"].ParseToNullableString(), + colour_flag = row["colour_flag"].ParseToNullableInt(), + colour_flag_update_time = row["colour_flag_update_time"].ParseToNullableString().ParseToDateTime(), + commission_amount = row["commission_amount"].ParseToNullableInt(), + county_name = row["county_name"].ParseToNullableString(), + create_time = row["create_time"].ParseToInt(), + delivery_deadline = row["delivery_deadline"].ParseToNullableInt(), + delivery_product_info = row["delivery_product_info"].ParseToNullableString(), + delivery_time = row["delivery_time"].ParseToNullableInt(), + detail_info = row["detail_info"].ParseToNullableString(), + discounted_price = row["discounted_price"].ParseToNullableInt(), + erp_send_code = row["erp_send_code"].ParseToNullableString(), + erp_send_company = row["erp_send_company"].ParseToNullableString(), + erp_send_status = row["erp_send_status"].ParseToNullableInt(), + erp_send_time = row["erp_send_time"].ParseToNullableString().ParseToDateTime(), + ewaybill_order_code = row["ewaybill_order_code"].ParseToNullableString(), + external_gift = row["external_gift"].ParseToNullableInt(), + ext_info = row["ext_info"].ParseToNullableString(), + 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"].ParseToNullableString(), + has_freight_insurance = row["has_freight_insurance"].ParseToNullableInt(), + house_number = row["house_number"].ParseToNullableString(), + 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"].ParseToNullableString(), + order_id = row["order_id"].ParseToNullableString(), + order_price = row["order_price"].ParseToNullableInt(), + out_account = row["out_account"].ParseToNullableString(), + out_after_sale_status = row["out_after_sale_status"].ParseToNullableString(), + out_amount = row["out_amount"].ParseToNullableInt(), + out_express_company = row["out_express_company"].ParseToNullableString(), + out_express_no = row["out_express_no"].ParseToNullableString(), + out_order_no = row["out_order_no"].ParseToNullableString(), + out_shipped = row["out_shipped_int"].ParseToNullableInt(), + pay_info = row["pay_info"].ParseToNullableString(), + postal_code = row["postal_code"].ParseToNullableString(), + predict_commission_fee = row["predict_commission_fee"].ParseToNullableInt(), + product_price = row["product_price"].ParseToNullableInt(), + profit = row["profit"].ParseToNullableInt(), + province_name = row["province_name"].ParseToNullableString(), + purchase_price = row["purchase_price"].ParseToNullableInt(), + purchase_status = row["purchase_status"].ParseToNullableInt(), + purchase_time = row["purchase_time"].ParseToNullableInt(), + settle_info = row["settle_info"].ParseToNullableString(), + ship_done_time = row["ship_done_time"].ParseToNullableInt(), + shop_id = row["shop_id"].ParseToLong(), + shop_name = row["shop_name"].ParseToNullableString(), + shop_remark = row["shop_remark"].ParseToNullableString(), + soft_remark = row["soft_remark"].ParseToNullableString(), + status = row["status"].ParseToNullableInt(), + supplier_remark_exception = row["supplier_remark_exception"].ParseToNullableString(), + tel_number = row["tel_number"].ParseToNullableString(), + tel_number_ext_info = row["tel_number_ext_info"].ParseToNullableString(), + transfer_warehouse_status = row["transfer_warehouse_status"].ParseToNullableInt(), + unionid = row["unionid"].ParseToNullableString(), + update_time = row["update_time"].ParseToInt(), + user_name = row["user_name"].ParseToNullableString(), + use_tel_number = row["use_tel_number"].ParseToNullableInt(), + virtual_order_tel_number = row["virtual_order_tel_number"].ParseToNullableString(), + }; + if (order.order_id == "3737914129536416512") + { + + } + orderList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(orderList, 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\":\"输入为空\"}"; + } + + + 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 orderItemList = new List(); + 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"].ParseToNullableString(), + 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"].ParseToNullableString(), + finish_aftersale_sku_cnt = row["finish_aftersale_sku_cnt"].ParseToNullableInt(), + is_change_price = row["is_change_price"].ParseToNullableString(), + is_discounted = row["is_discounted"].ParseToNullableString(), + 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"].ParseToNullableString(), + out_product_id = row["out_product_id"].ParseToNullableString(), + out_sku_id = row["out_sku_id"].ParseToNullableString(), + out_warehouse_id = row["out_warehouse_id"].ParseToNullableString(), + product_id = row["product_id"].ParseToNullableString(), + real_price = row["real_price"].ParseToNullableInt(), + refund_status = row["refund_status"].ParseToNullableInt(), + return_address = row["return_address"].ParseToNullableString(), + sale_price = row["sale_price"].ParseToNullableInt(), + sku_attrs = row["sku_attrs"].ParseToNullableString(), + sku_cnt = row["sku_cnt"].ParseToNullableInt(), + sku_code = row["sku_code"].ParseToNullableString(), + sku_deliver_info = row["sku_deliver_info"].ParseToNullableString(), + sku_id = row["sku_id"].ParseToNullableString(), + thumb_img = row["thumb_img"].ParseToNullableString(), + title = row["title"].ParseToNullableString(), + use_deduction = row["use_deduction"].ParseToNullableString(), + }; + 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\":\"输入为空\"}"; + } + + + public string WXGetErpRefundList(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_refund 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_refund 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 refundItemList = new List(); + foreach (DataRow row in dt.Rows) + { + oms_wei_refund order = new oms_wei_refund + { + id = row["id"].ParseToLong(), + merchant_id = row["merchant_id"].ParseToLong(), + order_id = row["order_id"].ParseToNullableString(), + shop_id = row["shop_id"].ParseToLong(), + erp_goods_id = row["erp_goods_id"].ParseToNullableLong(), + erp_goods_sku_id = row["erp_goods_sku_id"].ParseToNullableLong(), + product_id = row["product_id"].ParseToNullableString(), + sku_id = row["sku_id"].ParseToNullableString(), + after_sale_order_id = row["after_sale_order_id"].ParseToNullableString(), + complaint_id = row["complaint_id"].ParseToNullableString(), + count = row["count"].ParseToNullableInt(), + create_time = row["create_time"].ParseToNullableInt(), + details = row["details"].ParseToNullableString(), + fast_refund = row["fast_refund"].ParseToNullableString(), + merchant_upload_info = row["merchant_upload_info"].ParseToNullableString(), + openid = row["openid"].ParseToNullableString(), + pull_status = row["pull_status"].ParseToNullableInt(), + pull_time = row["pull_time"].ParseToNullableString().ParseToDateTime(), + reason = row["reason"].ParseToNullableString(), + reason_text = row["reason_text"].ParseToNullableString(), + refund_amount = row["refund_amount"].ParseToNullableInt(), + refund_reason = row["refund_reason"].ParseToNullableInt(), + refund_resp = row["refund_resp"].ParseToNullableString(), + return_delivery_id = row["return_delivery_id"].ParseToNullableString(), + return_delivery_name = row["return_delivery_name"].ParseToNullableString(), + return_waybill_id = row["return_waybill_id"].ParseToNullableString(), + status = row["status"].ParseToNullableString(), + type = row["type"].ParseToNullableString(), + unionid = row["unionid"].ParseToNullableString(), + update_time = row["update_time"].ParseToNullableInt(), + warehouse_status = row["warehouse_status"].ParseToNullableInt(), + return_city = row["return_city"].ParseToNullableString(), + return_county = row["return_county"].ParseToNullableString(), + return_detail = row["return_detail"].ParseToNullableString(), + return_province = row["return_province"].ParseToNullableString(), + return_tel = row["return_tel"].ParseToNullableString(), + return_user_name = row["return_user_name"].ParseToNullableString(), + }; + refundItemList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(refundItemList, 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\":\"输入为空\"}"; + } + + + + + /// + /// 微信添加修改采购映射商品(含sku映射和) + /// + /// + /// + public string WXAddMdyBuyProdMap(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + // 软件用户名 + string spu_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_code"))?.Replace("'", "\\'"); + string sku_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_code"))?.Replace("'", "\\'"); + string user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_user_name"))?.Replace("'", "\\'"); + string map_url = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_url"))?.Replace("'", "\\'"); + string map_goods_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_goods_name"))?.Replace("'", "\\'"); + string map_spec_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_spec_name"))?.Replace("'", "\\'"); + string map_goods_id = RegexUtils.GetStringQuery(ref inputData, "map_goods_id")?.Replace("'", "\\'"); + string map_sku_id = RegexUtils.GetStringQuery(ref inputData, "map_sku_id")?.Replace("'", "\\'"); + string map_send_address = RegexUtils.GetStringQuery(ref inputData, "map_send_address")?.Replace("'", "\\'"); + string transit_warehouse_id = RegexUtils.GetStringQuery(ref inputData, "transit_warehouse_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(spu_code) || string.IsNullOrEmpty(sku_code)) + return "{\"code\":500,\"msg\":\"缺少系统商品或SKU编号\"}"; + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":500,\"msg\":\"缺少用户名\"}"; + if (string.IsNullOrEmpty(map_url) && (string.IsNullOrEmpty(map_goods_id) || string.IsNullOrEmpty(map_sku_id))) + return "{\"code\":500,\"msg\":\"缺少采购商品信息\"}"; + if (string.IsNullOrEmpty(transit_warehouse_id)) + return "{\"code\":500,\"msg\":\"缺少中转仓信息\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT 1 FROM `bxx`.`product_buy_map` where user_name='" + user_name + "' AND spu_code='" + spu_code + "' AND sku_code='" + sku_code + "'"; + string where = ""; + sql += where; + var exist = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (exist == 0) + { + sql = " INSERT INTO `bxx`.`product_buy_map` (user_name,spu_code,sku_code,map_url,map_goods_name,map_spec_name,map_goods_id,map_sku_id,map_send_address,transit_warehouse_id)" + + " VALUES (@user_name,@spu_code,@sku_code,@map_url,@map_goods_name,@map_spec_name,@map_goods_id,@map_sku_id,@map_send_address,@transit_warehouse_id);"; + } + else + { + sql = "UPDATE `bxx`.`product_buy_map` SET "; + if (map_url != null) + sql += " map_url=@map_url,"; + if (map_goods_name != null) + sql += " map_goods_name=@map_goods_name,"; + if (map_spec_name != null) + sql += " map_spec_name=@map_spec_name,"; + if (map_goods_id != null) + sql += " map_goods_id=@map_goods_id,"; + if (map_sku_id != null) + sql += " map_sku_id=@map_sku_id,"; + if (map_send_address != null) + sql += " map_send_address=@map_send_address,"; + if (transit_warehouse_id != null) + sql += " transit_warehouse_id=@transit_warehouse_id,"; + sql = sql.TrimEnd(','); + sql += " WHERE user_name=@user_name and spu_code=@spu_code and sku_code=@sku_code;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "spu_code", Value = spu_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_code", Value = sku_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_url", Value = map_url, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_goods_name", Value = map_goods_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_spec_name", Value = map_spec_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_goods_id", Value = map_goods_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_sku_id", Value = map_sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_send_address", Value = map_send_address, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "transit_warehouse_id", Value = transit_warehouse_id, }); + mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 微信获取采购映射商品 + /// + /// + /// + public string WXGetBuyPordMap(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string spu_codes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_codes"))?.Replace("'", "\\'"); + string sku_codes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_codes"))?.Replace("'", "\\'"); + string user_name = RegexUtils.GetStringQuery(ref inputData, "main_user_name")?.Replace("'", "\\'"); + string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(spu_codes)) + return "{\"code\":500,\"msg\":\"商品编码不能为空\"}"; + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":500,\"msg\":\"用户名不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "SELECT COUNT(*) FROM `bxx`.`product_buy_map` WHERE 1=1"; + string where = ""; + if (spu_codes != null) + where += " and spu_code IN ('" + spu_codes.Replace(",", "','") + "')"; + if (sku_codes != null) + where += " and sku_code IN ('" + sku_codes.Replace(",", "','") + "')"; + if (user_name != null) + where += " and user_name='" + user_name + "'"; + sql += where; + sql += ";"; + + if (not_count == "false") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `bxx`.`product_buy_map` WHERE 1=1"; + sql += where; + sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; + dt = mySql.ExecuteDataTable(sql); + } + mySql.Close(); + + if (dt != null) + { + try + { + List WXBuyMapInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WXBuyMapInfoLst.Add(new WXBuyMapInfo() + { + id = row["id"].ParseToInt(), + user_name = row["user_name"].ParseToNullableString(), + spu_code = row["spu_code"].ParseToNullableString(), + sku_code = row["sku_code"].ParseToNullableString(), + map_url = row["map_url"].ParseToNullableString(), + map_goods_name = row["map_goods_name"].ParseToNullableString(), + map_spec_name = row["map_spec_name"].ParseToNullableString(), + map_goods_id = row["map_goods_id"].ParseToNullableString(), + map_sku_id = row["map_sku_id"].ParseToNullableString(), + map_send_address = row["map_send_address"].ParseToNullableString(), + transit_warehouse_id = row["transit_warehouse_id"].ParseToNullableString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(WXBuyMapInfoLst, 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\":\"输入为空\"}"; + } + + /// + /// 获取中转仓订单信息 + /// + /// + /// + public string WXGetTransitOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + var count = -1; + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_no"))?.Replace("'", "\\'"); + string order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_sku_id"))?.Replace("'", "\\'"); + string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); + string transfer_warehouse_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "transfer_warehouse_status"))?.Replace("'", "\\'"); + string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); + string is_admin = RegexUtils.GetStringQuery(ref inputData, "is_admin")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_no) && string.IsNullOrEmpty(out_order_no) && string.IsNullOrEmpty(order_sku_id) && is_admin != "true") + return "{\"code\":500,\"msg\":\"中转订单查询信息不能为空\"}"; + + try + { + var oms_wei_external_procurement_log_list = GetTransitOrderTable(page, page_size, order_no, order_sku_id, out_order_no, pre_allocated_order_no, transfer_warehouse_status, not_count, out count); + if (oms_wei_external_procurement_log_list != null) + { + + + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(oms_wei_external_procurement_log_list, 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 + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + /// + /// 查询中转仓订单 + /// + public List GetTransitOrderTable( + int page, + int pageSize, + string orderNo, + string orderSkuId, + string outOrderNo, + string preAllocatedOrderNo, + string transferWarehouseStatus, + string not_count, out int count) + { + var timeCalc = DateTime.Now; + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + + string sql = ""; + count = -1; + + sql = "SELECT COUNT(*) FROM `erp`.`oms_wei_external_procurement_log` WHERE 1=1"; + string where = ""; + if (!string.IsNullOrEmpty(orderNo)) + where += $" and order_no IN ('{orderNo.Replace(",", "','")}')"; + + if (!string.IsNullOrEmpty(orderSkuId)) + where += $" and order_sku_id IN ('{orderSkuId.Replace(",", "','")}')"; + + if (!string.IsNullOrEmpty(outOrderNo)) + where += $" and out_order_no IN ('{outOrderNo.Replace(",", "','")}')"; + + if (!string.IsNullOrEmpty(preAllocatedOrderNo)) + where += $" and pre_allocated_order_no IN ({preAllocatedOrderNo})"; + + if (!string.IsNullOrEmpty(transferWarehouseStatus)) + where += $" and transfer_warehouse_status IN ({transferWarehouseStatus})"; + sql += where; + sql += ";"; + + if (not_count == "false") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `erp`.`oms_wei_external_procurement_log` WHERE 1=1"; + sql += where; + sql += " order by id desc limit " + Math.Max(0, page - 1) * pageSize + "," + pageSize + ";"; + dt = mySql.ExecuteDataTable(sql); + } + mySql.Close(); + + if (dt != null) + { + List oms_wei_external_procurement_log_list = new List(); + + foreach (DataRow row in dt.Rows) + { + oms_wei_external_procurement_log_list.Add(new oms_wei_external_procurement_log() + { + id = row["id"].ParseToInt(), + buyer_account = row["buyer_account"].ParseToNullableString(), + order_no = row["order_no"].ParseToNullableString(), + order_sku_id = row["order_sku_id"].ParseToNullableString(), + out_amount = row["out_amount"].ParseToNullableInt(), + out_order_no = row["out_order_no"].ParseToNullableString(), + purchaser_note = row["purchaser_note"].ParseToNullableString(), + created_time = row["created_time"].ParseToNullableString().ParseToDateTime(), + express_1_company = row["express_1_company"].ParseToNullableString(), + express_1_waybill = row["express_1_waybill"].ParseToNullableString(), + express_2_company = row["express_2_company"].ParseToNullableString(), + express_2_waybill = row["express_2_waybill"].ParseToNullableString(), + order_code = row["order_code"].ParseToNullableString(), + order_platform_code = row["order_platform_code"].ParseToNullableString(), + pickup_time = row["pickup_time"].ParseToNullableString().ParseToDateTime(), + platform = row["platform"].ParseToNullableString(), + pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), + raw_message = row["raw_message"].ParseToNullableString(), + refund_status = row["refund_status"].ParseToNullableString(), + transfer_warehouse_status = row["transfer_warehouse_status"].ParseToNullableInt(), + updated_time = row["updated_time"].ParseToNullableString().ParseToDateTime(), + is_transfer_ship = row["is_transfer_ship"].ParseToNullableInt(), + random_code = row["random_code"].ParseToNullableString(), + transfer_refund_status = row["transfer_refund_status"].ParseToNullableInt(), + order_void_status = row["order_void_status"].ParseToNullableInt(), + warehouse_status = row["warehouse_status"].ParseToNullableInt(), + inbound_time = row["inbound_time"].ParseToNullableString().ParseToDateTimeNullable(), + outbound_time = row["outbound_time"].ParseToNullableString().ParseToDateTimeNullable(), + }); + } + return oms_wei_external_procurement_log_list; + + } + else + { + throw new Exception(mySql.Message); + } + return null; + } + + + /// + /// 修改中转仓订单信息(真实物流),临时补救 + /// + /// + /// + public string WXUpdateErpOrderExpress(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + string express_1_company = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "express_1_company"))?.Replace("'", "\\'"); + string express_1_waybill = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "express_1_waybil"))?.Replace("'", "\\'"); + string refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refund_status"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(out_order_no)) + return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; + //if (string.IsNullOrEmpty(express_1_company)) + // return "{\"code\":500,\"msg\":\"物流公司不能为空\"}"; + //if (string.IsNullOrEmpty(express_1_waybill)) + // return "{\"code\":500,\"msg\":\"物流单号不能为空\"}"; + + if (string.IsNullOrEmpty(express_1_company) && string.IsNullOrEmpty(express_1_waybill) && string.IsNullOrEmpty(refund_status)) + return "{\"code\":500,\"msg\":\"修改信息不能为空\"}"; + + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update `erp`.`oms_wei_external_procurement_log` set "; + if (!string.IsNullOrEmpty(express_1_company)) + sql += " express_1_company='" + express_1_company + "',"; + if (!string.IsNullOrEmpty(express_1_waybill)) + sql += " express_1_waybill='" + express_1_waybill + "',"; + if (!string.IsNullOrEmpty(refund_status)) + sql += " refund_status='" + refund_status + "',"; + sql = sql.TrimEnd(','); + sql += " where out_order_no = '" + out_order_no + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 修改中转仓订单信息(取号状态),临时补救 + /// + /// + /// + public string WXUpdateErpAllocatedOrderNo(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(out_order_no)) + return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update `erp`.`oms_wei_external_procurement_log` set "; + if (!string.IsNullOrEmpty(pre_allocated_order_no)) + sql += " pre_allocated_order_no=" + pre_allocated_order_no + ","; + sql = sql.TrimEnd(','); + sql += " where out_order_no = '" + out_order_no + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 删除中转仓订单 临时补救,慎用 + /// + /// + /// + public string WXDelErpTransitWarehouseOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(out_order_no)) + return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " DELETE FROM `erp`.`oms_wei_external_procurement_log` WHERE out_order_no in ('" + out_order_no.Replace(",", "','") + "')"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + if (count == 0) + { + return "{\"code\":500,\"msg\":\"删除失败,订单不存在\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 修改订单软件备注 + /// + /// + /// + public string WXUpdateErpSoftRemark(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + string soft_remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "soft_remark"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update erp.oms_wei_order set "; + if (soft_remark != null) + sql += " soft_remark='" + soft_remark + "',"; + sql = sql.TrimEnd(','); + sql += " where order_id = '" + order_id + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXUpdateErpOutAfterSaleStatus(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + string out_after_sale_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_after_sale_status"))?.Replace("'", "\\'"); + if (out_after_sale_status == null) + return "{\"code\":500,\"msg\":\"售后状态不能为NULL\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update erp.oms_wei_order set "; + if (out_after_sale_status != null) + { + if (out_after_sale_status == "" || out_after_sale_status == "NULL") + sql += " out_after_sale_status=NULL,"; + else + sql += " out_after_sale_status='" + out_after_sale_status + "',"; + } + sql = sql.TrimEnd(','); + sql += " where order_id = '" + order_id + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXAddMdyBuyerOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string wx_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); + string wx_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); + string wx_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_send_type"))?.Replace("'", "\\'"); + if (wx_send_type.IsNullOrEmpty()) + wx_send_type = "0"; + string TransitCreateTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "TransitCreateTime"))?.Replace("'", "\\'"); + string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); + string buyerId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerId"))?.Replace("'", "\\'"); + string buyerName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerName"))?.Replace("'", "\\'"); + string pdd_order_sn = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pdd_order_sn"))?.Replace("'", "\\'"); + string order_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_amount"))?.Replace("'", "\\'"); + string order_time = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_time"))?.Replace("'", "\\'"); + string outExpressCompanyCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "outExpressCompanyCode"))?.Replace("'", "\\'"); + string tracking_number = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "tracking_number"))?.Replace("'", "\\'"); + string order_status_prompt = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_status_prompt"))?.Replace("'", "\\'"); + string after_sales_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sales_status"))?.Replace("'", "\\'"); + string order_detail = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_detail"))?.Replace("'", "\\'"); + string wx_order_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_send_type"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(wx_order_send_type)) + wx_order_send_type = "1"; + if (string.IsNullOrEmpty(wx_order_id) || string.IsNullOrEmpty(pdd_order_sn)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "select id from wxxd.order_pdd_buyer_order where order_sn='" + pdd_order_sn + "'"; + var id = mySql.ExecuteFirstInt(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + //sql = "INSERT INTO wxxd.order_pdd_buyer_order (wx_order_id,wx_sku_id,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,order_sn,order_amount,order_time," + + // "outExpressCompanyCode,tracking_number,order_status_prompt,after_sales_status,order_detail)"; + //sql += "VALUES(@wx_order_id,@wx_sku_id,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@pdd_order_sn,@order_amount,@order_time," + + // "@outExpressCompanyCode,@tracking_number,@order_status_prompt,@after_sales_status,@order_detail)"; + //sql += " ON DUPLICATE KEY UPDATE wx_order_id=VALUES(@wx_order_id),wx_sku_id=VALUES(@wx_sku_id),TransitCreateTime=VALUES(@TransitCreateTime)," + + // "pre_allocated_order_no=VALUES(@pre_allocated_order_no),buyerId=VALUES(@buyerId),buyerName=VALUES(@buyerName),order_amount=VALUES(@order_amount)," + + // "order_time=VALUES(@order_time),outExpressCompanyCode=VALUES(@outExpressCompanyCode),tracking_number=VALUES(@tracking_number),order_status_prompt=VALUES(@order_status_prompt)," + + // "after_sales_status=VALUES(@after_sales_status),order_detail=VALUES(@order_detail)"; + + if (id == 0) + { + sql = "INSERT INTO wxxd.order_pdd_buyer_order (wx_order_id,wx_sku_id,wx_send_type,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,order_sn,order_amount,order_time," + + "outExpressCompanyCode,tracking_number,order_status_prompt,after_sales_status,order_detail,wx_order_send_type)"; + sql += "VALUES(@wx_order_id,@wx_sku_id,@wx_send_type,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@pdd_order_sn,@order_amount,@order_time," + + "@outExpressCompanyCode,@tracking_number,@order_status_prompt,@after_sales_status,@order_detail@wx_order_send_type);"; + } + else + { + sql = "UPDATE wxxd.order_pdd_buyer_order SET "; + if (!string.IsNullOrEmpty(wx_order_id)) + sql += " wx_order_id=@wx_order_id,"; + if (!string.IsNullOrEmpty(wx_sku_id)) + sql += " wx_sku_id=@wx_sku_id,"; + if (!string.IsNullOrEmpty(wx_send_type)) + sql += " wx_send_type=@wx_send_type,"; + if (!string.IsNullOrEmpty(TransitCreateTime)) + sql += " TransitCreateTime=@TransitCreateTime,"; + if (!string.IsNullOrEmpty(pre_allocated_order_no)) + sql += " pre_allocated_order_no=@pre_allocated_order_no,"; + if (!string.IsNullOrEmpty(buyerId)) + sql += " buyerId=@buyerId,"; + if (!string.IsNullOrEmpty(buyerName)) + sql += " buyerName=@buyerName,"; + if (!string.IsNullOrEmpty(order_amount)) + sql += " order_amount=@order_amount,"; + if (!string.IsNullOrEmpty(order_time)) + sql += " order_time=@order_time,"; + if (!string.IsNullOrEmpty(outExpressCompanyCode)) + sql += " outExpressCompanyCode=@outExpressCompanyCode,"; + if (!string.IsNullOrEmpty(tracking_number)) + sql += " tracking_number=@tracking_number,"; + if (!string.IsNullOrEmpty(order_status_prompt)) + sql += " order_status_prompt=@order_status_prompt,"; + if (!string.IsNullOrEmpty(after_sales_status)) + sql += " after_sales_status=@after_sales_status,"; + if (!string.IsNullOrEmpty(order_detail)) + sql += " order_detail=@order_detail,"; + if (!string.IsNullOrEmpty(wx_order_send_type)) + sql += " wx_order_send_type=@wx_order_send_type,"; + sql = sql.TrimEnd(','); + sql += " where order_sn=@pdd_order_sn"; + } + //260705-105706954352823 + + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_order_id", Value = wx_order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_sku_id", Value = wx_sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "wx_send_type", Value = wx_send_type.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "TransitCreateTime", Value = TransitCreateTime.ParseToDateTime(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "pre_allocated_order_no", Value = pre_allocated_order_no.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerId", Value = buyerId, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerName", Value = buyerName, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "pdd_order_sn", Value = pdd_order_sn, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "order_amount", Value = order_amount.ParseToNullableInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int64, ParameterName = "order_time", Value = order_time.ParseToLong(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "outExpressCompanyCode", Value = outExpressCompanyCode, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "tracking_number", Value = tracking_number, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_status_prompt", Value = order_status_prompt, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "after_sales_status", Value = after_sales_status.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "wx_order_send_type", Value = wx_order_send_type.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_detail", Value = order_detail, }); + //sql = " update `wxxd`.`order_pdd_buyer_order` set "; + //if (!string.IsNullOrEmpty(soft_remark)) + // sql += " soft_remark=" + soft_remark + ","; + //sql = sql.TrimEnd(','); + //sql += " where order_id = '" + wx_order_id + "';"; + + count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetBuyerOrderList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); + var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); + if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) + { + 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 wxxd.order_pdd_buyer_order o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(wx_order_id_in)) + where += " and o.wx_order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) + where += " and o.order_sn in ('" + buyer_order_sn_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" + + " wxxd.order_pdd_buyer_order 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 buyerOrderList = new List(); + foreach (DataRow row in dt.Rows) + { + order_pdd_buyer_order order = new order_pdd_buyer_order + { + id = row["id"].ParseToLong(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + after_sales_status = row["after_sales_status"].ParseToNullableInt(), + buyerId = row["buyerId"].ParseToString(), + buyerName = row["buyerName"].ParseToString(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + order_amount = row["order_amount"].ParseToNullableInt(), + order_detail = row["order_detail"].ParseToString(), + order_sn = row["order_sn"].ParseToString(), + order_status_prompt = row["order_status_prompt"].ParseToString(), + order_time = row["order_time"].ParseToNullableLong(), + outExpressCompanyCode = row["outExpressCompanyCode"].ParseToString(), + pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), + tracking_number = row["tracking_number"].ParseToString(), + TransitCreateTime = row["TransitCreateTime"].ParseToString().ParseToDateTime(), + wx_order_id = row["wx_order_id"].ParseToString(), + wx_sku_id = row["wx_sku_id"].ParseToString(), + wx_order_send_type = row["wx_order_send_type"].ParseToNullableInt(), + wx_send_type = row["wx_send_type"].ParseToInt(), + }; + buyerOrderList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(buyerOrderList, 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\":\"输入为空\"}"; + } + + + public string WXAddMdyBuyerAfterSale(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string wx_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); + string wx_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); + string wx_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_send_type"))?.Replace("'", "\\'"); + if (wx_send_type.IsNullOrEmpty()) + wx_send_type = "0"; + string TransitCreateTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "TransitCreateTime"))?.Replace("'", "\\'"); + string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); + string buyerId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerId"))?.Replace("'", "\\'"); + string buyerName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerName"))?.Replace("'", "\\'"); + string orderSn = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderSn"))?.Replace("'", "\\'"); + string afterSalesId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "afterSalesId"))?.Replace("'", "\\'"); + string orderAmount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderAmount"))?.Replace("'", "\\'"); + string orderDate = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderDate"))?.Replace("'", "\\'"); + string order_detail = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_detail"))?.Replace("'", "\\'"); + string refundAmount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refundAmount"))?.Replace("'", "\\'"); + string statusText = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "statusText"))?.Replace("'", "\\'"); + string afterSaleAddress = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "afterSaleAddress"))?.Replace("'", "\\'"); + string is_mdy = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "is_mdy"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(wx_order_id) || string.IsNullOrEmpty(orderSn) || string.IsNullOrEmpty(afterSalesId)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "select id from wxxd.order_pdd_buyer_after_sale where afterSalesId='" + afterSalesId + "'"; + var id = mySql.ExecuteFirstInt(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (id == 0 && is_mdy != "true") + { + sql = "INSERT INTO wxxd.order_pdd_buyer_after_sale (wx_order_id,wx_sku_id,wx_send_type,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,orderSn,afterSalesId,orderAmount,orderDate," + + "refundAmount,statusText,afterSaleAddress,order_detail)"; + sql += "VALUES(@wx_order_id,@wx_sku_id,@wx_send_type,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@orderSn,@afterSalesId,@orderAmount,@orderDate," + + "@refundAmount,@statusText,@afterSaleAddress,@order_detail);"; + } + else + { + sql = "UPDATE wxxd.order_pdd_buyer_after_sale SET "; + if (!string.IsNullOrEmpty(wx_order_id)) + sql += " wx_order_id=@wx_order_id,"; + if (!string.IsNullOrEmpty(wx_sku_id)) + sql += " wx_sku_id=@wx_sku_id,"; + if (!string.IsNullOrEmpty(wx_send_type)) + sql += " wx_send_type=@wx_send_type,"; + if (!string.IsNullOrEmpty(TransitCreateTime)) + sql += " TransitCreateTime=@TransitCreateTime,"; + if (!string.IsNullOrEmpty(pre_allocated_order_no)) + sql += " pre_allocated_order_no=@pre_allocated_order_no,"; + if (!string.IsNullOrEmpty(buyerId)) + sql += " buyerId=@buyerId,"; + if (!string.IsNullOrEmpty(buyerName)) + sql += " buyerName=@buyerName,"; + if (!string.IsNullOrEmpty(orderSn)) + sql += " orderSn=@orderSn,"; + if (!string.IsNullOrEmpty(orderAmount)) + sql += " orderAmount=@orderAmount,"; + if (!string.IsNullOrEmpty(refundAmount)) + sql += " refundAmount=@refundAmount,"; + if (!string.IsNullOrEmpty(statusText)) + sql += " statusText=@statusText,"; + if (!string.IsNullOrEmpty(orderDate)) + sql += " orderDate=@orderDate,"; + if (!string.IsNullOrEmpty(afterSaleAddress)) + sql += " afterSaleAddress=@afterSaleAddress,"; + + if (!string.IsNullOrEmpty(order_detail)) + sql += " order_detail=@order_detail,"; + sql = sql.TrimEnd(','); + sql += " where afterSalesId=@afterSalesId"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_order_id", Value = wx_order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_sku_id", Value = wx_sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "wx_send_type", Value = wx_send_type.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "TransitCreateTime", Value = TransitCreateTime.ParseToDateTime(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "pre_allocated_order_no", Value = pre_allocated_order_no.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerId", Value = buyerId, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerName", Value = buyerName, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "statusText", Value = statusText, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "orderSn", Value = orderSn, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "afterSalesId", Value = afterSalesId, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "refundAmount", Value = refundAmount.ParseToNullableInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "orderAmount", Value = orderAmount.ParseToNullableInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int64, ParameterName = "orderDate", Value = orderDate.ParseToLong(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "afterSaleAddress", Value = afterSaleAddress, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_detail", Value = order_detail, }); + + count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetBuyerAfterSaleList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); + var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); + if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) + { + 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 wxxd.order_pdd_buyer_after_sale o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(wx_order_id_in)) + where += " and o.wx_order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) + where += " and o.order_sn in ('" + buyer_order_sn_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" + + " wxxd.order_pdd_buyer_after_sale 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 buyerAfterSaleLst = new List(); + foreach (DataRow row in dt.Rows) + { + order_pdd_buyer_after_sale afterSale = new order_pdd_buyer_after_sale + { + id = row["id"].ParseToLong(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + afterSalesId = row["afterSalesId"].ParseToString(), + buyerId = row["buyerId"].ParseToString(), + buyerName = row["buyerName"].ParseToString(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + orderAmount = row["orderAmount"].ParseToNullableInt(), + order_detail = row["order_detail"].ParseToString(), + orderSn = row["orderSn"].ParseToString(), + orderDate = row["orderDate"].ParseToNullableInt(), + refundAmount = row["refundAmount"].ParseToNullableInt(), + statusText = row["statusText"].ParseToString(), + afterSaleAddress = row["afterSaleAddress"].ParseToString(), + pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), + TransitCreateTime = row["TransitCreateTime"].ParseToString().ParseToDateTime(), + wx_order_id = row["wx_order_id"].ParseToString(), + wx_sku_id = row["wx_sku_id"].ParseToString(), + wx_send_type = row["wx_send_type"].ParseToInt(), + }; + buyerAfterSaleLst.Add(afterSale); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(buyerAfterSaleLst, 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\":\"输入为空\"}"; + } + + + public string WXGetTransitWarehouseAfterSaleList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); + var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); + if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) + { + 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(1000); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM erp.oms_wei_external_procurement_after_sale o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(wx_order_id_in)) + where += " and o.order_no in ('" + wx_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) + where += " and o.order_code in ('" + buyer_order_sn_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_external_procurement_after_sale 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 refundItemList = new List(); + foreach (DataRow row in dt.Rows) + { + oms_wei_external_procurement_after_sale_info order = new oms_wei_external_procurement_after_sale_info + { + id = row["id"].ParseToLong(), + order_no = row["order_no"].ParseToString(), + order_code = row["order_code"].ParseToString(), + inbound_time = row["inbound_time"].ParseToString().ParseToDateTimeNullable(), + outbound_time = row["outbound_time"].ParseToString().ParseToDateTimeNullable(), + account_user = row["account_user"].ParseToString(), + after_sale_no = row["after_sale_no"].ParseToString(), + created_time = row["created_time"].ParseToString().ParseToDateTimeNullable(), + create_user = row["create_user"].ParseToString(), + downstream_express_code = row["downstream_express_code"].ParseToString(), + downstream_waybill = row["downstream_waybill"].ParseToString(), + external_order_no = row["external_order_no"].ParseToString(), + raw_message = row["raw_message"].ParseToString(), + recipient_name = row["recipient_name"].ParseToString(), + recipient_phone = row["recipient_phone"].ParseToString(), + refund_city = row["refund_city"].ParseToString(), + refund_county = row["refund_county"].ParseToString(), + refund_detail_address = row["refund_detail_address"].ParseToString(), + refund_province = row["refund_province"].ParseToString(), + refund_waybill = row["refund_waybill"].ParseToString(), + return_express_company = row["return_express_company"].ParseToString(), + return_or_exchange = row["return_or_exchange"].ParseToNullableInt(), + status = row["status"].ParseToNullableInt(), + updated_time = row["updated_time"].ParseToString().ParseToDateTimeNullable(), + update_user = row["update_user"].ParseToString(), + warehouse_status = row["warehouse_status"].ParseToNullableInt(), + }; + refundItemList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(refundItemList, 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\":\"输入为空\"}"; + } + + /// + /// 订单异常重拍 + /// + /// + /// + public string WXUpdateAbnormalTransitOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + var order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_no"))?.Replace("'", "\\'"); + var order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_sku_id"))?.Replace("'", "\\'"); + var buyer_account = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyer_account"))?.Replace("'", "\\'"); + var out_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_amount"))?.Replace("'", "\\'"); + var purchaser_note = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "purchaser_note"))?.Replace("'", "\\'"); + var refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refund_status"))?.Replace("'", "\\'"); + var old_out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_out_order_no"))?.Replace("'", "\\'"); + var old_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_order_no"))?.Replace("'", "\\'"); + var old_order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_order_sku_id"))?.Replace("'", "\\'"); + var old_buyer_account = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_buyer_account"))?.Replace("'", "\\'"); + var old_out_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_out_amount"))?.Replace("'", "\\'"); + var old_purchaser_note = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_purchaser_note"))?.Replace("'", "\\'"); + var old_refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_refund_status"))?.Replace("'", "\\'"); + var order_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_code"))?.Replace("'", "\\'"); + if (order_code.IsNullOrEmpty() || old_purchaser_note.IsNullOrEmpty() || old_out_amount.ParseToInt().IsNullOrZero() || old_buyer_account.IsNullOrEmpty() || old_order_no.IsNullOrEmpty() || old_out_order_no.IsNullOrEmpty() || + purchaser_note.IsNullOrEmpty() || out_amount.ParseToInt().IsNullOrZero() || buyer_account.IsNullOrEmpty() || order_no.IsNullOrEmpty() || out_order_no.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"异常单记录信息不完整\",\"affected_rows\":" + 0 + "}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn, true); + + string sql; + + sql = "INSERT INTO wxxd.order_abnormal_transit_order_rebuy_record (out_order_no,order_no,order_sku_id,buyer_account,out_amount,purchaser_note,refund_status,order_code) "; + sql += " VALUES('" + old_out_order_no + "','" + old_order_no + "','" + old_order_sku_id + "','" + old_buyer_account + "'," + old_out_amount + ",'" + + old_purchaser_note + "','" + old_refund_status + "','" + order_code + "')"; + var rows = mySql.ExecuteAffectedRows(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + rows + "}"; + } + if (rows == 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"创建异常单重拍记录失败\",\"affected_rows\":" + rows + "}"; + } + + sql = "UPDATE erp.oms_wei_external_procurement_log SET "; + sql += " out_order_no='" + out_order_no + "',"; + sql += " order_no='" + order_no + "',"; + sql += " order_sku_id='" + order_sku_id + "',"; + sql += " buyer_account='" + buyer_account + "',"; + sql += " out_amount=" + out_amount + ","; + sql += " purchaser_note='" + purchaser_note + "',"; + sql += " refund_status='" + refund_status + "',"; + sql = sql.TrimEnd(','); + sql += " WHERE order_code='" + order_code + "' AND order_no='" + old_order_no + "';"; + rows = mySql.ExecuteAffectedRows(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + rows + "}"; + } + if (rows == 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"更新异常单拍单失败\",\"affected_rows\":" + rows + "}"; + } + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rows + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string WXAddOrderItemExtInfo(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); + string sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); + string out_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_id"))?.Replace("'", "\\'"); + string shop_app_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_app_id"))?.Replace("'", "\\'"); + string shop_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_name"))?.Replace("'", "\\'"); + string buy_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buy_type"))?.Replace("'", "\\'"); + string abnormal_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "abnormal_text"))?.Replace("'", "\\'"); + string flag = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "flag"))?.Replace("'", "\\'"); + string label = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "label"))?.Replace("'", "\\'"); + string remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "remark"))?.Replace("'", "\\'"); + string after_sale_user_delivery_address = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sale_user_delivery_address"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(order_id) || string.IsNullOrEmpty(sku_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "select id from wxxd.order_item_ext where order_id='" + order_id + "' and sku_id='" + sku_id + "'"; + var id = mySql.ExecuteFirstInt(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (id > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"订单已存在\"}"; + } + + sql = "INSERT INTO wxxd.order_item_ext (order_id,sku_id,out_order_id,shop_app_id,shop_name,buy_type,abnormal_text,flag,label,remark,after_sale_user_delivery_address)"; + sql += "VALUES(@order_id,@sku_id,@out_order_id,@shop_app_id,@shop_name,@buy_type,@abnormal_text,@flag,@label,@remark,@after_sale_user_delivery_address);"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_id", Value = order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_id", Value = sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "out_order_id", Value = out_order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_app_id", Value = shop_app_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_name", Value = shop_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buy_type", Value = buy_type, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "abnormal_text", Value = abnormal_text, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "flag", Value = flag, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "label", Value = label, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "remark", Value = remark, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "after_sale_user_delivery_address", Value = after_sale_user_delivery_address, }); + + count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXMdyOrderItemExtInfo(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); + string sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); + string out_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_id"))?.Replace("'", "\\'"); + string shop_app_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_app_id"))?.Replace("'", "\\'"); + string shop_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_name"))?.Replace("'", "\\'"); + string buy_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buy_type"))?.Replace("'", "\\'"); + string abnormal_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "abnormal_text"))?.Replace("'", "\\'"); + string flag = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "flag"))?.Replace("'", "\\'"); + string label = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "label"))?.Replace("'", "\\'"); + string remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "remark"))?.Replace("'", "\\'"); + string after_sale_user_delivery_address = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sale_user_delivery_address"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(order_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "UPDATE wxxd.order_item_ext SET "; + if (!string.IsNullOrEmpty(shop_app_id)) + sql += " shop_app_id=@shop_app_id,"; + if (!string.IsNullOrEmpty(out_order_id)) + sql += " out_order_id=@out_order_id,"; + if (!string.IsNullOrEmpty(shop_name)) + sql += " shop_name=@shop_name,"; + if (buy_type != null) + sql += " buy_type=@buy_type,"; + if (abnormal_text != null) + sql += " abnormal_text=@abnormal_text,"; + if (!string.IsNullOrEmpty(flag)) + sql += " flag=@flag,"; + if (label != null) + sql += " label=@label,"; + if (remark != null) + sql += " remark=@remark,"; + if (!string.IsNullOrEmpty(after_sale_user_delivery_address)) + sql += " after_sale_user_delivery_address=@after_sale_user_delivery_address,"; + sql = sql.TrimEnd(','); + sql += " where 1=1"; + if (!string.IsNullOrEmpty(order_id)) + sql += " and order_id=@order_id"; + if (!string.IsNullOrEmpty(sku_id)) + sql += " and sku_id=@sku_id"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_id", Value = order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_id", Value = sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "out_order_id", Value = out_order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_app_id", Value = shop_app_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_name", Value = shop_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buy_type", Value = buy_type, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "abnormal_text", Value = abnormal_text, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "flag", Value = flag, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "label", Value = label, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "remark", Value = remark, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "after_sale_user_delivery_address", Value = after_sale_user_delivery_address, }); + + var count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetOrderItemExtInfoList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); + var wx_sku_id = RegexUtils.GetStringQuery(ref inputData, "wx_sku_id_in")?.Replace("'", "\\'"); + var out_order_id_in = RegexUtils.GetStringQuery(ref inputData, "out_order_id_in")?.Replace("'", "\\'"); + if (wx_order_id_in.IsNullOrEmpty() && out_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 wxxd.order_item_ext o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(wx_order_id_in)) + where += " and o.order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(wx_sku_id)) + where += " and o.sku_id in ('" + wx_sku_id.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(out_order_id_in)) + where += " and o.out_order_id in ('" + out_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" + + " wxxd.order_item_ext 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 buyerOrderList = new List(); + foreach (DataRow row in dt.Rows) + { + order_item_ext order = new order_item_ext + { + id = row["id"].ParseToLong(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + buy_type = row["buy_type"].ParseToString(), + abnormal_text = row["abnormal_text"].ParseToString(), + after_sale_user_delivery_address = row["after_sale_user_delivery_address"].ParseToString(), + flag = row["flag"].ParseToNullableInt(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + label = row["label"].ParseToString(), + order_id = row["order_id"].ParseToString(), + remark = row["remark"].ParseToString(), + shop_app_id = row["shop_app_id"].ParseToString(), + shop_name = row["shop_name"].ParseToString(), + sku_id = row["sku_id"].ParseToString(), + out_order_id = row["out_order_id"].ParseToString(), + }; + buyerOrderList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(buyerOrderList, 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\":\"输入为空\"}"; + } + } } \ No newline at end of file diff --git a/KJDService/KJD_WebService/BLL/WXXD/WXShopRevenueStatisticsManage.cs b/KJDService/KJD_WebService/BLL/WXXD/WXShopRevenueStatisticsManage.cs new file mode 100644 index 0000000..9ec8adc --- /dev/null +++ b/KJDService/KJD_WebService/BLL/WXXD/WXShopRevenueStatisticsManage.cs @@ -0,0 +1,300 @@ +using KJD_Web.Model; +using KJD_Web.Model.WxModel; +using KJD_Web.Upload.Prod; +using KJD_Web.Utils; +using MySql.Data.MySqlClient; +using Mysqlx.Crud; +using NaiBa.Util.Extension; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Web; +using System.Web.ApplicationServices; +using System.Web.Security; +using System.Web.UI.WebControls; + +namespace KJD_Web.BLL.WXXD +{ + public class WXShopRevenueStatisticsManage + { + public WXShopRevenueStatisticsManage() + { + + } + public string GetShopOrderAmountRange(string inputData) + { + Result ret = Result.ArgumentNull(); + if (!string.IsNullOrEmpty(inputData)) + { + try + { + // todo 获取当前用户微信店铺,或指定某一个店铺,某一段时间 + // 获取店铺下时间范围内的所有订单涉及到的金额 + // 直接返回 + if (!WXUserManage.GetSign(inputData)) + throw new ArgumentException("校验失败"); + var timeCalc = DateTime.Now; + + string shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "");//所有店铺信息 + if (string.IsNullOrEmpty(shop_ids)) + throw new ArgumentException("请选择店铺"); + List shopIdLst = shop_ids.Split(',').ToList(); + if (shopIdLst.Count > 0) + shop_ids = "'" + string.Join("','", shopIdLst) + "'"; + + + + string start_Time = RegexUtils.GetStringQuery(ref inputData, "start_time")?.Replace("'", ""); + string end_Time = RegexUtils.GetStringQuery(ref inputData, "end_time")?.Replace("'", ""); + DateTime startTime = DateTime.Now.AddDays(-7); + DateTime endTime = DateTime.Now; + if (!string.IsNullOrEmpty(start_Time)) + startTime = TimeUtils.StampMillisecondsToDateTime(start_Time.ParseToLong()); + if (!string.IsNullOrEmpty(end_Time)) + endTime = TimeUtils.StampMillisecondsToDateTime(end_Time.ParseToLong()); + if (endTime <= startTime) + throw new ArgumentException("结束时间必须大于开始时间"); + if (endTime > startTime.AddMonths(3)) + throw new ArgumentException("时间范围不能超过3个月"); + + int startTimestamp = TimeUtils.DateTimeToTimestampSeconds(startTime); + int endTimestamp = TimeUtils.DateTimeToTimestampSeconds(endTime); + + StringBuilder sb = new StringBuilder(); + sb.Append("SELECT "); + sb.Append("A.shop_name, "); + sb.Append("A.create_time, "); + sb.Append("A.order_id, "); + sb.Append("A.`status`, "); + sb.Append("A.product_price, "); + sb.Append("A.order_price, "); + sb.Append("A.purchase_price, "); + sb.Append("A.freight, "); + sb.Append("A.predict_commission_fee, "); + sb.Append("A.commission_amount, "); + sb.Append("A.discounted_price, "); + sb.Append("A.profit, "); + sb.Append("A.purchase_status, "); + sb.Append("A.out_amount, "); + sb.Append("B.refund_status, "); + sb.Append("c.`status` as refund_status_string, "); + sb.Append("IFNULL(C.refund_amount, 0) AS refund_amount "); + sb.Append("FROM erp.oms_wei_order AS A "); + sb.Append("INNER JOIN erp.`oms_wei_order_item` AS B ON A.`order_id` = B.`order_id` "); + sb.Append("LEFT JOIN ( SELECT order_id,`status`,refund_amount,id FROM erp.`oms_wei_refund` WHERE id IN ( SELECT MAX(id) FROM erp.`oms_wei_refund` GROUP BY order_id)) AS C ON A.order_id = C.order_id "); + sb.Append("WHERE A.create_time BETWEEN " + startTimestamp + " AND " + endTimestamp + " "); + sb.Append("AND A.`status` > 10 "); + sb.Append("AND B.shop_id IN (" + shop_ids + ") "); + sb.Append("ORDER BY A.create_time asc"); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + DataTable dt = mySql.ExecuteDataTable(sb.ToString()); + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + throw new Exception(mySql.Message); + + // out_amount 为空或为0的订单,从中转仓订单表(GetTransitOrderTable)补全外采金额 + // external_procurement:0=未查到,1=从 GetTransitOrderTable 查询到 + Dictionary transitOutAmountMap = new Dictionary(); + if (dt != null && dt.Rows.Count > 0) + { + HashSet needLookupOrderIds = new HashSet(); + foreach (DataRow row in dt.Rows) + { + int? rowOutAmount = row["out_amount"].ParseToInt(); + if (rowOutAmount == null || rowOutAmount.Value == 0) + { + string orderId = row["order_id"].ParseToString(); + if (!string.IsNullOrEmpty(orderId)) + needLookupOrderIds.Add(orderId); + } + } + + if (needLookupOrderIds.Count > 0) + { + WXOrderManage wxOrderManage = new WXOrderManage(); + const int chunkSize = 100; + const int transitPageSize = 500; + List needLookupList = needLookupOrderIds.ToList(); + for (int i = 0; i < needLookupList.Count; i += chunkSize) + { + int takeCount = Math.Min(chunkSize, needLookupList.Count - i); + string chunkOrderIds = string.Join(",", needLookupList.GetRange(i, takeCount)); + int pageIndex = 1; + while (true) + { + int count = -1; + var transitList = wxOrderManage.GetTransitOrderTable(pageIndex, transitPageSize, chunkOrderIds, null, null, null, null, "true", out count); + if (transitList == null || transitList.Count == 0) + break; + foreach (var transit in transitList) + { + if (transit != null && !string.IsNullOrEmpty(transit.order_no) && needLookupOrderIds.Contains(transit.order_no)) + { + if (!transitOutAmountMap.ContainsKey(transit.order_no)) + transitOutAmountMap[transit.order_no] = transit.out_amount ?? 0; + } + } + if (transitList.Count < transitPageSize) + break; + pageIndex++; + } + } + } + } + + List orderList = new List(); + if (dt != null) + { + foreach (DataRow row in dt.Rows) + orderList.Add(BuildOrderAmountInfo(row, transitOutAmountMap)); + } + + // 买手号退款金额:退款订单(refund_status>1)且非外采时,从买手售后表补全退款金额 + FillBuyerRefundAmount(orderList, conn); + + ret.Code = 200; + ret.Msg = "success"; + ret.Data = orderList; + } + catch (Exception ex) + { + ret.Code = 500; + ret.Msg = ex.Message; + } + } + return JsonUtils.SerializeObjectToString(ret, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore + }); + } + + /// + /// 将订单行转换为金额详情:out_amount 为空或0时从中转仓订单表补全,并计算利润 + /// + private WXOrderAmountInfo BuildOrderAmountInfo(DataRow row, Dictionary transitOutAmountMap) + { + string orderId = row["order_id"].ParseToString(); + + int outAmount = row["out_amount"].ParseToInt(); + int externalProcurement = 0; + if (outAmount == 0) + { + int transitAmount; + if (transitOutAmountMap.TryGetValue(orderId, out transitAmount)) + { + externalProcurement = 1; + outAmount = transitAmount; + } + } + + int orderPrice = row["order_price"].ParseToInt(); + int predictCommissionFee = row["predict_commission_fee"].ParseToInt(); + int commissionAmount = row["commission_amount"].ParseToInt(); + int refund_amount = row["refund_amount"].ParseToInt(); + // 利润 = 订单金额 - 外采金额 - 平台服务费 - 达人佣金(为空按0处理) + int profit = orderPrice - outAmount - predictCommissionFee - commissionAmount; + if (refund_amount > 0) //退款利润计算 + { + profit = orderPrice - refund_amount; + } + + return new WXOrderAmountInfo + { + shop_name = row["shop_name"].ParseToString(), + create_time = row["create_time"].ParseToInt(), + order_id = orderId, + status = row["status"].ParseToInt(), + product_price = row["product_price"].ParseToInt(), + order_price = orderPrice, + purchase_price = row["purchase_price"].ParseToInt(), + freight = row["freight"].ParseToInt(), + predict_commission_fee = predictCommissionFee, + commission_amount = commissionAmount, + discounted_price = row["discounted_price"].ParseToInt(), + profit = profit, + purchase_status = row["purchase_status"].ParseToInt(), + out_amount = outAmount, + refund_status = row["refund_status"].ParseToInt(), + refund_status_string = row["refund_status_string"].ParseToString(), + refund_amount = row["refund_amount"].ParseToInt(), + external_procurement = externalProcurement + }; + } + + /// + /// 买手号退款金额:退款订单(refund_status>1)且非外采时,从买手售后表(wxxd.order_pdd_buyer_after_sale)查询退款金额(refundAmount)填入 + /// + private void FillBuyerRefundAmount(List orderList, string conn) + { + if (orderList == null || orderList.Count == 0) + return; + + // 退款订单(refund_status>1)且非外采(out_amount、external_procurement都为0)的订单才查询买手号退款金额 + HashSet needLookupOrderIds = new HashSet(); + foreach (WXOrderAmountInfo order in orderList) + { + if (order.refund_status > 1 && order.external_procurement == 1 && order.out_amount > 0) + { + if (!string.IsNullOrEmpty(order.order_id)) + needLookupOrderIds.Add(order.order_id); + } + } + if (needLookupOrderIds.Count == 0) + return; + + Dictionary> buyerRefundAmountMap = new Dictionary>(); + MysqlUtils mySql = new MysqlUtils(conn); + try + { + const int chunkSize = 100; + List needLookupList = needLookupOrderIds.ToList(); + for (int i = 0; i < needLookupList.Count; i += chunkSize) + { + int takeCount = Math.Min(chunkSize, needLookupList.Count - i); + string chunkOrderIds = string.Join("','", needLookupList.GetRange(i, takeCount)); + string sql = "SELECT WX_ORDER_ID,refundAmount,statusText FROM wxxd.order_pdd_buyer_after_sale a " + + "WHERE a.WX_ORDER_ID IN ('" + chunkOrderIds + "') AND a.id = ( SELECT MAX(b.id) FROM wxxd.order_pdd_buyer_after_sale b WHERE b.WX_ORDER_ID = a.WX_ORDER_ID) ORDER BY a.WX_ORDER_ID;"; + DataTable buyerDt = mySql.ExecuteDataTable(sql); + if (buyerDt != null) + { + foreach (DataRow row in buyerDt.Rows) + { + string wxOrderId = row["WX_ORDER_ID"].ParseToString(); + int refundAmount = row["refundAmount"].ParseToInt(); + string statusText = row["statusText"].ParseToString(); + if (!string.IsNullOrEmpty(wxOrderId) && !buyerRefundAmountMap.ContainsKey(wxOrderId)) + buyerRefundAmountMap[wxOrderId] = new Tuple(refundAmount, statusText); + } + } + } + } + finally + { + mySql.Close(); + } + if (!string.IsNullOrEmpty(mySql.Message)) + throw new Exception(mySql.Message); + + foreach (WXOrderAmountInfo order in orderList) + { + Tuple buyerRefundAmount; + if (buyerRefundAmountMap.TryGetValue(order.order_id, out buyerRefundAmount)) + { + order.buyer_refund_amount = buyerRefundAmount.Item1; + order.buyer_refund_status = buyerRefundAmount.Item2; + } + } + } + } +} diff --git a/KJDService/KJD_WebService/Global.asax.cs b/KJDService/KJD_WebService/Global.asax.cs index cb13802..8bfb466 100644 --- a/KJDService/KJD_WebService/Global.asax.cs +++ b/KJDService/KJD_WebService/Global.asax.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState; +using KJD_Web.Utils; namespace KJD_Web { @@ -159,14 +160,27 @@ namespace KJD_Web { hPath = hPath.Replace("/wxxd_order/", "/WXOrderService.asmx/"); Context.RewritePath(hPath); - } - } + } + else if (!hPath.Contains(".asmx") && hPath.Contains("/wxxd_shop_revenue_statistics/")) + { + hPath = hPath.Replace("/wxxd_shop_revenue_statistics/", "/WXShopRevenueStatistics.asmx/"); + Context.RewritePath(hPath); + } + // 请求录制:捕获请求链接与请求内容,用于迁移后的回放校验 + //try { ApiRequestLogger.BeginRequest(Context); } catch { } + } protected void Application_AuthenticateRequest(object sender, EventArgs e) { } + protected void Application_EndRequest(object sender, EventArgs e) + { + // 请求录制:合并响应内容并落盘 + //try { ApiRequestLogger.EndRequest(Context); } catch { } + } + protected void Application_Error(object sender, EventArgs e) { diff --git a/KJDService/KJD_WebService/KJD_WebService.csproj b/KJDService/KJD_WebService/KJD_WebService.csproj index 21d3e76..55f7b49 100644 --- a/KJDService/KJD_WebService/KJD_WebService.csproj +++ b/KJDService/KJD_WebService/KJD_WebService.csproj @@ -81,6 +81,7 @@ + @@ -120,6 +121,7 @@ + @@ -130,6 +132,7 @@ + @@ -147,9 +150,11 @@ + + WXOrderService.asmx Component @@ -184,6 +189,10 @@ DYShopService.asmx Component + + WXShopRevenueStatistics.asmx + Component + WXUserService.asmx Component diff --git a/KJDService/KJD_WebService/KJD_WebService.csproj.user b/KJDService/KJD_WebService/KJD_WebService.csproj.user index c789fae..038b08e 100644 --- a/KJDService/KJD_WebService/KJD_WebService.csproj.user +++ b/KJDService/KJD_WebService/KJD_WebService.csproj.user @@ -1,4 +1,4 @@ - + true @@ -8,8 +8,8 @@ - Release|Any CPU - ShowAllFiles + Debug|Any CPU + ProjectFiles diff --git a/KJDService/KJD_WebService/Model/Result.cs b/KJDService/KJD_WebService/Model/Result.cs new file mode 100644 index 0000000..0d25775 --- /dev/null +++ b/KJDService/KJD_WebService/Model/Result.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Model +{ + public class Result + { + public Result() + { + + } + public Result(int code, string msg) + { + Code = code; + Msg = msg; + } + + public int Code { get; set; } + public string Msg { get; set; } + public object Data { get; set; } + + public static Result Success(string msg) + { + return new Result + { + Code = 200, + Msg = msg + }; + } + public static Result Failure(string msg) + { + return new Result + { + Code = 500, + Msg = msg + }; + } + //参数不合法 + public static Result ArgumentNull() + { + return new Result { Code = 19999, Msg = "输入为空" }; + + } + } +} diff --git a/KJDService/KJD_WebService/Model/WxModel/WXOrderAmountInfo.cs b/KJDService/KJD_WebService/Model/WxModel/WXOrderAmountInfo.cs new file mode 100644 index 0000000..79f3bd7 --- /dev/null +++ b/KJDService/KJD_WebService/Model/WxModel/WXOrderAmountInfo.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Model.WxModel +{ + /// + /// 微信订单金额详情 + /// + public class WXOrderAmountInfo + { + /// + /// 店铺名称 + /// + public string shop_name { get; set; } + /// + /// 下单时间(秒级时间戳) + /// + public int create_time { get; set; } + /// + /// 订单号 + /// + public string order_id { get; set; } + /// + /// 订单状态 + /// + public int status { get; set; } + /// + /// 商品总价(分) + /// + public int product_price { get; set; } + /// + /// 订单金额(分) + /// + public int order_price { get; set; } + /// + /// 采购价(分) + /// + public int purchase_price { get; set; } + /// + /// 运费(分) + /// + public int freight { get; set; } + /// + /// 平台服务费(预计技术服务费,分) + /// + public int predict_commission_fee { get; set; } + /// + /// 达人佣金(分) + /// + public int commission_amount { get; set; } + /// + /// 优惠金额(分) + /// + public int discounted_price { get; set; } + /// + /// 利润 = 订单金额 - 外采金额 - 平台服务费 - 达人佣金(分) + /// + public int profit { get; set; } + /// + /// 采购状态 + /// + public int purchase_status { get; set; } + /// + /// 外采金额(分),out_amount 为空或0时从中转仓订单表补全 + /// + public int out_amount { get; set; } + /// + /// 售后状态(订单明细 refund_status) + /// + public int refund_status { get; set; } + /// + /// 售后状态(退款单 status) + /// + public string refund_status_string { get; set; } + /// + /// 售后退款金额(分),无退款默认0 + /// + public int refund_amount { get; set; } + /// + /// 是否外采:0=未从中转仓订单表查到,1=查到 + /// + public int external_procurement { get; set; } + /// + /// 买手号退款金额(分):退款订单且非外采时,从买手售后表(order_pdd_buyer_after_sale)补全,无退款默认0 + /// + public int buyer_refund_amount { get; set; } + /// + /// 买手号退款状态 + /// + public string buyer_refund_status { get; set; } + } +} diff --git a/KJDService/KJD_WebService/Utils/ApiRequestLogger.cs b/KJDService/KJD_WebService/Utils/ApiRequestLogger.cs new file mode 100644 index 0000000..118e499 --- /dev/null +++ b/KJDService/KJD_WebService/Utils/ApiRequestLogger.cs @@ -0,0 +1,303 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Web; +using Newtonsoft.Json; + +namespace KJD_Web.Utils +{ + /// + /// API 请求录制工具:挂接在 Global.asax 的 BeginRequest / EndRequest, + /// 捕获请求链接(action/service)、请求内容(body/query)与响应,按天落盘为 JSON Lines, + /// 用于 .NET Core 迁移后的回放校验。 + /// 配置(Web.config appSettings): + /// ApiRequestLog = 1 开启 / 0 关闭(默认开启) + /// ApiRequestLogDir = 日志目录(默认 ~/App_Data/ApiLogs) + /// + public static class ApiRequestLogger + { + private const string ItemKey = "__ApiRequestLog__"; + private const string FilterItemKey = "__ApiResponseCapture__"; + private const int MaxBodyLogLength = 100000; + + private static readonly object SyncRoot = new object(); + private static readonly Regex SensitiveKeyValueRegex = new Regex( + @"(?i)(\b(?:password|passwd|pwd|token|access_token|secret|app_secret|client_secret|sign|signature|api_key|authorization|key)=)([^&\s""]*)", + RegexOptions.Compiled); + + private static readonly Regex SensitiveRegex = new Regex( + "\"((?i)password|passwd|pwd|token|access_token|secret|app_secret|client_secret|sign|signature|api_key|authorization|key)\"\\s*:\\s*\"([^\"]*)\"", + RegexOptions.Compiled); + + private static readonly string[] FriendlyPrefixes = + { + "/user/", "/shop/", "/update/", "/order/", "/product/", "/product_third/", "/price/", + "/bxx_user/", "/bxx_shop/", "/bxx_product/", "/bxx_product_third/", "/bxx_price/", + "/dyxd_user/", "/dyxd_shop/", "/dyxd_product/", "/dyxd_product_third/", "/dyxd_price/", + "/wxxd_user/", "/wxxd_shop/", "/wxxd_product/", "/wxxd_product_third/", "/wxxd_price/", "/wxxd_order/" + }; + + private static bool _configLoaded; + private static bool _enabled = true; + private static string _logDir; + + private sealed class RequestRecord + { + public string id; + public DateTime time; + public string service; + public string action; + public string url; + public string path; + public string method; + public string query; + public string body; + public string ip; + public string ua; + } + + /// 请求入口:解析 action/service、读取并缓存请求体、安装响应捕获。 + public static void BeginRequest(HttpContext context) + { + try + { + EnsureConfig(context); + if (!_enabled) return; + + string path = context.Request.Path ?? ""; + if (!IsApiPath(path)) return; + + string service, action; + ParsePath(path, out service, out action); + + string body = ReadBody(context); + + var record = new RequestRecord + { + id = Guid.NewGuid().ToString("N"), + time = DateTime.Now, + service = service, + action = action, + path = path, + method = context.Request.HttpMethod, + url = SafeGet(() => context.Request.Url == null ? path : context.Request.Url.ToString(), path), + query = Desensitize(SafeGet(() => context.Request.Url == null ? "" : context.Request.Url.Query, "")), + body = Truncate(Desensitize(body)), + ip = SafeGet(() => context.Request.UserHostAddress, ""), + ua = SafeGet(() => context.Request.UserAgent, "") + }; + + context.Items[ItemKey] = record; + try { context.Response.Headers["X-Request-Id"] = record.id; } catch { } + + try + { + var filter = new ApiResponseCaptureStream(context.Response.Filter); + context.Response.Filter = filter; + context.Items[FilterItemKey] = filter; + } + catch { } + } + catch { } + } + + /// 请求出口:合并响应,写一条 JSON Lines 记录。 + public static void EndRequest(HttpContext context) + { + try + { + if (!_enabled) return; + var record = context.Items[ItemKey] as RequestRecord; + if (record == null) return; + + string responseText = null; + try + { + var filter = context.Items[FilterItemKey] as ApiResponseCaptureStream; + if (filter != null) responseText = Truncate(Desensitize(filter.GetCapturedText())); + } + catch { } + + var line = JsonConvert.SerializeObject(new + { + id = record.id, + time = record.time.ToString("yyyy-MM-dd HH:mm:ss.fff"), + service = record.service, + action = record.action, + method = record.method, + url = record.url, + path = record.path, + query = record.query, + body = record.body, + response = responseText, + ip = record.ip, + ua = record.ua, + status = SafeGet(() => context.Response.StatusCode, 0) + }); + + string fileName = Path.Combine(_logDir, "api_" + DateTime.Now.ToString("yyyyMMdd") + ".jsonl"); + lock (SyncRoot) + { + File.AppendAllText(fileName, line + Environment.NewLine, Encoding.UTF8); + } + } + catch { } + } + + private static void EnsureConfig(HttpContext context) + { + if (_configLoaded) return; + lock (SyncRoot) + { + if (_configLoaded) return; + try + { + string sw = ConfigurationManager.AppSettings["ApiRequestLog"]; + if (!string.IsNullOrEmpty(sw)) + _enabled = (sw == "1" || sw.Equals("true", StringComparison.OrdinalIgnoreCase) || sw.Equals("on", StringComparison.OrdinalIgnoreCase)); + + string dir = ConfigurationManager.AppSettings["ApiRequestLogDir"]; + if (string.IsNullOrEmpty(dir)) dir = "~/App_Data/ApiLogs"; + _logDir = dir.StartsWith("~/") ? context.Server.MapPath(dir) : dir; + if (!Directory.Exists(_logDir)) Directory.CreateDirectory(_logDir); + } + catch { } + _configLoaded = true; + } + } + + private static string ReadBody(HttpContext context) + { + try + { + var input = context.Request.InputStream; + if (input == null || !input.CanRead || input.Length <= 0) return ""; + string text; + using (var reader = new StreamReader(input, Encoding.UTF8, true, 1024, true)) + { + text = reader.ReadToEnd(); + } + try { if (input.CanSeek) input.Position = 0; } catch { } + return text; + } + catch { return ""; } + } + + private static bool IsApiPath(string path) + { + if (string.IsNullOrEmpty(path)) return false; + if (path.IndexOf(".asmx", StringComparison.OrdinalIgnoreCase) >= 0) return true; + foreach (string p in FriendlyPrefixes) + { + if (path.StartsWith(p, StringComparison.OrdinalIgnoreCase)) return true; + } + return false; + } + + private static void ParsePath(string path, out string service, out string action) + { + service = ""; + action = ""; + if (string.IsNullOrEmpty(path)) return; + string p = path.TrimStart('/'); + if (p.EndsWith("/")) p = p.TrimEnd('/'); + string[] segs = p.Split('/'); + if (segs.Length == 0) return; + action = segs[segs.Length - 1]; + if (segs.Length >= 2) + { + int asmxIdx = -1; + for (int i = 0; i < segs.Length; i++) + { + if (segs[i].EndsWith(".asmx", StringComparison.OrdinalIgnoreCase)) { asmxIdx = i; break; } + } + if (asmxIdx >= 0) service = segs[asmxIdx].Replace(".asmx", ""); + else service = segs[0]; + } + else if (p.EndsWith(".asmx", StringComparison.OrdinalIgnoreCase)) + { + service = p.Replace(".asmx", ""); + action = service; + } + } + + private static string Desensitize(string text) + { + if (string.IsNullOrEmpty(text)) return text; + string r = SensitiveRegex.Replace(text, "\"$1\":\"***\""); + r = SensitiveKeyValueRegex.Replace(r, "$1***"); + return r; + } + + private static string Truncate(string text) + { + if (string.IsNullOrEmpty(text) || text.Length <= MaxBodyLogLength) return text; + return text.Substring(0, MaxBodyLogLength) + " [truncated...]"; + } + + private static T SafeGet(Func fn, T def) + { + try { return fn(); } + catch { return def; } + } + + /// 响应捕获流:包装 Response.Filter,缓存写出内容。 + private sealed class ApiResponseCaptureStream : Stream + { + private readonly Stream _inner; + private readonly MemoryStream _buffer = new MemoryStream(); + private string _capturedText; + + public ApiResponseCaptureStream(Stream inner) + { + _inner = inner ?? new MemoryStream(); + } + + public string GetCapturedText() + { + if (_capturedText == null) _capturedText = BytesToText(_buffer.ToArray()); + return _capturedText; + } + + private static string BytesToText(byte[] bytes) + { + if (bytes == null || bytes.Length == 0) return ""; + bool binary = false; + for (int i = 0; i < bytes.Length; i++) + { + byte b = bytes[i]; + if (b == 0 || b < 8) { binary = true; break; } + } + if (binary) return ""; + return Encoding.UTF8.GetString(bytes); + } + + public override bool CanRead { get { return _inner.CanRead; } } + public override bool CanSeek { get { return _inner.CanSeek; } } + public override bool CanWrite { get { return _inner.CanWrite; } } + public override long Length { get { return _inner.Length; } } + public override long Position { get { return _inner.Position; } set { _inner.Position = value; } } + public override void Flush() { _inner.Flush(); } + public override int Read(byte[] buffer, int offset, int count) { return _inner.Read(buffer, offset, count); } + public override long Seek(long offset, SeekOrigin origin) { return _inner.Seek(offset, origin); } + public override void SetLength(long value) { _inner.SetLength(value); } + public override void Write(byte[] buffer, int offset, int count) + { + _buffer.Write(buffer, offset, count); + _inner.Write(buffer, offset, count); + } + protected override void Dispose(bool disposing) + { + if (disposing) + { + try { GetCapturedText(); } catch { } + try { _inner.Dispose(); } catch { } + } + base.Dispose(disposing); + } + } + } +} \ No newline at end of file diff --git a/KJDService/KJD_WebService/WXShopRevenueStatistics.asmx b/KJDService/KJD_WebService/WXShopRevenueStatistics.asmx new file mode 100644 index 0000000..5343caa --- /dev/null +++ b/KJDService/KJD_WebService/WXShopRevenueStatistics.asmx @@ -0,0 +1 @@ +<%@ WebService Language="C#" CodeBehind="WXShopRevenueStatistics.asmx.cs" Class="KJD_Web.WXShopRevenueStatistics" %> diff --git a/KJDService/KJD_WebService/WXShopRevenueStatistics.asmx.cs b/KJDService/KJD_WebService/WXShopRevenueStatistics.asmx.cs new file mode 100644 index 0000000..e760f85 --- /dev/null +++ b/KJDService/KJD_WebService/WXShopRevenueStatistics.asmx.cs @@ -0,0 +1,68 @@ +using KJD_Web.BLL.BXX; +using KJD_Web.BLL.WXXD; +using KJD_Web.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Web; +using System.Web.Services; + +namespace KJD_Web +{ + /// + /// UserService 的摘要说明 + /// + [WebService(Namespace = "http://tempuri.org/")] + [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] + [System.ComponentModel.ToolboxItem(false)] + // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 + // [System.Web.Script.Services.ScriptService] + public class WXShopRevenueStatistics : System.Web.Services.WebService + { + public WXShopRevenueStatistics() + { + + } + private string GetRequestJsonString() + { + Context.Response.ContentType = "text/html;charset=utf-8"; + Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); + + using (Stream s = HttpContext.Current.Request.InputStream) // 获得json 字符流 + { + // 还原数据流 + byte[] b = new byte[s.Length]; + s.Read(b, 0, (int)s.Length); + string jsonText = Encoding.UTF8.GetString(b); // JSON字符串 + if (string.IsNullOrEmpty(jsonText)) + { + var qs = HttpContext.Current.Request.QueryString; + if (qs != null && qs.Keys.Count > 0) + { + jsonText = "{"; + foreach (var key in qs.Keys) + { + jsonText += "\"" + key + "\":" + "\"" + qs[key.ToString()] + "\";"; + } + jsonText = jsonText.TrimEnd(';') + "}"; + } + } + return jsonText; + } + } + + [WebMethod] + public void get_shop_order_amount() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = new WXShopRevenueStatisticsManage().GetShopOrderAmountRange(jsontext); + + Context.Response.Write(result); + Context.Response.End(); + } + } +}