SchoolPhysicalExamination/application/code/controller/Qrcode.php

424 lines
19 KiB
PHP
Raw Normal View History

2024-12-07 18:56:07 +08:00
<?php
namespace app\code\controller;
use think\Controller;
use think\Db;
use think\Cache;
use think\Log;
class Qrcode extends Base{
public function ordinary_code(){
// $num = Db::table('app_version_log')->order('id desc')->find();
2025-01-22 12:31:08 +08:00
// echo '你好,这里仅仅是个展示页面-配合小白快乐成长&宠物小白使用';
2024-12-07 18:56:07 +08:00
// echo '<br><a href="'.$num['download_url'].'">点击下载</a>';
// $url = Db::table('app_version_log')->order('id desc')->find();
// $this->assign([
// 'url' => $url['download_url'],
// ]);
2025-01-22 12:31:08 +08:00
return $this->fetch();
2024-12-07 18:56:07 +08:00
}
public function bluetooth_code(){
2025-01-22 12:31:08 +08:00
$url = Db::table('app_version_log')->order('id desc')->find();
$this->assign([
2024-12-07 18:56:07 +08:00
2025-01-22 12:31:08 +08:00
'url' => $url['download_url'],
]);
return $this->fetch();
2024-12-07 18:56:07 +08:00
}
2025-04-03 18:19:04 +08:00
##################################################################小贴士视频部分start##################################################################
##################################################################小贴士视频部分start##################################################################
##################################################################小贴士视频部分start##################################################################
// 小贴士的前端二维码页面
public function little_tips_project(){
$qrcode_db = Db::connect('qrcode_db');
// $temporary_data = $qrcode_db->table('little_tips_data')->where(['is_del'=>0])->order('id desc')->select();
// $temporary_data = $qrcode_db->table('little_tips_data')->where(['is_del'=>0])->order('id desc')->select();
$temporary_data2 = $qrcode_db->table('little_tips_label')->where(['type'=>1])->order('is_del,id')->select();
$title = $qrcode_db->table('little_tips_label')->where(['id'=>3])->find();
// dump($temporary_data);
// dump($temporary_data2);
// dump($title);
// die;
$this->assign([
'label' => $temporary_data2,
'title' => $title,
'default_id' => $temporary_data2[0]['id'],
]);
return $this->fetch();
}
// 小贴士前端页面获取数据
public function little_tips_get_video_list(){
$data = input();
$qrcode_db = Db::connect('qrcode_db');
$temporary_data = $qrcode_db->table('little_tips_data')->where(['device_category'=>$data['id'],'is_del'=>0])->order('id desc')->select();
return $this->msg($temporary_data);
}
// 小贴士视频上传管理页面
public function little_tips_project_set_page(){
$qrcode_db = Db::connect('qrcode_db');
$temporary_data = $qrcode_db->table('little_tips_data')
->alias('a')
->join('little_tips_label b','a.device_category = b.id','LEFT')
->field('a.*,b.type_name')
->order('is_del,id desc')
->select();
$temporary_data2 = $qrcode_db->table('little_tips_label')->where(['type'=>1])->order('is_del,id desc')->select();
$title = $qrcode_db->table('little_tips_label')->where(['id'=>3])->find();
$this->assign([
'data' => $temporary_data,
'label' => $temporary_data2,
'title' => $title,
]);
return $this->fetch();
}
public function little_tips_project_upload_action(){
// return $this->msg([]);
$temporary_data = [];
$qrcode_db = Db::connect('qrcode_db');
$device_model = request()->param('device_model_name');
$device_model_type = request()->param('device_model_type');
$device_describe = request()->param('device_describe');
$device_category = request()->param('device_category');
$image_type = request()->param('image_type');
$video_type = request()->param('video_type');
if(!$device_model){
return $this->msg(10001,'设备名称不能为空');
}
$temporary_data = [];
$temporary_data['device_model'] = $device_model;
if($device_describe){
$temporary_data['device_describe'] = $device_describe;
}
if($device_model_type){
$temporary_data['device_type'] = $device_model_type;
}
if($device_category){
$temporary_data['device_category'] = $device_category;
}
// dump($image_type);
// dump($video_type);
if($image_type == 'yes'){
$pic = request()->file('image');
$name_pic = $pic->getInfo()['name'];
$pathinfo_pic = pathinfo($name_pic);
$extension_pic = strtolower($pathinfo_pic['extension']); // 转换为小写以进行不区分大小写的比较
$new_filename_pic = 'pic_'.time().$this->generateRandomString(). '.' . $extension_pic;
$info_pic = $pic->validate(['size'=>10*1024*1024,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'teaching_video',$new_filename_pic);
if(!$info_pic){
// 上传失败获取错误信息
return $this->msg(10010,$pic->getError());
}
$temporary_data['pic_url'] = "https://tc.pcxbc.com/teaching_video/".$new_filename_pic;
$temporary_data['pic_name'] = $new_filename_pic;
}
if($video_type == 'yes'){
$video = request()->file('video');
$name_video = $video->getInfo()['name'];
$pathinfo_video = pathinfo($name_video);
$extension_video = strtolower($pathinfo_video['extension']); // 转换为小写以进行不区分大小写的比较
$new_filename_video = 'pic_'.time().$this->generateRandomString(). '.' . $extension_video;
2025-09-26 16:35:42 +08:00
$info_video = $video->validate(['size'=>1024*1024*1024,'ext'=>'mp4,avi,mkv,wmv'])->move(ROOT_PATH . 'public' . DS . 'teaching_video',$new_filename_video);
2025-04-03 18:19:04 +08:00
if(!$info_video){
// 上传失败获取错误信息
unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $new_filename_pic);
return $this->msg(10011,$video->getError());
}
$temporary_data['video_url'] = "https://tc.pcxbc.com/teaching_video/".$new_filename_video;
$temporary_data['video_name'] = $new_filename_video;
}
// dump($temporary_data);
// die;
// 判断是修改还是新建
$device_data = $qrcode_db->table('little_tips_data')->where(['device_model'=>$temporary_data['device_model']])->find();
if($device_data){
// 修改
// unset($temporary_data['create_time']);
$result = $qrcode_db->table('little_tips_data')
->where(['device_model'=>$temporary_data['device_model']])
->update($temporary_data);
// 删除刚才存储的图片和视频文件
if($image_type == 'yes'){
if($device_data['pic_name']){
if (file_exists(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['pic_name'])) {
unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['pic_name']);
}
}
}
if($video_type == 'yes'){
if($device_data['video_name']){
if (file_exists(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['video_name'])) {
unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['video_name']);
}
}
}
}else{
$temporary_data['create_time'] = date('Y-m-d H:i:s');
$result = $qrcode_db->table('little_tips_data')->insertGetId($temporary_data);
}
if($result){
return $this->msg([]);
}else{
return $this->msg(10002,'操作失败');
}
// // dump($device_model);
// // dump($device_model_type);
// // dump($device_describe);
// // dump($device_category);
// // die;
// if(!$device_model){
// return $this->msg(10001,'设备名称不能为空');
// }
// dump($device_model);
// dump($devicdevice_model_typee_model);
// dump($device_category);
// dump($device_describe);
// dump($pic);
// dump($video);
// die;
// // if(!$device_model_type){
// // return $this->msg(10001,'设备类型不能为空');
// // }
// // if(!$device_category){
// // return $this->msg(10001,'设备设备分类不能为空');
// // }
// if(!$pic || !$video){
// return $this->msg(10001,'未选择图片或者视频');
// }else{
// // $name_pic = $pic->getInfo()['name'];
// // $pathinfo_pic = pathinfo($name_pic);
// // $extension_pic = strtolower($pathinfo_pic['extension']); // 转换为小写以进行不区分大小写的比较
// // $new_filename_pic = 'pic_'.time().$this->generateRandomString(). '.' . $extension_pic;
// // $name_video = $video->getInfo()['name'];
// // $pathinfo_video = pathinfo($name_video);
// // $extension_video = strtolower($pathinfo_video['extension']); // 转换为小写以进行不区分大小写的比较
// // $new_filename_video = 'pic_'.time().$this->generateRandomString(). '.' . $extension_video;
// // $info_pic = $pic->validate(['size'=>10*1024*1024,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'teaching_video',$new_filename_pic);
// // if(!$info_pic){
// // // 上传失败获取错误信息
// // return $this->msg(10010,$pic->getError());
// // }
// // $info_video = $video->validate(['size'=>90*1024*1024,'ext'=>'mp4,avi,mkv,wmv'])->move(ROOT_PATH . 'public' . DS . 'teaching_video',$new_filename_video);
// // if(!$info_video){
// // // 上传失败获取错误信息
// // unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $new_filename_pic);
// // return $this->msg(10011,$video->getError());
// // }
// $temporary_data = [
// 'device_model'=>$device_model,
// 'device_describe'=>$device_describe,
// 'device_type'=>$device_model_type,
// 'device_category'=>$device_category,
// 'pic_url'=>"https://tc.pcxbc.com/teaching_video/".$new_filename_pic,
// 'video_url'=>"https://tc.pcxbc.com/teaching_video/".$new_filename_video,
// 'pic_name'=>$new_filename_pic,
// 'video_name'=>$new_filename_video,
// 'create_time'=>date('Y-m-d H:i:s'),
// ];
// if($device_data){
// unset($temporary_data['create_time']);
// $result = $qrcode_db->table('little_tips_data')
// ->where(['device_model'=>$temporary_data['device_model']])
// ->update($temporary_data);
// // 删除刚才存储的图片和视频文件
// if (file_exists(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['pic_name'])) {
// unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['pic_name']);
// }
// if (file_exists(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['video_name'])) {
// unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['video_name']);
// }
// return $this->msg([]);
// }else{
// $result = $qrcode_db->table('little_tips_data')->insertGetId($temporary_data);
// }
// if($result){
// return $this->msg([]);
// }else{
// return $this->msg(10002,'添加失败');
// }
// }
}
// 小贴士下架操作
public function little_tips_is_del_update(){
$data = input();
$qrcode_db = Db::connect('qrcode_db');
if(!array_key_exists('id', $data)){
return $this->msg(10001,'id缺失');
}
if(!array_key_exists('type', $data)){
return $this->msg(10001,'type缺失');
}
$device_data = $qrcode_db->table('little_tips_data')->where(['id'=>$data['id']])->field('pic_name,video_name')->find();
if($device_data){
$temporary_data = $qrcode_db->table('little_tips_data')->where(['id'=>$data['id']])->update(['is_del'=>$data['type']]);
if($temporary_data){
return $this->msg([]);
}else{
return $this->msg(10002,'操作失败');
}
}else{
return $this->msg(10002,'未找到对应设备信息');
}
}
// 小贴士删除操作
public function little_tips_del_action(){
$data = input();
$qrcode_db = Db::connect('qrcode_db');
if(!array_key_exists('id', $data)){
return $this->msg(10001,'id缺失');
}
$device_data = $qrcode_db->table('little_tips_data')->where(['id'=>$data['id']])->field('pic_name,video_name')->find();
$temporary_data = $qrcode_db->table('little_tips_data')->where(['id'=>$data['id']])->delete();
unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['pic_name']);
unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $device_data['video_name']);
if($temporary_data){
return $this->msg([]);
}else{
return $this->msg(10002,'操作失败');
}
}
##################################################################小贴士视频部分end##################################################################
##################################################################小贴士视频部分end##################################################################
##################################################################小贴士视频部分end##################################################################
public function add_label_action(){
$data = input();
$qrcode_db = Db::connect('qrcode_db');
if(!array_key_exists('label', $data)){
return $this->msg(10001,'label缺失');
}
$device_data = $qrcode_db->table('little_tips_label')->insert([
'type_name'=>$data['label'],
'create_time'=>date('Y-m-d H:i:s'),
'type'=>1,
]);
if($device_data){
return $this->msg([]);
}else{
return $this->msg(10002,'操作失败');
}
}
2025-09-03 19:09:13 +08:00
public function del_device_label_name(){
$data = input();
$qrcode_db = Db::connect('qrcode_db');
if(!array_key_exists('label', $data)){
return $this->msg(10001,'label缺失');
}
$device_data = $qrcode_db->table('little_tips_label')->where(['id'=>$data['label']])->delete();
if($device_data){
return $this->msg([]);
}else{
return $this->msg(10002,'操作失败');
}
}
2025-04-03 18:19:04 +08:00
public function update_title_action(){
$data = input();
$qrcode_db = Db::connect('qrcode_db');
if(!array_key_exists('title', $data)){
return $this->msg(10001,'title缺失');
}
$device_data = $qrcode_db->table('little_tips_label')->where(['id'=>3])->update([
'type_name'=>$data['title'],
]);
if($device_data){
return $this->msg([]);
}else{
return $this->msg(10002,'操作失败');
}
}
2025-07-23 21:32:05 +08:00
##################################################################儿童膳食食谱文档跳转start##################################################################
##################################################################儿童膳食食谱文档跳转start##################################################################
##################################################################儿童膳食食谱文档跳转start##################################################################
public function children_meals_cookbook(){
// header("Location: http://121.36.67.254:3000/tiansf/childrens-dietary-recipes");
header("Location: http://git.ybhdmob.com:3000/tiansf/childrens-dietary-recipes");
}
##################################################################儿童膳食食谱文档跳转end##################################################################
##################################################################儿童膳食食谱文档跳转end##################################################################
##################################################################儿童膳食食谱文档跳转end##################################################################
2025-04-03 18:19:04 +08:00
2025-07-23 21:32:05 +08:00
##################################################################二维码-厨房秤小程序跳转start##################################################################
##################################################################二维码-厨房秤小程序跳转start##################################################################
##################################################################二维码-厨房秤小程序跳转start##################################################################
public function kitchen_qrcode(){
return $this->fetch();
}
##################################################################二维码-厨房秤小程序跳转end##################################################################
##################################################################二维码-厨房秤小程序跳转end##################################################################
##################################################################二维码-厨房秤小程序跳转end##################################################################
2025-04-03 18:19:04 +08:00
##################################################################以下是工具部分##################################################################
##################################################################以下是工具部分##################################################################
##################################################################以下是工具部分##################################################################
public function generateRandomString($length = 10) {
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
2024-12-07 18:56:07 +08:00
}