1209 lines
		
	
	
		
			37 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			1209 lines
		
	
	
		
			37 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | ||
| /**
 | ||
|  * 商业使用授权协议
 | ||
|  * 
 | ||
|  * Copyright (c) 2025 [云泽网]. 保留所有权利.
 | ||
|  * 
 | ||
|  * 本软件仅供评估使用。任何商业用途必须获得书面授权许可。
 | ||
|  * 未经授权商业使用本软件属于侵权行为,将承担法律责任。
 | ||
|  * 
 | ||
|  * 授权购买请联系: 357099073@qq.com
 | ||
|  * 官方网站: https://www.yunzer.cn
 | ||
|  * 
 | ||
|  * 评估用户须知:
 | ||
|  * 1. 禁止移除版权声明
 | ||
|  * 2. 禁止用于生产环境
 | ||
|  * 3. 禁止转售或分发
 | ||
|  */
 | ||
| 
 | ||
| namespace app\admin\controller;
 | ||
| use app\admin\controller\Base;
 | ||
| use think\facade\Db;
 | ||
| use think\facade\View;
 | ||
| use think\facade\Request;
 | ||
| use app\admin\controller\LogController as Log;
 | ||
| use app\admin\model\AdminSysMenu;
 | ||
| use app\admin\model\AdminUserGroup;
 | ||
| use app\admin\model\AdminUser;
 | ||
| use app\admin\model\User\Users;
 | ||
| use app\admin\model\User\UsersGroup;
 | ||
| use app\admin\model\Banner;
 | ||
| use app\admin\model\ContentPush\ContentPush;
 | ||
| use app\admin\model\ContentPush\ContentPushSetting;
 | ||
| use app\admin\model\Resource\Resource;
 | ||
| use app\admin\model\Article\Articles;
 | ||
| 
 | ||
| 
 | ||
| class YunzeradminController extends Base
 | ||
| {
 | ||
| 	// 角色列表
 | ||
| 	public function groupinfo()
 | ||
| 	{
 | ||
| 		$group = AdminUserGroup::select();
 | ||
| 		View::assign([
 | ||
| 			'group' => $group
 | ||
| 		]);
 | ||
| 		return View::fetch();
 | ||
| 	}
 | ||
| 
 | ||
| 	// 角色添加
 | ||
| 	public function groupadd()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$data['group_name'] = trim(input('post.group_name'));
 | ||
| 			if (!$data['group_name']) {
 | ||
| 				Log::record('添加角色', 0, '角色名称不能为空', '角色管理');
 | ||
| 				return json(['code' => 1, 'msg' => '角色名称不能为空']);
 | ||
| 			}
 | ||
| 			$data['status'] = intval(trim(input('post.status')));
 | ||
| 			$data['create_time'] = time();
 | ||
| 			$menus = input('post.menu/a');
 | ||
| 			if ($menus) {
 | ||
| 				$data['rights'] = json_encode(array_keys($menus));
 | ||
| 			}
 | ||
| 			$res = AdminUserGroup::insert($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('添加角色', 0, '添加角色失败', '角色管理');
 | ||
| 				return json(['code' => 1, 'msg' => '添加角色失败']);
 | ||
| 			}
 | ||
| 			Log::record('添加角色', 1, '', '角色管理');
 | ||
| 			return json(['code' => 0, 'msg' => '添加成功']);
 | ||
| 		} else {
 | ||
| 			$menus = AdminSysMenu::order('type,sort desc')->where('status', '=', 1)->select();
 | ||
| 			$menu = [];
 | ||
| 
 | ||
| 			// 先处理所有父菜单
 | ||
| 			foreach ($menus as $menus_v) {
 | ||
| 				if ($menus_v['parent_id'] == 0) {
 | ||
| 					$menu[$menus_v['smid']] = $menus_v;
 | ||
| 					$menu[$menus_v['smid']]['children'] = []; // 初始化 children 数组
 | ||
| 				}
 | ||
| 			}
 | ||
| 
 | ||
| 			// 再处理子菜单
 | ||
| 			foreach ($menus as $menus_v) {
 | ||
| 				if ($menus_v['parent_id'] != 0 && isset($menu[$menus_v['parent_id']])) {
 | ||
| 					$menu[$menus_v['parent_id']]['children'][] = $menus_v;
 | ||
| 				}
 | ||
| 			}
 | ||
| 
 | ||
| 			View::assign([
 | ||
| 				'menus' => $menu
 | ||
| 			]);
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	// 角色编辑
 | ||
| 	public function groupedit()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$group_id = (int) trim(input('post.group_id'));
 | ||
| 			$data['group_name'] = trim(input('post.group_name'));
 | ||
| 			if (!$data['group_name']) {
 | ||
| 				Log::record('编辑角色', 0, '角色名称不能为空', '角色管理');
 | ||
| 				return json(['code' => 1, 'msg' => '角色名称不能为空']);
 | ||
| 			}
 | ||
| 			$data['status'] = (int) trim(input('post.status'));
 | ||
| 			$menus = input('post.menu/a');
 | ||
| 			if ($menus) {
 | ||
| 				$data['rights'] = json_encode(array_keys($menus));
 | ||
| 			} else {
 | ||
| 				$data['rights'] = '';
 | ||
| 			}
 | ||
| 			$res = AdminUserGroup::where('group_id', $group_id)->update($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('编辑角色', 0, '更新角色失败', '角色管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新角色失败']);
 | ||
| 			}
 | ||
