diff --git a/application/DeviceEnter/controller/Savemsg.php b/application/DeviceEnter/controller/Savemsg.php index e9bef3b..aef16e8 100644 --- a/application/DeviceEnter/controller/Savemsg.php +++ b/application/DeviceEnter/controller/Savemsg.php @@ -8,12 +8,14 @@ use think\Cache; class Savemsg extends Base{ + // 设备名称列表 protected $name_list = [ - [ - 'name'=>'c03', - ], - + ['name'=>'PC-C02Pro'] + // [ + // 'name'=>'PC-C02Pro', + // ], ]; + // 默认选中的设备名称下标 protected $name_default = 0; // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -31,7 +33,7 @@ class Savemsg extends Base{ } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); - $logContent["line"] = $e->getLine(); + $logContent["line"] = $e->getLine(); = $logContent['all_content'] = "异常信息:\n"; $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; @@ -45,7 +47,7 @@ class Savemsg extends Base{ } - public function save_device_msg($data = ['mac'=>'564654564654654','device_name'=>'bl_5520','batch_code'=>'bc250826']){ + public function save_device_msg($data = ['mac'=>'564654564654654','device_name'=>'bl_5520','batch_code'=>'bc250826','token'=>'as56d4a56s1d5as4d6']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -60,6 +62,9 @@ class Savemsg extends Base{ if(!array_key_exists('batch_code', $data)){ return $this->msg(10001); } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } if(!$this->verify_data_is_ok($data['mac'],'str')){ return $this->msg(10005); } @@ -69,6 +74,9 @@ class Savemsg extends Base{ if(!$this->verify_data_is_ok($data['batch_code'],'str')){ return $this->msg(10005); } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } $result = $this->save_device_msg_action($data); return $result; } catch (\Exception $e) { @@ -90,27 +98,67 @@ class Savemsg extends Base{ } + // 历史箱号数据 public function device_batch_list(){ - // try { - - $result = $this->device_batch_list_action(); + try { + // 你的业务逻辑 + if(count(input()) > 0){ + $data = input(); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $result = $this->device_batch_list_action($data); return $result; - // } 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'] .= "函数名: " . __FUNCTION__ . "\n"; - // $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; - // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; - // // dump($data); - // // die; - // $this->record_api_log([], $logContent, null); - // return $this->msg(99999); - // } + } 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'] .= "函数名: " . __FUNCTION__ . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log([], $logContent, null); + return $this->msg(99999); + } + + } + + // 详细批次数据 + public function device_content_msg($data = ['batch_code'=>'tcxbc250904']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('batch_code', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['batch_code'],'str')){ + return $this->msg(10005); + } + $result = $this->device_content_msg_action($data); + return $this->msg($result); + } 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'] .= "函数名: " . __FUNCTION__ . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log([], $logContent, null); + return $this->msg(99999); + } } @@ -131,37 +179,79 @@ class Savemsg extends Base{ ]; return $data; } - public function save_device_msg_action($data){ + // 验证mac地址是否存在且不为空 + if (!isset($data['mac']) || empty(trim($data['mac']))) { + return $this->msg(10002, 'MAC地址不能为空'); + } $device_enter = Db::connect('device_enter_db'); - $mac_code = $device_enter->table('device_C02pro')->where(['device_mac'=>$data['mac']])->count(); - if($mac_code > 0){ - return $this->msg(10002,'该MAC地址已录入'); - } - $result = $device_enter->table('device_C02pro')->insert([ + // $mac_code = $device_enter->table('device_C03')->where(['device_mac'=>$data['mac']])->find(); + // if($mac_code){ + // return $this->msg(10002,'该MAC地址已录入,批次号:'.$mac_code['batch_code']); + // } + $result = $device_enter->table('device_C03')->insert([ 'device_mac'=>$data['mac'], 'device_name'=>$data['device_name'], 'batch_code'=>$data['batch_code'], + 'token'=>$data['token'], 'create_time'=>date('Y-m-d H:i:s'), ]); if($result){ - return $this->msg([]); + $all_data = $this->device_content_msg_action($data); + return $this->msg($all_data); }else{ return $this->msg(10002); + } } - public function device_batch_list_action(){ + public function device_batch_list_action($data){ $device_enter = Db::connect('device_enter_db'); $result = $device_enter->query(" SELECT device_name, batch_code, COUNT(*) as num - FROM device_C02pro + FROM device_C03 + WHERE token = '".$data['token']."' GROUP BY batch_code,device_name ORDER BY MAX(id) desc "); return $this->msg($result); } + + public function device_content_msg_action($data){ + + $device_enter = Db::connect('device_enter_db'); + $result = $device_enter->query(" + SELECT device_mac + FROM device_C03 + WHERE batch_code = '".$data['batch_code']."' + order by id desc + "); + $return_result = [ + 'list'=>[], + 'num'=>0, + ]; + for ($i=0; $i < count($result); $i++) { + array_push($return_result['list'],$result[$i]['device_mac']); + $return_result['num'] = $return_result['num']+1; + } + return $return_result; + } + + + ################################################################测试################################################################ + ################################################################测试################################################################ + ################################################################测试################################################################ + + public function ceshi(){ + // $device_enter = Db::connect('device_enter_db'); + // $mac_code = $device_enter->table('device_C03')->select(); + // $data = []; + // foreach ($mac_code as $key => $value) { + // $data[] = $value['device_mac']; + // } + // dump($data); + } } \ No newline at end of file diff --git a/application/DeviceEnter/controller/Wechat.php b/application/DeviceEnter/controller/Wechat.php new file mode 100644 index 0000000..a866115 --- /dev/null +++ b/application/DeviceEnter/controller/Wechat.php @@ -0,0 +1,79 @@ + 0){ + $data = input('post.'); + } + if(!array_key_exists('code', $data)){ + // return $this->msg(10001,''); + return $this->msg(10001,'code is miss'); + } + // 校验参数 + if (empty($data['code'])) { + return $this->msg(10001,'code is miss.'); + } + + $code = $data['code']; + $config = [ + 'app_id' => $this->app_id, + 'app_secret' => $this->app_secret, + ]; + $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$config['app_id']}&secret={$config['app_secret']}&js_code={$code}&grant_type=authorization_code"; + + $result = file_get_contents($url); + $data = json_decode($result, true); + if (isset($data['errcode'])) { + // return json(['code' => 500, 'msg' => '获取openid失败:'.$data['errmsg']]); + return $this->msg(10002,'获取openid失败:'.$data['errmsg']); + } + + + $device_enter = Db::connect('device_enter_db'); + + $user_find = $device_enter->table('device_user')->where(['openid'=>$data['openid']])->find(); + if($user_find){ + return $this->msg(['token' => $user_find['token']]); + }else{ + $token = md5($data['openid']); + $user_result = $device_enter->table('device_user') + ->insert([ + 'openid'=>$data['openid'], + 'token'=>$token, + 'create_time'=>date('Y-m-d H:i:s') + ]); + if($user_result){ + return $this->msg(['token' => $token]); + } + } + } 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'] .= "方法: " . __METHOD__ . "\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); + } + } + + +} \ No newline at end of file diff --git a/application/DeviceEnter/controller/admin/Base.php b/application/DeviceEnter/controller/admin/Base.php new file mode 100644 index 0000000..3d5252f --- /dev/null +++ b/application/DeviceEnter/controller/admin/Base.php @@ -0,0 +1,185 @@ +'关键参数缺失', + '10002'=>'操作失败', + '10003'=>'信息核实错误', + '10004'=>'未找到有效数据', + '10005'=>'参数格式错误', + '10006'=>'参数不能为空', + '10007'=>'参数错误', + '10008'=>'', + '10009'=>'', + '10010'=>'自定义信息', + '20001'=>'登录失效', + '99999'=>'网络异常,请稍后重试', + ]; + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + // 接口记录 + public function record_api_log($params, $error = null, $response = null){ + // dump($params); + // dump($error); + // die; + $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'; + } + } + + + // 验证 + public function verify_data_is_ok($data = 2,$type){ + if($type == 'str'){ + if (is_string($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]); + return false; + } + }else if($type == 'num'){ + if (is_numeric($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]); + return false; + } + }else if($type == 'intnum'){ + $pattern = '/^\d+$/'; + // dump($data); + if (preg_match($pattern, $data)) { + return true; // 匹配成功,返回 true + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]); + return false; // 匹配失败,返回 false + } + }else if($type == 'datetime'){ + $formats = ['Y-m-d','Y-m-d H:i:s']; + foreach ($formats as $format) { + $dateTime = \DateTime::createFromFormat($format, $data); + // 检查时间字符串是否成功解析,并且解析后的日期时间与原始字符串表示的时间一致 + if ($dateTime && $dateTime->format($format) === $data) { + return true; + } + } + // 如果所有格式都解析失败,则返回 false + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]); + return false; + }else if($type == 'other'){ + + } + + } + + + + public function msg($data,$str='',$result = []){ + if(is_array($data)){ + if($str != ''){ + return json(['code'=>0,'msg'=>$str,'data'=>$data]); + }else{ + return json(['code'=>0,'msg'=>'操作成功','data'=>$data]); + } + }else{ + if($str != ''){ + return json(['code'=>$data,'msg'=>$str,'data'=>$result]); + } + return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]); + } + } + + 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'; + } + + +} \ No newline at end of file diff --git a/application/DeviceEnter/controller/admin/Device.php b/application/DeviceEnter/controller/admin/Device.php new file mode 100644 index 0000000..f969922 --- /dev/null +++ b/application/DeviceEnter/controller/admin/Device.php @@ -0,0 +1,105 @@ +=',$data['s_time']]; + // } + // if($data['e_time']){ + // $parameter['create_time'] = ['<=',$data['e_time']]; + // } + } + $device = Db::connect('device_enter_db'); + $num = $device->table('device_batch')->where($parameter)->count(); + $result = $device->table('device_batch')->where($parameter)->order('is_activate,id desc')->page($page,$this->page_num)->select(); + if(!$pd){ + $result['num'] = $num; + $result['data'] = $result; + return $this->msg(0,'success',$result); + } + $this->assign([ + 'result' => $result, + 'num' => $num, + ]); + return $this->fetch(); + } + + public function device_list($page = 1){ + $data = input(); + $pd = true; + $parameter = []; + $parameter['batch_code'] = $data['id']; + if(array_key_exists('tt', $data)){ + $page = $data['page_num']; + unset($data['page_num']); + unset($data['tt']); + $pd = false; + } + $device = Db::connect('device_enter_db'); + $num = $device->table('device_C03')->where($parameter)->count(); + $result = $device->table('device_C03')->where($parameter)->order('is_activate,id desc')->page($page,$this->page_num)->select(); + if(!$pd){ + $result['num'] = $num; + $result['data'] = $result; + $result['id'] = $parameter['batch_code']; + return $this->msg(0,'success',$result); + } + $this->assign([ + 'result' => $result, + 'num' => $num, + 'id' => $parameter['batch_code'], + ]); + return $this->fetch(); + } + + public function device_all(){ + $data = input(); + $device = Db::connect('device_enter_db'); + $device->startTrans(); + try{ + $device->table('device_batch')->where(['id'=>$data['id']])->update(['is_activate'=>$data['state']]); + + $device->table('device_C03')->where(['batch_code'=>$data['id']])->update(['is_activate'=>$data['state']]); + // 提交事务 + $device->commit(); + return $this->msg([]); + } catch (\Exception $e) { + // 回滚事务 + $device->rollback(); + return $this->msg(10002,$e->getMessage()); + } + } + + + +} \ No newline at end of file diff --git a/application/DeviceEnter/controller/admin/Index.php b/application/DeviceEnter/controller/admin/Index.php new file mode 100644 index 0000000..9852a78 --- /dev/null +++ b/application/DeviceEnter/controller/admin/Index.php @@ -0,0 +1,24 @@ +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/DeviceEnter/controller/admin/Login.php b/application/DeviceEnter/controller/admin/Login.php new file mode 100644 index 0000000..9376987 --- /dev/null +++ b/application/DeviceEnter/controller/admin/Login.php @@ -0,0 +1,42 @@ +fetch(); + } + + // 检测登录信息是否超时 + public function login_action(){ + $data = input(); + // 验证数据项是否完整 + if(!array_key_exists('username', $data) || !array_key_exists('password', $data)){ + return $this->msg(10001); + } + $data['password_md5'] = md5($data['password']); + $device = Db::connect('device_enter_db'); + $account = $device->ttable('admin_account')->where(['user_name'=>$data['username'],'pass_word'=>$data['password_md5']])->find(); + if($account>0){ + return $this->msg([]); + }else{ + return $this->msg(10003); + } + } + + + +} \ No newline at end of file diff --git a/application/DeviceEnter/view/admin/device/device_add.html b/application/DeviceEnter/view/admin/device/device_add.html new file mode 100644 index 0000000..05dbb72 --- /dev/null +++ b/application/DeviceEnter/view/admin/device/device_add.html @@ -0,0 +1,223 @@ + + + + + + 设备管理_add + + + + + + + + + + + + +
+
+
+
+ + +
+ + +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+
+ + + +
+
+
+
+ + + + + \ No newline at end of file diff --git a/application/DeviceEnter/view/admin/device/device_edit.html b/application/DeviceEnter/view/admin/device/device_edit.html new file mode 100644 index 0000000..d80b175 --- /dev/null +++ b/application/DeviceEnter/view/admin/device/device_edit.html @@ -0,0 +1,238 @@ + + + + + + 设备管理_edit + + + + + + + + + + + + +
+
+
+
+ + +
+ + +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+ + + +
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/DeviceEnter/view/admin/device/device_list.html b/application/DeviceEnter/view/admin/device/device_list.html new file mode 100644 index 0000000..fb58bb2 --- /dev/null +++ b/application/DeviceEnter/view/admin/device/device_list.html @@ -0,0 +1,319 @@ + + + + + 所有设备管理 + + + + + + + + + + +
+
+
+
+ +
+ + + + +
+
+ + + + + + + + + + + + + + {volist name="result" id="vo"} + + + + + + {if condition="$vo.is_activate == 1"} + + + {else /} + + + {/if} + + + {/volist} + +
ID设备码创建时间是否激活操作
{$vo.id}{$vo.device_mac}{$vo.create_time}已激活未激活 + +
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/application/DeviceEnter/view/admin/device/index.html b/application/DeviceEnter/view/admin/device/index.html new file mode 100644 index 0000000..db4cb65 --- /dev/null +++ b/application/DeviceEnter/view/admin/device/index.html @@ -0,0 +1,357 @@ + + + + + 所有设备管理 + + + + + + + + + + +
+ + 首页 + 演示 + + 导航元素 + + + +
+
+
+
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + {volist name="result" id="vo"} + + + + + + + {if condition="$vo.is_activate == 1"} + + + {else /} + + + {/if} + + + {/volist} + +
ID设备型号批次编号创建时间创建人是否激活操作
{$vo.id}{$vo.name}{$vo.batch_code}{$vo.create_time}{$vo.token}已激活未激活 + +
+
+
+
+
+
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/application/DeviceEnter/view/admin/index/index.html b/application/DeviceEnter/view/admin/index/index.html new file mode 100644 index 0000000..39b8bdb --- /dev/null +++ b/application/DeviceEnter/view/admin/index/index.html @@ -0,0 +1,92 @@ + + + + + 后台登录-X-admin2.2 + + + + + + + + + + + + + +
+ +
+ +
+ + +
+ + + +
+
+ +
+
+ + + +
+
+ +
+
+
关闭当前
+
关闭其它
+
关闭全部
+
+
+
+ +
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/DeviceEnter/view/admin/index/welcome.html b/application/DeviceEnter/view/admin/index/welcome.html new file mode 100644 index 0000000..f362ddd --- /dev/null +++ b/application/DeviceEnter/view/admin/index/welcome.html @@ -0,0 +1,219 @@ + + + + + 欢迎页面-X-admin2.2 + + + + + + + + + + +
+
+ +
+
+
最新一周新增用户
+
+
+ +
+
+
+
+
+
最新一周PV/UV量
+
+
+ +
+
+
+
+
+
用户来源
+
+
+ +
+
+
+
+
+
硬盘使用量
+
+
+ +
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/DeviceEnter/view/admin/login/login.html b/application/DeviceEnter/view/admin/login/login.html new file mode 100644 index 0000000..e8a286f --- /dev/null +++ b/application/DeviceEnter/view/admin/login/login.html @@ -0,0 +1,77 @@ + + + + + 后台登录-X-admin2.2 + + + + + + + + + + + + + +
+
设备录入管理后台
+
+
+ +
+ +
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/application/KitchenScale/controller/app/Cookbook.php b/application/KitchenScale/controller/app/Cookbook.php index af28f05..e9b8cbc 100644 --- a/application/KitchenScale/controller/app/Cookbook.php +++ b/application/KitchenScale/controller/app/Cookbook.php @@ -424,7 +424,7 @@ class Cookbook extends Base{ } } // 获取所有食材列表 - public function get_food_list($data=['food_level2_id'=>'2','search_data'=>'','page'=>1]){ + public function get_food_list($data=['food_level2_id'=>'6','search_data'=>'','page'=>1]){ // 尝试捕获异常 try { if(count(input('post.')) > 0){ diff --git a/application/KitchenScale/controller/app/Countfood.php b/application/KitchenScale/controller/app/Countfood.php index 54554fe..17dc8e7 100644 --- a/application/KitchenScale/controller/app/Countfood.php +++ b/application/KitchenScale/controller/app/Countfood.php @@ -19,6 +19,7 @@ class Countfood extends Base{ 'followlist'=>'app_user_follow_list',//关注列表 'collect_list'=>'app_user_collect_list',//收藏列表 'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3 + 'foodlist4'=>'app_z_national_standard_food_type_4',//食材列表3 'eat_log'=>'app_user_kcal_log',//食材列表3 'user'=>'app_user_data',//banner ]; @@ -74,9 +75,9 @@ class Countfood extends Base{ } } // 获取记食器板块内容 - public function get_countfoot_content($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'time'=>'2025-08-25']){ + public function get_countfoot_content($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'time'=>'2025-09-17']){ // 尝试捕获异常 - try { + // try { if(count(input('post.')) > 0){ $data = input('post.'); } @@ -101,20 +102,20 @@ class Countfood extends Base{ $return_data = $this->get_countfoot_content_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' => '系统错误']); + // } } // 获取记食器记录 public function get_log_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'s_time'=>'2025-03-15','e_time'=>'2025-03-16']){ @@ -418,10 +419,13 @@ class Countfood extends Base{ ->alias('a') ->join('app_z_national_standard_food_type_3 b','a.food_id = b.id','LEFT') ->where("a.is_del = 0 AND a.aud_id = " . $data['aud_id'] . " AND CAST(a.create_time AS DATE) = CAST('" . $data['time'] . "' AS DATE)") - ->field('a.meals_type,a.food_name,a.weight,a.kcal_val,a.carbohydrate_val,a.protein_val,a.fat_val,a.id,\'https://tc.pcxbc.com\' + b.pic_url as pic_url') + ->field('a.meals_type,a.food_name,a.weight,a.kcal_val,a.carbohydrate_val,a.protein_val,a.fat_val,a.id,\'https://tc.pcxbc.com\' + b.pic_url as pic_url,a.food_id') ->select(); - // dump($food_content); - // die; + + if(count($food_content) > 0){ + $food_content = $this->calculate_nutrients($food_content); + } + $date = date('Y-m-d H:i:s'); $return_data = [ 'suggestion'=>[ @@ -493,7 +497,10 @@ class Countfood extends Base{ 'weight'=>$value['weight'].'克', 'id'=>$value['id'], 'pic_url'=>$value['pic_url'], - 'val'=>$value['kcal_val'].'kcal' + // 'val'=>$value['kcal_val'].'kcal', + 'val'=>$value['kcal_val'], + 'nutrients_four' => $value['nutrients_four'], + 'nutrients_list' => $value['nutrients_list'] ]); }else if($value['meals_type'] == '午餐'){ $return_data['list'][1]['val'] = bcadd($return_data['list'][1]['val'],$value['kcal_val'],2); @@ -502,7 +509,10 @@ class Countfood extends Base{ 'weight'=>$value['weight'].'克', 'id'=>$value['id'], 'pic_url'=>$value['pic_url'], - 'val'=>$value['kcal_val'].'kcal' + // 'val'=>$value['kcal_val'].'kcal', + 'val'=>$value['kcal_val'], + 'nutrients_four' => $value['nutrients_four'], + 'nutrients_list' => $value['nutrients_list'] ]); }else if($value['meals_type'] == '晚餐'){ $return_data['list'][2]['val'] = bcadd($return_data['list'][2]['val'],$value['kcal_val'],2); @@ -511,7 +521,10 @@ class Countfood extends Base{ 'weight'=>$value['weight'].'克', 'id'=>$value['id'], 'pic_url'=>$value['pic_url'], - 'val'=>$value['kcal_val'].'kcal' + // 'val'=>$value['kcal_val'].'kcal', + 'val'=>$value['kcal_val'], + 'nutrients_four' => $value['nutrients_four'], + 'nutrients_list' => $value['nutrients_list'] ]); }else if($value['meals_type'] == '早加餐'){ $return_data['list'][3]['val'] = bcadd($return_data['list'][3]['val'],$value['kcal_val'],2); @@ -520,7 +533,10 @@ class Countfood extends Base{ 'weight'=>$value['weight'].'克', 'id'=>$value['id'], 'pic_url'=>$value['pic_url'], - 'val'=>$value['kcal_val'].'kcal' + // 'val'=>$value['kcal_val'].'kcal', + 'val'=>$value['kcal_val'], + 'nutrients_four' => $value['nutrients_four'], + 'nutrients_list' => $value['nutrients_list'] ]); }else if($value['meals_type'] == '午加餐'){ $return_data['list'][4]['val'] = bcadd($return_data['list'][4]['val'],$value['kcal_val'],2); @@ -529,7 +545,10 @@ class Countfood extends Base{ 'weight'=>$value['weight'].'克', 'id'=>$value['id'], 'pic_url'=>$value['pic_url'], - 'val'=>$value['kcal_val'].'kcal' + // 'val'=>$value['kcal_val'].'kcal', + 'val'=>$value['kcal_val'], + 'nutrients_four' => $value['nutrients_four'], + 'nutrients_list' => $value['nutrients_list'] ]); }else if($value['meals_type'] == '晚加餐'){ $return_data['list'][5]['val'] = bcadd($return_data['list'][5]['val'],$value['kcal_val'],2); @@ -538,7 +557,10 @@ class Countfood extends Base{ 'weight'=>$value['weight'].'克', 'id'=>$value['id'], 'pic_url'=>$value['pic_url'], - 'val'=>$value['kcal_val'].'kcal' + // 'val'=>$value['kcal_val'].'kcal', + 'val'=>$value['kcal_val'], + 'nutrients_four' => $value['nutrients_four'], + 'nutrients_list' => $value['nutrients_list'] ]); }else{ @@ -552,6 +574,7 @@ class Countfood extends Base{ } $return_data['list'] = array_values($return_data['list']); $return_data['remaining_kcal'] = bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2)>=0?bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2):0; + return $this->msg($return_data); } @@ -850,6 +873,110 @@ class Countfood extends Base{ 'e_time' => $endTime->format('Y-m-d H:i:s'), ]; } + // 计算营养物质 + public function calculate_nutrients($data){ + // dump($data); + $food_id_arr = []; + for ($i=0; $i < count($data); $i++) { + $food_id_arr[] = $data[$i]['food_id']; + } + + $cfc = Db::connect('cfc_db'); + $nutrients_list = $cfc->table($this->kitchenscale_db_msg['foodlist4']) + ->where("father_id in ('".implode("','",$food_id_arr)."')") + // ->field() + ->select(); + + $nutrients_arr = ['VitaminA','VitaminB1','VitaminB2','VitaminB6','VitaminB12','VitaminD','VitaminK','Niacin','VitaminC','VitaminE','FolicAcid','Biotin','PantothenicAcid','TotalCholine','Ca','Phosphorus','Kalium','Mg','Na','Fe','Zn','Se','Cu','Mn','Iodine']; + // dump($nutrients_list); + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + for ($i=0; $i < count($data); $i++) { + $data[$i]['nutrients_four'][] = [ + 'name' => '卡路里', + 'unit' => 'kcal', + 'color' => '', + 'value' => $data[$i]['kcal_val'], + 'proportion' => 0, + ]; + $data[$i]['nutrients_four'][] = [ + 'name' => '蛋白质', + 'unit' => 'g', + 'color' => '#5180D8', + 'value' => $data[$i]['protein_val'], + 'proportion' => bcmul(bcdiv($data[$i]['protein_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0), + ]; + $data[$i]['nutrients_four'][] = [ + 'name' => '脂肪', + 'unit' => 'g', + 'color' => '#ED7886', + 'value' => $data[$i]['fat_val'], + 'proportion' => bcmul(bcdiv($data[$i]['fat_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0), + ]; + $data[$i]['nutrients_four'][] = [ + 'name' => '碳水化合物', + 'unit' => 'g', + 'color' => '#FFB169', + 'value' => $data[$i]['carbohydrate_val'], + 'proportion' => bcmul(bcdiv($data[$i]['carbohydrate_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0), + ]; + $data[$i]['nutrients_list'][] = [ + 'name' => 'Calorie', + 'name_ch' => '卡路里', + 'unit' => 'kcal', + 'value' => $data[$i]['kcal_val'], + 'type' => 1, + 'type_name' => '能量及宏量营养素', + 'color' => '#C4FFE0', + ]; + $data[$i]['nutrients_list'][] = [ + 'name' => 'Protein', + 'name_ch' => '蛋白质', + 'unit' => 'g', + 'value' => $data[$i]['protein_val'], + 'type' => 1, + 'type_name' => '能量及宏量营养素', + 'color' => '#C4FFE0', + ]; + $data[$i]['nutrients_list'][] = [ + 'name' => 'Fat', + 'name_ch' => '脂肪', + 'unit' => 'g', + 'value' => $data[$i]['fat_val'], + 'type' => 1, + 'type_name' => '能量及宏量营养素', + 'color' => '#C4FFE0', + ]; + $data[$i]['nutrients_list'][] = [ + 'name' => 'Carbohydrate', + 'name_ch' => '碳水化合物', + 'unit' => 'g', + 'value' => $data[$i]['carbohydrate_val'], + 'type' => 1, + 'type_name' => '能量及宏量营养素', + 'color' => '#C4FFE0', + ]; + foreach ($nutrients_list as $key => $value) { + if($value['father_id'] == $data[$i]['food_id']){ + if(in_array($value['name'],$nutrients_arr)){ + $data[$i]['nutrients_list'][] = [ + 'name' => $value['name'], + 'name_ch' => $value['name_ch'], + 'unit' => $value['unit'], + 'value' => bcmul($value['value'],bcdiv($data[$i]['weight'],100,20),2), + 'type' => $value['type'], + 'type_name' => $value['type'] == 1?'能量及宏量营养素':($value['type'] == 2?'维生素':($value['type'] == 3?'矿物质':'')), + 'color' => $value['type'] == 1?'#C4FFE0':($value['type'] == 2?'#FFEFB7':($value['type'] == 3?'#7DA8E0':'')), + ]; + } + + } + } + } + return $data; + } diff --git a/application/ZengJieCode/controller/app/Savemsg.php b/application/ZengJieCode/controller/app/Savemsg.php index d1faac2..b7cea54 100644 --- a/application/ZengJieCode/controller/app/Savemsg.php +++ b/application/ZengJieCode/controller/app/Savemsg.php @@ -359,6 +359,8 @@ class Savemsg extends Base{ ######################################################测试######################################################### public function ceshiyong(){ + $data = input('post.'); + dump($data); // // 添加测试一维码数据 // $data = []; // for ($i = 0; $i < 500; $i++) { diff --git a/application/app/controller/Msginformation.php b/application/app/controller/Msginformation.php index b648df5..1196113 100644 --- a/application/app/controller/Msginformation.php +++ b/application/app/controller/Msginformation.php @@ -446,7 +446,7 @@ class Msginformation extends Base{ 'notice'=>[], 'banner'=>[] ]; - // return $this->msg($return_data); + return $this->msg($return_data); // 所有可用记录. $all_data = Db::table($this->msginformation_use_db_name['3'])->where("is_del = 0 AND scene_data IN (1,2,3)")->order('sort_num')->select(); // 用户阅读记录 diff --git a/application/code/controller/Qrcode.php b/application/code/controller/Qrcode.php index 1bdd423..9926901 100644 --- a/application/code/controller/Qrcode.php +++ b/application/code/controller/Qrcode.php @@ -135,7 +135,7 @@ class Qrcode extends Base{ $pathinfo_video = pathinfo($name_video); $extension_video = strtolower($pathinfo_video['extension']); // 转换为小写以进行不区分大小写的比较 $new_filename_video = 'pic_'.time().$this->generateRandomString(). '.' . $extension_video; - $info_video = $video->validate(['size'=>90*1024*1024,'ext'=>'mp4,avi,mkv,wmv'])->move(ROOT_PATH . 'public' . DS . 'teaching_video',$new_filename_video); + $info_video = $video->validate(['size'=>1024*1024*1024,'ext'=>'mp4,avi,mkv,wmv'])->move(ROOT_PATH . 'public' . DS . 'teaching_video',$new_filename_video); if(!$info_video){ // 上传失败获取错误信息 unlink(ROOT_PATH . 'public' . DS . 'teaching_video' . DS . $new_filename_pic); diff --git a/application/code/view/qrcode/little_tips_project_set_page.html b/application/code/view/qrcode/little_tips_project_set_page.html index 521dfc5..be954ed 100644 --- a/application/code/view/qrcode/little_tips_project_set_page.html +++ b/application/code/view/qrcode/little_tips_project_set_page.html @@ -211,7 +211,7 @@
设备图片:请不要上传超过10M的图片

