Browse Source

陪护小程序

zgg 1 month ago
parent
commit
b10c011556

+ 3 - 0
application/admin/controller/Index.php

@@ -200,6 +200,9 @@ class Index extends Auth
         // 小程序二维码
         $wxcode = Db::name('org')->where('id',$this->orgId)->value('wxqrcode');
         $this->assign('wxcode',$wxcode);
+        // 陪护小程序二维码
+        $wxcode2 = Db::name('org')->where('id',$this->orgId)->value('wxqrcode2');
+        $this->assign('wxcode2',$wxcode2);
         // 陪护h5
         $phcode = think_encrypt(config("app.app_host").config('app.ph_url').'?orgId='.$this->orgId);
         $this->assign('phcode',$phcode);

+ 3 - 0
application/admin/controller/Orders.php

@@ -1275,6 +1275,7 @@ class Orders extends Auth {
     }
     //批量派单
     public function batchsend($id, $mode = 1) {
+        ini_set('memory_limit', '256M');
         if (request()->isGet()) {
             $this->assign('id', $id);
             $this->assign('mode', $mode);
@@ -1368,6 +1369,7 @@ class Orders extends Auth {
                 ->where('os.to_user_id', 'in', $userIds)
                 ->where('os.del', 0)
                 ->select();
+            unset($userIds,$taskCounts);
             $addrMap = [];
             foreach ($addrInfo as $addr) {
                 $addrMap[$addr['to_user_id']] = $addr;
@@ -1378,6 +1380,7 @@ class Orders extends Auth {
             $address = Db::name('address')
                 ->where('id','in',$addressIds)
                 ->column('title','id');
+            unset($start,$end,$addressIds);
             foreach ($newUser as $key => $value) {
                 $userId = $value['id'];
                 $counts = $taskCountMap[$userId] ?? ['nums' => 0, 'nums2' => 0];

+ 6 - 0
application/admin/view/index/def.html

@@ -247,6 +247,12 @@
 <!--                        <div class="title">小程序二维码</div>-->
 <!--                    </div>-->
 <!--                    {/notempty}-->
+                    {notempty name="wxcode2"}
+                    <div class="qrcode2">
+                        <img src="{$wxcode2}" alt="陪护小程序二维码">
+                        <div class="title">陪护小程序二维码</div>
+                    </div>
+                    {/notempty}
                     <div class="qrcode2">
                         <img src="{:url('Qrcode/qrcode',['code'=>$download,'type'=>1])}" alt="APP下载二维码">
                         <div class="title">APP下载二维码</div>

+ 58 - 2
application/api/controller/h5/Notify.php

@@ -65,6 +65,62 @@ class Notify extends Controller
 
         $response->send();
     }
+
+    public function phorder2(){
+        $config = config('app.wx_mini_config_ph');
+        $app = Factory::payment($config);
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                // 用户是否支付成功
+                $tradeNo = $message['out_trade_no'];
+                // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+                $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
+                if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
+                    return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
+                }
+                $ret = model('PhOrderPay')->paySuccess($order['id'],2);
+                if(!$ret){
+                    trace('订单修改失败');
+                    $fail('订单修改失败');
+                }
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+
+            return true; // 返回处理完成
+        });
+
+        $response->send();
+    }
+
+
+    //萍乡市人民医院
+    public function phOrderPx2(){
+        $config = config('app.wx_mini_config_ph_px');
+        $app = Factory::payment($config);
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                // 用户是否支付成功
+                $tradeNo = $message['out_trade_no'];
+                // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+                $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
+                if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
+                    return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
+                }
+                $ret = model('PhOrderPay')->paySuccess($order['id'],2);
+                if(!$ret){
+                    trace('订单修改失败');
+                    $fail('订单修改失败');
+                }
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+
+            return true; // 返回处理完成
+        });
+
+        $response->send();
+    }
     public function xshopOrder(){
         $config = config('app.wx_config');
         $app = Factory::payment($config);
@@ -79,9 +135,9 @@ class Notify extends Controller
                 }
                 $ret = Db::name('g_orders')->where('id',$order['id'])->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')]);
                 $goods = Db::name('g_order_goods')->where('order_id',$order['id'])->select();
