瀏覽代碼

用户装扮管理

lizhen_gitee 3 年之前
父節點
當前提交
ab52804d5c

+ 76 - 0
application/admin/controller/Userdecorate.php

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

+ 20 - 0
application/admin/lang/zh-cn/userdecorate.php

@@ -0,0 +1,20 @@
+<?php
+
+return [
+    'Id'              => 'ID',
+    'User_id'         => '用户ID',
+    'Decorate_id'     => '装扮ID',
+    'Decorate_type'   => '类型',
+    'Decorate_type 1' => '座驾',
+    'Decorate_type 2' => '头饰',
+    'Decorate_type 3' => '尾灯',
+    'Decorate_type 4' => '气泡',
+    'Is_using'        => '状态',
+    'Is_using 1'      => '使用中',
+    'Is_using 0'      => '未使用',
+    'End_time'        => '结束时间',
+    'Createtime'      => '创建时间',
+    'Updatetime'      => '更新时间',
+    'Decorate.name'   => '名称',
+    'User.username'   => '用户名'
+];

+ 84 - 0
application/admin/model/Userdecorate.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class Userdecorate extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'user_decorate';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'decorate_type_text',
+        'is_using_text',
+        'end_time_text'
+    ];
+    
+
+    
+    public function getDecorateTypeList()
+    {
+        return ['1' => __('Decorate_type 1'), '2' => __('Decorate_type 2'), '3' => __('Decorate_type 3'), '4' => __('Decorate_type 4')];
+    }
+
+    public function getIsUsingList()
+    {
+        return ['1' => __('Is_using 1'), '0' => __('Is_using 0')];
+    }
+
+
+    public function getDecorateTypeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['decorate_type']) ? $data['decorate_type'] : '');
+        $list = $this->getDecorateTypeList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getIsUsingTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['is_using']) ? $data['is_using'] : '');
+        $list = $this->getIsUsingList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getEndTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+    protected function setEndTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+
+    public function decorate()
+    {
+        return $this->belongsTo('Decorate', 'decorate_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function user()
+    {
+        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+}

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

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

+ 52 - 0
application/admin/view/userdecorate/add.html

@@ -0,0 +1,52 @@
+<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">{:__('Decorate_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-decorate_id" data-rule="required" data-source="decorate/index" class="form-control selectpage" name="row[decorate_id]" type="text" value="">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Decorate_type')}:</label>
+        <div class="col-xs-12 col-sm-8">
+                        
+            <select  id="c-decorate_type" class="form-control selectpicker" name="row[decorate_type]">
+                {foreach name="decorateTypeList" item="vo"}
+                    <option value="{$key}" {in name="key" value="1"}selected{/in}>{$vo}</option>
+                {/foreach}
+            </select>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Is_using')}:</label>
+        <div class="col-xs-12 col-sm-8">
+                        
+            <select  id="c-is_using" class="form-control selectpicker" name="row[is_using]">
+                {foreach name="isUsingList" item="vo"}
+                    <option value="{$key}" {in name="key" value="0"}selected{/in}>{$vo}</option>
+                {/foreach}
+            </select>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-end_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="{:date('Y-m-d H:i:s')}">
+        </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>

+ 52 - 0
application/admin/view/userdecorate/edit.html

@@ -0,0 +1,52 @@
+<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">{:__('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="{$row.user_id|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Decorate_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-decorate_id" data-rule="required" data-source="decorate/index" class="form-control selectpage" name="row[decorate_id]" type="text" value="{$row.decorate_id|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Decorate_type')}:</label>
+        <div class="col-xs-12 col-sm-8">
+                        
+            <select  id="c-decorate_type" class="form-control selectpicker" name="row[decorate_type]">
+                {foreach name="decorateTypeList" item="vo"}
+                    <option value="{$key}" {in name="key" value="$row.decorate_type"}selected{/in}>{$vo}</option>
+                {/foreach}
+            </select>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Is_using')}:</label>
+        <div class="col-xs-12 col-sm-8">
+                        
+            <select  id="c-is_using" class="form-control selectpicker" name="row[is_using]">
+                {foreach name="isUsingList" item="vo"}
+                    <option value="{$key}" {in name="key" value="$row.is_using"}selected{/in}>{$vo}</option>
+                {/foreach}
+            </select>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-end_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="{:$row.end_time?datetime($row.end_time):''}">
+        </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/userdecorate/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('userdecorate/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('userdecorate/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('userdecorate/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('userdecorate/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('userdecorate/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('userdecorate/edit')}" 
+                           data-operate-del="{:$auth->check('userdecorate/del')}" 
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 59 - 0
public/assets/js/backend/userdecorate.js

@@ -0,0 +1,59 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'userdecorate/index' + location.search,
+                    add_url: 'userdecorate/add',
+                    edit_url: 'userdecorate/edit',
+                    del_url: 'userdecorate/del',
+                    multi_url: 'userdecorate/multi',
+                    import_url: 'userdecorate/import',
+                    table: 'user_decorate',
+                }
+            });
+
+            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: 'decorate_id', title: __('Decorate_id')},
+                        {field: 'decorate_type', title: __('Decorate_type'), searchList: {"1":__('Decorate_type 1'),"2":__('Decorate_type 2'),"3":__('Decorate_type 3'),"4":__('Decorate_type 4')}, formatter: Table.api.formatter.normal},
+                        {field: 'is_using', title: __('Is_using'), searchList: {"1":__('Is_using 1'),"0":__('Is_using 0')}, formatter: Table.api.formatter.normal},
+                        {field: 'end_time', title: __('End_time'), 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: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'decorate.name', title: __('Decorate.name'), operate: 'LIKE'},
+                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
+//                        {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;
+});