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 @@ + + + + + 图片管理 + + + + + + + + + + + + +
+
+ {volist name="result" id="vo"} +
+ {/volist} +
+
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/application/KitchenScale/view/admin/cookbook/add_cookbook.html b/application/KitchenScale/view/admin/cookbook/add_cookbook.html new file mode 100644 index 0000000..9480e45 --- /dev/null +++ b/application/KitchenScale/view/admin/cookbook/add_cookbook.html @@ -0,0 +1,420 @@ + + + + + + 菜谱管理 + + + + + + + + + + + +
+
+
+
+ +
+ +
+
+ +
+ +
+
点击选择
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+
+
+ + + + +
+
+
+ +
+
+ +
+ +
+
+
+
+ + +
+
+ 步骤图片预览 + +
+ + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/application/KitchenScale/view/admin/cookbook/card_edit.html b/application/KitchenScale/view/admin/cookbook/card_edit.html new file mode 100644 index 0000000..d448a5c --- /dev/null +++ b/application/KitchenScale/view/admin/cookbook/card_edit.html @@ -0,0 +1,232 @@ + + + + + + app版本管理 + + + + + + + + + + + + +
+
+
+
+ + +
+ + +
+ +
+
+ +
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+ + + +
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/KitchenScale/view/admin/cookbook/index.html b/application/KitchenScale/view/admin/cookbook/index.html new file mode 100644 index 0000000..1e7f477 --- /dev/null +++ b/application/KitchenScale/view/admin/cookbook/index.html @@ -0,0 +1,288 @@ + + + + + 所有卡片管理 + + + + + + + + + + +
+ + 首页 + 演示 + + 导航元素 + + + +
+
+
+
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + {volist name="result" id="vo"} + + + + + + + + + + + + {/volist} + +
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} + + +
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/application/KitchenScale/view/admin/index/index.html b/application/KitchenScale/view/admin/index/index.html new file mode 100644 index 0000000..2e3e1f9 --- /dev/null +++ b/application/KitchenScale/view/admin/index/index.html @@ -0,0 +1,230 @@ + + + + + 后台登录-X-admin2.2 + + + + + + + + + + + + + +
+ +
+ +
+ + +
+ + + +
+
+ +
+
+ + + +
+
+ +
+
+
关闭当前
+
关闭其它
+
关闭全部
+
+
+
+ +
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/KitchenScale/view/admin/index/welcome.html b/application/KitchenScale/view/admin/index/welcome.html new file mode 100644 index 0000000..f362ddd --- /dev/null +++ b/application/KitchenScale/view/admin/index/welcome.html @@ -0,0 +1,219 @@ + + + + + 欢迎页面-X-admin2.2 + + + + + + + + + + +
+
+ +
+
+
最新一周新增用户
+
+
+ +
+
+
+
+
+
最新一周PV/UV量
+
+
+ +
+
+
+
+
+
用户来源
+
+
+ +
+
+
+
+
+
硬盘使用量
+
+
+ +
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/KitchenScale/view/admin/login/login.html b/application/KitchenScale/view/admin/login/login.html new file mode 100644 index 0000000..56b9866 --- /dev/null +++ b/application/KitchenScale/view/admin/login/login.html @@ -0,0 +1,77 @@ + + + + + 后台登录-X-admin2.2 + + + + + + + + + + + + + +
+
轻厨记管理后台
+
+
+ +
+ +
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/application/admin/view/base/pic_index.html b/application/admin/view/base/pic_index.html index b349fc9..e71e7f6 100644 --- a/application/admin/view/base/pic_index.html +++ b/application/admin/view/base/pic_index.html @@ -58,7 +58,7 @@
-
+
{volist name="result" id="vo"}
{/volist} diff --git a/application/app/controller/Login.php b/application/app/controller/Login.php index 34454ba..88f389e 100644 --- a/application/app/controller/Login.php +++ b/application/app/controller/Login.php @@ -430,10 +430,10 @@ class Login extends Base{ $num = mt_rand(100000,999999); if (preg_match('/^\d{11}$/', $data['data'])) { // 本公司短信 - $result = $this->send_tel_code($data['data'],$num); + // $result = $this->send_tel_code($data['data'],$num); // 阿里云短信 - // $sms_all = new Smsaliyun; - // $result = $sms_all->send_sms($data['data'],$num); + $sms_all = new Smsaliyun; + $result = $sms_all->send_sms($data['data'],$num); // dump($result); $road = 'tel'; }else{ diff --git a/application/app/controller/Smsaliyun.php b/application/app/controller/Smsaliyun.php index de38148..4051555 100644 --- a/application/app/controller/Smsaliyun.php +++ b/application/app/controller/Smsaliyun.php @@ -14,16 +14,67 @@ class Smsaliyun extends Controller 'accessKeyId' => 'LTAI5tQCdWe9Epir3ydXWbzp', 'accessKeySecret' => 'JKLzF0b5AXw2ajhwtem2fhPSUZVOZ5', 'signName' => '郑州巨天信息', - 'templateCode' => 'SMS_484085215', + // 'signName' => '郑州品传科技', + // 'templateCode' => 'SMS_484085215',//reedaw模板 :您好,欢迎使用Reedaw,您的手机验证码是: ${code},验证码一分钟内有效,若非本人操作,请忽略本短信 + 'templateCode' => 'SMS_491550200',//巨天通用模板 :您好,您的手机验证码是: ${code},请尽快输入避免验证码失效,若非本人操作,请忽略本短信 + // 'templateCode' => 'SMS_491320295',//品传通用模板 :您好,您的手机验证码是: ${code},请尽快输入避免验证码失效,若非本人操作,请忽略本短信 'regionId' => 'cn-hangzhou' ]; + + public function send_sms_api(){ + $data = input(); + if(!array_key_exists('tel',$data)){ + return json([ + 'code'=>10001, + 'msg'=>'缺少手机号码', + 'data'=>[], + ]); + } + if(!array_key_exists('code',$data)){ + return json([ + 'code'=>10002, + 'msg'=>'缺少验证码', + 'data'=>[], + ]); + } + if(!$this->validatePhoneNumber($data['tel'])){ + return json([ + 'code'=>10001, + 'msg'=>'手机号码格式错误', + 'data'=>[], + ]); + } + if(!$this->validateSixDigitCode($data['code'])){ + return json([ + 'code'=>10002, + 'msg'=>'验证码格式错误', + 'data'=>[], + ]); + } + + $result = $this->send_sms($data['tel'],$data['code']); + + return json($result); + } + // 验证函数定义(可以放在单独的文件中) + public function validatePhoneNumber($phone) { + $pattern = '/^1[3-9]\d{9}$/'; + return preg_match($pattern, $phone) === 1; + } + + public function validateSixDigitCode($code) { + $pattern = '/^\d{6}$/'; + return preg_match($pattern, $code) === 1; + } + + /** * 发送短信接口 * @param string $phone 手机号 * @param string $code 验证码 */ - public function send_sms($phone='18530934717', $code='0932') + public function send_sms($phone, $code) { try { // 初始化阿里云客户端 @@ -53,7 +104,7 @@ class Smsaliyun extends Controller ->request(); $result = $result->toArray(); - + // return $result; if ($result['Code'] == 'OK') { return [ 'code' => 0, diff --git a/application/code/view/qrcode/kitchen_qrcode.html b/application/code/view/qrcode/kitchen_qrcode.html index 35f403e..6822e3d 100644 --- a/application/code/view/qrcode/kitchen_qrcode.html +++ b/application/code/view/qrcode/kitchen_qrcode.html @@ -40,7 +40,9 @@ } - window.location.href = 'weixin://dl/business/?appid=wx9c0b7a436ada6d1e&path=pages/home/home'; + window.location.href = 'weixin://dl/business/?appid=wx1f32af4f93c913f6&path=pages/index/index'; + // window.location.href = 'https://mp.weixin.qq.com/a/~hlVtiIugLJKBe4bZVEVfAA~~'; + diff --git a/application/route.php b/application/route.php index 7bbbc08..3c81b77 100644 --- a/application/route.php +++ b/application/route.php @@ -53,6 +53,10 @@ Route::any('/kitchen_qrcode', 'code/qrcode/kitchen_qrcode'); +Route::post('/send_sms_api', 'app/smsaliyun/send_sms_api'); + + + @@ -450,6 +454,7 @@ Route::any('/open_wechat_content', 'app/Msginformation/open_wechat_content'); ################################################################下面是厨房秤################################################################ ########################################################################################################################################### +#########################################################前端接口############################################################ // 微信小程序快捷登录接口 Route::any('/kitchenscale/wechat_quick_login', 'app/kitchenscale/app.index/wechat_quick_login'); Route::any('/testedition/kitchenscale/wechat_quick_login', 'app/kitchenscale/app.index/wechat_quick_login'); @@ -571,6 +576,25 @@ Route::any('/kitchenscale/get_default_configuration', 'app/kitchenscale/app.prod // Route::any('/kitchenscale/getRelatedConfigurations', 'app/kitchenscale/app.product/getRelatedConfigurations'); // Route::any('/kitchenscale/getOptionConfigurations', 'app/kitchenscale/app.product/getOptionConfigurations'); +#########################################################管理后台############################################################ + +// 图片选择上传 +Route::any('/k/admin/pic', 'app/kitchenscale/admin.base/pic_index'); +Route::any('/k/admin/pic_upload_action', 'app/kitchenscale/admin.base/pic_upload_action'); + +// 登录页 +Route::any('/k/a/login', 'app/kitchenscale/admin.login/login'); +Route::any('/k/a/login_action', 'app/kitchenscale/admin.login/login_action'); +// 首页 +Route::any('/k/a/index', 'app/kitchenscale/admin.index/index'); +Route::any('/k/a/welcome', 'app/kitchenscale/admin.index/welcome'); +// 食谱页 +Route::any('/k/a/cookbook/index', 'app/kitchenscale/admin.cookbook/index'); +Route::any('/k/a/cookbook/add_cookbook', 'app/kitchenscale/admin.cookbook/add_cookbook'); +Route::any('/k/a/cookbook/add_cookbook_action', 'app/kitchenscale/admin.cookbook/add_cookbook_action'); +Route::any('/k/a/cookbook/find_food_list', 'app/kitchenscale/admin.cookbook/find_food_list'); +Route::any('/k/a/cookbook/stop_and_run', 'app/kitchenscale/admin.cookbook/stop_and_run'); + diff --git a/application/test/controller/Testuse.php b/application/test/controller/Testuse.php index 844c639..77df8f0 100644 --- a/application/test/controller/Testuse.php +++ b/application/test/controller/Testuse.php @@ -9,6 +9,7 @@ use think\Log; use \think\Validate; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; +use app\app\controller\Smsaliyun; class Testuse extends Controller{ @@ -687,91 +688,121 @@ class Testuse extends Controller{ public function caipu_shuju_chuli() { + // // 处理图片,查看本地文件,数据存到图片表,修改原始数据的状态start####################################################################### + // // 初始化SQL Server数据库连接 + // $cfc = Db::connect('cfc_db'); + // // 查询需要处理的原始数据 + // $yuanshi_data = $cfc->table('linshi_caidan_biao') + // ->where(['pic_clean' => 1,'is_move_ok'=>0]) + // ->page("1,100") + // ->field('id,pic_url,name,yuanshi_id,category,pic_clean') + // ->select(); + // // dump($yuanshi_data); + // // die; + // if(count($yuanshi_data) <= 0){ + // return $this->msg(99999,'ok',[]); + // } - // 初始化SQL Server数据库连接 + // $yuanshi_mulu = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img'; + // $new_mulu = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img\linshi'; + + + // $result = [ + // 'all'=>count($yuanshi_data), + // 'ok'=>0, + // 'no'=>0, + // 'none'=>0, + // ]; + + // $temporary_arr_data = []; + // $temporary_arr_ok = []; + // $temporary_arr_none = []; + // foreach ($yuanshi_data as $key => $value) { + + // // 先判断是不是个有效的图片名字 + // if (preg_match('/\.jpg$/i', $value['pic_url'])) { + // // 是 + // // 判断目录下是否有这个文件 + // if (!file_exists($yuanshi_mulu.DS.$value['pic_url'])) { + // $result['none'] = $result['none']+1; + // array_push($temporary_arr_none,$value['yuanshi_id']); + // continue; + // }else{ + // $result['ok'] = $result['ok']+1; + // array_push($temporary_arr_ok,$value['yuanshi_id']); + // array_push($temporary_arr_data,[ + // 'user_token' => 'caadd1be045a65f30b92aa805f1de54a', + // 'pic_name' => $value['pic_url'], + // 'pic_url' => "https://tc.pcxbc.com/kitchenscale_all/cook_img/".$value['pic_url'], + // 'create_time' => date('Y-m-d H:i:s'), + // 'special_record_str' => $value['yuanshi_id'] + // ]); + // rename($yuanshi_mulu.DS.$value['pic_url'], $new_mulu.DS.$value['pic_url']); + // } + // } else { + // $result['none'] = $result['none']+1; + // array_push($temporary_arr_none,$value['yuanshi_id']); + // continue; + // } + // } + // // 启动事务 + // $cfc->startTrans(); + // try { + + // if($result['ok'] > 0){ + // $cfc->table('app_user_upload_img')->insertAll($temporary_arr_data); + // $cfc->table('linshi_caidan_biao')->where("yuanshi_id in ('".implode("','",$temporary_arr_ok)."')")->update(['is_move_ok'=>1]); + // } + // if($result['none'] > 0){ + // $cfc->table('linshi_caidan_biao')->where("yuanshi_id in ('".implode("','",$temporary_arr_none)."')")->update(['is_move_ok'=>2]); + // } + + // $cfc->commit(); + // return json(['code'=>0,'msg'=>'成功','data'=>$result]); + // } catch (\Exception $e) { + // $cfc->rollback(); + // return json(['code'=>99999,'msg'=>'成功','data'=>[]]); + // } + // // 处理图片,查看本地文件,数据存到图片表,修改原始数据的状态end####################################################################### + + //更新菜谱的图片数据为图片表的数据start######################################### + $cfc = Db::connect('cfc_db'); - // 查询需要处理的原始数据 - $yuanshi_data = $cfc->table('linshi_caidan_biao') - ->where(['pic_clean' => 1,'is_move_ok'=>0]) - ->page("1,100") - ->field('id,pic_url,name,yuanshi_id,category,pic_clean') - ->select(); - // dump($yuanshi_data); - // die; + $page = 1; + $data = input(); + $page = $data['page']; + // 查食谱 - $yuanshi_mulu = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img'; - $new_mulu = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img\linshi'; - - - $result = [ - 'all'=>count($yuanshi_data), - 'ok'=>0, - 'no'=>0, - 'none'=>0, - ]; - $temporary_arr_data = []; - $temporary_arr_ok = []; - $temporary_arr_none = []; - foreach ($yuanshi_data as $key => $value) { - - // 先判断是不是个有效的图片名字 - if (preg_match('/\.jpg$/i', $value['pic_url'])) { - // 是 - // 判断目录下是否有这个文件 - if (!file_exists($yuanshi_mulu.DS.$value['pic_url'])) { - $result['none'] = $result['none']+1; - array_push($temporary_arr_none,$value['yuanshi_id']); - continue; - }else{ - $result['ok'] = $result['ok']+1; - array_push($temporary_arr_data,[ - 'user_token' => 'caadd1be045a65f30b92aa805f1de54a', - 'pic_name' => $value['pic_url'], - 'pic_url' => "https://tc.pcxbc.com/kitchenscale_all/cook_img/".$value['pic_url'], - 'create_time' => date('Y-m-d H:i:s'), - 'special_record_str' => $value['yuanshi_id'] - ]); - rename($yuanshi_mulu.DS.$value['pic_url'], $new_mulu.DS.$value['pic_url']) - } - } else { - $result['none'] = $result['none']+1; - array_push($temporary_arr_none,$value['yuanshi_id']); - continue; - } + // $img_data = $cfc->table('app_user_upload_img')->where(["special_record_str"=>$cookbook_data[0]['original_cookbook_id']])->field('id,special_record_str')->select(); + $img_data = $cfc->table('app_user_upload_img')->where(["operate_log"=>0])->page("$page,1")->field('id,special_record_str')->select(); + if(count($img_data) <= 0){ + return $this->msg(99999,'没了',[]); + } + $cookbook_data = $cfc->table('app_user_cookbook')->where(['original_cookbook_id'=>$img_data[0]['special_record_str']])->field('id')->select(); + if(count($cookbook_data) <= 0){ + return $this->msg(0,'no1',[]); } // 启动事务 $cfc->startTrans(); try { - if($result['ok'] > 0){ - $cfc->table('app_user_upload_img')->insertAll($temporary_arr_data); - $cfc->table('linshi_caidan_biao')->where("yuanshi_id in ('".implode("','",$temporary_arr_ok)."')")->update(['is_move_ok'=>1]); - } - if($result['none'] > 0){ - $cfc->table('linshi_caidan_biao')->where("yuanshi_id in ('".implode("','",$temporary_arr_none)."')")->update(['is_move_ok'=>2]); - } + $cfc->table('app_user_cookbook')->where(['original_cookbook_id'=>$img_data[0]['special_record_str']])->update(['cover'=>$img_data[0]['id']]); + $cfc->table('app_user_upload_img')->where(['id'=>$img_data[0]['id']])->update(['operate_log'=>1]); $cfc->commit(); - dump($result); + return $this->msg(0,'ok',['num'=>$img_data[0]['special_record_str']]); } catch (\Exception $e) { $cfc->rollback(); - dump($e); + return $this->msg(0,'no2',[]); } + } - dump($result); - dump($temporary_arr_ok); - dump($temporary_arr_no); - dump($temporary_arr_none); - dump($temporary_arr_data); - die; + // 从execl直接导入菜谱 + public function execl_import_cookbook(){ - - - - } ################################################################################################################### diff --git a/application/test/view/testuse/clean_data_all_page.html b/application/test/view/testuse/clean_data_all_page.html index 10713a9..dfde32a 100644 --- a/application/test/view/testuse/clean_data_all_page.html +++ b/application/test/view/testuse/clean_data_all_page.html @@ -5,12 +5,24 @@ 洗数据 + +
开始
当前第1
累积成功0
-
累积失败0
+
查找菜谱失败0
+
修改数据失败0
+
成功原始菜谱id:
@@ -19,8 +31,46 @@ var page = 1; var page_str = 1; var ok_str = 0; - var no_str = 0; + var no1_str = 0; + var no2_str = 0; + // // 本地数据处理进图片表 + // function start_action(){ + // $.ajax({ + // // url:"clean_data_all", //请求的url地址 + // url:"caipu_shuju_chuli", //请求的url地址 + // dataType:"json", //返回格式为json + // async:true,//请求是否异步,默认为异步,这也是ajax重要特性 + // data:{"page":page}, //参数值 + // type:"POST", //请求方式 + // success:function(req){ + // //请求成功时处理 + // if(req.code == 0){ + // $('.jilu').html(page_str) + // page_str = page_str+1; + // ok_str = ok_str + req.data.ok + // no1_str = no1_str + req.data.no + // no2_str = no2_str + req.data.none + + + // $('.ok').html(ok_str) + + // $('.no1').html(no1_str) + // $('.no2').html(no2_str) + // setTimeout(() => { + // start_action() + // }, 500); + + // }else if(req.code == 99999){ + // return + // } + // }, + // error:function(){ + // //请求出错处理 + // }}); + // } + + // 处理图片表跟食谱表的数据统一 function start_action(){ $.ajax({ // url:"clean_data_all", //请求的url地址 @@ -31,17 +81,28 @@ type:"POST", //请求方式 success:function(req){ //请求成功时处理 + console.log(req.msg) if(req.code == 0){ - page_str = page_str+1; $('.jilu').html(page_str) - ok_str = ok_str + req.data.ok - no_str = no_str + req.data.no - - $('.ok').html(ok_str) - $('.no').html(no_str) + page_str = page_str+1; + if(req.msg == 'ok'){ + ok_str = ok_str + 1 + $('.ok').html(ok_str) + $('.cook').append(''+req.data.num+','); + } + if(req.msg == 'no1'){ + no1_str = no1_str + 1 + // console.log(no_str) + $('.no1').html(no1_str) + } + if(req.msg == 'no2'){ + no2_str = no2_str + 1 + // console.log(no_str) + $('.no2').html(no2_str) + } setTimeout(() => { start_action() - }, 1000); + }, 500); }else if(req.code == 99999){ return