-               //增加销量
+                //增加销量
                 foreach ($goods as $k=>$v){
-                   Db::name('g_goods')
+                    Db::name('g_goods')
                         ->where('id',$v['id'])
                         ->inc('sale',$v['nums'])
                         ->update();

+ 9 - 1
application/api/controller/h5/Oauth.php

@@ -11,7 +11,7 @@ class Oauth extends Controller
 
     public function checkCode(){
         try{
-            $type = input('type/d',1); //1=微信公众号 2=微信小城序
+            $type = input('type/d',1); //1=微信公众号 2=微信小城序 3=陪护小程序
             $code = input('code','','trim');
 
             $openid = "";
@@ -33,6 +33,14 @@ class Oauth extends Controller
                     throw new Exception('登录失败');
                 }
                 $openid = $ret['openid'];
+            }else if($type == 3){
+                $config = config('app.wx_mini_config_ph');
+                $app = \EasyWeChat\Factory::miniProgram($config);
+                $ret = $app->auth->session($code);
+                if(!isset($ret['openid']) || !$ret['openid']){
+                    throw new Exception('登录失败');
+                }
+                $openid = $ret['openid'];
             }
 
             if(!$openid){

+ 56 - 0
application/api/controller/h5/PhOrders.php

@@ -93,5 +93,61 @@ class PhOrders extends Base
         HelpHander::success($ret,'成功');
     }
 
+    public function pay2(){
+        $payId = input('payId/d',0);
+        $info = Db::name('ph_order_pay')->where('id',$payId)->where('status',0)->find();
+        if(!$info){
+            HelpHander::error('订单不存在');
+        }
+        if ($this->orgId == 100){
+            $config = config('app.wx_mini_config_ph_px');
+            $notify = config("app.app_host").'/api/h5/notify/phOrderPx2';
+        }else{
+            $config = config('app.wx_mini_config_ph');
+            $notify = config("app.app_host").'/api/h5/notify/phorder2';
+        }
+        try{
+            $openid = Db::name('wxuser')->where('id',$this->userId)->where('type',3)->value('openid');
+            $app = Factory::payment($config);
+            $title = "预付款";
+            if($info['bus_type'] == 1){
+                $title = "服务费";
+            }
+            $result = $app->order->unify([
+                'body' => $title,
+                'out_trade_no' => $info['sn'],
+                'total_fee' => $info['money']*100,
+                'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
+                'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
+                'openid' => $openid,
+            ]);
+            if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
+                \exception(json_encode($result));
+            }
+
+            $jssdk = $app->jssdk;
+            $ret = $jssdk->sdkConfig($result['prepay_id']); // 返回数组
+            $ret['sn'] = $info['sn'];
+            $ret['money'] = $info['money'];
+            trace($ret);
+        }catch (\Exception $e){
+            trace($e->getMessage());
+            HelpHander::error($e->getMessage());
+        }
+
+        HelpHander::success($ret,'成功');
+    }
+    public function temps(){
+        $temps = [
+//            'COP22f3d6KAFhCHpZQQC9xx8y4GJcxunfbjfiHKlRAY',
+//            'j6ZzH3cgDUU57mKEpcJzVNa3VbwR0mrznuOmkBoPwd0',
+//            'wfDNG2rNhVcdOd5L3XHMT-mcbrwLAN8IUBBeCvpdTrw'
+        ];
+        $data = [
+            'tips' => '为更好地服务您,小程序需要在订单变化时向您发送消息',
+            'temps' => $temps
+        ];
+        HelpHander::success($data);
+    }
 
 }

+ 28 - 0
application/common/model/Org.php