图片预览:

-
设备视频:请不要上传超过90M的视频,大于90M的视频概率会导致提交失败

+
设备视频:请不要上传超过1G的视频,大于1G的视频概率会导致提交失败

视频名称:

设备分类: diff --git a/application/route.php b/application/route.php index ce7c8d5..6c17fd3 100644 --- a/application/route.php +++ b/application/route.php @@ -626,11 +626,30 @@ Route::any('/z/print_combined_code', 'app/ZengJieCode/admin.printaction/print_co ################################################################下面是设备入库录入################################################################ ################################################################################################################################################ // 默认配置 +Route::any('/de/login', 'app/DeviceEnter/Wechat/login'); +// 默认配置 Route::any('/de/config_msg', 'app/DeviceEnter/savemsg/config_msg'); // 存入设备信息 Route::any('/de/save_device_msg', 'app/DeviceEnter/savemsg/save_device_msg'); // 获取设备批次列表 Route::any('/de/device_batch_list', 'app/DeviceEnter/savemsg/device_batch_list'); +// 详细批次数据 +Route::any('/de/device_content_msg', 'app/DeviceEnter/savemsg/device_content_msg'); +// 详细批次数据 +Route::any('/de/ceshi', 'app/DeviceEnter/savemsg/ceshi'); +################################################################管理后台 +// 登录页 +Route::any('/de/admin/login', 'app/DeviceEnter/admin.login/login'); +Route::any('/de/admin/login_a', 'app/DeviceEnter/admin.login/login_action'); + +// 首页 +Route::any('/de/admin/index', 'app/DeviceEnter/admin.index/index'); +Route::any('/de/admin/welcome', 'app/DeviceEnter/admin.index/welcome'); + +// 设备管理 +Route::any('/de/admin/device/index', 'app/DeviceEnter/admin.device/index'); +Route::any('/de/admin/device/device_list', 'app/DeviceEnter/admin.device/device_list'); +Route::any('/de/admin/device/device_all', 'app/DeviceEnter/admin.device/device_all'); diff --git a/application/test/controller/Testuse.php b/application/test/controller/Testuse.php index 77df8f0..768521c 100644 --- a/application/test/controller/Testuse.php +++ b/application/test/controller/Testuse.php @@ -112,7 +112,37 @@ class Testuse extends Controller{ unset($data[$key]); } } - + $type_arr = [ + 'Calorie' => 1, + 'Protein' => 1, + 'Fat' => 1, + 'Carbohydrate' => 1, + 'VitaminA' => 2, + 'VitaminB1' => 2, + 'VitaminB2' => 2, + 'VitaminB6' => 2, + 'VitaminB12' => 2, + 'VitaminD' => 2, + 'VitaminK' => 2, + 'Niacin' => 2, + 'VitaminC' => 2, + 'VitaminE' => 2, + 'FolicAcid' => 2, + 'Biotin' => 2, + 'PantothenicAcid' => 2, + 'TotalCholine' => 2, + 'Ca' => 3, + 'Phosphorus' => 3, + 'Kalium' => 3, + 'Mg' => 3, + 'Na' => 3, + 'Fe' => 3, + 'Zn' => 3, + 'Se' => 3, + 'Cu' => 3, + 'Mn' => 3, + 'Iodine' => 3, + ]; foreach ($data as $key => $value) { $temporary_arr2 = []; foreach ($temporary_arr_title as $k => $v) { @@ -121,10 +151,12 @@ class Testuse extends Controller{ $temporary_arr2['name_ch'] = $temporary_arr2['desc']; unset($temporary_arr2['desc']); unset($temporary_arr2['description']); - + $temporary_arr2['type'] = $type_arr[$temporary_arr2['name']]; array_push($temporary_arr,$temporary_arr2); } + // dump($type_arr); // dump($temporary_arr); + // die; $cfc = Db::connect('cfc_db'); // 获取账号下信息以及用户信息 $user_data = $cfc->table('app_z_national_standard_food_type_4')->insertAll($temporary_arr);