后台优化
This commit is contained in:
68
application/common/controller/DashboardBase.php
Normal file
68
application/common/controller/DashboardBase.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* 系统概览公共控制器
|
||||
* 提供统一的业务逻辑,供admin和adminghd模块继承使用
|
||||
*/
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\common\BaseController;
|
||||
use think\Db;
|
||||
|
||||
class DashboardBase extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取统计数据
|
||||
*/
|
||||
public function getStatistics()
|
||||
{
|
||||
try {
|
||||
// 获取表名
|
||||
$userTable = $this->getTableName('user');
|
||||
$infoTable = $this->getTableName('real_time_info');
|
||||
$recordTable = $this->getTableName('calculate_record');
|
||||
|
||||
// 小程序注册用户数量
|
||||
$userCount = Db::name($userTable)->count();
|
||||
|
||||
// 首页资讯数量
|
||||
$infoCount = Db::name($infoTable)->count();
|
||||
|
||||
// 最近一次计算时间
|
||||
$lastCalculate = Db::name($recordTable)
|
||||
->order('create_time desc')
|
||||
->value('create_time');
|
||||
|
||||
// 今日新增用户
|
||||
$todayUserCount = Db::name($userTable)
|
||||
->whereTime('create_time', 'today')
|
||||
->count();
|
||||
|
||||
// 总计算次数
|
||||
$totalCalculateCount = Db::name($recordTable)->count();
|
||||
|
||||
return json([
|
||||
'status' => 1,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'user_count' => $userCount,
|
||||
'info_count' => $infoCount,
|
||||
'last_calculate_time' => $lastCalculate ?: '暂无',
|
||||
'today_user_count' => $todayUserCount,
|
||||
'total_calculate_count' => $totalCalculateCount
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'status' => 0,
|
||||
'msg' => '获取失败:' . $e->getMessage(),
|
||||
'data' => [
|
||||
'user_count' => 0,
|
||||
'info_count' => 0,
|
||||
'last_calculate_time' => '暂无',
|
||||
'today_user_count' => 0,
|
||||
'total_calculate_count' => 0
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
100
application/common/controller/WechatinfroBase.php
Normal file
100
application/common/controller/WechatinfroBase.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* 微信用户信息管理公共控制器
|
||||
* 提供统一的业务逻辑,供admin和adminghd模块继承使用
|
||||
*/
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\common\BaseController;
|
||||
use think\Request;
|
||||
use think\Db;
|
||||
|
||||
class WechatinfroBase extends BaseController
|
||||
{
|
||||
/**
|
||||
* 查看小程序注册用户信息
|
||||
* @author hjc
|
||||
* @date 2024-05-14
|
||||
*/
|
||||
public function getWechatUserList(Request $request)
|
||||
{
|
||||
$post = $request->param();
|
||||
|
||||
$page = isset($post['page']) && !empty($post['page']) ? $post['page'] : 1; // 页数
|
||||
$page_size = isset($post['page_size']) && !empty($post['page_size']) ? $post['page_size'] : 30; // 每页条数
|
||||
|
||||
// 搜索
|
||||
$where = [];
|
||||
if (isset($post['title']) && !empty($post['title'])) {
|
||||
$where['nickname'] = ['like', '%' . $post['title'] . '%'];
|
||||
}
|
||||
|
||||
// 获取用户表名
|
||||
$tableName = $this->getTableName('user');
|
||||
|
||||
// 升序获取菜单列表
|
||||
$res = Db::name($tableName)
|
||||
->field('uid,nickname,headimg,create_time')
|
||||
->where($where)
|
||||
->order('create_time desc')
|
||||
->paginate($page_size, false, ['page' => $page]);
|
||||
|
||||
$lists = $res->items();
|
||||
$start = ($page - 1) * $page_size;
|
||||
foreach ($lists as $k => $v) {
|
||||
$start += 1;
|
||||
$lists[$k]['no_id'] = $start;
|
||||
}
|
||||
|
||||
$result['lists'] = $lists;
|
||||
$result['lastPage'] = $res->lastPage(); // 总页数
|
||||
$result['currentPage'] = $res->currentPage(); // 当前页
|
||||
$result['erro'] = 0;
|
||||
$result['msg'] = '查询成功';
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看小程序记录
|
||||
* @author hjc
|
||||
* @date 2024-05-14
|
||||
*/
|
||||
public function getWechatRecordList(Request $request)
|
||||
{
|
||||
$post = $request->param();
|
||||
|
||||
$page = isset($post['page']) && !empty($post['page']) ? $post['page'] : 1; // 页数
|
||||
$page_size = isset($post['page_size']) && !empty($post['page_size']) ? $post['page_size'] : 30; // 每页条数
|
||||
|
||||
// 搜索
|
||||
$where = [];
|
||||
if (isset($post['title']) && !empty($post['title'])) {
|
||||
$where['name'] = ['like', '%' . $post['title'] . '%'];
|
||||
}
|
||||
|
||||
// 获取计算记录表名
|
||||
$tableName = $this->getTableName('calculate_record');
|
||||
|
||||
// 查询列表
|
||||
$res = Db::name($tableName)
|
||||
->field('id,name,age,height,bone_age,father_height,mother_height,IGF,LH,uterus_thickness,calculate_resutlt,create_time')
|
||||
->where($where)
|
||||
->order('create_time desc')
|
||||
->paginate($page_size, false, ['page' => $page]);
|
||||
|
||||
$lists = $res->items();
|
||||
$start = ($page - 1) * $page_size;
|
||||
foreach ($lists as $k => $v) {
|
||||
$start += 1;
|
||||
$lists[$k]['no_id'] = $start;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result['lists'] = $lists;
|
||||
$result['lastPage'] = $res->lastPage(); // 总页数
|
||||
$result['currentPage'] = $res->currentPage(); // 当前页
|
||||
$result['erro'] = 0;
|
||||
$result['msg'] = '查询成功';
|
||||
return json($result);
|
||||
}
|
||||
}
|
||||
169
application/common/controller/WechatsetBase.php
Normal file
169
application/common/controller/WechatsetBase.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* 微信设置管理公共控制器
|
||||
* 提供统一的业务逻辑,供admin和adminghd模块继承使用
|
||||
*/
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\common\BaseController;
|
||||
use think\Request;
|
||||
use think\Db;
|
||||
|
||||
class WechatsetBase extends BaseController
|
||||
{
|
||||
/**
|
||||
* 查询小程序资讯信息
|
||||
* @author hjc
|
||||
* @date 2024-05-14
|
||||
*/
|
||||
public function getWechatRealTimeInfoList(Request $request)
|
||||
{
|
||||
$post = $request->param();
|
||||
|
||||
$page = isset($post['page']) && !empty($post['page']) ? $post['page'] : 1; // 页数
|
||||
$page_size = isset($post['page_size']) && !empty($post['page_size']) ? $post['page_size'] : 30; // 每页条数
|
||||
|
||||
// 搜索
|
||||
$where = [];
|
||||
if (isset($post['title']) && !empty($post['title'])) {
|
||||
$where['title_plain'] = ['like', '%' . $post['title'] . '%'];
|
||||
}
|
||||
|
||||
// 获取资讯表名
|
||||
$tableName = $this->getTableName('real_time_info');
|
||||
|
||||
// 升序获取菜单列表
|
||||
$res = Db::name($tableName)
|
||||
->field('id,title_plain,thumbnail,excerpt_plain,url,create_time')
|
||||
->where($where)
|
||||
->order('create_time desc')
|
||||
->paginate($page_size, false, ['page' => $page]);
|
||||
|
||||
$lists = $res->items();
|
||||
$start = ($page - 1) * $page_size;
|
||||
foreach ($lists as $k => $v) {
|
||||
$start += 1;
|
||||
$lists[$k]['no_id'] = $start;
|
||||
}
|
||||
|
||||
$result['lists'] = $lists;
|
||||
$result['lastPage'] = $res->lastPage(); // 总页数
|
||||
$result['currentPage'] = $res->currentPage(); // 当前页
|
||||
$result['erro'] = 0;
|
||||
$result['msg'] = '查询成功';
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除小程序资讯信息
|
||||
* @author hjc
|
||||
* @date 2024-05-14
|
||||
*/
|
||||
public function delWechatRealTimeInfo(Request $request)
|
||||
{
|
||||
$post = $request->param();
|
||||
if (!isset($post['id']) || empty($post['id'])) {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = "请选择要删除的记录";
|
||||
return json($result);
|
||||
}
|
||||
|
||||
$tableName = $this->getTableName('real_time_info');
|
||||
$id = Db::name($tableName)->where('id', $post['id'])->value('id');
|
||||
|
||||
if (empty($id)) {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = "该记录异常,无法删除";
|
||||
return json($result);
|
||||
}
|
||||
|
||||
$res = Db::name($tableName)->where('id', $id)->delete();
|
||||
if ($res > 0) {
|
||||
$result['erro'] = 0;
|
||||
$result['msg'] = '删除成功';
|
||||
} else {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = '删除失败';
|
||||
}
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存小程序资讯信息
|
||||
* @author hjc
|
||||
*/
|
||||
public function saveWechatRealTimeInfo(Request $request)
|
||||
{
|
||||
$post = $request->param();
|
||||
|
||||
if (!isset($post['title_plain']) || empty($post['title_plain'])) {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = "未传入标题";
|
||||
return json($result);
|
||||
}
|
||||
if (!isset($post['thumbnail']) || empty($post['thumbnail'])) {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = "未传入图片";
|
||||
return json($result);
|
||||
}
|
||||
if (!isset($post['excerpt_plain']) || empty($post['excerpt_plain'])) {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = "未传入简介";
|
||||
return json($result);
|
||||
}
|
||||
if (!isset($post['url']) || empty($post['url'])) {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = "未传入资讯跳转链接";
|
||||
return json($result);
|
||||
}
|
||||
|
||||
// 提交数据
|
||||
$data = [];
|
||||
$data['title_plain'] = $post['title_plain']; // 标题
|
||||
$data['thumbnail'] = $post['thumbnail']; // 图片
|
||||
$data['excerpt_plain'] = $post['excerpt_plain']; // 介绍
|
||||
$data['url'] = $post['url']; // 跳转连接
|
||||
|
||||
$tableName = $this->getTableName('real_time_info');
|
||||
|
||||
if (isset($post['id']) && !empty($post['id'])) {
|
||||
// 修改数据
|
||||
$res = Db::name($tableName)->where('id', $post['id'])->update($data);
|
||||
} else {
|
||||
// 保存记录数据
|
||||
$data['id'] = md5(time() . rand(100000, 999999));
|
||||
$data['create_time'] = date('Y-m-d H:i:s');
|
||||
$res = Db::name($tableName)->insert($data);
|
||||
}
|
||||
|
||||
if ($res === false) {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = "添加失败";
|
||||
return json($result);
|
||||
} else {
|
||||
$result['erro'] = 0;
|
||||
$result['msg'] = "添加成功";
|
||||
return json($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询资讯信息详情
|
||||
* @author hjc
|
||||
*/
|
||||
public function getRealTimeInfoDetail(Request $request)
|
||||
{
|
||||
$post = $request->param();
|
||||
if (!isset($post['id']) || empty($post['id'])) {
|
||||
$result['erro'] = -1;
|
||||
$result['msg'] = "未传入资讯id";
|
||||
return json($result);
|
||||
}
|
||||
|
||||
$tableName = $this->getTableName('real_time_info');
|
||||
$result['infro'] = Db::name($tableName)->where('id', $post['id'])->find();
|
||||
$result['erro'] = 0;
|
||||
$result['msg'] = "查询成功";
|
||||
return json($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user