当前位置:首页 > PHP教程 > php应用 > 列表

PHP实现财务审核通过后返现金额到客户的功能

发布:smiling 来源: PHP粉丝网  添加日期:2021-12-01 11:43:38 浏览: 评论:0 

有这么一个返现的系统,当前端客户发起提现的时候,后端就要通过审核这笔返现订单,才可以返现到客户的账号里,这篇文章主要介绍了PHP实现财务审核通过后返现金额到客户 ,需要的朋友可以参考下。

应用场景:

有这么一个返现的系统,当前端客户发起提现的时候,后端就要通过审核这笔返现订单,才可以返现到客户的账号里。

来看看下面的截图

PHP财务审核 PHP返现金额

这里的业务场景就是经过两轮审核:销售审核,财务审核都通过后,后端就会付款一笔钱到客户,当然,这里财务审核会有很多种情况,不通过与通过,通过后直接付款又有很多种情况,详细可以查看微信付款到零钱的文档。下面就来看看具体你的代码实现

微信支付配置

1,数据表大概如下

  1. CREATE TABLE `zmq_weixin_config` ( 
  2.  `id` int(1) unsigned NOT NULL AUTO_INCREMENT COMMENT '微信公众平台编号,自增id', 
  3.  `weixin_name` varchar(10) NOT NULL COMMENT '微信公众平台名称', 
  4.  `token` varchar(100) NOT NULL, 
  5.  `appid` char(18) NOT NULL, 
  6.  `appsecret` char(32) NOT NULL, 
  7.  `access_token` varchar(300) NOT NULL, 
  8.  `api_ticket` varchar(300) DEFAULT NULL COMMENT '微信卡包api_ticket', 
  9.  `api_ticket_expired_at` datetime DEFAULT NULL COMMENT '微信卡包api_ticket过期时间', 
  10.  `mchid` varchar(20) DEFAULT NULL COMMENT '商户号', 
  11.  `mchkey` varchar(50) DEFAULT NULL COMMENT '支付密钥', 
  12.  `expired_at` timestamp NULL DEFAULT NULL COMMENT 'access_token过期时间,会自动更新', 
  13.  `updated_at` timestamp NULL DEFAULT NULL COMMENT '记录更新时间', 
  14.  `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', 
  15.  `sort_order` smallint(5) NOT NULL DEFAULT '0' COMMENT '排序', 
  16.  `points_url` varchar(100) DEFAULT NULL, 
  17.  PRIMARY KEY (`id`) 
  18. ) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='微信配置表'; 

2 .config的配置方法

  1. /** 
  2.  * 获取微信支付配置 
  3.  * 这里我是把配置信息存储在数据表里,方便调用 
  4.  * $param是从controller里传值过来:weixin_config_id,notify_url 
  5.  * @return array 
  6.  */ 
  7. public function getWechatConfig($param) 
  8. { 
  9.   $weixin = WeixinConfigBaseModel::find($param['weixin_config_id']); 
  10.   if (empty($weixin)) { 
  11.     throw new Exception('微信配置ID错误'); 
  12.   } 
  13.  
  14.   return [ 
  15.     'wechat' =>[ 
  16.       $app_id => $weixin->appid, 
  17.       'mch_id' => $weixin->mchid, 
  18.       'notify_url' => empty($param['notify_url']) ? '' : $param['notify_url'], //回调url 
  19.       'key' => $weixin->mchkey, 
  20.       'cert_client' => resource_path().'/wechat/'.$weixin->id.'/apiclient_cert.pem', //证书与key 
  21.       'cert_key' => resource_path().'/wechat/'.$weixin->id.'/apiclient_key.pem', 
  22.     ] 
  23.   ]; 
  24. } 

企业付款到个人零钱核心代码

  1. /** 
  2.  * 获取微信支付配置 
  3.  * 这里我是把配置信息存储在数据表里,方便调用 
  4.  * $param是从controller里传值过来:weixin_config_id,notify_url 
  5.  * @return array 
  6.  */ 
  7. public function getWechatConfig($param) 
  8. { 
  9.   $weixin = WeixinConfigBaseModel::find($param['weixin_config_id']); 
  10.   if (emptyempty($weixin)) { 
  11.     throw new Exception('微信配置ID错误'); 
  12.   } 
  13.  
  14.   return [ 
  15.     'wechat' =>[ 
  16.       $app_id => $weixin->appid, 
  17.       'mch_id' => $weixin->mchid, 
  18.       'notify_url' => emptyempty($param['notify_url']) ? '' : $param['notify_url'], //回调url 
  19.       'key' => $weixin->mchkey, 
  20.       'cert_client' => resource_path().'/wechat/'.$weixin->id.'/apiclient_cert.pem', //证书与key 
  21.       'cert_key' => resource_path().'/wechat/'.$weixin->id.'/apiclient_key.pem', 
  22.     ] 
  23.   ]; 
  24. } 

财务审核,也就是微信返现到零钱,这个时候会返回成功结果,或者是各种不成功的结果

这里我用一个方法封装

  1. //财务审核 
  2. if($param['status'] == 2){ 
  3.  
  4.   //判断返现金额与修改后的金额 
  5.   if($before_rebate_amount != $param['rebate_amount']){ 
  6.     //返现金额不相等,则出款金额改变 
  7.     $out_amount = $param['rebate_amount'] - $before_rebate_amount ; 
  8.     $this->outMount($business->business_id,$out_amount); 
  9.   } 
  10.  
  11.   if($param['rebate_status'] == 9){ 
  12.     //财务拒绝通过 
  13.     $business->audit_status = $param['rebate_status']; 
  14.     $business->rebate_amount = $param['rebate_amount']; 
  15.     $business->status = 6; 
  16.     $business->save(); 
  17.  
  18.     //生成日志 
  19.     $this->insertWithdrawLog($param['withdraw_id'], $business->status, $business->audit_status, $param['rebate_remark'], $param['admin_id']); 
  20.  
  21.   }else{ 
  22.     //提现的各种返回结果 
  23.     $this->payReturnResult($business,$param); 
  24.   } 
  25. } 
  26.  
  27. /** 
  28.  * Function:微信提现返回的各种结果 
  29.  * Author:cyw0413 
  30.  * @param $res 
  31.  * @param $business 
  32.  * @param $param 
  33.  */ 
  34. public function payReturnResult($business,$param) 
  35. { 
  36.   $input = [ 
  37.     'weixin_config_id' => 20 , 
  38.     'openid'      => $business->business->open_id, 
  39.     'amount'      => $param['rebate_amount'] * 100, 
  40.     'trade_no'     => $business->order_sn, //商户订单号 
  41.     'desc'       => "微信提现" 
  42.   ]; 
  43.  
  44.   $pay = new PayLogBaseService(); 
  45.   $res = $pay->weixinPay($input); 
  46.  
  47.   if($res['result_code']=="SUCCESS"){ 
  48.     //提现成功 
  49.     $business->audit_status = 4; 
  50.     $business->status = 4; 
  51.     $business->rebate_amount = $param['rebate_amount']; 
  52.     $param['rebate_remark'] = "已付款(".$param['rebate_amount'].")"; 
  53.  
  54.   }elseif ($res['err_code'] == "MONEY_LIMIT"){ 
  55.     $business->audit_status = 3; 
  56.     $business->status = 3; 
  57.     $param['rebate_remark'] = "提现失败,已达到付款给此用户额度上限"; 
  58.     //throw new \Exception($param['rebate_remark']); 
  59.  
  60.   }elseif ($res['err_code'] == "AMOUNT_LIMIT"){ 
  61.     $business->audit_status = 3; 
  62.     $business->status = 3; 
  63.     $param['rebate_remark'] = "提现失败,低于最低付款金额或者高于最高付款金额"; 
  64.     //throw new \Exception($param['rebate_remark']); 
  65. egdf 
  66.   }elseif ($res['err_code'] == "NOTENOUGH"){ 
  67.     $business->audit_status = 3; 
  68.     $business->status = 3; 
  69.     $param['rebate_remark'] = "提现失败,付款帐号余额不足或资金未到账"; 
  70.     //throw new \Exception($param['rebate_remark']); 
  71.  
  72.   }elseif ($res['err_code'] == "SIGN_ERROR"){ 
  73.     $business->audit_status = 3; 
  74.     $business->status = 3; 
  75.     $param['rebate_remark'] = "提现失败,签名错误"; 
  76.  
  77.   }elseif ($res['err_code'] == "PARAM_ERROR"){ 
  78.     $business->audit_status = 3; 
  79.     $business->status = 3; 
  80.     $param['rebate_remark'] = "提现失败,参数错误"; 
  81.  
  82.   }elseif ($res['err_code'] == "OPENID_ERROR"){ 
  83.     $business->audit_status = 3; 
  84.     $business->status = 3; 
  85.     $param['rebate_remark'] = "提现失败,Openid错误"; 
  86.  
  87.   }elseif ($res['err_code'] == "FATAL_ERROR"){ 
  88.     $business->audit_status = 3; 
  89.     $business->status = 3; 
  90.     $param['rebate_remark'] = "提现失败,两次请求参数不一致"; 
  91.  
  92.   }elseif ($res['err_code'] == "CA_ERROR"){ 
  93.     $business->audit_status = 3; 
  94.     $business->status = 3; 
  95.     $param['rebate_remark'] = "提现失败,商户API证书校验出错"; 
  96.  
  97.   }elseif ($res['err_code'] == "V2_ACCOUNT_SIMPLE_BAN"){ 
  98.     $business->audit_status = 3; 
  99.     $business->status = 3; 
  100.     $param['rebate_remark'] = "提现失败,无法给非实名用户付款"; 
  101.  
  102.   }else{ 
  103.     $business->audit_status = 3; 
  104.     $business->status = 3; 
  105.     $param['rebate_remark'] = "提现失败,服务器繁忙,请稍后再试"; 
  106.     //throw new \Exception($param['rebate_remark']); 
  107.   } 
  108.  
  109.   $business->save(); 
  110.  
  111. } 

当微信平台余额不足或者出现各种错误而提现失败的时候,这里还有支持重新付款的功能:其实就是点击按钮后重新调用付款到零钱的功能,知道成功付款

  1. /** 
  2.  * Function:重新付款 
  3.  * Author:cyw0413 
  4.  * @param $param 
  5.  * @throws \Exception 
  6.  */ 
  7. public function repay($param) 
  8. { 
  9.   if(emptyempty($param)){ 
  10.     throw new \Exception("参数错误"); 
  11.   } 
  12.   $business = GroupBusinessWithdrawBaseModel::find($param['withdraw_id']); 
  13.   if(emptyempty($business)){ 
  14.     throw new \Exception("不存在!"); 
  15.   } 
  16.   if($business->audit_status != 3){ 
  17.     throw new \Exception("状态有错误"); 
  18.   } 
  19.   //提现的各种返回结果 
  20.   $this->payReturnResult($business,$param); 
  21. }

Tags: PHP财务审核 PHP返现金额

分享到: