/// <summary> /// 处理提现结果 /// </summary> /// <param name="item"></param> /// <param name="code"></param> /// <param name="msg"></param> public void CommandDrawCashResult(DrawCashApply item, int code, string resultmsg, C_UserInfo userinfo) { //表示微信那边返回错误码为“SYSTEMERROR”时,一定要使用原单号重试,否则可能造成重复支付等资金风险。 //该提现记录不能算失败也不能算成功,维持原状等待下次提现队列 if (code == -1) { writeLog(resultmsg); return; } DrawCashApplyBLL drawCashApplyBLL = DrawCashApplyBLL.SingleModel; string msg = ""; switch (item.applyType) { case (int)DrawCashApplyType.分销收益提现: msg = drawCashApplyBLL.UpdateDistributionDrawCashApply(code, item, resultmsg, userinfo); break; case (int)DrawCashApplyType.平台店铺提现: msg = drawCashApplyBLL.UpdatePlayDrawCashResult(code, item, resultmsg); break; case (int)DrawCashApplyType.普通提现: break; case (int)DrawCashApplyType.拼享惠平台交易: case (int)DrawCashApplyType.拼享惠扫码收益: msg = drawCashApplyBLL.UpdatePinStoreDrawCashResult(code, item, resultmsg); break; case (int)DrawCashApplyType.拼享惠代理收益: msg = drawCashApplyBLL.UpdatePinAgentDrawCashResult(code, item, resultmsg); break; case (int)DrawCashApplyType.拼享惠用户返现: msg = drawCashApplyBLL.UpdatePxhUserDrawCashResult(code, item, resultmsg); break; } if (msg.Length > 0) { writeLog(msg); } }
/// <summary> /// 银行账号确认提现 /// </summary> /// <param name="aid"></param> /// <param name="id"></param> /// <returns></returns> public ActionResult ConfirmDrawCash(int aid = 0, int id = 0) { _returnData = new Return_Msg(); if (id <= 0) { _returnData.Msg = "id不能为0"; return(Json(_returnData)); } DrawCashApply model = DrawCashApplyBLL.SingleModel.GetModel(id); if (model == null) { _returnData.Msg = "找不到提现申请数据"; return(Json(_returnData)); } string msg = DrawCashApplyBLL.SingleModel.UpdatePlayDrawCashResult(1, model, "银行账号体现成功"); _returnData.isok = msg.Length <= 0; _returnData.Msg = _returnData.isok ? "操作成功" : msg; return(Json(_returnData)); }
/// <summary> /// 获取商家订单提成 /// </summary> /// <param name="apply"></param> /// <returns></returns> public bool AddStoreIncome(DrawCashApply apply) { bool result = false; TransactionModel tran = new TransactionModel(); PinStore store = PinStoreBLL.SingleModel.GetModelByAid_UserId(apply.Aid, apply.userId); if (store == null) { log4net.LogHelper.WriteInfo(GetType(), $"获取商家订单提成失败:商户不存在 userId:{apply.userId}"); return(result); } //更新提现状态 tran.Add(DrawCashApplyBLL.SingleModel.BuildUpdateSql(apply, "drawstate,drawtime,updatetime,remark")); //各级分成 if (store.agentId > 0) { PinAgent fagent = GetModelById(store.agentId); if (fagent == null) { log4net.LogHelper.WriteInfo(GetType(), $"获取商家订单提成失败:代理不存在 agentId:{store.agentId}"); return(result); } PinAgentLevelConfig fagentLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(fagent.AgentLevel, fagent.aId); if (fagentLevelConfig == null) { log4net.LogHelper.WriteInfo(GetType(), $"获取商家订单提成错误:代理商{fagent.id}等级找不到"); return(result); } //表示商家上级找到了进行分成 int money = fagentLevelConfig.OrderExtract * apply.applyMoney; fagent.cash += money; fagent.money += money; tran.Add(BuildUpdateSql(fagent, "cash,money")); PinAgentIncomeLogBLL.SingleModel.AddAgentLog(store, money, fagent, tran, "");//插入上级提成日志 #region 表示有上上级推广者 PinStore fatherStore = PinStoreBLL.SingleModel.GetModelByAid_UserId(apply.Aid, fagent.userId);//查找出推广者的店铺,然后再找出上上级推广者 if (fatherStore != null) { if (fatherStore.agentId > 0) { //表示有上上级推广者 PinAgent gfAgent = GetModelById(fatherStore.agentId); if (gfAgent != null) { PinAgentLevelConfig gfLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(gfAgent.AgentLevel, gfAgent.aId); if (gfLevelConfig == null) { log4net.LogHelper.WriteInfo(GetType(), $"获取商家订单提成错误:上上级代理商{fagent.id}等级找不到"); return(result); } int gfatherAgentMoney = gfLevelConfig.SecondOrderExtract * apply.applyMoney; gfAgent.cash += gfatherAgentMoney; gfAgent.money += gfatherAgentMoney; tran.Add(BuildUpdateSql(gfAgent, "cash,money")); PinAgentIncomeLogBLL.SingleModel.AddAgentLog(store, gfatherAgentMoney, gfAgent, tran, "");//插入上上级提成日志 } } } #endregion } result = ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray); return(result); }
/// <summary> /// 获取提现结果 /// </summary> /// <param name="item"></param> /// <param name="code"></param> /// <param name="msg"></param> public void GetDrawCashResult(DrawCashApply item, ref int code, ref string msg, out C_UserInfo userinfo) { item.drawState = (int)DrawCashState.提现失败; userinfo = C_UserInfoBLL.SingleModel.GetModel(item.userId); if (userinfo != null) { PayCenterSetting setting = PayCenterSettingBLL.SingleModel.GetPayCenterSetting(userinfo.appId); if (setting == null) { msg = "提现失败更新提现申请记录失败PayCenterSetting为NULL"; } else { WxPayData data = new WxPayData(); data.SetValue("openid", userinfo.OpenId); //openid data.SetValue("amount", item.cashMoney); //取款金额 data.SetValue("re_user_name", ReplaceSpecialChar(userinfo.NickName, '?')); //收款用户姓名 data.SetValue("desc", string.Format("{0},小程序{1}提现{2}元", ReplaceSpecialChar(userinfo.NickName, '?'), Enum.GetName(typeof(DrawCashApplyType), item.applyType), item.cashMoneyStr)); data.SetValue("partner_trade_no", item.partner_trade_no); //订单号 data.SetValue("spbill_create_ip", ConfigurationManager.AppSettings["IP"]); //订单号 WxPayData result = WxPayApi.CompanyPay(data, setting); if (result != null) { try { string resultStr = result.ToJson(); //企业付款(客户提现),接收返回数据 //---------------------- //判断执行提现结果 //---------------------- int i = DrawResult(result, item.cashMoney, setting); if (i == 1) { msg = "提现成功"; code = 1; item.drawState = (int)DrawCashState.提现成功; } else if (i == -2) { code = -1; //表示微信那边返回错误码为“SYSTEMERROR”时,一定要使用原单号重试,否则可能造成重复支付等资金风险。 //该提现记录不能算失败也不能算成功,维持原状等待下次提现队列 msg = "返回错误码为“SYSTEMERROR”等待下次提现队列提现返回结果" + resultStr; } else { code = 0; msg = result.GetValue("err_code_des").ToString(); } } catch (Exception ex) { msg = "提现失败发生异常" + ex.Message; } } else { msg = "提现失败(证书路径不存在)"; } } } else { msg = "提现用户不存在"; } item.DrawTime = DateTime.Now; DrawCashApplyBLL.SingleModel.Update(item, "drawState,DrawTime"); writeLog(msg); }
/// <summary> /// 提现审核 /// </summary> /// <param name="aid"></param> /// <param name="id"></param> /// <param name="state"></param> /// <returns></returns> public ActionResult UpdateState(int aid = 0, int id = 0, int state = -999) { if (aid <= 0 || id <= 0 || state == -999) { result.msg = "参数错误"; return(Json(result)); } DrawCashApply apply = DrawCashApplyBLL.SingleModel.GetModelByAid_Id(aid, id); if (apply == null) { result.msg = "申请不存在"; return(Json(result)); } if (apply.drawState != (int)DrawCashState.未开始提现 && apply.state != (int)ApplyState.除) { result.msg = "该申请已开始提现处理"; return(Json(result)); } if (state == (int)ApplyState.除) { if (apply.state != (int)ApplyState.审核不通过) { result.msg = "无法删除,只有审核不通过的才能删除"; return(Json(result)); } } TransactionModel tran = new TransactionModel(); //if (apply.state == (int)ApplyState.审核通过 && apply.pinStore.agentId > 0 && apply.applyType == (int)DrawCashApplyType.拼享惠平台交易)//如果是通过审核改为其他状态,要将代理提成减掉 //{ // if (!pinAgentBLL.ReturnStoreIncome(apply, tran)) // { // result.msg = "操作失败,代理金额回撤失败"; // return Json(result); // } //} if (state == (int)ApplyState.审核不通过) { apply.state = (int)ApplyState.审核不通过; apply.UpdateTime = DateTime.Now; switch (apply.applyType) { case (int)DrawCashApplyType.拼享惠平台交易: case (int)DrawCashApplyType.拼享惠扫码收益: result.code = DrawCashApplyBLL.SingleModel.ReturnPinStoreCash(apply, tran) ? 1 : 0; log4net.LogHelper.WriteInfo(this.GetType(), Newtonsoft.Json.JsonConvert.SerializeObject(tran)); result.code = DrawCashApplyBLL.SingleModel.ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray) ? 1 : 0; break; case (int)DrawCashApplyType.拼享惠代理收益: result.code = DrawCashApplyBLL.SingleModel.ReturnPinAgentCash(apply, tran) ? 1 : 0; result.code = DrawCashApplyBLL.SingleModel.ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray) ? 1 : 0; break; case (int)DrawCashApplyType.拼享惠用户返现: result.msg = DrawCashApplyBLL.SingleModel.UpdatePxhUserDrawCashResult(0, apply, "", state); result.code = result.msg.Length <= 0 ? 1 : 0; if (result.msg.Length > 0) { return(Json(result)); } break; } } else if (state == (int)ApplyState.审核通过) { apply.state = (int)ApplyState.审核通过; apply.UpdateTime = DateTime.Now; apply.drawState = (int)DrawCashState.提现中; if (apply.applyType != (int)DrawCashApplyType.拼享惠用户返现) { apply.userId = apply.appId == WebSiteConfig.GongZhongAppId ? apply.OrderId : apply.userId; apply.pinStore = PinStoreBLL.SingleModel.GetModelByAid_UserId(apply.Aid, apply.userId); if (apply.pinStore == null) { result.msg = "门店不存在"; return(Json(result)); } } result.code = DrawCashApplyBLL.SingleModel.Update(apply, "state,updatetime,drawState") ? 1 : 0; } else if (state == 2)//人工提现 { apply.state = (int)ApplyState.审核通过; apply.UpdateTime = DateTime.Now; apply.drawState = (int)DrawCashState.人工提现; apply.userId = apply.appId == WebSiteConfig.GongZhongAppId ? apply.OrderId : apply.userId; apply.pinStore = PinStoreBLL.SingleModel.GetModelByAid_UserId(apply.Aid, apply.userId); if (apply.pinStore == null) { result.msg = "门店不存在"; return(Json(result)); } result.code = DrawCashApplyBLL.SingleModel.Update(apply, "state,updatetime,drawState") ? 1 : 0; if (result.code == 1) { PinAgentBLL.SingleModel.AddStoreIncome(apply); } } else { apply.state = state; apply.UpdateTime = DateTime.Now; result.code = DrawCashApplyBLL.SingleModel.Update(apply, "state,updatetime") ? 1 : 0; } result.msg = result.code == 1 ? "操作成功" : "操作失败"; return(Json(result)); }