Пример #1
0
 /// <summary>
 /// 设置回答为最佳答案(金额)
 /// </summary>
 /// <param name="model">回答model</param>
 /// <param name="收益明细">收益明细model</param>
 /// <returns></returns>
 public async Task <bool> SetBestAnswerAllotMoneyAsync(FaqsAnswerModel model, DoctorEaringsDetailModel earingsDetailModel, DoctorBalanceModel balanceModel, FaqsQuestionModel questionModel, bool isNewBalanceModel)
 {
     return(await MySqlHelper.TransactionAsync(async (conn, trans) =>
     {
         if (isNewBalanceModel)
         {
             if (string.IsNullOrWhiteSpace(await conn.InsertAsync <string, DoctorBalanceModel>(balanceModel)))
             {
                 return false;
             }
         }
         else
         {
             if ((await conn.UpdateAsync(balanceModel)) < 1)
             {
                 return false;
             }
         }
         if (await conn.UpdateAsync(model) == 0)
         {
             return false;
         }
         if (await conn.UpdateAsync(questionModel) == 0)
         {
             return false;
         }
         if (string.IsNullOrWhiteSpace(await conn.InsertAsync <string, DoctorEaringsDetailModel>(earingsDetailModel)))
         {
             return false;
         }
         return true;
     }));
 }
Пример #2
0
        /// <summary>
        /// 更新model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <bool> UpdateAsync(FaqsAnswerModel model)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                var result = await conn.UpdateAsync(model);

                return(result > 0);
            }
        }
Пример #3
0
 /// <summary>
 /// 添加答案
 /// </summary>
 /// <returns></returns>
 public virtual async Task <bool> InsertAsync(FaqsAnswerModel entity, FaqsQuestionModel faqsQuestionModel)
 {
     return(await MySqlHelper.TransactionAsync(async (conn, trans) =>
     {
         await conn.InsertAsync <string, FaqsAnswerModel>(entity);
         await conn.UpdateAsync(faqsQuestionModel);
         return true;
     }));
 }
Пример #4
0
        public async Task <IActionResult> ReplyFaqsQuestionAsync([FromBody] ReplyFaqsQuestionRequestDto request)
        {
            var questionBiz = new FaqsQuestionBiz();
            var question    = await new FaqsQuestionBiz().GetModelAsync(request.QuestionGuid);

            if (question == null)
            {
                return(Failed(ErrorCode.Empty, "参数错误"));
            }
            var isExistAnswer = await questionBiz.GetIsAnswerExist(question.QuestionGuid, UserID);

            if (isExistAnswer)
            {
                return(Failed(ErrorCode.DataBaseError, "该问题已回答过,不能二次回答!"));
            }
            var model = new FaqsAnswerModel
            {
                CreatedBy       = UserID,
                Enable          = true,
                Content         = request.Content,
                AnswerGuid      = Guid.NewGuid().ToString("N"),
                LastUpdatedBy   = UserID,
                ReceiveType     = question.RewardType,
                MainAnswer      = false,
                OrgGuid         = string.Empty,
                QuestionGuid    = request.QuestionGuid,
                UserGuid        = UserID,
                RewardIntergral = 0
            };
            FaqsAnswerBiz faqsAnswerBiz = new FaqsAnswerBiz();

            lock (lockObject)
            {
                question.AnswerNum = (faqsAnswerBiz.GetTotalByQuestionIdAsync(question.QuestionGuid).Result + 1);
                var result = faqsAnswerBiz.InsertAsync(model, question).Result;
                return(Success());
            }
        }
Пример #5
0
        /// <summary>
        /// 设置回答为最佳答案(积分)
        /// </summary>
        /// <param name="model">回答model</param>
        /// <param name="scoreModel">积分model</param>
        /// <returns></returns>
        public async Task <bool> SetBestAnswerAsync(FaqsAnswerModel model, ScoreModel scoreModel, FaqsQuestionModel questionModel)
        {
            return(await MySqlHelper.TransactionAsync(async (conn, trans) =>
            {
                if (await conn.UpdateAsync(model) == 0)
                {
                    return false;
                }

                if (await conn.UpdateAsync(questionModel) == 0)
                {
                    return false;
                }

                if (string.IsNullOrWhiteSpace(await conn.InsertAsync <string, ScoreModel>(scoreModel)))
                {
                    return false;
                }


                return true;
            }));
        }
