wupengfei 2 years ago
parent
commit
1bad12249f

+ 183 - 0
application/nutrition/controller/SeriesDatum.php

@@ -0,0 +1,183 @@
+<?php
+namespace app\Nutrition\controller;
+use app\common\model\datum_idIntro;
+use app\common\model\datum_idUrl;
+use app\common\model\DatumIntro;
+use app\common\model\DatumUrl;
+use library\Controller;
+use library\tools\Data;
+use think\Db;
+use app\common\model\DatumCate;
+/**
+ * 资料管理
+ * Class OneDatum
+ * @package app\Nutrition\controller
+ */
+class SeriesDatum extends Controller
+{
+
+    /**
+     * 绑定数据表
+     * @var string
+     */
+    protected $table = 'DatumIntro';
+
+
+    /**
+     * 列表
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function index()
+    {
+        $this->title = '资料列表';
+        $datum_cate = DatumCate::field('id,title')->select()->toArray();
+        $this->datum_cate = array_column($datum_cate,null,'id');
+        $sel_where = [];
+        $sel_where[] = ['is_deleted','=',0];
+        $sel_where[] = ['type','=',2];
+        if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%'];
+        $query = $this->_query($this->table);
+        $query->where($sel_where)->order('status desc ,is_top desc ,sort desc,id desc')->page();
+    }
+
+    /**
+     * 数据列表处理
+     * @auth true
+     * @menu true
+     * @param array $data
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    protected function _index_page_filter(&$data)
+    {
+
+
+    }
+
+
+
+    /**
+     * 添加
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function add()
+    {
+        $this->title = '添加资料';
+        $this->type = input('get.type',2);
+        $this->_form($this->table, 'form');
+    }
+
+
+    /**
+     * 编辑
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function edit()
+    {
+        $this->title = '编辑资料';
+        $this->type = input('get.type',2);
+        $this->_form($this->table, 'form') ;
+    }
+
+    /**
+     * 禁用
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function forbidden()
+    {
+        $this->_save($this->table, ['status' => '0']);
+    }
+
+    /**
+     * 启用
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function enable()
+    {
+        $this->_save($this->table, ['status' => 1]);
+    }
+
+
+
+
+    /**
+     * 删除资料
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function del()
+    {
+        $this->_save($this->table, ['is_deleted' => 1]);
+    }
+
+
+    /**
+     * 表单数据处理
+     * @auth true
+     * @menu true
+     * @param array $data
+     */
+    protected function _form_filter(&$data)
+    {
+        if($this->request->isGet()){
+            $this->datum_cate = DatumCate::column('id,title,is_vip','id');
+        }
+
+        if($this->request->isPost()) {
+
+        }
+    }
+
+    protected function  _form_result($result){
+        if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) {
+            $datum_info = DatumIntro::where('id',$result)->find()->toArray();
+            $datum_url = [
+                'datum_id' => $result,
+                'url' => $datum_info['datum_url'],
+                'sort' => $datum_info['sort'],
+                'is_deleted' => 0,
+                'is_vip' => $datum_info['is_vip'],
+                'source' => 1,
+                'title' => $datum_info['title'],
+            ];
+            Data::save('DatumUrl',$datum_url,'datum_id',['datum_id' => $result]);
+        }
+    }
+
+}

+ 62 - 0
application/nutrition/view/series_datum/form.html

