Exemplo n.º 1
0
        public dm_task_reviceEntity CancelByRevicePerson(int revice_id, int IsPubCancel = 0)
        {
            IRepository db = null;

            try
            {
                /* 取消任务
                 * 1、更改接受任务表的任务状态
                 * 2、修改任务主表的接单人数
                 * 3、向任务发布人增加取消任务通知
                 */
                dm_task_reviceEntity dm_Task_ReviceEntity = GetEntity(revice_id);
                #region 更改接受任务表状态
                if (dm_Task_ReviceEntity.IsEmpty())
                {
                    throw new Exception("接受任务记录异常!");
                }
                if (dm_Task_ReviceEntity.status == 2)
                {
                    throw new Exception("任务正在审核中,取消任务失败!");
                }
                if (dm_Task_ReviceEntity.status == 3)
                {
                    throw new Exception("任务已完成,取消任务失败!");
                }
                if (dm_Task_ReviceEntity.status == 4)
                {
                    throw new Exception("任务已取消,请勿重复提交!");
                }

                dm_taskEntity dm_TaskEntity = dm_TaskService.GetEntity(dm_Task_ReviceEntity.task_id);
                if (dm_TaskEntity.isactivity == 1)
                {
                    throw new Exception("活动任务不能取消哟!");
                }

                if (IsPubCancel == 1)
                {
                    DateTime diffTime = ((DateTime)dm_Task_ReviceEntity.revice_time).AddHours(dm_TaskEntity.task_time_limit);
                    if (DateTime.Now < diffTime)
                    {
                        throw new Exception("该用户提交资料未超过设定时间,无法取消任务,您可在" + diffTime.ToString("yyyy-MM-dd HH:mm:ss") + "重试操作!");
                    }
                }


                dm_Task_ReviceEntity.status     = 4;
                dm_Task_ReviceEntity.canceltime = DateTime.Now;
                dm_Task_ReviceEntity.Modify(dm_Task_ReviceEntity.id);
                #endregion

                #region 修改任务主表数据
                dm_TaskEntity.revicecount -= 1;
                dm_TaskEntity.Modify(dm_TaskEntity.id);
                #endregion

                #region 增加消息记录
                dm_messagerecordEntity dm_MessagerecordEntity = new dm_messagerecordEntity
                {
                    isread         = 0,
                    user_id        = dm_TaskEntity.user_id,
                    messagetitle   = "接单人取消",
                    messagecontent = "您发布的任务编号:" + dm_TaskEntity.task_no + "接单人已取消,请及时查看!",
                    messagetype    = 2,
                    createtime     = DateTime.Now
                };
                #endregion

                db = BaseRepository("dm_data").BeginTrans();
                db.Update(dm_Task_ReviceEntity);
                db.Update(dm_TaskEntity);
                db.Insert(dm_MessagerecordEntity);

                db.Commit();

                return(dm_Task_ReviceEntity);
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Exemplo n.º 2
0
        public dm_task_reviceEntity ReviceTask(dm_task_reviceEntity dm_Task_ReviceEntity, string appid)
        {
            lock (_object)
            {
                IRepository db = null;
                try
                {
                    dm_basesettingEntity dm_BasesettingEntity = dM_BaseSettingService.GetEntityByCache(appid);
                    if (dm_BasesettingEntity.IsEmpty())
                    {
                        throw new Exception("配置信息获取错误!");
                    }

                    dm_taskEntity dm_TaskEntity = dm_TaskService.GetEntity(dm_Task_ReviceEntity.task_id);
                    if (dm_TaskEntity.IsEmpty())
                    {
                        throw new Exception("任务id错误!");
                    }
                    if (dm_TaskEntity.task_status == -2)
                    {
                        throw new Exception("任务正在审核中,暂时无法接受!");
                    }
                    if (dm_TaskEntity.task_status == 1)
                    {
                        throw new Exception("您来晚了一步,当前任务已抢光!");
                    }
                    if (dm_TaskEntity.task_status == 2)
                    {
                        throw new Exception("当前任务已取消,您可接受其他任务!");
                    }
                    if (dm_TaskEntity.task_status == 3)
                    {
                        throw new Exception("当前任务已下架,您可接受其他任务!");
                    }

                    if (dm_TaskEntity.revicecount >= dm_TaskEntity.needcount)
                    {
                        throw new Exception("您来晚了一步,当前任务已抢光!");
                    }

                    /*一个任务可重复接受  2020-07-27*/
                    dm_task_reviceEntity reviceEntity = GetReviceEntity(dm_Task_ReviceEntity.user_id, dm_Task_ReviceEntity.task_id);
                    if (!reviceEntity.IsEmpty())
                    {
                        //throw new Exception("请勿重复接受该任务!");
                        throw new Exception("您已接受该任务,请勿重复接受!!");
                    }

                    dm_userEntity dm_UserEntity = dM_UserService.GetEntity(dm_Task_ReviceEntity.user_id);
                    if (dm_UserEntity.userlevel != 1 && dm_UserEntity.userlevel != 2)
                    {
                        throw new Exception("当前等级无法接受任务,请升级后重试!");
                    }

                    //判断当前未在审核状态的任务数量
                    int noFinishCount = BaseRepository("dm_data").IQueryable <dm_task_reviceEntity>(t => (t.status == 1 || t.status == 2) && t.user_id == dm_Task_ReviceEntity.user_id).Count();
                    if (noFinishCount >= dm_BasesettingEntity.revicetaskcountlimit)
                    {
                        throw new Exception("同时接单任务数已达到上限,请先完成其他任务后再来接单!");
                    }


                    dm_Task_ReviceEntity.revice_time = DateTime.Now;
                    dm_Task_ReviceEntity.status      = 1;
                    dm_Task_ReviceEntity.Create();

                    dm_TaskEntity.revicecount += 1;
                    dm_TaskEntity.Modify(dm_TaskEntity.id);

                    db = BaseRepository("dm_data").BeginTrans();
                    db.Update(dm_TaskEntity);
                    db.Insert(dm_Task_ReviceEntity);
                    db.Commit();

                    return(dm_Task_ReviceEntity);
                }
                catch (Exception ex)
                {
                    if (db != null)
                    {
                        db.Rollback();
                    }
                    if (ex is ExceptionEx)
                    {
                        throw;
                    }
                    else
                    {
                        throw ExceptionEx.ThrowServiceException(ex);
                    }
                }
            }
        }