zxhxx vor 3 Jahren
Ursprung
Commit
5d74849a93

+ 1 - 1
application/admin/model/institution/Ade.php

@@ -60,7 +60,7 @@ class Ade extends Model
     {
         $model = new self();
         $model = $model->where('status', 1);
-        $model = $model->where('cid',$cid);
+        if($cid>0) $model = $model->where('cid',$cid);
         if ($latitude && $longitude) {
             $model = $model->field(['*', self::distanceSql($latitude, $longitude)])->order('distance asc');
         }

+ 5 - 2
application/api/controller/Institution.php

@@ -12,16 +12,19 @@ class Institution extends Api
     protected $noNeedRight = ['*'];
     public function ade(Request $request)
     {
-        list($latitude, $longitude, $page, $limit) = UtilService::getMore(
+        list($latitude, $longitude, $page, $limit,$all) = UtilService::getMore(
             [
                 ['latitude',''],
                 ['longitude',''],
                 ['page',1],
                 ['limit',10],
+                ['all',0],
             ],$request,true
 
         );
-        $this->success('获取成功',Ade::lst($this->cid,$latitude,$longitude,$page,$limit));
+
+        if($all==0) $cid = $this->cid: $cid=0;
+        $this->success('获取成功',Ade::lst($cid,$latitude,$longitude,$page,$limit));
     }
     public function insti(Request $request)
     {

+ 100 - 0
application/api/controller/MiniProgram.php

@@ -0,0 +1,100 @@
+<?php
+namespace app\api\controller;
+use app\common\controller\Api;
+use app\common\model\UserRelation;
+use app\common\model\User;
+use liuniu\MiniProgramService;
+use liuniu\UtilService;
+use think\Hook;
+use think\Request;
+
+class MiniProgram extends  Api
+{
+    /**
+     * 小程序授权登录
+     * @param Request $request
+     * @return mixed
+     * @throws \Psr\SimpleCache\InvalidArgumentException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function mp_auth(Request $request)
+    {
+        $cache_key = '';
+        list($code, $post_cache_key, $login_type) = UtilService::postMore([
+            ['code', ''],
+            ['cache_key', ''],
+            ['login_type', '']
+        ], $request, true);
+        $session_key = cache('post_cache_key',$post_cache_key);
+        if (!$code && !$session_key)
+            $this->error('授权失败,参数有误');
+        if ($code && !$session_key) {
+            try {
+                $userInfoCong = MiniProgramService::getUserInfo($this->cid,$code);
+                $session_key = $userInfoCong['session_key'];
+                $cache_key = md5(time() . $code);
+                cache('post_cache_key', $session_key, 86400);
+            } catch (\Exception $e) {
+                $this->error('',['message' => $e->getMessage(), 'line' => $e->getLine()]);
+            }
+        }
+
+        $data = UtilService::postMore([
+            ['spread_spid', 0],
+            ['spread_code', ''],
+            ['iv', ''],
+            ['encryptedData', ''],
+        ]);//获取前台传的code
+        try {
+            //解密获取用户信息
+            $userInfo = MiniProgramService::encryptor($session_key, $data['iv'], $data['encryptedData']);
+        } catch (\Exception $e) {
+            if ($e->getCode() == '-41003') $this->error('获取会话密匙失败');
+        }
+
+        if (!isset($userInfoCong['openid'])) $this->error('openid获取失败');
+        if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
+        $userInfo['openId'] = $userInfoCong['openid'];
+        $userInfo['spid'] = $data['spread_spid'];
+        $userInfo['code'] = $data['spread_code'];
+        $userInfo['session_key'] = $session_key;
+        $userInfo['login_type'] = $login_type;
+
+        $user = User::where('id', UserRelation::openidToUid($userInfo['openId'], 'routine_openid'))->find();
+        if (!$user)
+            $this->error('获取用户失败');
+
+        $this->auth->direct($user['id']);
+        return $this->success('登录成功', $this->auth->getUserinfo());
+
+    }
+
+
+    /**
+     * 小程序支付回调
+     */
+    public function notify()
+    {
+        MiniProgramService::handleNotify();
+    }
+
+    /**
+     * 获取小程序订阅消息id
+     * @return mixed
+     */
+    public function teml_ids()
+    {
+        $temlIdsName = SubscribeTemplateService::getConstants();
+        $temlIdsList = CacheService::get('TEML_IDS_LIST', function () use ($temlIdsName) {
+            $temlId = [];
+            foreach ($temlIdsName as $key => $item) {
+                $temlId[strtolower($key)] = SubscribeTemplateService::setTemplateId($item);
+            }
+            return $temlId;
+        });
+        return app('json')->success($temlIdsList);
+    }
+
+}

+ 4 - 0
application/route.php

@@ -43,6 +43,10 @@ Route::group('api', function () {
         Route::get('auth', 'api/wechat/auth');
         Route::get('wxconfig', 'api/Index/wxconfig');
     });
+    Route::group('mini', function () {
+        Route::get('auth', 'api/MiniProgram/mp_auth');
+        Route::get('wxconfig', 'api/Index/wxconfig');
+    });
     //机构
     Route::group('institution', function () {
         Route::get('aed', 'api/institution/ade');