-
+
- + 我的桌面
-
+
- 关闭当前 +
- 关闭其它 +
- 关闭全部
diff --git a/application/KitchenScale/controller/admin/Base.php b/application/KitchenScale/controller/admin/Base.php index 3631230..38be76b 100644 --- a/application/KitchenScale/controller/admin/Base.php +++ b/application/KitchenScale/controller/admin/Base.php @@ -27,6 +27,7 @@ class Base extends Controller{ '20001'=>'登录失效', '99999'=>'网络异常,请稍后重试', ]; + protected $file_max = 1024*1024*2;//xxxMB // 加 bcadd(,,20) // 减 bcsub(,,20) // 乘 bcmul(,,20) @@ -34,74 +35,7 @@ class Base extends Controller{ ################################################################接口################################################################ ################################################################接口################################################################ ################################################################接口################################################################ - // 接口记录 - public function record_api_log($params, $error = null, $response = null){ - $logContent = "接口请求参数:" . json_encode($params, JSON_UNESCAPED_UNICODE) . PHP_EOL; - if ($error) { - $logContent .= "错误信息:" . $error['all_content'] . PHP_EOL; - if(!cache($error['flie']."_".$error['line'])){ - cache($error['flie']."_".$error['line'],"API错误",3600); - $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'厨房秤(后台)','content'=>$logContent]); - } - } - if ($response) { - $logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL; - } - // 使用ThinkPHP的日志记录方法 - Log::record($logContent, 'api_log'); - - } - /* 接口说明(发邮件) - * $address(收件人的邮箱地址) 数组 格式: ['460834639@qq.com','460834639@qq.com'.......] - * $content(邮件的主题数据信息) 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123'] - * $annex(附件路径信息) 字符串 - */ - public function send_email_api_error($address,$content,$annex=''){ - // $ad = '460834639@qq.com'; - $ad1 = '295155911@qq.com'; - $mail = new PHPMailer(); //实例化 - $mail->IsSMTP(); // 启用SMTP - $mail->Host = "smtp.126.com"; //SMTP服务器 163邮箱例子 - $mail->Port = 465; //邮件发送端口 - $mail->SMTPAuth = true; //启用SMTP认证 - $mail->SMTPSecure = 'ssl'; - $mail->CharSet = "UTF-8"; //字符集 - $mail->Encoding = "base64"; //编码方式 - $mail->Username = "tsf3920322@126.com"; //你的邮箱 - $mail->Password = "HLWXNRPUCTHJFIIX"; //你的密码(邮箱后台的授权密码) - $mail->From = "tsf3920322@126.com"; //发件人地址(也就是你的邮箱) - - // $mail->Subject = "微盟测试邮件"; //邮件标题 - $mail->Subject = $content['title']; //邮件标题 - - // $mail->FromName = "微盟体测中心"; //发件人姓名 - $mail->FromName = $content['from_user_name']; //发件人姓名 - - - for ($i=0; $i < count($address); $i++) { - $mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称) - } - - if($annex != ''){ - // $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg'; - $mail->AddAttachment($annex,''); // 添加附件,并指定名称 - } - - $mail->IsHTML(true); //支持html格式内容 - - $neirong = $content['content']; - - $mail->Body = $neirong; //邮件主体内容 - //发送 - if (!$mail->Send()) { - - return ['code' => 10003,'msg'=>$mail->ErrorInfo]; - // return $mail->ErrorInfo; - } else { - return ['code' => 0]; - // return 'success'; - } - } + // 验证 @@ -143,9 +77,80 @@ class Base extends Controller{ }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)){ @@ -162,9 +167,6 @@ class Base extends Controller{ } } - public function ceshi(){ - echo 'hello'; - } } \ No newline at end of file diff --git a/application/KitchenScale/controller/admin/Cookbook.php b/application/KitchenScale/controller/admin/Cookbook.php new file mode 100644 index 0000000..48589cd --- /dev/null +++ b/application/KitchenScale/controller/admin/Cookbook.php @@ -0,0 +1,178 @@ +=',$data['s_time']]; + // } + // if($data['e_time']){ + // $parameter['create_time'] = ['<=',$data['e_time']]; + // } + } + $where = '1=1'; + $cfc = Db::connect('cfc_db'); + $num = $cfc->table('app_user_cookbook')->where($parameter)->count(); + $sql = " + SELECT + a.id, + a.title, + a.create_user_nickname, + a.likes_num, + a.read_it, + a.is_del, + a.create_time, + b.pic_url + FROM + app_user_cookbook a + LEFT JOIN + app_user_upload_img b ON a.cover = b.id + WHERE + $where + ORDER BY + a.id DESC + OFFSET (".($page - 1)." * ".$this->page_num.") ROWS + FETCH NEXT ".$this->page_num." ROWS ONLY; + "; + $result = $cfc->query($sql); + + if(!$pd){ + $return_data['num'] = $num; + $return_data['data'] = $result; + return $this->msg($return_data); + } + $this->assign([ + 'result' => $result, + 'num' => $num, + ]); + return $this->fetch(); + + } + + public function add_cookbook(){ + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('app_user_cookbook_label')->where(['is_del'=>0])->select(); + $this->assign([ + 'result' => $result, + ]); + return $this->fetch(); + } + + public function add_cookbook_action(){ + $data = input(); + $cfc = Db::connect('cfc_db'); + // dump($data); + // 处理食谱数据 + $id_list = []; + $food_cookbook_relationship = []; + foreach ($data['foodList'] as $key => $value) { + if(!in_array($value['id'],$id_list)){ + array_push($id_list,$value['id']); + array_push($food_cookbook_relationship,[ + 'cookbook_id' => '', + 'food_id' => $value['id'] + ]); + } + } + $kcal_data = $cfc->table('app_z_national_standard_food_type_3')->where("id in (".implode(',',$id_list).")")->field('id,Calorie_val')->select(); + for ($i=0; $i < count($kcal_data); $i++) { + $id_list[$kcal_data[$i]['id']] = $kcal_data[$i]['Calorie_val']; + } + foreach ($data['foodList'] as $key => $value) { + $data['foodList'][$key]['kcal'] = bcmul(bcdiv($value['weight'],100,20),$id_list[$value['id']],2); + $data['foodList'][$key]['unit'] = 'g'; + } + + // 设置食谱信息 + $cookbook_data = [ + 'title'=>$data['title'], + 'cover'=>$data['cover'], + 'create_user_token'=>'caadd1be045a65f30b92aa805f1de54a', + 'create_user_head_pic'=>'https://tc.pcxbc.com/tsf/head_pic.png', + 'create_user_nickname'=>'clown', + 'describe_data'=>$data['description'], + 'food_data'=>json_encode($data['foodList']), + 'step_data'=>json_encode($data['stepList']), + 'create_time'=>date('Y-m-d H:i:s'), + 'original_cookbook_id'=>'admin', + 'cook_label'=>$data['cook_label'], + 'is_del'=>1, + + ]; + + $cfc->startTrans(); + try { + + $cookbook_id = $cfc->table('app_user_cookbook')->insertGetId($cookbook_data); + for ($i=0; $i < count($food_cookbook_relationship); $i++) { + $food_cookbook_relationship[$i]['cookbook_id'] = $cookbook_id; + } + $cfc->table('app_user_cookbook_food_relation')->insertAll($food_cookbook_relationship); + $cfc->commit(); + return $this->msg([]); + } catch (\Exception $e) { + $cfc->rollback(); + return $this->msg(10002,'数据保存失败,'.$e->getMessage()); + } + + } + + public function stop_and_run(){ + $data = input(); + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('app_user_cookbook')->where(['id'=>$data['id']])->update(['is_del'=>$data['status']]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + + + + + public function find_food_list(){ + $data = input(); + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('app_z_national_standard_food_type_3')->where("food_name like '%". $data['search_data'] ."%'")->field('id,food_name,Calorie_val')->select(); + return $this->msg(0,'success',$result); + } + + +} \ No newline at end of file diff --git a/application/KitchenScale/controller/admin/Index.php b/application/KitchenScale/controller/admin/Index.php new file mode 100644 index 0000000..f06f5e1 --- /dev/null +++ b/application/KitchenScale/controller/admin/Index.php @@ -0,0 +1,30 @@ +assign('domain',$a); + return $this->fetch(); + } + + public function welcome(){ + // $this->assign('domain',$a); + return $this->fetch(); + } + +} \ No newline at end of file diff --git a/application/KitchenScale/controller/admin/Login.php b/application/KitchenScale/controller/admin/Login.php index 57a980c..2f0eddf 100644 --- a/application/KitchenScale/controller/admin/Login.php +++ b/application/KitchenScale/controller/admin/Login.php @@ -6,7 +6,7 @@ use think\Db; class Login extends Base{ - protected $login_hours_out = 24; + // protected $login_hours_out = 24; // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -16,103 +16,24 @@ class Login extends Base{ ################################################################接口################################################################ ################################################################接口################################################################ - // 登录请求api - public function login($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); - // } + // 登录 + public function login(){ + return $this->fetch(); } - // 检测登录信息是否超时 - public function check_login($data = ['token'=>'123']){ - // try { - // 你的业务逻辑 - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - - $return_data = $this->check_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); - } - - } - - public function check_login_action(){ - $user = Db::table('admin_user_account_number')->where(["token"=>$data['token']])->field('create_time')->find(); - if (!$user) { - return $this->msg(10001); // 如果用户不存在,直接返回 false - } - // 假设 $user['create_time'] 是一个日期时间字符串 - $createTime = new DateTime($user['create_time']); - $currentTime = new DateTime(); - - // 计算时间差 - $interval = $currentTime->diff($createTime); - - // 判断时间差是否超过指定小时数 - $totalHours = $interval->days * 24 + $interval->h; - if ($totalHours > $this->login_hours_out) { + public function login_action(){ + $data = input(); + // 验证数据项是否完整 + if(!array_key_exists('username', $data) || !array_key_exists('password', $data)){ return $this->msg(10001); - } else { + } + $cfc = Db::connect('cfc_db'); + $account = $cfc->table('admin_user_account_number')->where(['account_num'=>$data['username'],'password'=>$data['password']])->count(); + if($account>0){ return $this->msg([]); + }else{ + return $this->msg(10003); } } diff --git a/application/KitchenScale/controller/app/Cookbook.php b/application/KitchenScale/controller/app/Cookbook.php index 78f9301..5a76f76 100644 --- a/application/KitchenScale/controller/app/Cookbook.php +++ b/application/KitchenScale/controller/app/Cookbook.php @@ -495,7 +495,7 @@ class Cookbook extends Base{ // 获取查询页页面导航食材列表 public function get_search_food_page_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){ // 尝试捕获异常 - try { + // try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -508,20 +508,20 @@ class Cookbook extends Base{ $return_data = $this->get_search_food_page_list_action($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 json(['status' => 'error', 'message' => '系统错误']); - } + // } 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 json(['status' => 'error', 'message' => '系统错误']); + // } } #######################################################################action####################################################################### @@ -742,7 +742,7 @@ class Cookbook extends Base{ ->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT') ->where(['a.cook_label'=>$cook_label,'a.is_del'=>0]) ->field('a.id,a.title,b.pic_url as cover,a.create_user_head_pic,a.create_user_nickname,a.likes_num') - ->order('id DESC') + // ->order('id DESC') ->page("$page_now,$page_num") ->select(); @@ -982,33 +982,45 @@ class Cookbook extends Base{ 'desc'=>'重量', 'list'=>$cookbook_data['food_data'], ]); - array_push($cookbook_data['tags'],[ - 'title'=>'能量', - 'desc'=>'含量', - 'list'=>$nutrition, - ]); - array_push($cookbook_data['tags'],[ - 'title'=>'维生素', - 'desc'=>'含量', - 'list'=>$vitamin, - ]); - array_push($cookbook_data['tags'],[ - 'title'=>'矿物质', - 'desc'=>'含量', - 'list'=>$mineral, - ]); - - - // $cookbook_data['nutrition']['list'] = $nutrition; - // // $cookbook_data['nutrition']['title'] = '能量及宏量营养素'; - // $cookbook_data['nutrition']['title'] = '能量'; - // $cookbook_data['nutrition']['desc'] = '含量'; - // $cookbook_data['vitamin']['list'] = $vitamin; - // $cookbook_data['vitamin']['title'] = '维生素'; - // $cookbook_data['vitamin']['desc'] = '含量'; - // $cookbook_data['mineral']['list'] = $mineral; - // $cookbook_data['mineral']['title'] = '矿物质'; - // $cookbook_data['mineral']['desc'] = '含量'; + if(count($nutrition)>0){ + array_push($cookbook_data['tags'],[ + 'title'=>'能量', + 'desc'=>'含量', + 'list'=>$nutrition, + ]); + }else{ + array_push($cookbook_data['tags'],[ + 'title'=>'', + 'desc'=>'', + 'list'=>[], + ]); + } + if(count($vitamin)>0){ + array_push($cookbook_data['tags'],[ + 'title'=>'维生素', + 'desc'=>'含量', + 'list'=>$vitamin, + ]); + }else{ + array_push($cookbook_data['tags'],[ + 'title'=>'', + 'desc'=>'', + 'list'=>[], + ]); + } + if(count($mineral)>0){ + array_push($cookbook_data['tags'],[ + 'title'=>'矿物质', + 'desc'=>'含量', + 'list'=>$mineral, + ]); + }else{ + array_push($cookbook_data['tags'],[ + 'title'=>'', + 'desc'=>'', + 'list'=>[], + ]); + } $cookbook_data['token'] = $cookbook_data['create_user_token']; $cookbook_data['description'] = $cookbook_data['describe_data']; @@ -1024,6 +1036,7 @@ class Cookbook extends Base{ unset($cookbook_data['is_del']); return $this->msg($cookbook_data); } + public function cookbook_follow_action($data){ // 获取账号下信息以及用户信息 $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find(); @@ -1176,10 +1189,17 @@ class Cookbook extends Base{ "); if(count($food_data)>0){ + for ($i=0; $i < count($food_data); $i++) { + if($food_data[$i]['pic_url'] != ''){ + $food_data[$i]['pic_url'] = 'https://tc.pcxbc.com/kitchenscale_all'.$food_data[$i]['pic_url']; + } + } return $this->msg($food_data); }else{ return $this->msg(10004,'未找到该食材'); } + + } public function get_food_list_action($data){ @@ -1201,7 +1221,7 @@ class Cookbook extends Base{ if($data['search_data'] === ""){ $data['search_data'] = ""; }else{ - $data['search_data'] = " AND name LIKE '%".$data['search_data']."%'"; + $data['search_data'] = " AND food_name LIKE '%".$data['search_data']."%'"; } } $search_sql_str = $search_sql_str.$data['search_data']; @@ -1286,7 +1306,7 @@ class Cookbook extends Base{ // 肉类id:10 11 14 $data_list = $cfc->table($this->kitchenscale_db_msg['foodlist3']) ->where('two_id in (4,6,7,10,11,14) and is_popular = 1') - ->field('id,name,two_id') + ->field('id,food_name,two_id') ->select(); $result = [ 'food'=>[ @@ -1306,9 +1326,9 @@ class Cookbook extends Base{ ]; foreach ($data_list as $key => $value) { if($value['two_id'] == 4 || $value['two_id'] == 6 || $value['two_id'] == 7){ - array_push($result['food']['list'][0]['list'],['id'=>$value['id'],'name'=>$value['name']]); + array_push($result['food']['list'][0]['list'],['id'=>$value['id'],'name'=>$value['food_name']]); }else if($value['two_id'] == 10 || $value['two_id'] == 11 || $value['two_id'] == 14){ - array_push($result['food']['list'][1]['list'],['id'=>$value['id'],'name'=>$value['name']]); + array_push($result['food']['list'][1]['list'],['id'=>$value['id'],'name'=>$value['food_name']]); } } diff --git a/application/KitchenScale/view/admin/base/pic_index.html b/application/KitchenScale/view/admin/base/pic_index.html new file mode 100644 index 0000000..ae123b5 --- /dev/null +++ b/application/KitchenScale/view/admin/base/pic_index.html @@ -0,0 +1,209 @@ + + +
+ +
| ID | +食谱名称 | +预览图 | +创建人 | +点赞数 | +阅读数 | +创建时间 | +状态 | +操作 |
|---|---|---|---|---|---|---|---|---|
| {$vo.id} | +{$vo.title} | +{$vo.create_user_nickname} | +{$vo.likes_num} | +{$vo.read_it} | +{$vo.create_time} | ++ {if condition="$vo.is_del == 1"} + 已停用 + {else /} + 已启用 + {/if} + | ++ + | +