@@ -0,0 +1,62 @@
+<div class="think-box-shadow">
+    <form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
+        <div class="layui-card-body">
+
+            <div class="layui-form-item">
+                <label class="layui-form-label label-required">标题</label>
+                <div class="layui-input-block">
+                    <input name="title" maxlength="20"  value='{$vo.title|default=""}' placeholder="请输入标题" class="layui-input">
+                </div>
+            </div>
+
+            <div class="layui-form-item">
+                <label class="layui-form-label label-required">文件</label>
+
+                <label class="layui-col-xs10 relative">
+                    <label class="layui-col-xs9 think-form-group-left">
+                        <input name="datum_url" value='{$vo.datum_url|default=""}'  readonly placeholder="请上传" class="layui-input">
+                    </label>
+                    <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
+                </label>
+            </div>
+
+            <div class="layui-form-item">
+                <label class="layui-form-label label-required">是否VIP</label>
+                <div class="layui-input-block">
+                    <select class="layui-select" name="is_vip">
+                        <option    value="0">否</option>
+                        <option   {if !empty($vo.is_vip) &&  $vo.is_vip == 1 }selected{/if}  value="1">是</option>
+                    </select>
+                </div>
+            </div>
+
+            {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
+            <div class="layui-form-item text-center">
+                <button class="layui-btn" type='submit'>保 存</button>
+                <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定取消编辑吗?" data-close>取消编辑</button>
+            </div>
+        </div>
+    </form>
+    <script src="/static/plugs/layui/layui.all.js" charset="utf-8"></script>
+    <script>
+
+        window.form.render();
+
+        layui.use(['upload', 'element', 'layer'], function(){
+            var $ = layui.jquery
+                ,upload = layui.upload
+                ,element = layui.element
+                ,layer = layui.layer;
+            upload.render({
+                elem: '#test3',
+                url: '/api/upload/upload', //此处用的是第三方的 http 请求演示,实际使用时改成您自己的上传接口即可。,accept: 'file', //普通文件,
+                accept: 'file', //普通文件,
+                done: function(res){
+                    console.log(res)
+                    $("input[name='datum_url']").val(res.data);
+                    layer.msg(re.msg);
+                }
+            });
+        });
+    </script>
+</div>

+ 67 - 0
application/nutrition/view/series_datum/index.html

@@ -0,0 +1,67 @@
+{extend name='admin@main'}
+{block name="button"}
+<button data-modal='{:url("add")}' data-title="添加" class='layui-btn layui-btn-sm layui-btn-primary'>添加</button>
+{/block}
+{block name="content"}
+<div class="think-box-shadow">
+    <table class="layui-table margin-top-20" lay-skin="line">
+        <thead>
+        <tr>
+            <th class='text-left nowrap'>ID</th>
+            <th class='text-left nowrap'>标题</th>
+            <th class='text-left nowrap'>文件</th>
+            <th class='text-left nowrap'>是否VIP</th>
+            <th class="text-left" style="width: 20%">操作</th>
+        </tr>
+        </thead>
+        <tbody>
+        {foreach $list as $key=>$vo}
+        <tr>
+            <td class='text-left nowrap'>{$vo.id|default=''}</td>
+            <td class='text-left nowrap'>{$vo.title|default=''}</td>
+            <td class='text-left nowrap'>{$vo.datum_url|default=''}</td>
+            <td class='text-left nowrap'>{$vo.is_vip ? '是':'否'}</td>
+            <td class='text-left' style="width: 20%">
+                <a data-title="编辑" class="layui-btn layui-btn-xs" data-modal='{:url("edit")}?id={$vo.id}'>编 辑</a>
+                {if $vo.status eq 1 }
+                <a class="layui-btn layui-btn-warm layui-btn-xs" data-confirm="确定要禁用目录吗?" data-action="{:url('forbid')}" data-value="id#{$vo.id};status#0" data-csrf="{:systoken('forbid')}">禁 用</a>
+                {else}
+                <a class="layui-btn layui-btn-warm layui-btn-xs" data-action="{:url('resume')}" data-value="id#{$vo.id};status#1" data-csrf="{:systoken('resume')}">启 用</a>
+                {/if}
+                <a class="layui-btn layui-btn-danger layui-btn-xs" data-confirm="确定要删除数据吗?" data-action="{:url('remove')}" data-value="id#{$vo.id}" data-csrf="{:systoken('remove')}">删 除</a>
+            </td>
+        </tr>
+        {/foreach}
+        </tbody>
+    </table>
+
+
+
+    {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
+</div>
+<script>
+    function btn_confirm(msg,fun,id) {
+        layer.confirm('请确定是否'+msg, {btn: ['确定', '取消'], title: "提示"}, function () {
+            var url = "/nutrition/series_datum/"+fun;
+            layer.closeAll();
+            $.ajax({
+                type: "post",
+                url: url,
+                data: {id:id},
+                dataType: "json",
+                async: false,
+                success: function (data) {
+                    layer.msg(data.info);
+                    setTimeout(function () {
+                        window.location.reload();
+                    },1000)
+                }
+            });
+        });
+    }
+
+</script>
+{/block}
+
+
+

+ 16 - 0
application/nutrition/view/series_datum/index_search.html

@@ -0,0 +1,16 @@
+<fieldset>
+    <legend>条件搜索</legend>
+    <form class="layui-form layui-form-pane form-search" action="{:request()->url()}" onsubmit="return false" method="get" autocomplete="off">
+        <div class="layui-form-item layui-inline">
+            <label class="layui-form-label">目录名称</label>
+            <div class="layui-input-inline">
+                <input name="title" value="{$Think.get.title|default=''}" placeholder="请输入目录名称" class="layui-input">
+            </div>
+        </div>
+
+        <div class="layui-form-item layui-inline">
+            <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
+        </div>
+    </form>
+    <script>form.render()</script>
+</fieldset>