Przeglądaj źródła

增加交友宣言

15954078560 3 lat temu
rodzic
commit
b41be49af9

+ 3 - 1
.gitignore

@@ -1,3 +1,5 @@
 /application/database.php
 /runtime
-/public/uploads
+/public/uploads
+/public/.htaccess
+/public/nginx.htaccess

+ 142 - 0
application/admin/controller/applys/Declarationauth.php

@@ -0,0 +1,142 @@
+<?php
+
+namespace app\admin\controller\applys;
+
+use app\common\controller\Backend;
+use think\Db;
+
+/**
+ * 用户交友宣言审核
+ *
+ * @icon fa fa-circle-o
+ */
+class Declarationauth extends Backend
+{
+    
+    /**
+     * Declarationauth模型对象
+     * @var \app\admin\model\applys\Declarationauth
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\applys\Declarationauth;
+        $this->view->assign("statusList", $this->model->getStatusList());
+    }
+
+    public function import()
+    {
+        parent::import();
+    }
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+    
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = true;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+
+            $list = $this->model
+                    ->with(['user'])
+                    ->where($where)
+                    ->order($sort, $order)
+                    ->paginate($limit);
+
+            foreach ($list as $row) {
+                
+                $row->getRelation('user')->visible(['username','nickname']);
+            }
+
+            $result = array("total" => $list->total(), "rows" => $list->items());
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    /**
+     * 编辑
+     */
+    public function edit($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds)) {
+            if (!in_array($row[$this->dataLimitField], $adminIds)) {
+                $this->error(__('You have no permission'));
+            }
+        }
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params = $this->preExcludeFields($params);
+                $result = false;
+                Db::startTrans();
+                try {
+                    if($row['status'] == 0 && $row['status'] != $params['status']) {
+                        if($params['status'] == 1) {
+                            \app\common\model\User::update(['declaration'=>$params['declaration']],['id'=>$params['user_id']]);
+                            $title = '交友宣言审核成功!';
+                            $content = '恭喜您,您的交友宣言修改审核成功!';
+                            \app\common\model\SysMsg::sendSysMsg($row['user_id'],8,$title,$content);
+                        }
+                        if($params['status'] == -1) {
+//                            \app\common\model\User::update(['declaration'=>$params['old_declaration']],['id'=>$params['user_id']]);
+                            $title = '交友宣言审核失败!';
+                            $content = '非常抱歉,您的交友宣言由于不符合平台规范,管理员已审核拒绝!';
+                            \app\common\model\SysMsg::sendSysMsg($row['user_id'],8,$title,$content);
+                        }
+                    }
+
+                    //是否采用模型验证
+                    if ($this->modelValidate) {
+                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
+                        $row->validateFailException(true)->validate($validate);
+                    }
+                    $result = $row->allowField(true)->save($params);
+                    delUserInfo($params['user_id']);
+                    Db::commit();
+                } catch (ValidateException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (PDOException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                if ($result !== false) {
+                    $this->success();
+                } else {
+                    $this->error(__('No rows were updated'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $this->view->assign("row", $row);
+        return $this->view->fetch();
+    }
+}

+ 15 - 0
application/admin/lang/zh-cn/applys/declarationauth.php

@@ -0,0 +1,15 @@
+<?php
+
+return [
+    'User_id'         => '用户ID',
+    'Declaration'     => '申请的交友宣言',
+    'Old_declaration' => '原交友宣言',
+    'Status'          => '状态',
+    'Status -1'       => '拒绝',
+    'Status 0'        => '待审核',
+    'Status 1'        => '已审核',
+    'Updatetime'      => '审核时间',
+    'Createtime'      => '创建时间',
+    'User.username'   => '用户名',
+    'User.nickname'   => '昵称'
+];

+ 53 - 0
application/admin/model/applys/Declarationauth.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace app\admin\model\applys;
+
+use think\Model;
+
+
+class Declarationauth extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'declaration_auth';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'status_text'
+    ];
+    
+
+    
+    public function getStatusList()
+    {
+        return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1')];
+    }
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
+        $list = $this->getStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+
+
+    public function user()
+    {
+        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+}

+ 27 - 0
application/admin/validate/applys/Declarationauth.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\validate\applys;
+
+use think\Validate;
+
+class Declarationauth extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+    ];
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'add'  => [],
+        'edit' => [],
+    ];
+    
+}

+ 40 - 0
application/admin/view/applys/declarationauth/add.html

@@ -0,0 +1,40 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Declaration')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-declaration" data-rule="required" class="form-control" name="row[declaration]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Old_declaration')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-old_declaration" data-rule="required" class="form-control" name="row[old_declaration]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            
+            <div class="radio">
+            {foreach name="statusList" item="vo"}
+            <label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="-1"}checked{/in} /> {$vo}</label> 
+            {/foreach}
+            </div>
+
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 40 - 0
application/admin/view/applys/declarationauth/edit.html

@@ -0,0 +1,40 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('用户昵称')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-user_id" disabled data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Declaration')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-declaration" data-rule="required" class="form-control" name="row[declaration]" type="text" value="{$row.declaration|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Old_declaration')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-old_declaration" data-rule="required" class="form-control" name="row[old_declaration]" type="text" value="{$row.old_declaration|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            
+            <div class="radio">
+            {foreach name="statusList" item="vo"}
+            <label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label> 
+            {/foreach}
+            </div>
+
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 45 - 0
application/admin/view/applys/declarationauth/index.html

