/// <summary> /// 赠送积分 /// </summary> /// <param name="uid">会员ID</param> /// <param name="integral">积分</param> /// <param name="remarks">描述</param> /// <param name="isFanHuan">返回积分不更新积分表</param> public void PresentIntegral(int uid, int integral, string remarks, bool isFanHuan = false) { MemberIntegralTemplateEnum me = MemberIntegralTemplateEnum.赠送积分; MemberIntegralLock ml = new MemberIntegralLock(); if (!ml.isAllow(uid, me)) { return; } using (DbConnection conn = db.CreateConnection()) { conn.Open(); DbTransaction tran = conn.BeginTransaction(); try { //更新积分表 if (!isFanHuan) { string sql = string.Format(@"IF NOT EXISTS( SELECT * FROM dbo.MemberIntegral WHERE uid={0}) INSERT INTO MemberIntegral VALUES({0},{1},{1}) ELSE UPDATE MemberIntegral SET integral=integral+{1},realityIntegral=realityIntegral+{1} WHERE uid={0}", uid, integral); db.ExecuteNonQuery(db.GetSqlStringCommand(sql), tran); } SOSOshop.BLL.Integral.MemberIntegralDetail bll = new MemberIntegralDetail(); SOSOshop.Model.Integral.MemberIntegralDetail model = new Model.Integral.MemberIntegralDetail(); model.action = "增加"; model.created = DateTime.Now; model.integral = integral; model.remarks = remarks; model.uid = uid; bll.Add(model, tran); tran.Commit(); ml.created = (DateTime)model.created; ml.mte = me; ml.uid = uid; ml.insert(); } catch (Exception e) { tran.Rollback(); throw e; } } }
/// <summary> /// 增加积分 /// </summary> /// <param name="uid">会员ID</param> /// <param name="price">如果是订单则传入订单金额</param> /// <param name="me">模板类型</param> /// <param name="msg">如果是订单则传入订单号</param> public void AddIntegral(int uid, decimal price, MemberIntegralTemplateEnum me, string msg, string orderid = "") { string sql = ""; MemberIntegralLock ml = new MemberIntegralLock(); if (!ml.isAllow(uid, me)) { return; } decimal dc = 0; if (me == MemberIntegralTemplateEnum.成交订单) { // OTC sql = "SELECT CompanyClass FROM dbo.memberaccount WHERE UID=" + uid; string obj = ExecuteScalar(sql) as string; if (obj == null) { return; } var cc = SOSOshop.Model.CompanyClass.GetModel(obj); if (cc.Price == "Price_02") { DateTime time = (DateTime)ExecuteScalar(string.Format("SELECT ShopDate FROM dbo.Orders WHERE OrderId='{0}'", orderid)); OtcIntegralDay bll = new OtcIntegralDay(); var m = bll.GetList(((int)time.DayOfWeek).ToString()); if (m.Count > 0) { var model = m.First(); if (model.state) { dc = price * model.multiple; } } } else //批发 { dc = new MemberIntegralTemplate().GetIntegral(me); if (dc == 0) { return; } dc = price * dc; } } else { dc = new MemberIntegralTemplate().GetIntegral(me); } using (DbConnection conn = db.CreateConnection()) { conn.Open(); DbTransaction tran = conn.BeginTransaction(); try { //更新积分表 sql = string.Format(@"IF NOT EXISTS( SELECT * FROM dbo.MemberIntegral WHERE uid={0}) INSERT INTO MemberIntegral VALUES({0},{1},{1}) ELSE UPDATE MemberIntegral SET integral=integral+{1},realityIntegral=realityIntegral+{1} WHERE uid={0}", uid, (int)dc); db.ExecuteNonQuery(db.GetSqlStringCommand(sql), tran); SOSOshop.BLL.Integral.MemberIntegralDetail bll = new MemberIntegralDetail(); SOSOshop.Model.Integral.MemberIntegralDetail model = new Model.Integral.MemberIntegralDetail(); model.action = "增加"; model.created = DateTime.Now; model.integral = (int)dc; model.remarks = string.Format("{0}:{1}", me, msg); model.uid = uid; bll.Add(model, tran); tran.Commit(); ml.created = (DateTime)model.created; ml.mte = me; ml.uid = uid; ml.orderid = orderid; ml.insert(); } catch (Exception e) { tran.Rollback(); throw e; } } }