From f8ed1f60de86eda630e68f3ac750a1b8d22b9f4d Mon Sep 17 00:00:00 2001
From: 王晓刚 <wxg@bronet.cn>
Date: Mon, 11 Feb 2019 15:11:51 +0800
Subject: [PATCH] 代理人注册

---
 app/index/controller/FormController.php          | 16 ----------------
 app/portal/controller/PayRenewController.php     | 23 +++++++++++++++++++++++
 simplewind/cmf/controller/HomeBaseController.php | 25 +++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/app/index/controller/FormController.php b/app/index/controller/FormController.php
index 8bdd90e..0a47a93 100644
--- a/app/index/controller/FormController.php
+++ b/app/index/controller/FormController.php
@@ -475,22 +475,6 @@ class FormController extends WeChatBaseController
             $arr['msg'] = '创建续费订单失败!';
             return json_encode($arr);
         }
-        $collocationModel = new CollocationModel();
-        $collocation = $collocationModel->findData(array('c.id'=>$param['id']));
-        //推送模板消息
-        $templateId = 'HVcMt58ic_QhO4yHm4IONQE466ijqQxF0l7rPDcQK1o';
-        $data1 = array(
-            'first'=>"尊敬的用户,您的订单续费成功。",
-            'keyword1'=>$collocation['product_name'],
-            'keyword2'=>$collocation['insurance_num'],
-            'keyword3'=>$collocation['insurer'],
-            'keyword4'=>"$collocation[payment_time]年",
-            'keyword5'=>$collocation['take_time'],
-            'remark'=>"立即查看保单",
-        );
-        $url = url('me_guarantee/guarantee_info',array('id'=>$order_info['id']),'',true);
-        $user1 = Db::name('third_party_user')->where('user_id',$collocation['user_id'])->find();
-        $this->template($templateId,$data1,$url,$user1['openid']);
         $arr['code'] = 20000;
         $arr['msg'] = '创建续费订单成功';
         $arr['data'] = $result;
diff --git a/app/portal/controller/PayRenewController.php b/app/portal/controller/PayRenewController.php
index 7611fc1..3bd677f 100644
--- a/app/portal/controller/PayRenewController.php
+++ b/app/portal/controller/PayRenewController.php
@@ -2,6 +2,9 @@
 
 namespace app\portal\controller;
 
+use app\index\model\CollocationModel;
+use app\index\model\OrderInfoModel;
+use app\index\model\OrderModel;
 use cmf\controller\HomeBaseController;
 use EasyWeChat\Foundation\Application;
 use EasyWeChat\Payment\Order;
@@ -94,6 +97,26 @@ class PayRenewController extends HomeBaseController
                 $update['pay_time']=time();
                 // 不是已经支付状态则修改为已经支付状态
                 $update['status'] = 2;
+                $orderModel = new OrderModel();
+                $order = $orderModel->findData(array('num'=>$out_trade_no));
+                $collocationModel = new CollocationModel();
+                $collocation = $collocationModel->findData(array('c.id'=>$order['collocation_id']));
+                //推送模板消息
+                $templateId = 'HVcMt58ic_QhO4yHm4IONQE466ijqQxF0l7rPDcQK1o';
+                $data1 = array(
+                    'first'=>"尊敬的用户,您的订单续费成功。",
+                    'keyword1'=>$collocation['product_name'],
+                    'keyword2'=>$collocation['insurance_num'],
+                    'keyword3'=>$collocation['insurer'],
+                    'keyword4'=>"$collocation[payment_time]年",
+                    'keyword5'=>$collocation['take_time'],
+                    'remark'=>"立即查看保单",
+                );
+                $orderinfoModel = new OrderInfoModel();
+                $order_info = $orderinfoModel->findData2(array('order_id'=>$order['id']));
+                $url = url('me_guarantee/guarantee_info',array('id'=>$order_info['id']),'',true);
+                $user1 = Db::name('third_party_user')->where('user_id',$collocation['user_id'])->find();
+                $this->template($templateId,$data1,$url,$user1['openid']);
             } else { // 用户支付失败
                 $update['status'] = 1;
             }
diff --git a/simplewind/cmf/controller/HomeBaseController.php b/simplewind/cmf/controller/HomeBaseController.php
index 7c73b7b..15df604 100644
--- a/simplewind/cmf/controller/HomeBaseController.php
+++ b/simplewind/cmf/controller/HomeBaseController.php
@@ -11,6 +11,7 @@
 namespace cmf\controller;
 
 use app\user\model\UserModel;
+use EasyWeChat\Foundation\Application;
 use think\Db;
 use app\admin\model\ThemeModel;
 use think\View;
@@ -211,5 +212,29 @@ class HomeBaseController extends BaseController
         $result = $result.($user_count+1);
         return $result;
     }
+    public function template($templateId,$data,$url=null,$openid){
+        $options=config('wechat_config');
+        $app = new Application($options);
+        $notice = $app->notice;
+        if(empty($url)){
+            $notice->uses($templateId)->andData($data)->andReceiver($openid)->send();
+        }else{
+            $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($openid)->send();
+        }
+    }
+    public function note($content,$mobile){
+        $data = array(
+            'content' 	=> $content,//短信内容
+            'mobile' 	=> $mobile,//手机号码
+            'productid' => '887361',//产品id
+            'xh'		=> ''//小号
+        );
+        $result = send_sms($data);
+        if(substr($result,0,strpos($result,',')) == "1"){
+            return true;
+        }else{
+            return false;
+        }
+    }
 
 }
\ No newline at end of file
--
libgit2 0.24.0