示例#1
0
        public void CancelByReleasePerson(int task_id)
        {
            IRepository db = null;

            try
            {
                DM_Task_ReviceService dm_Task_ReviceService = new DM_Task_ReviceService();

                IEnumerable <dm_task_reviceEntity> dm_Task_ReviceEntities = dm_Task_ReviceService.GetReviceListByTaskID(task_id);
                if (dm_Task_ReviceEntities.Where(t => t.status == 1).Count() > 0)
                {
                    throw new Exception("存在正在进行中的记录,当前任务无法取消!");
                }
                if (dm_Task_ReviceEntities.Where(t => t.status == 2).Count() > 0)
                {
                    throw new Exception("当前存在未审核的资料,任务无法取消,请审核之后重试!");
                }
                dm_taskEntity dm_TaskEntity = GetEntity(task_id);
                if (dm_TaskEntity.task_status == 2)
                {
                    throw new Exception("该任务已取消!");
                }
                if (dm_TaskEntity.task_status == 1 || dm_TaskEntity.finishcount == dm_TaskEntity.needcount)
                {
                    throw new Exception("该任务已完成!");
                }
                if (dm_TaskEntity.finishcount > dm_TaskEntity.needcount)
                {
                    throw new Exception("错误码:1001--任务存在异常记录,请联系管理员!");
                }

                //取消任务
                dm_TaskEntity.task_status = 2;
                dm_userEntity dm_UserEntity = dm_UserService.GetEntity(dm_TaskEntity.user_id);

                #region 存在两种退款  1、全部退  2部分退
                decimal caclePrice = 0;
                if (dm_TaskEntity.finishcount == 0)
                {//全部退
                    caclePrice = dm_TaskEntity.totalcommission;
                }
                else
                {//部分退
                    caclePrice = Math.Round((dm_TaskEntity.needcount - dm_TaskEntity.finishcount) * dm_TaskEntity.singlecommission, 2);
                }
                dm_UserEntity.accountprice += caclePrice;
                #endregion

                dm_accountdetailEntity dm_AccountdetailEntity = new dm_accountdetailEntity
                {
                    createtime   = DateTime.Now,
                    remark       = "取消发布任务" + dm_TaskEntity.task_no,
                    stepvalue    = caclePrice,
                    currentvalue = dm_UserEntity.accountprice,
                    title        = "取消发布任务",
                    type         = 13,
                    profitLoss   = CommonHelper.GetProfitLoss(13),
                    user_id      = dm_TaskEntity.user_id
                };

                db = BaseRepository("dm_data").BeginTrans();
                dm_UserEntity.Modify(dm_UserEntity.id);
                db.Update(dm_UserEntity);
                dm_TaskEntity.Modify(dm_TaskEntity.id);
                db.Update(dm_TaskEntity);
                db.Insert(dm_AccountdetailEntity);
                db.Commit();
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }

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