Ejemplo n.º 1
0
        public JsonResult BatchConfirmApply(string ids, Himall.Entities.ApplyWithDrawInfo.ApplyWithDrawStatus comfirmStatus, string remark)
        {
            if (string.IsNullOrWhiteSpace(ids))
            {
                return(ErrorResult("审核的ID,不能为空"));
            }
            var idArray = ids.Split(',').Select(e =>
            {
                long id = 0;
                long.TryParse(e, out id);
                return(id);
            }).Where(e => e > 0);

            var status      = comfirmStatus;
            var models      = _iMemberCapitalService.GetApplyWithDrawInfoByIds(idArray);
            var isHaveError = false;

            foreach (var model in models)
            {
                if (status == Himall.Entities.ApplyWithDrawInfo.ApplyWithDrawStatus.Refuse)
                {
                    _iMemberCapitalService.RefuseApplyWithDraw(model.Id, status, CurrentManager.UserName, remark);
                    //操作日志
                    WithDrawOperateLog(string.Format("会员提现审核拒绝,会员Id={0},状态为:{1}, 说明是:{2}", model.MemId, status, remark));
                    //return Json(new Result { success = true, msg = "审核成功!" });
                }
                else
                {
                    if (model.ApplyStatus == Himall.Entities.ApplyWithDrawInfo.ApplyWithDrawStatus.PayPending)
                    {
                        return(Json(new Result {
                            success = false, msg = "等待第三方处理中,如有误操作,请先取消后再进行付款操作!"
                        }));
                    }
                    Plugin <IPaymentPlugin> plugins = null;
                    bool isCheckName = false;
                    if (model.ApplyType == CommonModel.UserWithdrawType.ALiPay)
                    {
                        isCheckName = true;
                        plugins     = PluginsManagement.GetPlugins <IPaymentPlugin>(true).FirstOrDefault(e => e.PluginInfo.PluginId == PLUGIN_PAYMENT_ALIPAY);
                    }
                    else
                    {
                        plugins = PluginsManagement.GetPlugins <IPaymentPlugin>(true).Where(e => e.PluginInfo.PluginId.ToLower().Contains("weixin")).FirstOrDefault();
                    }
                    if (plugins != null)
                    {
                        try
                        {
                            var tradeno            = model.ApplyTime.ToString("yyyyMMddHHmmss") + model.Id.ToString();
                            EnterprisePayPara para = new EnterprisePayPara()
                            {
                                amount       = model.ApplyAmount,
                                check_name   = isCheckName,
                                openid       = model.OpenId,
                                re_user_name = model.NickName,
                                out_trade_no = tradeno,
                                desc         = "提现"
                            };
                            //调用转账接口
                            PaymentInfo result = plugins.Biz.EnterprisePay(para);
                            //更新提现状态
                            Himall.Entities.ApplyWithDrawInfo info = new Himall.Entities.ApplyWithDrawInfo
                            {
                                PayNo       = result.TradNo,
                                ApplyStatus = Himall.Entities.ApplyWithDrawInfo.ApplyWithDrawStatus.WithDrawSuccess,
                                Remark      = remark,
                                PayTime     = result.TradeTime.HasValue ? result.TradeTime.Value : DateTime.Now,
                                ConfirmTime = DateTime.Now,
                                OpUser      = CurrentManager.UserName,
                                ApplyAmount = model.ApplyAmount,
                                Id          = model.Id
                            };
                            _iMemberCapitalService.ConfirmApplyWithDraw(info);
                            //操作日志
                            WithDrawOperateLog(string.Format("会员提现审核成功,会员Id={0},状态为:{1}, 说明是:{2}", model.MemId, status, remark));
                        }
                        catch (PluginException pex)
                        {//转账失败(业务级别),直接返回错误信息
                            Log.Error("调用企业付款接口异常:" + pex.Message);
                            isHaveError = true;
                            //更新提现状态
                            Himall.Entities.ApplyWithDrawInfo info = new Himall.Entities.ApplyWithDrawInfo
                            {
                                ApplyStatus = Himall.Entities.ApplyWithDrawInfo.ApplyWithDrawStatus.PayFail,
                                Remark      = pex.Message,
                                ConfirmTime = DateTime.Now,
                                OpUser      = CurrentManager.UserName,
                                ApplyAmount = model.ApplyAmount,
                                Id          = model.Id
                            };
                            _iMemberCapitalService.ConfirmApplyWithDraw(info);
                            //操作日志
                            WithDrawOperateLog(string.Format("会员提现审核失败,会员Id={0},状态为:{1}, 说明是:{2}", model.MemId, status, remark));
                            //return Json(new Result { success = false, msg = pex.Message });
                        }
                        catch (Exception ex)
                        {//转账失败(系统级别),直接返回错误信息
                            Log.Error("提现审核异常:" + ex.Message);
                            isHaveError = true;
                            //更新提现状态
                            Himall.Entities.ApplyWithDrawInfo info = new Himall.Entities.ApplyWithDrawInfo
                            {
                                ApplyStatus = Himall.Entities.ApplyWithDrawInfo.ApplyWithDrawStatus.PayFail,
                                Remark      = "审核操作异常,请检查一下支付配置",
                                ConfirmTime = DateTime.Now,
                                OpUser      = CurrentManager.UserName,
                                ApplyAmount = model.ApplyAmount,
                                Id          = model.Id
                            };
                            _iMemberCapitalService.ConfirmApplyWithDraw(info);
                            //操作日志
                            WithDrawOperateLog(string.Format("会员提现审核失败,会员Id={0},状态为:{1}, 说明是:{2}", model.MemId, status, remark));
                            //return Json(new Result { success = false, msg = "付款接口异常" });
                        }
                    }
                    else
                    {
                        return(Json(new Result {
                            success = false, msg = "未找到支付插件"
                        }));
                    }
                }
            }
            if (isHaveError)
            {
                return(Json(new Result {
                    success = true, msg = "审核操作完成,但部分提现失败,请检查!"
                }));
            }
            else
            {
                return(Json(new Result {
                    success = true, msg = "审核操作完成!"
                }));
            }
        }