WIN-2308041133\Administrator 8 months ago
parent
commit
8ba72efbbf

+ 69 - 0
application/admin/controller/third/Platform.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace app\admin\controller\third;
+
+use app\common\controller\Backend;
+
+class Platform extends Backend
+{
+    // 模型对象
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\third\Platform;
+    }
+
+    // 列表页
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+            $total = $this->model
+                ->where($where)
+                ->order($sort, $order)
+                ->count();
+            $list = $this->model
+                ->where($where)
+                ->order($sort, $order)
+                ->limit($offset, $limit)
+                ->select();
+            $result = [
+                "total" => $total,
+                "rows" => $list,
+            ];
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    // 添加/编辑
+    public function add()
+    {
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params['createtime'] = time(); // 自动填充时间戳
+                $result = $this->model->save($params);
+                if ($result) {
+                    $this->success();
+                } else {
+                    $this->error(__('Operation failed'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        return $this->view->fetch();
+    }
+
+    // 删除
+    public function del($ids = "")
+    {
+        if ($ids) {
+            $this->model->destroy($ids);
+            $this->success();
+        }
+        $this->error(__('Parameter %s can not be empty', 'ids'));
+    }
+}

+ 22 - 0
application/admin/model/third/Platform.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace app\admin\model\third;
+
+use think\Model;
+
+class Platform extends Model
+{
+    // 表名
+    protected $name = '第三方平台列表';
+
+    // 自动写入时间戳字段(createtime 为 int 类型)
+    protected $autoWriteTimestamp = 'int';
+    protected $createTime = 'createtime';
+    protected $updateTime = false;
+
+    // 字段格式化(将 createtime 转换为日期格式)
+    public function getCreatetimeAttr($value)
+    {
+        return date('Y-m-d H:i:s', $value);
+    }
+}

+ 22 - 0
application/admin/view/third/platform/add.html

@@ -0,0 +1,22 @@
+{extend name="../../layout/view.html" /}
+
+{block name="content"}
+<div class="panel panel-default">
+  <div class="panel-heading">添加平台</div>
+  <div class="panel-body">
+    <form class="form-horizontal" method="post">
+      <div class="form-group">
+        <label class="col-sm-2 control-label">平台名称</label>
+        <div class="col-sm-8">
+          <input type="text" name="row[name]" class="form-control" required>
+        </div>
+      </div>
+      <div class="form-group">
+        <div class="col-sm-8 col-sm-offset-2">
+          <button type="submit" class="btn btn-primary">提交</button>
+        </div>
+      </div>
+    </form>
+  </div>
+</div>
+{/block}

+ 37 - 0
application/admin/view/third/platform/index.html

@@ -0,0 +1,37 @@
+{extend name="../../layout/view.html" /}
+
+{block name="content"}
+<div class="panel panel-default">
+  <div class="panel-heading">
+    <span class="panel-title">第三方平台列表</span>
+    <div class="pull-right">
+      <a href="{:url('add')}" class="btn btn-primary btn-xs"><i class="fa fa-plus"></i> 添加</a>
+    </div>
+  </div>
+  <div class="panel-body">
+    <table id="bootstrap-table" class="table table-hover">
+      <thead>
+      <tr>
+        <th>ID</th>
+        <th>平台名称</th>
+        <th>创建时间</th>
+        <th>操作</th>
+      </tr>
+      </thead>
+      <tbody>
+      {volist name="list" id="vo"}
+      <tr>
+        <td>{$vo.id}</td>
+        <td>{$vo.name}</td>
+        <td>{$vo.createtime}</td>
+        <td>
+          <a href="{:url('edit', ['id' => $vo.id])}" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i> 编辑</a>
+          <a href="javascript:;" data-url="{:url('del')}" data-id="{$vo.id}" class="btn btn-xs btn-danger btn-del"><i class="fa fa-trash"></i> 删除</a>
+        </td>
+      </tr>
+      {/volist}
+      </tbody>
+    </table>
+  </div>
+</div>
+{/block}