@@ -0,0 +1,45 @@
+<div class="panel panel-default panel-intro">
+    
+    <div class="panel-heading">
+        {:build_heading(null,FALSE)}
+        <ul class="nav nav-tabs" data-field="status">
+            <li class="{:$Think.get.status === null ? 'active' : ''}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
+            {foreach name="statusList" item="vo"}
+            <li class="{:$Think.get.status === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
+            {/foreach}
+        </ul>
+    </div>
+
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                        <!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('declarationauth/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('declarationauth/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
+<!--                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('declarationauth/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
+<!--                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('declarationauth/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
+
+                       <!-- <div class="dropdown btn-group {:$auth->check('declarationauth/multi')?'':'hide'}">
+                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
+                            <ul class="dropdown-menu text-left" role="menu">
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
+                            </ul>
+                        </div>-->
+
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="{:$auth->check('applys/declarationauth/edit')}"
+                           data-operate-del="{:$auth->check('applys/declarationauth/del')}"
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 21 - 2
application/api/controller/User.php

@@ -627,13 +627,31 @@ class User extends Api
             } else {
                 $res1 = true;
             }
-            $declaration && $user->declaration = $declaration;
+            if($declaration) {
+                if (iconv_strlen($declaration, 'utf-8') > 64) {
+                    $this->error('交友宣言最多64位哦!');
+                }
+                $user->declaration_auth = $declaration;
+                // 添加交友宣言修改申请表
+                if(\app\common\model\DeclarationAuth::where(["status"=>0,"user_id"=>$this->auth->id])->find()) $this->error("交友宣言已在审核中!请勿重复申请");
+                $data = [];
+                $data['user_id'] = $this->auth->id;
+                $data['declaration'] = $declaration;
+                $data['old_declaration'] = $user->declaration;
+                $data['createtime'] = time();
+                $res3 = \app\common\model\DeclarationAuth::insert($data);
+            } else {
+                $res3 = true;
+            }
+//            $declaration && $user->declaration = $declaration;
             $res2 = $user->save();
-            if($res1 && $res2) {
+            if($res1 && $res2 && $res3) {
                 Db::commit();
                 delUserInfo($this->auth->id);
                 if($wechat) {
                     $this->success("微信号修改申请已提交,请耐心等待审核!");
+                } elseif ($declaration) {
+                    $this->success("交友宣言修改申请已提交,请耐心等待审核!");
                 } else {
                     $this->success("修改成功!");
                 }
@@ -958,6 +976,7 @@ class User extends Api
         $userInfo['nickname_auth_stauts'] = \app\common\model\NicknameAuth::getAuthStatus($userInfo['id'],$userInfo['nickname_auth']);
         $userInfo['avatar_auth_stauts'] = \app\common\model\AvatarAuth::getAuthStatus($userInfo['id'],$userInfo['avatar_auth']);
         $userInfo['wechat_auth_stauts'] = \app\common\model\WechatAuth::getAuthStatus($userInfo['id'],$userInfo['wechat_auth']);
+        $userInfo['declaration_auth_stauts'] = \app\common\model\DeclarationAuth::getAuthStatus($userInfo['id'],$userInfo['declaration_auth']);
 
 
 //            $userInfo = $userInfo->toArray();

+ 20 - 0
application/common/model/DeclarationAuth.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 昵称审核
+ */
+class DeclarationAuth Extends Model
+{
+
+    public static function getAuthStatus($user_id,$nickname) {
+        $status = self::where(['user_id'=>$user_id,'wechat'=>$nickname])->order("createtime","desc")->value("status");
+        if(!in_array($status,[-1,1]) && $status !== 0) {
+            $status = 1;
+        }
+        return $status;
+    }
+}

+ 77 - 0
public/assets/js/backend/applys/declarationauth.js

@@ -0,0 +1,77 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'applys/declarationauth/index' + location.search,
+                    add_url: 'applys/declarationauth/add',
+                    edit_url: 'applys/declarationauth/edit',
+                    del_url: 'applys/declarationauth/del',
+                    multi_url: 'applys/declarationauth/multi',
+                    import_url: 'applys/declarationauth/import',
+                    table: 'declaration_auth',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'user_id', title: __('User_id')},
+                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
+                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
+                        {field: 'declaration', title: __('Declaration'), operate: 'LIKE'},
+                        {field: 'old_declaration', title: __('Old_declaration'), operate: 'LIKE'},
+                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
+                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
+                            buttons:[
+                                {
+                                    name: 'edit',
+                                    text: '同意',
+                                    icon: 'fa fa-pencil',
+                                    title: __('Edit'),
+                                    extend: 'data-toggle="tooltip"',
+                                    classname: 'btn btn-xs btn-success btn-editone'
+                                }, {
+                                    name: 'del',
+                                    text: '拒绝',
+                                    icon: 'fa fa-trash',
+                                    title: __('Del'),
+                                    extend: 'data-toggle="tooltip"',
+                                    classname: 'btn btn-xs btn-danger btn-delone'
+                                },
+                            ]
+
+                        }
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});