From 340470be9d3392b8daac89a7c7c3b12935d3e649 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Mon, 16 Aug 2021 15:32:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/WxPaymentController.class.php | 85 +++++ Application/Payment/View/WxPayment/lists.html | 25 +- .../Payment/View/WxPayment/showPayment.html | 352 ++++++++++++++++++ .../Vendor/WeixinPayBtoC/WeixinPayBtoC.php | 22 +- 4 files changed, 456 insertions(+), 28 deletions(-) create mode 100644 Application/Payment/View/WxPayment/showPayment.html diff --git a/Application/Payment/Controller/WxPaymentController.class.php b/Application/Payment/Controller/WxPaymentController.class.php index a74833bb9..c9e2759c2 100644 --- a/Application/Payment/Controller/WxPaymentController.class.php +++ b/Application/Payment/Controller/WxPaymentController.class.php @@ -194,13 +194,27 @@ class WxPaymentController extends BaseController if(count($checkarr) < 1){ $this->ajaxReturn(["status"=>1,"msg"=>"ok"]); } + + $pinyin = new \Think\Pinyin(); + + $wxPayment = M('wx_payment',"tab_"); foreach ($checkarr as $k => &$v) { if(!isset($v['realname']) || !isset($v['openid']) || !isset($v['statement_money']) || $v['realname'] == '' || $v['openid'] == '' || $v['statement_money'] <= 0){ $wxPayment->where("batch_num = '{$v['batch_num']}'")->delete(); $this->ajaxReturn(["status"=>0,"msg"=>"真实姓名,openid,打款金额均不允许为空"]); } + + $num = mb_strlen($v['realname'], 'UTF8'); + $short = ''; + for ($i = 0; $i < $num; $i++) { + $str = mb_substr($v['realname'], $i, $i + 1, 'UTF8'); + $short .= $pinyin->getFirstChar($str); + } + $v['batch_num'] = $batch; + $v['statement_num'] = "WX{$short}".date('Ymd').date('His').sp_random_string(5); + $v['create_time'] = time(); $res = $wxPayment->add($v); if($res === false){ @@ -210,6 +224,77 @@ class WxPaymentController extends BaseController } $this->ajaxReturn(["status"=>1,"msg"=>"ok"]); } + public function showPayment() + { + if(!isset($_REQUEST['ids'])) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + + $data = M("wx_payment","tab_") + ->field("*") + ->where("id in ({$ids}) and pay_status < 1") + ->select(); + + $count = M("wx_payment","tab_")->field("sum(statement_money) statement_money")->where("id in ({$ids}) and pay_status < 1")->find(); + + $paymentInfo = C("WX_PAYMENT") ? C("WX_PAYMENT")['mchid'] : false; + // $this->getAccountMoney(); + + $this->assign("data",$data); + $this->assign("mobile",$this->admininfo['mobile']); + $this->assign("count",$count); + $this->assign("paymentInfo",$paymentInfo); + $this->display(); + } + + public function checkVerify() + { + $mobile = $this->admininfo['mobile']; + $verify = $_REQUEST['verify']; + if (!A("Public")->checksafecode($mobile, $verify)) { + $this->ajaxReturn(["error"=>"验证码错误"]); + } + $this->ajaxReturn(["success"=>"验证码验证成功","data"=>[]]); + } + + public function doPayment() + { + $id = $_REQUEST['id']; + if (empty(C("WX_PAYMENT"))) { + $this->ajaxReturn(["success"=>"配置错误,无法打款","data"=>['status'=>0]]); + } + Vendor("WeixinPayBtoC/WeixinPayBtoC"); + $fund = new \WeixinPayBtoC(C("WX_PAYMENT")); + $dbres = M("wx_payment", "tab_")->where("id='{$id}' and pay_status < 1")->find(); + if(!$dbres){ + $this->ajaxReturn(["success"=>"打款成功无法重复打款","data"=>['status'=>0]]); + } + + if ($dbres['pay_status'] != 1) { + //执行打款 + $payres = $fund->wxPayBtoC($dbres['statement_money'], $dbres['openid'], $dbres['realname'], $dbres['statement_num']); + + $returnCode = $payres['return_code']; + $resultCode = $payres['result_code']; + + $savedata = ["id"=>$dbres['id']]; + if (!empty($returnCode) && $returnCode == 'SUCCESS' && !empty($resultCode) && $resultCode == 'SUCCESS') { + $savedata["pay_status"]=1; + } else { + $savedata["pay_status"]=-1; + } + $savedata["pay_info"] = json_encode($payres, JSON_UNESCAPED_UNICODE); + $savedata["pay_time"]=time(); + } + M("wx_payment", "tab_")->save($savedata); + if ($savedata['pay_status'] == 1) { + $this->ajaxReturn(["success"=>"打款成功","data"=>['status'=>1]]); + } else { + $this->ajaxReturn(["success"=>"打款失败","data"=>['status'=>0]]); + } + + + } + diff --git a/Application/Payment/View/WxPayment/lists.html b/Application/Payment/View/WxPayment/lists.html index 740ff5e17..1d48f92c9 100644 --- a/Application/Payment/View/WxPayment/lists.html +++ b/Application/Payment/View/WxPayment/lists.html @@ -216,8 +216,8 @@ {$data.create_time} {$data.pay_time} - 查看 - 导出 + 打款详情 @@ -682,34 +682,21 @@ $("#doPayment").on("click",function(){ - var verifytip = 0; var text = $("input:checkbox[name='ids[]']:checked").map(function(index,elem) { - var verifystatus = $(elem).data('verifystatus'); - if($(elem).data("pay") == 1){ + console.log($(elem).data('paystatus')); + if($(elem).data('paystatus') < 1){ return $(elem).val(); } - - // if (verifystatus != 1) { - // verifytip = 1; - // } }).get(); - - // if (verifytip == 1) { - // layer.msg("审核通过方能打款"); - // return; - // } - + console.log(text); if(text.length < 1){ layer.msg("请先选择需要打款的结算单,仅大于0.1元的打款单才能进行打款"); return; } - - checkPaymentOrder(); - return; - text = text.join(","); window.location.href = "{:U('showPayment')}"+"&ids="+text; }) + $("#leadExcel").on("click",function(){ window.location.href = "{:U(add)}"; }) diff --git a/Application/Payment/View/WxPayment/showPayment.html b/Application/Payment/View/WxPayment/showPayment.html new file mode 100644 index 000000000..33cf57f9c --- /dev/null +++ b/Application/Payment/View/WxPayment/showPayment.html @@ -0,0 +1,352 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
序号真实姓名openid金额(元)
{$key-0+1}{$vo.realname}{$vo.openid}{$vo.statement_money}
合计:打款总金额: {$count['statement_money']}
+
+
+ +
+
+ 微信商户号:{$paymentInfo} +
+ + +
+ +
获取验证码
+
接收验证码手机:{$mobile}
+
+ + + +
+ 打款接口错误,无法打款 +
+
+
+ + + + + +
+ + + \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/WeixinPayBtoC/WeixinPayBtoC.php b/ThinkPHP/Library/Vendor/WeixinPayBtoC/WeixinPayBtoC.php index d7cf58dde..dcb350b3d 100644 --- a/ThinkPHP/Library/Vendor/WeixinPayBtoC/WeixinPayBtoC.php +++ b/ThinkPHP/Library/Vendor/WeixinPayBtoC/WeixinPayBtoC.php @@ -12,10 +12,6 @@ class Common_util_pub const SSLCERT_PATH = __DIR__ . '/cacert/apiclient_cert.pem'; const SSLKEY_PATH = __DIR__ . '/cacert/apiclient_key.pem'; - protected $appid = 'wxb7264c023beac13c'; - protected $mchid = '1581995741'; - protected $secret = 'PBcd63LMUeqbLPXMqqmxbjduQMqPm23M'; - function __construct($appid='', $mchid='') { if ($appid) $this->appid=$appid; @@ -325,12 +321,20 @@ class Wxpay_client_pub extends Common_util_pub */ class WeixinPayBtoC extends Wxpay_client_pub { - function __construct($appid='',$mchid='') + function __construct($config) { - if ($appid) - $this->appid = $appid; - if ($mchid) - $this->mchid = $mchid; + if(empty($config)){ + throw new Exception("请输入配置"); + } + $this->appid = $config['appid']; + $this->mchid = $config['mchid']; + $this->secret = $config['secret']; + + + // if ($appid) + // $this->appid = $appid; + // if ($mchid) + // $this->mchid = $mchid; //设置接口链接 $this->url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; //设置curl超时时间