Просмотр исходного кода

Merge branch 'master' of http://git.huxiukeji.com/lizhen/lanjingling

lizhen_gitee 1 год назад
Родитель
Сommit
917eceb81b

+ 3 - 1
application/api/controller/Pay.php

@@ -248,12 +248,14 @@ class Pay extends Api
 
             $openid = $this->auth->mini_openid;
             $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
+            $payTest = config('param.pay_test');
+            $orderAmount = $payTest == 1 ? 0.01 : $data['order_amount'];
             //下单
             $params = [
                 'type'         => $pay_type,
                 'orderid'      => $data['out_trade_no'],
                 'title'        => '余额充值',
-                'amount'       => $data['order_amount'],
+                'amount'       => $orderAmount,
                 'method'       => $platform,
                 'openid'       => $openid,
                 'notifyurl' => $httpStr.'/api/pay/order_notify_base/paytype/'.$pay_type.'/func/recharge',

+ 9 - 0
application/api/controller/PreOrder.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use app\common\service\UserService;
 use think\Db;
 use think\Exception;
 
@@ -103,6 +104,14 @@ class PreOrder extends Api
             if (!$res) {
                 throw new Exception('操作失败');
             }
+            if (empty($id)) {//微信消息推送
+                /*$userService = new UserService();
+                $params = ['pre_order_id' => $res];
+                $wechatMsgRes = $userService->wechatMessageSend($params);
+                if (!$wechatMsgRes['status']) {
+                    throw new Exception($wechatMsgRes['msg']);
+                }*/
+            }
             $this->success('操作成功');
         } catch (Exception $e) {
             $this->error($e->getMessage());

+ 3 - 1
application/common/service/OrderService.php

@@ -89,11 +89,13 @@ class OrderService
             if ($payType == 'wechat') {//微信支付 记录日志,生成订单,商家端操作完成增加收入
                 $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
                 //下单
+                $payTest = config('param.pay_test');
+                $orderAmount = $payTest == 1 ? 0.01 : $data['order_amount'];
                 $paramsData = [
                     'type'      => $payType,
                     'orderid'   => $data['out_trade_no'],
                     'title'     => '购买套餐',
-                    'amount'    => $data['order_amount'],
+                    'amount'    => $orderAmount,
                     'method'    => $platform,
                     'openid'    => $miniOpenId,
                     'notifyurl' => $httpStr.'/api/pay/order_notify_base/paytype/'.$payType.'/func/package_do',

+ 62 - 0
application/common/service/UserService.php

@@ -2,7 +2,9 @@
 
 namespace app\common\service;
 
+use GuzzleHttp\Client;
 use think\Db;
+use think\Exception;
 
 class UserService
 {
@@ -91,4 +93,64 @@ class UserService
         }
         return $result;
     }
+
+    /**
+     * 微信消息发送
+     * @return void
+     */
+    public function wechatMessageSend($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '操作成功',
+            'data' => [],
+        ];
+        try {
+            $preOrderId = isset($params['pre_order_id']) ? $params['pre_order_id'] : 0;
+
+            $p = 'pre_order';
+            $u = 'user';
+            $field = $p.'.*,'.$u.'.mini_openid';
+            $where[$p.'.id'] = $preOrderId;
+            $preOrder = Db::name($p)->alias($p)->field($field)
+                ->join($u,$u.'.id = '.$p.'.user_id','LEFT')
+                ->where($where)->find();
+            if (empty($preOrder)) {
+                throw new Exception('未找到预约信息');
+            }
+            $client = new Client();
+            $tk = getAccessToken();
+            /*联系人: {{name.DATA}}
+            联系电话: {{phone_number.DATA}}
+            车牌号: {{car_number.DATA}}
+            预约时间: {{date.DATA}}*/
+            $uri = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='.$tk;
+            $openId = $preOrder['mini_openid'];
+            $wechatTemplate = config('param.wechat_template');
+            $preOrderMsg = isset($wechatTemplate['pre_order']) ? $wechatTemplate['pre_order'] : [];
+            $data = [//数据内容
+                "name"         => ["value" => $preOrder['name']],
+                "phone_number" => ["value" => $preOrder['mobile']],
+                "car_number"   => ["value" => $preOrder['car_number']],
+                "date"         => ["value" => date('Y年m月d日 H:i:s',$preOrder['pre_time'])],
+            ];
+            $jsonData = [
+                "touser"            => $openId,                          //openid
+                "template_id"       => $preOrderMsg['template_id'],      //模版ID
+                "page"              => $preOrderMsg['page'],             //跳转地址
+                "miniprogram_state" => $preOrderMsg['miniprogram_state'],//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
+                "lang"              => $preOrderMsg['lang'],             //支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
+                "data"              => $data,                            //数据
+            ];
+            $res = $client->request('POST', $uri, ['json' => $jsonData]);
+            $returnRes = $res->getBody()->getContents();
+            if (!$returnRes['errcode']) {
+                throw new Exception($returnRes['errmsg']);
+            }
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
 }

+ 14 - 0
application/extra/param.php

@@ -0,0 +1,14 @@
+<?php
+
+return [
+    //微信消息模版
+    'wechat_template' => [
+        'pre_order' => [  //预约模版
+            'template_id'       => '',//模版ID
+            'page'              => '',//跳转地址
+            'miniprogram_state' => 'trial',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
+            'lang'              => 'zh_CN',//支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
+        ],
+    ],
+    'pay_test' => 1,//支付测试  1=测试,0正常
+];