コード例 #1
0
        public void AgreePay(ProjectDemand projectDemand)
        {
            var     projectBidding = projectDemand.ProjectBidding;
            var     developer      = projectBidding.Developer;
            var     account        = projectDemand.Account;
            decimal payMoney       = 0;

            if (!projectDemand.HasPaid)
            {
                if (projectDemand.Price > 0)//雇主标价
                {
                    _developerPointsLogService.AddPoint(developer, projectDemand.Price, "{0}任务支付".With(projectDemand.Title));
                    Haspaid(projectDemand);
                    payMoney = projectDemand.Price;
                }
                else
                {
                    if (projectBidding.Price < SiteConfig.PROJECTDMANDDEPOSIT)//开发者竞价小于雇主押金
                    {
                        _pointsLogService.ChangePoint(account, SiteConfig.PROJECTDMANDDEPOSIT - projectBidding.Price, "{0}任务多余押金返还".With(projectDemand.Title));
                        _developerPointsLogService.AddPoint(developer, projectBidding.Price, "{0}任务支付".With(projectDemand.Title));

                        Haspaid(projectDemand);
                    }
                    else//开发者竞价大于雇主押金,需判断用户剩余积分是否足够支付
                    {
                        if (projectBidding.Price - SiteConfig.PROJECTDMANDDEPOSIT < account.Points)
                        {
                            _pointsLogService.ChangePoint(account, SiteConfig.PROJECTDMANDDEPOSIT - projectBidding.Price, "{0}任务超出押金部分支付给开发者".With(projectDemand.Title));
                            _developerPointsLogService.AddPoint(developer, projectBidding.Price, "{0}任务支付".With(projectDemand.Title));

                            Haspaid(projectDemand);
                        }
                        else
                        {
                            throw new Exception("您的积分不足够支付开发者,请充值积分{0}".With(projectBidding.Price - SiteConfig.PROJECTDMANDDEPOSIT));
                        }
                    }
                    payMoney = projectBidding.Price;
                }
            }
            else
            {
                throw new Exception("您已经成功支付给开发者,请勿刷新页面避免重复支付!");
            }

            var projectPayLog = _projectPayLogService.GetObject(z => z.ProjectDemandId == projectDemand.Id);

            if (projectPayLog != null)
            {
                projectPayLog.Type         = (int)ProjectPay_Type.已支付给开发者;
                projectPayLog.CompleteTime = DateTime.Now;
                _projectPayLogService.SaveObject(projectPayLog);
            }
            SuccessDemand(projectDemand, account);
            //发送邮件提醒开发者雇主已付款
            SendEmail sendEmail     = new SendEmail(SendEmailType.ProjectDemandAgreePay);
            var       sendEmailPara = new SendEmailParameter_ProjectDemandAgreePay(developer.Account.Email, developer.Account.UserName,
                                                                                   payMoney,
                                                                                   projectDemand.Title);

            sendEmail.Send(sendEmailPara, true);

            //发送站内信
            _messageBoxService.SendMessage(sendEmail.SentSubject, sendEmail.SentBody, developer.Id);
        }