Example #1
0
 public OtcIntegralDay()
 {
     db = new MongoHelper <OtcIntegralDay>();
     if (db._mongoCollection.Count() == 0)
     {
         for (int i = 0; i < 7; i++)
         {
             OtcIntegralDay model = new OtcIntegralDay("");
             model.id       = i.ToString();
             model.multiple = 1;
             model.state    = true;
             db._mongoCollection.Insert(model);
         }
     }
 }
        /// <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;
                }
            }
        }