2025-12-22 03:58:08 +08:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-03 18:56:47 +08:00
|
|
|
namespace app\KitchenScale3\controller\admin;
|
2025-12-22 03:58:08 +08:00
|
|
|
|
|
|
|
|
use think\Controller;
|
|
|
|
|
use think\Db;
|
|
|
|
|
use think\Cache;
|
|
|
|
|
use think\Log;
|
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
|
|
|
|
|
|
class Base extends Controller{
|
|
|
|
|
|
|
|
|
|
protected $base_use_db_name = [
|
|
|
|
|
'1'=>'test_app_data_log',
|
|
|
|
|
];
|
|
|
|
|
protected $return_data_all = [
|
|
|
|
|
'10001'=>'关键参数缺失',
|
|
|
|
|
'10002'=>'操作失败',
|
|
|
|
|
'10003'=>'信息核实错误',
|
|
|
|
|
'10004'=>'未找到有效数据',
|
|
|
|
|
'10005'=>'参数格式错误',
|
|
|
|
|
'10006'=>'参数不能为空',
|
|
|
|
|
'10007'=>'参数错误',
|
|
|
|
|
'10008'=>'',
|
|
|
|
|
'10009'=>'',
|
|
|
|
|
'10010'=>'自定义信息',
|
|
|
|
|
'20001'=>'登录失效',
|
|
|
|
|
'99999'=>'网络异常,请稍后重试',
|
|
|
|
|
];
|
|
|
|
|
protected $file_max = 1024*1024*2;//xxxMB
|
|
|
|
|
// 加 bcadd(,,20)
|
|
|
|
|
// 减 bcsub(,,20)
|
|
|
|
|
// 乘 bcmul(,,20)
|
|
|
|
|
// 除 bcdiv(,,20)
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 验证
|
|
|
|
|
public function verify_data_is_ok($data = 2,$type){
|
|
|
|
|
if($type == 'str'){
|
|
|
|
|
if (is_string($data)) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}else if($type == 'num'){
|
|
|
|
|
if (is_numeric($data)) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}else if($type == 'intnum'){
|
|
|
|
|
$pattern = '/^\d+$/';
|
|
|
|
|
if (preg_match($pattern, $data)) {
|
|
|
|
|
return true; // 匹配成功,返回 true
|
|
|
|
|
} else {
|
|
|
|
|
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]);
|
|
|
|
|
return false; // 匹配失败,返回 false
|
|
|
|
|
}
|
|
|
|
|
}else if($type == 'datetime'){
|
|
|
|
|
$formats = ['Y-m-d','Y-m-d H:i:s'];
|
|
|
|
|
foreach ($formats as $format) {
|
|
|
|
|
$dateTime = \DateTime::createFromFormat($format, $data);
|
|
|
|
|
// 检查时间字符串是否成功解析,并且解析后的日期时间与原始字符串表示的时间一致
|
|
|
|
|
if ($dateTime && $dateTime->format($format) === $data) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果所有格式都解析失败,则返回 false
|
|
|
|
|
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]);
|
|
|
|
|
return false;
|
|
|
|
|
}else if($type == 'other'){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
####################################################图片选择上传start##############################################################
|
|
|
|
|
public function pic_index($page = 1) {
|
|
|
|
|
$data = input();
|
|
|
|
|
$pd = true;
|
|
|
|
|
if(array_key_exists('page',$data)){
|
|
|
|
|
$page = $data['page'];
|
|
|
|
|
$pd = false;
|
|
|
|
|
}
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
$num = $cfc->table('app_user_upload_img')->where(['special_record_str'=>'admin'])->count();
|
|
|
|
|
$result = $cfc->table('app_user_upload_img')->where(['special_record_str'=>'admin'])->order('id desc')->page($page,20)->field('id,pic_url')->select();
|
|
|
|
|
if(!$pd){
|
|
|
|
|
$return_result['num'] = $num;
|
|
|
|
|
$return_result['result'] = $result;
|
|
|
|
|
return $this->msg(0,'success',$return_result);
|
|
|
|
|
}
|
|
|
|
|
$this->assign([
|
|
|
|
|
'result' => $result,
|
|
|
|
|
'num' => $num,
|
|
|
|
|
]);
|
|
|
|
|
return $this->fetch();
|
|
|
|
|
}
|
|
|
|
|
public function pic_upload_action(){
|
|
|
|
|
|
|
|
|
|
$save_data = [];
|
|
|
|
|
$error_data = [];
|
|
|
|
|
// 获取表单上传文件
|
|
|
|
|
$files = request()->file('image');
|
|
|
|
|
foreach($files as $file){
|
|
|
|
|
$name = $file->getInfo()['name'];
|
|
|
|
|
// 使用 pathinfo() 函数获取文件名的扩展名
|
|
|
|
|
$pathinfo = pathinfo($name);
|
|
|
|
|
$extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
|
|
|
|
|
$file_name = $pathinfo['filename'];
|
|
|
|
|
// 判断扩展名是否不是 .png 或 .gif
|
|
|
|
|
if ($extension !== 'png' && $extension !== 'gif') {
|
|
|
|
|
// 修改文件名,将扩展名改为 .jpg
|
|
|
|
|
$new_filename = date('YmdHis').$file_name . '.jpg';
|
|
|
|
|
} else {
|
|
|
|
|
$new_filename = date('YmdHis').$name;
|
|
|
|
|
}
|
|
|
|
|
$info = $file->validate(['size'=>$this->file_max,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename);
|
|
|
|
|
if($info){
|
|
|
|
|
array_push($save_data,[
|
|
|
|
|
'user_token'=>'caadd1be045a65f30b92aa805f1de54a',
|
|
|
|
|
'pic_name'=>$new_filename,
|
|
|
|
|
'pic_url'=>'https://tc.pcxbc.com/kitchenscale_all/user_upload/'.$new_filename,
|
|
|
|
|
'create_time'=>date('Y-m-d H:i:s'),
|
|
|
|
|
'special_record_str'=>'admin',
|
|
|
|
|
'operate_log'=>1
|
|
|
|
|
]);
|
|
|
|
|
}else{
|
|
|
|
|
array_push($error_data,[
|
|
|
|
|
'pic_name'=>$name,
|
|
|
|
|
'error_msg'=>$file->getError(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
$pic_result = $cfc->table('app_user_upload_img')->insertAll ($save_data);
|
|
|
|
|
if($pic_result){
|
|
|
|
|
return $this->msg(['success'=>count($save_data),'error_data'=>$error_data]);
|
|
|
|
|
}else{
|
|
|
|
|
for ($i=0; $i < count($save_data); $i++) {
|
|
|
|
|
unlink(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload' . DS . $new_filename);
|
|
|
|
|
}
|
|
|
|
|
return $this->msg(10002,'图片数据保存失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
####################################################图片选择上传end##############################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function msg($data,$str='',$result = []){
|
|
|
|
|
if(is_array($data)){
|
|
|
|
|
if($str != ''){
|
|
|
|
|
return json(['code'=>0,'msg'=>$str,'data'=>$data]);
|
|
|
|
|
}else{
|
|
|
|
|
return json(['code'=>0,'msg'=>'操作成功','data'=>$data]);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if($str != ''){
|
|
|
|
|
return json(['code'=>$data,'msg'=>$str,'data'=>$result]);
|
|
|
|
|
}
|
|
|
|
|
return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|