优化打款

master
chenzhi 3 years ago
parent 38151288a0
commit 340470be9d

@ -194,13 +194,27 @@ class WxPaymentController extends BaseController
if(count($checkarr) < 1){ if(count($checkarr) < 1){
$this->ajaxReturn(["status"=>1,"msg"=>"ok"]); $this->ajaxReturn(["status"=>1,"msg"=>"ok"]);
} }
$pinyin = new \Think\Pinyin();
$wxPayment = M('wx_payment',"tab_"); $wxPayment = M('wx_payment',"tab_");
foreach ($checkarr as $k => &$v) { foreach ($checkarr as $k => &$v) {
if(!isset($v['realname']) || !isset($v['openid']) || !isset($v['statement_money']) || $v['realname'] == '' || $v['openid'] == '' || $v['statement_money'] <= 0){ 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(); $wxPayment->where("batch_num = '{$v['batch_num']}'")->delete();
$this->ajaxReturn(["status"=>0,"msg"=>"真实姓名,openid,打款金额均不允许为空"]); $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['batch_num'] = $batch;
$v['statement_num'] = "WX{$short}".date('Ymd').date('His').sp_random_string(5);
$v['create_time'] = time(); $v['create_time'] = time();
$res = $wxPayment->add($v); $res = $wxPayment->add($v);
if($res === false){ if($res === false){
@ -210,6 +224,77 @@ class WxPaymentController extends BaseController
} }
$this->ajaxReturn(["status"=>1,"msg"=>"ok"]); $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]]);
}
}

@ -216,8 +216,8 @@
<td>{$data.create_time}</td> <td>{$data.create_time}</td>
<td>{$data.pay_time}</td> <td>{$data.pay_time}</td>
<td> <td>
<a class='confirm viewPool' data-id='{$data.id}'>查看</a> <!-- <a class='confirm viewPool' data-id='{$data.id}'>查看</a>
<a class='confirm exportPool' data-id='{$data.id}'>导出</a> <a class='confirm exportPool' data-id='{$data.id}'>导出</a> -->
<if condition="$data['pay_status'] neq 0"> <if condition="$data['pay_status'] neq 0">
<a class='confirm paymentInfo' data-id='{$data.id}'>打款详情</a> <a class='confirm paymentInfo' data-id='{$data.id}'>打款详情</a>
</if> </if>
@ -682,34 +682,21 @@
$("#doPayment").on("click",function(){ $("#doPayment").on("click",function(){
var verifytip = 0;
var text = $("input:checkbox[name='ids[]']:checked").map(function(index,elem) { var text = $("input:checkbox[name='ids[]']:checked").map(function(index,elem) {
var verifystatus = $(elem).data('verifystatus'); console.log($(elem).data('paystatus'));
if($(elem).data("pay") == 1){ if($(elem).data('paystatus') < 1){
return $(elem).val(); return $(elem).val();
} }
// if (verifystatus != 1) {
// verifytip = 1;
// }
}).get(); }).get();
console.log(text);
// if (verifytip == 1) {
// layer.msg("<font style='color:white'>审核通过方能打款</font>");
// return;
// }
if(text.length < 1){ if(text.length < 1){
layer.msg("<font style='color:white'>请先选择需要打款的结算单仅大于0.1元的打款单才能进行打款</font>"); layer.msg("<font style='color:white'>请先选择需要打款的结算单仅大于0.1元的打款单才能进行打款</font>");
return; return;
} }
checkPaymentOrder();
return;
text = text.join(","); text = text.join(",");
window.location.href = "{:U('showPayment')}"+"&ids="+text; window.location.href = "{:U('showPayment')}"+"&ids="+text;
}) })
$("#leadExcel").on("click",function(){ $("#leadExcel").on("click",function(){
window.location.href = "{:U(add)}"; window.location.href = "{:U(add)}";
}) })

