示例#1
0
        public async Task <IActionResult> GetMyEaringsAsync()
        {
            var balanceBiz   = new DoctorBalanceBiz();
            var balanceModel = await balanceBiz.GetAsync(UserID ?? "");

            if (balanceModel == null)
            {
                balanceModel = new DoctorBalanceModel
                {
                    BalanceGuid   = UserID,
                    TotalEarnings = 0,
                    AccBalance    = 0,
                    TotalWithdraw = 0,
                    Status        = DoctorBalanceStatusEnum.Normal.ToString(),
                    CreatedBy     = UserID,
                    LastUpdatedBy = UserID,
                    OrgGuid       = string.Empty
                };
                var isSucc = await balanceBiz.InsertAsync(balanceModel);

                if (!isSucc)
                {
                    return(Failed(ErrorCode.Empty, "网络异常,请检查!"));
                }
            }
            else if (!balanceModel.Enable || balanceModel.Status.Equals(DoctorBalanceStatusEnum.Frozen.ToString()))
            {
                return(Failed(ErrorCode.Empty, "该用户收益数据不可用,请检查!"));
            }
            var response = balanceModel.ToDto <GetMyEaringsAsyncResponse>();

            response.TotalEarnings = response.TotalEarnings / 100;
            response.AccBalance    = response.AccBalance / 100;
            response.TotalWithdraw = response.TotalWithdraw / 100;
            return(Success(response));
        }
示例#2
0
        public async Task <IActionResult> WithdrawEaringsAsync(WithdrawEaringsAsyncRequest request)
        {
            var bannerBiz    = new DoctorBalanceBiz();
            var balanceModel = await bannerBiz.GetAsync(UserID ?? "");

            if (balanceModel == null || !balanceModel.Enable || balanceModel.Status.Equals(DoctorBalanceStatusEnum.Frozen.ToString()))
            {
                return(Failed(ErrorCode.Empty, "无法获取收益数据,请检查!"));
            }
            decimal balanceNum = balanceModel.AccBalance / 100;

            if (balanceNum < 99 || request.WithdrawNum < 99 || request.WithdrawNum > 299)
            {
                return(Failed(ErrorCode.UserData, "1.余额小于99,2.提现金额小于99,3.提现金额大于299,均不能提现!"));
            }
            var withdrawBiz = new DoctorWithDrawApplyBiz();

            if (await withdrawBiz.GetModelDataInTimeAsync(UserID) > 1)
            {
                return(Failed(ErrorCode.UserData, "每天只能提现一次!"));
            }
            if (string.IsNullOrWhiteSpace(""))
            {
                return(Failed(ErrorCode.SystemException, "功能暂为开放!"));
            }
            var userModel = new UserBiz().GetUser(UserID);
            //创建流水
            var transferFlowingModel = new TransferFlowingModel
            {
                FlowingGuid       = Guid.NewGuid().ToString("N"),
                TransactionNumber = $"FAQSZN_{GetRandomString(10, false, false, true, false, "")}{DateTime.Now.ToString("yyyyMMddHHmmss")}",
                OutTradeNo        = $"FAQSZZ_{GetRandomString(10, false, false, true, false, "")}{DateTime.Now.ToString("yyyyMMddHHmmss")}",
                Channel           = "微信转账",
                ChannelNumber     = "2",
                PayAccount        = userModel?.WechatOpenid ?? "",
                Amount            = Convert.ToInt32(request.WithdrawNum * 100),
                TransactionStatus = TransferFlowingModel.TransferStatusEnum.WaitForPayment.ToString(),
                Remarks           = string.Empty,
                OrgGuid           = string.Empty,
                CreatedBy         = UserID,
                LastUpdatedBy     = UserID
            };
            string timeStamp = (DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalMilliseconds.ToString();
            var    newModel  = new DoctorWithDrawApplyModel
            {
                ApplyGuid              = Guid.NewGuid().ToString("N"),
                ApplyCode              = $"FAQSWD_{GetRandomString(10, false, false, true, false, "")}{DateTime.Now.ToString("yyyyMMddHHmmss")}",//FAQSWD 问答提现申请
                DoctorGuid             = UserID,
                Withdraw               = Convert.ToInt32(request.WithdrawNum * 100),
                Status                 = FaqsApplyStatusEnum.Apply.ToString(),
                TransactionFlowingGuid = transferFlowingModel.FlowingGuid,
                ApproverGuid           = string.Empty,
                Reason                 = string.Empty,
                Remark                 = request.Remark,
                CreatedBy              = UserID,
                LastUpdatedBy          = UserID,
                OrgGuid                = string.Empty
            };

            //调用微信转账
            #region 当前不支持提现,关闭该功能
            var result = await new WeiXinPayBiz().EnterpasePayAsync(transferFlowingModel.OutTradeNo, userModel.WechatOpenid, userModel.UserName, newModel.Withdraw, "192.168.1.1");
            if (!result.result_code.Equals("SUCCESS"))
            {
                balanceModel.AccBalance                = balanceModel.AccBalance - newModel.Withdraw;
                balanceModel.TotalWithdraw             = balanceModel.TotalWithdraw + newModel.Withdraw;
                newModel.Status                        = FaqsApplyStatusEnum.Complete.ToString();
                transferFlowingModel.TransactionStatus = TransferFlowingModel.TransferStatusEnum.Success.ToString();
            }
            //申请+流水
            var isSucc = await new DoctorWithDrawApplyBiz().InsertApplyModelAndFlowingModelAsync(newModel, transferFlowingModel, balanceModel);
            if (!isSucc)
            {
                return(Failed(ErrorCode.DataBaseError, "申请出错,请检查!"));
            }
            #endregion
            return(Success(isSucc));
        }