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 @@
确认打款前请先确认账户余额是否足够
+序号 | +真实姓名 | +openid | +金额(元) | +||||
---|---|---|---|---|---|---|---|
{$key-0+1} | +{$vo.realname} | +{$vo.openid} | +{$vo.statement_money} | +||||
合计: | +打款总金额: {$count['statement_money']} | +