Пример #6
0
        /// <summary>
        /// 问答分配悬赏金额
        /// </summary>
        /// <param name="parentGuid"></param>
        /// <returns></returns>
        public async Task <int> FaqsAllotFeeAsync()
        {
            var qusetionModelList = await Get15DaysQuestionModelListAsync();

            int conpleteNum = 0;

            foreach (var item in qusetionModelList)
            {
                item.Status          = FaqsQuestionModel.QuestionStatusEnum.End.ToString();
                item.LastUpdatedDate = DateTime.Now;
                var answerList = await GetAnswerModelListByQuestionGuidAsync(item.QuestionGuid);

                if (answerList == null || answerList.Count < 1)
                {
                    //没有回答,金额退给用户,变更问题状态为过期
                    //获取流水,调用退款接口
                    var flowingModel = await new TransactionFlowingBiz().GetModelsById(item.TransferFlowingGuid);
                    var requestDto   = new Dtos.MallPay.FangDiInterface.DoRefundRequestDto
                    {
                        Reason     = "FAQS=>问题无回答,退款.",
                        Refund_Fee = Convert.ToInt32(flowingModel.Amount).ToString(),
                        Refund_No  = flowingModel.TransactionNumber,
                        Trade_No   = flowingModel?.OutTradeNo
                    };
                    var response = await new FangDiPayBiz().RefundAsync(requestDto);
                    if (response.ResultCode.Equals("0") && response.ResultMsg.ToLower().Equals("success"))
                    {
                        flowingModel.TransactionStatus = TransactionStatusEnum.RefundSuccess.ToString();
                        flowingModel.OutRefundNo       = response.Refund_No;
                        flowingModel.Update();
                        item.Update();
                    }
                    conpleteNum++;
                    continue;
                }
                int answerCount = answerList.Count;
                if (answerCount > 10)
                {
                    answerList = answerList.Take(10).ToList();
                }                                                                   //.OrderByDescending(a => a.LikeCount).OrderByDescending(a => a.CreationDate)
                decimal allotNum = 0;
                GetManthNumber(item.RewardIntergral, answerList.Count, ref allotNum);
                var balanceBiz = new DoctorBalanceBiz();
                if (answerList.Count < 11)
                {
                    var answerModelList        = new List <FaqsAnswerModel>();
                    var earingsDetailModelList = new List <DoctorEaringsDetailModel>();
                    var doctorBalanceModelList = new List <Dictionary <bool, DoctorBalanceModel> >();
                    foreach (var answerItem in answerList)
                    {
                        #region 更新Model
                        var newAnswerModel = new FaqsAnswerModel
                        {
                            AnswerGuid      = answerItem.AnswerGuid,
                            MainAnswer      = answerItem.MainAnswer,
                            Content         = answerItem.Content,
                            QuestionGuid    = answerItem.QuestionGuid,
                            UserGuid        = answerItem.UserGuid,
                            ReceiveType     = FaqsAnswerModel.AnswerReceiveTypeEnum.Money.ToString(),
                            RewardIntergral = Convert.ToInt32(allotNum * 100),
                            CreatedBy       = answerItem.CreatedBy,
                            LastUpdatedBy   = answerItem.LastUpdatedBy,
                            CreationDate    = answerItem.CreationDate.Value,
                            LastUpdatedDate = DateTime.Now,
                            OrgGuid         = answerItem.OrgGuid,
                            Enable          = answerItem.Enable
                        };
                        answerModelList.Add(newAnswerModel);
                        var newEaringsDetailModel = new DoctorEaringsDetailModel
                        {
                            DetailGuid    = Guid.NewGuid().ToString("N"),
                            AnswerGuid    = answerItem.AnswerGuid,
                            DoctorGuid    = answerItem.UserGuid,
                            FeeFrom       = DoctorEaringsDetailModel.FeeFromTypeEnum.Answer.ToString(),
                            ReceivedFee   = Convert.ToInt32(allotNum * 100),
                            OrgGuid       = string.Empty,
                            CreatedBy     = answerItem.UserGuid,
                            LastUpdatedBy = answerItem.UserGuid,
                            Remark        = string.Empty
                        };
                        earingsDetailModelList.Add(newEaringsDetailModel);
                        var balanceModel = await balanceBiz.GetAsync(answerItem.UserGuid ?? "");

                        var isNewBalanceModel = false;
                        if (balanceModel == null)
                        {
                            isNewBalanceModel = true;
                            balanceModel      = new DoctorBalanceModel
                            {
                                BalanceGuid   = answerItem.UserGuid,
                                TotalEarnings = Convert.ToInt32(allotNum * 100),
                                AccBalance    = Convert.ToInt32(allotNum * 100),
                                TotalWithdraw = 0,
                                Status        = DoctorBalanceModel.DoctorBalanceStatusEnum.Normal.ToString(),
                                CreatedBy     = answerItem.UserGuid,
                                LastUpdatedBy = answerItem.UserGuid,
                                OrgGuid       = string.Empty
                            };
                        }
                        else
                        {
                            balanceModel.TotalEarnings += Convert.ToInt32(allotNum * 100);
                            balanceModel.AccBalance    += Convert.ToInt32(allotNum * 100);
                        }
                        doctorBalanceModelList.Add(new Dictionary <bool, DoctorBalanceModel> {
                            { isNewBalanceModel, balanceModel }
                        });
                        #endregion
                    }
                    var isSucc = await FaqsAllotQuestionFee(item, answerModelList, earingsDetailModelList, doctorBalanceModelList);

                    if (!isSucc)
                    {
                        Logger.Error($"FaqsAllotFeeAsync=>问答分配悬赏金失败,QuestionGuid: {item.QuestionGuid}");
                        continue;
                    }
                    conpleteNum++;
                }
            }

            return(conpleteNum);
        }