Jelajahi Sumber

feat:
- 反馈管理
- 个人信息接口
- 提交反馈接口

zzb 2 tahun lalu
induk
melakukan
47cdf4cd66

+ 70 - 0
app/admin/controller/Feedback.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\controller\base\Permissions;
+use think\Db;
+
+class Feedback extends Permissions
+{
+    private function getModel()
+    {
+        return new \app\common\model\Feedback();
+    }
+
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            $post = $this->request->param();
+            $where = [];
+            if (isset($post['ids']) and !empty($post['ids'])) {
+                $where['id'] = ['in', $post['ids']];
+            }
+            if (!empty($post["content"])) {
+                $where["content"] = ['like', '%' . $post["content"] . '%'];
+            }
+            if (isset($post["user_id"]) and "" != $post["user_id"]) {
+                $where["user_id"] = $post["user_id"];
+            }
+            if (isset($post["create_time"]) and !empty($post["create_time"])) {
+                $timerang = explode(' - ', $post["create_time"]);
+                $min_time = strtotime($timerang[0]);
+                $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
+                $where["create_time"] = [['>=', $min_time], ['<=', $max_time]];
+            }
+
+            $model = $this->getModel();
+            $count = $model->where($where)->count();
+            $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();
+
+            return array('code' => 0, 'count' => $count, 'data' => $data);
+        } else {
+            return $this->fetch();
+        }
+    }
+
+
+    public function delete()
+    {
+        if ($this->request->isAjax()) {
+            $id = $this->request->param('id', 0, 'intval');
+            if (false == $this->getModel()->where('id', $id)->delete()) {
+                $this->error('删除失败');
+            } else {
+                $this->success('删除成功', 'index');
+            }
+        }
+    }
+
+    public function deletes()
+    {
+        if ($this->request->isAjax()) {
+            $post = $this->request->param();
+            $ids = $post['ids'];
+            if ($this->getModel()->where('id', 'in', $ids)->delete()) {
+                $this->success('删除成功');
+            }
+        }
+    }
+
+}

+ 76 - 59
app/admin/view/code_generation/tpl/ApiDoc.md.tp

@@ -7,18 +7,22 @@
 请求方式:get / post
 
 请求数据:
-```
-id      | 指定ID,则只返回一条数据 |  int |
-page    | 第几页,默认1           |  int |
-pagenum | 每页几条,默认20        |  int,<=:1000 |
-```
+
+| 参数名 | 说明  | 备注  |
+| ---   | ---   | ---  |
+|  id      | 指定ID,则只返回一条数据 |  int   |
+|  page    | 第几页,默认1           |  int   |
+|  pagenum | 每页几条,默认20        |  int,<=:1000 |
+
 
 响应数据:(json格式)
 ```
-code int 状态,1代表成功,0代表失败
-msg  string 消息
-time int 时间戳
-data json 返回数据
+{
+    "code": 1, // 返回状态,1代表成功,0代表失败
+    "msg": "success", // 返回消息
+    "time": "1586490789", // 响应时间戳
+    "data": null // 结果数据,json格式,没数据时为 null
+}
 ```
 {/if}
 
@@ -31,7 +35,9 @@ data json 返回数据
 请求方式:get / post
 
 请求数据:
-```
+
+| 参数名 | 说明  | 备注  |
+| ---   | ---   | ---  |
      {volist name="$fieldsInfo" id="vo"}
        {php}
            $field_key = $vo['Field'];
@@ -41,6 +47,8 @@ data json 返回数据
            if(!empty($vo['Comment'])){
                $comment = $vo['Comment'];
                $field_key.= " | " . $comment;
+           }else{
+               $field_key.= " | ";
            }
            $field_val = "";
            if($vo['Default'] === null){
@@ -56,22 +64,23 @@ data json 返回数据
        {/php}
 
        {notempty name="$field_val"}
-  {$field_key} |  {$field_val} |
-       {/notempty}
-
+|  {$field_key} |  {$field_val} |
+{/notempty}
     {/volist}
 
-```
 
 响应数据:(json格式)
 ```
-code int 状态,1代表成功,0代表失败
-msg string 消息
-time int 时间戳
-data json 返回数据
+{
+    "code": 1, // 返回状态,1代表成功,0代表失败
+    "msg": "success", // 返回消息
+    "time": "1586490789", // 响应时间戳
+    "data": null // 结果数据,json格式,没数据时为 null
+}
 ```
 {/if}
 
+
 {if condition="array_key_exists('delete',$crud)"}
 # 删除{$menuName}
 
@@ -80,20 +89,25 @@ data json 返回数据
 请求方式:get / post
 
 请求数据:
-```
- id | 数据ID |  int |
-```
+
+| 参数名 | 说明  | 备注  |
+| ---   | ---   | ---  |
+| id | 数据ID |  int |
+
 
 响应数据:(json格式)
 ```
-code int 状态,1代表成功,0代表失败
-msg string 消息
-time int 时间戳
-data json 返回数据
+{
+    "code": 1, // 返回状态,1代表成功,0代表失败
+    "msg": "success", // 返回消息
+    "time": "1586490789", // 响应时间戳
+    "data": null // 结果数据,json格式,没数据时为 null
+}
 ```
 {/if}
 
 
+
 {if condition="array_key_exists('update',$crud)"}
 # 修改{$menuName}
 
@@ -102,44 +116,47 @@ data json 返回数据
 请求方式:get / post
 
 请求数据:
-```
-          id | 数据ID |  int |
-     {volist name="$fieldsInfo" id="vo"}
-       {php}
-           $field_key = $vo['Field'];
-           if(in_array($field_key,['id','create_time','update_time'])){
-               continue;
-           }
-           if($vo['Default'] === null){
-              continue;
-           }
-           if(!empty($vo['Comment'])){
-               $comment = $vo['Comment'];
-               $field_key.= " | " . $comment;
-           }
-           $field_val = "";
-           if(startWith($vo["Type"],'int') || startWith($vo["Type"],'tinyint')){
-               $field_val .= empty($field_val) ? "int" : ",int";
-           }
-           if(startWith($vo["Type"],'varchar')){
-               $maxLen = str_replace(['varchar(',')'],['',''],$vo["Type"]);
-               $field_val .= empty($field_val) ? "max:".$maxLen : ",max:".$maxLen;
-           }
-       {/php}
 
-       {notempty name="$field_val"}
-  {$field_key} |  {$field_val} |
-       {/notempty}
+| 参数名 | 说明  | 备注  |
+| ---   | ---   | ---  |
+| id | 数据ID |  int |
+{volist name="$fieldsInfo" id="vo"}
+    {php}
+       $field_key = $vo['Field'];
+       if(in_array($field_key,['id','create_time','update_time'])){
+           continue;
+       }
+       if($vo['Default'] === null){
+          continue;
+       }
+       if(!empty($vo['Comment'])){
+           $comment = $vo['Comment'];
+           $field_key.= " | " . $comment;
+       }else{
+            $field_key.= " | ";
+       }
+       $field_val = "";
+       if(startWith($vo["Type"],'int') || startWith($vo["Type"],'tinyint')){
+           $field_val .= empty($field_val) ? "int" : ",int";
+       }
+       if(startWith($vo["Type"],'varchar')){
+           $maxLen = str_replace(['varchar(',')'],['',''],$vo["Type"]);
+           $field_val .= empty($field_val) ? "max:".$maxLen : ",max:".$maxLen;
+       }
+    {/php}
+    {notempty name="$field_val"}
+|  {$field_key} |  {$field_val} |
+{/notempty}
+{/volist}
 
-    {/volist}
-
-```
 
 响应数据:(json格式)
 ```
-code int 状态,1代表成功,0代表失败
-msg string 消息
-time int 时间戳
-data json 返回数据
+{
+    "code": 1, // 返回状态,1代表成功,0代表失败
+    "msg": "success", // 返回消息
+    "time": "1586490789", // 响应时间戳
+    "data": null // 结果数据,json格式,没数据时为 null
+}
 ```
 {/if}

+ 2 - 2
app/admin/view/code_generation/tpl/index.html.tp

@@ -255,16 +255,16 @@
 
             {if condition="array_key_exists('update',$crud) or array_key_exists('delete',$crud)"}
             table.on('tool(table)', function (obj) {
-                {if condition="array_key_exists('update',$crud)"}
                 if (obj.event == 'edit') {
+                 {if condition="array_key_exists('update',$crud)"}
                     window.parent.tab.tabAdd({
                         icon: "fa-bookmark",
                         id: "{$tableName}" + obj.data.id,
                         title: obj.data.title == null ? "{$menuName}" + obj.data.id : obj.data.title,
                         url: "/admin/{$underLineName}/publish?id=" + obj.data.id
                     });
+                  {/if}
                 }
-                {/if}
                 {if condition="array_key_exists('delete',$crud)"}
                 else if (obj.event == 'del') {
                     layer.confirm('确定要删除?', function (index) {

+ 185 - 0
app/admin/view/feedback/index.html

@@ -0,0 +1,185 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>layui</title>
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+    <link rel="stylesheet" href="/static/public/layui/css/layui.css" media="all">
+    <link rel="stylesheet" href="/static/public/font-awesome/css/font-awesome.min.css" media="all"/>
+    <link rel="stylesheet" href="/static/admin/css/admin.css" media="all">
+    <style type="text/css">
+        /* tooltip */
+        #tooltip {
+            position: absolute;
+            border: 1px solid #ccc;
+            background: #333;
+            padding: 2px;
+            display: none;
+            color: #fff;
+        }
+
+        .tooltip > img {
+            width: 20px;
+            height: 20px;
+        }
+    </style>
+</head>
+<body style="padding:10px;">
+<div class="tplay-body-div">
+
+
+    <script type="text/html" id="toolbarDemo">
+        <div class="layui-btn-container">
+            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="deletes">批量删除</button>
+        </div>
+    </script>
+
+    <form class="layui-form serch" action="index" method="post">
+        <div class="layui-form-item" style="float: left;">
+
+            <div class="layui-input-inline">
+                <input type="text" name="ids" autocomplete="off" placeholder="请输入ID,多个id逗号分隔"
+                       class="layui-input layui-btn-sm">
+            </div>
+            <div class="layui-input-inline">
+                <input type="text" name="content" autocomplete="off" placeholder="内容(模糊搜索)"
+                       class="layui-input layui-btn-sm">
+            </div>
+            <div class="layui-input-inline" style="width:100px">
+                <input type="number" name="user_id" autocomplete="off" placeholder="发布人"
+                       class="layui-input layui-btn-sm">
+            </div>
+            <div class="layui-input-inline">
+                <input type="text" class="layui-input time_range" id="time_range_create_time" autocomplete="off"
+                       placeholder="日期" name="create_time">
+            </div>
+            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
+        </div>
+    </form>
+
+    <script type="text/html" id="barDemo">
+        <div class="layui-btn-group">
+            <button class="layui-btn layui-btn-xs delete" lay-event="del"><i class="layui-icon"
+                                                                             style="margin-right: 0;"></i></button>
+        </div>
+    </script>
+
+    <table class="layui-table" id="table" lay-filter="table"></table>
+    {include file="public/foot"}
+
+    <script type="text/javascript">
+        layui.use(['table', 'layer', 'form', 'laydate'], function () {
+            var table = layui.table,
+                form = layui.form,
+                layer = layui.layer;
+            var laydate = layui.laydate;
+            //第一个实例
+            table.render({
+                id: 'table'
+                , elem: '#table'
+                , size: 'sm' //小尺寸的表格
+                , toolbar: '#toolbarDemo'
+                , limit: 15
+                , limits: [15, 20, 30, 40, 50, 100]
+                , url: "{:url('index')}" //数据接口
+                , page: true //开启分页
+                , cols: [[ //表头
+                    {type: 'checkbox'},
+
+                    {field: 'id', title: 'ID', width: 60},
+                    {field: "content", title: '内容'},
+                    {field: "user_id", title: '发布人'},
+                    {field: "create_time", title: '日期'},
+                    {field: 'action', title: '操作', toolbar: '#barDemo', fixed: 'right'}
+                ]],
+                done: function () {
+                    if (isExitsFunction('showThumb')) {
+                        showThumb()
+                    }
+                }
+            });
+
+            laydate.render({
+                elem: '#time_range_create_time'
+                , type: 'datetime'
+                , range: true
+                , max: 0 //最大值0天后
+                , theme: 'molv'
+                , calendar: true
+                , done: function (value, date, endDate) {
+                    if (endDate.hours == 0 && endDate.minutes == 0 && endDate.seconds == 0) {
+                        setTimeout(function () {
+                            $('#time_range_create_time').val(value.replace(/00:00:00$/, '23:59:59'))
+                        }, 100)
+                    }
+                }
+            });
+
+            form.on('submit(serch)', function (data) {
+                table.reload('table', {
+                    where: data.field
+                    , page: {
+                        curr: 1 //重新从第 1 页开始
+                    }
+                });
+                return false;
+            });
+
+            table.on('tool(table)', function (obj) {
+                if (obj.event == 'edit') {
+                }
+                else if (obj.event == 'del') {
+                    layer.confirm('确定要删除?', function (index) {
+                        $.ajax({
+                            url: "{:url('delete')}",
+                            dataType: 'json',
+                            data: {id: obj.data.id},
+                            success: function (res) {
+                                layer.msg(res.msg);
+                                if (res.code == 1) {
+                                    table.reload('table');
+                                }
+                            }
+                        })
+                    })
+                }
+            });
+            //监听事件
+            table.on('toolbar(table)', function (obj) {
+                if (obj.event == 'deletes') {
+                    var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
+                    var data = checkStatus.data;
+                    if (data.length > 0) {
+                        var ids = [];//数组
+                        data.forEach(function (item, key) {
+                            ids[key] = item.id;
+                        })
+                        layer.confirm('是否删除?', function (index, layero) {
+                            $.ajax({
+                                url: "{:url('deletes')}",
+                                dataType: 'json',
+                                data: {"ids": ids},
+                                type: 'post',
+                                success: function (res) {
+                                    layer.msg(res.msg);
+                                    if (res.code == 1) {
+                                        table.reload('table');
+                                    }
+                                }
+                            })
+                            layer.close(index)
+                        });
+                    } else {
+                        layer.msg('请先勾选需要操作的记录');
+                    }
+                }
+            });
+        });
+    </script>
+
+
+</div>
+</body>
+</html>

+ 123 - 0
app/admin/view/feedback/publish.html

@@ -0,0 +1,123 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>反馈表编辑</title>
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+    <link rel="stylesheet" href="/static/public/layui/css/layui.css"  media="all">
+    <link rel="stylesheet" href="/static/public/font-awesome/css/font-awesome.min.css" media="all" />
+    <link rel="stylesheet" href="/static/admin/css/admin.css"  media="all">
+    <script src="/static/public/layui/layui.js"></script>
+    <script src="/static/public/jquery/jquery.min.js"></script>
+</head>
+<style>
+  .layui-upload-img{
+    cursor: pointer;
+    width:150px;
+    height:150px;
+    background: url('/static/public/images/uploadimg.jpg');
+    background-size:contain;
+    border-radius: 2px;
+    border-width: 1px;
+    border-style: solid;
+    border-color: #e6e6e6;
+  }
+</style>
+<body style="padding:10px;">
+  <div class="tplay-body-div">
+
+    {empty name="$data"}
+    <div class="layui-tab">
+      <ul class="layui-tab-title">
+        <li><a href="index" class="a_menu">列表</a></li>
+        <li class="layui-this">新增</li>
+      </ul>
+    </div>
+    {/empty}
+
+    <div style="margin-top: 20px;"></div>
+    <form class="layui-form" id="publish" method="post">
+
+                      <!-- 输入框 -->
+              <div class="layui-form-item">
+                <label class="layui-form-label">标题</label>
+                <div class="layui-input-inline" style="max-width:300px;">
+                  <input name="title"  autocomplete="off" placeholder="请输入" class="layui-input" type="text" {notempty name="$data"}value="{$data.title}"{/notempty}>
+                </div>
+                                </div>
+                          <!-- 输入框 -->
+              <div class="layui-form-item">
+                <label class="layui-form-label">内容</label>
+                <div class="layui-input-inline" style="max-width:300px;">
+                  <input name="content"  autocomplete="off" placeholder="请输入" class="layui-input" type="text" {notempty name="$data"}value="{$data.content}"{/notempty}>
+                </div>
+                                </div>
+                            <!-- 数字 -->
+              <div class="layui-form-item">
+                <label class="layui-form-label">发布人</label>
+                <div class="layui-input-inline" style="max-width:300px;">
+                  <input name="user_id"  autocomplete="off" placeholder="请输入" class="layui-input" type="number" {notempty name="$data"}value="{$data.user_id}"{/notempty}>
+                </div>
+                                </div>
+            
+
+        
+        {notempty name="$data"}
+          <input type="hidden" name="id" value="{$data.id}">
+        {/notempty}
+       
+      <div class="layui-form-item">
+        <div class="layui-input-block">
+          <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
+          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
+        </div>
+      </div>
+    </form>
+
+    <script>
+        layui.use(['layer', 'form' ,'laydate'], function () {
+            var layer = layui.layer,
+                $ = layui.jquery,
+                form = layui.form;
+            var laydate = layui.laydate;
+
+            $(window).on('load', function () {
+                form.on('submit(admin)', function (data) {
+                    $.ajax({
+                        url: "{:url('publish')}",
+                        data: $('#publish').serialize(),
+                        type: 'post',
+                        dataType: 'json',
+                        async: false,
+                        success: function (res) {
+                            if (res.code == 1) {
+                                if (res.msg == "添加成功") {
+                                    layer.alert(res.msg, function (index) {
+                                        location.href = res.url;
+                                    })
+                                }else{
+                                    layer.confirm(res.msg, {
+                                        btn: ['关闭', '继续编辑']
+                                    }, function (index) {
+                                        window.parent.tab.close('tplay_feedback{$data.id|default=0}');
+                                    }, function (index, layero) {
+                                        location.href = res.url;
+                                    });
+                                }
+                            } else {
+                                layer.msg(res.msg);
+                            }
+                        }
+                    })
+                    return false;
+                });
+
+                
+            });
+        });
+    </script>
+  </div>
+</body>
+</html>

+ 22 - 0
app/api/controller/User.md

@@ -0,0 +1,22 @@
+
+# 提交反馈接口
+接口地址:/api/user/feedback
+
+请求方式:get / post
+
+请求数据:
+
+| 参数名 | 说明  | 备注  |
+| ---   | ---   | ---  |
+| content | 内容 |  max:500 |
+
+
+响应数据:(json格式)
+```
+{
+    "code": 1, // 返回状态,1代表成功,0代表失败
+    "msg": "success", // 返回消息
+    "time": "1586490789", // 响应时间戳
+    "data": null // 结果数据,json格式,没数据时为 null
+}
+```

+ 25 - 25
app/api/controller/User.php

@@ -9,36 +9,36 @@
 namespace app\api\controller;
 
 
-use app\api\controller\base\Base;
+use app\common\model\Feedback;
+use app\api\controller\base\Permissions;
 
-class User extends Base
+class User extends Permissions
 {
-    protected $user;
-
-    protected function _initialize()
-    {
-        $unionid = $this->request->param('unionid');
-        if (!$unionid) {
-            $openid = $this->request->param('openid');
-            if (!$openid) {
-                $this->json_error('请先登入');
-            }
-            $user = \app\common\model\User::get(['openid' => $openid]);
-            if (!$user) {
-                $this->json_error('账号不存在');
-            }
-        }
-        $user = \app\common\model\User::get(['unionid' => $unionid]);
-        if (!$user) {
-            $this->json_error('账号不存在');
-        }
-
-        $this->user = $user;
-    }
-
     //个人资料接口
     public function info()
     {
         $this->json_success('success', $this->user);
     }
+
+    //提交反馈接口
+    public function feedback()
+    {
+        $post = $this->request->param();
+        //验证
+        $validate = new \think\Validate([
+            ['content|内容', 'require|max:500'],
+        ]);
+        if (!$validate->check($post)) {
+            $this->error('提交失败:' . $validate->getError());
+        }
+
+        $model = new Feedback();
+        $post['user_id'] = $this->user->id;
+        $res = $model->allowField(true)->save($post);
+        if ($res) {
+            $this->json_success("创建成功", $model);
+        } else {
+            $this->json_error("创建失败");
+        }
+    }
 }

+ 13 - 138
app/api/controller/base/Permissions.php

@@ -8,12 +8,6 @@
 
 namespace app\api\controller\base;
 
-use app\common\model\User;
-use Exception;
-use Firebase\JWT\JWT;
-use Firebase\JWT\Key;
-use think\exception\HttpResponseException;
-
 /**
  * 登入鉴权的接口父类
  * Class Permissions
@@ -21,145 +15,26 @@ use think\exception\HttpResponseException;
  */
 class Permissions extends Base
 {
-    const JWT_COOKIE_NAME = 'x-token';
-    const JWT_SESSION_NAME = 'user_info';
-
-    private $userId;
-    private $user;
+    protected $user;
 
     protected function _initialize()
     {
-        parent::_initialize();
-        //get token from header param body
-        $jwt = $this->request->header('x-token', "");
-        if (!$jwt) {
-            $jwt = $this->request->param('x-token', "");
-            if (!$jwt) {
-                $callbackBody = file_get_contents('php://input');
-                if (!$callbackBody) {
-                    $this->json_error('请先登入');
-                }
-                $callbackJson = json_decode($callbackBody, true);
-                $jwt = isset($callbackJson['x-token']) ? $callbackJson['x-token'] : '';
-                if (!$jwt) {
-                    $this->json_error('请先登入');
-                }
+        $unionid = $this->request->param('unionid');
+        if (!$unionid) {
+            $openid = $this->request->param('openid');
+            if (!$openid) {
+                $this->json_error('请先登入');
             }
-        }
-
-        //check x-token
-        try {
-            JWT::$leeway = 60;
-            $jwt_key = system_salt();
-            $decoded = JWT::decode($jwt, new Key($jwt_key, 'HS256'));
-
-            $arr = (array)$decoded;
-            if (!isset($arr['exp']) || $arr['exp'] < time()) {
-                self::clear_session();
-                throw new \think\Exception('登入超时,请重新登录');
-            } else {
-                //鉴权成功
-                $this->userId = $arr['data']->userId;
-                $loginTime = $arr['data']->loginTime;
-                $exptime = $arr['exp'];
-                //限制账号多次登入
-//                if ($this->getUser()->getData('login_time') > $loginTime) {
-//                    $this->clear_session();
-//                    throw new \think\Exception('您的账号已经在其它地方登入');
-//                }
-                // 每次刷新jwt,loginTime要保持不变
-                self::createJwt($this->userId, $loginTime, 3600, $exptime);
-                return;
-            }
-        } catch (Exception $e) {
-            $this->json_error($this->getErrorMsg($e));
-        }
-    }
-
-    private function getErrorMsg(Exception $e)
-    {
-        if ($e instanceof HttpResponseException) {
-            return $e->getResponse()->getData()['msg'];
-        }
-        switch ($e->getMessage()) {
-            case "Expired token":
-                self::clear_session();
-                $msg = '登入超时,请重新登录';
-                break;
-            case "Wrong number of segments":
-                self::clear_session();
-                $msg = 'Token验证失败,请重新登录';
-                break;
-            default:
-                $msg = "error:" . $e->getMessage();
-        }
-        return $msg;
-    }
-
-    /**
-     * 获取登入token,并设置登入状态
-     * @param $userId int 用户id
-     * @param $loginTime int 用户登入时间
-     * @param int $expire 设置jwt过期时间,从当前时间开始计算
-     * @param null $exp 强制指定过期时间,用来刷新jwt
-     * @return string
-     */
-    public static function createJwt($userId, $loginTime, $expire = 3600, $exp = null)
-    {
-        $nowtime = time();
-        $exptime = $exp ? $exp : $nowtime + $expire;
-        //添加 exptime,后端可以判断过期并退出, 不通过session
-        $data = ['userId' => $userId, 'loginTime' => $loginTime, 'exptime' => $exptime];
-        $token = [
-            'iss' => PRODUCT_URL, //签发者
-            'aud' => PRODUCT_URL, //jwt所面向的用户
-            'iat' => $nowtime, //签发时间
-            'nbf' => $nowtime + 10, //在什么时间之后该jwt才可用
-            'exp' => $exptime, //过期时间
-            'data' => $data //不要存放隐私信息,jwt可以保证内容不被修改,但可以被解码查看内容
-        ];
-        // 得到jwt
-        $jwt_key = system_salt();
-        $jwt = JWT::encode($token, $jwt_key, 'HS256');
-
-        //设置登入状态
-        session(self::JWT_SESSION_NAME, $data);
-        cookie(self::JWT_COOKIE_NAME, $jwt, 3600 * 12);
-        return $jwt;
-    }
-
-    /**
-     * 获取user对象
-     * @return null|User
-     */
-    protected function getUser()
-    {
-        if (!$this->user) {
-            $user = User::get($this->userId);
+            $user = \app\common\model\User::get(['openid' => $openid]);
             if (!$user) {
-                $this->json_error('找不到用户信息,请重新登入');
+                $this->json_error('账号不存在');
             }
-            $this->user = $user;
         }
-        return $this->user;
-    }
-
-    /**
-     * 获取userid
-     * @return null
-     */
-    protected function getUserId()
-    {
-        return $this->userId;
-    }
-
+        $user = \app\common\model\User::get(['unionid' => $unionid]);
+        if (!$user) {
+            $this->json_error('账号不存在');
+        }
 
-    /**
-     * 退出登入状态
-     */
-    public static function clear_session()
-    {
-        cookie(self::JWT_COOKIE_NAME, null);
-        session(self::JWT_SESSION_NAME, null);
+        $this->user = $user;
     }
 }

+ 10 - 0
app/common/model/Feedback.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+class Feedback extends Model
+{
+    protected $updateTime = false;
+}

+ 5 - 0
db.sql

@@ -735,3 +735,8 @@ INSERT INTO `tplay_webconfig` (`id`, `name`, `is_log`, `is_close_site`, `file_ty
 /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
 /*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
+
+
+ALTER TABLE `tplay_feedback`
+	CHANGE COLUMN `content` `content` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '内容' COLLATE 'utf8_general_ci' AFTER `id`,
+	DROP COLUMN `title`;