public void SaveEntity(int?keyValue, dm_accountdetailEntity entity)
 {
     try
     {
         if (keyValue > 0)
         {
             entity.Modify(keyValue);
             BaseRepository("dm_data").Update(entity);
         }
         else
         {
             entity.Create();
             BaseRepository("dm_data").Insert(entity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowServiceException(ex);
     }
 }
Exemple #2
0
        public void ReceiveAwards(int user_id, int?task_id)
        {
            IRepository db = null;

            try
            {
                #region 获取任务记录
                dm_task_person_settingEntity dm_Task_Person_SettingEntity = GetEntity(task_id);
                #endregion
                if (dm_Task_Person_SettingEntity.s_type == 1)
                {
                    dm_UserService.SignIn(user_id);
                }
                else
                {
                    dm_userEntity dm_UserEntity = dm_UserService.GetEntityByCache(user_id);

                    if (dm_Task_Person_SettingEntity.s_type == 4)
                    {
                        dm_user_relationEntity dm_User_RelationEntity = dm_UserRelationService.GetEntityByUserID(user_id);
                        if (dm_User_RelationEntity.ordercount < dm_Task_Person_SettingEntity.needcount)
                        {
                            throw new Exception("请完成购物任务后再来领取!");
                        }
                    }
                    else if (dm_Task_Person_SettingEntity.s_type == 2)
                    {
                        if (dm_UserEntity.mychildcount < dm_Task_Person_SettingEntity.needcount)
                        {
                            throw new Exception("请完成邀请任务后再来领取!");
                        }
                    }

                    dm_task_person_recordEntity dm_Task_Person_RecordEntity = dm_Task_Person_RecordService.GetMyPersonRecord(user_id, task_id);
                    if (dm_Task_Person_RecordEntity.IsEmpty())
                    {
                        #region 增加任务领取记录
                        dm_Task_Person_RecordEntity            = new dm_task_person_recordEntity();
                        dm_Task_Person_RecordEntity.user_id    = user_id;
                        dm_Task_Person_RecordEntity.task_id    = task_id;
                        dm_Task_Person_RecordEntity.createtime = DateTime.Now;
                        dm_Task_Person_RecordEntity.status     = 1;
                        #endregion


                        db = BaseRepository("dm_data").BeginTrans();
                        //积分任务
                        if (dm_Task_Person_SettingEntity.rewardtype == 0)
                        {
                            #region 增加积分变更明细
                            int stepvalue = int.Parse(dm_Task_Person_SettingEntity.rewardcount.ToString());//积分无小数
                            dm_intergraldetailEntity dm_IntergraldetailEntity = new dm_intergraldetailEntity();
                            dm_IntergraldetailEntity.type         = 4;
                            dm_IntergraldetailEntity.profitLoss   = 1;
                            dm_IntergraldetailEntity.user_id      = user_id;
                            dm_IntergraldetailEntity.createtime   = DateTime.Now;
                            dm_IntergraldetailEntity.currentvalue = dm_UserEntity.integral + stepvalue;
                            dm_IntergraldetailEntity.stepvalue    = stepvalue;
                            dm_IntergraldetailEntity.title        = dm_Task_Person_SettingEntity.title;
                            dm_IntergraldetailEntity.remark       = dm_Task_Person_SettingEntity.remark;
                            dm_IntergraldetailEntity.Create();

                            dm_UserEntity.integral = dm_IntergraldetailEntity.currentvalue;
                            #endregion
                            db.Insert(dm_UserEntity);
                        }
                        else
                        { //余额任务
                            #region 增加余额变更明细
                            dm_accountdetailEntity dm_AccountdetailEntity = new dm_accountdetailEntity();
                            dm_AccountdetailEntity.user_id      = user_id;
                            dm_AccountdetailEntity.type         = 10;
                            dm_AccountdetailEntity.profitLoss   = CommonHelper.GetProfitLoss(10);
                            dm_AccountdetailEntity.createtime   = DateTime.Now;
                            dm_AccountdetailEntity.currentvalue = dm_UserEntity.accountprice + dm_Task_Person_SettingEntity.rewardcount;
                            dm_AccountdetailEntity.stepvalue    = dm_Task_Person_SettingEntity.rewardcount;
                            dm_AccountdetailEntity.title        = dm_Task_Person_SettingEntity.title;
                            dm_AccountdetailEntity.remark       = dm_Task_Person_SettingEntity.remark;
                            dm_AccountdetailEntity.Create();
                            #endregion

                            dm_UserEntity.accountprice = dm_AccountdetailEntity.currentvalue;
                            db.Insert(dm_AccountdetailEntity);
                        }

                        dm_UserEntity.Modify(user_id);
                        db.Update(dm_UserEntity);
                        db.Insert(dm_Task_Person_RecordEntity);

                        db.Commit();
                    }
                    else
                    {
                        throw new Exception("该任务已领取!");
                    }
                }
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }