/// <summary> /// 账户花销(包含写帐户日志) /// </summary> /// <param name="orderId"></param> /// <returns></returns> public bool AccountExpend(decimal orderId,string ip) { Bll.Order.TOrderBLL obll = new TMM.Service.Bll.Order.TOrderBLL(); Bll.Order.AccountLogBLL albll = new TMM.Service.Bll.Order.AccountLogBLL(); TOrder o = obll.Get(orderId); MAccount acc = GetByUserId(o.UserId); if (acc.Amount >= o.Total) { AccountLog accLog = new AccountLog() { UserId = o.UserId, OrderId = o.OrderId, Amount = -o.Total, AccountWay = (int)AmountWay.Out, Ip = ip }; albll.Insert(accLog); acc.Amount = acc.Amount - o.Total; return Update(acc); } return false; }
public void DoExchange(decimal orderId) { OrderService os = Context.GetService<OrderService>(); TOrder o = os.TOrderBll.Get(orderId); o.Status = (int)OrderStatus.AdminDoExchange; o.UpdateTime = DateTime.Now; os.TOrderBll.Update(o); //写账户日志 AccountLog accLog = new AccountLog() { AccountWay = (int)AmountWay.EOut, Amount = -o.Total, CreateTime = DateTime.Now, Ip = Utils.TmmUtils.IPAddress(), OrderId = o.OrderId, UserId = o.UserId, PayWay = 0, AdminRemark = "兑换" }; os.MAccountLogBll.Insert(accLog); //更新账户信息 MAccount acc = os.MAccountBll.GetByUserId(o.UserId); acc.FrozenAmount -= o.Total; acc.TotalExchange += o.Total; acc.UpdateTime = DateTime.Now; os.MAccountBll.Update(acc); //发系统消息 M_Message msg = new M_Message() { SenderId = Helper.ConfigHelper.AdminUserId, RecieverId = o.UserId, CreateTime = DateTime.Now, IsRead = false, Mtype = (int)Model.Enums.MessageType.Inform, Title = "您的兑换申请已经被受理", Content = string.Format("您的兑换申请已被管理员受理,请注意查收您的{0}账号",o.Remark == "1" ? "支付宝" : "银行") }; Service.Bll.User.M_MessageBLL msgBll = new TMM.Service.Bll.User.M_MessageBLL(); msgBll.Insert(msg); base.SuccessInfo(); RedirectToReferrer(); }
public void DoManualOperate(int userId, int accountWay, decimal amount, string remark) { try { UserService us = Context.GetService<UserService>(); if (amount == 0) throw new TmmException("金额不能为0"); if (accountWay == 0) throw new TmmException("请选择类型"); if (accountWay == (int)AmountWay.MIn) { if (amount <= 0) throw new TmmException("增加金额不能小于0"); } if (accountWay == (int)AmountWay.AOut) { if (amount >= 0) throw new TmmException("扣除金额不能大于0"); } if (string.IsNullOrEmpty(remark)) throw new TmmException("备注不能为空"); MAccount acc = us.MAccountBll.GetByUserId(userId); //写账户日志 AccountLog log = new AccountLog() { AccountWay = accountWay, AdminRemark = remark, Amount = amount, CreateTime = DateTime.Now, Ip = Utils.TmmUtils.IPAddress(), UserId = userId }; us.AccountLogBll.Insert(log); acc.Amount += amount; us.MAccountBll.Update(acc); //发消息-异步 M_Message msg = new M_Message() { Content = string.Format("【帐户通知】,您的账户由土木迷管理员{0}¥{1:F2}", amount > 0 ? "充入" : "扣除", amount), CreateTime = DateTime.Now, IsRead = false, Mtype = (int)Model.Enums.MessageType.Inform, RecieverId = userId, SenderId = Core.Helper.ConfigHelper.AdminUserId, Title = "帐户通知" }; Queue<M_Message> queueMsg = new Queue<M_Message>(); queueMsg.Enqueue(msg); Common.AsynMessage am = new AsynMessage(queueMsg); am.Send(); base.SuccessInfo(); Redirect("account.do"); return; } catch (TmmException te) { AddError(te.Message); Flash["accountWay"] = accountWay; Flash["amount"] = amount; Flash["remark"] = remark; } RedirectToReferrer(); }
/// <summary> /// 更新数据 /// </summary> /// <param name="obj"></param> /// <returns>返回:ture 成功,false 失败</returns> public bool Update(AccountLog obj) { return dal.Update(obj); }
/// <summary> /// 插入数据 /// </summary> /// <param name="obj">对象</param> /// <returns>返回:该条数据的主键Id</returns> public int Insert(AccountLog obj) { obj.CreateTime = DateTime.Now; return dal.Insert(obj); }
/// <summary> /// 插入数据 /// </summary> /// <param name="obj">对象</param> /// <returns>返回:该条数据的主键Id</returns> public int Insert(AccountLog obj) { if (obj == null) throw new ArgumentNullException("obj"); String stmtId = "AccountLog.Insert"; return SqlMapper.Instance().QueryForObject<int>(stmtId, obj); }
/// <summary> /// 更新数据 /// </summary> /// <param name="obj"></param> /// <returns>返回:ture 成功,false 失败</returns> public bool Update(AccountLog obj) { if (obj == null) throw new ArgumentNullException("obj"); String stmtId = "AccountLog.Update"; int result = SqlMapper.Instance().QueryForObject<int>(stmtId, obj); return result > 0 ? true : false; }
/// <summary> /// 支付成功后给上传人返利 /// </summary> protected void AddAmountForUploader( decimal orderId,int uploaderId,decimal amount, OrderService os,int docId,string docTitle,int buyerId,int payway) { //先写入账户日志 AccountLog al = new AccountLog() { OrderId = orderId, UserId = uploaderId, Amount = amount, AccountWay = (int)AmountWay.INCOME, Ip = Utils.TmmUtils.IPAddress(), PayWay = payway }; int a = os.MAccountLogBll.Insert(al); //账户增加收入 if (a > 0) { os.MAccountBll.AddAmount(uploaderId, amount); } //发送系统通知 string tmp = "您的文档<a href='/p-{0}.html' target='_blank'>{1}</a>" + "被<a href='/home/{2}.html' target='_blank'>{3}</a>下载,获得收入¥{4}"; M_Message msg = new M_Message() { SenderId = Helper.ConfigHelper.AdminUserId, Title = "恭喜您获得文档销售收入", CreateTime = DateTime.Now, Content = string.Format(tmp,docId,docTitle,buyerId,Helper.UserHelper.GetUserById(buyerId).TmmDispName,amount), IsRead = false, Mtype = (int)Model.Enums.MessageType.Inform, RecieverId = uploaderId }; Service.Bll.User.M_MessageBLL mbll = new TMM.Service.Bll.User.M_MessageBLL(); mbll.Insert(msg); }
/// <summary> /// 帐户花销 for 购买悬赏文档(包含写帐户日志) /// </summary> /// <param name="userId"></param> /// <param name="total"></param> /// <param name="ip"></param> /// <returns></returns> public bool AccountExpend(int userId, decimal total, string ip,string remark) { Bll.Order.AccountLogBLL albll = new TMM.Service.Bll.Order.AccountLogBLL(); MAccount acc = GetByUserId(userId); if (acc.Amount >= total) { AccountLog accLog = new AccountLog() { UserId = userId, Amount = -total, AccountWay = (int)AmountWay.ROut, Ip = ip, PayWay = 0, AdminRemark = remark }; albll.Insert(accLog); acc.Amount = acc.Amount - total; return Update(acc); } return false; }
/// <summary> /// 帐户充值 for 投稿收入(包含写帐户日志) /// </summary> /// <param name="userId">投稿人</param> /// <param name="amount"></param> /// <param name="ip"></param> /// <param name="payway"></param> /// <param name="remark">将悬赏文档的名称写入备注</param> /// <returns></returns> public bool AddAmount(int userId, decimal amount, string ip,string remark) { Bll.Order.AccountLogBLL albll = new TMM.Service.Bll.Order.AccountLogBLL(); //写账户日志 AccountLog accLog = new AccountLog() { UserId = userId, Amount = amount, AccountWay = (int)AmountWay.INCOME_TG, Ip = ip, PayWay = 0, AdminRemark = remark }; albll.Insert(accLog); //更新账户 MAccount acc = GetByUserId(userId); acc.Amount = acc.Amount + amount; return Update(acc); }
/// <summary> /// 账户充值 for 订单 /// </summary> /// <param name="orderId">订单ID</param> /// <param name="amount">金额</param> public bool AddAmount(decimal orderId, decimal amount,string ip,int payway) { Bll.Order.TOrderBLL obll = new TMM.Service.Bll.Order.TOrderBLL(); Bll.Order.AccountLogBLL albll = new TMM.Service.Bll.Order.AccountLogBLL(); TOrder o = obll.Get(orderId); //写账户日志 AccountLog accLog = new AccountLog() { UserId = o.UserId, OrderId = o.OrderId, Amount = amount, AccountWay = (int)AmountWay.In, Ip = ip, PayWay = payway }; albll.Insert(accLog); //更新账户 MAccount acc = GetByUserId(o.UserId); acc.Amount = acc.Amount + amount; return Update(acc); }