您好,登錄后才能下訂單哦!
小編給大家分享一下PHP如何實現財務審核通過后返現金額到客戶的功能,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
應用場景:
有這么一個返現的系統,當前端客戶發起提現的時候,后端就要通過審核這筆返現訂單,才可以返現到客戶的賬號里。
來看看下面的截圖
這里的業務場景就是經過兩輪審核:銷售審核,財務審核都通過后,后端就會付款一筆錢到客戶,當然,這里財務審核會有很多種情況,不通過與通過,通過后直接付款又有很多種情況,詳細可以查看微信付款到零錢的文檔。下面就來看看具體你的代碼實現
微信支付配置
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如何實現財務審核通過后返現金額到客戶的功能”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。