@ -0,0 +1,352 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="__CSS__/base.css" media="all">
<link rel="stylesheet" type="text/css" href="__CSS__/common.css" media="all">
<link rel="stylesheet" type="text/css" href="__CSS__/style.css" media="all">
<link rel="stylesheet" type="text/css" href="__CSS__/default_color.css" media="all">
<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<script type="text/javascript" src="__STATIC__/layer3/layer.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"charset="UTF-8"></script>
<script src="__STATIC__/juicer-min.js" type="text/javascript"></script>
<script src="__STATIC__/table2excel.js"></script>
</head>
<block name="body">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<link rel="stylesheet" href="__CSS__/pro_promote.css" type="text/css" />
<script src="__STATIC__/jquery.form.js"></script>
<script src="__STATIC__/layer/layer.js"></script>
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<script type="text/javascript" src="__STATIC__/layer3/layer.js"></script>
<style>
tml {
min-width:100%;
}
body {
padding: 0px 10px 150px 10px;
/* width: 960px; */
margin: auto;
}
tr{
border-bottom: dotted 1px #c7c7c7;
}
.tabcon1711 table {
width: 480px;
}
.tabcon1711 table {
width: 480px;
}
table {
margin: auto;
}
.hidebox {
display: none;
}
.r {
width: 300px;
}
.l {
width: 180px;
}
.select2-container--default .select2-selection--single {
color: #000;
resize: none;
border-width: 1px;
border-style: solid;
border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
box-shadow: 0px 3px 3px #F7F8F9 inset;
height: 35px;
height: 28px;
border-radius: 3px;
font-size: 12px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height: 35px;
line-height: 28px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 26px;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
height: 26px;
line-height: 26px;
font-size: 12px;
}
.select2-results__option[aria-selected] {
font-size: 12px;
}
.input-list,
.i_list {
float: left;
margin: 0;
}
#sendSasfeCode {
border-radius:3px;
width:100px;
cursor:pointer;
border:1px solid;
top:0;
right:0;
height:40px;
text-align: center;
line-height: 40px;
}
.g-btntn{
border-color: grey;
color: grey;
}
.g-btn{
border-color: #2697FF;
color: #2697FF;
}
</style>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">批量打款</h3>
<p class="description_text">确认打款前请先确认账户余额是否足够</p>
</div>
<div class="data_list box_mt">
<div class="">
<table>
<thead>
<tr>
<th style="border-right: solid 1px #b6cad2;">序号</th>
<th style="border-right: solid 1px #b6cad2;">真实姓名</th>
<th style="border-right: solid 1px #b6cad2;">openid</th>
<th style="border-right: solid 1px #b6cad2;">金额(元)</th>
</tr>
</thead>
<tbody id="statementShow">
<foreach name="data" item="vo" >
<tr>
<td>{$key-0+1}</td>
<td>{$vo.realname}</td>
<td>{$vo.openid}</td>
<td>{$vo.statement_money}</td>
</tr>
</foreach>
<tr>
<td colspan="2">合计:</td>
<td colspan="6">打款总金额:&nbsp;{$count['statement_money']}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div style="display: flex;justify-content:space-between;">
<div style="color: red;font-size: 18px;line-height: 82px;">
微信商户号:{$paymentInfo}
</div>
<if condition="$paymentInfo">
<div style="display: flex;padding:20px 10px;line-height: 40px;justify-content:center;">
<input name="verify" type="text" class="login_input verify" value="" placeholder="请填写验证码"/>
<div id="sendSasfeCode" class="g-btn" style="margin-left: 20px;">获取验证码</div>
<div style="margin-left: 20px;">接收验证码手机:{$mobile}</div>
</div>
<div class="search_list" style="display:flex;margin: 0;align-items:center;margin-right: 20px;">
<a class="sch-btn" href="javascript:;" id="setPayment" style="width: 150px;height: 40px;line-height: 40px;">确认打款</a>
</div>
<else />
<div style="font-size: 18px;line-height: 82px;">
打款接口错误,无法打款
</div>
</if>
</div>
<div style="width: 100vw;height: 100vh;padding: 0;position: absolute;top: 0;z-index: 9999;display: none;" id="creat_msg">
<div class="layui-layer layui-layer-dialog layui-layer-border layui-layer-msg layui-layer-hui"
type="dialog" times="1" showtime="50000" contype="string" style="z-index: 19891015; top:30%; left:45%;">
<div class="layui-layer-content" style="padding: 15px 0 5px;font-size: 20px;font-weight: 600;">执行进度</div>
<div id="tip_msg" class="layui-layer-content">开始时间与结束时间都不允许为空</div>
<div class="layui-layer-content" style="padding: 5px 10px 15px;font-size: 10px;color: #BBB;">TIP:未执行完成之前请勿刷新或关闭此页面</div>
<span class="layui-layer-setwin"></span>
</div>
</div>
</block>
<block name="script">
<script>
var DATA={
data:{$data|json_encode = JSON_UNESCAPED_UNICODE}
};
var pay_status = 1;
// $("#creat_msg").show();
// highlight_subnav("{:U('lists')}");
var MSG={
showmsg:function(str){
$("#creat_msg").show();
$("#tip_msg").html(str);
},
hidemsg:function(){
$("#creat_msg").hide();
$("#tip_msg").html('');
}
}
var COMPARE={
publiucAjax:function(url,senddata,callback){
$.ajax({
type: 'post',
url: url,
data:senddata,
success: function(data) {
if(data.success){
callback(data.data);
}else{
MSG.hidemsg();
layer.alert(data.error);
return false;
}
},
error:function(){
MSG.hidemsg();
layer.alert("网络错误或超时");
return false;
}
});
},
//验证验证码
checkVerify:function(callback){
MSG.showmsg("验证码验证中....");
COMPARE.publiucAjax("{:U('checkVerify')}",{verify:DATA.verify},function(data){
MSG.showmsg("验证码验证通过,开始进行打款 [0/"+DATA.datacount+"] ......");
callback();
});
},
//打款
doPayment:function(callback){
var senddata ={id:DATA.data[(DATA.now-1)]['id']} ;
COMPARE.publiucAjax("{:U('doPayment')}",senddata,function(data){
MSG.showmsg("开始进行打款 ["+DATA.now+"/"+DATA.datacount+"] ......");
DATA.now ++;
if (data.status == 0) {
pay_status = 0;
}
if( DATA.now > DATA.datacount){
callback();
}else{
COMPARE.doPayment(callback)
}
});
}
}
var r = function(i, t) {
if (i>0) {
var r = 60;
e='#sendSasfeCode';
$(e).removeClass('g-btn').addClass('g-btntn');
var a = setInterval(function() {
r--;
$(e).text(r + '秒');
0 == r && ($(e).removeClass('g-btntn').addClass('g-btn'),
$(e).text('获取验证码'),
clearInterval(a))
},1000)
}
};
$('#sendSasfeCode').on('click',function() {
if ($(this).hasClass('g-btntn')) {
return false;
}
var phone = "{$mobile}";
$.ajax({
type:'post',
dataType:'json',
data:'phone='+phone,
url:'{:U("Public/telsafecode")}',
success:function(data) {
if (data.status ==1) {
r(1);
} else {
alert(data.msg);
}
},
error:function() {
alert('服务器开小差了,请稍后再试。');
}
});
});
$("#setPayment").on("click",function(){
MSG.showmsg("程序初始化中...");
var verify = $("input[name='verify']").val();
if($.trim(verify) == ''){
MSG.hidemsg();
alert('验证码不能为空');
return false;
};
DATA.now=1;
DATA.verify=verify;
DATA.datacount = DATA.data.length;
//执行流程
COMPARE.checkVerify(function(){
COMPARE.doPayment(function(){
MSG.showmsg("打款结束,执行跳转中......");
setTimeout(function(){
// window.location.href = "{:U('lists')}";
window.parent.closeLayer(pay_status);
},2000)
})
});
})
function cancelPoolAjax(opurl,senddata){
//执行
$.ajax({
type: "POST",
url: opurl,
dataType: 'json',
async: false,
data: senddata,
success:function(data){
if(data.status==1){
layer.msg("<font style='color:white'>" + data.info + "</font>");
setTimeout(function(){
window.location.reload();
},1500);
}else{
layer.msg("<font style='color:white'>" + data.info + "</font>");
return false;
}
}
});
}
</script>
</block>

