public IActionResult CustomStatusUpload() { var customId = Request.Form["CustomId"].ToString().ToInt(); try { if (customId > 0) { if (!Request.Form["CustomStatus"].Equals(string.Empty)) { var customStatus = Request.Form["CustomStatus"].ObjToInt(); SugarHandler db = new SugarHandler(); if (db.Update <retail_custom>(x => new retail_custom() { Status = customStatus }, q => q.Id == customId)) { return(Ok("信息更新成功")); } } } return(Problem("更新失败,请检查参数是否准确")); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult MachineBindUpload() { try { var companyId = Request.Headers["CompanyId"].ToString().ToInt(); var companyPid = Request.Headers["CompanyPid"].ToString().ToInt(); int machineId = Request.Form["machineId"].ToString().ToInt(); string bindUid = Request.Form["bindUid"].ToString(); string bindComputerName = Request.Form["bindComputerName"].ToString(); if (string.IsNullOrEmpty(bindUid)) { return(Problem("绑定Uid不允许为空")); } SugarHandler db = new SugarHandler(); var machine = db.Single <retail_machine>(x => x.Id == machineId && x.CompanyId == companyId); if (machine == null) { return(Problem("查询不到对应的机器")); } if (!string.IsNullOrEmpty(machine.BindUid) && !machine.BindUid.Equals(bindUid, StringComparison.OrdinalIgnoreCase)) { return(Problem("该机器号已被绑定")); } db.Update <retail_machine>(x => new retail_machine() { BindUid = bindUid, BindComputerName = bindComputerName }, q => q.Id == machineId, false); return(Ok("机器绑定成功")); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }
public IActionResult CategoryUpload() { SugarHandler db = new SugarHandler(); try { //企业Id var companyId = Request.Headers["companyId"].ToString().ToInt(); //企业Pid var companyPid = Request.Headers["companyPid"].ToString().ToInt(); string jsonCategory = Request.Form["jsonCategory"].ToString(); if (string.IsNullOrEmpty(jsonCategory)) { return(Problem("参数不正确")); } JObject obj = JsonConvert.DeserializeObject <JObject>(jsonCategory); var category = obj.JObjectTransToModel <retail_category>(); category.Id = obj["categoryId"].ToString().ToInt(); if (category.Id == 0) { category.CompanyPid = companyPid; category.Status = 1; var result = (category.Id = db.AddReturnId(category)) > 0; retail_ref_company_category company_Category = new retail_ref_company_category() { CategoryId = category.Id, CompanyId = companyId, CompanyPid = companyPid }; result = db.Add(company_Category); db.CommitTran(); if (result) { return(Ok(category)); } } else { var result = db.Update <retail_category>(x => new retail_category() { CategoryCode = category.CategoryCode, CategoryName = category.CategoryName, SordIndex = category.SordIndex, CategoryType = category.CategoryType, ParentId = category.ParentId }, q => q.Id == category.Id, false); db.CommitTran(); if (result) { return(Ok("更新成功")); } } return(Problem("参数有误")); } catch (Exception ex) { db.RollbackTran(); return(Problem(ex.Message)); } }
public IActionResult CustomUpload() { LogHelper.WriteLog(LogType.BASE, "进入客户信息上传接口"); try { //企业Id var companyId = Request.Headers["companyId"].ToString().ToInt(); LogHelper.WriteLog(LogType.BASE, $"企业id:{companyId}"); //企业Pid var companyPid = Request.Headers["companyPid"].ToString().ToInt(); LogHelper.WriteLog(LogType.BASE, $"企业id:{companyPid}"); SugarHandler db = new SugarHandler(); string jsonCustom = Request.Form["jsonCustom"].ToString(); LogHelper.WriteLog(LogType.BASE, $"客户信息:{jsonCustom}"); JObject jObject = (JObject)JsonConvert.DeserializeObject(jsonCustom); retail_custom custom = new retail_custom(); custom = jObject.JTokenTransToModel <retail_custom>(); custom.CompanyPid = companyPid; custom.Id = jObject["CustomId"].ObjToInt(); if (custom.Id == 0) { LogHelper.WriteLog(LogType.BASE, $"新增客户"); custom.Status = 1; custom.CreateDate = DateTime.Now; custom.ModifyDate = DateTime.Now; custom.Id = db.AddReturnId(custom); retail_ref_company_custom company_Custom = new retail_ref_company_custom(); company_Custom.CustomId = custom.Id; company_Custom.CompanyId = companyId; db.AddReturnBool(company_Custom); JObject obj = new JObject(); obj["CustomId"] = custom.Id; return(Ok(custom)); } else { LogHelper.WriteLog(LogType.BASE, $"更新客户"); if (db.Update <retail_custom>(x => new retail_custom { CustomCode = custom.CustomCode, CustomName = custom.CustomName, ProvinceId = custom.ProvinceId, CityId = custom.CityId, AreaId = custom.AreaId, LegalPerson = custom.LegalPerson, Phone = custom.Phone, Fax = custom.Fax, Address = custom.Address, Relation = custom.Relation, RelationPhone = custom.RelationPhone, Remark = custom.Remark, ModifyDate = DateTime.Now }, q => q.Id == custom.Id, false)) { return(Ok(true)); } } return(Problem("更新失败,请检查参数")); } catch (Exception ex) { LogHelper.WriteErrorLog(LogType.BASE, ex); return(Problem("参数异常:" + ex.Message)); } }
public IActionResult OrderInfoUpload() { var companyId = Request.Headers["CompanyId"].ToString().ToInt(); var companyPid = Request.Headers["CompanyPid"].ToString().ToInt(); HttpContext.Response.ContentType = "application/json"; string jsonOrder = ""; using (var sr = new StreamReader(Request.Body, Encoding.UTF8)) { var v = sr.ReadToEndAsync();//或者sr.ReadToEnd() v.Wait(); jsonOrder = v.Result; } JObject orderObj = (JObject)JsonConvert.DeserializeObject(jsonOrder); string orderNum = orderObj["OrderNum"].ToString(); SugarHandler db = new SugarHandler(); var orderModel = db.Single <retail_order>(x => x.OrderNum == orderNum); if (orderModel == null) { orderModel = new retail_order(); } orderModel = orderObj.JObjectTransToModel <retail_order>(); JArray jArray = (JArray)JsonConvert.DeserializeObject(orderObj["OrderDetail"].ObjToString()); List <retail_order_item> orderDetails = new List <retail_order_item>(); foreach (var item in jArray) { retail_order_item orderDetail = new retail_order_item(); orderDetail = item.JTokenTransToModel <retail_order_item>(); orderDetails.Add(orderDetail); } db.BeginTran(); try { if (orderModel.Id > 0) { db.Update <retail_order>(x => new retail_order() { CustomId = orderModel.CustomId, CustomName = orderModel.CustomName, Relation = orderModel.Relation, RelationPhone = orderModel.RelationPhone, Address = orderModel.Address, PayMentType = orderModel.PayMentType, OriginalPrice = orderModel.OriginalPrice, OrderDiscount = orderModel.OrderDiscount, OrderDiscountAmount = orderModel.OrderDiscountAmount, ReceivePrice = orderModel.ReceivePrice, PayStatus = orderModel.PayStatus, PayDate = orderModel.PayDate, OrderStatus = orderModel.OrderStatus, Remark = orderModel.Remark, SaleMan = orderModel.SaleMan }, q => q.Id == orderModel.Id, false); } else { orderModel.Id = db.AddReturnId(orderModel); } foreach (var item in orderDetails) { var existsItem = db.Single <retail_order_item>(x => x.OrderNum == item.OrderNum && x.ItemGuid == item.ItemGuid); if (existsItem != null && existsItem.Id > 0) { db.Update <retail_order_item>(x => new retail_order_item() { ProductId = item.ProductId, ProductName = item.ProductName, ProductUnitName = item.ProductUnitName, SizeId = item.SizeId, SizeName = item.SizeName, IsSingleSize = item.IsSingleSize, OriginalPrice = item.OriginalPrice, ItemDiscount = item.ItemDiscount, ItemDiscountPrice = item.ItemDiscountPrice, PromotionPrice = item.PromotionPrice, BuyPrice = item.BuyPrice, BuyCount = item.BuyCount, PackUnitName = item.PackUnitName, ConversionValue = item.ConversionValue, ProductDescription = item.ProductDescription, Remark = item.Remark }, q => q.Id == existsItem.Id, false); } else { item.CreateDate = AppSetting.TimeNow; item.Id = db.AddReturnId(item); } } return(Ok("订单上传成功")); } catch (SqlSugar.SqlSugarException ex) { return(Problem(ex.Message)); } }