部分线上测试

This commit is contained in:
tiansf 2025-01-22 12:31:08 +08:00
parent 9fce437479
commit 8d3b39a59c
16 changed files with 2234 additions and 858 deletions

View File

@ -13,6 +13,7 @@ class Base extends Controller{
protected $base_use_db_name = [
'1'=>'test_app_data_log',
];
protected $file_size = 5*1024*1024;
protected $return_data_all = [
'10001'=>'关键参数缺失',
'10002'=>'操作失败',
@ -122,6 +123,7 @@ class Base extends Controller{
}
}else if($type == 'intnum'){
$pattern = '/^\d+$/';
// dump($data);
if (preg_match($pattern, $data)) {
return true; // 匹配成功,返回 true
} else {
@ -145,6 +147,118 @@ class Base extends Controller{
}
}
####################################################图片选择上传start##############################################################
public function pic_chose_list($page = 1) {
$data = input();
if(!array_key_exists('token',$data)){
return $this->msg(10001,'token is miss');
}
if(array_key_exists('page',$data)){
$page = $data['page'];
}
$parameter_data = [
'user_token'=>$data['token'],
'is_del'=>0
];
$cfc = Db::connect('cfc_db');
$num = $cfc->table('app_user_upload_img')->where($parameter_data)->count();
$result = $cfc->table('app_user_upload_img')->where($parameter_data)->order('id desc')->page($page,20)->field('id,pic_name,pic_url')->select();
$return_result['total_num'] = $num;
$return_result['page_now'] = $page;
$return_result['result'] = $result;
return $this->msg($return_result);
}
public function pic_upload_action(){
$insert_data = [];
$temporary_data = [];
$miss_data = 0;
$cfc = Db::connect('cfc_db');
$files = request()->file('images');
$token = request()->param('token');
if(!$token){
return $this->msg(10001,'token is miss');
}
if($files){
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 = time().$this->generateRandomString(). '.jpg';
} else {
$new_filename = time().$this->generateRandomString(). '.' . $extension;
}
$info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename);
if($info){
$temporary_data = [
'user_token'=>$token,
'pic_name'=>$new_filename,
'pic_url'=>"https://tc.pcxbc.com/kitchenscale_all/user_upload/".$new_filename,
// 'pic_url'=>"http://wm.tcxbc.com/kitchenscale_all/user_upload/".$new_filename,
'create_time'=>date('Y-m-d H:i:s'),
];
$pic_id = $cfc->table('app_user_upload_img')->insertGetId($temporary_data);
if($pic_id){
$temporary_data['id'] = $pic_id;
unset($temporary_data['create_time']);
unset($temporary_data['user_token']);
array_push($insert_data,$temporary_data);
}else{
$miss_data = $miss_data+1;
}
}else{
$miss_data = $miss_data+1;
}
}
return $this->msg(['error_data'=>$miss_data,'insert_data'=>$insert_data]);
}else{
return $this->msg(10001,'未选择图片');
}
// dump($file);
die;
if($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_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'upload_pic',$new_filename);
if($info){
$insert_data = [
'url_data'=>"https://tc.pcxbc.com/upload_pic/".$new_filename,
'name'=>$new_filename,
'create_time'=>date('Y-m-d H:i:s'),
];
$pic_result = Db::table('admin_pic_manage')->insertGetId($insert_data);
if($pic_result){
return $this->msg(['url'=>$insert_data['url_data'],'id'=>$pic_result]);
}else{
return $this->msg(10002,'图片数据保存失败');
}
}else{
return $this->msg(10002,'图片上传失败');
}
}
}
public function msg($data,$str='',$result = []){
@ -162,6 +276,16 @@ class Base extends Controller{
}
}
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;
}
public function ceshi(){
echo 'hello';
}

View File

