/// <summary> /// 添加一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpShopUser parm) { var res = new ApiResult <string>() { data = "1", statusCode = 200 }; try { //判断登录账号是否存在 var isExt = ErpShopUserDb.IsAny(m => m.ShopGuid == parm.ShopGuid && m.Mobile == parm.Mobile); if (isExt) { res.statusCode = (int)ApiEnum.ParameterError; res.message = "该会员已存在~"; } else { parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); parm.Guid = Guid.NewGuid().ToString(); var dbres = ErpShopUserDb.Insert(parm); if (!dbres) { res.statusCode = (int)ApiEnum.Error; res.message = "插入数据失败~"; } } } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 修改一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > ModifyAsync(ErpShopUser parm) { var res = new ApiResult <string>() { data = "1", statusCode = 200 }; try { ErpShopUserDb.Update(m => new ErpShopUser() { Mobile = parm.Mobile, UserName = parm.UserName, Sex = parm.Sex, Status = parm.Status, Birthday = parm.Birthday }, m => m.Guid == parm.Guid); } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
public void OnGet(string guid, string shop) { userModel = _userService.GetByGuidAsync(guid).Result.data; if (!string.IsNullOrEmpty(shop)) { userModel.ShopGuid = shop; } }
/// <summary> /// 添加一条记录 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpSaleOrder parm, string goodsJson) { var res = new ApiResult <string>() { data = "1", statusCode = (int)ApiEnum.Error }; try { DateTime dayTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00"); parm.Guid = Guid.NewGuid().ToString(); //判断销售订单字符串是否为空 if (string.IsNullOrEmpty(goodsJson)) { res.message = "销售订单里面的商品不能为空~"; return(await Task.Run(() => res)); } //判断用户信息存在,如果存在需要根据用户查询编号 ErpShopUser userModel = null; if (!string.IsNullOrEmpty(parm.UserGuid)) { //判断是否存在 userModel = ErpShopUserDb.GetSingle(m => m.Mobile == parm.UserGuid); if (userModel == null) { res.message = "会员不存在~"; return(await Task.Run(() => res)); } parm.UserGuid = userModel.Guid; } var isStockSuccess = true; //解析字符串转换成List对象 var roGoodsList = JsonConvert.DeserializeObject <List <ErpSaleOrderGoods> >(goodsJson); //验证销售商品的数量是否大于库存数量 foreach (var item in roGoodsList.GroupBy(m => m.GoodsGuid).Select(m => new ErpSaleOrderGoods { GoodsGuid = m.Key, Counts = m.Sum(g => g.Counts) }).ToList()) { var shopStockSum = Db.Queryable <ErpShopSku>() .Where(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == item.GoodsGuid).First(); if (shopStockSum.Stock < item.Counts) { isStockSuccess = false; } } if (!isStockSuccess) { res.message = "商品库存数量"; return(await Task.Run(() => res)); } //获得商品的所有id var goodIds = roGoodsList.Select(m => m.GoodsGuid).ToList(); //根据商品获得列表 var goodList = ErpGoodsSkuDb.GetList(m => goodIds.Contains(m.Guid)); //根据店铺获得加盟商的库存信息 var shopGoodsSkuList = ErpShopSkuDb.GetList(m => m.ShopGuid == parm.ShopGuid && goodIds.Contains(m.SkuGuid)); //满减变量 var fullJson = new List <ShopActivity>(); //根据活动编号,查询活动详情,处理对应金额 ErpShopActivity activityModel = null; if (!string.IsNullOrEmpty(parm.ActivityName)) { //查询活动 activityModel = ErpShopActivityDb.GetSingle(m => m.Guid == parm.ActivityName && m.Enable && !m.IsDel); if (activityModel != null) { parm.ActivityGuid = parm.ActivityName; parm.ActivityName = Utils.GetActivityMethod(activityModel.Method); parm.ActivityTypes = Utils.GetActivityTypes(activityModel.Method); if (!string.IsNullOrEmpty(activityModel.FullBack)) { //满减======序列号满减对象 fullJson = JsonConvert.DeserializeObject <List <ShopActivity> >(activityModel.FullBack); } } } //根据活动算好订单金额,如果有活动,满减或者打折,最终金额会根据活动而变 var roIndex = 0; //定义一个循环的标记 foreach (var item in roGoodsList) { roIndex++; var skuItem = goodList.Find(m => m.Guid == item.GoodsGuid); //增加到GoodsSku的销售数量 goodList.Find(m => m.Guid == item.GoodsGuid).SaleSum += item.Counts; //修改加盟商条形码表中的库存减少, 销售数量增加 var shopSkuModel = shopGoodsSkuList.Find(m => m.SkuGuid == skuItem.Guid); shopGoodsSkuList.Find(m => m.SkuGuid == item.GoodsGuid).Stock = shopSkuModel.Stock - item.Counts; //修改加盟商条形码表中的销售数量 增加 shopGoodsSkuList.Find(m => m.SkuGuid == item.GoodsGuid).Sale = shopSkuModel.Sale + item.Counts; //获得商品原价*购买商品的数量 parm.Money += Convert.ToDecimal(skuItem.SalePrice) * item.Counts; //如果没有活动直接结算金额 if (activityModel == null) { if (parm.SaleType == 1) { parm.RealMoney += Convert.ToInt32(skuItem.SalePrice) * item.Counts; item.Money = Convert.ToInt32(skuItem.SalePrice); } else { item.Money = parm.RealMoney; } } else { //统计非品牌活动,到下面去处理这个值 if (activityModel.Types != 2 && parm.SaleType == 1) { parm.RealMoney += Convert.ToInt32(skuItem.SalePrice) * item.Counts; } } //整除销售计算价格,残次品价格是前端传过来的 if (activityModel != null && parm.SaleType == 1) { //按品牌——这里面只处理打折的,并且是按品牌的 if (activityModel.Method == 1 && activityModel.Types == 2) { if (skuItem.BrankGuid == activityModel.BrandGuid) { //品牌打折 var tempMoney = Convert.ToDecimal(skuItem.SalePrice) * item.Counts; tempMoney = tempMoney * (Convert.ToDecimal(activityModel.CountNum) / 100); parm.RealMoney += tempMoney; item.Money = parm.RealMoney; } else { //不是该品牌部打折 parm.RealMoney += Convert.ToDecimal(skuItem.SalePrice) * item.Counts; item.Money = parm.RealMoney; } } //按品牌——满减 else if (activityModel.Method == 2 && activityModel.Types == 2) { //查询该品牌价格是否满足满减需要 var brankMoney = goodList.Where(m => m.BrankGuid == activityModel.BrandGuid).Sum(m => Convert.ToInt32(m.SalePrice) * item.Counts); var brankCount = goodList.Count(m => m.BrankGuid == activityModel.BrandGuid); //是否满足品牌打折的要求 var isBrankOk = false; //如果满足打折要求,满减值 var fullMoney = 0; //循环判断符合满减对象 foreach (var fullItem in fullJson.OrderByDescending(m => m.fullbegin).ToList()) { if (brankMoney >= fullItem.fullbegin) { isBrankOk = true; fullMoney = fullItem.fullend; break; } } //满足打折需求——根据品牌计算单个商品的价格 品牌平均分配价格 if (skuItem.BrankGuid == activityModel.BrandGuid && isBrankOk) { //单个商品的金额减满减值/品牌个数=订单详情商品的金额 item.Money = Convert.ToDecimal(skuItem.SalePrice) * item.Counts - Convert.ToDecimal(fullMoney / brankCount); parm.RealMoney += item.Money; } else { item.Money = Convert.ToDecimal(skuItem.SalePrice) * item.Counts; parm.RealMoney += item.Money; } } //按品牌——买一增一 else if (activityModel.Method == 3 && activityModel.Types == 2) { //按品牌买一增一 if (skuItem.BrankGuid == activityModel.BrandGuid) { if (roIndex == 1) { item.Money = Convert.ToDecimal(skuItem.SalePrice) * item.Counts; parm.RealMoney += item.Money; } else { item.Money = 0; } } else { //不是该品牌,不参与活动 既然后是品牌买一赠一活动,实际上不应该出现非品牌的商品出现 item.Money = Convert.ToDecimal(skuItem.SalePrice) * item.Counts; parm.RealMoney += item.Money; } } //按全部店铺——打折 else if (activityModel.Method == 1 && activityModel.Types != 2) { //全部商铺,也就是所有金额 var zhVal = Convert.ToDecimal(activityModel.CountNum) / 100; item.Money = (Convert.ToDecimal(skuItem.SalePrice) * item.Counts) * zhVal; } //按全部店铺——满减 else if (activityModel.Method == 2 && activityModel.Types != 2) { var allMoney = goodList.Sum(m => Convert.ToInt32(m.SalePrice) * item.Counts); var allCount = goodList.Count(); //是否满足品牌打折的要求 var isBrankOk = false; //如果满足打折要求,满减值 var fullMoney = 0; //循环判断符合满减对象 foreach (var fullItem in fullJson.OrderByDescending(m => m.fullbegin).ToList()) { if (allMoney >= fullItem.fullbegin) { isBrankOk = true; fullMoney = fullItem.fullend; break; } } if (isBrankOk) { item.Money = Convert.ToDecimal(skuItem.SalePrice) * item.Counts - Convert.ToDecimal(fullMoney / allCount); } } //按全部店铺——买一赠一 else if (activityModel.Method == 3 && activityModel.Types != 2) { item.Money = roIndex == 1 ? Convert.ToDecimal(skuItem.SalePrice) * item.Counts : 0; } } } //有活动,并且是正常销售的情况下 非按品牌 if (activityModel != null && parm.SaleType == 1 && activityModel.Types != 2) { //====打折/满减 if (activityModel.Method == 1) { //全部商铺,也就是所有金额 var zhVal = Convert.ToDecimal(activityModel.CountNum) / 100; parm.RealMoney = Convert.ToDecimal(parm.RealMoney * zhVal); } else if (activityModel.Method == 2) { //循环判断符合满减对象 foreach (var item in fullJson.OrderByDescending(m => m.fullbegin).ToList()) { if (parm.RealMoney >= item.fullbegin) { parm.RealMoney = parm.RealMoney - item.fullend; break; } } } else if (activityModel.Method == 3) { //买一增一 循环购买商品,只读取第一件,第二个是赠品 for (int i = 0; i < roGoodsList.Count; i++) { if (i == 0) { parm.RealMoney = Convert.ToDecimal(goodList.Find(m => m.Guid == roGoodsList[i].GoodsGuid).SalePrice); //给商品明细,第一条商品价格,第二价格为0元,不需要处理 roGoodsList[i].Money = parm.RealMoney; break; } } } } //查询今天销售数量 var dayCount = ErpSaleOrderDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime)); parm.Number = "SO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount); res.data = parm.Number; for (int i = 0; i < roGoodsList.Count; i++) { var item = roGoodsList[i]; item.OrderNumber = parm.Number; item.Guid = Guid.NewGuid().ToString(); item.ShopGuid = parm.ShopGuid; } var result = Db.Ado.UseTran(() => { //添加订单 Db.Insertable(parm).ExecuteCommand(); //添加订单商品 Db.Insertable(roGoodsList).ExecuteCommand(); //根据商品修改商品的销售数量 Db.Updateable(goodList).ExecuteCommand(); //修改加盟商商品条形码的销售数量 Db.Updateable(shopGoodsSkuList).ExecuteCommand(); if (userModel != null) { //根据实付金额,计算积分值 userModel.Points = Convert.ToInt32(parm.RealMoney / 10); //构建积分变动记录 var pointLogModel = new ErpUserPointLog() { Guid = Guid.NewGuid().ToString(), UserGuid = userModel.Guid, OperateGuid = parm.Guid, Types = 0, Point = userModel.Points, Summary = "[增加]-销售商品" }; Db.Insertable(pointLogModel).ExecuteCommand(); //修改用户积分 Db.Updateable <ErpShopUser>().UpdateColumns(m => m.Points == m.Points + userModel.Points).Where(m => m.Guid == userModel.Guid).ExecuteCommand(); } }); res.statusCode = (int)ApiEnum.Status; if (!result.IsSuccess) { res.statusCode = (int)ApiEnum.Error; res.message = result.ErrorMessage; } } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 添加一条记录 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpSaleOrder parm, string goodsJson) { var res = new ApiResult <string>() { data = "1", statusCode = (int)ApiEnum.Error }; try { DateTime dayTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00"); parm.Guid = Guid.NewGuid().ToString(); //判断销售订单字符串是否为空 if (string.IsNullOrEmpty(goodsJson)) { res.message = "销售订单里面的商品不能为空~"; return(await Task.Run(() => res)); } //判断用户信息存在,如果存在需要根据用户查询编号 ErpShopUser userModel = null; if (!string.IsNullOrEmpty(parm.UserGuid)) { //判断是否存在 userModel = ErpShopUserDb.GetSingle(m => m.Mobile == parm.UserGuid); if (userModel == null) { res.message = "会员不存在~"; return(await Task.Run(() => res)); } parm.UserGuid = userModel.Guid; } var isStockSuccess = true; //解析字符串转换成List对象 var roGoodsList = JsonConvert.DeserializeObject <List <ErpSaleOrderGoods> >(goodsJson); //验证销售商品的数量是否大于库存数量 foreach (var item in roGoodsList.GroupBy(m => m.GoodsGuid).Select(m => new ErpSaleOrderGoods { GoodsGuid = m.Key, Counts = m.Sum(g => g.Counts) }).ToList()) { var shopStockSum = Db.Queryable <ErpShopSku>() .Where(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == item.GoodsGuid).First(); if (shopStockSum.Stock < item.Counts) { isStockSuccess = false; } } if (!isStockSuccess) { res.message = "商品库存数量"; return(await Task.Run(() => res)); } //根据活动编号,查询活动详情,处理对应金额 ErpShopActivity activityModel = null; if (!string.IsNullOrEmpty(parm.ActivityName)) { //查询活动 activityModel = ErpShopActivityDb.GetById(parm.ActivityName); if (activityModel != null) { parm.ActivityGuid = parm.ActivityName; parm.ActivityName = activityModel.Method == 1 ? "打折" : "满减"; parm.ActivityTypes = activityModel.Method == 1 ? Convert.ToByte(2) : Convert.ToByte(3); } } //根据活动算好订单金额,如果有活动,满减或者打折,最终金额会根据活动而变 //获得商品的所有id var goodIds = roGoodsList.Select(m => m.GoodsGuid).ToList(); //根据商品获得列表 var goodList = ErpGoodsSkuDb.GetList(m => goodIds.Contains(m.Guid)); //根据店铺获得加盟商的库存信息 var shopGoodsSkuList = ErpShopSkuDb.GetList(m => m.ShopGuid == parm.ShopGuid && goodIds.Contains(m.SkuGuid)); foreach (var item in goodList) { foreach (var roitem in roGoodsList) { if (roitem.GoodsGuid == item.Guid) { //修改商品的销售数量 item.SaleSum += roitem.Counts; //修改加盟商条形码表中的库存减少, 销售数量增加 var shopSkuModel = shopGoodsSkuList.Find(m => m.SkuGuid == roitem.GoodsGuid); shopGoodsSkuList.Find(m => m.SkuGuid == roitem.GoodsGuid).Stock = shopSkuModel.Stock - roitem.Counts; //修改加盟商条形码表中的销售数量 增加 shopGoodsSkuList.Find(m => m.SkuGuid == roitem.GoodsGuid).Sale = shopSkuModel.Sale + roitem.Counts; //获得商品原价*购买商品的数量 parm.Money += Convert.ToDecimal(item.SalePrice) * roitem.Counts; //整除销售计算价格,残次品价格是前端传过来的 if (parm.SaleType == 1) { //这里面只处理打折的,并且是按品牌的 if (activityModel != null && activityModel.Method == 1 && activityModel.Types == 2) { if (item.BrankGuid == activityModel.BrandGuid) { //品牌打折 var tempMoney = Convert.ToDecimal(item.SalePrice) * roitem.Counts; tempMoney = tempMoney * (Convert.ToDecimal(activityModel.CountNum) / 100); parm.RealMoney += tempMoney; } else { //不是该品牌部打折 parm.RealMoney += Convert.ToDecimal(item.SalePrice) * roitem.Counts; } } //else if (activityModel != null && activityModel.Method == 2 && activityModel.Types == 2) { // //品牌满减 // if (item.BrankGuid == activityModel.BrandGuid) // { // } //} else { parm.RealMoney += Convert.ToDecimal(item.SalePrice) * roitem.Counts; } } } } } if (activityModel != null && parm.SaleType == 1) { //====打折/满减 if (activityModel.Method == 1) { //打折 实收金额=实收金额*(折扣值/100) if (activityModel.Types == 0) { //全部商铺,也就是所有金额 var zhVal = Convert.ToDecimal(activityModel.CountNum) / 100; parm.RealMoney = Convert.ToDecimal(parm.RealMoney * zhVal); } } else { //满减======序列号满减对象 var fullJson = JsonConvert.DeserializeObject <List <ShopActivity> >(activityModel.FullBack); //循环判断符合满减对象 foreach (var item in fullJson.OrderByDescending(m => m.fullbegin).ToList()) { if (parm.RealMoney > item.fullbegin) { parm.RealMoney = parm.RealMoney - item.fullend; break; } } } } //根据实付金额,计算积分值 if (userModel != null) { userModel.Points = Convert.ToInt32(parm.RealMoney / 10); } //查询今天销售数量 var dayCount = ErpSaleOrderDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime)); parm.Number = "SO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount); res.data = parm.Number; foreach (var item in roGoodsList) { item.OrderNumber = parm.Number; item.Guid = Guid.NewGuid().ToString(); item.ShopGuid = parm.ShopGuid; } var result = Db.Ado.UseTran(() => { //添加订单 Db.Insertable(parm).ExecuteCommand(); //添加订单商品 Db.Insertable(roGoodsList).ExecuteCommand(); //根据商品修改商品的销售数量 Db.Updateable(goodList).ExecuteCommand(); //修改加盟商商品条形码的销售数量 Db.Updateable(shopGoodsSkuList).ExecuteCommand(); if (userModel != null) { //修改用户积分 Db.Updateable <ErpShopUser>().UpdateColumns(m => m.Points == m.Points + userModel.Points).Where(m => m.Guid == userModel.Guid).ExecuteCommand(); } }); res.statusCode = (int)ApiEnum.Status; if (!result.IsSuccess) { res.statusCode = (int)ApiEnum.Error; res.message = result.ErrorMessage; } } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
public async Task <ApiResult <string> > EditUser(ErpShopUser parm) { return(await _shopUserService.ModifyAsync(parm)); }
public async Task <ApiResult <string> > AddUser(ErpShopUser parm) { return(await _shopUserService.AddAsync(parm)); }