| 			Log::record('编辑角色', 1, '', '角色管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		} else {
 | ||
| 			$group_id = (int) input('get.group_id');
 | ||
| 			$group = AdminUserGroup::where('group_id', $group_id)->find();
 | ||
| 			if ($group && $group['rights']) {
 | ||
| 				$group['rights'] = json_decode($group['rights']);
 | ||
| 			}
 | ||
| 
 | ||
| 			// 使用模型中的 getMenuTree 方法获取菜单树
 | ||
| 			$menu = AdminSysMenu::getMenuTree();
 | ||
| 
 | ||
| 			View::assign([
 | ||
| 				'group' => $group,
 | ||
| 				'menus' => $menu
 | ||
| 			]);
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	// 角色删除
 | ||
| 	public function groupdel()
 | ||
| 	{
 | ||
| 		$group_id = (int) input('post.group_id');
 | ||
| 		$res = AdminUserGroup::where('group_id', $group_id)->delete();
 | ||
| 		if (empty($res)) {
 | ||
| 			Log::record('删除角色', 0, '删除角色失败', '角色管理');
 | ||
| 			return json(['code' => 1, 'msg' => '删除角色失败']);
 | ||
| 		}
 | ||
| 		Log::record('删除角色', 1, '', '角色管理');
 | ||
| 		return json(['code' => 0, 'msg' => '删除成功']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 管理员列表
 | ||
| 	public function userinfo()
 | ||
| 	{
 | ||
| 		$lists = AdminUser::select();
 | ||
| 		$group = [];
 | ||
| 		$groups = AdminUserGroup::select();
 | ||
| 		foreach ($groups as $key => $value) {
 | ||
| 			$group[$value['group_id']] = $value;
 | ||
| 		}
 | ||
| 		View::assign([
 | ||
| 			'lists' => $lists,
 | ||
| 			'group' => $group
 | ||
| 		]);
 | ||
| 		return View::fetch();
 | ||
| 	}
 | ||
| 
 | ||
| 	// 管理员添加
 | ||
| 	public function useradd()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$data['account'] = trim(input('post.account'));
 | ||
| 			if (empty($data['account'])) {
 | ||
| 				Log::record('添加管理员', 0, '账号不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '账号不能为空']);
 | ||
| 			}
 | ||
| 			$pattern = "/^([0-9A-Za-z-_.]+)@([0-9a-z]+.[a-z]{2,3}(.[a-z]{2})?)$/i";
 | ||
| 			if (!preg_match($pattern, $data['account'])) {
 | ||
| 				Log::record('添加管理员', 0, '邮箱格式不正确', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '邮箱格式不正确']);
 | ||
| 			}
 | ||
| 			$item = AdminUser::where('account', $data['account'])->find();
 | ||
| 			if ($item) {
 | ||
| 				Log::record('添加管理员', 0, '该账号已存在', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '该账号已存在']);
 | ||
| 			}
 | ||
| 			$data['name'] = trim(input('post.name'));
 | ||
| 			$data['phone'] = trim(input('post.phone'));
 | ||
| 			$data['qq'] = (int) trim(input('post.qq'));
 | ||
| 			$data['group_id'] = (int) input('post.group_id');
 | ||
| 			$data['sex'] = (int) (input('post.sex'));
 | ||
| 			$data['status'] = (int) (input('post.status'));
 | ||
| 			$password = trim(input('post.password'));
 | ||
| 			if (empty($data['name'])) {
 | ||
| 				Log::record('添加管理员', 0, '姓名不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '姓名不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['phone'])) {
 | ||
| 				Log::record('添加管理员', 0, '手机号不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '手机号不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['group_id'])) {
 | ||
| 				Log::record('添加管理员', 0, '请选择角色', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '请选择角色']);
 | ||
| 			}
 | ||
| 			if (empty($password)) {
 | ||
| 				Log::record('添加管理员', 0, '密码不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '密码不能为空']);
 | ||
| 			} else {
 | ||
| 				$data['password'] = md5($password);
 | ||
| 			}
 | ||
| 			$data['create_time'] = time();
 | ||
| 			$data['update_time'] = time();
 | ||
| 			$res = AdminUser::insert($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('添加管理员', 0, '添加管理员失败', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '添加管理员失败']);
 | ||
| 			}
 | ||
| 			Log::record('添加管理员', 1, '', '管理员管理');
 | ||
| 			return json(['code' => 0, 'msg' => '添加成功']);
 | ||
| 		} else {
 | ||
| 			$group = [];
 | ||
| 			$groups = AdminUserGroup::select();
 | ||
| 			foreach ($groups as $key => $value) {
 | ||
| 				$group[$value['group_id']] = $value;
 | ||
| 			}
 | ||
| 			View::assign([
 | ||
| 				'group' => $group
 | ||
| 			]);
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	// 管理员编辑
 | ||
| 	public function useredit()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$uid = (int) trim(input('post.uid'));
 | ||
| 			$data['name'] = trim(input('post.name'));
 | ||
| 			$data['phone'] = trim(input('post.phone'));
 | ||
| 			$data['qq'] = (int) trim(input('post.qq'));
 | ||
| 			$data['group_id'] = (int) input('post.group_id');
 | ||
| 			$data['sex'] = (int) (input('post.sex'));
 | ||
| 			$data['status'] = (int) (input('post.status'));
 | ||
| 			if (empty($data['name'])) {
 | ||
| 				Log::record('编辑管理员', 0, '姓名不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '姓名不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['phone'])) {
 | ||
| 				Log::record('编辑管理员', 0, '手机号不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '手机号不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['group_id'])) {
 | ||
| 				Log::record('编辑管理员', 0, '请选择角色', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '请选择角色']);
 | ||
| 			}
 | ||
