PHP实现财务审核通过后返现金额到客户的功能
程序员文章站
2023-11-22 11:59:34
应用场景:
有这么一个返现的系统,当前端客户发起提现的时候,后端就要通过审核这笔返现订单,才可以返现到客户的账号里。
来看看下面的截图
这里的业务场景就是经过两轮...
应用场景:
有这么一个返现的系统,当前端客户发起提现的时候,后端就要通过审核这笔返现订单,才可以返现到客户的账号里。
来看看下面的截图
这里的业务场景就是经过两轮审核:销售审核,财务审核都通过后,后端就会付款一笔钱到客户,当然,这里财务审核会有很多种情况,不通过与通过,通过后直接付款又有很多种情况,详细可以查看微信付款到零钱的文档。下面就来看看具体你的代码实现
微信支付配置
1,数据表大概如下
create table `zmq_weixin_config` ( `id` int(1) unsigned not null auto_increment comment '微信公众平台编号,自增id', `weixin_name` varchar(10) not null comment '微信公众平台名称', `token` varchar(100) not null, `appid` char(18) not null, `appsecret` char(32) not null, `access_token` varchar(300) not null, `api_ticket` varchar(300) default null comment '微信卡包api_ticket', `api_ticket_expired_at` datetime default null comment '微信卡包api_ticket过期时间', `mchid` varchar(20) default null comment '商户号', `mchkey` varchar(50) default null comment '支付密钥', `expired_at` timestamp null default null comment 'access_token过期时间,会自动更新', `updated_at` timestamp null default null comment '记录更新时间', `created_at` timestamp null default null comment '创建时间', `sort_order` smallint(5) not null default '0' comment '排序', `points_url` varchar(100) default null, primary key (`id`) ) engine=myisam auto_increment=11 default charset=utf8 checksum=1 delay_key_write=1 row_format=dynamic comment='微信配置表';
2 .config的配置方法
/** * 获取微信支付配置 * 这里我是把配置信息存储在数据表里,方便调用 * $param是从controller里传值过来:weixin_config_id,notify_url * @return array */ public function getwechatconfig($param) { $weixin = weixinconfigbasemodel::find($param['weixin_config_id']); if (empty($weixin)) { throw new exception('微信配置id错误'); } return [ 'wechat' =>[ $app_id => $weixin->appid, 'mch_id' => $weixin->mchid, 'notify_url' => empty($param['notify_url']) ? '' : $param['notify_url'], //回调url 'key' => $weixin->mchkey, 'cert_client' => resource_path().'/wechat/'.$weixin->id.'/apiclient_cert.pem', //证书与key 'cert_key' => resource_path().'/wechat/'.$weixin->id.'/apiclient_key.pem', ] ]; }
企业付款到个人零钱核心代码
/** * 获取微信支付配置 * 这里我是把配置信息存储在数据表里,方便调用 * $param是从controller里传值过来:weixin_config_id,notify_url * @return array */ public function getwechatconfig($param) { $weixin = weixinconfigbasemodel::find($param['weixin_config_id']); if (empty($weixin)) { throw new exception('微信配置id错误'); } return [ 'wechat' =>[ $app_id => $weixin->appid, 'mch_id' => $weixin->mchid, 'notify_url' => empty($param['notify_url']) ? '' : $param['notify_url'], //回调url 'key' => $weixin->mchkey, 'cert_client' => resource_path().'/wechat/'.$weixin->id.'/apiclient_cert.pem', //证书与key 'cert_key' => resource_path().'/wechat/'.$weixin->id.'/apiclient_key.pem', ] ]; }
财务审核,也就是微信返现到零钱,这个时候会返回成功结果,或者是各种不成功的结果
这里我用一个方法封装
//财务审核 if($param['status'] == 2){ //判断返现金额与修改后的金额 if($before_rebate_amount != $param['rebate_amount']){ //返现金额不相等,则出款金额改变 $out_amount = $param['rebate_amount'] - $before_rebate_amount ; $this->outmount($business->business_id,$out_amount); } if($param['rebate_status'] == 9){ //财务拒绝通过 $business->audit_status = $param['rebate_status']; $business->rebate_amount = $param['rebate_amount']; $business->status = 6; $business->save(); //生成日志 $this->insertwithdrawlog($param['withdraw_id'], $business->status, $business->audit_status, $param['rebate_remark'], $param['admin_id']); }else{ //提现的各种返回结果 $this->payreturnresult($business,$param); } }
/** * function:微信提现返回的各种结果 * author:cyw0413 * @param $res * @param $business * @param $param */ public function payreturnresult($business,$param) { $input = [ 'weixin_config_id' => 20 , 'openid' => $business->business->open_id, 'amount' => $param['rebate_amount'] * 100, 'trade_no' => $business->order_sn, //商户订单号 'desc' => "微信提现" ]; $pay = new paylogbaseservice(); $res = $pay->weixinpay($input); if($res['result_code']=="success"){ //提现成功 $business->audit_status = 4; $business->status = 4; $business->rebate_amount = $param['rebate_amount']; $param['rebate_remark'] = "已付款(".$param['rebate_amount'].")"; }elseif ($res['err_code'] == "money_limit"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,已达到付款给此用户额度上限"; //throw new \exception($param['rebate_remark']); }elseif ($res['err_code'] == "amount_limit"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,低于最低付款金额或者高于最高付款金额"; //throw new \exception($param['rebate_remark']); egdf }elseif ($res['err_code'] == "notenough"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,付款帐号余额不足或资金未到账"; //throw new \exception($param['rebate_remark']); }elseif ($res['err_code'] == "sign_error"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,签名错误"; }elseif ($res['err_code'] == "param_error"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,参数错误"; }elseif ($res['err_code'] == "openid_error"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,openid错误"; }elseif ($res['err_code'] == "fatal_error"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,两次请求参数不一致"; }elseif ($res['err_code'] == "ca_error"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,商户api证书校验出错"; }elseif ($res['err_code'] == "v2_account_simple_ban"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,无法给非实名用户付款"; }else{ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,服务器繁忙,请稍后再试"; //throw new \exception($param['rebate_remark']); } $business->save(); }
当微信平台余额不足或者出现各种错误而提现失败的时候,这里还有支持重新付款的功能:其实就是点击按钮后重新调用付款到零钱的功能,知道成功付款
/** * function:重新付款 * author:cyw0413 * @param $param * @throws \exception */ public function repay($param) { if(empty($param)){ throw new \exception("参数错误"); } $business = groupbusinesswithdrawbasemodel::find($param['withdraw_id']); if(empty($business)){ throw new \exception("不存在!"); } if($business->audit_status != 3){ throw new \exception("状态有错误"); } //提现的各种返回结果 $this->payreturnresult($business,$param); }
总结
以上所述是小编给大家介绍的php实现财务审核通过后返现金额到客户的功能,希望对大家有所帮助