SchoolPhysicalExamination/application/app/controller/Msginformation.php

544 lines
24 KiB
PHP
Raw Normal View History

2024-11-23 16:46:38 +08:00
<?php
namespace app\app\controller;
use think\Db;
class Msginformation extends Base{
2025-04-03 18:19:04 +08:00
2025-12-19 21:44:56 +08:00
protected $judge_wechat_release = true;
2025-04-03 18:19:04 +08:00
2024-11-23 16:46:38 +08:00
protected $msginformation_use_db_name = [
'1'=>'admin_editor_text_content',
'2'=>'admin_editor_text_like_up_log',
2024-12-07 18:56:07 +08:00
'3'=>'admin_notice_banner',
'4'=>'admin_business_cooperation'
2024-11-23 16:46:38 +08:00
];
protected $page_num = 10;
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 获取板块,及板块下类型标签
2024-12-18 09:19:51 +08:00
public function get_sector_label_msg($data = ['token'=>'6441bf7dabea7b3360a30240d3b19fc5']){
2024-11-23 16:46:38 +08:00
try {
2025-10-11 18:11:41 +08:00
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
2024-12-18 09:19:51 +08:00
if(!array_key_exists('token', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
$return_data = $this->get_sector_label_msg_action($data);
2024-11-23 16:46:38 +08:00
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log([], $logContent, null);
return $this->msg(99999);
}
}
// 获取板块下信息
2024-12-18 09:19:51 +08:00
public function get_sector_content_msg($data = ['token'=>'6441bf7dabea7b3360a30240d3b19fc5','sector_id'=>1,'type'=>0,'page'=>1]){
2024-11-23 16:46:38 +08:00
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data) || !array_key_exists('sector_id', $data) || !array_key_exists('type', $data) || !array_key_exists('page', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['sector_id'],'intnum')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['type'],'intnum')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['page'],'intnum')){
return $this->msg(10005);
2024-12-26 19:14:44 +08:00
}else{
if($data['page'] < 1){
return $this->msg(10005,'页码不能小于1');
}
2024-11-23 16:46:38 +08:00
}
$return_data = $this->get_sector_content_msg_action($data);
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 资讯点赞
public function user_like_it($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','id'=>'44']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['id'],'intnum')){
return $this->msg(10005);
}
$return_data = $this->user_like_it_action($data);
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2024-12-18 09:19:51 +08:00
// 获取公告文章信息列表&banner
public function get_recommend_information($data=['token'=>'6441bf7dabea7b3360a30240d3b19fc5']){
try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
$this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]);
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
$return_result = $this->get_recommend_information_action($data);
2025-10-11 18:11:41 +08:00
// $this->record_api_log($data, null, $return_result);
2024-12-18 09:19:51 +08:00
return $return_result;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2024-12-07 18:56:07 +08:00
// 获取商务合作链接
public function get_business_cooperation_url(){
try {
$business_cooperation_data = Db::table($this->msginformation_use_db_name['4'])->where(['is_del'=>0])->field('title,data_url as url')->select();
$this->record_api_log([], null, $business_cooperation_data);
return $this->msg($business_cooperation_data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log([], $logContent, null);
return $this->msg(99999);
}
}
2024-12-18 09:19:51 +08:00
// 删除掉所有已经读过的文章记录
public function del_all_read_log($data=['token'=>'6441bf7dabea7b3360a30240d3b19fc5']){
try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
$this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]);
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
$is_ok = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token']])->delete();
if($is_ok){
echo '删除成功';
}else{
echo '删除失败';
}
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2024-12-26 19:14:44 +08:00
// 给微信使用的中间页(拉起微信)
// public function open_wechat_content($data=['id'=>8]){
public function open_wechat_content(){
try {
$data = input();
if(!array_key_exists('id', $data)){
$this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]);
return $this->msg(10001);
}
$url = Db::table('admin_notice_banner')->where(['id'=>$data['id']])->field('type,jump_url')->find();
if(!$url['type'] || $url['type'] != 2){
echo '<div style="font-size: 30px;font-weight: bold;">页面跑丢了... =。=</div>';
die;
}
header('Location: '.$url['jump_url']);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2024-11-23 16:46:38 +08:00
################################################################业务################################################################
################################################################get_sector_label_msg
2024-12-18 09:19:51 +08:00
public function get_sector_label_msg_action($data){
2025-04-03 18:19:04 +08:00
2024-11-23 16:46:38 +08:00
$Template_arr = [
1=>[
'id'=>'1',
'name'=>'推荐',
'loop_data'=>[],
'list'=>[
2025-02-18 17:22:00 +08:00
['id'=>0,'name'=>'全部'],
['id'=>1,'name'=>'身高管理'],
['id'=>2,'name'=>'体重管理'],
['id'=>3,'name'=>'肺活训练'],
['id'=>4,'name'=>'跳绳训练'],
['id'=>5,'name'=>'中考体测'],
2024-11-23 16:46:38 +08:00
]
],
];
2025-04-03 18:19:04 +08:00
if($this->judge_wechat_release === true){
$Template_arr = [
1=>[
'id'=>'1',
'name'=>'推荐',
'loop_data'=>[],
'list'=>[
]
],
];
}
2024-11-23 16:46:38 +08:00
// 获取需要版块id start
$sector = Db::query("
SELECT
sector
FROM ".$this->msginformation_use_db_name['1']."
group by sector
");
$sector_all = [];
foreach ($sector as $key => $value) {
foreach (explode(',', $value['sector']) as $k => $v) {
if(!in_array($v, $sector_all)){
array_push($sector_all, $v);
}
}
}
// 获取需要版块id end
// 填充进去版块的轮播start
$return_data = [];
foreach ($sector_all as $key => $value) {
$loop_result = Db::query("
SELECT
id,
title,
CONCAT('https://tc.pcxbc.com/', cover_image) AS cover_image
FROM ".$this->msginformation_use_db_name['1']."
WHERE
is_del = 0 AND loop_img > 0 AND sector LIKE '%".$value."%'
ORDER BY
loop_img desc
");
2024-12-18 09:19:51 +08:00
if(count($loop_result) > 0){
foreach ($loop_result as $k => $v) {
2024-12-26 19:14:44 +08:00
// $loop_result[$key]['jump_url'] = "https://tc.pcxbc.com/editortext/model_content?id=".$v['id']."&token=".$data['token'];
$loop_result[$key]['jump_url'] = "https://tc.pcxbc.com/editortext/model_content";
2024-12-18 09:19:51 +08:00
}
}
2024-11-23 16:46:38 +08:00
$Template_arr[$value]['loop_data'] = $loop_result;
array_push($return_data, $Template_arr[$value]);
}
2024-12-26 19:14:44 +08:00
2024-11-23 16:46:38 +08:00
// 填充进去版块的轮播end
return $this->msg($return_data);
}
################################################################get_sector_content_msg
public function get_sector_content_msg_action($data){
$return_result = [
'page_now'=>$data['page'],
'page_num'=>$this->page_num,
'content_data'=>[]
];
2025-04-03 18:19:04 +08:00
if($this->judge_wechat_release === true){
return $this->msg($return_result);
}
2024-11-23 16:46:38 +08:00
if($data['type'] != 0){
$type_str = " AND type LIKE '%".$data['type']."%'";
}else{
$type_str = "";
}
$content_result = Db::query("
SELECT
id,
title,
create_time,
i_like,
reading,
CONCAT('https://tc.pcxbc.com/', cover_image) AS cover_image,
top_up
FROM ".$this->msginformation_use_db_name['1']."
WHERE
is_del = 0 AND sector LIKE '%".$data['sector_id']."%'".$type_str."
ORDER BY
top_up desc,id
OFFSET
(".$data['page']." - 1) * ".$this->page_num." ROWS
FETCH NEXT
".$this->page_num." ROWS ONLY
");
2024-12-18 09:19:51 +08:00
if(count($content_result) > 0){
foreach ($content_result as $key => $value) {
2024-12-26 19:14:44 +08:00
// $content_result[$key]['jump_url'] = "https://tc.pcxbc.com/editortext/model_content?id=".$value['id']."&token=".$data['token'];
$content_result[$key]['jump_url'] = "https://tc.pcxbc.com/editortext/model_content";
2024-12-18 09:19:51 +08:00
}
}
2024-11-23 16:46:38 +08:00
$return_result['content_data'] = $content_result;
2024-12-18 09:19:51 +08:00
$user_like = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token']])->column('aetc_id');
2024-11-23 16:46:38 +08:00
foreach ($return_result['content_data'] as $key => $value) {
if(array_key_exists($value['id'], $user_like)){
$return_result['content_data'][$key]['is_like'] = 1;
}else{
$return_result['content_data'][$key]['is_like'] = 0;
}
}
return $this->msg($return_result);
}
################################################################user_like_it
public function user_like_it_action($data){
$user_like_data = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token'],'aetc_id'=>$data['id']])->find();
if($user_like_data){
// 如果找到有点赞记录
2024-12-18 09:19:51 +08:00
if($user_like_data['is_like'] == 1){
2024-11-23 16:46:38 +08:00
// 如果已经点了
// 启动事务
Db::startTrans();
try{
Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setDec('i_like');
2024-12-18 09:19:51 +08:00
Db::table($this->msginformation_use_db_name['2'])->where(['aetc_id'=>$data['id'],'token'=>$data['token']])->update(['is_like'=>0,'update_time'=>date('Y-m-d H:i:s')]);
2024-11-23 16:46:38 +08:00
// 提交事务
Db::commit();
2024-12-18 09:19:51 +08:00
return $this->msg(['user_like'=>0]);
2024-11-23 16:46:38 +08:00
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $this->msg(10002);
}
}else{
// 如果之前点过又取消了
// 启动事务
Db::startTrans();
try{
Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setInc('i_like');
2024-12-18 09:19:51 +08:00
Db::table($this->msginformation_use_db_name['2'])->where(['aetc_id'=>$data['id'],'token'=>$data['token']])->update(['is_like'=>1,'update_time'=>date('Y-m-d H:i:s')]);
2024-11-23 16:46:38 +08:00
// 提交事务
Db::commit();
2024-12-18 09:19:51 +08:00
return $this->msg(['user_like'=>1]);
2024-11-23 16:46:38 +08:00
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $this->msg(10002);
}
}
}else{
// 如果没有记录
// 启动事务
Db::startTrans();
try{
Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setInc('i_like');
Db::table($this->msginformation_use_db_name['2'])->insert([
'aetc_id'=>$data['id'],
'token'=>$data['token'],
2024-12-18 09:19:51 +08:00
'is_like'=>1,
2024-11-23 16:46:38 +08:00
'create_time'=>date('Y-m-d H:i:s'),
'update_time'=>date('Y-m-d H:i:s')
]);
// 提交事务
Db::commit();
2024-12-18 09:19:51 +08:00
return $this->msg(['user_like'=>1]);
2024-11-23 16:46:38 +08:00
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $this->msg(10002);
}
}
2024-12-18 09:19:51 +08:00
}
################################################################get_recommend_information
public function get_recommend_information_action($data){
$return_data = [
'pop'=>[],
'notice'=>[],
'banner'=>[]
];
2025-09-26 16:35:42 +08:00
return $this->msg($return_data);
// 所有可用记录.
2025-07-23 21:32:05 +08:00
$all_data = Db::table($this->msginformation_use_db_name['3'])->where("is_del = 0 AND scene_data IN (1,2,3)")->order('sort_num')->select();
2024-12-18 09:19:51 +08:00
// 用户阅读记录
$user_read_log = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token']])->field('aetc_id')->select();
$user_read_data = [];
// 先过滤一遍用户已经看过的文章记录
foreach ($user_read_log as $key => $value) {
array_push($user_read_data,$value['aetc_id']);
}
// 删掉已经读过的信息
foreach ($all_data as $key => $value) {
if($value['type'] == '1'){
if(in_array($value['parameter_data'], $user_read_data)){
2025-07-23 21:32:05 +08:00
// 如果读过
2024-12-18 09:19:51 +08:00
if($value['scene_data'] != 3){
2025-07-23 21:32:05 +08:00
// 如果不是banner
2024-12-18 09:19:51 +08:00
unset($all_data[$key]);
}else{
2024-12-26 19:14:44 +08:00
// $all_data[$key]['jump_url'] = $all_data[$key]['jump_url']."&token=".$data['token'];
$all_data[$key]['jump_url'] = $all_data[$key]['jump_url'];
2024-12-18 09:19:51 +08:00
$all_data[$key]['type'] = 'h5';
$all_data[$key]['id'] = $value['parameter_data'];
}
}else{
2024-12-26 19:14:44 +08:00
// $all_data[$key]['jump_url'] = $all_data[$key]['jump_url']."&token=".$data['token'];
$all_data[$key]['jump_url'] = $all_data[$key]['jump_url'];
2024-12-18 09:19:51 +08:00
$all_data[$key]['type'] = 'h5';
$all_data[$key]['id'] = $value['parameter_data'];
}
2025-07-23 21:32:05 +08:00
}else if($value['type'] == '3'){
$all_data[$key]['jump_url'] = $all_data[$key]['jump_url'];
$all_data[$key]['type'] = 'h5';
$all_data[$key]['id'] = $value['parameter_data'];
2024-12-18 09:19:51 +08:00
}else{
$all_data[$key]['type'] = 'wechat';
// 提取查询字符串部分(?后面的部分)
$queryString = substr($all_data[$key]['jump_url'], strpos($all_data[$key]['jump_url'], '?') + 1);
// 使用parse_str解析查询字符串
$params = [];
parse_str($queryString, $params);
// 提取appid和path的值
$appid = isset($params['appid']) ? $params['appid'] : null;
$path = isset($params['path']) ? $params['path'] : null;
$all_data[$key]['appid'] = $appid;
$all_data[$key]['path'] = $path;
2024-12-26 19:14:44 +08:00
// 重新定义跳转链接为中间页
$all_data[$key]['jump_url'] = "https://tc.pcxbc.com/open_wechat_content";
2024-12-18 09:19:51 +08:00
}
// $all_data[$key]['id'] = $all_data[$key]['parameter_data'];
unset($all_data[$key]['parameter_data']);
unset($all_data[$key]['is_del']);
unset($all_data[$key]['ROW_NUMBER']);
}
// 分类信息
foreach ($all_data as $key => $value) {
// 1:首屏弹窗2滚动公告3banner
2025-07-23 21:32:05 +08:00
2024-12-18 09:19:51 +08:00
if($value['scene_data'] == '1'){
array_push($return_data['pop'],$value);
}else if($value['scene_data'] == '2'){
array_push($return_data['notice'],$value);
}else if($value['scene_data'] == '3'){
2025-07-23 21:32:05 +08:00
2024-12-18 09:19:51 +08:00
array_push($return_data['banner'],$value);
}
}
// 设置pop当中只有一个数据
if(count($return_data['pop'])>0){
$return_data['pop'] = [$return_data['pop'][0]];
}
return $this->msg($return_data);
2024-11-23 16:46:38 +08:00
}
2025-04-03 18:19:04 +08:00
################################################################小工具################################################################
################################################################小工具################################################################
################################################################小工具################################################################
################################################################小工具################################################################
################################################################小工具################################################################
// 判断微信发版工具
2025-12-19 21:44:56 +08:00
// public function judge_wechat_release(){
2025-04-03 18:19:04 +08:00
2025-12-19 21:44:56 +08:00
// }
2024-11-23 16:46:38 +08:00
}