| 			$res = AdminUser::where('uid', $uid)->update($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('编辑管理员', 0, '更新管理员信息失败', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新管理员信息失败']);
 | ||
| 			}
 | ||
| 			Log::record('编辑管理员', 1, '', '管理员管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		} else {
 | ||
| 			$uid = (int) input('get.uid');
 | ||
| 			// 加载管理员
 | ||
| 			$lists = AdminUser::where('uid', $uid)->find();
 | ||
| 			// 加载角色
 | ||
| 			$group = [];
 | ||
| 			$groups = AdminUserGroup::select();
 | ||
| 			foreach ($groups as $key => $value) {
 | ||
| 				$group[$value['group_id']] = $value;
 | ||
| 			}
 | ||
| 			View::assign([
 | ||
| 				'lists' => $lists,
 | ||
| 				'group' => $group
 | ||
| 			]);
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	// 管理员删除
 | ||
| 	public function userdel()
 | ||
| 	{
 | ||
| 		$uid = (int) input('post.uid');
 | ||
| 		$res = AdminUser::where('uid', $uid)->delete();
 | ||
| 		if (empty($res)) {
 | ||
| 			Log::record('删除管理员', 0, '删除管理员失败', '管理员管理');
 | ||
| 			return json(['code' => 1, 'msg' => '删除管理员失败']);
 | ||
| 		}
 | ||
| 		Log::record('删除管理员', 1, '', '管理员管理');
 | ||
| 		return json(['code' => 0, 'msg' => '删除成功']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 管理员信息
 | ||
| 	public function admininfo()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$find = AdminUser::where('uid', $this->adminId)->find();
 | ||
| 			if (empty($find)) {
 | ||
| 				Log::record('修改个人信息', 0, '当前账户不存在', '个人信息');
 | ||
| 				return json(['code' => 1, 'msg' => '当前账户不存在']);
 | ||
| 			}
 | ||
| 			$data['name'] = trim(input('post.name'));
 | ||
| 			$data['phone'] = trim(input('post.phone'));
 | ||
| 			$data['qq'] = (int) trim(input('post.qq'));
 | ||
| 			$data['sex'] = (int) (input('post.sex'));
 | ||
| 			if (empty($data['name'])) {
 | ||
| 				Log::record('修改个人信息', 0, '姓名不能为空', '个人信息');
 | ||
| 				return json(['code' => 1, 'msg' => '姓名不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['phone'])) {
 | ||
| 				Log::record('修改个人信息', 0, '手机号不能为空', '个人信息');
 | ||
| 				return json(['code' => 1, 'msg' => '手机号不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			// 处理密码修改
 | ||
| 			$old_pw = trim(input('post.old_pw'));
 | ||
| 			$new_pw = trim(input('post.new_pw'));
 | ||
| 			if (!empty($old_pw) && !empty($new_pw)) {
 | ||
| 				if (md5($old_pw) != $find['password']) {
 | ||
| 					Log::record('修改个人信息', 0, '原密码错误', '个人信息');
 | ||
| 					return json(['code' => 1, 'msg' => '原密码错误']);
 | ||
| 				}
 | ||
| 				$data['password'] = md5($new_pw);
 | ||
| 			}
 | ||
| 
 | ||
| 			$res = AdminUser::where('uid', $this->adminId)->update($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('修改个人信息', 0, '更新管理员信息失败', '个人信息');
 | ||
| 				return json(['code' => 1, 'msg' => '更新管理员信息失败']);
 | ||
| 			}
 | ||
| 			Log::record('修改个人信息', 1, '', '个人信息');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		} else {
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	// 前端会员列表
 | ||
| 	public function frontuser()
 | ||
| 	{
 | ||
| 		$lists = Users::select();
 | ||
| 		$group = [];
 | ||
| 		$groups = UsersGroup::select();
 | ||
| 		foreach ($groups as $key => $value) {
 | ||
| 			$group[$value['group_id']] = $value['group_name'];
 | ||
| 		}
 | ||
| 		// 替换 group_id 为 group_name
 | ||
| 		foreach ($lists as &$user) {
 | ||
| 			$gid = $user['group_id'] ?? 0;
 | ||
| 			$user['group_id'] = isset($group[$gid]) ? $group[$gid] : '';
 | ||
| 		}
 | ||
| 		unset($user);
 | ||
| 		if (request()->isAjax()) {
 | ||
| 			return json([
 | ||
| 				'code' => 0,
 | ||
| 				'msg' => '',
 | ||
| 				'count' => count($lists),
 | ||
| 				'data' => $lists
 | ||
| 			]);
 | ||
| 		}
 | ||
| 		View::assign([
 | ||
| 			'lists' => $lists,
 | ||
| 			'group' => $group
 | ||
| 		]);
 | ||
| 		return View::fetch();
 | ||
| 	}
 | ||
| 
 | ||
| 	// 前端会员添加
 | ||
| 	public function frontuseradd()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$data['account'] = trim(input('post.account'));
 | ||
| 			if (empty($data['account'])) {
 | ||
| 				Log::record('添加管理员', 0, '账号不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '账号不能为空']);
 | ||
| 			}
 | ||
| 			$pattern = "/^([0-9A-Za-z-_.]+)@([0-9a-z]+.[a-z]{2,3}(.[a-z]{2})?)$/i";
 | ||
| 			if (!preg_match($pattern, $data['account'])) {
 | ||
| 				Log::record('添加管理员', 0, '邮箱格式不正确', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '邮箱格式不正确']);
 | ||
| 			}
 | ||
| 			$item = Users::where('account', $data['account'])->find();
 | ||
| 			if ($item) {
 | ||
| 				Log::record('添加管理员', 0, '该账号已存在', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '该账号已存在']);
 | ||
| 			}
 | ||
| 			$data['name'] = trim(input('post.name'));
 | ||
| 			$data['phone'] = trim(input('post.phone'));
 | ||
| 			$data['qq'] = (int) trim(input('post.qq'));
 | ||
| 			$data['group_id'] = (int) input('post.group_id');
 | ||
| 			$data['sex'] = (int) (input('post.sex'));
 | ||
| 			$data['status'] = (int) (input('post.status'));
 | ||
| 			$password = trim(input('post.password'));
 | ||
| 			if (empty($data['name'])) {
 | ||
| 				Log::record('添加管理员', 0, '姓名不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '姓名不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['phone'])) {
 | ||
| 				Log::record('添加管理员', 0, '手机号不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '手机号不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['group_id'])) {
 | ||
| 				Log::record('添加管理员', 0, '请选择角色', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '请选择角色']);
 | ||
| 			}
 | ||
| 			if (empty($password)) {
 | ||
| 				Log::record('添加管理员', 0, '密码不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '密码不能为空']);
 | ||
| 			} else {
 | ||
| 				$data['password'] = md5($password);
 | ||
| 			}
 | ||
| 			$data['create_time'] = time();
 | ||
| 			$data['update_time'] = time();
 | ||
| 			$res = Users::insert($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('添加管理员', 0, '添加管理员失败', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '添加管理员失败']);
 | ||
| 			}
 | ||
| 			Log::record('添加管理员', 1, '', '管理员管理');
 | ||
| 			return json(['code' => 0, 'msg' => '添加成功']);
 | ||
| 		} else {
 | ||
| 			$group = [];
 | ||
| 			$groups = UsersGroup::select();
 | ||
| 			foreach ($groups as $key => $value) {
 | ||
| 				$group[$value['group_id']] = $value;
 | ||
| 			}
 | ||
| 			View::assign([
 | ||
| 				'group' => $group
 | ||
| 			]);
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	// 前端会员编辑
 | ||
| 	public function frontuseredit()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$uid = (int) trim(input('post.uid'));
 | ||
| 			$data['name'] = trim(input('post.name'));
 | ||
| 			$data['phone'] = trim(input('post.phone'));
 | ||
| 			$data['qq'] = (int) trim(input('post.qq'));
 | ||
| 			$data['group_id'] = (int) input('post.group_id');
 | ||
| 			$data['sex'] = (int) (input('post.sex'));
 | ||
| 			$data['status'] = (int) (input('post.status'));
 | ||
| 			if (empty($data['name'])) {
 | ||
| 				Log::record('编辑管理员', 0, '姓名不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '姓名不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['phone'])) {
 | ||
| 				Log::record('编辑管理员', 0, '手机号不能为空', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '手机号不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['group_id'])) {
 | ||
| 				Log::record('编辑管理员', 0, '请选择角色', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '请选择角色']);
 | ||
| 			}
 | ||
| 			$res = Users::where('uid', $uid)->update($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('编辑管理员', 0, '更新管理员信息失败', '管理员管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新管理员信息失败']);
 | ||
| 			}
 | ||
| 			Log::record('编辑管理员', 1, '', '管理员管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		} else {
 | ||
| 			$uid = (int) input('get.uid');
 | ||
| 			// 加载前端会员
 | ||
| 			$lists = Users::where('uid', $uid)->find();
 | ||
| 			// 加载角色
 | ||
| 			$group = [];
 | ||
| 			$groups = UsersGroup::select();
 | ||
| 			foreach ($groups as $key => $value) {
 | ||
| 				$group[$value['group_id']] = $value;
 | ||
| 			}
 | ||
| 			View::assign([
 | ||
| 				'lists' => $lists,
 | ||
| 				'group' => $group
 | ||
| 			]);
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	// 前端会员删除
 | ||
| 	public function frontuserdel()
 | ||
| 	{
 | ||
| 		$uid = (int) input('post.uid');
 | ||
| 		$res = Users::where('uid', $uid)->delete();
 | ||
| 		if (empty($res)) {
 | ||
| 			Log::record('删除管理员', 0, '删除管理员失败', '管理员管理');
 | ||
| 			return json(['code' => 1, 'msg' => '删除管理员失败']);
 | ||
| 		}
 | ||
| 		Log::record('删除管理员', 1, '', '管理员管理');
 | ||
| 		return json(['code' => 0, 'msg' => '删除成功']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 前端会员信息
 | ||
| 	public function frontuserdetail()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$find = Users::where('uid', $this->adminId)->find();
 | ||
| 			if (empty($find)) {
 | ||
| 				Log::record('修改个人信息', 0, '当前账户不存在', '个人信息');
 | ||
| 				return json(['code' => 1, 'msg' => '当前账户不存在']);
 | ||
| 			}
 | ||
| 			$data['name'] = trim(input('post.name'));
 | ||
| 			$data['phone'] = trim(input('post.phone'));
 | ||
| 			$data['qq'] = (int) trim(input('post.qq'));
 | ||
| 			$data['sex'] = (int) (input('post.sex'));
 | ||
| 			if (empty($data['name'])) {
 | ||
| 				Log::record('修改个人信息', 0, '姓名不能为空', '个人信息');
 | ||
| 				return json(['code' => 1, 'msg' => '姓名不能为空']);
 | ||
| 			}
 | ||
| 			if (empty($data['phone'])) {
 | ||
| 				Log::record('修改个人信息', 0, '手机号不能为空', '个人信息');
 | ||
| 				return json(['code' => 1, 'msg' => '手机号不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			// 处理密码修改
 | ||
| 			$old_pw = trim(input('post.old_pw'));
 | ||
| 			$new_pw = trim(input('post.new_pw'));
 | ||
| 			if (!empty($old_pw) && !empty($new_pw)) {
 | ||
| 				if (md5($old_pw) != $find['password']) {
 | ||
| 					Log::record('修改个人信息', 0, '原密码错误', '个人信息');
 | ||
| 					return json(['code' => 1, 'msg' => '原密码错误']);
 | ||
| 				}
 | ||
| 				$data['password'] = md5($new_pw);
 | ||
| 			}
 | ||
| 
 | ||
| 			$res = Users::where('uid', $this->adminId)->update($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('修改个人信息', 0, '更新管理员信息失败', '个人信息');
 | ||
| 				return json(['code' => 1, 'msg' => '更新管理员信息失败']);
 | ||
| 			}
 | ||
| 			Log::record('修改个人信息', 1, '', '个人信息');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		} else {
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	//banner管理
 | ||
| 	public function banner()
 | ||
| 	{
 | ||
| 		return View::fetch();
 | ||
| 	}
 | ||
| 
 | ||
| 	// banner列表
 | ||
| 	public function bannerlist()
 | ||
| 	{
 | ||
| 		if (Request::isGet()) {
 | ||
| 			$page = intval(input('post.page', 1));
 | ||
| 			$limit = intval(input('post.limit', 10));
 | ||
| 
 | ||
| 			$query = Banner::where('delete_time', null)
 | ||
| 				->field('id, title, image, url, sort, create_time, update_time');
 | ||
| 
 | ||
| 			// 获取总记录数
 | ||
| 			$count = $query->count();
 | ||
| 
 | ||
| 			// 获取分页数据
 | ||
| 			$lists = $query->order(['sort DESC', 'id DESC'])
 | ||
| 				->page($page, $limit)
 | ||
| 				->select()
 | ||
| 				->toArray();
 | ||
| 
 | ||
| 			// 处理数据
 | ||
| 			foreach ($lists as &$item) {
 | ||
| 				$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : $item['create_time'];
 | ||
| 				$item['update_time'] = is_numeric($item['update_time']) ? date('Y-m-d H:i:s', $item['update_time']) : $item['update_time'];
 | ||
| 			}
 | ||
| 
 | ||
| 			return json([
 | ||
| 				'code' => 0,
 | ||
| 				'msg' => '',
 | ||
| 				'count' => $count,
 | ||
| 				'data' => $lists
 | ||
| 			]);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 添加banner
 | ||
| 	public function banneradd()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$data = [
 | ||
| 				'title' => input('post.title'),
 | ||
| 				'image' => input('post.image'),
 | ||
| 				'url' => input('post.url'),
 | ||
| 				'sort' => input('post.sort', 0),
 | ||
| 				'status' => 1,
 | ||
| 				'create_time' => time()
 | ||
| 			];
 | ||
| 
 | ||
| 			$res = Banner::insert($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('添加Banner', 0, '添加Banner失败', 'Banner管理');
 | ||
| 				return json(['code' => 1, 'msg' => '添加Banner失败']);
 | ||
| 			}
 | ||
| 			Log::record('添加Banner', 1, '', 'Banner管理');
 | ||
| 			return json(['code' => 0, 'msg' => '添加成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 编辑banner
 | ||
| 	public function banneredit()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('编辑Banner', 0, 'ID不能为空', 'Banner管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$data = [
 | ||
| 				'title' => input('post.title'),
 | ||
| 				'image' => input('post.image'),
 | ||
| 				'url' => input('post.url'),
 | ||
| 				'sort' => input('post.sort', 0),
 | ||
| 				'update_time' => time()
 | ||
| 			];
 | ||
| 
 | ||
| 			$res = Banner::where('id', $id)->update($data);
 | ||
| 			if ($res === false) {
 | ||
| 				Log::record('编辑Banner', 0, '更新Banner失败', 'Banner管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新Banner失败']);
 | ||
| 			}
 | ||
| 			Log::record('编辑Banner', 1, '', 'Banner管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 删除banner
 | ||
| 	public function bannerdel()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('删除Banner', 0, 'ID不能为空', 'Banner管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$res = Banner::where('id', $id)->update(['delete_time' => time()]);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('删除Banner', 0, '删除Banner失败', 'Banner管理');
 | ||
| 				return json(['code' => 1, 'msg' => '删除Banner失败']);
 | ||
| 			}
 | ||
| 			Log::record('删除Banner', 1, '', 'Banner管理');
 | ||
| 			return json(['code' => 0, 'msg' => '删除成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 修改banner状态
 | ||
| 	public function bannerstatus()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			$status = input('post.status');
 | ||
| 
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('修改Banner状态', 0, 'ID不能为空', 'Banner管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$res = Banner::where('id', $id)->update(['status' => $status]);
 | ||
| 			if ($res === false) {
 | ||
| 				Log::record('修改Banner状态', 0, '更新状态失败', 'Banner管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新状态失败']);
 | ||
| 			}
 | ||
| 			Log::record('修改Banner状态', 1, '', 'Banner管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	//内容推送
 | ||
| 	public function contentpush()
 | ||
| 	{
 | ||
| 		return View::fetch();
 | ||
| 	}
 | ||
| 
 | ||
| 	// 内容推送列表
 | ||
| 	public function contentpushlist()
 | ||
| 	{
 | ||
| 		if (Request::isGet()) {
 | ||
| 			// 获取分页参数
 | ||
| 			$page = (int) input('get.page', 1);
 | ||
| 			$limit = (int) input('get.limit', 10);
 | ||
| 
 | ||
| 			// 1. 获取 Articles 表(delete_time为空,status=2)
 | ||
| 			$articles = Articles::where('delete_time', null)
 | ||
| 				->where('status', 2)
 | ||
| 				->field('id, title, push, create_time')
 | ||
| 				->select()
 | ||
| 				->toArray();
 | ||
| 			foreach ($articles as &$a) {
 | ||
| 				$a['type'] = 'article';
 | ||
| 				$a['create_time'] = is_numeric($a['create_time']) ? date('Y-m-d H:i:s', $a['create_time']) : $a['create_time'];
 | ||
| 			}
 | ||
| 			unset($a);
 | ||
| 
 | ||
| 			// 2. 获取 Resource 表(delete_time为空,status=1)
 | ||
| 			$resources = Resource::where('delete_time', null)
 | ||
| 				->where('status', 1)
 | ||
| 				->field('id, title, push, create_time')
 | ||
| 				->select()
 | ||
| 				->toArray();
 | ||
| 			foreach ($resources as &$r) {
 | ||
| 				$r['type'] = 'resource';
 | ||
| 				$r['create_time'] = is_numeric($r['create_time']) ? date('Y-m-d H:i:s', $r['create_time']) : $r['create_time'];
 | ||
| 			}
 | ||
| 			unset($r);
 | ||
| 
 | ||
| 			// 3. 合并
 | ||
| 			$lists = array_merge($articles, $resources);
 | ||
| 
 | ||
| 			// 4. 优先显示push为0的数据,再按create_time倒序排序
 | ||
| 			usort($lists, function ($a, $b) {
 | ||
| 				// push为0的排在前面
 | ||
| 				if ($a['push'] != $b['push']) {
 | ||
| 					return $a['push'] - $b['push'];
 | ||
| 				}
 | ||
| 				// push相同则按create_time倒序
 | ||
| 				return strtotime($b['create_time']) <=> strtotime($a['create_time']);
 | ||
| 			});
 | ||
| 
 | ||
| 			// 5. 分页
 | ||
| 			$total = count($lists);
 | ||
| 			$offset = ($page - 1) * $limit;
 | ||
| 			$data = array_slice($lists, $offset, $limit);
 | ||
| 
 | ||
| 			return json([
 | ||
| 				'code' => 0,
 | ||
| 				'msg' => '',
 | ||
| 				'count' => $total,
 | ||
| 				'data' => $data
 | ||
| 			]);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 添加内容推送
 | ||
| 	public function contentpushadd()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$data = [
 | ||
| 				'title' => input('post.title'),
 | ||
| 				'content' => input('post.content'),
 | ||
| 				'image' => input('post.image'),
 | ||
| 				'url' => input('post.url'),
 | ||
| 				'type' => input('post.type', 1),
 | ||
| 				'status' => input('post.status', 1),
 | ||
| 				'sort' => input('post.sort', 0),
 | ||
| 				'create_time' => time()
 | ||
| 			];
 | ||
| 
 | ||
| 			$res = ContentPush::insert($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('添加内容推送', 0, '添加内容推送失败', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => '添加内容推送失败']);
 | ||
| 			}
 | ||
| 			Log::record('添加内容推送', 1, '', '内容推送管理');
 | ||
| 			return json(['code' => 0, 'msg' => '添加成功']);
 | ||
| 		} else {
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	// 编辑内容推送
 | ||
| 	public function contentpushedit()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('编辑内容推送', 0, 'ID不能为空', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$data = [
 | ||
| 				'title' => input('post.title'),
 | ||
| 				'content' => input('post.content'),
 | ||
| 				'image' => input('post.image'),
 | ||
| 				'url' => input('post.url'),
 | ||
| 				'type' => input('post.type', 1),
 | ||
| 				'status' => input('post.status', 1),
 | ||
| 				'sort' => input('post.sort', 0),
 | ||
| 				'update_time' => time()
 | ||
| 			];
 | ||
| 
 | ||
| 			$res = ContentPush::where('id', $id)->update($data);
 | ||
| 			if ($res === false) {
 | ||
| 				Log::record('编辑内容推送', 0, '更新内容推送失败', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新内容推送失败']);
 | ||
| 			}
 | ||
| 			Log::record('编辑内容推送', 1, '', '内容推送管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 删除内容推送
 | ||
| 	public function contentpushdel()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('删除内容推送', 0, 'ID不能为空', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$res = ContentPush::where('id', $id)->update(['delete_time' => time()]);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('删除内容推送', 0, '删除内容推送失败', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => '删除内容推送失败']);
 | ||
| 			}
 | ||
| 			Log::record('删除内容推送', 1, '', '内容推送管理');
 | ||
| 			return json(['code' => 0, 'msg' => '删除成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 修改内容推送状态
 | ||
| 	public function contentpushstatus()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			$status = input('post.status');
 | ||
| 
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('修改内容推送状态', 0, 'ID不能为空', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$res = ContentPush::where('id', $id)->update(['status' => $status]);
 | ||
| 			if ($res === false) {
 | ||
| 				Log::record('修改内容推送状态', 0, '更新状态失败', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新状态失败']);
 | ||
| 			}
 | ||
| 			Log::record('修改内容推送状态', 1, '', '内容推送管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	//推送配置列表(渲染列表)
 | ||
| 	public function contentpushsetting()
 | ||
| 	{
 | ||
| 		if (Request::isAjax() || Request::isPost()) {
 | ||
| 			$page = intval(input('get.page', 1));
 | ||
| 			$limit = intval(input('get.limit', 10));
 | ||
| 
 | ||
| 			$query = ContentPushSetting::where('delete_time', null)
 | ||
| 				->field('id, title, value, platformType, status, sort, create_time');
 | ||
| 
 | ||
| 			$count = $query->count();
 | ||
| 
 | ||
| 			$lists = $query->order(['sort' => 'DESC', 'id' => 'DESC'])
 | ||
| 				->page($page, $limit)
 | ||
| 				->select()
 | ||
| 				->toArray();
 | ||
| 
 | ||
| 			foreach ($lists as &$item) {
 | ||
| 				$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : $item['create_time'];
 | ||
| 			}
 | ||
| 
 | ||
| 			return json([
 | ||
| 				'code' => 0,
 | ||
| 				'msg' => '获取成功',
 | ||
| 				'count' => $count,
 | ||
| 				'data' => $lists
 | ||
| 			]);
 | ||
| 		} else {
 | ||
| 			return View::fetch();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	//选择列出推送内容列表
 | ||
| 	public function selectpushcontent()
 | ||
| 	{
 | ||
| 		$pushcate = strtolower(trim(input('get.pushcate', '')));
 | ||
| 		$where = ['push' => 0];
 | ||
| 
 | ||
| 		$modelMap = [
 | ||
| 			'article' => Articles::class,
 | ||
| 			'resource' => Resource::class,
 | ||
| 		];
 | ||
| 
 | ||
| 		if (!isset($modelMap[$pushcate])) {
 | ||
| 			return json(['code' => 1, 'msg' => '参数错误: pushcate']);
 | ||
| 		}
 | ||
| 
 | ||
| 		$model = $modelMap[$pushcate];
 | ||
| 
 | ||
| 		$query = $model::where($where)->field('title,id');
 | ||
| 		$count = $query->count();
 | ||
| 		$list = $query->order('id', 'desc')->select()->toArray();
 | ||
| 
 | ||
| 		// 判断是接口请求还是页面请求
 | ||
| 		if (request()->isAjax() || request()->isJson()) {
 | ||
| 			return json([
 | ||
| 				'code' => 0,
 | ||
| 				'msg' => '获取成功',
 | ||
| 				'count' => $count,
 | ||
| 				'data' => $list
 | ||
| 			]);
 | ||
| 		} else {
 | ||
| 			// 这里传递变量到模板
 | ||
| 			return View::fetch('', [
 | ||
| 				'data' => $list
 | ||
| 			]);
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	//推送配置添加和编辑通用方法
 | ||
| 	public function contentpushsettingadd()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$params = input('post.');
 | ||
| 			$id = isset($params['id']) ? intval($params['id']) : 0;
 | ||
| 
 | ||
| 			if ($id > 0) {
 | ||
| 				// 编辑
 | ||
| 				$res = ContentPushSetting::update($params, ['id' => $id]);
 | ||
| 				if ($res === false) {
 | ||
| 					Log::record('编辑推送配置', 0, '编辑推送配置失败', '推送配置管理');
 | ||
| 					return json(['code' => 1, 'msg' => '编辑推送配置失败']);
 | ||
| 				}
 | ||
| 				Log::record('编辑推送配置', 1, '', '推送配置管理');
 | ||
| 				return json(['code' => 0, 'msg' => '编辑成功']);
 | ||
| 			} else {
 | ||
| 				// 添加
 | ||
| 				$res = ContentPushSetting::create($params);
 | ||
| 				if (!$res) {
 | ||
| 					Log::record('添加推送配置', 0, '添加推送配置失败', '推送配置管理');
 | ||
| 					return json(['code' => 1, 'msg' => '添加推送配置失败']);
 | ||
| 				}
 | ||
| 				Log::record('添加推送配置', 1, '', '推送配置管理');
 | ||
| 				return json(['code' => 0, 'msg' => '添加成功']);
 | ||
| 			}
 | ||
| 		} else {
 | ||
| 			$id = input('get.id', 0);
 | ||
| 			$info = [];
 | ||
| 			if ($id) {
 | ||
| 				$info = ContentPushSetting::where('id', $id)->find();
 | ||
| 				if ($info) {
 | ||
| 					$info = $info->toArray();
 | ||
| 				}
 | ||
| 			}
 | ||
| 			return View::fetch('', ['info' => $info]);
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	//推送配置软删除
 | ||
| 	public function contentpushsettingdel()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = intval(input('post.id', 0));
 | ||
| 			if (!$id) {
 | ||
| 				return json(['code' => 1, 'msg' => '参数错误']);
 | ||
| 			}
 | ||
| 			$setting = ContentPushSetting::where('id', $id)->find();
 | ||
| 			if (!$setting) {
 | ||
| 				return json(['code' => 1, 'msg' => '配置不存在']);
 | ||
| 			}
 | ||
| 			$res = ContentPushSetting::where('id', $id)->update(['delete_time' => date('Y-m-d H:i:s')]);
 | ||
| 			if ($res === false) {
 | ||
| 				Log::record('删除推送配置', 0, '删除失败', '推送配置管理');
 | ||
| 				return json(['code' => 1, 'msg' => '删除失败']);
 | ||
| 			}
 | ||
| 			Log::record('删除推送配置', 1, '', '推送配置管理');
 | ||
| 			return json(['code' => 0, 'msg' => '删除成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方式错误']);
 | ||
| 	}
 | ||
| 
 | ||
| 	//素材中心
 | ||
| 	public function materialcenter()
 | ||
| 	{
 | ||
| 		return View::fetch();
 | ||
| 	}
 | ||
| 	// 内容推送列表
 | ||
| 	public function materialcenterlist()
 | ||
| 	{
 | ||
| 		if (Request::isGet()) {
 | ||
| 			$page = intval(input('post.page', 1));
 | ||
| 			$limit = intval(input('post.limit', 10));
 | ||
| 
 | ||
| 			$query = ContentPush::where('delete_time', null)
 | ||
| 				->field('id, title, type, status, sort, create_time, update_time');
 | ||
| 
 | ||
| 			// 获取总记录数
 | ||
| 			$count = $query->count();
 | ||
| 
 | ||
| 			// 获取分页数据
 | ||
| 			$lists = $query->order(['sort DESC', 'id DESC'])
 | ||
| 				->page($page, $limit)
 | ||
| 				->select()
 | ||
| 				->toArray();
 | ||
| 
 | ||
| 			// 处理数据
 | ||
| 			foreach ($lists as &$item) {
 | ||
| 				$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : $item['create_time'];
 | ||
| 				$item['update_time'] = is_numeric($item['update_time']) ? date('Y-m-d H:i:s', $item['update_time']) : $item['update_time'];
 | ||
| 			}
 | ||
| 
 | ||
| 			return json([
 | ||
| 				'code' => 0,
 | ||
| 				'msg' => '',
 | ||
| 				'count' => $count,
 | ||
| 				'data' => $lists
 | ||
| 			]);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 	// 添加内容推送
 | ||
| 	public function materialcenteradd()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$data = [
 | ||
| 				'title' => input('post.title'),
 | ||
| 				'content' => input('post.content'),
 | ||
| 				'image' => input('post.image'),
 | ||
| 				'url' => input('post.url'),
 | ||
| 				'type' => input('post.type', 1),
 | ||
| 				'status' => input('post.status', 1),
 | ||
| 				'sort' => input('post.sort', 0),
 | ||
| 				'create_time' => time()
 | ||
| 			];
 | ||
| 
 | ||
| 			$res = ContentPush::insert($data);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('添加内容推送', 0, '添加内容推送失败', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => '添加内容推送失败']);
 | ||
| 			}
 | ||
| 			Log::record('添加内容推送', 1, '', '内容推送管理');
 | ||
| 			return json(['code' => 0, 'msg' => '添加成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 编辑内容推送
 | ||
| 	public function materialcenteredit()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('编辑内容推送', 0, 'ID不能为空', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$data = [
 | ||
| 				'title' => input('post.title'),
 | ||
| 				'content' => input('post.content'),
 | ||
| 				'image' => input('post.image'),
 | ||
| 				'url' => input('post.url'),
 | ||
| 				'type' => input('post.type', 1),
 | ||
| 				'status' => input('post.status', 1),
 | ||
| 				'sort' => input('post.sort', 0),
 | ||
| 				'update_time' => time()
 | ||
| 			];
 | ||
| 
 | ||
| 			$res = ContentPush::where('id', $id)->update($data);
 | ||
| 			if ($res === false) {
 | ||
| 				Log::record('编辑内容推送', 0, '更新内容推送失败', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新内容推送失败']);
 | ||
| 			}
 | ||
| 			Log::record('编辑内容推送', 1, '', '内容推送管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 删除内容推送
 | ||
| 	public function materialcenterdel()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('删除内容推送', 0, 'ID不能为空', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$res = ContentPush::where('id', $id)->update(['delete_time' => time()]);
 | ||
| 			if (!$res) {
 | ||
| 				Log::record('删除内容推送', 0, '删除内容推送失败', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => '删除内容推送失败']);
 | ||
| 			}
 | ||
| 			Log::record('删除内容推送', 1, '', '内容推送管理');
 | ||
| 			return json(['code' => 0, 'msg' => '删除成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 	// 修改内容推送状态
 | ||
| 	public function materialcenterstatus()
 | ||
| 	{
 | ||
| 		if (Request::isPost()) {
 | ||
| 			$id = input('post.id');
 | ||
| 			$status = input('post.status');
 | ||
| 
 | ||
| 			if (empty($id)) {
 | ||
| 				Log::record('修改内容推送状态', 0, 'ID不能为空', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => 'ID不能为空']);
 | ||
| 			}
 | ||
| 
 | ||
| 			$res = ContentPush::where('id', $id)->update(['status' => $status]);
 | ||
| 			if ($res === false) {
 | ||
| 				Log::record('修改内容推送状态', 0, '更新状态失败', '内容推送管理');
 | ||
| 				return json(['code' => 1, 'msg' => '更新状态失败']);
 | ||
| 			}
 | ||
| 			Log::record('修改内容推送状态', 1, '', '内容推送管理');
 | ||
| 			return json(['code' => 0, 'msg' => '更新成功']);
 | ||
| 		}
 | ||
| 		return json(['code' => 1, 'msg' => '请求方法无效']);
 | ||
| 	}
 | ||
| 
 | ||
| 
 | ||
| 	public function gopush()
 | ||
| 	{
 | ||
| 		$platformType = input('post.platformType');
 | ||
| 		$urls = input('post.urls/a', []);
 | ||
| 
 | ||
| 		if (empty($platformType)) {
 | ||
| 			return json(['code' => 1, 'msg' => '平台参数缺失']);
 | ||
| 		}
 | ||
| 		if (empty($urls)) {
 | ||
| 			return json(['code' => 1, 'msg' => '推送内容url为空']);
 | ||
| 		}
 | ||
| 
 | ||
| 		// 查找推送平台配置
 | ||
| 		$setting = ContentPushSetting::where('platformType', $platformType)->find();
 | ||
| 		if (!$setting) {
 | ||
| 			return json(['code' => 1, 'msg' => '未找到该平台的推送配置']);
 | ||
| 		}
 | ||
| 		if ($setting['status'] == 0) {
 | ||
| 			return json(['code' => 1, 'msg' => '该平台推送已禁用']);
 | ||
| 		}
 | ||
| 		$api = $setting['value'];
 | ||
| 		if (empty($api)) {
 | ||
| 			return json(['code' => 1, 'msg' => '推送API地址未配置']);
 | ||
| 		}
 | ||
| 
 | ||
| 		// 推送
 | ||
| 		$ch = curl_init();
 | ||
| 		$options = array(
 | ||
| 			CURLOPT_URL => $api,
 | ||
| 			CURLOPT_POST => true,
 | ||
| 			CURLOPT_RETURNTRANSFER => true,
 | ||
| 			CURLOPT_POSTFIELDS => implode("\n", $urls), // 多行文本,每行一个url
 | ||
| 			CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
 | ||
| 		);
 | ||
| 		curl_setopt_array($ch, $options);
 | ||
| 		$result = curl_exec($ch);
 | ||
| 		$error = curl_error($ch);
 | ||
| 		curl_close($ch);
 | ||
| 
 | ||
| 		if ($error) {
 | ||
| 			return json(['code' => 1, 'msg' => $error, 'result' => $result]);
 | ||
| 		}
 | ||
| 
 | ||
| 		// 解析推送返回结果
 | ||
| 		$resultArr = json_decode($result, true);
 | ||
| 
 | ||
| 		// 判断返回是否有error字段
 | ||
| 		if (is_array($resultArr) && isset($resultArr['error'])) {
 | ||
| 			return json([
 | ||
| 				'code' => 1,
 | ||
| 				'msg' => '推送失败: ' . (isset($resultArr['message']) ? $resultArr['message'] : '未知错误'),
 | ||
| 				'result' => $resultArr
 | ||
| 			]);
 | ||
| 		}
 | ||
| 
 | ||
| 		// 判断是否有success字段,只有有success字段才认为推送成功
 | ||
| 		if (is_array($resultArr) && isset($resultArr['success'])) {
 | ||
| 			// 推送成功后,更新对应数据的push字段为1
 | ||
| 			// 解析urls,分别更新Articles或Resource表
 | ||
| 			foreach ($urls as $url) {
 | ||
| 				// 匹配文章
 | ||
| 				if (preg_match('/\/index\/articles\/detail\?id=(\d+)/', $url, $matches)) {
 | ||
| 					$id = intval($matches[1]);
 | ||
| 					if ($id > 0) {
 | ||
| 						Articles::where('id', $id)->update(['push' => 1]);
 | ||
| 					}
 | ||
| 				}
 | ||
| 				// 匹配资源
 | ||
| 				elseif (preg_match('/\/index\/resources\/detail\?id=(\d+)/', $url, $matches)) {
 | ||
| 					$id = intval($matches[1]);
 | ||
| 					if ($id > 0) {
 | ||
| 						Resource::where('id', $id)->update(['push' => 1]);
 | ||
| 					}
 | ||
| 				}
 | ||
| 			}
 | ||
| 			return json(['code' => 0, 'msg' => '推送成功', 'result' => $resultArr]);
 | ||
| 		} else {
 | ||
| 			// 没有success字段,视为推送失败,把失败的result反馈给前端
 | ||
| 			return json([
 | ||
| 				'code' => 1,
 | ||
| 				'msg' => '推送失败',
 | ||
| 				'result' => $resultArr !== null ? $resultArr : $result
 | ||
| 			]);
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 
 | ||
| } |