@ -0,0 +1,787 @@
<?php
namespace app\KitchenScale\controller\app;
use think\Db;
class Cookbook extends Base{
protected $code_time = 50;
// protected $token_time = 2592000;//30天的秒数
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
protected $reedaw_db_msg = [
'zhanghao'=>'app_account_number',//账号表
'juese'=>'app_user_data',//角色表
];
protected $kitchenscale_db_msg = [
'cookbook'=>'app_user_cookbook',//菜谱表
'uploadimg'=>'app_user_upload_img',//素材表
'followlist'=>'app_user_follow_list',//关注列表
'collectlist'=>'app_user_collect_list',//收藏列表
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 添加菜谱
public function add_cookbook(){
// 尝试捕获异常
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('cover', $data)){
return $this->msg(10001,'cover is miss');
}
if(!array_key_exists('description', $data)){
return $this->msg(10001,'description is miss');
}
if(!array_key_exists('cook_label', $data)){
return $this->msg(10001,'cook_label is miss');
}
if(!array_key_exists('food_list', $data)){
$data['food_list'] = [];
}
if(!array_key_exists('step_list', $data)){
$data['step_list'] = [];
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['cover'],'intnum')){
return $this->msg(10005,'cover type is error');
}
if(!$this->verify_data_is_ok($data['description'],'str')){
return $this->msg(10005,'description type is error');
}
if (!is_array($data['food_list'])) {
return $this->msg(10005,'food_list type is error');
}
if (!is_array($data['step_list'])) {
return $this->msg(10005,'step_list type is error');
}
$return_data = $this->add_cookbook_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["file"] = $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 json(['status' => 'error', 'message' => '系统错误']);
// }
}
// 根据菜谱标签查询列表(首页用)
public function find_by_cook_label($data=['token'=>'caadd1be045a65f3','cook_label'=>'早餐','page'=>'1']){
// 尝试捕获异常
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('cook_label', $data)){
return $this->msg(10001,'cook_label is miss');
}
if(!array_key_exists('page', $data)){
return $this->msg(10001,'page is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['cook_label'],'str')){
return $this->msg(10005,'cook_label type is error');
}
if(!$this->verify_data_is_ok($data['page'],'intnum')){
return $this->msg(10005,'page type is error');
}
$return_data = $this->find_by_cook_label_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["file"] = $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 json(['status' => 'error', 'message' => '系统错误']);
// }
}
// 根据食材详细查找列表
public function find_by_food($data=['token'=>'caadd1be045a65f3','food_name'=>'猪肉','page'=>'1']){
// 尝试捕获异常
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('food_name', $data)){
return $this->msg(10001,'food_name is miss');
}
if(!array_key_exists('page', $data)){
return $this->msg(10001,'page is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['food_name'],'str')){
return $this->msg(10005,'food_name type is error');
}
if(!$this->verify_data_is_ok($data['page'],'intnum')){
return $this->msg(10005,'page type is error');
}
$return_data = $this->find_by_food_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["file"] = $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 json(['status' => 'error', 'message' => '系统错误']);
// }
}
// 查询食谱的详情
public function cookbook_details($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','cookbook_id'=>'12']){
// 尝试捕获异常
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('cookbook_id', $data)){
return $this->msg(10001,'cookbook_id is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
return $this->msg(10005,'cookbook_id type is error');
}
$return_data = $this->cookbook_details_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["file"] = $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 json(['status' => 'error', 'message' => '系统错误']);
// }
}
// 关注菜谱
public function cookbook_follow($data=['token'=>'caadd1be045a65f3','cookbook_id'=>'12']){
// 尝试捕获异常
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('cookbook_id', $data)){
return $this->msg(10001,'cookbook_id is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
return $this->msg(10005,'cookbook_id type is error');
}
$return_data = $this->cookbook_follow_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["file"] = $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 json(['status' => 'error', 'message' => '系统错误']);
// }
}
// 收藏菜谱
public function cookbook_like($data=['token'=>'caadd1be045a65f3','cookbook_id'=>'12']){
// 尝试捕获异常
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('cookbook_id', $data)){
return $this->msg(10001,'cookbook_id is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
return $this->msg(10005,'cookbook_id type is error');
}
$return_data = $this->cookbook_like_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["file"] = $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 json(['status' => 'error', 'message' => '系统错误']);
// }
}
// 计算根据菜谱称重
public function cookbook_count_weight($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','cookbook_id'=>'12','food_weight'=>[]]){
// 尝试捕获异常
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('cookbook_id', $data)){
return $this->msg(10001,'cookbook_id is miss');
}
if(!array_key_exists('food_weight', $data)){
return $this->msg(10001,'food_weight is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
return $this->msg(10005,'cook_label type is error');
}
$return_data = $this->cookbook_count_weight_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["file"] = $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 json(['status' => 'error', 'message' => '系统错误']);
// }
}
#######################################################################action#######################################################################
public function add_cookbook_action($data){
if(count($data['food_list']) < 1){
return $this->msg(10005,'至少添加一个食物');
}
if(count($data['step_list']) < 1){
return $this->msg(10005,'至少添加一个步骤');
}
$food_type = [];
// 检验一下food_list是否合规食材列表
foreach ($data['food_list'] as $key => $value) {
if (!array_key_exists('name', $value) || !array_key_exists('weight', $value)) {
return $this->msg(10005,'食材缺少名称或者重量');
}
if(!$this->verify_data_is_ok($value['name'],'str')){
return $this->msg(10005,'食材名称格式错误,需字符串');
}
if(!$this->verify_data_is_ok($value['weight'],'intnum')){
return $this->msg(10005,'食材重量格式错误,需整数数字');
}
array_push($food_type, $value['name']);
}
// 检验一下step_list是否合规步骤列表
foreach ($data['step_list'] as $key => $value) {
// if (!array_key_exists('description', $value) || !array_key_exists('foot_list', $value) || !array_key_exists('pic_list', $value)) {
if (!array_key_exists('description', $value) || !array_key_exists('pic_list', $value)) {
return $this->msg(10005,'步骤缺少描述或者图片');
}
if(!$this->verify_data_is_ok($value['description'],'str')){
return $this->msg(10005,'步骤描述格式错误,需要正常字符');
}
foreach ($value['pic_list'] as $k => $v) {
if(!$this->verify_data_is_ok($v,'intnum')){
return $this->msg(10005,'步骤中图片ID错误,需整数数字');
}
}
// foreach ($value['foot_list'] as $k => $v) {
// if (!array_key_exists('name', $v) || !array_key_exists('weight', $v)) {
// return $this->msg(10005,'步骤食材缺少名称或者重量');
// }
// if(!$this->verify_data_is_ok($v['name'],'str')){
// return $this->msg(10005,'步骤食材名称格式错误,需字符串');
// }
// if(!$this->verify_data_is_ok($v['weight'],'intnum')){
// return $this->msg(10005,'步骤食材重量格式错误,需整数数字');
// }
// }
}
$cfc = Db::connect('cfc_db');
// 获取账号下信息以及用户信息
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
// 处理食材卡路里start
foreach ($data['food_list'] as $key => $value) {
$data['food_list'][$key]['kcal'] = '0kcal';
}
// foreach ($data['step_list'] as $key => $value) {
// foreach ($value['foot_list'] as $k => $v) {
// $data['step_list'][$key]['foot_list'][$k]['kcal'] = '0kcal';
// }
// }
// 处理食材卡路里end
$insert_data = [
'title'=>$data['title'],
'cover'=>$data['cover'],
'create_user_token'=>$user_data['token'],
'create_user_head_pic'=>$user_data['head_pic'],
'create_user_nickname'=>$user_data['nickname'],
'describe_data'=>$data['description'],
'food_data'=>json_encode($data['food_list']),
'step_data'=>json_encode($data['step_list']),
'food_type'=>implode(',', $food_type),
'cook_label'=>$data['cook_label'],
'create_time'=>date('Y-m-d H:i:s')
];
$cook_book_result = $cfc->table($this->kitchenscale_db_msg['cookbook'])->insert($insert_data);
if($cook_book_result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
public function find_by_cook_label_action($data){
$page_now = $data['page'];
$page_total = $data['page'];
$page_num = 20;
$cook_label = $data['cook_label'];
$cfc = Db::connect('cfc_db');
$content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
->where(['cook_label'=>$cook_label])
->count();
$page_total = ceil($content_num/$page_num);
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
->alias('cookbook')
->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT')
->where(['cookbook.cook_label'=>$cook_label])
->field('cookbook.id,cookbook.title,uploadimg.pic_url as cover,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.like_it as like_num')
->page("$page_now,$page_num")
->select();
// 处理本人是否关注 start
$like_it_arr = [];
foreach ($content_list as $key => $value) {
array_push($like_it_arr, $value['id']);
}
$like_it_data = $cfc->table($this->kitchenscale_db_msg['collectlist'])
->where("token = '".$data['token']."' AND cookbook_id in (".implode(',',$like_it_arr).") AND is_del = 0")
->select();
$like_it_arr2 = [];
foreach ($like_it_data as $key => $value) {
array_push($like_it_arr2, $value['cookbook_id']);
}
foreach ($content_list as $key => $value) {
if(in_array($value['id'],$like_it_arr2)){
$content_list[$key]['is_like'] = 1;
}else{
$content_list[$key]['is_like'] = 0;
}
}
// 处理本人是否关注 end
for ($i=0; $i < count($content_list); $i++) {
if($content_list[$i]['cover'] == null){
$content_list[$i]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
}
}
return $this->msg([
'page_now'=>$page_now,
'page_total'=>$page_total,
'content_list'=>$content_list
]);
}
public function find_by_food_action($data){
$page_now = $data['page'];
$page_total = $data['page'];
$page_num = 20;
$food_name = $data['food_name'];
$cfc = Db::connect('cfc_db');
$content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
->where("food_type like '%$food_name%'")
->count();
$page_total = ceil($content_num/$page_num);
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
->alias('cookbook')
->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT')
->where("cookbook.food_type like '%$food_name%'")
->field('cookbook.id,cookbook.title,uploadimg.pic_url as cover,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.like_it')
->page("$page_now,$page_num")
->select();
// 处理本人是否关注 start
$like_it_arr = [];
foreach ($content_list as $key => $value) {
array_push($like_it_arr, $value['id']);
}
$like_it_data = $cfc->table($this->kitchenscale_db_msg['collectlist'])
->where("token = '".$data['token']."' AND cookbook_id in (".implode(',',$like_it_arr).") AND is_del = 0")
->select();
$like_it_arr2 = [];
foreach ($like_it_data as $key => $value) {
array_push($like_it_arr2, $value['cookbook_id']);
}
foreach ($content_list as $key => $value) {
if(in_array($value['id'],$like_it_arr2)){
$content_list[$key]['is_like'] = 1;
}else{
$content_list[$key]['is_like'] = 0;
}
}
// 处理本人是否关注 end
for ($i=0; $i < count($content_list); $i++) {
if($content_list[$i]['cover'] == null){
$content_list[$i]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
}
}
return $this->msg([
'page_now'=>$page_now,
'page_total'=>$page_total,
'content_list'=>$content_list
]);
}
public function cookbook_details_action($data){
$cfc = Db::connect('cfc_db');
$img_arr = [];
// 查询菜谱详情
$cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->find();
if(!$cookbook_data){
return $this->msg(10002,'菜谱不存在');
}
$cookbook_data['food_data'] = json_decode($cookbook_data['food_data'],true);
$cookbook_data['step_data'] = json_decode($cookbook_data['step_data'],true);
$cookbook_data_step_data_count = count($cookbook_data['step_data']);
// 设置需要的图片id
array_push($img_arr, $cookbook_data['cover']);
foreach ($cookbook_data['step_data'] as $key => $value) {
if(count($value['pic_list']) > 0){
foreach ($value['pic_list'] as $k => $v) {
if(!in_array($v, $img_arr)){
array_push($img_arr, $v);
}
}
}
}
$img_arr = implode(',',$img_arr);
// 查找需要的图片
$img_arr_data = $cfc->table($this->kitchenscale_db_msg['uploadimg'])->where("id in ($img_arr) AND is_del = 0")->field('id,pic_name,pic_url')->select();
$cookbook_img_data = [];
// 处理菜谱图片
foreach ($img_arr_data as $key => $value) {
$cookbook_img_data[$value['id']] = $value['pic_url'];
}
// 设置菜谱图片
foreach ($cookbook_data['step_data'] as $key => $value) {
$cookbook_data['step_data'][$key]['pic_list_ls'] = [];
foreach ($value['pic_list'] as $k => $v) {
if(array_key_exists($v, $cookbook_img_data)){
array_push($cookbook_data['step_data'][$key]['pic_list_ls'],$cookbook_img_data[$v]);
}else{
array_push($cookbook_data['step_data'][$key]['pic_list_ls'],'https://tc.pcxbc.com/kitchenscale_all/diule.jpg');
}
}
$cookbook_data['step_data'][$key]['pic_list'] = $cookbook_data['step_data'][$key]['pic_list_ls'];
unset($cookbook_data['step_data'][$key]['pic_list_ls']);
$cookbook_data['step_data'][$key]['step_num'] = "步骤".($key+1).'/'.$cookbook_data_step_data_count;
}
if(array_key_exists($cookbook_data['cover'], $cookbook_img_data)){
$cookbook_data['cover'] = $cookbook_img_data[$cookbook_data['cover']];
}else{
$cookbook_data['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
}
// 处理关注跟收藏信息
if($data['token'] == $cookbook_data['create_user_token']){
// 如果查询跟作者一致
$cookbook_data['follow_status'] = 3;
$cookbook_data['collect_status'] = 3;
}else{
$follow_data = $cfc->table($this->kitchenscale_db_msg['followlist'])
->where([
'follow_user_token'=>$data['token'],
'being_follow_user_token'=>$cookbook_data['create_user_token'],
])
->find();
if($follow_data){
if($follow_data['is_del'] == 0){
// 如果有结果并且没被删过
$cookbook_data['follow_status'] = 1;
}else{
// 如果有结果被删过
$cookbook_data['follow_status'] = 0;
}
}else{
// 如果没结果
$cookbook_data['follow_status'] = 0;
}
$collect_data = $cfc->table($this->kitchenscale_db_msg['collectlist'])
->where([
'token'=>$data['token'],
'cookbook_id'=>$data['cookbook_id'],
])
->find();
if($collect_data){
if($collect_data['is_del'] == 0){
// 如果有结果并且没被删过
$cookbook_data['collect_status'] = 1;
}else{
// 如果有结果被删过
$cookbook_data['collect_status'] = 0;
}
}else{
// 如果没结果
$cookbook_data['collect_status'] = 0;
}
}
// 添加阅读量
$read_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('read_it');
if($read_num){
$cookbook_data['read_it'] = $cookbook_data['read_it']+1;
}
unset($cookbook_data['create_user_token']);
unset($cookbook_data['create_time']);
unset($cookbook_data['cook_label']);
unset($cookbook_data['food_type']);
unset($cookbook_data['ROW_NUMBER']);
return $this->msg($cookbook_data);
// dump($cookbook_data);
}
public function cookbook_follow_action($data){
// dump($data);
$cfc = Db::connect('cfc_db');
$cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token')->find();
if(!$cookbook_data){
return $this->msg(10002,'未找到菜谱');
}
if($data['token'] == $cookbook_data['create_user_token']){
// 如果查询跟作者一致
return $this->msg(10002,'不能关注自己');
}
$follow_data = $cfc->table($this->kitchenscale_db_msg['followlist'])
->where([
'follow_user_token'=>$data['token'],
'being_follow_user_token'=>$cookbook_data['create_user_token'],
])
->find();
$follow_data_state = 0;
if($follow_data){
if($follow_data['is_del'] == 0){
// 如果当前是关注状态
$follow_data_state = 1;
}else{
$follow_data_state = 0;
}
$follow_result= $cfc->table($this->kitchenscale_db_msg['followlist'])
->where([
'follow_user_token'=>$data['token'],
'being_follow_user_token'=>$cookbook_data['create_user_token'],
])
->update(['is_del'=>$follow_data_state]);
}else{
$follow_result = $cfc->table($this->kitchenscale_db_msg['followlist'])
->insert([
'follow_user_token'=>$data['token'],
'being_follow_user_token'=>$cookbook_data['create_user_token'],
'create_time'=>date('Y-m-d H:i:s')
]);
}
if($follow_result){
return $this->msg([]);
}else{
return $this->msg(10001,'操作失败');
}
}
public function cookbook_like_action($data){
$cfc = Db::connect('cfc_db');
$cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token')->find();
if(!$cookbook_data){
return $this->msg(10002,'未找到菜谱');
}
if($data['token'] == $cookbook_data['create_user_token']){
// 如果查询跟作者一致
return $this->msg(10002,'不能收藏自己');
}
$like_data = $cfc->table($this->kitchenscale_db_msg['collectlist'])
->where([
'token'=>$data['token'],
'cookbook_id'=>$data['cookbook_id'],
])
->find();
$like_data_state = 0;
if($like_data){
if($like_data['is_del'] == 0){
// 如果当前是关注状态
$like_data_state = 1;
}else{
$like_data_state = 0;
}
// 启动事务
Db::startTrans();
try{
$cfc->table($this->kitchenscale_db_msg['collectlist'])
->where([
'token'=>$data['token'],
'cookbook_id'=>$data['cookbook_id'],
])
->update(['is_del'=>$like_data_state]);
if($like_data_state == 0){
$cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('like_it');
}else{
$cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setDec('like_it');
}
// 提交事务
Db::commit();
return $this->msg([]);
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $this->msg(10001,'操作失败');
}
}else{
// 启动事务
Db::startTrans();
try{
$cfc->table($this->kitchenscale_db_msg['collectlist'])
->insert([
'token'=>$data['token'],
'cookbook_id'=>$data['cookbook_id'],
'create_time'=>date('Y-m-d H:i:s')
]);
$cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('like_it');
// 提交事务
Db::commit();
return $this->msg([]);
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $this->msg(10001,'操作失败');
}
}
}
public function cookbook_count_weight_action($data){
$data['food_weight'] = [
[
'food_name'=>'牛肉',
'food_weight'=>'100',
'food_kcal'=>'190',
],
[
'food_name'=>'狗肉',
'food_weight'=>'100',
'food_kcal'=>'116',
],
];
foreach ($variable as $key => $value) {
if(!array_key_exists('food_name', $data['food_weight']) || !array_key_exists('food_weight', $data['food_weight']) || !array_key_exists('food_kcal', $data['food_weight'])){
return $this->msg(10001,'食材称重参数错误');
}
}
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace app\KitchenScale\controller\app;
use think\Db;
class Login extends Base{
protected $code_time = 50;
// protected $token_time = 2592000;//30天的秒数
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
protected $login_use_db_name = [
'1'=>'app_account_number',
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 注册
public function login_api($data = ['account'=>123,'password'=>456]){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('account', $data) && !array_key_exists('password', $data)){
return $this->msg(10001);
}
$return_data = $this->login_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);
}
}
#######################################################################action#######################################################################
public function login_action($data){
// dump($data);
$user = Db::table('admin_user_account_number')->where(["account_num"=>$data['account'],'password'=>$data['password']])->find();
// dump($user);
// die;
if($user){
return $this->msg(['token'=>$user['token']]);
}else{
return $this->msg(10004);
}
}
}

View File

@ -10,12 +10,19 @@ class Index extends Base{
// protected $token_time = 2592000;//30天的秒数
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
protected $reedaw_db_msg = [
'zhanghao'=>'test_app_account_number',//账号表
'juese'=>'test_app_user_data',//角色表
'banner'=>'admin_notice_banner',//角色表
'read_log'=>'admin_editor_text_like_up_log',//角色表
'zhanghao'=>'app_account_number',//账号表
'juese'=>'app_user_data',//角色表
'banner'=>'admin_notice_banner',//banner
'read_log'=>'admin_editor_text_like_up_log',//阅读记录
'cookbook'=>'app_user_cookbook',//菜谱表
'upload_img'=>'app_user_upload_img',//素材表
];
protected $kitchenscale_db_msg = [
'cookbook'=>'app_user_cookbook',//菜谱表
'uploadimg'=>'app_user_upload_img',//素材表
'foodlist1'=>'app_food_type_one',//素材表
'foodlist2'=>'app_food_type_two',//素材表
'foodlist3'=>'app_food_type_three',//素材表
];
@ -27,12 +34,12 @@ class Index extends Base{
################################################################接口################################################################
################################################################接口################################################################
// 获取默认配置信息
// 获取默认配置信息(包含:食材的分类列表)
public function get_default_config(){
// try {
$return_data = $this->get_default_config_action($data);
$return_data = $this->get_default_config_action();
// 成功
$this->record_api_log($data, null, $return_data);
// $this->record_api_log($data, null, $return_data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
@ -51,7 +58,7 @@ class Index extends Base{
}
// 获取首页信息
public function get_homepage_information($data = ['token'=>'6441bf7dabea7b3360a30240d3b19fc5']){
public function get_homepage_information($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
// try {
// 你的业务逻辑
if(count(input('post.')) > 0){
@ -81,10 +88,41 @@ class Index extends Base{
// return $this->msg(99999);
// }
}
#######################################################################action#######################################################################
public function get_default_config_action(){
$return_data = [
'food_list'=>[],
];
$cfc = Db::connect('cfc_db');
// 获取食材分类列表start
$foodlist1 = $cfc->table($this->kitchenscale_db_msg['foodlist1'])->where("is_del = 0")->field('id,name')->select();
$foodlist2 = $cfc->table($this->kitchenscale_db_msg['foodlist2'])->where("is_del = 0")->field('id,name,one_id')->select();
$foodlist3 = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where("is_del = 0")->field('id,name,two_id,kcal')->select();
// dump($foodlist3);
foreach ($foodlist1 as $key => $value) {
unset($foodlist1[$key]['ROW_NUMBER']);
$foodlist1[$key]['list'] = [];
foreach ($foodlist2 as $k => $v) {
$foodlist2[$k]['list'] = [];
foreach ($foodlist3 as $k3 => $v3) {
if($v3['two_id'] == $v['id']){
unset($foodlist3[$k3]['ROW_NUMBER']);
array_push($foodlist2[$k]['list'],$foodlist3[$k3]);
// unset($foodlist3[$k3]);
}
}
if($v['one_id'] == $value['id']){
unset($foodlist2[$k]['ROW_NUMBER']);
array_push($foodlist1[$key]['list'],$foodlist2[$k]);
// unset($foodlist2[$k]);
}
}
}
$return_data['food_list'] = $foodlist1;
// 获取食材分类列表end
return $this->msg($return_data);
}
public function get_homepage_information_action($data){
@ -92,19 +130,22 @@ class Index extends Base{
$return_data = [
'account'=>[],
'banner'=>[],
'content'=>[],
'content'=>[
'label_list'=>[],
'content_list'=>[],
],
];
$cfc = Db::connect('cfc_db');
// 获取账号下信息以及用户信息
$user_account = Db::table($this->reedaw_db_msg['zhanghao'])
->alias('zhanghao')
->join($this->reedaw_db_msg['juese'].' juese','zhanghao.id = juese.aan_id','LEFT')
->where(["zhanghao.token"=>$data['token'],'juese.is_del'=>0])
->field('juese.id as aud_id,juese.nickname,juese.birthday,juese.gender,juese.last_update_time,juese.grade,juese.head_pic,juese.weight,juese.height,juese.identity_name,juese.address,juese.identity_id,juese.weight')
// ->field('juese.id as aud_id,juese.nickname,juese.birthday,juese.gender,juese.last_update_time,juese.grade,juese.head_pic,juese.weight,juese.height,juese.identity_name,juese.address,juese.identity_id,juese.weight')
->field('juese.id as aud_id,juese.nickname,juese.birthday,juese.gender,juese.grade,juese.head_pic')
->select();
$return_data['account'] = $user_account;
// 获取banner
$banner_list = Db::table($this->reedaw_db_msg['banner'])
->where("is_del = 0 AND scene_data IN (21)")
@ -138,15 +179,30 @@ class Index extends Base{
$return_data['banner'] = $banner_list;
// 获取菜谱列表
$label_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])->group('cook_label')->field('cook_label,count(*) as num')->select();
if(count($label_list) <= 0){
$return_data['content']['label_list'] = [];
$return_data['content']['content_list'] = [];
return $this->msg($return_data);
}
dump($return_data);
die;
if($user){
return $this->msg(['token'=>$user['token']]);
}else{
return $this->msg(10004);
}
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
->alias('zhanghao')
->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','zhanghao.cover = uploadimg.id','LEFT')
->where(['zhanghao.cook_label'=>$label_list[0]['cook_label']])
->field('zhanghao.title,uploadimg.pic_url as cover,zhanghao.create_user_head_pic,zhanghao.create_user_nickname,zhanghao.like_it')
->page("1,20")
->select();
$return_data['content']['label_list'] = $label_list;
for ($i=0; $i < count($content_list); $i++) {
if($content_list[$i]['cover'] == null){
$content_list[$i]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
}
}
$return_data['content']['content_list'] = $content_list;
return $this->msg($return_data);
}

View File

@ -212,9 +212,22 @@ class Device extends Base{
public function device_request_api(){
$data = input();
// $data = input();
$rawData = file_get_contents('php://input'); // 获取原始请求体
$result = Db::table('app_device_log_test')->insert(['content'=>json_encode($data),'create_time'=>date('Y-m-d H:i:s)')]);
// $params = explode(',', trim($rawData, '{}')); // 假设参数是用逗号分隔的,并且被大括号包裹
// // 现在$params是一个数组包含了['03', '180.0', '65.1']
// $param1 = $params[0]; // 获取第一个参数
// $param2 = $params[1]; // 获取第二个参数,注意转换为浮点数或保持字符串形式
// $param3 = $params[2]; // 获取第三个参数
// dump($data);
// dump(json_encode($data));
// dump($rawData);
$content = json_encode($rawData);
// dump($content);
// die;
$result = Db::table('app_device_log_test')->insert(['content'=>$content,'create_time'=>date('Y-m-d H:i:s')]);
if($result){
return $this->msg(0,'success');
@ -235,16 +248,17 @@ class Device extends Base{
$neirong = '';
foreach ($result as $key => $value) {
$temporary_arr1 = json_decode($value['content'],true);
if(count($temporary_arr1) == 0){
$temporary_arr2 = '请求参数为:</br>'."本次未发送请求参数</br>";
}else{
$temporary_arr2 = '请求参数为:</br>';
}
foreach ($temporary_arr1 as $k => $v) {
$temporary_arr2 = $temporary_arr2.$k."(参数名):".$v."(参数值)</br>";
}
$neirong = $neirong.$temporary_arr2.'请求时间为:'.$value['create_time']."</br></br></br>";
$neirong = $neirong.'第'.($key+1).'次请求</br>本次请求参数为:'.$value['content'].'</br>'.'请求时间为:'.$value['create_time']."</br></br></br>";
// $temporary_arr1 = json_decode($value['content'],true);
// if(count($temporary_arr1) == 0){
// $temporary_arr2 = '请求参数为:</br>'."本次未发送请求参数</br>";
// }else{
// $temporary_arr2 = '请求参数为:</br>';
// }
// foreach ($temporary_arr1 as $k => $v) {
// $temporary_arr2 = $temporary_arr2.$k."(参数名):".$v."(参数值)</br>";
// }
// $neirong = $neirong.$temporary_arr2.'请求时间为:'.$value['create_time']."</br></br></br>";
}

View File

@ -47,7 +47,11 @@ class Skip extends Base{
if(!$this->verify_data_is_ok($data['type'],'str')){
return $this->msg(10005);
}
if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){
// {"aud_id":"331","num":"100","r_time":"2025-01-15","time_m":"","time_s":"","type":"free","token":"2581d40766e7cfd25ca140f3514072bd","aan_id":"254"}
// if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){
// $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
// }
if(!$this->verify_data_is_ok($data['num'],'intnum') || !$this->verify_data_is_ok($data['time_m'],'intnum') || !$this->verify_data_is_ok($data['time_s'],'intnum')){
$return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
}
if($data['num'] <= 0){

View File

@ -11,27 +11,26 @@ class Qrcode extends Base{
public function ordinary_code(){
// $num = Db::table('app_version_log')->order('id desc')->find();
echo '你好,这里仅仅是个展示页面-配合小白快乐成长&宠物小白使用';
// echo '你好,这里仅仅是个展示页面-配合小白快乐成长&宠物小白使用';
// echo '<br><a href="'.$num['download_url'].'">点击下载</a>';
// $url = Db::table('app_version_log')->order('id desc')->find();
// $this->assign([
// 'url' => $url['download_url'],
// ]);
// return $this->fetch();
return $this->fetch();
}
public function bluetooth_code(){
// $num = Db::table('app_version_log')->order('id desc')->find();
echo '你好,这里仅仅是个展示页面-配合reedaw&宠物小白使用';
// echo '<br><a href="'.$num['download_url'].'">点击下载</a>';
// $url = Db::table('app_version_log')->order('id desc')->find();
// $this->assign([
$url = Db::table('app_version_log')->order('id desc')->find();
// 'url' => $url['download_url'],
// ]);
// return $this->fetch();
$this->assign([
'url' => $url['download_url'],
]);
return $this->fetch();
}
}

View File

@ -1,218 +0,0 @@
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>app版本管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="/x_admin/css/font.css">
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
<!-- 让IE8/9支持媒体查询从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="layui-fluid">
<div class="layui-row">
<form class="layui-form">
<div class="layui-form-item">
<label for="L_email" class="layui-form-label">
<span class="x-red"></span>卡片图标</label>
</label>
<div class="layui-input-inline">
<!-- <input type="text" id="L_email" name="email" required="" lay-verify="email" autocomplete="off" class="layui-input"> -->
<input type="file" id="upload_file_app" lay-verify="upload_file_app" name="file_data">
</div>
<!-- <div class="layui-form-mid layui-word-aux">
<span class="x-red">*</span>将会成为您唯一的登入名
</div> -->
</div>
<div class="layui-form-item">
<label for="card_name" class="layui-form-label">
<span class="x-red"></span>卡片名称</label>
<div class="layui-input-inline">
<input type="text" id="card_name" name="card_name" required="" lay-verify="card_name" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label for="page_url_record" class="layui-form-label">
<span class="x-red">*</span>手动记录路径</label>
<div class="layui-input-inline">
<input type="text" id="page_url_record" name="page_url_record" required="" lay-verify="page_url_record" autocomplete="off" class="layui-input"></div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
<label for="page_url_report" class="layui-form-label">
<span class="x-red">*</span>报告页路径</label>
<div class="layui-input-inline">
<input type="text" id="page_url_report" name="page_url_report" required="" lay-verify="page_url_report" autocomplete="off" class="layui-input"></div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
<label for="page_url_bluetooth" class="layui-form-label">
<span class="x-red">*</span>蓝牙路径</label>
<div class="layui-input-inline">
<input type="text" id="page_url_bluetooth" name="page_url_bluetooth" required="" lay-verify="page_url_bluetooth" autocomplete="off" class="layui-input"></div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
<label for="content" class="layui-form-label">
<span class="x-red">*</span>描述</label>
<div class="layui-input-inline">
<input type="text" id="content" name="content" required="" lay-verify="content" autocomplete="off" class="layui-input"></div>
</div>
<div class="layui-form-item">
<label for="L_repass" class="layui-form-label"></label>
<!-- <div class="layui-btn" id="add" lay-filter="add" lay-submit="">增加</div>
<input value="登录" lay-submit lay-filter="add" type="submit" class="layui-btn"> -->
<button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
</div>
</form>
</div>
</div>
<script>
$(document).ready(function(){
var file_name_all = ''
var file_name = ''
var file_extension = ''
var pd = true
$('#upload_file_app').on('change', function() {
// 获取被选择的文件
var fileInput = $(this)[0];
var file = fileInput.files[0];
// 检查是否有文件被选择
if (file) {
// 获取文件的名称
file_name_all = file.name;
// 使用lastIndexOf和substring来获取文件名不包括后缀
var lastIndex = file_name_all.lastIndexOf('.');
file_name = lastIndex !== -1 ? file_name_all.substring(0, lastIndex) : file_name_all;
// 获取文件后缀
file_extension = lastIndex !== -1 ? file_name_all.substring(lastIndex + 1) : '';
$('#file_name').val(file_name)
console.log(file_name)
console.log(file_extension)
// formdata.append('apk',$('#upload_file_app')[0].files[0])
}
});
function add_data(){
if(pd === false){
return
}
var formdata = new FormData();
formdata.append('upload_file_app',$('#upload_file_app')[0].files[0])
formdata.append('card_name',$('#card_name').val())
formdata.append('page_url_record',$('#page_url_record').val())
formdata.append('page_url_report',$('#page_url_report').val())
formdata.append('page_url_bluetooth',$('#page_url_bluetooth').val())
formdata.append('content',$('#content').val())
formdata.append('file_extension',file_extension)
load()
pd = false
console.log('进来了')
$.ajax({
url:"/card/card_add_action", //请求的url地址
contentType:false,
processData:false,
async:true,//请求是否异步默认为异步这也是ajax重要特性
data:formdata, //参数值
type:"POST", //请求方式
success:function(req){
c_load()
pd = true
if(req.code == 0){
layer.alert("增加成功", {icon: 6},function() {
//关闭当前frame
xadmin.close();
// 可以对父窗口进行刷新
xadmin.father_reload();
});
}else{
layer.alert("增加失败"+req.msg, {icon: 6},function() {
//关闭当前frame
xadmin.close();
// 可以对父窗口进行刷新
xadmin.father_reload();
});
}
//请求成功时处理
console.log(req)
},
error:function(){
//请求出错处理
pd = true
}
});
}
layui.use(['form', 'layer','jquery'],function() {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer;
//自定义验证规则
form.verify({
upload_file_app: function(value) {
if (value == '') {
return '请先选择文件';
}
},
card_name: function(value) {
if (value == '') {
return '必须填写文件名';
}
},
// version_num: [/[\d.]{0,9}$/, '版本号必须以大写V开头最多10个字符由数字跟英文"."组成)'],
content: function(value) {
if (value == '') {
return '必须填写描述';
}
},
});
//监听提交
form.on('submit(add)',function(data) {
//发异步把数据提交给php
add_data()
return false;
});
});
//加载提示开启
function load() {
var index = layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
}
// 关闭加载提示
function c_load() {
layer.close(layer.index)
}
});
// });
</script>
</body>
</html>

View File

@ -1,232 +0,0 @@
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>app版本管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="/x_admin/css/font.css">
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
<!-- 让IE8/9支持媒体查询从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="layui-fluid">
<div class="layui-row">
<form class="layui-form">
<div class="layui-form-item">
<label for="L_email" class="layui-form-label">
<span class="x-red"></span>卡片图标</label>
</label>
<div class="layui-input-inline">
<!-- <input type="text" id="L_email" name="email" required="" lay-verify="email" autocomplete="off" class="layui-input"> -->
<input type="file" id="upload_file_app" lay-verify="upload_file_app" name="file_data">
</div>
<!-- <div class="layui-form-mid layui-word-aux">
<span class="x-red">*</span>将会成为您唯一的登入名
</div> -->
</div>
<div class="layui-form-item">
<label for="card_name" class="layui-form-label">
<span class="x-red"></span>卡片名称</label>
<div class="layui-input-inline">
<input type="text" id="card_name" name="card_name" required="" lay-verify="card_name" autocomplete="off" class="layui-input" value="{$result.name}">
</div>
</div>
<div class="layui-form-item">
<label for="page_url_record" class="layui-form-label">
<span class="x-red">*</span>手动记录路径</label>
<div class="layui-input-inline">
<input type="text" id="page_url_record" name="page_url_record" required="" lay-verify="page_url_record" autocomplete="off" class="layui-input" value="{$result.page_url_record}"></div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
<label for="page_url_report" class="layui-form-label">
<span class="x-red">*</span>报告页路径</label>
<div class="layui-input-inline">
<input type="text" id="page_url_report" name="page_url_report" required="" lay-verify="page_url_report" autocomplete="off" class="layui-input" value="{$result.page_url_report}"></div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
<label for="page_url_bluetooth" class="layui-form-label">
<span class="x-red">*</span>蓝牙路径</label>
<div class="layui-input-inline">
<input type="text" id="page_url_bluetooth" name="page_url_bluetooth" required="" lay-verify="page_url_bluetooth" autocomplete="off" class="layui-input" value="{$result.page_url_bluetooth}"></div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
<label for="content" class="layui-form-label">
<span class="x-red">*</span>描述</label>
<div class="layui-input-inline">
<input type="text" id="content" name="content" required="" lay-verify="content" autocomplete="off" class="layui-input" value="{$result.content}"></div>
</div>
<div class="layui-form-item">
<label for="L_repass" class="layui-form-label"></label>
<!-- <div class="layui-btn" id="add" lay-filter="add" lay-submit="">增加</div>
<input value="登录" lay-submit lay-filter="add" type="submit" class="layui-btn"> -->
<button class="layui-btn" lay-filter="add" lay-submit="">修改</button>
</div>
</form>
</div>
</div>
<!-- <div class="layui-fluid">
<div id="official_1" class="layui-row">
<div style="margin-left: 8%;margin-top: 5%;font-size: 25px;">请先下载模板文件,信息填写完成并上传该文件后点击生成</div>
<img style="width: 90%;margin-left: 3%;"src="/uploads/code_demo.png?v=1.0" alt="">
<div class="layui-form-item" style="width: 30%;margin-left: 33%;margin-top: 5%;">
<span>步骤1</span><a href="/uploads/code_demo.xlsx" class="layui-btn" lay-filter="add">下载模板文件</a>
</div>
<div class="layui-form-item" style="width: 50%;margin-left: 33%;margin-top: 5%;">
<span>步骤2</span><input type="file" id="data_excel" name="data_excel">
</div>
<div class="layui-form-item" style="width: 30%;margin-left: 33%;margin-top: 5%;">
<span>步骤3</span><button class="layui-btn" lay-filter="add" lay-submit="" onclick="add_data()">生成</button>
</div>
</div>
</div> -->
<script>
$(document).ready(function(){
var id = "{$result.id}"
var file_name_all = ''
var file_name = ''
var file_extension = ''
var pd = true
$('#upload_file_app').on('change', function() {
// 获取被选择的文件
var fileInput = $(this)[0];
var file = fileInput.files[0];
// 检查是否有文件被选择
if (file) {
// 获取文件的名称
file_name_all = file.name;
// 使用lastIndexOf和substring来获取文件名不包括后缀
var lastIndex = file_name_all.lastIndexOf('.');
file_name = lastIndex !== -1 ? file_name_all.substring(0, lastIndex) : file_name_all;
// 获取文件后缀
file_extension = lastIndex !== -1 ? file_name_all.substring(lastIndex + 1) : '';
$('#file_name').val(file_name)
// console.log($('#upload_file_app')[0].files[0])
// formdata.append('apk',$('#upload_file_app')[0].files[0])
}
});
function edit_data(){
if(pd === false){
return
}
var formdata = new FormData();
formdata.append('upload_file_app',$('#upload_file_app')[0].files[0])
formdata.append('card_name',$('#card_name').val())
formdata.append('page_url_record',$('#page_url_record').val())
formdata.append('page_url_report',$('#page_url_report').val())
formdata.append('page_url_bluetooth',$('#page_url_bluetooth').val())
formdata.append('content',$('#content').val())
formdata.append('file_extension',file_extension)
formdata.append('id',id)
load()
pd = false
console.log('进来了')
$.ajax({
url:"/card/card_edit_action", //请求的url地址
contentType:false,
processData:false,
async:true,//请求是否异步默认为异步这也是ajax重要特性
data:formdata, //参数值
type:"POST", //请求方式
success:function(req){
c_load()
pd = true
if(req.code == 0){
layer.alert("修改成功", {icon: 6},function() {
//关闭当前frame
xadmin.close();
// 可以对父窗口进行刷新
xadmin.father_reload();
});
}else{
layer.alert("修改失败"+req.msg, {icon: 6},function() {
//关闭当前frame
xadmin.close();
// 可以对父窗口进行刷新
xadmin.father_reload();
});
}
//请求成功时处理
console.log(req)
},
error:function(){
//请求出错处理
pd = true
}
});
}
layui.use(['form', 'layer','jquery'],function() {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer;
//自定义验证规则
form.verify({
// upload_file_app: function(value) {
// if (value == '') {
// return '请先选择文件';
// }
// },
file_name: function(value) {
if (value == '') {
return '必须填写文件名';
}
},
// version_num: [/[\d.]{0,9}$/, '版本号必须以大写V开头最多10个字符由数字跟英文"."组成)'],
content: function(value) {
if (value == '') {
return '必须填写描述';
}
},
});
//监听提交
form.on('submit(add)',function(data) {
//发异步把数据提交给php
edit_data()
return false;
});
});
//加载提示开启
function load() {
var index = layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
}
// 关闭加载提示
function c_load() {
layer.close(layer.index)
}
});
// });
</script>
</body>
</html>

View File

@ -1,360 +0,0 @@
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>所有卡片管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="/x_admin/css/font.css">
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
<script src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
<style>
/* th{
min-width:30px;
} */
</style>
</head>
<body>
<div class="x-nav">
<span class="layui-breadcrumb">
<a href="">首页</a>
<a href="">演示</a>
<a>
<cite>导航元素</cite></a>
</span>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
<div class="layui-col-md12">
<div class="layui-card">
<!-- <div class="layui-card-body ">
<form class="layui-form layui-col-space5">
<div class="layui-inline layui-show-xs-block">
<input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="s_time">
</div>
<div class="layui-inline layui-show-xs-block">
<input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="e_time">
</div>
<div class="layui-inline layui-show-xs-block">
<input type="text" name="username" placeholder="请输入用户手机" autocomplete="off" class="layui-input" id="tel">
</div>
<div class="layui-inline layui-show-xs-block">
<input type="text" name="username" placeholder="请输入用户邮箱" autocomplete="off" class="layui-input" id="email">
</div>
<div class="layui-input-inline layui-show-xs-block">
<select name="contrller" id="status_num">
<option value="">状态</option>
<option value="0">启用</option>
<option value="1">停用</option>
</select>
</div>
<div class="layui-inline layui-show-xs-block">
<div class="layui-btn" lay-submit="" lay-filter="sreach" onclick="find('y')"><i class="layui-icon">&#xe615;</i></div>
</div>
</form>
</div> -->
<div class="layui-card-header">
<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量停用</button>
<!-- <button class="layui-btn" onclick="xadmin.open('添加用户','/appversion/app_add','100%','100%')"><i class="layui-icon"></i>添加</button> -->
<button class="layui-btn" onclick="xadmin.open('添加版本','/card/card_add','80%','60%')"><i class="layui-icon"></i>添加</button>
</div>
<div class="layui-card-body layui-table-body layui-table-main">
<table class="layui-table layui-form">
<thead>
<tr>
<th><input type="checkbox" lay-filter="checkall" name="" lay-skin="primary"></th>
<th>ID</th>
<th>卡片名称</th>
<th>卡片图标</th>
<th>卡片描述</th>
<th>创建时间</th>
<th>状态</th>
<th>操作</th></tr>
</thead>
<tbody id='content'>
{volist name="result" id="vo"}
<tr>
<td><input type="checkbox" name="id" value="{$vo.id}" lay-skin="primary"></td>
<td>{$vo.id}</td>
<td>{$vo.name}</td>
<td><img src="{$vo.pic}" alt=""></td>
<td>{$vo.content}</td>
<td>{$vo.create_time}</td>
<td class="td-status">
{if condition="$vo.is_del == 1"}
<span onclick="app_stop(this,'{$vo.id}')" class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled" title="停用">已停用</span>
{else /}
<span onclick="app_stop(this,'{$vo.id}')" class="layui-btn layui-btn-normal layui-btn-mini" title="启用">已启用</span>
{/if}
</td>
<td>
<button class="layui-btn" onclick="xadmin.open('修改','/card/card_edit?id={$vo.id}','80%','60%')">修改</button>
</td>
</tr>
{/volist}
</tbody>
</table>
</div>
<div class="layui-card-body ">
<div id="page" style="text-align: center;">
</div>
</div>
<!-- <div class="layui-card-body ">
<div class="page">
<div>
<a class="prev" href="">&lt;&lt;</a>
<a class="num" href="">1</a>
<span class="current">2</span>
<a class="num" href="">3</a>
<a class="num" href="">489</a>
<a class="next" href="">&gt;&gt;</a>
</div>
</div>
</div> -->
</div>
</div>
</div>
</div>
</body>
<script>
var form
layui.use(['laydate','form'], function(){
var laydate = layui.laydate;
form = layui.form;
// 监听全选
form.on('checkbox(checkall)', function(data){
if(data.elem.checked){
$('tbody input').prop('checked',true);
}else{
$('tbody input').prop('checked',false);
}
form.render('checkbox');
});
//执行一个laydate实例
laydate.render({
elem: '#s_time' //指定元素
});
//执行一个laydate实例
laydate.render({
elem: '#e_time' //指定元素
});
});
var page_num;
var laypage;
var all_page = "{$num}";
layui.use('laypage', function () {
laypage = layui.laypage;
//执行一个laypage实例
laypage.render({
elem: 'page',
count: all_page, //数据总数,从服务端得到
limit: 10,
groups:10,
jump: function (obj, first) {
//首次不执行
if (!first) {
//obj包含了当前分页的所有参数比如
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
console.log(obj.limit); //得到每页显示的条数
page_num = obj.curr;
find("n")
}
}
});
});
/*用户-停用*/
function app_stop(obj,id){
// return
var title = '',is_del,num
if($(obj).attr('title')=='启用'){
title = '停用'
is_del = 1
num = 5
}else{
title = '启用'
is_del = 0
num = 6
}
// console.log('点击时'+$(obj).attr('title')+'====='+id+'===传到后台是否删除:'+is_del)
layer.confirm('确认要'+ title +'吗?',function(index){
load()
$.ajax({
url:"/card/card_del", //请求的url地址
dataType:"json", //返回格式为json
async:true,//请求是否异步默认为异步这也是ajax重要特性
data:{"id":id,'is_del':is_del}, //参数值
type:"POST", //请求方式
success:function(req){
c_load()
//请求成功时处理
if(req['code'] == 0){
//发异步把用户状态进行更改
$(obj).attr('title',title)
if(is_del == 1){
$(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已'+ title);
}else{
$(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已'+ title);
}
layer.msg('已'+ title,{icon: num});
}else{
layer.msg('操作失败!',{icon: 5});
}
},
error:function(){
//请求出错处理
}});
});
}
function delAll (argument) {
// layer.msg('停用成功', {icon: 2});
// return
var ids = [];
// 获取选中的id
$('tbody input').each(function(index, el) {
if($(this).prop('checked')){
ids.push($(this).val())
}
});
if(ids.length <= 0){
return
}
console.log(ids);
layer.confirm('确认要停用吗ID为'+ids.toString(),function(index){
//捉到所有被选中的,发异步进行删除
$.ajax({
url:"/card/card_del", //请求的url地址
dataType:"json", //返回格式为json
async:true,//请求是否异步默认为异步这也是ajax重要特性
data:{"id":ids,'is_del':1}, //参数值
type:"POST", //请求方式
success:function(req){
c_load()
//请求成功时处理
if(req['code'] == 0){
//发异步把用户状态进行更改
layer.msg('停用成功', {icon: 1});
$(".layui-form-checked").not('.header').parents('tr').find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
}else{
layer.msg('操作失败!',{icon: 2});
}
},
error:function(){
//请求出错处理
}});
});
}
function find(pd) {
if(!page_num || pd == 'y'){
page_num = 1;
}
page({
"status_num":$('#status_num').val(),
"tel":$('#tel').val(),
"email":$('#email').val(),
"s_time":$('#s_time').val(),
"e_time":$('#e_time').val(),
"page_num":page_num,
"tt":1},pd);
}
function page(data,pd) {
console.log(data)
load()
$.ajax({
url: "member_list", //请求的url地址s
dataType: "json", //返回格式为json
async: true,//请求是否异步默认为异步这也是ajax重要特性
data: data, //参数值
type: "POST", //请求方式
success: function (req) {
console.log(req)
c_load();
if (req['code'] == 0) {
var str,str_s,str_c,str_all="";
for (let i = 0; i < req['data']['data'].length; i++) {
if(req['data']['data'][i]['is_del'] == 1){
str = '<span onclick="member_stop(this,\''+req['data']['data'][i]['id']+'\')" class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled" title="停用">已停用</span>'
}else{
str = '<span onclick="member_stop(this,\''+ req['data']['data'][i]['id'] +'\')" class="layui-btn layui-btn-normal layui-btn-mini" title="启用">已启用</span>'
}
str_c = "<tr>"+
'<td><input type="checkbox" name="id" value="'+req['data']['data'][i]['id']+'" lay-skin="primary"></td>'+
'<td>'+req['data']['data'][i]['id']+'</td>'+
'<td>'+req['data']['data'][i]['token']+'</td>'+
'<td>'+req['data']['data'][i]['tel']+'</td>'+
'<td>'+req['data']['data'][i]['email']+'</td>'+
'<td>'+req['data']['data'][i]['create_time']+'</td>'+
'<td class="td-status">'+
str+
'</td>'
'</tr>'
str_all = str_all+str_c;
}
$('#content').html(str_all);
form.render();
if(pd == 'y'){
$("#page").html("")
laypage.render({
elem: 'page',
count: req['data']['num'], //数据总数,从服务端得到
limit: 10,
groups:10,
jump: function (obj, first) {
//首次不执行
if (!first) {
//obj包含了当前分页的所有参数比如
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
console.log(obj.limit); //得到每页显示的条数
page_num = obj.curr;
// page({"page":page_num,"tt":1});
find("n")
}
}
});
}
} else {
layer.msg(req['msg'])
}
},
error: function () {
//请求出错处理
}
});
}
//加载提示开启
function load() {
var index = layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
}
// 关闭加载提示
function c_load() {
layer.close(layer.index)
}
</script>
</html>

View File

@ -0,0 +1,234 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no, email=no">
<meta name="full-screen" content="true">
<meta name="screen-orientation" content="portrait">
<meta name="x5-fullscreen" content="true">
<meta name="360-fullscreen" content="true">
<title>跳转页</title>
<script src="/x_admin/js/jq.js"></script>
<style>
*{
padding: 0 0;
margin: 0 0;
}
.big_box{
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
}
.content_1{
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: center;
overflow: auto;
padding: 10vw;
box-sizing: border-box;
font-size: 4vw;
}
.download{
width: 60vw;
height: 18vw;
margin-bottom: 0vw;
margin-top: 10vw;
background: url('/download_img/code_qrcode_reedaw_app.png') no-repeat;
background-size: contain;
background-position: center;
}
.title{
width: 60vw;
height: 20vw;
margin-bottom: 0vw;
margin-top: 7vw;
background: url('/download_img/code_qrcode_title.png') no-repeat;
background-size: contain;
background-position: center;
}
.jump1{
width: 60vw;
height: 18vw;
margin-bottom: 0vw;
margin-top: 15vw;
background: url('/download_img/code_qrcode_reedaw_wechat.png') no-repeat;
background-size: contain;
background-position: center;
}
.jump2{
width: 60vw;
height: 18vw;
margin-bottom: 0vw;
margin-top: 10vw;
background: url('/download_img/code_qrcode_cwxb.png') no-repeat;
background-size: contain;
background-position: center;
}
.ts{
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.8);
}
.ts_box{
width: 85vw;
height: 27vw;
position: absolute;
top: 20%;
left: 12%;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: space-evenly;
align-items: flex-start;
font-size: 5vw;
color: white;
font-weight: bold;
}
.ts_pic{
width: 32vw;
height: 40vw;
position: absolute;
top: 0%;
right: 0%;
background: url(/tsf/registered_arrow.png) no-repeat;
background-size: contain;
background-position: center;
}
a{
margin-top: 10vw;
text-decoration: none;
color: blue;
}
.bouncing-button-container {
transform-origin: center bottom; /* 设置旋转的基点在底部中心 */
animation: rotateAndRaise 2s ease-in-out forwards infinite;
}
@keyframes rotateAndRaise {
0% {
transform: rotate(0deg) translateY(0); /* 初始状态,不旋转也不升高 */
}
10% {
transform: rotate(5deg); /* 初始状态,不旋转也不升高 */
}
20% {
transform: rotate(0deg) translateY(-50px); /* 50%时旋转15°并升高50px */
}
30% {
transform: rotate(-5deg); /* 初始状态,不旋转也不升高 */
}
40% {
transform: rotate(0deg) translateY(0px); /* 结束状态往右旋转30°并升高50px */
}
100% {
transform: rotate(0deg) translateY(0px); /* 结束状态往右旋转30°并升高50px */
}
}
.bottom_d{
width: 100vw;
height: 65vw;
position: absolute;
bottom: 0;
left: 0;
background: url('/download_img/bottom.png') no-repeat;
background-position: bottom;
background-size: contain;
}
</style>
</head>
<body id="box_k">
<div class="big_box">
<div class="content_1">
<div class="title"></div>
<div class="jump1" onclick="jump('reedaw')"></div>
<div class="download" onclick="download()"></div>
<div class="jump2" onclick="jump('cwxb')"></div>
<div class="bottom_d"></div>
</div>
</div>
<div class="ts" style="display: none;">
<div class="ts_box">
<div>1、点击右上角“ ··· ”</div>
<div>2、在菜单中选择“在浏览器中打开”</div>
</div>
<div class="ts_pic"></div>
</div>
</body>
</html>
<script>
var str_url = "{$url}";
function isWeixin() {
var ua = navigator.userAgent.toLowerCase();
return /micromessenger/i.test(ua);
}
function isIOS() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
return /iPad|iPhone|iPod/.test(userAgent) && !window.MSStream;
}
function jump(){
// window.location.href = 'weixin://dl/business/?appid=wx3e50e84030fe0d1e&path=pages/index/index';
window.location.href = 'weixin://dl/business/?appid=wx9c0b7a436ada6d1e&path=pages/home/home';
}
$('.ts').on('click',function(){
$(this).hide()
})
// if(isWeixin() && !isIOS()){
// $('.ts').show()
// }else{
// // console.log('当前不在微信环境中');
// // $('.download').addClass('bouncing-button-container')
// }
function download(){
if (isIOS()) {
console.log('当前是iOS设备');
window.location.href = "https://apps.apple.com/app/reedaw/id6654906497";
}else{
if (isWeixin()) {
console.log('当前在微信环境中');
$('.ts').show()
}else{
console.log('当前不是iOS设备');
// 在这里执行非iOS设备下的代码
window.location.href = str_url;
}
}
}
function jump(str){
if(str == 'reedaw'){
window.location.href = 'weixin://dl/business/?appid=wx9c0b7a436ada6d1e&path=pages/home/home';
}else{
window.location.href = 'weixin://dl/business/?appid=wx82a3493aa3ef1b6a&path=pages/index/index';
}
}
</script>

View File

@ -0,0 +1,182 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no, email=no">
<meta name="full-screen" content="true">
<meta name="screen-orientation" content="portrait">
<meta name="x5-fullscreen" content="true">
<meta name="360-fullscreen" content="true">
<title>跳转页</title>
<script src="/x_admin/js/jq.js"></script>
<style>
*{
padding: 0 0;
margin: 0 0;
}
.big_box{
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
}
.content_1{
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: center;
overflow: auto;
padding: 10vw;
box-sizing: border-box;
font-size: 4vw;
}
.title{
width: 60vw;
height: 20vw;
margin-bottom: 0vw;
margin-top: 7vw;
background: url('/download_img/code_qrcode_title2.png') no-repeat;
background-size: contain;
background-position: center;
}
.jump1{
width: 60vw;
height: 18vw;
margin-bottom: 0vw;
margin-top: 20vw;
background: url('/download_img/code_qrcode_cwxb.png') no-repeat;
background-size: contain;
background-position: center;
}
.jump2{
width: 60vw;
height: 18vw;
margin-bottom: 0vw;
margin-top: 20vw;
background: url('/download_img/code_qrcode_xbklcz.png') no-repeat;
background-size: contain;
background-position: center;
}
.ts{
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.8);
}
.ts_box{
width: 85vw;
height: 27vw;
position: absolute;
top: 20%;
left: 12%;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: space-evenly;
align-items: flex-start;
font-size: 5vw;
color: white;
font-weight: bold;
}
.ts_pic{
width: 32vw;
height: 40vw;
position: absolute;
top: 0%;
right: 0%;
background: url(/tsf/registered_arrow.png) no-repeat;
background-size: contain;
background-position: center;
}
a{
margin-top: 10vw;
text-decoration: none;
color: blue;
}
.bouncing-button-container {
transform-origin: center bottom; /* 设置旋转的基点在底部中心 */
animation: rotateAndRaise 2s ease-in-out forwards infinite;
}
@keyframes rotateAndRaise {
0% {
transform: rotate(0deg) translateY(0); /* 初始状态,不旋转也不升高 */
}
10% {
transform: rotate(5deg); /* 初始状态,不旋转也不升高 */
}
20% {
transform: rotate(0deg) translateY(-50px); /* 50%时旋转15°并升高50px */
}
30% {
transform: rotate(-5deg); /* 初始状态,不旋转也不升高 */
}
40% {
transform: rotate(0deg) translateY(0px); /* 结束状态往右旋转30°并升高50px */
}
100% {
transform: rotate(0deg) translateY(0px); /* 结束状态往右旋转30°并升高50px */
}
}
.bottom_d{
width: 100vw;
height: 65vw;
position: absolute;
bottom: 0;
left: 0;
background: url('/download_img/bottom.png') no-repeat;
background-position: bottom;
background-size: contain;
}
</style>
</head>
<body id="box_k">
<div class="big_box">
<div class="content_1">
<div class="title"></div>
<div class="jump1" onclick="jump('cwxb')"></div>
<div class="jump2" onclick="jump('xbklcz')"></div>
<div class="bottom_d"></div>
</div>
</div>
</body>
</html>
<script>
function isWeixin() {
var ua = navigator.userAgent.toLowerCase();
return /micromessenger/i.test(ua);
}
function isIOS() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
return /iPad|iPhone|iPod/.test(userAgent) && !window.MSStream;
}
function jump(str){
if(str == 'xbklcz'){
window.location.href = 'weixin://dl/business/?appid=wx3e50e84030fe0d1e&path=pages/index/index';
}else{
window.location.href = 'weixin://dl/business/?appid=wx82a3493aa3ef1b6a&path=pages/index/index';
}
}
</script>

View File

@ -248,6 +248,7 @@ return [
'type' => 'sqlsrv',
// 服务器地址
'hostname' => '121.36.67.254',
// 'hostname' => '127.0.0.1',
// 数据库名
'database' => 'kitchen_scale',
// 用户名

View File

@ -395,10 +395,45 @@ Route::any('/open_wechat_content', 'app/Msginformation/open_wechat_content');
################################################################下面是厨房秤################################################################
###########################################################################################################################################
// 公共内容################################################################
// 获取用户上传图片列表
Route::any('/kitchenscale/pic_chose_list', 'app/kitchenscale/app.base/pic_chose_list');
Route::any('/testedition/kitchenscale/pic_chose_list', 'app/kitchenscale/testapp.base/pic_chose_list');
// 用户多图上传接口
Route::any('/kitchenscale/pic_upload_action', 'app/kitchenscale/app.base/pic_upload_action');
Route::any('/testedition/kitchenscale/pic_upload_action', 'app/kitchenscale/testapp.base/pic_upload_action');
// 首页内容################################################################
// 获取配置类信息
Route::any('/kitchenscale/get_default_config', 'app/kitchenscale/app.index/get_default_config');
Route::any('/testedition/kitchenscale/get_default_config', 'app/kitchenscale/testapp.index/get_default_config');
// 获取首页页面展示数据
Route::any('/kitchenscale/get_homepage_information', 'app/kitchenscale/app.index/get_homepage_information');
Route::any('/testedition/kitchenscale/get_homepage_information', 'app/kitchenscale/testapp.index/get_homepage_information');
// 菜谱内容################################################################
// 添加菜谱
Route::any('/kitchenscale/add_cookbook', 'app/kitchenscale/app.cookbook/add_cookbook');
Route::any('/testedition/kitchenscale/add_cookbook', 'app/kitchenscale/testapp.cookbook/add_cookbook');
// 根据菜谱标签查询列表(首页用)
Route::any('/kitchenscale/find_by_cook_label', 'app/kitchenscale/app.cookbook/find_by_cook_label');
Route::any('/testedition/kitchenscale/find_by_cook_label', 'app/kitchenscale/testapp.cookbook/find_by_cook_label');
// 根据食材详细查找列表
Route::any('/kitchenscale/find_by_food', 'app/kitchenscale/app.cookbook/find_by_food');
Route::any('/testedition/kitchenscale/find_by_food', 'app/kitchenscale/testapp.cookbook/find_by_food');
// 查询食谱的详情
Route::any('/kitchenscale/cookbook_details', 'app/kitchenscale/app.cookbook/cookbook_details');
Route::any('/testedition/kitchenscale/cookbook_details', 'app/kitchenscale/testapp.cookbook/cookbook_details');
// 关注菜谱
Route::any('/kitchenscale/cookbook_follow', 'app/kitchenscale/app.cookbook/cookbook_follow');
Route::any('/testedition/kitchenscale/cookbook_follow', 'app/kitchenscale/testapp.cookbook/cookbook_follow');
// 收藏菜谱
Route::any('/kitchenscale/cookbook_like', 'app/kitchenscale/app.cookbook/cookbook_like');
Route::any('/testedition/kitchenscale/cookbook_like', 'app/kitchenscale/testapp.cookbook/cookbook_like');
Route::any('/get_homepage_information', 'app/KitchenScale/app.index/get_homepage_information');
Route::any('/testedition/get_homepage_information', 'testapp/KitchenScale/app.get_homepage_information');

View File

@ -0,0 +1,256 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测试菜谱提交</title>
<style>
.ingredient, .step {
margin: 5px 0;
padding: 5px;
border: 1px solid #ccc;
}
.ingredient button, .step button {
margin-left: 10px;
}
.foot_list {
margin-top: 10px;
}
.foot_list .ingredient {
margin: 5px 0;
}
</style>
<script src="../x_admin/js/jq.js"></script>
</head>
<body>
<p style="font-weight: bold;">菜谱信息</p>
<div class='box1'>
<label for="cover">上传封面:</label>
<input type="file" id="cover" name="cover" accept="image/*" multiple>
<br>
<label for="title">菜谱标题:</label>
<input type="text" id="title" name="title">
<br>
<label for="description">菜谱简介:</label>
<textarea id="description" name="description" rows="4" cols="50"></textarea>
<br>
</div>
<p style="font-weight: bold;">添加食材</p>
<div class='box2'>
<div id="box2_content">
</div>
<div id="box2_action" style="margin:10px 0;display: flex;flex-direction: row;flex-wrap: nowrap;justify-content: space-around;">
<div onclick="clearIngredients()">清空</div>
<div onclick="addIngredient()">添加食材</div>
</div>
</div>
<p style="font-weight: bold;">编辑步骤</p>
<div class='box3'>
<div id="box3_content"></div>
<div id="box3_action">
<button onclick="addStep()">添加步骤</button>
</div>
</div>
<div onclick="saveData()" style="margin:50px 0;">保存</div>
</body>
</html>
<script>
var submit_data;
let ingredientsList = [];
function addIngredient() {
const ingredients = ['鸡肉', '牛肉', '猪肉'];
const randomIngredient = ingredients[Math.floor(Math.random() * ingredients.length)];
const randomWeight = Math.floor(Math.random() * (300 - 100 + 1)) + 100;
const ingredientDiv = document.createElement('div');
ingredientDiv.className = 'ingredient';
ingredientDiv.textContent = `${randomIngredient} ${randomWeight}克`;
const deleteButton = document.createElement('button');
deleteButton.textContent = '删除';
deleteButton.onclick = function() {
removeIngredient(ingredientDiv, randomIngredient, randomWeight);
};
ingredientDiv.appendChild(deleteButton);
document.getElementById('box2_content').appendChild(ingredientDiv);
ingredientsList.push({ name: randomIngredient, weight: randomWeight });
}
function removeIngredient(divElement, ingredientName, ingredientWeight) {
divElement.remove();
ingredientsList = ingredientsList.filter(item => !(item.name === ingredientName && item.weight === ingredientWeight));
}
function clearIngredients() {
const box2Content = document.getElementById('box2_content');
while (box2Content.firstChild) {
box2Content.removeChild(box2Content.firstChild);
}
ingredientsList = [];
}
function addStep() {
const stepDiv = document.createElement('div');
stepDiv.className = 'step';
// 多图上传
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'image/*';
fileInput.name = 'images[]';
fileInput.multiple = true;
stepDiv.appendChild(fileInput);
// 选择食材按钮
const selectIngredientButton = document.createElement('button');
selectIngredientButton.textContent = '选择食材';
selectIngredientButton.onclick = function() {
selectIngredient(stepDiv);
};
stepDiv.appendChild(selectIngredientButton);
// 步骤输入说明
const stepDescription = document.createElement('textarea');
stepDescription.placeholder = '步骤说明';
stepDescription.rows = 4;
stepDescription.cols = 50;
stepDiv.appendChild(stepDescription);
// 每个步骤的 foot_list
const footList = document.createElement('div');
footList.className = 'foot_list';
stepDiv.appendChild(footList);
document.getElementById('box3_content').appendChild(stepDiv);
}
function selectIngredient(stepDiv) {
if (ingredientsList.length === 0) {
alert('没有可用的食材');
return;
}
// 获取当前步骤的 foot_list
const footList = stepDiv.querySelector('.foot_list');
// 获取已经添加过的食材
const addedIngredients = Array.from(footList.getElementsByClassName('ingredient')).map(div => div.textContent);
// 过滤已经添加过的食材
const availableIngredients = ingredientsList.filter(item => {
const ingredientText = `${item.name} ${item.weight}克`;
return !addedIngredients.includes(ingredientText);
});
if (availableIngredients.length === 0) {
alert('所有食材已添加');
return;
}
const randomIndex = Math.floor(Math.random() * availableIngredients.length);
const selectedIngredient = availableIngredients[randomIndex];
const ingredientDiv = document.createElement('div');
ingredientDiv.className = 'ingredient';
ingredientDiv.textContent = `${selectedIngredient.name} ${selectedIngredient.weight}克`;
const deleteButton = document.createElement('button');
deleteButton.textContent = '删除';
deleteButton.onclick = function() {
removeFootIngredient(ingredientDiv, selectedIngredient.name, selectedIngredient.weight, footList);
};
ingredientDiv.appendChild(deleteButton);
footList.appendChild(ingredientDiv);
}
function removeFootIngredient(divElement, ingredientName, ingredientWeight, footList) {
divElement.remove();
// 重新过滤 ingredientsList 以确保删除后不会重复添加
const addedIngredients = Array.from(footList.getElementsByClassName('ingredient')).map(div => div.textContent);
ingredientsList = ingredientsList.filter(item => {
const ingredientText = `${item.name} ${item.weight}克`;
return !addedIngredients.includes(ingredientText);
});
}
function saveData() {
const formData = new FormData();
// 封面文件
const coverInput = document.getElementById('cover');
if (coverInput.files.length > 0) {
formData.append('cover', coverInput.files[0]);
}
// 菜谱标题
const titleInput = document.getElementById('title');
formData.append('title', titleInput.value);
// 菜谱描述
const descriptionInput = document.getElementById('description');
formData.append('description', descriptionInput.value);
// 食材列表
formData.append('ingredientsList', JSON.stringify(ingredientsList));
// 步骤内容
const steps = document.querySelectorAll('.step');
steps.forEach((step, index) => {
// 步骤说明
const stepDescription = step.querySelector('textarea');
formData.append(`steps[${index}][description]`, stepDescription.value);
// 选择的食材
const footList = step.querySelector('.foot_list');
const ingredients = Array.from(footList.getElementsByClassName('ingredient')).map(div => {
const [name, weightText] = div.textContent.split(' ');
const weight = parseInt(weightText, 10);
return { name, weight };
});
formData.append(`steps[${index}][ingredients]`, JSON.stringify(ingredients));
// 上传的图片
const fileInput = step.querySelector('input[type="file"]');
Array.from(fileInput.files).forEach((file, fileIndex) => {
formData.append(`steps[${index}][images][${fileIndex}]`, file);
});
});
submit_data = formData;
// 打印 formData 内容
console.log('submit_data:', formData);
// 遍历 formData 以查看其内容
for (var pair of formData.entries()) {
console.log(pair[0] + ': ' + pair[1]);
}
$.ajax({
url: "http://wm.tcxbc.com/kitchenscale/add_cookbook", // 请求的url地址
contentType: false,
processData: false,
async: true, // 请求是否异步默认为异步这也是ajax重要特性
data: submit_data, // 参数值
type: "POST", // 请求方式
beforeSend: function() {
// 请求前的处理
},
success: function(req) {
// 请求成功时处理
console.log('成功:', req);
},
complete: function() {
// 请求完成的处理
},
error: function(err) {
// 请求出错处理
console.error('错误:', err);
}
});
}
</script>

View File

@ -0,0 +1,427 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测试菜谱提交</title>
<style>
.yc{
display: none;
}
.ingredient, .step {
margin: 5px 0;
padding: 5px;
border: 1px solid #ccc;
}
.ingredient button, .step button {
margin-left: 10px;
}
.foot_list {
margin-top: 10px;
}
.foot_list .ingredient {
margin: 5px 0;
}
#fileInput{
display: none;
}
#img_chose{
width: 95vw;
height: 100vw;
background-color: #ccc;
position: absolute;
top: 20%;
left: 0;
right: 0;
margin: 0 auto;
display: none;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
align-content: flex-start;
}
#img_chose img{
width:20vw;
height: 20vw;
}
.cover_show img{
width: 30%;
}
.step_show_all img{
width: 20%;
}
</style>
<script src="../x_admin/js/jq.js"></script>
</head>
<body>
<p style="font-weight: bold;">菜谱信息~</p>
<div class='box1'>
<label for="cover">上传封面:</label>
<button onclick="open_img_chose('cover',0)">选择图片</button>
<br>
<div class="cover_show"></div>
<br>
<br>
<label for="title">菜谱标题:</label>
<input type="text" id="title" name="title">
<br>
<br>
<label for="description">菜谱简介:</label>
<textarea id="description" name="description" rows="4" cols="50"></textarea>
<br>
</div>
<p style="font-weight: bold;">添加食材</p>
<div class='box2'>
<div id="box2_content">
</div>
<div id="box2_action" style="margin:10px 0;display: flex;flex-direction: row;flex-wrap: nowrap;justify-content: space-around;">
<div onclick="clearIngredients()">清空</div>
<div onclick="addIngredient()">添加食材</div>
</div>
</div>
<p style="font-weight: bold;">编辑步骤</p>
<div class='box3'>
<div id="box3_content"></div>
<div id="box3_action">
<button onclick="addStep()">添加步骤</button>
</div>
</div>
<div onclick="saveData()" style="margin:50px 0;">保存</div>
<!-- 图片选择组件 -->
<div id="img_chose" class="yc">
<div onclick="upload_action()"><img src="http://tc.pcxbc.com/tsf/upload_pic.jpg" alt=""></div>
<button onclick="close_action()">关闭</button>
</div>
<input type="file" id="fileInput" accept="image/*" name="img_list" multiple>
</body>
</html>
<script>
// 设置最终提交变量important
var post_data = {
"cook_label": '早餐', //菜谱标签,属于什么菜系之类的
"token": 'caadd1be045a65f30b92aa805f1de54a', //菜谱标签,属于什么菜系之类的
"cover": '', //封面图片
"title": '', //菜谱标题
"description": '', //菜谱简介
"food_list": [], //食材列表
"step_list": [], //步骤列表
};
var what_button = '';//用来判断是封面还是步骤
function open_img_chose(str,num){
what_button = str+','+num;
// $('#img_chose').html('');
var user_img_list = [];
$.ajax({
url:"https://tc.pcxbc.com/kitchenscale/pic_chose_list", //请求的url地址
// url:"http://wm.tcxbc.com/kitchenscale/pic_chose_list", //请求的url地址
dataType:"json", //返回格式为json
async:true,//请求是否异步默认为异步这也是ajax重要特性
data:{"token":"caadd1be045a65f30b92aa805f1de54a"}, //参数值
type:"POST", //请求方式
success:function(req){
if(req.code==0){
for (let index = 0; index < req.data.result.length; index++) {
var newDiv = $('<div></div>')
.addClass('pic_box')
.attr('onclick', 'sendParamToParent(\''+req.data.result[index]['id']+'\',\''+req.data.result[index]['pic_url']+'\',\''+what_button+'\')')
.append($('<img></img>')
.attr('src', req.data.result[index]['pic_url'])
.attr('alt', '')
);
$('#img_chose > div:first').after(newDiv);
}
$('#img_chose').css('display', 'flex');
}
},
error:function(){
//请求出错处理
}
});
}
function upload_action(){
document.getElementById('fileInput').click();
}
$('#fileInput').on('change', function() {
// 获取被选择的文件
var files = event.target.files;
if (files.length > 5) {
alert('最多只能选择5张图片,您选择了' + files.length + ' 张图片');
// 清空文件输入,取消选择的文件
$(this).val('');
return
}
console.log('当前选择了' + files.length + ' 张图片');
// 检查是否有文件被选择
if (files.length > 0) {
var formdata = new FormData();
for (var i = 0; i < files.length; i++) {
formdata.append('images[]', files[i]);
}
formdata.append('token', 'caadd1be045a65f30b92aa805f1de54a');
$.ajax({
url:"https://tc.pcxbc.com/kitchenscale/pic_upload_action", //请求的url地址
// url:"http://wm.tcxbc.com/kitchenscale/pic_upload_action", //请求的url地址
contentType:false,
processData:false,
async:true,//请求是否异步默认为异步这也是ajax重要特性
data:formdata, //参数值
type:"POST", //请求方式
success:function(req){
alert('本次添加失败'+req.data.error_data+'张');
for (let index = 0; index < req.data.insert_data.length; index++) {
var newDiv = $('<div></div>')
.addClass('pic_box')
.attr('onclick', 'sendParamToParent(\''+req.data.insert_data[index]['id']+'\',\''+req.data.insert_data[index]['pic_url']+'\',\''+what_button+'\')')
.append($('<img></img>')
.attr('src', req.data.insert_data[index]['pic_url'])
.attr('alt', '')
);
$('#img_chose > div:first').after(newDiv);
}
},
error:function(){
//请求出错处理
}
});
}
});
function sendParamToParent(id,url,parameter){
var parameter_arr = parameter.split(",");
if(parameter_arr[0] == 'cover'){
// 添加数据进最终提交变量important
post_data.cover = id;
$('.cover_show').html('');
$('.cover_show')
.append($('<img></img>')
.attr('src', url)
.attr('alt', '')
);
}else{
// 添加数据进最终提交变量important
post_data.step_list[parameter_arr[1]]['pic_list'].push(id);
$('.step_show_'+parameter_arr[1])
.append($('<img></img>')
.attr('src', url)
.attr('alt', '')
);
}
console.log(post_data)
}
function close_action(){
$('#img_chose').hide();
$('#img_chose .pic_box').remove();
}
</script>
<script>
var submit_data;
let ingredientsList = [];
// 添加随机的食材,从'鸡肉', '牛肉', '猪肉'随机选重量从100-300克随机选
function addIngredient() {
const ingredients = ['鸡肉', '牛肉', '猪肉'];
const randomIngredient = ingredients[Math.floor(Math.random() * ingredients.length)];
const randomWeight = Math.floor(Math.random() * (300 - 100 + 1)) + 100;
const ingredientDiv = document.createElement('div');
ingredientDiv.className = 'ingredient';
ingredientDiv.textContent = `${randomIngredient} ${randomWeight}克`;
const deleteButton = document.createElement('button');
deleteButton.textContent = '删除';
deleteButton.onclick = function() {
removeIngredient(ingredientDiv, randomIngredient, randomWeight);
};
ingredientDiv.appendChild(deleteButton);
document.getElementById('box2_content').appendChild(ingredientDiv);
post_data.food_list.push({ name: randomIngredient, weight: randomWeight });
console.log(post_data)
}
// 删除单个食材
function removeIngredient(divElement, ingredientName, ingredientWeight) {
divElement.remove();
post_data.food_list = post_data.food_list.filter(item => !(item.name === ingredientName && item.weight === ingredientWeight));
}
// 清除所有食材
function clearIngredients() {
const box2Content = document.getElementById('box2_content');
while (box2Content.firstChild) {
box2Content.removeChild(box2Content.firstChild);
}
post_data.food_list = [];
}
// 添加步骤
function addStep() {
const stepDiv = document.createElement('div');
stepDiv.className = 'step';
// 在步骤里面添加一个空数据
var num = post_data.step_list.push({ pic_list: [], foot_list: [] ,description:""});
// console.log(post_data.step_list.push({ pic_list: [], foot_list: [] ,description:""}))
// <div class="cover_show"></div>
const show_img = document.createElement('div');
show_img.className = 'step_show_all step_show_'+(num-1);
stepDiv.appendChild(show_img);
// 多图上传
const fileInput = document.createElement('button');
fileInput.textContent = '选择图片';
fileInput.onclick = function() {
open_img_chose('step_list',num-1);
};
stepDiv.appendChild(fileInput);
// 选择食材按钮
const selectIngredientButton = document.createElement('button');
selectIngredientButton.textContent = '选择食材';
selectIngredientButton.onclick = function() {
selectIngredient(stepDiv,num-1);
};
stepDiv.appendChild(selectIngredientButton);
// 步骤输入说明
const stepDescription = document.createElement('textarea');
stepDescription.placeholder = '步骤说明';
stepDescription.rows = 4;
stepDescription.cols = 50;
stepDescription.onblur = function() {
writeDescriptionChild(this,num-1);
};
stepDiv.appendChild(stepDescription);
// 每个步骤的 foot_list
const footList = document.createElement('div');
footList.className = 'foot_list';
stepDiv.appendChild(footList);
document.getElementById('box3_content').appendChild(stepDiv);
}
function selectIngredient(stepDiv,num) {
if (post_data.food_list.length === 0) {
alert('没有可用的食材');
return;
}
// 获取当前步骤的 foot_list
const footList = stepDiv.querySelector('.foot_list');
// 获取已经添加过的食材
const addedIngredients = Array.from(footList.getElementsByClassName('ingredient')).map(div => div.textContent);
// 过滤已经添加过的食材
const availableIngredients = post_data.food_list.filter(item => {
const ingredientText = `${item.name} ${item.weight}克`;
return !addedIngredients.includes(ingredientText);
});
if (availableIngredients.length === 0) {
alert('所有食材已添加');
return;
}
const randomIndex = Math.floor(Math.random() * availableIngredients.length);
const selectedIngredient = availableIngredients[randomIndex];
const ingredientDiv = document.createElement('div');
ingredientDiv.className = 'ingredient';
ingredientDiv.textContent = `${selectedIngredient.name} ${selectedIngredient.weight}克`;
const deleteButton = document.createElement('button');
deleteButton.textContent = '删除';
deleteButton.onclick = function() {
removeFootIngredient(ingredientDiv, selectedIngredient.name, selectedIngredient.weight, footList);
};
ingredientDiv.appendChild(deleteButton);
footList.appendChild(ingredientDiv);
// 添加数据进最终提交变量important
post_data.step_list[num]['foot_list'].push({name:selectedIngredient.name,weight:selectedIngredient.weight});
console.log(post_data)
}
function removeFootIngredient(divElement, ingredientName, ingredientWeight, footList) {
divElement.remove();
// 重新过滤 ingredientsList 以确保删除后不会重复添加
const addedIngredients = Array.from(footList.getElementsByClassName('ingredient')).map(div => div.textContent);
post_data.food_list = post_data.food_list.filter(item => {
const ingredientText = `${item.name} ${item.weight}克`;
return !addedIngredients.includes(ingredientText);
});
}
// 每个步骤的描述写入
function writeDescriptionChild(e,num){
// 添加数据进最终提交变量important
post_data.step_list[num]['description'] = $(e).val();
console.log(post_data)
}
function saveData() {
post_data.title = $("#title").val();
post_data.description = $("#description").val();
// 最终数据格式示意start
// post_data = {
// "cook_label": "早餐",
// "token": "asdasdasda123141321dfsd34123",
// "cover": "1",
// "title": "测试菜谱1",
// "description": "测试菜谱描述",
// "food_list": [
// {"name": " 牛肉","weight": "100"},
// {"name": " 鸡肉","weight": "200"},
// ...
// ],
// "step_list": [
// {
// "pic_list": [1,2],
// "foot_list": [
// {"name": " 牛肉","weight": "100"},
// ...
// ],
// "description": "步骤1说明"
// },
// ...
// ],
// };
// 最终数据格式示意end
console.log(post_data)
$.ajax({
url:"https://tc.pcxbc.com/kitchenscale/add_cookbook", //请求的url地址
// url:"http://wm.tcxbc.com/kitchenscale/add_cookbook", //请求的url地址
dataType:"json", //返回格式为json
async:true,//请求是否异步默认为异步这也是ajax重要特性
data:post_data, //参数值
type:"POST", //请求方式
success:function(req){
//请求成功时处理
if(req.code == 200){
alert("操作成功");
}else{
alert("操作失败");
}
},
error:function(){
//请求出错处理
}
});
}
</script>