@@ -27,6 +27,7 @@ class Org extends Base
         }
         if($data['type'] == 2){
             $this->createWxQrcode($this->id);
+            $this->createWxPhQrcode($this->id);
         }
         return true;
     }
@@ -72,6 +73,9 @@ class Org extends Base
         if($info && $info['type'] == 2 && !$info['wxqrcode']){
             $this->createWxQrcode($id);
         }
+        if($info && $info['type'] == 2 && !$info['wxqrcode2']){
+            $this->createWxPhQrcode($id);
+        }
         return true;
     }
 
@@ -100,6 +104,30 @@ class Org extends Base
         }
     }
 
+    private function createWxPhQrcode($orgId){
+        try{
+            $config = config('app.wx_mini_config_ph');
+            $app = \EasyWeChat\Factory::miniProgram($config);
+
+            $dir = '/uploads/qrcode';
+            $response = $app->app_code->getUnlimit('org-'.$orgId, [
+                'page'  => 'pages/index/index',
+                'width' => 600,
+            ]);
+            trace($response);
+            if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
+                $response->saveAs('.'.$dir, 'orgph'.$orgId.'.png');
+            }else{
+                exception('生成失败');
+            }
+
+            $file = $dir.'/orgph'.$orgId.'.png';
+            Db::name('org')->where('id',$orgId)->setField('wxqrcode2',$file);
+        }catch (\Exception $e){
+            trace('小程序码:'.$e->getMessage());
+        }
+    }
+
     public function authSave(){
         $orgId = input('orgId/d',0);
         if($orgId <= 0){

+ 7 - 2
application/common/model/PhOrderPay.php

@@ -21,7 +21,8 @@ class PhOrderPay extends Base
             'cate' => 1,
             'status' => 0,
             'create_time' => date('Y-m-d H:i:s'),
-            'bus_type' => $busType
+            'bus_type' => $busType,
+            'from' =>input('from',1)
         ];
 
         $map[] = ['id','=',$orderId];
@@ -226,7 +227,11 @@ class PhOrderPay extends Base
             }
 
             if($data['type'] == 2){ // 线上,微信退款
-                $config = $orgId == 100 ? config('app.wx_config_px') : config('app.wx_config');
+                if ($pay['from'] == 1){
+                    $config = $orgId == 100 ? config('app.wx_config_px') : config('app.wx_config');
+                }else{
+                    $config = $orgId == 100 ? config('app.wx_mini_config_ph_px') : config('app.wx_mini_config_ph');
+                }
                 $app = \EasyWeChat\Factory::payment($config);
                 $ret = $app->refund->byOutTradeNumber($pay['sn'], $data['sn'], $pay['money']*100, $data['money']*100);
                 if($ret['return_code'] != 'SUCCESS' || $ret['result_code'] != 'SUCCESS'){

+ 19 - 0
config/app.php

@@ -240,6 +240,25 @@ return [
             'file' =>  env('runtime_path').'/log/wechat.log',
         ],
     ],
+    //-----陪护微信小程序配置 萍乡市人民医院---------
+    'wx_mini_config_ph_px' => [
+        'app_id' => 'wx24a33c5d6e3816d6',
+        'secret' => 'b916c6c34cdfcf595359cce0e4dd016c',
+        'mch_id' => '1718480120', // 商户号
+        'key' => '29452e7ad4db9fb53ddc1a8ab66ecb2a',   // API 密钥  操作密码:667421
+        // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
+        'cert_path' => env('root_path').'public/certs2/apiclient_cert.pem',
+        'key_path' => env('root_path').'public/certs2/apiclient_key.pem',
+
+        // 下面为可选项
+        // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
+        'response_type' => 'array',
+
+        'log' => [
+            'level' => 'error',
+            'file' =>  env('runtime_path').'/log/wechat.log',
+        ],
+    ],
     //------微信公众号配置---------
   /*  'wx_config' => [
         'app_id' => 'wx2f0195c58ad8c3ec',