@ -12,10 +12,6 @@ class Common_util_pub
const SSLCERT_PATH = __DIR__ . '/cacert/apiclient_cert.pem'; const SSLCERT_PATH = __DIR__ . '/cacert/apiclient_cert.pem';
const SSLKEY_PATH = __DIR__ . '/cacert/apiclient_key.pem'; const SSLKEY_PATH = __DIR__ . '/cacert/apiclient_key.pem';
protected $appid = 'wxb7264c023beac13c';
protected $mchid = '1581995741';
protected $secret = 'PBcd63LMUeqbLPXMqqmxbjduQMqPm23M';
function __construct($appid='', $mchid='') { function __construct($appid='', $mchid='') {
if ($appid) if ($appid)
$this->appid=$appid; $this->appid=$appid;
@ -325,12 +321,20 @@ class Wxpay_client_pub extends Common_util_pub
*/ */
class WeixinPayBtoC extends Wxpay_client_pub class WeixinPayBtoC extends Wxpay_client_pub
{ {
function __construct($appid='',$mchid='') function __construct($config)
{ {
if ($appid) if(empty($config)){
$this->appid = $appid; throw new Exception("请输入配置");
if ($mchid) }
$this->mchid = $mchid; $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"; $this->url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
//设置curl超时时间 //设置curl超时时间

Loading…
Cancel
Save