Пример #1
0
        /// <summary>
        /// 删除充值码设置项
        /// </summary>
        /// <param name="entity">业务实体</param>
        public void RechargeSetDelete(RechargeSet entity)
        {
            int used = RechargeCodeOfCount(entity.Org_ID, entity.Rs_ID, true, true);

            if (used > 0)
            {
                throw new Exception("当前设置项中涉及的充值码已经存在消费记录,不能删除!可以选择禁用。");
            }
            using (DbTrans tran = Gateway.Default.BeginTrans())
            {
                try
                {
                    tran.Delete <RechargeSet>(entity);
                    tran.Delete <RechargeCode>(RechargeCode._.Rs_ID == entity.Rs_ID);

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
                finally
                {
                    tran.Close();
                }
            }
        }
Пример #2
0
 /// <summary>
 /// 生成充值码
 /// </summary>
 /// <param name="setEntity"></param>
 private void _RechargeCodeBuilds(RechargeSet setEntity, int count)
 {
     for (int i = 0; i < count; i++)
     {
         Song.Entities.RechargeCode code = new RechargeCode();
         //面额
         code.Rc_Price = setEntity.Rs_Price;
         //是否启用
         code.Rc_IsEnable = true;
         //创建时间
         code.Rc_CrtTime = DateTime.Now;
         //类型
         code.Rc_Type = 0;
         //设置项id
         code.Rs_ID = setEntity.Rs_ID;
         //机构id
         code.Org_ID = setEntity.Org_ID;
         //时间效
         code.Rc_LimitStart = setEntity.Rs_LimitStart;
         code.Rc_LimitEnd   = setEntity.Rs_LimitEnd;
         //卡值码与其密码
         code.Rc_Code = _RechargeCodeBuildCoder(setEntity.Rs_Pw, i, setEntity.Rs_CodeLength);
         code.Rc_Pw   = _RechargeCodeBuildPw(i, setEntity.Rs_PwLength);
         Gateway.Default.Save <RechargeCode>(code);
     }
 }
Пример #3
0
        /// <summary>
        /// 使用该充值码
        /// </summary>
        /// <param name="entity"></param>
        public void CouponUseCode(RechargeCode entity)
        {
            //是否被禁用
            Song.Entities.RechargeSet set = Gateway.Default.From <RechargeSet>().Where(RechargeSet._.Rs_ID == entity.Rs_ID).ToFirst <RechargeSet>();
            if (set == null || set.Rs_IsEnable == false)
            {
                throw new Exception("该充值码已经被禁用");
            }
            //是否过期
            if (!(DateTime.Now > entity.Rc_LimitStart && DateTime.Now < entity.Rc_LimitEnd.Date.AddDays(1)))
            {
                throw new Exception("该充值码已经过期");
            }
            //标注已经使用
            entity.Rc_IsUsed   = true;
            entity.Rc_UsedTime = DateTime.Now;
            //产生流水
            CouponAccount ca = new CouponAccount();

            ca.Ca_Value  = entity.Rc_Price;
            ca.Ac_ID     = entity.Ac_ID;
            ca.Ca_From   = 2;
            ca.Rc_Code   = entity.Rc_Code + "-" + entity.Rc_Pw;
            ca.Ca_Source = "充值码充值";
            using (DbTrans tran = Gateway.Default.BeginTrans())
            {
                try
                {
                    Business.Do <IAccounts>().CouponAdd(ca);
                    tran.Save <RechargeCode>(entity);
                    RechargeSet setEnity = tran.From <RechargeSet>().Where(RechargeSet._.Rs_ID == entity.Rs_ID).ToFirst <RechargeSet>();
                    if (setEnity != null)
                    {
                        setEnity.Rs_UsedCount++;
                        tran.Save <RechargeSet>(setEnity);
                    }
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
                finally
                {
                    tran.Close();
                }
            }
        }
Пример #4
0
 /// <summary>
 /// 修改充值码设置项
 /// </summary>
 /// <param name="entity">业务实体</param>
 public void RechargeSetSave(RechargeSet entity)
 {
     using (DbTrans tran = Gateway.Default.BeginTrans())
     {
         try
         {
             Song.Entities.RechargeSet rs = tran.From <RechargeSet>().Where(RechargeSet._.Rs_ID == entity.Rs_ID).ToFirst <RechargeSet>();
             //如果新增了充值码
             if (rs.Rs_Count < entity.Rs_Count)
             {
                 _RechargeCodeBuilds(entity, entity.Rs_Count - rs.Rs_Count);
             }
             //如果减少的充值码
             if (rs.Rs_Count > entity.Rs_Count)
             {
                 Song.Entities.RechargeCode[] rcs = tran.From <RechargeCode>().Where(RechargeCode._.Rs_ID == entity.Rs_ID && RechargeCode._.Rc_IsUsed == false).ToArray <RechargeCode>(rs.Rs_Count - entity.Rs_Count);
                 foreach (RechargeCode r in rcs)
                 {
                     tran.Delete <RechargeCode>(r);
                 }
             }
             tran.Update <RechargeCode>(new Field[] { RechargeCode._.Rc_Price, RechargeCode._.Rc_LimitStart, RechargeCode._.Rc_LimitEnd },
                                        new object[] { entity.Rs_Price, entity.Rs_LimitStart, entity.Rs_LimitEnd },
                                        RechargeCode._.Rs_ID == entity.Rs_ID && RechargeCode._.Rc_IsUsed == false);
             tran.Save <RechargeSet>(entity);
             tran.Commit();
         }
         catch (Exception ex)
         {
             tran.Rollback();
             throw ex;
         }
         finally
         {
             tran.Close();
         }
     }
 }
Пример #5
0
 /// <summary>
 /// 添加充值码设置项
 /// </summary>
 /// <param name="entity">业务实体</param>
 public void RechargeSetAdd(RechargeSet entity)
 {
     entity.Rs_CrtTime = DateTime.Now;
     Gateway.Default.Save <RechargeSet>(entity);
     _RechargeCodeBuilds(entity, entity.Rs_Count);
 }
Пример #6
0
        /// <summary>
        /// 删除,按主键ID;
        /// </summary>
        /// <param name="identify">实体的主键</param>
        public void RechargeSetDelete(int identify)
        {
            RechargeSet set = RechargeSetSingle(identify);

            RechargeSetDelete(set);
        }