Browse Source

用户关注

lizhen_gitee 3 years ago
parent
commit
ced1cfd082

+ 75 - 0
application/admin/controller/Userfollow.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\common\controller\Backend;
+
+/**
+ * 用户关注管理
+ *
+ * @icon fa fa-circle-o
+ */
+class Userfollow extends Backend
+{
+    
+    /**
+     * Userfollow模型对象
+     * @var \app\admin\model\Userfollow
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\Userfollow;
+
+    }
+
+    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','followuser'])
+                    ->where($where)
+                    ->order($sort, $order)
+                    ->paginate($limit);
+
+            foreach ($list as $row) {
+                
+                $row->getRelation('user')->visible(['username']);
+				$row->getRelation('followuser')->visible(['username']);
+            }
+
+            $result = array("total" => $list->total(), "rows" => $list->items());
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+}

+ 11 - 0
application/admin/lang/zh-cn/userfollow.php

@@ -0,0 +1,11 @@
+<?php
+
+return [
+    'Id'            => 'ID',
+    'Uid'           => '关注者uid',
+    'Follow_uid'    => '被关注用户uid',
+    'Createtime'    => '创建时间',
+    'Updatetime'    => '更新时间',
+    'User.username' => '用户名',
+    'Followuser.username' => '被关注用户名'
+];

+ 50 - 0
application/admin/model/Userfollow.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class Userfollow extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'user_follow';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+
+    ];
+    
+
+    
+
+
+
+
+
+
+
+    public function user()
+    {
+        return $this->belongsTo('User', 'uid', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function followuser()
+    {
+        return $this->belongsTo('User', 'follow_uid', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+}

+ 27 - 0
application/admin/validate/Userfollow.php

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

+ 22 - 0
application/admin/view/userfollow/add.html

@@ -0,0 +1,22 @@
+<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">{:__('Uid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-uid" class="form-control" name="row[uid]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Follow_uid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-follow_uid" class="form-control" name="row[follow_uid]" type="number" value="0">
+        </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>

+ 22 - 0
application/admin/view/userfollow/edit.html

@@ -0,0 +1,22 @@
+<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">{:__('Uid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-uid" class="form-control" name="row[uid]" type="number" value="{$row.uid|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Follow_uid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-follow_uid" class="form-control" name="row[follow_uid]" type="number" value="{$row.follow_uid|htmlentities}">
+        </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>

+ 35 - 0
application/admin/view/userfollow/index.html

@@ -0,0 +1,35 @@
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+
+    <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('userfollow/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('userfollow/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('userfollow/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('userfollow/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('userfollow/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('userfollow/edit')}" 
+                           data-operate-del="{:$auth->check('userfollow/del')}" 
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 56 - 0
application/api/controller/Userfollow.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 关注
+ */
+class Userfollow extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    //关注某人
+    public function follow_one(){
+        $follow_uid = input('follow_uid',0);
+        if(!$follow_uid){
+            $this->error(__('Invalid parameters'));
+        }
+
+        $map = [
+            'uid' => $this->auth->id,
+            'follow_uid' => $follow_uid,
+        ];
+
+        $check = Db::name('user_follow')->where($map)->find();
+        if($check){
+            $this->success('success');
+        }
+
+        $map['createtime'] = time();
+        $map['updatetime'] = time();
+        $id = Db::name('user_follow')->insertGetId($map);
+
+        $this->success('success',$id);
+    }
+
+    //取关某人
+    public function un_follow_one(){
+        $follow_uid = input('follow_uid',0);
+        if(!$follow_uid){
+            $this->error(__('Invalid parameters'));
+        }
+
+        $map = [
+            'uid' => $this->auth->id,
+            'follow_uid' => $follow_uid,
+        ];
+
+        //不检查,全删
+
+        $rs = Db::name('user_follow')->where($map)->delete();
+        $this->success('success');
+    }
+}

+ 8 - 8
application/common/model/WalletLog.php

@@ -37,10 +37,10 @@ class WalletLog
      * @param string $wallet_name 指定钱包名
      * @return array|float
      */
-    public function getWallet($uid = '', $wallet_name = '')
+    public function getWallet($id = '', $wallet_name = '')
     {
         //所有钱包余额
-        $wallet = Db::name('user')->where(['uid' => $uid])->field('uid,username,money,score')->find();
+        $wallet = Db::name('user')->where(['id' => $id])->field('id,username,money,score')->find();
         if(!$wallet) {
             abort(500,'钱包余额获取失败');
         }
@@ -58,8 +58,8 @@ class WalletLog
      * @param $accountType 货币类型,money,score
      * @param $logtype 日志的类型
      * @param $remark  备注
-     * @param $uid  用户id
-     * @param $data_id  表id
+     * @param $user_id  用户id
+     * @param $table_id  表id
      * @param $table  来源表
      * @param $isAdmin 是否是管理员处理
      * @return array
@@ -92,7 +92,7 @@ class WalletLog
             $result['msg'] = '交易金额:0';
             return $result;
         }
-        $wallet = Db::name('user')->lock(true)->where(['uid'=>$user_id])->find();
+        $wallet = Db::name('user')->lock(true)->where(['id'=>$user_id])->find();
 
         //检测
         if(!$wallet)
@@ -115,7 +115,7 @@ class WalletLog
 
                 //钱币记录
                 $data = array();
-                $data['uid'] = $user_id;
+                $data['user_id'] = $user_id;
                 $data['log_type'] = $logtype;
                 $data['money_type'] = $accountType;
                 $data['change_value'] = $number;
@@ -135,9 +135,9 @@ class WalletLog
 
                 //新的方式
                 if(bccomp($number, 0) === 1){
-                    $rs1 = Db::name('user')->where(['uid'=>$wallet['uid']])->setInc($accountType,$number);
+                    $rs1 = Db::name('user')->where(['id'=>$wallet['id']])->setInc($accountType,$number);
                 }else{
-                    $rs1 = Db::name('user')->where(['uid'=>$wallet['uid']])->setDec($accountType,abs($number));
+                    $rs1 = Db::name('user')->where(['id'=>$wallet['id']])->setDec($accountType,abs($number));
                 }
 
 

+ 56 - 0
public/assets/js/backend/userfollow.js

@@ -0,0 +1,56 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'userfollow/index' + location.search,
+                    add_url: 'userfollow/add',
+                    edit_url: 'userfollow/edit',
+                    del_url: 'userfollow/del',
+                    multi_url: 'userfollow/multi',
+                    import_url: 'userfollow/import',
+                    table: 'user_follow',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'uid', title: __('Uid')},
+                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
+                        {field: 'follow_uid', title: __('Follow_uid')},
+                        {field: 'followuser.username', title: __('Followuser.username'), operate: 'LIKE'},
+                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'updatetime', title: __('Updatetime'), 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}
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            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;
+});