作者 郭鑫

微信支付完善

@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 // +---------------------------------------------------------------------- 10 // +----------------------------------------------------------------------
11 namespace app\portal\controller; 11 namespace app\portal\controller;
12 //use cmf\controller\HomeBaseController; 12 //use cmf\controller\HomeBaseController;
  13 +use api\portal\model\OrderModel;
13 use app\portal\model\MemberModel; 14 use app\portal\model\MemberModel;
14 use app\portal\model\UserModel; 15 use app\portal\model\UserModel;
15 use app\portal\service\PostService; 16 use app\portal\service\PostService;
@@ -113,5 +114,23 @@ class IndexController extends CommonController @@ -113,5 +114,23 @@ class IndexController extends CommonController
113 \QRcode::png($url); 114 \QRcode::png($url);
114 } 115 }
115 116
  117 + // 检测微信支付是否完成
  118 + public function checkStatus() {
  119 + if($this->request->isAjax()) {
  120 + $order_sn = $this->request->param('order_sn');
  121 + $order_model = new OrderModel();
  122 + $status = $order_model->where(['order_sn'=>$order_sn])->value('status');
  123 + if(empty($status)) {
  124 + $this->apiResponse(0,'订单不存在');
  125 + }
  126 + if($status == 1 || $status == 9) {
  127 + $this->apiResponse(0,'未支付成功');
  128 + }
  129 + if($status == 2) {
  130 + $this->apiResponse(1,'支付成功');
  131 + }
  132 + }
  133 + }
  134 +
116 135
117 } 136 }
@@ -44,6 +44,7 @@ class NotifyController extends HomeBaseController @@ -44,6 +44,7 @@ class NotifyController extends HomeBaseController
44 $orderInfo = $order_model->where(['order_sn'=>$order_sn])->find(); 44 $orderInfo = $order_model->where(['order_sn'=>$order_sn])->find();
45 if($orderInfo['status'] == 1) { 45 if($orderInfo['status'] == 1) {
46 $info = [ 46 $info = [
  47 + 'pay_type'=>1,
47 'pay_time'=>time(), 48 'pay_time'=>time(),
48 'status'=>2, 49 'status'=>2,
49 'transaction_id'=>$data['transaction_id'] 50 'transaction_id'=>$data['transaction_id']
@@ -182,6 +182,20 @@ @@ -182,6 +182,20 @@
182 }); 182 });
183 $("#home-slider").show(); 183 $("#home-slider").show();
184 }); 184 });
  185 +
  186 + setInterval(function(){
  187 + $.ajax({
  188 + url:"{:url('checkStatus')}",
  189 + type:"POST",
  190 + data:{
  191 + order_sn:123123123123
  192 + },
  193 + dataType:"JSON",
  194 + success:function(res){
  195 + console.log(res);
  196 + }
  197 + })
  198 + },1000)
185 </script> 199 </script>
186 <hook name="before_body_end"/> 200 <hook name="before_body_end"/>
187 </body> 201 </body>