public UserPhoneEmail GetShopAdministratorPhoneEmail(int accId, bool isEncrypt = false) { var phoneEmail = _userPhoneDataRepository.Find( u => u.AccountId == accId && u.Grade == AccountUserGradeConsts.Administrator); if (phoneEmail == null) { throw new YuanbeiException("获取店铺管理员信息失败,未找到对应信息"); } if (isEncrypt) { var email = phoneEmail.Email; var phone = phoneEmail.Phone; var i = email.IndexOf("@", StringComparison.Ordinal); if (i < 3) { phoneEmail.Email = email.Substring(0, i) + "******" + email.Substring(i); } else { phoneEmail.Email = email.Substring(0, 3) + "******" + email.Substring(i); } if (phone.Trim().Length == 13) { phoneEmail.Phone = phone.Substring(0, 3) + "******" + phone.Substring(9); } } return(phoneEmail); }
/// <summary> /// 积分增加 /// </summary> /// <param name="userContext"></param> /// <param name="userInfo"></param> /// <param name="uIntegral"></param> /// <returns></returns> public bool IntegrationAdd(UserContext userContext, UserInfoDetail userInfo, int uIntegral) { var userExistInfo = _userInfoDetailRepository.Find(x => x.Uid == userInfo.Uid); if (userExistInfo == null) { return(false); } var userInfoDetail = new UserInfoDetail { Uid = userInfo.Uid, UIntegral = userExistInfo.UIntegral + uIntegral }; return(_userInfoDetailRepository.Update <UserInfoDetail>(userInfoDetail, item => new { item.UIntegral })); }
public void Update() { var entity = dapper.Find(1); entity.DataUpdateDateTime = DateTime.Now; dapper.Update(entity); }
/// <summary> /// 销售还款 /// </summary> /// <param name="userContext"></param> /// <param name="salesId"></param> /// <param name="money"></param> /// <param name="remark"></param> /// <param name="sendsms"></param> /// <returns></returns> public int SalesRepayment(UserContext userContext, int salesId, decimal money, string remark, int sendsms, int operatorID) { var salesInfo = _salesDapperRepository.Find(x => x.saleID == salesId && x.accID == userContext.AccId); if (salesInfo == null) { return(-1); } else if (salesInfo.UnpaidMoney <= 0) { return(-2); } else { var updateSalesInfo = new SalesInfo(); updateSalesInfo.accID = userContext.AccId; updateSalesInfo.saleID = salesId; updateSalesInfo.UnpaidMoney = salesInfo.UnpaidMoney - money; updateSalesInfo.CashMoney = salesInfo.CashMoney + money; bool result = _salesDapperRepository.Update <SalesInfo>(updateSalesInfo, item => new { item.UnpaidMoney, item.CashMoney }); if (result) { var logModel = new SaleLogInfo { accID = userContext.AccId, saleID = salesId, saleListID = 0, logType = 3, itemType = 0, OriginalVal = salesInfo.UnpaidMoney, EditVal = money }; logModel.FinalVal = logModel.OriginalVal - logModel.EditVal; logModel.LogTime = DateTime.Now; logModel.operatorTime = DateTime.Now; logModel.operatorID = userContext.Operater; logModel.operatorIP = userContext.IpAddress; logModel.addedLgUserId = operatorID == 0 ? userContext.Operater : operatorID; logModel.Remark = remark; logModel.Flag = ""; _salesLogDapperRepository.Insert(logModel); if (sendsms == 1) { //TODO 接统一短信接口 } } return(result ? 1 : 0); } }
public CouponInfoItem GetCouponInfo(int accId, int groupId) { var result = _couponInfoDapperRepository.Find(x => x.Id == groupId); var count = _couponListDapperRepository.FindAll(x => x.AccId == accId && x.GroupId == groupId).Count(); var couponInfoItem = Mapper.Map <CouponInfo, CouponInfoItem>(result); couponInfoItem.CouponType = Enum.GetName(typeof(CouponEnum.CouponType), couponInfoItem.CouponType); return(couponInfoItem); }
/// <summary> /// 根据Id获取支出记录 /// </summary> /// <param name="id"></param> /// <param name="userContext"></param> /// <returns></returns> public ResponseModel GetExpensesById(int id, UserContext userContext) { var result = _expensesRepository.Find(x => x.Id == id); return(new ResponseModel { Code = result != null ? (int)ErrorCodeEnum.Success : (int)ErrorCodeEnum.NotFound, Data = result }); }
public void FindWhereOperator_MicroOrm() { using (IDbConnection connection = new SqlConnection(Consts.ConnectionString)) { var repository = new DapperRepository <User>(connection); for (int i = 0; i < CountQueries; i++) { var user = repository.Find(q => q.Name == "name50"); } } }
/// <summary> /// 获取用户消息处理行为是否存在(是否点击、是否查看) /// </summary> /// <param name="userContext"></param> /// <param name="tipsType"></param> /// <returns></returns> private UserBehaviorModel GetUserBehaviorResult(UserContext userContext, int tipsType) { var modelConfig = ((UserBehaviorNameEnum)tipsType).GetConfig(); if (modelConfig == null) { return(null); } var eventType = (int)modelConfig.EventType; var userBehaviorResult = _userBehaviorDapperRepository.Find( x => x.AccId == userContext.AccId && x.AccUserId == userContext.UserId && x.ElementId == tipsType && x.EventType == eventType); return(userBehaviorResult); }
private AccountVersionBasic GetAccountVersionBasic(int accId) { var strSql = @" SELECT m.aotjb AS [Version] ,m.endtime AS VersionExpirationTime ,ISNULL(m.BetaAdvance, 0) AS BetaAdvance ,ISNULL(n.IndustryName, '') AS IndustryName FROM T_Business m LEFT JOIN T_IndustryShop_Setting n ON m.accountid = n.AccId WHERE m.accountid = @accountId"; var sqlParams = new { accountId = accId }; var dapperParam = new DynamicParameters(sqlParams); var sqlQuery = new SqlQuery(strSql.ToString(), dapperParam); var accountVersion = _accountVersionRepository.Find(sqlQuery); return(accountVersion); }
public ResponseModel GetGoodsInfoByGid(int gid, UserContext userContext) { var result = _goodsSummaryRepository.Find(x => x.Id == gid && x.AccId == userContext.AccId, null, item => new { item.Id, item.GName, item.IsService, item.AccId }); if (result == null) { return(new ResponseModel { Code = (int)ErrorCodeEnum.NotFound, Message = "未找到对应的资源", Data = null }); } return(new ResponseModel { Code = (int)ErrorCodeEnum.Success, Message = "获取数据成功", Data = result }); }
/// <summary> /// 会员充值 /// </summary> /// <param name="userContext"></param> /// <param name="userStoreParam"></param> /// <returns></returns> public ResponseModel UserStoreMoney(UserContext userContext, UserStoreMoneyAdd userStoreParam) { var tranFlag = false; var userInfo = new UserInfoDetail(); if (userStoreParam.UserId > 0) { userInfo = _userInfoRepository.Find(x => x.Uid == userStoreParam.UserId && x.AccId == userContext.AccId); } var conn = _useraddDapperRepository.Connection; conn.Open(); var trans = conn.BeginTransaction(); try { //1.先获取充值会员的个人信息(储值余额、计次卡、上次购买时间等) if (userStoreParam.UserId == 0) { //1.1 新会员储值,先增加会员,然后充值 if (userStoreParam.UserId == 0) { var userNo = _userService.GetUserNewNo(userContext.AccId).Data.ToString(); //1.2 新增会员,储值 var userHandel = new UserHandle { Id = userStoreParam.UserId, UserNo = userNo, UserPhone = userStoreParam.Phone, UserName = userStoreParam.UserName, UserStoreMoney = userStoreParam.RechargeMoney, PinYin = Helper.GetPinyin(userStoreParam.UserName), PY = Helper.GetInitials(userStoreParam.UserName), OperatorId = userContext.UserId, AccId = userContext.AccId }; var userInsertResult = _useraddDapperRepository.Insert(userHandel, trans); if (userInsertResult) { //1.3 记录日志 var storeLogInfo = new UserLogInfo { AccId = userContext.AccId, OriginalAccId = userContext.AccId, UId = userHandel.Id, LogType = (int)UserLogTypeEnum.StoreChange, ItemType = (int)UserLogItemTypeEnum.Shopping, OriginalVal = 0, EditMoney = userStoreParam.RealMoney, EditVal = userStoreParam.RechargeMoney, FinalVal = userStoreParam.RechargeMoney, LogTime = DateTime.Now, OperatorTime = DateTime.Now, OperatorId = userContext.UserId, OperatorIp = userContext.IpAddress, Remark = userStoreParam.Remark, Flag = string.Empty, FlagStatus = 0, FlagStatusTime = DateTime.Now, EditMoneyType = userStoreParam.PayType, AddedLgUserId = userStoreParam.Salesman, BindCardId = 0 }; if (_userLogRepository.Insert(storeLogInfo, trans)) { tranFlag = true; } } } } else { //2.储值并记录日志 tranFlag = LoggingStoreMoneyLog(userContext, userStoreParam, userInfo, trans); } } catch (Exception) { trans.Rollback(); tranFlag = false; throw; } finally { if (tranFlag) { trans.Commit(); //3.发送提醒短信 if (userStoreParam.SendMsg) { Task.Run(() => { _shardService.SendSms(userContext); }); } } else { trans.Rollback(); } trans.Dispose(); conn.Close(); } //4.返回数据 return(new ResponseModel { Code = tranFlag ? (int)ErrorCodeEnum.Success : (int)ErrorCodeEnum.StoreMoneyFailed, Data = userStoreParam }); }
/// <summary> /// 店铺店员签到 /// </summary> /// <param name="userContext"></param> public int AddSignin(UserContext userContext, int signType) { //TODO:signOption 签到随机产生的激励名句 var accountBusiness = _accountBusinessDapperRepository.Find(x => x.accountid == userContext.AccId); int addSmsNum = 0; //默认短信条数 int addRegStorage = 0; //默认会员空间 int addIntegral = 2; //默认积分倍数 int daygap = -1; int serialDay = 0; //获取连续登陆次数,今天是否签到 var strSqlCoupon = @"SELECT top(1) @DayGap=DATEDIFF(day,CreatTime,GETDATE()), @SerialDay=SerialDay FROM T_LogSign WHERE accountID=@AccountId AND CreatTime BETWEEN DATEADD(day,-3,GETDATE()) AND GETDATE() ORDER BY CreatTime DESC; IF @DayGap IS NULL SET @DayGap=-1; IF @SerialDay IS NULL SET @SerialDay=0; "; var sqlParams = new { AccountId = userContext.AccId, }; var dapperParam = new DynamicParameters(sqlParams); dapperParam.Add("DayGap", dbType: DbType.Int32, direction: ParameterDirection.Output); dapperParam.Add("SerialDay", dbType: DbType.Int32, direction: ParameterDirection.Output); var sqlQuery = new SqlQuery(strSqlCoupon, dapperParam); _accountUserLogSignDapperRepository.FindAll(sqlQuery); daygap = dapperParam.Get <int>("DayGap"); serialDay = dapperParam.Get <int>("SerialDay"); if (daygap == 0) { //今天已签到 return(-1); } else { serialDay = serialDay + 1; if (signType == 1) { addIntegral = IntegralStragetyForWeb(serialDay, addIntegral); } if (signType == 3) { addIntegral = IntegralStragetyForApp(serialDay, addIntegral); } } //新增日志 LogSign logSignInsert = new LogSign(); logSignInsert.accountID = userContext.AccId.ToString(); logSignInsert.CreatTime = DateTime.Now; logSignInsert.SignType = signType; //signType:1=网页;3=APP logSignInsert.SerialDay = serialDay; logSignInsert.Add_Storage = addRegStorage; logSignInsert.Add_Sms = addSmsNum; logSignInsert.Add_Integral = addIntegral; _accountUserLogSignDapperRepository.Insert(logSignInsert); //更新业务表积分 Business businessUpdate = new Business(); businessUpdate.accountid = userContext.AccId; businessUpdate.gsreguser = accountBusiness.gsreguser + addRegStorage; businessUpdate.integral = accountBusiness.integral + addIntegral; _accountBusinessDapperRepository.Update <Business>(businessUpdate, item => new { item.gsreguser, item.integral }); //LogInfo LogInfo logInfoInsert = new LogInfo(); logInfoInsert.accID = userContext.AccId; logInfoInsert.LogType = 7; logInfoInsert.Keys = "Integral"; logInfoInsert.OriginalVal = accountBusiness.integral.ToString(); logInfoInsert.EditVal = addIntegral.ToString(); logInfoInsert.FinialVal = businessUpdate.integral.ToString(); logInfoInsert.CreatTime = DateTime.Now; logInfoInsert.ReMark = "每日签到"; logInfoInsert.Flags = "0"; _accountUserLogInfoDapperRepository.Insert(logInfoInsert); return(1); }
/// <summary> /// 根据店铺人员的Id获取详细信息 /// </summary> /// <param name="userContext"></param> /// <param name="id"></param> /// <returns></returns> public AccountUser GetAccountUserInfoById(UserContext userContext, int id) { return(_accountUserDapperRepository.Find(x => x.Id == id && x.AccountId == userContext.AccId)); }
/// <summary> /// 获取店铺基本信息 /// </summary> /// <param name="userContext"></param> /// <returns></returns> public AccountBaseInfo GetAccountBaseInfo(UserContext userContext) { var accountInfo = _accountDapperRepository.Find(x => x.Id == userContext.AccId); var accountBusiness = _accountBusinessDapperRepository.Find(x => x.accountid == userContext.AccId); var accountUser = _accountUserDapperRepository.Find(x => x.Id == userContext.UserId && x.AccountId == userContext.AccId); var accountExpand = _accountExpandDapperRepository.Find(x => x.AccountId == userContext.AccId); var accountLogoModel = _accountLogoDapperRepository.Find(x => x.ShopperId == userContext.AccId); //头像 var accountLogo = "/v/assets/images/logo.png"; var accountAvatar = "/SetUp/assets/img/pic-default.png"; if (accountLogoModel != null && !string.IsNullOrEmpty(accountLogoModel.ImgUrl)) { accountLogo = "/upload/logo/" + accountLogoModel.ImgUrl; } if (!string.IsNullOrEmpty(accountExpand.t_Avatar)) { accountAvatar = "http://img.i200.cn" + accountExpand.t_Avatar + "!small"; } //礼金券 var strSqlCoupon = @"SELECT @ActiveCouponNum=COUNT(1) FROM T_Order_CouponList LEFT JOIN T_Order_CouponInfo ON T_Order_CouponList.groupId=T_Order_CouponInfo.id WHERE T_Order_CouponList.toAccId=@AccountId AND (T_Order_CouponList.couponStatus=0 OR T_Order_CouponList.couponStatus=2) AND (T_Order_CouponInfo.couponType=1 OR T_Order_CouponInfo.couponType=2)"; var sqlParams = new { AccountId = userContext.AccId }; var dapperParam = new DynamicParameters(sqlParams); dapperParam.Add("ActiveCouponNum", dbType: DbType.Int32, direction: ParameterDirection.Output); var sqlQuery = new SqlQuery(strSqlCoupon, dapperParam); _orderGouponDapperRepository.FindAll(sqlQuery); var accountActiveCoupon = dapperParam.Get <int>("ActiveCouponNum"); //今日积分 var strSqlIntegral = @"SELECT @TodayIntegral=SUM(CAST(EditVal AS INT)) FROM T_LogInfo WHERE accID=@AccountId AND Keys='Integral' AND CreatTime>convert(varchar(10),getdate(),120) IF @TodayIntegral IS NULL SET @TodayIntegral=0;"; var sqlParams2 = new { AccountId = userContext.AccId }; var dapperParam2 = new DynamicParameters(sqlParams2); dapperParam2.Add("TodayIntegral", dbType: DbType.Int32, direction: ParameterDirection.Output); var sqlQuery2 = new SqlQuery(strSqlIntegral, dapperParam2); _accountUserLogInfoDapperRepository.FindAll(sqlQuery2); var accountIntegralToday = dapperParam2.Get <int>("TodayIntegral"); //资金账户 decimal accountTotalMoney = 0; var responesModelAccountbook = _accountbookService.GetWithdrawingBalance(userContext); if (responesModelAccountbook.Code == 200) { var responseData = (AccountBalanceResponse)responesModelAccountbook.Data; accountTotalMoney = responseData.TotalBalance; } var accountBaseInfo = new AccountBaseInfo(); accountBaseInfo.accountId = accountInfo.Id; accountBaseInfo.accountName = accountInfo.CompanyName; accountBaseInfo.accountContactPhone = accountUser.PhoneNumber; if (accountBusiness.aotjb != 3 && accountBusiness.aotjb != 5) { accountBaseInfo.accountLicense = 1; } else { accountBaseInfo.accountLicense = accountBusiness.aotjb; } accountBaseInfo.accountLicenseName = StatusDictionary.DicAccountLicenseNameStatus[accountBaseInfo.accountLicense]; accountBaseInfo.accountEnterprise = string.IsNullOrEmpty(accountInfo.EnterpriseId) ? 0 : 1; accountBaseInfo.accountLogo = accountLogo; accountBaseInfo.accountAvatar = accountAvatar; accountBaseInfo.accountIntegral = accountBusiness.integral; accountBaseInfo.accountIntegralToday = accountIntegralToday; accountBaseInfo.accountActiveCoupon = accountActiveCoupon; accountBaseInfo.accountTotalMoney = accountTotalMoney; accountBaseInfo.accountLoginUser = new accountLoginUser(); accountBaseInfo.accountLoginUser.userId = accountUser.Id; accountBaseInfo.accountLoginUser.userName = accountUser.Name; accountBaseInfo.accountLoginUser.role = accountUser.Grade == "管理员" ? 1 : 0; return(accountBaseInfo); }
/// <summary> /// 销售退货 /// </summary> /// <param name="userContext"></param> /// <param name="salesId"></param> /// <param name="remark"></param> /// <param name="type"></param> /// <returns></returns> public int SalesReturnGoods(UserContext userContext, int salesListId, string remark, int type) { var salesReturnGoodsType = (SalesReturnGoodsType)type; //销售列表信息 var salesList = _salesListDapperRepository.Find(x => x.saleListID == salesListId); //销售基本信息 var salesInfo = _salesDapperRepository.Find(x => x.saleID == salesList.saleID); if (salesList == null) { return(-1); } var returnNumber = salesList.GoodsNum; //退货数量 decimal returnAbleMoney = salesList.AbleMoney; //应收金额 decimal returnRealMoney = salesList.RealMoney; //实收金额 var itemDesc = ""; switch (type) { case 1: itemDesc = "商品质量原因"; break; case 2: itemDesc = "商品不一致"; break; case 3: itemDesc = "其他原因"; break; case 4: itemDesc = "输入错误,删除本条记录!"; break; } #region 会员信息处理 if (salesInfo.isRetail == 0 && salesInfo.uid > 0) { var userInfo = _userInfoDapperRepository.Find(x => x.Uid == salesInfo.uid && x.AccId == userContext.AccId); //是否记次 if (salesInfo.payType == 3) { var userTimesResponse = _iUserTimesCardService.GetUserTimesCardList(userContext, new UserTimesCardSearchParam() { UserId = salesInfo.uid.ToString() }); var returnBackTimes = 0; decimal returnBackTimesMoney = 0; if (userTimesResponse.Code == 0) { var userTimesCard = (UserTimesCardSearchParamResult)userTimesResponse.Data; returnBackTimesMoney = (userTimesCard.TotalStoreMoney / userTimesCard.TotalAvaiable) * returnNumber; StringBuilder strSqlUserTimes = new StringBuilder(); //实际金额大于扣除储值金额(部分为现金支付) strSqlUserTimes.Append( " UPDATE T_SaleInfo SET RealMoney =ISNULL(RealMoney,0)-cast(@reRealMoney as decimal(18, 2)), StoreMoney =ISNULL(StoreMoney,0)-@ToBackStoreMoney,CashMoney =ISNULL(CashMoney,0)-cast(@ToBackCash as decimal(18, 2)), ReturnBackMoney =ISNULL(ReturnBackMoney,0)+cast(@reRealMoney as decimal(18, 2)) where accID=@accID and saleID=@saleID; "); //退回储值金额 strSqlUserTimes.Append( " UPDATE T_UserInfo SET uStoreMoney =ISNULL(uStoreMoney,0)+cast(@ToBackStoreMoney as decimal(18, 2)) where [uid]=@userID and accID IN ( SELECT id FROM dbo.T_Account WHERE max_shop IN (SELECT max_shop FROM dbo.T_Account WHERE ID= @accID));"); var sqlParamsUserTimes = new { accID = userContext.AccId, uid = salesInfo.uid, reRealMoney = returnRealMoney, reNumber = returnNumber, timesCardId = salesList.TimeCardId, timesMoneyPay = returnBackTimesMoney, saleID = salesInfo.saleID, }; var dapperParamUserTimes = new DynamicParameters(sqlParamsUserTimes); var sqlQueryUserTimes = new SqlQuery(strSqlUserTimes.ToString(), dapperParamUserTimes); _salesDapperRepository.Find(sqlQueryUserTimes); //写日志 #region 记次日志 var timesLogInfo = new UserLogInfo { AccId = userContext.AccId, OriginalAccId = userContext.AccId, UId = salesInfo.uid, LogType = (int)UserLogTypeEnum.TimesCardChange, ItemType = (int)UserLogItemTypeEnum.ModifyIntegral, LogTime = DateTime.Now, OperatorTime = DateTime.Now, OperatorId = userContext.UserId, OperatorIp = userContext.IpAddress, Remark = remark, Flag = string.Empty, FlagStatus = 0, FlagStatusTime = DateTime.Now, EditMoney = 0, EditMoneyType = 0, AddedLgUserId = userContext.UserId, BindCardId = salesList.TimeCardId, OriginalVal = userTimesCard.TotalAvaiable, EditVal = returnNumber, FinalVal = userTimesCard.TotalAvaiable + returnNumber, }; _userLogRepository.Insert(timesLogInfo); #endregion } } //是否储值 if (salesInfo.payType == 4) { //如果实际金额大于扣除储值金额(部分为现金支付) var returnBackCash = returnRealMoney - salesInfo.StoreMoney; var returnBackStoreMoney = salesInfo.StoreMoney; StringBuilder strSqlStoreMoney = new StringBuilder(); //实际金额大于扣除储值金额(部分为现金支付) strSqlStoreMoney.Append(" UPDATE T_SaleInfo SET RealMoney =ISNULL(RealMoney,0)-cast(@reRealMoney as decimal(18, 2)), StoreMoney =ISNULL(StoreMoney,0)-@ToBackStoreMoney,CashMoney =ISNULL(CashMoney,0)-cast(@ToBackCash as decimal(18, 2)), ReturnBackMoney =ISNULL(ReturnBackMoney,0)+cast(@reRealMoney as decimal(18, 2)) where accID=@accID and saleID=@saleID; "); //退回储值金额 strSqlStoreMoney.Append(" UPDATE T_UserInfo SET uStoreMoney =ISNULL(uStoreMoney,0)+cast(@ToBackStoreMoney as decimal(18, 2)) where [uid]=@userID and accID IN ( SELECT id FROM dbo.T_Account WHERE max_shop IN (SELECT max_shop FROM dbo.T_Account WHERE ID= @accID));"); var sqlParamsStoreMoney = new { accID = userContext.AccId, uid = salesInfo.uid, reRealMoney = returnRealMoney, ToBackCash = returnBackStoreMoney, ToBackStoreMoney = returnBackCash, saleID = salesInfo.saleID, }; var dapperParamStoreMoney = new DynamicParameters(sqlParamsStoreMoney); var sqlQueryStoreMoney = new SqlQuery(strSqlStoreMoney.ToString(), dapperParamStoreMoney); _salesDapperRepository.Find(sqlQueryStoreMoney); //写日志 #region 储值日志 var storeMoneyLogInfo = new UserLogInfo { AccId = userContext.AccId, OriginalAccId = userContext.AccId, UId = salesInfo.uid, LogType = (int)UserLogTypeEnum.StoreChange, ItemType = (int)UserLogItemTypeEnum.ModifyIntegral, LogTime = DateTime.Now, OperatorTime = DateTime.Now, OperatorId = userContext.UserId, OperatorIp = userContext.IpAddress, Remark = remark, Flag = string.Empty, FlagStatus = 0, FlagStatusTime = DateTime.Now, EditMoney = returnRealMoney, EditMoneyType = 0, AddedLgUserId = userContext.UserId, BindCardId = salesList.TimeCardId, OriginalVal = userInfo.UStoreMoney, EditVal = returnRealMoney, FinalVal = userInfo.UStoreMoney + returnRealMoney, }; _userLogRepository.Insert(storeMoneyLogInfo); #endregion } //会员积分(等级) if (salesList.isIntegral == 1) { //积分配置 var accountInfo = _accountDapperRepository.Find(x => x.Id == userContext.AccId); var integralConfig = accountInfo.Proportion; //会员积分处理 int nowIntegral = 0; int newIntrgral = 0; decimal propMoney = 0; int propIntegral = 0; decimal tempPropIntegral = 0; string tempStrPropIntegral = "0"; //获取积分比例 var propList = integralConfig.Split('/'); decimal.TryParse(propList[0], out propMoney); decimal.TryParse(propList[1], out tempPropIntegral); tempStrPropIntegral = Math.Round(tempPropIntegral).ToString(); int.TryParse(tempStrPropIntegral, out propIntegral); if (propMoney != 0) { nowIntegral = Convert.ToInt32(Math.Floor((returnRealMoney / propMoney) * propIntegral)); } else { nowIntegral = 0; } newIntrgral = userInfo.UIntegral - nowIntegral; if (newIntrgral < 0) { newIntrgral = 0; } //操作积分、等级 _iUserService.SetUserIntegral(UserIntegralSetTypeEnum.Add, userContext, userInfo.Uid, newIntrgral, ""); } } #endregion #region 调整库存 var goodsInfo = _goodsSummaryDapperRepository.Find(x => x.Id == salesList.GoodsID); var returnedRemark = "退货入库"; if (!string.IsNullOrEmpty(remark)) { returnedRemark += remark; } if (goodsInfo.IsService == 1) { StockInto(userContext.AccId, -2, salesList.CostPrice, goodsInfo.Id, 0M, DateTime.Now, returnedRemark, userContext.Operater, userContext.IpAddress); } else { //颜色尺码入库 if (goodsInfo.IsExtend == 1) { StockIntoEx(userContext.AccId, salesList.CostPrice, -2, goodsInfo.Id, salesList.SkuId, salesList.GoodsName, returnNumber, DateTime.Now, returnedRemark, userContext.Operater, userContext.IpAddress); } else { StockInto(userContext.AccId, -2, salesList.CostPrice, goodsInfo.Id, returnNumber, DateTime.Now, returnedRemark, userContext.Operater, userContext.IpAddress); } } #endregion #region 操作销售表 if (salesReturnGoodsType == SalesReturnGoodsType.InputErrorOfGoods) { //删除:操作销售表 StringBuilder strSqlSalesDelete = new StringBuilder(); strSqlSalesDelete.Append(" DELETE FROM T_Sale_List where accID=@accID and saleListID=@saleListID; "); strSqlSalesDelete.Append( " UPDATE T_SaleInfo SET saleKind =ISNULL(saleKind,0)-1, saleNum =ISNULL(saleNum,0)-cast(@GoodsNum as decimal(18, 2)) where accID=@accID and saleID=@saleID; "); var sqlParamsSalesDelete = new { accID = userContext.AccId, uid = salesInfo.uid, saleListID = salesListId, saleID = salesInfo.saleID, GoodsNum = salesList.GoodsNum, }; var dapperParamSalesDelete = new DynamicParameters(sqlParamsSalesDelete); var sqlQuerySalesDelete = new SqlQuery(strSqlSalesDelete.ToString(), dapperParamSalesDelete); _salesDapperRepository.Find(sqlQuerySalesDelete); return(1); } else { //退货:操作销售表 StringBuilder strSqlSalesUpdate = new StringBuilder(); strSqlSalesUpdate.Append( " UPDATE T_Sale_List SET returnStatus =1, returnFlag =@itemType, returnDesc =@itemDesc, returnRemark =@Remark,returnTime=GETDATE() where accID=@accID and saleListID=@saleListID; "); strSqlSalesUpdate.Append( " UPDATE T_SaleInfo SET saleNum=saleNum-isnull(@reNumber,0) where accID=@accID and saleID=@saleId; "); var sqlParamsSalesUpdate = new { accID = userContext.AccId, saleListID = salesListId, saleID = salesInfo.saleID, itemType = type, itemDesc = itemDesc, Remark = remark, reNumber = returnNumber, }; var dapperParamSalesUpdate = new DynamicParameters(sqlParamsSalesUpdate); var sqlQuerySalesUpdate = new SqlQuery(strSqlSalesUpdate.ToString(), dapperParamSalesUpdate); _salesDapperRepository.Find(sqlQuerySalesUpdate); return(1); } #endregion return(1); }
/// <summary> /// 呈现某个功能模块 /// </summary> /// <param name="userContext"></param> /// <param name="modulesId"></param> /// <returns></returns> public int ShowAccountModule(UserContext userContext, int modulesId) { //安装失败 int result = 0; var accountBusiness = _accountBusinessDapperRepository.Find(x => x.accountid == userContext.AccId); var module = _moduleDapperRepository.Find(x => x.Id == modulesId); //免费用户 if (accountBusiness.aotjb == 0 || accountBusiness.aotjb == 1) { if (module != null && module.Enable == 1 && module.IsPaid == 1) { //付费功能,无法安装 result = -2; } else { //可以安装 result = 1; } } else { //可以安装 result = 1; } if (result == 1) { var userModules = _moduleUserDapperRepository.FindAll(x => x.Enable == 1 && x.AccountId == userContext.AccId && x.AccountUserId == userContext.UserId); if (userModules.Count() >= 8) { //安装超过8个模块 result = -1; } else { var userModuleExist = _moduleUserDapperRepository.Find(x => x.ModuleId == modulesId && x.AccountId == userContext.AccId && x.AccountUserId == userContext.UserId); if (userModuleExist == null) { var userModuleInsert = new Entity.Model.Modules.AccountUserModule(); userModuleInsert.AccountId = userContext.AccId; userModuleInsert.AccountUserId = userContext.UserId; userModuleInsert.ModuleId = modulesId; userModuleInsert.Enable = 1; userModuleInsert.CreateTime = DateTime.Now; userModuleInsert.UpdateTime = DateTime.Now; _moduleUserDapperRepository.Insert(userModuleInsert); userModuleExist = _moduleUserDapperRepository.Find(x => x.ModuleId == modulesId && x.AccountId == userContext.AccId && x.AccountUserId == userContext.UserId); } var userModule = new Entity.Model.Modules.AccountUserModule { Id = userModuleExist.Id, Enable = 1, }; bool flag = _moduleUserDapperRepository.Update <Entity.Model.Modules.AccountUserModule>(userModule, item => new { item.Enable }); result = flag ? 1 : 0; } } return(result); }
/// <summary> /// 获取支出记录列表 /// </summary> /// <returns></returns> public ResponseModel GetExpenses(UserContext userContext, ExpensesSearchParam param) { //1.获取筛选的条件 if (param.CurrentPage == null || param.CurrentPage < 1) { param.CurrentPage = 1; } if (param.PageSize == null || param.PageSize < 1) { param.PageSize = 25; } var result = new ExpensesSearchResult(); var mainCategoryName = string.Empty; var subCategoryName = string.Empty; var strSql = new StringBuilder(); var sqlWhereBuilder = new StringBuilder(); var tRowBuilder = new StringBuilder(); sqlWhereBuilder.Append(" WHERE t_PayRecord.ShopperId= @ShopperId"); //日期过滤 if (param.StartDate != null && param.EndDate != null && param.StartDate <= param.EndDate) { sqlWhereBuilder.Append(" and t_PayRecord.PayDate >=@StartDate and t_PayRecord.PayDate <=@EndDate "); } //支出人员过滤 if (param.Staff != null && param.Staff > 0) { sqlWhereBuilder.Append(" and t_PayRecord.InsertUserId =@InsertUserId "); } //支出大分类过滤 if (param.MainCategoryId != null) { var mainCategory = _expensesCategoryRepository.Find(x => x.Id == param.MainCategoryId); if (mainCategory != null) { mainCategoryName = mainCategory.Name; sqlWhereBuilder.Append(" and t_PayRecord.PayMaxType =@PayMaxType "); } } //支出小分类过滤 if (param.SubCategoryId != null) { var subCategory = _expensesCategoryRepository.Find(x => x.Id == param.SubCategoryId); if (subCategory != null) { subCategoryName = subCategory.Name; sqlWhereBuilder.Append(" and t_PayRecord.PayMinType =@PayMinType "); } } //筛选项 tRowBuilder.Append(" SELECT ROW_NUMBER() OVER ( "); tRowBuilder.Append(" ORDER BY t_PayRecord.ID DESC "); tRowBuilder.Append(" ) AS rownumber "); tRowBuilder.Append( " ,*,PaySum as Amount,PayMaxType as MainCategoryName,PayName as Notes,PayMinType as SubCategoryName,ShopperId as MerchanId,insertUserName as UserName"); tRowBuilder.Append(" FROM t_PayRecord "); tRowBuilder.Append(sqlWhereBuilder); //分页查询 strSql.Append(" SELECT *"); strSql.Append(" FROM ("); strSql.Append(tRowBuilder); strSql.Append(" ) AS T"); strSql.Append(" WHERE RowNumber BETWEEN (@PageIndex-1)*@PageSize+1 "); strSql.Append(" AND @PageSize*@PageIndex ;"); //统计支出总金额 strSql.Append(" SELECT @TotalMoney= ISNULL(SUM(T.PaySum),0),@TotalNum=COUNT(1) from ( "); strSql.Append(tRowBuilder); strSql.Append(" ) AS T"); var sqlParams = new { ShopperId = userContext.AccId, param.StartDate, param.EndDate, InsertUserId = param.Staff, PayMaxType = mainCategoryName, PayMinType = subCategoryName, param.PageSize, PageIndex = param.CurrentPage }; var dapperParam = new DynamicParameters(sqlParams); dapperParam.Add("TotalMoney", dbType: DbType.Decimal, direction: ParameterDirection.Output, precision: 10, scale: 2); dapperParam.Add("TotalNum", dbType: DbType.Int32, direction: ParameterDirection.Output); var sqlQuery = new SqlQuery(strSql.ToString(), dapperParam); result.Items = _expensesRepository.FindAll(sqlQuery); result.CurrentPage = param.CurrentPage ?? 1; result.PageSize = param.PageSize ?? 25; result.TotalExpensesAmount = dapperParam.Get <decimal>("TotalMoney"); result.TotalSize = dapperParam.Get <int>("TotalNum"); result.TotalPage = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(result.TotalSize) / Convert.ToDecimal(result.PageSize))); //2.返回查询结果 return(new ResponseModel { Code = result.Items.Any() ? (int)ErrorCodeEnum.Success : (int)ErrorCodeEnum.NotFound, Data = result }); }
/// <summary> /// 根据Token和Appkey获取用户的相关信息 /// </summary> /// <param name="token"></param> /// <param name="appKey"></param> /// <param name="userId"></param> /// <returns></returns> public UserContext GetUserContext(string token, string appKey, string userId) { var redisCacheService = new RedisCacheService(); var expireDate = DateTime.Now.AddHours(-30); var intUserId = 0; if (string.IsNullOrWhiteSpace(token)) { throw new ArgumentNullException("token cannot be null"); } //if (!int.TryParse(userId, out intUserId)) //{ // throw new ArgumentException("userId is not valid"); //} var tokenRedisKey = string.IsNullOrWhiteSpace(appKey) ? RedisConsts.WebUserTokenKey + userId : RedisConsts.AppUserTokenKey + userId; var tokenResult = redisCacheService.Get <UserContext>(tokenRedisKey); if (tokenResult != null) { if (CheckSearchToken(token, tokenResult)) { return(null); } _logger.Debug(string.Format("Get app user context from redis cache. {0},{1},{2} ", token, appKey, tokenRedisKey)); return(tokenResult); } _webTokenRepository.Find( t => t.Token == token && t.CreateTime > expireDate && t.CreateTime < DateTime.Now); var retToken = string.IsNullOrWhiteSpace(appKey) ? _webTokenRepository.Find( t => t.Token == token && t.CreateTime > expireDate && t.CreateTime < DateTime.Now, null, t => t.CreateTime, OrderDirection.DESC) : _apiTokenRepository.Find( t => t.Token == token && t.CreateTime > expireDate && t.CreateTime < DateTime.Now, null, t => t.CreateTime, OrderDirection.DESC); if (retToken == null) { return(null); } if (retToken.Token != token) { throw new YuanbeiHttpRequestException((int)ErrorCodeEnum.TokenIsExpired, "token不正确"); } var strSql = new StringBuilder(); strSql.Append( "SELECT m.accountid AS AccId,m.id AS UserId,m.name AS OperaterName,m.grade AS Grade,UserPower AS UserPower, "); strSql.Append( "n.max_shop AS masterId ,m.PhoneNumber AS PhoneNumber FROM dbo.T_Account_User m left JOIN dbo.T_Account n ON "); strSql.Append("m.accountid =n.ID WHERE m.accountid=@accountId AND m.id=@userId "); var sqlParams = new { accountId = retToken.AccId, userId = retToken.UserId }; var dapperParam = new DynamicParameters(sqlParams); var sqlQuery = new SqlQuery(strSql.ToString(), dapperParam); var accountUser = _accoutUserRepository.Find(sqlQuery); if (accountUser == null) { throw new YuanbeiHttpRequestException((int)ErrorCodeEnum.TokenIsExpired, "没有找到用户相关信息"); } return(new UserContext { AccId = retToken.AccId, MasterId = accountUser.MasterId, UserId = retToken.UserId, PhoneNumber = accountUser.PhoneNumber, CompanyName = accountUser.CompanyName, OperaterName = retToken.UserName, Token = retToken.Token, AppKey = retToken.AppKey, Role = accountUser.Grade == AccountUserGradeConsts.Administrator ? 1 : 0, Powers = accountUser.UserPower }); }
public TEntity Find(Expression <Func <TEntity, bool> > expression) { return(ExecuteWithTryCatch(() => _internalRepository.Find(expression))); }
/// <summary> /// 获取商品详情从DB(针对移动端) /// </summary> /// <param name="goodsId"></param> /// <returns></returns> private MaterialGoodsInfo GetMaterialGoodsDb(int goodsId) { MaterialGoodsInfo entity = Mapper.Map <T_MaterialGoods2, MaterialGoodsInfo>(_materialGoods.Find(x => x.GoodsId == goodsId)); var listPic = _materalgoodspic.FindAll(x => x.GoodsId == goodsId); var materialGoodsPics = listPic as IList <T_MaterialGoodsPic> ?? listPic.ToList(); if (listPic != null && materialGoodsPics.Any()) { entity.CoverImage = new List <T_MaterialGoodsPic>( materialGoodsPics .Where(c => c.Type == (int)MaterialGoodsPicTypeEnum.CoverImage && c.Status == 0) .OrderBy(c => c.RankNo)); //TODO:移动端特殊处理 entity.Description = new List <T_MaterialGoodsPic>( materialGoodsPics .Where(c => c.Type == (int)MaterialGoodsPicTypeEnum.MobileDescription && c.Status == 0) .OrderBy(c => c.RankNo)); entity.HeadThumb = new List <T_MaterialGoodsPic>( materialGoodsPics .Where(c => c.Type == (int)MaterialGoodsPicTypeEnum.HeadThumb && c.Status == 0) .OrderBy(c => c.RankNo)); } return(entity); }