251121修改
This commit is contained in:
parent
06211d0838
commit
89f38dfcc7
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale\controller\admin;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class Base extends Controller{
|
||||
|
||||
protected $base_use_db_name = [
|
||||
'1'=>'test_app_data_log',
|
||||
];
|
||||
protected $return_data_all = [
|
||||
'10001'=>'关键参数缺失',
|
||||
'10002'=>'操作失败',
|
||||
'10003'=>'信息核实错误',
|
||||
'10004'=>'未找到有效数据',
|
||||
'10005'=>'参数格式错误',
|
||||
'10006'=>'参数不能为空',
|
||||
'10007'=>'参数错误',
|
||||
'10008'=>'',
|
||||
'10009'=>'',
|
||||
'10010'=>'自定义信息',
|
||||
'20001'=>'登录失效',
|
||||
'99999'=>'网络异常,请稍后重试',
|
||||
];
|
||||
protected $file_max = 1024*1024*2;//xxxMB
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
|
||||
|
||||
// 验证
|
||||
public function verify_data_is_ok($data = 2,$type){
|
||||
if($type == 'str'){
|
||||
if (is_string($data)) {
|
||||
return true;
|
||||
} else {
|
||||
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]);
|
||||
return false;
|
||||
}
|
||||
}else if($type == 'num'){
|
||||
if (is_numeric($data)) {
|
||||
return true;
|
||||
} else {
|
||||
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]);
|
||||
return false;
|
||||
}
|
||||
}else if($type == 'intnum'){
|
||||
$pattern = '/^\d+$/';
|
||||
if (preg_match($pattern, $data)) {
|
||||
return true; // 匹配成功,返回 true
|
||||
} else {
|
||||
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]);
|
||||
return false; // 匹配失败,返回 false
|
||||
}
|
||||
}else if($type == 'datetime'){
|
||||
$formats = ['Y-m-d','Y-m-d H:i:s'];
|
||||
foreach ($formats as $format) {
|
||||
$dateTime = \DateTime::createFromFormat($format, $data);
|
||||
// 检查时间字符串是否成功解析,并且解析后的日期时间与原始字符串表示的时间一致
|
||||
if ($dateTime && $dateTime->format($format) === $data) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// 如果所有格式都解析失败,则返回 false
|
||||
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]);
|
||||
return false;
|
||||
}else if($type == 'other'){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
####################################################图片选择上传start##############################################################
|
||||
public function pic_index($page = 1) {
|
||||
$data = input();
|
||||
$pd = true;
|
||||
if(array_key_exists('page',$data)){
|
||||
$page = $data['page'];
|
||||
$pd = false;
|
||||
}
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$num = $cfc->table('app_user_upload_img')->where(['special_record_str'=>'admin'])->count();
|
||||
$result = $cfc->table('app_user_upload_img')->where(['special_record_str'=>'admin'])->order('id desc')->page($page,20)->field('id,pic_url')->select();
|
||||
if(!$pd){
|
||||
$return_result['num'] = $num;
|
||||
$return_result['result'] = $result;
|
||||
return $this->msg(0,'success',$return_result);
|
||||
}
|
||||
$this->assign([
|
||||
'result' => $result,
|
||||
'num' => $num,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
public function pic_upload_action(){
|
||||
|
||||
$save_data = [];
|
||||
$error_data = [];
|
||||
// 获取表单上传文件
|
||||
$files = request()->file('image');
|
||||
foreach($files as $file){
|
||||
$name = $file->getInfo()['name'];
|
||||
// 使用 pathinfo() 函数获取文件名的扩展名
|
||||
$pathinfo = pathinfo($name);
|
||||
$extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
|
||||
$file_name = $pathinfo['filename'];
|
||||
// 判断扩展名是否不是 .png 或 .gif
|
||||
if ($extension !== 'png' && $extension !== 'gif') {
|
||||
// 修改文件名,将扩展名改为 .jpg
|
||||
$new_filename = date('YmdHis').$file_name . '.jpg';
|
||||
} else {
|
||||
$new_filename = date('YmdHis').$name;
|
||||
}
|
||||
$info = $file->validate(['size'=>$this->file_max,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename);
|
||||
if($info){
|
||||
array_push($save_data,[
|
||||
'user_token'=>'caadd1be045a65f30b92aa805f1de54a',
|
||||
'pic_name'=>$new_filename,
|
||||
'pic_url'=>'https://tc.pcxbc.com/kitchenscale_all/user_upload/'.$new_filename,
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
'special_record_str'=>'admin',
|
||||
'operate_log'=>1
|
||||
]);
|
||||
}else{
|
||||
array_push($error_data,[
|
||||
'pic_name'=>$name,
|
||||
'error_msg'=>$file->getError(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$pic_result = $cfc->table('app_user_upload_img')->insertAll ($save_data);
|
||||
if($pic_result){
|
||||
return $this->msg(['success'=>count($save_data),'error_data'=>$error_data]);
|
||||
}else{
|
||||
for ($i=0; $i < count($save_data); $i++) {
|
||||
unlink(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload' . DS . $new_filename);
|
||||
}
|
||||
return $this->msg(10002,'图片数据保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
####################################################图片选择上传end##############################################################
|
||||
|
||||
|
||||
public function msg($data,$str='',$result = []){
|
||||
if(is_array($data)){
|
||||
if($str != ''){
|
||||
return json(['code'=>0,'msg'=>$str,'data'=>$data]);
|
||||
}else{
|
||||
return json(['code'=>0,'msg'=>'操作成功','data'=>$data]);
|
||||
}
|
||||
}else{
|
||||
if($str != ''){
|
||||
return json(['code'=>$data,'msg'=>$str,'data'=>$result]);
|
||||
}
|
||||
return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale\controller\admin;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class Cookbook extends Base{
|
||||
|
||||
// protected $login_hours_out = 24;
|
||||
|
||||
protected $page_num = 15;
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 登录
|
||||
public function index($page = 1){
|
||||
$data = input();
|
||||
$pd = true;
|
||||
$parameter = [];
|
||||
// $parameter['is_del'] = 0;
|
||||
if(array_key_exists('tt', $data)){
|
||||
$page = $data['page_num'];
|
||||
unset($data['page_num']);
|
||||
unset($data['tt']);
|
||||
$pd = false;
|
||||
// if($data['status_num'] === "0" || $data['status_num'] === "1"){
|
||||
// $parameter['is_del'] = $data['status_num'];
|
||||
// }
|
||||
|
||||
// if($data['tel']){
|
||||
// $parameter['tel'] = $data['tel'];
|
||||
// }
|
||||
// if($data['email']){
|
||||
// $parameter['email'] = $data['email'];
|
||||
// }
|
||||
// if($data['s_time']){
|
||||
// $parameter['create_time'] = ['>=',$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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale\controller\admin;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class Index extends Base{
|
||||
|
||||
// protected $login_hours_out = 24;
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 登录
|
||||
public function index(){
|
||||
// $this->assign('domain',$a);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function welcome(){
|
||||
// $this->assign('domain',$a);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale\controller\admin;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class Login extends Base{
|
||||
|
||||
// protected $login_hours_out = 24;
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 登录
|
||||
public function login(){
|
||||
return $this->fetch();
|
||||
|
||||
}
|
||||
// 检测登录信息是否超时
|
||||
public function login_action(){
|
||||
$data = input();
|
||||
// 验证数据项是否完整
|
||||
if(!array_key_exists('username', $data) || !array_key_exists('password', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
|
||||
class Aipart extends Base{
|
||||
|
||||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||||
protected $page_num = 10;
|
||||
protected $kitchenscale_db_msg = [
|
||||
'cookbook'=>'app_user_cookbook',//菜谱表
|
||||
'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
|
||||
'user'=>'app_user_data',//banner
|
||||
];
|
||||
|
||||
// 百度接口参数
|
||||
protected $baidu_api_key = "3WRiEJgo0P0Zz3bmV3V1kJsS";
|
||||
protected $baidu_secret_key = "yUNCE4QpuO8Ht7kmZm7IRFwr1kECCFv4";
|
||||
protected $baidu_accesstoken_expire_time = 432000;//5天
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
################################################################百度接口################################################################
|
||||
################################################################百度接口################################################################
|
||||
################################################################百度接口################################################################
|
||||
|
||||
|
||||
// 百度图片识别食材
|
||||
public function baidu_identify_food(){
|
||||
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!array_key_exists('img_str', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['img_str'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$result = $this->baidu_identify_food_action($data['img_str']);
|
||||
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'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
// dump($data);
|
||||
// die;
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 识别食材
|
||||
private function baidu_identify_food_action($img_str){
|
||||
// dump($str);
|
||||
$access_token = $this->baidu_get_accesstoken();
|
||||
if($access_token == false){
|
||||
return $this->msg(10002,'识别失败01');
|
||||
}
|
||||
// dump($access_token);
|
||||
// die;
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => "https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient?access_token=".$access_token,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS => http_build_query(array(
|
||||
'image' => $img_str,
|
||||
'top_num'=>10
|
||||
)),
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
'Accept: application/json'
|
||||
),
|
||||
));
|
||||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
$result = json_decode($response,true);
|
||||
if(array_key_exists('result',$result)){
|
||||
// return ['code'=>0,'data'=>$result['result']];
|
||||
return $this->msg(['name'=>$result['result'][0]['name']]);
|
||||
}else{
|
||||
return $this->msg(10002,'识别失败02');
|
||||
}
|
||||
}
|
||||
|
||||
// 获取AccessToken
|
||||
private function baidu_get_accesstoken(){
|
||||
$baidu_cache = cache('baidu_accesstoken');
|
||||
if($baidu_cache != false){
|
||||
// dump($baidu_cache);
|
||||
// die;
|
||||
return $baidu_cache;
|
||||
}
|
||||
$baidu_cache = cache('baidu_accesstoken');
|
||||
$curl = curl_init();
|
||||
$postData = array(
|
||||
'grant_type' => 'client_credentials',
|
||||
'client_id' => $this->baidu_api_key,
|
||||
'client_secret' => $this->baidu_secret_key
|
||||
);
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => 'https://aip.baidubce.com/oauth/2.0/token',
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POSTFIELDS => http_build_query($postData)
|
||||
));
|
||||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
$rtn = json_decode($response,true);
|
||||
// dump($rtn);
|
||||
if(array_key_exists('access_token',$rtn)){
|
||||
cache('baidu_accesstoken', $rtn['access_token'], ($rtn['expires_in']-$this->baidu_accesstoken_expire_time));
|
||||
return $rtn['access_token'];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,561 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class Base extends Controller{
|
||||
|
||||
protected $base_use_db_name = [
|
||||
'6'=>'app_account_number',
|
||||
'search_history'=>'app_user_search_history',
|
||||
'foodlist4'=>'app_z_national_standard_food_type_4'
|
||||
];
|
||||
protected $token_time = 30;//30天的秒数
|
||||
protected $file_size = 5*1024*1024;
|
||||
protected $return_data_all = [
|
||||
'10001'=>'关键参数缺失',
|
||||
'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';
|
||||
}
|
||||
}
|
||||
|
||||
################################################################通用工具################################################################
|
||||
################################################################通用工具################################################################
|
||||
################################################################通用工具################################################################
|
||||
// 判断token是否过期
|
||||
public function token_time_validate($token){
|
||||
// 591b70e0d80b5fa6d77e6e1384453ab9
|
||||
if(is_string($token)){
|
||||
$length = strlen($token);
|
||||
if ($length < 10 ) {
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,字符串长度小于10', 'token_log');
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log');
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->field('id,login_time')->find();
|
||||
if(!$user_login){
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建 DateTime 对象来表示指定的日期和时间
|
||||
$specifiedDateTime = new \DateTime($user_login['login_time']);
|
||||
|
||||
// 获取当前时间的 DateTime 对象
|
||||
$currentDateTime = new \DateTime();
|
||||
|
||||
// 计算两个日期之间的差异(以秒为单位)
|
||||
$interval = $currentDateTime->diff($specifiedDateTime);
|
||||
|
||||
// 将差异转换为天数(注意:这里的天数可能不是整数,因为差异可能包括小时、分钟等)
|
||||
$daysDifference = $interval->days;
|
||||
|
||||
// 如果需要更精确的计算(包括小时、分钟等转换成的天数),可以使用以下方式:
|
||||
// $totalSecondsDifference = $interval->format('%a') * 86400 + $interval->format('%h') * 3600 + $interval->format('%i') * 60 + $interval->format('%s');
|
||||
// $daysDifference = floor($totalSecondsDifference / 86400); // 将总秒数转换为天数并取整
|
||||
|
||||
// 判断差异是否超过指定的天数
|
||||
if ($daysDifference > $this->token_time) {
|
||||
// echo "超过 {$specifiedDays} 天";
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token,或该token已经超过30天', 'token_log');
|
||||
return false;
|
||||
} else {
|
||||
// echo "未超过 {$specifiedDays} 天";
|
||||
$user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
if($user_login){
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log');
|
||||
return true;
|
||||
}else{
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,数据库更新时间未成功', 'token_log');
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// 验证数据类型
|
||||
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 calculate_age($data = '1991-04-20'){
|
||||
$today = time(); // 获取当前时间的 Unix 时间戳
|
||||
$birthDate = strtotime($data); // 将出生日期字符串转换为 Unix 时间戳
|
||||
if ($birthDate !== false) {
|
||||
$age = date('Y', $today) - date('Y', $birthDate);
|
||||
// 如果当前年份的月份和日期小于出生年份的月份和日期,那么年龄减一
|
||||
if (date('m-d', $today) < date('m-d', $birthDate)) {
|
||||
$age--;
|
||||
}
|
||||
return $age;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 计算常规卡路里
|
||||
public function count_user_nutrition_all($data){
|
||||
// 计算基础代谢率(BMR)
|
||||
if($data['gender'] == 1){
|
||||
// 男性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) + 5
|
||||
$bmr = bcmul(10,$data['weight'],20);
|
||||
$bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20);
|
||||
$bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20);
|
||||
$bmr = bcadd($bmr,5,2);
|
||||
}else if($data['gender'] == 2){
|
||||
// 女性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) - 161
|
||||
$bmr = bcmul(10,$data['weight'],20);
|
||||
$bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20);
|
||||
$bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20);
|
||||
$bmr = bcsub($bmr,161,2);
|
||||
}else{
|
||||
return $this->msg(10003,'性别未知');
|
||||
}
|
||||
|
||||
// 每日总能量消耗(TDEE)
|
||||
// 久坐(很少或没有运动):BMR × 1.2
|
||||
// 轻度活动(每周1-3天轻度运动):BMR × 1.375
|
||||
// 中度活动(每周3-5天中度运动):BMR × 1.55
|
||||
// 高度活动(每周6-7天高强度运动):BMR × 1.725
|
||||
// 极高活动(体力劳动或每天高强度训练):BMR × 1.9
|
||||
$tdee = bcmul($bmr,1.55,2);
|
||||
|
||||
// 碳水化合物:通常占总热量的45-65%
|
||||
// 蛋白质:通常占总热量的10-35%
|
||||
// 脂肪:通常占总热量的20-35%
|
||||
// 孩子&成年人:碳水化合物50%,蛋白质20%,脂肪30%。
|
||||
// 老人:碳水化合物50%,蛋白质25%,脂肪25%。
|
||||
// 建议每日摄入量计算:
|
||||
// 1.碳水化合物(克): (TDEE × 碳水化合物比例) / 4
|
||||
// 2.蛋白质(克):(TDEE × 蛋白质比例) / 4
|
||||
// 3.脂肪(克): (TDEE × 脂肪比例) / 9
|
||||
$carbohydrate = bcdiv(bcmul($tdee,0.5,20),4,2);
|
||||
if($data['age_num'] < 65){
|
||||
$protein = bcdiv(bcmul($tdee,0.2,20),4,2);
|
||||
$fat = bcdiv(bcmul($tdee,0.3,20),9,2);
|
||||
}else{
|
||||
$protein = bcdiv(bcmul($tdee,0.25,20),4,2);
|
||||
$fat =bcdiv(bcmul($tdee,0.25,20),9,2);
|
||||
}
|
||||
return ['kcal'=>$tdee,'carbohydrate'=>$carbohydrate,'protein'=>$protein,'fat'=>$fat,'bmr'=>$bmr];
|
||||
}
|
||||
|
||||
// 计算营养物质
|
||||
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->base_use_db_name['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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function add_search_history_action($data){
|
||||
// 添加一条搜索记录start
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$insert_search_log = $cfc->table($this->base_use_db_name['search_history'])->where(['user_id'=>$data['id'],'keyword'=>$data['search_data'],'type'=>$data['type']])->field('id,search_count')->find();
|
||||
if($insert_search_log){
|
||||
$cfc->table($this->base_use_db_name['search_history'])->where(['id'=>$insert_search_log['id']])->update([
|
||||
'search_count'=>$insert_search_log['search_count']+1,
|
||||
'last_searched_at'=>date('Y-m-d H:i:s'),
|
||||
]);
|
||||
}else{
|
||||
$cfc->table($this->base_use_db_name['search_history'])->insert([
|
||||
'user_id'=>$data['id'],
|
||||
'keyword'=>$data['search_data'],
|
||||
'type'=>$data['type'],
|
||||
]);
|
||||
}
|
||||
// 添加一条搜索记录end
|
||||
}
|
||||
####################################################图片选择上传start##############################################################
|
||||
####################################################图片选择上传start##############################################################
|
||||
####################################################图片选择上传start##############################################################
|
||||
public function pic_chose_list($page = 1) {
|
||||
$data = input();
|
||||
$page_num = 20;
|
||||
if(!array_key_exists('token',$data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(array_key_exists('page',$data)){
|
||||
$page = $data['page'];
|
||||
}
|
||||
$parameter_data = [
|
||||
'user_token'=>$data['token'],
|
||||
'is_del'=>0
|
||||
];
|
||||
|
||||
$cfc = Db::connect('cfc_db');
|
||||
|
||||
$num = $cfc->table('app_user_upload_img')->where($parameter_data)->count();
|
||||
$result = $cfc->table('app_user_upload_img')->where($parameter_data)->order('id desc')->page($page,$page_num)->field('id,pic_name,pic_url')->select();
|
||||
$return_result['page_total'] = $page_total = ceil($num/$page_num);
|
||||
$return_result['page_now'] = $page;
|
||||
$return_result['result'] = $result;
|
||||
return $this->msg($return_result);
|
||||
}
|
||||
public function pic_upload_one_action(){
|
||||
$temporary_data = [];
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$file = request()->file('image');
|
||||
$token = request()->param('token');
|
||||
if(!$token){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if($file){
|
||||
$name = $file->getInfo()['name'];
|
||||
// 使用 pathinfo() 函数获取文件名的扩展名
|
||||
$pathinfo = pathinfo($name);
|
||||
$extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
|
||||
$new_filename = time().$this->generateRandomString(). '.' . $extension;
|
||||
$info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename);
|
||||
if($info){
|
||||
$temporary_data = [
|
||||
'user_token'=>$token,
|
||||
'pic_name'=>$new_filename,
|
||||
'pic_url'=>"https://tc.pcxbc.com/kitchenscale_all/user_upload/".$new_filename,
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
];
|
||||
$pic_id = $cfc->table('app_user_upload_img')->insertGetId($temporary_data);
|
||||
if($pic_id){
|
||||
$temporary_data['id'] = $pic_id;
|
||||
unset($temporary_data['create_time']);
|
||||
unset($temporary_data['user_token']);
|
||||
return $this->msg($temporary_data);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}else{
|
||||
// 上传失败获取错误信息
|
||||
return $this->msg(10010,$file->getError());
|
||||
}
|
||||
}else{
|
||||
return $this->msg(10001,'未选择图片');
|
||||
}
|
||||
}
|
||||
public function pic_upload_action(){
|
||||
$insert_data = [];
|
||||
$temporary_data = [];
|
||||
$miss_data = 0;
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$files = request()->file('images');
|
||||
$token = request()->param('token');
|
||||
if(!$token){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if($files){
|
||||
if(count($files)>5){
|
||||
return $this->msg(10001,'单次最多上传5张图片');
|
||||
}
|
||||
foreach($files as $file){
|
||||
$name = $file->getInfo()['name'];
|
||||
// 使用 pathinfo() 函数获取文件名的扩展名
|
||||
$pathinfo = pathinfo($name);
|
||||
$extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
|
||||
$file_name = $pathinfo['filename'];
|
||||
// 判断扩展名是否不是 .png 或 .gif
|
||||
if ($extension !== 'png' && $extension !== 'gif') {
|
||||
// 修改文件名,将扩展名改为 .jpg
|
||||
$new_filename = time().$this->generateRandomString(). '.jpg';
|
||||
} else {
|
||||
$new_filename = time().$this->generateRandomString(). '.' . $extension;
|
||||
}
|
||||
$info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename);
|
||||
if($info){
|
||||
$temporary_data = [
|
||||
'user_token'=>$token,
|
||||
'pic_name'=>$new_filename,
|
||||
'pic_url'=>"https://tc.pcxbc.com/kitchenscale_all/user_upload/".$new_filename,
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
];
|
||||
$pic_id = $cfc->table('app_user_upload_img')->insertGetId($temporary_data);
|
||||
if($pic_id){
|
||||
$temporary_data['id'] = $pic_id;
|
||||
unset($temporary_data['create_time']);
|
||||
unset($temporary_data['user_token']);
|
||||
array_push($insert_data,$temporary_data);
|
||||
}else{
|
||||
$miss_data = $miss_data+1;
|
||||
}
|
||||
}else{
|
||||
$miss_data = $miss_data+1;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->msg(['error_num'=>$miss_data,'insert_data'=>$insert_data]);
|
||||
|
||||
}else{
|
||||
return $this->msg(10001,'未选择图片');
|
||||
}
|
||||
}
|
||||
####################################################图片选择上传end##############################################################
|
||||
####################################################图片选择上传end##############################################################
|
||||
####################################################图片选择上传end##############################################################
|
||||
|
||||
|
||||
########################################################其他工具########################################################
|
||||
########################################################其他工具########################################################
|
||||
########################################################其他工具########################################################
|
||||
public function msg($data,$str='',$result = []){
|
||||
if(is_array($data)){
|
||||
if($str != ''){
|
||||
return json(['code'=>0,'msg'=>$str,'data'=>$data]);
|
||||
}else{
|
||||
return json(['code'=>0,'msg'=>'操作成功','data'=>$data]);
|
||||
}
|
||||
}else{
|
||||
if($str != ''){
|
||||
return json(['code'=>$data,'msg'=>$str,'data'=>$result]);
|
||||
}
|
||||
return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]);
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,418 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use think\Controller;
|
||||
|
||||
class Guessyoulike extends Controller {
|
||||
|
||||
protected $kitchenscale_db_msg = [
|
||||
'cookbook' => 'app_user_cookbook', //食谱表
|
||||
'cookbook_label' => 'app_user_cookbook_label', //食谱标签表
|
||||
'cookbook_food_relation' => 'app_user_cookbook_food_relation', //食谱跟食材关系表
|
||||
'foodlist2' => 'app_z_national_standard_food_type_2', //食材标签表2
|
||||
'foodlist3' => 'app_z_national_standard_food_type_3', //食材表
|
||||
'kcal_log' => 'app_user_kcal_log', //用户饮食记录表记录用户吃了什么食材
|
||||
'search_history' => 'app_user_search_history', //用户搜索记录表,记录用户搜索过什么内容
|
||||
'tag_preference' => 'app_user_tag_preference', //用户标签偏好表
|
||||
'recommend_cache' => 'app_recommend_cache' //智能推荐缓存表
|
||||
];
|
||||
|
||||
protected $config = [
|
||||
'tag_limit' => 2,
|
||||
'item_limit' => 12,
|
||||
'cache_time' => 3600
|
||||
];
|
||||
|
||||
/**
|
||||
* 猜你喜欢主接口
|
||||
*/
|
||||
public function getGuessYouLike($user_id = 1, $type = 'food', $limit = null) {
|
||||
try {
|
||||
$cfc = Db::connect('cfc_db');
|
||||
// dump(1);
|
||||
// 设置限制数量
|
||||
$tag_limit = $limit ? intval($limit) : $this->config['tag_limit'];
|
||||
$item_limit = $this->config['item_limit'];
|
||||
|
||||
// 检查缓存
|
||||
// $cache_key = $user_id . ':' . $type;
|
||||
// $cache_result = $this->getCache($cfc, $cache_key);
|
||||
// // die;
|
||||
// if ($cache_result !== null) {
|
||||
// return $cache_result;
|
||||
// }
|
||||
|
||||
// 判断用户是否有历史数据
|
||||
$has_history = $this->checkUserHistory($cfc, $user_id);
|
||||
if (!$has_history) {
|
||||
// 新用户,返回最火信息(仅一个标签)
|
||||
$result = $this->getPopularRecommendations($cfc, $type, 1, $item_limit);
|
||||
} else {
|
||||
// 老用户,根据类型返回个性化推荐
|
||||
if ($type === 'cookbook') {
|
||||
$result = $this->getCookbookRecommendations($cfc, $user_id, $tag_limit, $item_limit);
|
||||
|
||||
} else {
|
||||
$result = $this->getFoodRecommendations($cfc, $user_id, $tag_limit, $item_limit);
|
||||
}
|
||||
}
|
||||
|
||||
// 确保返回格式正确
|
||||
if (!is_array($result)) {
|
||||
$result = [];
|
||||
}
|
||||
|
||||
// 更新缓存
|
||||
// $this->updateCache($cfc, $cache_key, $user_id, $type, $result);
|
||||
|
||||
return $result;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误日志
|
||||
\think\Log::error('猜你喜欢功能错误: ' . $e->getMessage());
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否有历史数据
|
||||
*/
|
||||
private function checkUserHistory($db, $user_id) {
|
||||
try {
|
||||
// 检查饮食记录
|
||||
$kcal_result = $db->query("
|
||||
SELECT COUNT(*) as count
|
||||
FROM {$this->kitchenscale_db_msg['kcal_log']}
|
||||
WHERE aud_id = ? AND is_del = 0
|
||||
", [$user_id]);
|
||||
$kcal_count = $kcal_result[0]['count'] ?? 0;
|
||||
|
||||
// 检查搜索记录
|
||||
$search_result = $db->query("
|
||||
SELECT COUNT(*) as count
|
||||
FROM {$this->kitchenscale_db_msg['search_history']}
|
||||
WHERE user_id = ? AND is_del = 0
|
||||
", [$user_id]);
|
||||
$search_count = $search_result[0]['count'] ?? 0;
|
||||
|
||||
return ($kcal_count > 0 || $search_count > 0);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存数据
|
||||
*/
|
||||
private function getCache($db, $cache_key) {
|
||||
try {
|
||||
$cache_result = $db->query("
|
||||
SELECT id, cache_key, user_id, keyword, recommend_data, hit_count, last_hit, is_del, create_time
|
||||
FROM {$this->kitchenscale_db_msg['recommend_cache']}
|
||||
WHERE cache_key = ? AND is_del = 0
|
||||
", [$cache_key]);
|
||||
|
||||
if (!empty($cache_result)) {
|
||||
$cache = $cache_result[0];
|
||||
$last_hit_timestamp = strtotime($cache['last_hit']);
|
||||
|
||||
if (time() - $last_hit_timestamp < $this->config['cache_time']) {
|
||||
// 更新命中次数和时间
|
||||
$db->execute("
|
||||
UPDATE {$this->kitchenscale_db_msg['recommend_cache']}
|
||||
SET hit_count = hit_count + 1, last_hit = GETDATE()
|
||||
WHERE id = ?
|
||||
", [$cache['id']]);
|
||||
|
||||
$data = json_decode($cache['recommend_data'], true);
|
||||
return is_array($data) ? $data : null;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 忽略缓存错误,继续执行
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新缓存
|
||||
*/
|
||||
private function updateCache($db, $cache_key, $user_id, $keyword, $data) {
|
||||
try {
|
||||
$current_time = date('Y-m-d H:i:s');
|
||||
$recommend_data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// 检查是否存在缓存
|
||||
$existing_result = $db->query("
|
||||
SELECT id FROM {$this->kitchenscale_db_msg['recommend_cache']}
|
||||
WHERE cache_key = ? AND is_del = 0
|
||||
", [$cache_key]);
|
||||
|
||||
if (!empty($existing_result)) {
|
||||
// 更新现有缓存
|
||||
$db->execute("
|
||||
UPDATE {$this->kitchenscale_db_msg['recommend_cache']}
|
||||
SET user_id = ?, keyword = ?, recommend_data = ?, hit_count = 1,
|
||||
last_hit = ?, create_time = ?
|
||||
WHERE cache_key = ? AND is_del = 0
|
||||
", [$user_id, $keyword, $recommend_data, $current_time, $current_time, $cache_key]);
|
||||
} else {
|
||||
// 插入新缓存
|
||||
$db->execute("
|
||||
INSERT INTO {$this->kitchenscale_db_msg['recommend_cache']}
|
||||
(cache_key, user_id, keyword, recommend_data, hit_count, last_hit, create_time, is_del)
|
||||
VALUES (?, ?, ?, ?, 1, ?, ?, 0)
|
||||
", [$cache_key, $user_id, $keyword, $recommend_data, $current_time, $current_time]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 忽略缓存更新错误
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门推荐(新用户)
|
||||
*/
|
||||
private function getPopularRecommendations($db, $type, $tag_limit, $item_limit) {
|
||||
// dump($type);
|
||||
if ($type === 'cookbook') {
|
||||
return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
|
||||
} else {
|
||||
// dump(111);
|
||||
return $this->getPopularFoods($db, $tag_limit, $item_limit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门食谱(新用户)
|
||||
*/
|
||||
private function getPopularCookbooks($db, $tag_limit, $item_limit) {
|
||||
try {
|
||||
// 简化查询,避免复杂关联导致的错误
|
||||
$popular_cookbooks = $db->query("
|
||||
SELECT TOP {$item_limit}
|
||||
id,
|
||||
title as name
|
||||
FROM {$this->kitchenscale_db_msg['cookbook']}
|
||||
WHERE is_del = 0
|
||||
ORDER BY likes_num DESC, read_it DESC, create_time DESC
|
||||
");
|
||||
// dump('sp');
|
||||
// dump($popular_cookbooks);
|
||||
$result = [];
|
||||
$label_data = [];
|
||||
|
||||
foreach ($popular_cookbooks as $cookbook) {
|
||||
$label_data[] = [
|
||||
'name' => $cookbook['name'] ?? '未知食谱',
|
||||
'id' => $cookbook['id'] ?? 0,
|
||||
'type' => 'cookbook'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($label_data)) {
|
||||
$result['最火食谱搜索'] = $label_data;
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门食材(新用户)
|
||||
*/
|
||||
private function getPopularFoods($db, $tag_limit, $item_limit) {
|
||||
try {
|
||||
// dump(2222);
|
||||
// // 简化查询,避免复杂关联导致的错误
|
||||
$popular_foods = $db->query("
|
||||
SELECT TOP {$item_limit}
|
||||
id,
|
||||
keyword as name,
|
||||
COUNT(*) as num
|
||||
FROM {$this->kitchenscale_db_msg['search_history']}
|
||||
WHERE is_del = 0 AND type = 'food'
|
||||
GROUP BY id, keyword
|
||||
ORDER BY num DESC
|
||||
");
|
||||
// dump('sc');
|
||||
// dump($popular_foods);
|
||||
|
||||
$popular_foods_2 = [];
|
||||
if(count($popular_foods) < $item_limit){
|
||||
$num = $item_limit - count($popular_foods);
|
||||
$popular_foods_2 = $db->query("
|
||||
SELECT TOP {$num}
|
||||
id,
|
||||
food_name as name
|
||||
FROM {$this->kitchenscale_db_msg['foodlist3']}
|
||||
WHERE is_del = 0
|
||||
ORDER BY is_popular DESC, food_name ASC
|
||||
");
|
||||
}
|
||||
|
||||
foreach ($popular_foods_2 as $key => $value) {
|
||||
$popular_foods[] = $value;
|
||||
}
|
||||
|
||||
|
||||
$result = [];
|
||||
$label_data = [];
|
||||
|
||||
foreach ($popular_foods as $food) {
|
||||
$label_data[] = [
|
||||
'name' => $food['name'] ?? '未知食材',
|
||||
'id' => $food['id'] ?? 0,
|
||||
'type' => 'food'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($label_data)) {
|
||||
$result['最火食材搜索'] = $label_data;
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个性化食谱推荐(老用户)
|
||||
*/
|
||||
private function getCookbookRecommendations($db, $user_id, $tag_limit, $item_limit) {
|
||||
try {
|
||||
// 获取用户最常吃的食材
|
||||
$user_top_foods = $db->query("
|
||||
SELECT TOP 10 food_id, COUNT(*) as eat_count
|
||||
FROM {$this->kitchenscale_db_msg['kcal_log']}
|
||||
WHERE aud_id = ? AND is_del = 0
|
||||
GROUP BY food_id
|
||||
ORDER BY eat_count DESC
|
||||
", [$user_id]);
|
||||
|
||||
if (empty($user_top_foods)) {
|
||||
return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
|
||||
}
|
||||
|
||||
$food_ids = array_column($user_top_foods, 'food_id');
|
||||
if (empty($food_ids)) {
|
||||
return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
|
||||
}
|
||||
$food_ids_str = implode(',', $food_ids);
|
||||
|
||||
// 获取包含这些食材的食谱标签
|
||||
$preferred_labels = $db->query("
|
||||
SELECT TOP {$tag_limit} lbl.id, lbl.name, COUNT(DISTINCT cb.id) as match_count
|
||||
FROM {$this->kitchenscale_db_msg['cookbook_label']} lbl
|
||||
INNER JOIN {$this->kitchenscale_db_msg['cookbook']} cb ON lbl.id = cb.cook_label AND cb.is_del = 0
|
||||
INNER JOIN {$this->kitchenscale_db_msg['cookbook_food_relation']} cfr ON cb.id = cfr.cookbook_id
|
||||
WHERE lbl.is_del = 0 AND cfr.food_id IN ({$food_ids_str})
|
||||
GROUP BY lbl.id, lbl.name
|
||||
ORDER BY match_count DESC
|
||||
");
|
||||
|
||||
$result = [];
|
||||
foreach ($preferred_labels as $label) {
|
||||
// 使用子查询避免GROUP BY复杂性问题
|
||||
$cookbooks = $db->query("
|
||||
SELECT TOP {$item_limit} cb.id, cb.title as name
|
||||
FROM {$this->kitchenscale_db_msg['cookbook']} cb
|
||||
WHERE cb.id IN (
|
||||
SELECT DISTINCT cfr.cookbook_id
|
||||
FROM {$this->kitchenscale_db_msg['cookbook_food_relation']} cfr
|
||||
WHERE cfr.food_id IN ({$food_ids_str})
|
||||
)
|
||||
AND cb.cook_label = ?
|
||||
AND cb.is_del = 0
|
||||
ORDER BY cb.likes_num DESC, cb.read_it DESC
|
||||
", [$label['id']]);
|
||||
|
||||
$label_data = [];
|
||||
foreach ($cookbooks as $cookbook) {
|
||||
$label_data[] = [
|
||||
'name' => $cookbook['name'] ?? '未知食谱',
|
||||
'id' => $cookbook['id'] ?? 0,
|
||||
'type' => 'cookbook'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($label_data)) {
|
||||
$result[$label['name'] ?? '未知标签'] = $label_data;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个性化食材推荐(老用户)
|
||||
*/
|
||||
private function getFoodRecommendations($db, $user_id, $tag_limit, $item_limit) {
|
||||
try {
|
||||
// 获取用户最常吃的食材
|
||||
$user_top_foods = $db->query("
|
||||
SELECT TOP 10 food_id, COUNT(*) as eat_count
|
||||
FROM {$this->kitchenscale_db_msg['kcal_log']}
|
||||
WHERE aud_id = ? AND is_del = 0
|
||||
GROUP BY food_id
|
||||
ORDER BY eat_count DESC
|
||||
", [$user_id]);
|
||||
|
||||
if (empty($user_top_foods)) {
|
||||
return $this->getPopularFoods($db, $tag_limit, $item_limit);
|
||||
}
|
||||
|
||||
$food_ids = array_column($user_top_foods, 'food_id');
|
||||
if (empty($food_ids)) {
|
||||
return $this->getPopularFoods($db, $tag_limit, $item_limit);
|
||||
}
|
||||
$food_ids_str = implode(',', $food_ids);
|
||||
|
||||
// 获取用户偏好食材的分类
|
||||
$preferred_categories = $db->query("
|
||||
SELECT TOP {$tag_limit} f2.id, f2.name, COUNT(DISTINCT f3.id) as food_count
|
||||
FROM {$this->kitchenscale_db_msg['foodlist2']} f2
|
||||
INNER JOIN {$this->kitchenscale_db_msg['foodlist3']} f3 ON f2.id = f3.two_id
|
||||
WHERE f3.id IN ({$food_ids_str}) AND f2.is_del = 0 AND f3.is_del = 0
|
||||
GROUP BY f2.id, f2.name
|
||||
ORDER BY food_count DESC
|
||||
");
|
||||
|
||||
$result = [];
|
||||
foreach ($preferred_categories as $category) {
|
||||
// 获取该分类下的其他食材
|
||||
$foods = $db->query("
|
||||
SELECT TOP {$item_limit} id, food_name as name
|
||||
FROM {$this->kitchenscale_db_msg['foodlist3']}
|
||||
WHERE two_id = ? AND is_del = 0 AND id NOT IN ({$food_ids_str})
|
||||
ORDER BY is_popular DESC, food_name ASC
|
||||
", [$category['id']]);
|
||||
|
||||
$category_data = [];
|
||||
foreach ($foods as $food) {
|
||||
$category_data[] = [
|
||||
'name' => $food['name'] ?? '未知食材',
|
||||
'id' => $food['id'] ?? 0,
|
||||
'type' => 'food'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($category_data)) {
|
||||
$result[$category['name'] ?? '未知分类'] = $category_data;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
return $this->getPopularFoods($db, $tag_limit, $item_limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,890 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use app\KitchenScale2\controller\app\Guessyoulike;// 引入Wechat服务类
|
||||
|
||||
class Index extends Base{
|
||||
|
||||
protected $code_time = 50;
|
||||
// protected $token_time = 2592000;//30天的秒数
|
||||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||||
protected $reedaw_db_msg = [
|
||||
'zhanghao'=>'app_account_number',//账号表
|
||||
'juese'=>'app_user_data',//角色表
|
||||
];
|
||||
protected $kitchenscale_db_msg = [
|
||||
'cookbook'=>'app_user_cookbook',//菜谱表
|
||||
'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
|
||||
'uploadimg'=>'app_user_upload_img',//图片素材表
|
||||
'foodlist1'=>'app_z_national_standard_food_type_1',//食材列表1
|
||||
'foodlist2'=>'app_z_national_standard_food_type_2',//食材列表2
|
||||
'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
|
||||
'foodlist4'=>'app_z_national_standard_food_type_4',//食材列表3
|
||||
'collect_list'=>'app_user_collect_list',//点赞表
|
||||
'banner'=>'app_banner_data',//banner
|
||||
'version'=>'app_version_log',//版本表
|
||||
'user'=>'app_user_data',//用户表
|
||||
'kcal_log'=>'app_user_kcal_log',//饮食记录表
|
||||
'search_history'=>'app_user_search_history',//搜索历史表
|
||||
'business_cooperation'=>'app_business_cooperation',//搜索历史表
|
||||
|
||||
];
|
||||
|
||||
protected $reedaw_db_name = [
|
||||
'banner'=>'admin_notice_banner',//菜谱表
|
||||
|
||||
];
|
||||
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 检测版本及判断是否登录失效
|
||||
public function login_invalid_version($data = ['token'=>'']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
// if(!array_key_exists('token', $data)){
|
||||
// return $this->msg(10001);
|
||||
// }
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['version'])->order('is_del,id desc')->find();
|
||||
if($result){
|
||||
$version = $result['version_num_original'];
|
||||
$url = $result['download_url'];
|
||||
}else{
|
||||
$version = '';
|
||||
$url = '';
|
||||
}
|
||||
|
||||
if($this->token_time_validate($data['token']) === false){
|
||||
$this->record_api_log($data, null, ['code'=>-1,'msg'=>'未登录',['version'=>$version,'url'=>$url]]);
|
||||
return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url]);
|
||||
}else{
|
||||
$this->record_api_log($data, null, ['code'=>0,'msg'=>'success',['version'=>$version,'url'=>$url]]);
|
||||
return $this->msg(['version'=>$version,'url'=>$url]);
|
||||
}
|
||||
|
||||
} 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 wechat_quick_login($data = ['code'=>'asdasdasd','encryptedData'=>'adsadasdasd','iv'=>'asdasdasdasd']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('code', $data)){
|
||||
// return $this->msg(10001,'');
|
||||
return $this->msg(10001,'code is miss');
|
||||
}
|
||||
if(!array_key_exists('encryptedData', $data)){
|
||||
return $this->msg(10001,'encryptedData is miss');
|
||||
}
|
||||
if(!array_key_exists('iv', $data)){
|
||||
return $this->msg(10001,'iv is miss');
|
||||
}
|
||||
// 校验参数
|
||||
if (empty($data['code'])) {
|
||||
return $this->msg(10001,'code is miss.');
|
||||
}
|
||||
if (empty($data['encryptedData'])) {
|
||||
return $this->msg(10001,'encryptedData is miss.');
|
||||
}
|
||||
if (empty($data['iv'])) {
|
||||
return $this->msg(10001,'iv is miss.');
|
||||
}
|
||||
|
||||
// 调用Wechat服务类处理微信登录逻辑
|
||||
$wechatService = new Wechat();
|
||||
// die;
|
||||
$result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']);
|
||||
// dump($result);
|
||||
// die;
|
||||
if($result['code'] == 0){
|
||||
// return $this->msg($result['code'],$result['msg']);
|
||||
|
||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['tel'=>$result['data']['phoneNumber'],'is_del'=>0])->find();
|
||||
|
||||
if($user_data){
|
||||
Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$user_data['token']])->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
$return_data = $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
|
||||
}else{
|
||||
$set_data['password'] = '';
|
||||
$set_data['tel'] = $result['data']['phoneNumber'];
|
||||
$set_data['head_pic'] = $this->default_head_pic;
|
||||
$set_data['nickname'] = '用户'.$result['data']['phoneNumber'];
|
||||
$set_data['create_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['login_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['token'] = md5($result['data']['phoneNumber'].$this->create_random_string(12).time());
|
||||
$set_user_result = Db::table($this->reedaw_db_msg['zhanghao'])->insertGetId($set_data);
|
||||
if($set_user_result){
|
||||
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$set_user_result],'登录成功');
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
}
|
||||
return $return_data;
|
||||
}else{
|
||||
return $this->msg($result['code'],$result['msg']);
|
||||
}
|
||||
|
||||
} 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'] .= "方法: (wechat_quick_login)" . "\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);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取默认配置信息(包含:食材的分类列表,用户角色信息)(OK)
|
||||
public function get_default_config(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
$return_data = $this->get_default_config_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'] .= "接口: (get_default_config)\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);
|
||||
}
|
||||
}
|
||||
|
||||
// 首页搜索接口(OK)
|
||||
public function search_column($data = ['search_data'=>'鱼','token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1]){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('search_data', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!array_key_exists('page', $data)){
|
||||
return $this->msg(10001,'page is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['search_data'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['page'],'intnum')){
|
||||
return $this->msg(10005,'page type is error');
|
||||
}
|
||||
$return_data = $this->search_column_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'] .= "接口: (search_column)\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#######################################################################
|
||||
#######################################################################action#######################################################################
|
||||
#######################################################################action#######################################################################
|
||||
|
||||
// 新版
|
||||
public function get_default_config_action($data){
|
||||
$return_data = [
|
||||
// 'user_data'=>[],
|
||||
// 'kcal_data'=>[
|
||||
// 'title'=>'今日已摄入热量',
|
||||
// 'time'=>date('Y-m-d H:i:s'),
|
||||
// 'kcal'=>['value'=>0,'unit'=>'kcal','standard'=>'不达标','color'=>'#F0AD4E'],
|
||||
// 'other_elements'=>[
|
||||
// 'carbohydrate'=>['value'=>0,'unit'=>'g'],
|
||||
// 'protein'=>['value'=>0,'unit'=>'g'],
|
||||
// 'fat'=>['value'=>0,'unit'=>'g'],
|
||||
// ],
|
||||
// 'list'=>[
|
||||
// ['title'=>'早餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
|
||||
// ['title'=>'午餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
|
||||
// ['title'=>'晚餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
|
||||
// ['title'=>'加餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
|
||||
// ],
|
||||
// ],
|
||||
'business_cooperation'=>[],
|
||||
'banner_data'=>[],
|
||||
'search_history'=>['cookbook'=>[],'food'=>[]],
|
||||
'search_guess'=>[],
|
||||
'default_count_foot'=>[
|
||||
'date'=>'', //时间
|
||||
"nutrients_four"=>[
|
||||
[
|
||||
"name"=>"卡路里",
|
||||
"unit"=>"kcal",
|
||||
"suggestion"=>0,
|
||||
"today_intake"=>0,
|
||||
"icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png",
|
||||
"color"=>"#5180D8",
|
||||
"proportion"=>0,
|
||||
"proportion_fp"=>0
|
||||
],
|
||||
[
|
||||
"name"=>"碳水",
|
||||
"unit"=>"g",
|
||||
"suggestion"=>0,
|
||||
"today_intake"=>0,
|
||||
"icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png",
|
||||
"color"=>"#ED7886",
|
||||
"proportion"=>0,
|
||||
"proportion_fp"=>0
|
||||
],
|
||||
[
|
||||
"name"=>"蛋白质",
|
||||
"unit"=>"g",
|
||||
"suggestion"=>0,
|
||||
"today_intake"=>0,
|
||||
"icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_protein.png",
|
||||
"color"=>"#FFB169",
|
||||
"proportion"=>0,
|
||||
"proportion_fp"=>0
|
||||
],
|
||||
[
|
||||
"name"=>"脂肪",
|
||||
"unit"=>"g",
|
||||
"suggestion"=>0,
|
||||
"today_intake"=>0,
|
||||
"icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_fat.png",
|
||||
"color"=>"#3CB383",
|
||||
"proportion"=>0,
|
||||
"proportion_fp"=>0
|
||||
]
|
||||
],
|
||||
'remaining_kcal'=>0, //剩下可摄入卡路里量
|
||||
'details'=>[ //当天营养元素能量占比
|
||||
'carbohydrate'=>['name'=>'碳水','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','color'=>'#ED7886','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
|
||||
'protein'=>['name'=>'蛋白质','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','color'=>'#FFB169','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
|
||||
'fat'=>['name'=>'脂肪','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','color'=>'#3CB383','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
|
||||
],
|
||||
'trace_elements_all_day' => [
|
||||
[
|
||||
'name' => 'VitaminA',
|
||||
'name_ch' => '维生素A',
|
||||
'unit' => 'μg RAE',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'VitaminB1',
|
||||
'name_ch' => '硫胺素',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'VitaminB2',
|
||||
'name_ch' => '核黄素',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'VitaminB6',
|
||||
'name_ch' => '维生素B6',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'VitaminB12',
|
||||
'name_ch' => '维生素B12',
|
||||
'unit' => 'μg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'VitaminD',
|
||||
'name_ch' => '维生素D',
|
||||
'unit' => 'μg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'VitaminK',
|
||||
'name_ch' => '维生素K',
|
||||
'unit' => 'μg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Niacin',
|
||||
'name_ch' => '烟酸',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'VitaminC',
|
||||
'name_ch' => '维生素C',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'VitaminE',
|
||||
'name_ch' => '维生素E',
|
||||
'unit' => 'mg α-TE',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'FolicAcid',
|
||||
'name_ch' => '叶酸',
|
||||
'unit' => 'μg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Biotin',
|
||||
'name_ch' => '生物素',
|
||||
'unit' => 'μg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'PantothenicAcid',
|
||||
'name_ch' => '泛酸',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'TotalCholine',
|
||||
'name_ch' => '总胆碱',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Ca',
|
||||
'name_ch' => '钙',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Phosphorus',
|
||||
'name_ch' => '磷',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Kalium',
|
||||
'name_ch' => '钾',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Mg',
|
||||
'name_ch' => '镁',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Na',
|
||||
'name_ch' => '钠',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Fe',
|
||||
'name_ch' => '铁',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Zn',
|
||||
'name_ch' => '锌',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Se',
|
||||
'name_ch' => '硒',
|
||||
'unit' => 'μg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Cu',
|
||||
'name_ch' => '铜',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Mn',
|
||||
'name_ch' => '锰',
|
||||
'unit' => 'mg',
|
||||
'value' => 0
|
||||
],
|
||||
[
|
||||
'name' => 'Iodine',
|
||||
'name_ch' => '碘',
|
||||
'unit' => 'μg',
|
||||
'value' => 0
|
||||
]
|
||||
],
|
||||
'list'=>[
|
||||
[
|
||||
'name'=>'早餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#0992B4',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png',
|
||||
'icon_home'=>'/static/1.png',
|
||||
'bgimg_home'=>'/static/2.png',
|
||||
'kcal_proportion'=>0,
|
||||
"nutrients_four"=> [
|
||||
[
|
||||
'name'=>'卡路里',
|
||||
'unit'=>'kcal',
|
||||
'color'=>'',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'碳水化合物',
|
||||
'unit'=>'g',
|
||||
'color'=>'#FFB169',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'蛋白质',
|
||||
'unit'=>'g',
|
||||
'color'=>'#5180D8',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'脂肪',
|
||||
'unit'=>'g',
|
||||
'color'=>'#ED7886',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
|
||||
],
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'午餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#4F9211',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png',
|
||||
'icon_home'=>'/static/3.png',
|
||||
'bgimg_home'=>'/static/4.png',
|
||||
'kcal_proportion'=>0,
|
||||
"nutrients_four"=> [
|
||||
[
|
||||
'name'=>'卡路里',
|
||||
'unit'=>'kcal',
|
||||
'color'=>'',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'蛋白质',
|
||||
'unit'=>'g',
|
||||
'color'=>'#5180D8',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'脂肪',
|
||||
'unit'=>'g',
|
||||
'color'=>'#ED7886',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'碳水化合物',
|
||||
'unit'=>'g',
|
||||
'color'=>'#FFB169',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
],
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'晚餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#B354B0',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png',
|
||||
'icon_home'=>'/static/5.png',
|
||||
'bgimg_home'=>'/static/6.png',
|
||||
'kcal_proportion'=>0,
|
||||
"nutrients_four"=> [
|
||||
[
|
||||
'name'=>'卡路里',
|
||||
'unit'=>'kcal',
|
||||
'color'=>'',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'蛋白质',
|
||||
'unit'=>'g',
|
||||
'color'=>'#5180D8',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'脂肪',
|
||||
'unit'=>'g',
|
||||
'color'=>'#ED7886',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'碳水化合物',
|
||||
'unit'=>'g',
|
||||
'color'=>'#FFB169',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
],
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'加餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#C08433',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png',
|
||||
'icon_home'=>'/static/7.png',
|
||||
'bgimg_home'=>'/static/8.png',
|
||||
'kcal_proportion'=>0,
|
||||
"nutrients_four"=> [
|
||||
[
|
||||
'name'=>'卡路里',
|
||||
'unit'=>'kcal',
|
||||
'color'=>'',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'蛋白质',
|
||||
'unit'=>'g',
|
||||
'color'=>'#5180D8',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'脂肪',
|
||||
'unit'=>'g',
|
||||
'color'=>'#ED7886',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
[
|
||||
'name'=>'碳水化合物',
|
||||
'unit'=>'g',
|
||||
'color'=>'#FFB169',
|
||||
'value'=>0,
|
||||
'proportion'=>0,
|
||||
],
|
||||
],
|
||||
'list'=>[],
|
||||
],
|
||||
],
|
||||
]
|
||||
// 'cookbook_label'=>[],
|
||||
];
|
||||
$cfc = Db::connect('cfc_db');
|
||||
|
||||
// 如果有账号信息
|
||||
if(array_key_exists('token', $data)){
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
// 获取账号下信息以及用户信息 start
|
||||
$user = $cfc->table($this->kitchenscale_db_msg['user'])->where(["token"=>$data['token']])->find();
|
||||
|
||||
if($user){
|
||||
// return $this->msg(20001,'账号信息错误');
|
||||
// 处理搜索历史 start
|
||||
$search_history_cookbook = $cfc->table($this->kitchenscale_db_msg['search_history'])
|
||||
->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'cookbook'])
|
||||
->field('id,keyword,last_searched_at,type')
|
||||
->order('last_searched_at desc')
|
||||
->limit(30)
|
||||
->select();
|
||||
$search_history_food = $cfc->table($this->kitchenscale_db_msg['search_history'])
|
||||
->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'food'])
|
||||
->field('id,keyword,last_searched_at,type')
|
||||
->order('last_searched_at desc')
|
||||
->limit(30)
|
||||
->select();
|
||||
// 去重
|
||||
foreach ($search_history_cookbook as $key => $value) {
|
||||
unset($search_history_cookbook[$key]['type']);
|
||||
unset($search_history_cookbook[$key]['ROW_NUMBER']);
|
||||
}
|
||||
foreach ($search_history_food as $key => $value) {
|
||||
unset($search_history_food[$key]['type']);
|
||||
unset($search_history_food[$key]['ROW_NUMBER']);
|
||||
}
|
||||
|
||||
$return_data['search_history']['cookbook'] = $search_history_cookbook;
|
||||
$return_data['search_history']['food'] = $search_history_food;
|
||||
// 处理搜索历史 end
|
||||
}
|
||||
// $return_data['user_data'] = $user;
|
||||
// if($return_data['user_data']['birthday']){
|
||||
// $return_data['user_data']['age'] = $this->calculate_age($return_data['user_data']['birthday']);
|
||||
// }
|
||||
// unset($return_data['user_data']['id']);
|
||||
// unset($return_data['user_data']['token']);
|
||||
// unset($return_data['user_data']['update_time']);
|
||||
// unset($return_data['user_data']['ROW_NUMBER']);
|
||||
// 获取账号下信息以及用户信息 end
|
||||
// // 处理计食器信息 start
|
||||
// $kcal = $cfc->table($this->kitchenscale_db_msg['kcal_log'])->where(["aud_id"=>$user['id'],'is_del'=>0])->whereTime('create_time', 'today')->order('id desc')->select();
|
||||
// if(count($kcal)>0){
|
||||
// $return_data['kcal_data']['title'] = '今日已摄入热量(千卡)'.$kcal[0]['create_time'];
|
||||
// $return_data['kcal_data']['time'] = $kcal[0]['create_time'];
|
||||
// foreach ($kcal as $key => $value) {
|
||||
|
||||
// $return_data['kcal_data']['kcal']['value'] = bcadd($return_data['kcal_data']['kcal']['value'],$value['kcal_val'],2);
|
||||
// $return_data['kcal_data']['other_elements']['carbohydrate']['value'] = bcadd($return_data['kcal_data']['other_elements']['carbohydrate']['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['kcal_data']['other_elements']['protein']['value'] = bcadd($return_data['kcal_data']['other_elements']['protein']['value'],$value['protein_val'],2);
|
||||
// $return_data['kcal_data']['other_elements']['fat']['value'] = bcadd($return_data['kcal_data']['other_elements']['fat']['value'],$value['fat_val'],2);
|
||||
// if($value['meals_type'] == '早餐'){
|
||||
// $return_data['kcal_data']['list'][0]['value'] = bcadd($return_data['kcal_data']['list'][0]['value'],$value['kcal_val'],2);
|
||||
// }else if($value['meals_type'] == '午餐'){
|
||||
// $return_data['kcal_data']['list'][1]['value'] = bcadd($return_data['kcal_data']['list'][1]['value'],$value['kcal_val'],2);
|
||||
// }else if($value['meals_type'] == '晚餐'){
|
||||
// $return_data['kcal_data']['list'][2]['value'] = bcadd($return_data['kcal_data']['list'][2]['value'],$value['kcal_val'],2);
|
||||
// }else{
|
||||
// $return_data['kcal_data']['list'][3]['value'] = bcadd($return_data['kcal_data']['list'][3]['value'],$value['kcal_val'],2);
|
||||
// }
|
||||
// }
|
||||
// foreach ($return_data['kcal_data']['list'] as $key => $value) {
|
||||
// if($value['value'] <= 0){
|
||||
// $return_data['kcal_data']['list'][$key]['value'] = '-';
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if($user['is_use_set_kcal'] == 1){
|
||||
// $nutrition_data['kcal'] = $user['set_kcal'];
|
||||
// }else{
|
||||
// $user['age_num'] = $return_data['user_data']['age'];
|
||||
// $nutrition_data = $this->count_user_nutrition_all($user);
|
||||
// }
|
||||
|
||||
// if(bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) < 0.9){
|
||||
// $return_data['kcal_data']['kcal']['standard'] = '不达标';
|
||||
// $return_data['kcal_data']['kcal']['color'] = '#F0AD4E';
|
||||
// }else if(bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) >= 0.9 && bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) < 1.1){
|
||||
// $return_data['kcal_data']['kcal']['standard'] = '达标';
|
||||
// $return_data['kcal_data']['kcal']['color'] = '#4CD964';
|
||||
// }else{
|
||||
// $return_data['kcal_data']['kcal']['standard'] = '超标';
|
||||
// $return_data['kcal_data']['kcal']['color'] = '#FF0000';
|
||||
// }
|
||||
// // 处理计食器信息 end
|
||||
|
||||
|
||||
// dump($return_data);
|
||||
|
||||
}else{
|
||||
|
||||
}
|
||||
$banner_list = Db::table($this->reedaw_db_name['banner'])->where(['scene_data' => '3','is_del'=>0])->cache(43200)->order('sort_num desc')->field('id,type,pic,jump_url,parameter_data,sort_num')->select();
|
||||
for ($i=0; $i < count($banner_list); $i++) {
|
||||
if($banner_list[$i]['type'] != 1){
|
||||
$banner_list[$i]['parameter_data'] = '';
|
||||
}
|
||||
unset($banner_list[$i]['sort_num']);
|
||||
unset($banner_list[$i]['ROW_NUMBER']);
|
||||
}
|
||||
$return_data['banner_data'] = $banner_list;
|
||||
// 处理banner信息 end
|
||||
|
||||
// 处理猜你喜欢信息start
|
||||
// 使用三元运算符判断$user是否存在
|
||||
$user_id = isset($user) ? $user['id'] : 9999999;
|
||||
$cnxh = new Guessyoulike;
|
||||
$cookbook_data = $cnxh->getGuessYouLike($user_id,'cookbook');
|
||||
$food_data = $cnxh->getGuessYouLike($user_id,'food');
|
||||
foreach ($cookbook_data as $key => $value) {
|
||||
$return_data['search_guess']['cookbook'][] = ['title'=>$key,'list'=>$value];
|
||||
}
|
||||
foreach ($food_data as $key => $value) {
|
||||
$return_data['search_guess']['food_data'][] = ['title'=>$key,'list'=>$value];
|
||||
}
|
||||
// 处理猜你喜欢信息end
|
||||
|
||||
// 添加商务合作信息start
|
||||
$business_cooperation = $cfc->table($this->kitchenscale_db_msg['business_cooperation'])->where(["is_del"=>0])->field('id,title,data_url as jump_url')->find();
|
||||
$return_data['business_cooperation'] = $business_cooperation;
|
||||
// 添加商务合作信息start
|
||||
|
||||
// 添加菜谱label start
|
||||
|
||||
// $cookbook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label'])->where(["is_del"=>0])->field('id,name')->select();
|
||||
// $return_data['cookbook_label'] = $cookbook_label;
|
||||
// 添加菜谱label end
|
||||
|
||||
// 添加每餐背景图start
|
||||
$return_data['meal_list'] = [
|
||||
['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png','name'=>'早餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1_bg.jpg'],
|
||||
['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png','name'=>'午餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2_bg.jpg'],
|
||||
['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png','name'=>'晚餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3_bg.jpg'],
|
||||
['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png','name'=>'加餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4_bg.jpg'],
|
||||
];
|
||||
// 添加每餐背景图start
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
|
||||
public function search_column_action($data){
|
||||
|
||||
// $cookbook = new Cookbook();
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$page_now = array_key_exists('page',$data)?$data['page']:1;
|
||||
$page_total = $page_now;
|
||||
$page_num = 20;
|
||||
// 获取菜谱信息
|
||||
$content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
||||
->where("title LIKE '%".$data['search_data']."%' OR describe_data LIKE '%".$data['search_data']."%'")
|
||||
->count();
|
||||
$page_total = ceil($content_num/$page_num);
|
||||
|
||||
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
||||
->alias('cookbook')
|
||||
->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT')
|
||||
->where("cookbook.title LIKE '%".$data['search_data']."%' OR cookbook.describe_data LIKE '%".$data['search_data']."%'")
|
||||
->field("cookbook.id,cookbook.title,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.likes_num,uploadimg.pic_url as cover")
|
||||
->page("$page_now,$page_num")
|
||||
->select();
|
||||
|
||||
|
||||
if(count($content_list)<=0){
|
||||
return $this->msg([]);
|
||||
}
|
||||
if(array_key_exists('token',$data)){
|
||||
if($data['token'] != ''){
|
||||
// 获取账号下信息以及用户信息
|
||||
$user_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
|
||||
if($user_data){
|
||||
// 获取用户收藏列表
|
||||
$my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
|
||||
->where(['token'=>$data['token']])
|
||||
->column('cookbook_id');
|
||||
// dump();
|
||||
// 处理菜谱收藏信息
|
||||
foreach ($content_list as $key => $value) {
|
||||
if(array_key_exists($value['id'],$my_collect_list)){
|
||||
$content_list[$key]['is_me_like_it'] = 'yes';
|
||||
}else{
|
||||
$content_list[$key]['is_me_like_it'] = 'no';
|
||||
}
|
||||
if($value['cover'] == null){
|
||||
$content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
||||
}
|
||||
unset($content_list[$key]['ROW_NUMBER']);
|
||||
}
|
||||
if($data['search_data'] != ''){
|
||||
$this->add_search_history_action(['id'=>$user_data['id'],'search_data'=>$data['search_data'],'type'=>'cookbook']);
|
||||
}
|
||||
|
||||
}else{
|
||||
foreach ($content_list as $key => $value) {
|
||||
$content_list[$key]['is_me_like_it'] = 'no';
|
||||
if($value['cover'] == null){
|
||||
$content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
||||
}
|
||||
unset($content_list[$key]['ROW_NUMBER']);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($content_list as $key => $value) {
|
||||
$content_list[$key]['is_me_like_it'] = 'no';
|
||||
if($value['cover'] == null){
|
||||
$content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
||||
}
|
||||
unset($content_list[$key]['ROW_NUMBER']);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($content_list as $key => $value) {
|
||||
$content_list[$key]['is_me_like_it'] = 'no';
|
||||
if($value['cover'] == null){
|
||||
$content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
||||
}
|
||||
unset($content_list[$key]['ROW_NUMBER']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->msg([
|
||||
'page_now'=>$page_now,
|
||||
'page_total'=>$page_total,
|
||||
'content_list'=>$content_list
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
########################################################################################################################################################################
|
||||
########################################################################################################################################################################
|
||||
########################################################################################################################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
public function create_random_string($length = 12)
|
||||
{
|
||||
//创建随机字符
|
||||
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
$str = "";
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,705 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use app\app\controller\Wechat;// 引入Wechat服务类
|
||||
|
||||
|
||||
class Login extends Base{
|
||||
protected $code_time = 50;
|
||||
// protected $token_time = 2592000;//30天的秒数
|
||||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||||
protected $login_use_db_name = [
|
||||
'1'=>'app_account_number',
|
||||
];
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 注册
|
||||
public function register_action($data = ['data'=>13408173311,'password'=>'123','code'=>'746119']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
// 验证是否前段发送过来的数据
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
// 验证数据项是否完整
|
||||
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
// 验证数据值是否合规
|
||||
if(!$data['data'] || !$data['password'] || !$data['code']){
|
||||
return $this->msg(10006);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['password'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['code'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
// 验证是手机还是邮箱
|
||||
$montage_data = $this->is_tel_email($data['data']);
|
||||
if($montage_data == false){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
|
||||
// 查询账号是否已经注册
|
||||
$inspect_repeat = Db::table($this->login_use_db_name['1'])->where([$montage_data=>$data['data'],'is_del'=>0])->count();
|
||||
|
||||
if($inspect_repeat > 0){
|
||||
return $this->msg(10002,'注册失败,账号已存在');
|
||||
}
|
||||
|
||||
// 检查验证码
|
||||
$code_result = $this->check_code($data['data'],$data['code']);
|
||||
if($code_result !== true){
|
||||
return $this->msg(10002,$code_result);
|
||||
}
|
||||
// 验证完之后
|
||||
$set_data = [];
|
||||
if($montage_data == 'tel'){
|
||||
$set_data['tel'] = $data['data'];
|
||||
}else{
|
||||
$set_data['email'] = $data['data'];
|
||||
}
|
||||
$set_data['password'] = $data['password'];
|
||||
$set_data['head_pic'] = $this->default_head_pic;
|
||||
$set_data['nickname'] = '用户'.time();
|
||||
$set_data['create_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['login_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
|
||||
$result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data);
|
||||
if($result){
|
||||
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]);
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
|
||||
// 成功
|
||||
$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'] .= "方法: " . __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);
|
||||
}
|
||||
|
||||
}
|
||||
// 重置密码
|
||||
public function reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
// 验证是否前段发送过来的数据
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
// 验证数据项是否完整
|
||||
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
// 验证数据值是否合规
|
||||
if($data['password'] != $data['c_password']){
|
||||
return $this->msg(10003,'两次密码不一致');
|
||||
}
|
||||
if($data['password'] == ''){
|
||||
return $this->msg(10003,'密码不能为空');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['password'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['code'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
// 检查验证码
|
||||
$code_result = $this->check_code($data['data'],$data['code']);
|
||||
if($code_result !== true){
|
||||
return $this->msg(10003,$code_result);
|
||||
}
|
||||
$t_y = $this->is_tel_email($data['data']);
|
||||
if($t_y === false){
|
||||
return $this->msg(10003,'账号格式错误');
|
||||
}
|
||||
// 检查账号是否存在
|
||||
$find_data = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find();
|
||||
if(!$find_data){
|
||||
return $this->msg(10003);
|
||||
}
|
||||
$result = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]);
|
||||
if($result){
|
||||
$return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]);
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
|
||||
// 成功
|
||||
$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'] .= "方法: " . __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);
|
||||
}
|
||||
|
||||
}
|
||||
// 登录
|
||||
public function login_action($data = ['data'=>'18530934717','validate_data'=>'0932','type'=>'login','validate_type'=>'password']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
// 检测是否为手机
|
||||
$montage_data = $this->is_tel_email($data['data']);
|
||||
if($montage_data == false){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
|
||||
$verify_result[$montage_data] = $data['data'];
|
||||
$verify_result['is_del'] = 0;
|
||||
// 检测校验途径
|
||||
if($data['validate_type'] == 'code'){
|
||||
$code_name = $data['data'];
|
||||
if($this->check_code($code_name,$data['validate_data']) === true){
|
||||
$result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token')->find();
|
||||
if($result){
|
||||
Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]);
|
||||
}else{
|
||||
$set_data['password'] = '';
|
||||
$set_data[$montage_data] = $data['data'];
|
||||
$set_data['head_pic'] = $this->default_head_pic;
|
||||
$set_data['nickname'] = '用户'.$data['data'];
|
||||
$set_data['create_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['login_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
|
||||
$result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data);
|
||||
if($result){
|
||||
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功');
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$return_data = $this->msg(10003,'登录失败,验证码错误或失效');
|
||||
}
|
||||
}else if($data['validate_type'] == 'password'){
|
||||
// $verify_result['password'] = $data['validate_data'];
|
||||
$result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token,password')->find();
|
||||
if($result){
|
||||
if($result['password'] == ''){
|
||||
$return_data = $this->msg(10003,'该账户未设密码,请用验证码登录');
|
||||
}
|
||||
if($data['validate_data'] != $result['password']){
|
||||
$return_data = $this->msg(10003,'账号密码错误');
|
||||
}else{
|
||||
|
||||
Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功');
|
||||
}
|
||||
}else{
|
||||
$return_data = $this->msg(10003,'账号未注册,请先注册');
|
||||
}
|
||||
}else{
|
||||
$return_data = $this->msg(10003,'校验参数错误');
|
||||
}
|
||||
|
||||
// 成功
|
||||
$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'] .= "方法: " . __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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// 微信手机号快捷登录
|
||||
public function wechat_quick_login(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('code', $data)){
|
||||
// return $this->msg(10001,'');
|
||||
return $this->msg(10001,'code is miss');
|
||||
}
|
||||
if(!array_key_exists('encryptedData', $data)){
|
||||
return $this->msg(10001,'encryptedData is miss');
|
||||
}
|
||||
if(!array_key_exists('iv', $data)){
|
||||
return $this->msg(10001,'iv is miss');
|
||||
}
|
||||
// 校验参数
|
||||
if (empty($data['code'])) {
|
||||
return $this->msg(10001,'code is miss.');
|
||||
}
|
||||
if (empty($data['encryptedData'])) {
|
||||
return $this->msg(10001,'encryptedData is miss.');
|
||||
}
|
||||
if (empty($data['iv'])) {
|
||||
return $this->msg(10001,'iv is miss.');
|
||||
}
|
||||
|
||||
// 调用Wechat服务类处理微信登录逻辑
|
||||
$wechatService = new Wechat();
|
||||
$result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']);
|
||||
|
||||
// die;
|
||||
if($result['code'] == 0){
|
||||
// return $this->msg($result['code'],$result['msg']);
|
||||
|
||||
$user_data = Db::table($this->login_use_db_name['1'])->where(['tel'=>$result['data']['phoneNumber'],'is_del'=>0])->find();
|
||||
|
||||
if($user_data){
|
||||
Db::table($this->login_use_db_name['1'])->where(['token'=>$user_data['token']])->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
$return_data = $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
|
||||
}else{
|
||||
$set_data['password'] = '';
|
||||
$set_data['tel'] = $result['data']['phoneNumber'];
|
||||
$set_data['head_pic'] = $this->default_head_pic;
|
||||
$set_data['nickname'] = '用户'.$result['data']['phoneNumber'];
|
||||
$set_data['create_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['login_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['token'] = md5($result['data']['phoneNumber'].$this->create_random_string(12).time());
|
||||
$set_user_result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data);
|
||||
if($set_user_result){
|
||||
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$set_user_result],'登录成功');
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
}
|
||||
return $return_data;
|
||||
}else{
|
||||
return $this->msg($result['code'],$result['msg']);
|
||||
}
|
||||
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
// 退出登录操作
|
||||
public function user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
$return_data = $this->msg(10001);
|
||||
}
|
||||
if($this->token_time_validate($data['token']) === false){
|
||||
$return_data = $this->msg(20001);
|
||||
}
|
||||
|
||||
$result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']);
|
||||
if($result){
|
||||
$return_data = $this->msg([]);
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
// 成功
|
||||
$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'] .= "方法: " . __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);
|
||||
}
|
||||
|
||||
}
|
||||
// 删除账号
|
||||
public function delete_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
$return_data = $this->msg(10001);
|
||||
}
|
||||
$result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-09-01 00:00:00']);
|
||||
if($result){
|
||||
$return_data = $this->msg([]);
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
|
||||
// 成功
|
||||
$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'] .= "方法: " . __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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
|
||||
|
||||
// 发送验证码 手机/邮箱
|
||||
/* 接口说明(发邮件)
|
||||
* $data(手机或者邮箱信息) 字符串
|
||||
* $type(验证类型,是注册用,还是其他用途) 字符串 默认register(注册)(register、login、reset_password)
|
||||
* $road(是手机还是邮箱还是其他) 字符串 默认tel或email
|
||||
*/
|
||||
//18736019909
|
||||
public function send_phone_email_code($data = ['data'=>'18736019909']){
|
||||
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('data', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
|
||||
if(cache($data['data'])){
|
||||
return $this->msg(10002,'60秒仅可发送一次验证码');
|
||||
}
|
||||
|
||||
$num = mt_rand(100000,999999);
|
||||
if (preg_match('/^\d{11}$/', $data['data'])) {
|
||||
// 本公司短信
|
||||
$result = $this->send_tel_code($data['data'],$num);
|
||||
// 阿里云短信
|
||||
// $sms_all = new Smsaliyun;
|
||||
// $result = $sms_all->send_sms($data['data'],$num);
|
||||
// dump($result);
|
||||
$road = 'tel';
|
||||
}else{
|
||||
$result = $this->send_email_code([$data['data']],['title'=>'体测APP验证码','from_user_name'=>'体测APP','content'=>$num]);
|
||||
$road = 'email';
|
||||
}
|
||||
if(is_array($result) && $result['code'] == 0){
|
||||
cache($data['data'], $num, $this->code_time);
|
||||
// return $this->msg(['code'=>$num]);
|
||||
return $this->msg([]);
|
||||
// return true;
|
||||
}else{
|
||||
return $this->msg(10010,'验证码发送失败');
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
|
||||
################################内部调用################################
|
||||
/* 接口说明(发手机短信)
|
||||
|
||||
*/
|
||||
public function send_tel_code($tel,$code){
|
||||
// 初始化cURL会话
|
||||
$ch = curl_init();
|
||||
$headers = [
|
||||
'Accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
];
|
||||
// 设置头部信息
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
// 设置请求的URL
|
||||
$url = "http://sms.ybhdmob.com/Message/Send?token=ybhdmob";
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
// 设置为POST请求
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
// 设置POST数据
|
||||
$postData = array(
|
||||
'phone' => $tel,
|
||||
// 'content' => '【巨天】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||
// 'content' => '【郑州品传科技】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||
// 'content' => '【每日一称】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||
'content' => '【小白健康】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||
);
|
||||
$postData = json_encode($postData);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
||||
// 设置返回结果不直接输出,而是返回到变量中
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// 发送请求并获取响应
|
||||
$response = curl_exec($ch);
|
||||
// dump($response);
|
||||
// 检查是否有错误发生
|
||||
if (curl_errno($ch)) {
|
||||
$error_message = curl_error($ch);
|
||||
return "请求错误: " . $error_message;
|
||||
}
|
||||
// 关闭cURL会话
|
||||
curl_close($ch);
|
||||
// 处理响应
|
||||
// dump(json_decode($response,true));
|
||||
if ($response) {
|
||||
return json_decode($response,true);
|
||||
} else {
|
||||
echo "未收到响应";
|
||||
}
|
||||
}
|
||||
// 手机号区分
|
||||
function getCarrierByPhone($phone) {
|
||||
// 验证手机号格式(11位数字且以1开头)
|
||||
if (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
|
||||
return '无效手机号';
|
||||
}
|
||||
|
||||
$prefix3 = substr($phone, 0, 3);
|
||||
|
||||
// 2025年最新3位号段(排除4位号段)
|
||||
$carriers = [
|
||||
'中国移动' => ['134', '135', '136', '137', '138', '139', '150', '151', '152', '157', '158', '159', '178', '182', '183', '184', '187', '188', '195', '197', '198'],
|
||||
'中国联通' => ['130', '131', '132', '155', '156', '166', '175', '176', '185', '186', '196'],
|
||||
'中国电信' => ['133', '153', '173', '177', '180', '181', '189', '190', '191', '193', '199'],
|
||||
'中国广电' => ['192']
|
||||
];
|
||||
|
||||
foreach ($carriers as $carrier => $segments) {
|
||||
if (in_array($prefix3, $segments)) {
|
||||
return $carrier;
|
||||
}
|
||||
}
|
||||
|
||||
return '未知运营商';
|
||||
}
|
||||
/* 接口说明(发邮件)
|
||||
* $address(收件人的邮箱地址) 数组 格式: ['460834639@qq.com','460834639@qq.com'.......]
|
||||
* $content(邮件的主题数据信息) 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123']
|
||||
* $annex(附件路径信息) 字符串
|
||||
*/
|
||||
public function send_email_code($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 = '<div style="margin: 0; padding: 0;">
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background: #f3f3f3; min-width: 350px; font-size: 1px; line-height: normal;">
|
||||
<tbody><tr>
|
||||
<td align="center" valign="top">
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="750" class="table750" style="width: 100%; max-width: 750px; min-width: 350px; background: #f3f3f3;">
|
||||
<tbody><tr>
|
||||
<td class="mob_pad" width="25" style="width: 25px; max-width: 25px; min-width: 25px;"> </td>
|
||||
<td align="center" valign="top" style="background: #ffffff;">
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;">
|
||||
<tbody><tr>
|
||||
<td align="right" valign="top">
|
||||
<div class="top_pad" style="height: 25px; line-height: 25px; font-size: 23px;"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
|
||||
<tbody><tr>
|
||||
<td align="left" valign="top">
|
||||
<div style="height: 39px; line-height: 39px; font-size: 37px;"> </div>
|
||||
<font class="mob_title1" face="\'Source Sans Pro\', sans-serif" color="#1a1a1a" style="font-size: 52px; line-height: 55px; font-weight: 300; letter-spacing: -1.5px;">
|
||||
<span class="mob_title1" style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #fb966e; font-size: 48px; line-height: 55px; font-weight: 700; letter-spacing: -1.5px;">Reedaw!</span>
|
||||
</font>
|
||||
<div style="height: 73px; line-height: 73px; font-size: 71px;"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
|
||||
<tbody><tr>
|
||||
<td align="left" valign="top">
|
||||
<div style="height: 33px; line-height: 33px; font-size: 31px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">感谢您选择锐动产品!</span>
|
||||
</font>
|
||||
<div style="height: 33px; line-height: 33px; font-size: 31px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">以下6位数字是邮箱验证码,请在需要的位置填写以通过验证</span>
|
||||
</font>
|
||||
<div style="height: 18px; line-height: 33px; font-size: 31px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #aaaaaa; font-size: 16px; line-height: 32px;">(如果您从未请求发送邮箱验证码,请忽略此邮件)</span>
|
||||
</font>
|
||||
<div style="height: 33px; line-height: 33px; font-size: 31px;"> </div>
|
||||
<table class="mob_btn" cellpadding="0" cellspacing="0" border="0" style="background: #fb966e; border-radius: 4px;">
|
||||
<tbody><tr>
|
||||
<td align="center" valign="top">
|
||||
<span style="display: block; border: 1px solid #fb966e; border-radius: 0px; padding: 6px 12px; font-family: \'Nunito\', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">
|
||||
<font face="\'Nunito\', sans-serif" color="#ffffff" style="font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">
|
||||
<span style="font-family: \'Nunito\', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">'.$content['content'].'</span>
|
||||
</font>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
<div style="height: 75px; line-height: 75px; font-size: 73px;"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;">
|
||||
<tbody><tr>
|
||||
<td align="center" valign="top">
|
||||
<div style="height: 34px; line-height: 34px; font-size: 32px;"> </div>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
|
||||
<tbody><tr>
|
||||
<td align="center" valign="top">
|
||||
<div style="height:12px; line-height: 34px; font-size: 32px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#868686" style="font-size: 17px; line-height: 20px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #868686; font-size: 17px; line-height: 20px;">© Zhengzhou Pinchuan Technology Co., Ltd. </span>
|
||||
</font>
|
||||
<div style="height: 3px; line-height: 3px; font-size: 1px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#1a1a1a" style="font-size: 17px; line-height: 20px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px;"><a target="_blank" style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px; text-decoration: none;" href="https://paoluz.link/"></a></span>
|
||||
</font>
|
||||
<div style="height: 35px; line-height: 35px; font-size: 33px;"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
</td>
|
||||
<td class="mob_pad" width="25" style="width: 25px; max-width: 25px; min-width: 25px;"> </td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
</div>';
|
||||
|
||||
$mail->Body = $neirong; //邮件主体内容
|
||||
//发送
|
||||
if (!$mail->Send()) {
|
||||
|
||||
return ['code' => 10003,'msg'=>$mail->ErrorInfo];
|
||||
// return $mail->ErrorInfo;
|
||||
} else {
|
||||
return ['code' => 0];
|
||||
// return 'success';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function check_code($data = 18530934717 , $code = 123456){
|
||||
// // 默认验证码正确
|
||||
|
||||
if(cache($data) == false){
|
||||
return '验证码过期';
|
||||
}else{
|
||||
if($code != cache($data)){
|
||||
return '验证码错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
################################################################other################################################################
|
||||
################################################################other################################################################
|
||||
################################################################other################################################################
|
||||
|
||||
|
||||
public function create_random_string($length = 12)
|
||||
{
|
||||
//创建随机字符
|
||||
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
$str = "";
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
// use think\Controller;
|
||||
use think\Db;
|
||||
|
||||
class Product extends Base
|
||||
{
|
||||
protected $is_default = 1;
|
||||
|
||||
// 获取配置信息
|
||||
public function get_default_configuration()
|
||||
{
|
||||
$cfc = Db::connect('cfc_db');
|
||||
// $data = input();
|
||||
|
||||
|
||||
// 2. 获取所点击选项的所有直属上级配置项
|
||||
$content_num = $cfc->table("ceshi3_option")
|
||||
->alias('xuanxiang')
|
||||
->join('ceshi2_configuration peizhi','xuanxiang.parent_id = peizhi.id','LEFT')
|
||||
->where(['peizhi.is_default'=>$this->is_default])
|
||||
->field("xuanxiang.*,peizhi.name")
|
||||
->select();
|
||||
$temporary = [];
|
||||
foreach ($content_num as $key => $value) {
|
||||
$temporary[$value['name']]['id'] = $value['parent_id'];
|
||||
$temporary[$value['name']]['name'] = $value['name'];
|
||||
$temporary[$value['name']]['type'] = "configuration";
|
||||
$temporary[$value['name']]['list'][$value['value']] = [];
|
||||
$temporary[$value['name']]['list'][$value['value']]['id'] = $value['id'];
|
||||
$temporary[$value['name']]['list'][$value['value']]['name'] = $value['value'];
|
||||
$temporary[$value['name']]['list'][$value['value']]['type'] = "parameter";
|
||||
$temporary[$value['name']]['list'][$value['value']]['list'] = [];
|
||||
}
|
||||
// dump($temporary);
|
||||
// die;
|
||||
return $this->msg($temporary);
|
||||
}
|
||||
|
||||
// 获取所点击选项的所有直属上级配置项
|
||||
private function getAncestorConfigurations($cfc, $optionId)
|
||||
{
|
||||
$ancestors = [];
|
||||
|
||||
// 获取当前选项的配置项
|
||||
$currentConfig = $cfc->query("
|
||||
SELECT c.id, c.name, c.parent_id
|
||||
FROM configurations c
|
||||
JOIN options o ON c.id = o.config_id
|
||||
WHERE o.id = ?
|
||||
", [$optionId]);
|
||||
|
||||
if (!empty($currentConfig)) {
|
||||
$currentConfig = $currentConfig[0];
|
||||
|
||||
// 获取直属上级配置项
|
||||
if ($currentConfig['parent_id']) {
|
||||
$parentConfig = $cfc->query("
|
||||
SELECT c.id, c.name
|
||||
FROM configurations c
|
||||
WHERE c.id = ?
|
||||
", [$currentConfig['parent_id']]);
|
||||
|
||||
if (!empty($parentConfig)) {
|
||||
$parentConfig = $parentConfig[0];
|
||||
$ancestors[] = $parentConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ancestors;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,811 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class Usercenter extends Base{
|
||||
|
||||
protected $code_time = 50;
|
||||
// protected $token_time = 2592000;//30天的秒数
|
||||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||||
protected $page_num = 20;
|
||||
protected $reedaw_db_msg = [
|
||||
'zhanghao'=>'app_account_number',//账号表
|
||||
'juese'=>'app_user_data',//角色表
|
||||
];
|
||||
protected $kitchenscale_db_msg = [
|
||||
'cookbook'=>'app_user_cookbook',//菜谱表
|
||||
'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
|
||||
'uploadimg'=>'app_user_upload_img',//图片素材表
|
||||
'foodlist1'=>'app_z_national_standard_food_type_1',//食材列表1
|
||||
'foodlist2'=>'app_z_national_standard_food_type_2',//食材列表2
|
||||
'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
|
||||
'collect_list'=>'app_user_collect_list',//点赞表
|
||||
'banner'=>'app_banner_data',//banner
|
||||
'user'=>'app_user_data',//用户表
|
||||
'search_history'=>'app_user_search_history',//用户搜索表
|
||||
'business_cooperation'=>'app_business_cooperation_log',//商务合作
|
||||
'eat_log'=>'app_user_kcal_log',//食材列表3
|
||||
];
|
||||
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 获取角色信息
|
||||
public function get_user_msg($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||
// try { 、
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$return_data = $this->get_user_msg_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'] .= "接口: (get_default_config)\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 update_user_msg(){
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(!array_key_exists('nickname', $data)){
|
||||
return $this->msg(10001,'nickname is miss');
|
||||
}
|
||||
if(!array_key_exists('gender', $data)){
|
||||
return $this->msg(10001,'gender is miss');
|
||||
}
|
||||
if(!array_key_exists('birthday', $data)){
|
||||
return $this->msg(10001,'birthday is miss');
|
||||
}
|
||||
if(!array_key_exists('height', $data)){
|
||||
return $this->msg(10001,'height is miss');
|
||||
}
|
||||
if(!array_key_exists('weight', $data)){
|
||||
return $this->msg(10001,'weight is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['nickname'],'str')){
|
||||
return $this->msg(10005,'nickname type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
|
||||
return $this->msg(10005,'gender type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||||
return $this->msg(10005,'birthday type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['height'],'num')){
|
||||
return $this->msg(10005,'height type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['weight'],'num')){
|
||||
return $this->msg(10005,'weight type is error');
|
||||
}
|
||||
$return_data = $this->update_user_msg_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'] .= "接口: (get_default_config)\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);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户收藏点赞列表(OK)
|
||||
public function get_user_collect_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1,'search_data'=>'']){
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(!array_key_exists('page', $data)){
|
||||
return $this->msg(10001,'page is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['page'],'intnum')){
|
||||
return $this->msg(10005,'page type is error');
|
||||
}
|
||||
$return_data = $this->get_user_collect_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'] .= "接口: (get_default_config)\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 get_my_cookbook($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1,'search_data'=>'']){
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(!array_key_exists('page', $data)){
|
||||
return $this->msg(10001,'page is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['page'],'intnum')){
|
||||
return $this->msg(10005,'page type is error');
|
||||
}
|
||||
$return_data = $this->get_my_cookbook_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'] .= "接口: (get_default_config)\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 del_my_cookbook($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'cookbook_id'=>'33']){
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(!array_key_exists('aud_id', $data)){
|
||||
return $this->msg(10001,'aud_id is miss');
|
||||
}
|
||||
if(!array_key_exists('cookbook_id', $data)){
|
||||
return $this->msg(10001,'cookbook_id is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
|
||||
return $this->msg(10005,'cookbook_id type is error');
|
||||
}
|
||||
$return_data = $this->del_my_cookbook_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'] .= "接口: (get_default_config)\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 del_search_history(){
|
||||
// 尝试捕获异常
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if(!array_key_exists('del_arr', $data)){
|
||||
return $this->msg(10001,'del_arr is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['del_arr'],'str')){
|
||||
return $this->msg(10005,'del_arr type is error');
|
||||
}
|
||||
$data['del_arr'] = strval($data['del_arr']);
|
||||
$data['del_arr'] = trim($data['del_arr']);
|
||||
// 判断是否是 "all"(不区分大小写)
|
||||
if (strtolower($data['del_arr']) !== 'all' && preg_match('/^\d+(,\d+)*$/', $data['del_arr']) !== 1) {
|
||||
return $this->msg(10005,'del_arr type is error');
|
||||
}
|
||||
|
||||
$return_data = $this->del_search_history_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' => '系统错误']);
|
||||
}
|
||||
}
|
||||
|
||||
// 商务合作
|
||||
public function business_cooperation(){
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#######################################################################action#######################################################################
|
||||
#######################################################################action#######################################################################
|
||||
#######################################################################action#######################################################################
|
||||
|
||||
public function get_user_msg_action($data){
|
||||
// 获取账号下信息以及用户信息
|
||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic,tel,email')->find();
|
||||
if(!$user_data){
|
||||
return $this->msg(10004);
|
||||
}
|
||||
// $return_data = [];
|
||||
// 获取账号下信息以及用户信息start
|
||||
$user_all_data['aud_id'] = '';
|
||||
$user_all_data['token'] = $user_data['token'];
|
||||
$user_all_data['nickname'] = $user_data['nickname'];
|
||||
$user_all_data['head_pic'] = $user_data['head_pic'];
|
||||
$user_all_data['gender'] = '';
|
||||
$user_all_data['age'] = '';
|
||||
$user_all_data['height'] = '';
|
||||
$user_all_data['weight'] = '';
|
||||
$user_all_data['set_kcal'] = '';
|
||||
$user_all_data['is_use_set_kcal'] = '';
|
||||
$user_all_data['tel'] = $user_data['tel'];
|
||||
$user_all_data['email'] = $user_data['email'];
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$user_account = $cfc->table($this->kitchenscale_db_msg['user'])
|
||||
->where(["token"=>$data['token']])
|
||||
->field('id as aud_id,token,nickname,head_pic,gender,age,height,weight,set_kcal,is_use_set_kcal,birthday')
|
||||
->find();
|
||||
if($user_account){
|
||||
if($user_account['set_kcal'] == '.00'){
|
||||
$user_account['set_kcal'] = 0;
|
||||
}
|
||||
$user_all_data['aud_id'] = $user_account['aud_id'];
|
||||
$user_all_data['gender'] = $user_account['gender'];
|
||||
$user_all_data['age'] = $user_account['age']?$user_account['age']:$this->calculate_age($user_account['birthday']);
|
||||
$user_all_data['height'] = $user_account['height'];
|
||||
$user_all_data['weight'] = $user_account['weight'];
|
||||
$user_all_data['set_kcal'] = $user_account['set_kcal'];
|
||||
$user_all_data['is_use_set_kcal'] = $user_account['is_use_set_kcal'];
|
||||
$user_all_data['birthday'] = $user_account['birthday'];
|
||||
$user_all_data['food_count'] = $this->user_that_day_food_count($user_account);
|
||||
}else{
|
||||
return $this->msg(10004);
|
||||
}
|
||||
|
||||
|
||||
// $return_data = $user_all_data;
|
||||
return $this->msg($user_all_data);
|
||||
// 获取账号下信息以及用户信息end
|
||||
}
|
||||
public function update_user_msg_action($data){
|
||||
if($data['gender'] == 0){
|
||||
return $this->msg(10005,'性别信息错误');
|
||||
}
|
||||
// 获取账号下信息以及用户信息
|
||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
|
||||
if($user_data<=0){
|
||||
return $this->msg(10005,'账号信息错误');
|
||||
}
|
||||
|
||||
$cfc = Db::connect('cfc_db');
|
||||
|
||||
$is_user_true = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->count();
|
||||
|
||||
$user_msg['nickname'] = $data['nickname'];
|
||||
$user_msg['head_pic'] = $data['gender'] == 1?'https://tc.pcxbc.com/tsf/1.png':'https://tc.pcxbc.com/tsf/2.png';
|
||||
$user_msg['gender'] = $data['gender'];
|
||||
$user_msg['birthday'] = $data['birthday'];
|
||||
$user_msg['height'] = $data['height'];
|
||||
$user_msg['weight'] = $data['weight'];
|
||||
|
||||
if($is_user_true>0){
|
||||
$user_msg['update_time'] = date('Y-m-d H:i:s');
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['user'])
|
||||
->where(['token'=>$data['token']])
|
||||
->update($user_msg);
|
||||
}else{
|
||||
$user_msg['token'] = $data['token'];
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['user'])
|
||||
->insert($user_msg);
|
||||
}
|
||||
Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->update(['nickname'=>$user_msg['nickname']]);
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
public function get_user_collect_list_action($data){
|
||||
// 获取账号下信息以及用户信息
|
||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
|
||||
if($user_data<=0){
|
||||
return $this->msg(10005,'账号信息错误');
|
||||
}
|
||||
|
||||
$search_sql_str = "a.token = '".$data['token']."' AND a.is_del = 0 AND b.is_del = 0";
|
||||
if(!array_key_exists('search_data', $data)){
|
||||
$data['search_data'] = "";
|
||||
}else{
|
||||
if($data['search_data'] === ""){
|
||||
$data['search_data'] = "";
|
||||
}else{
|
||||
$data['search_data'] = " AND (b.title LIKE '%".$data['search_data']."%' OR b.describe_data LIKE '%".$data['search_data']."%')";
|
||||
}
|
||||
}
|
||||
$search_sql_str = $search_sql_str.$data['search_data'];
|
||||
// "a.token = 'asdasdasdasda' AND a.is_del = 0 AND b.title LIKE '%鱼%' OR b.describe_data LIKE '%鱼%'";
|
||||
|
||||
$cfc = Db::connect('cfc_db');
|
||||
|
||||
$content_num = $cfc->table($this->kitchenscale_db_msg['collect_list'])
|
||||
->alias('a')
|
||||
->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT')
|
||||
->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
|
||||
->where($search_sql_str)
|
||||
->count();
|
||||
$page_total = ceil($content_num/$this->page_num);;
|
||||
$collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
|
||||
->alias('a')
|
||||
->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT')
|
||||
->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
|
||||
->where($search_sql_str)
|
||||
->field("b.id,b.title,b.cover as cover_id,c.pic_url as cover_url,b.likes_num,b.create_user_token,b.create_user_head_pic,b.create_user_nickname")
|
||||
->page($data['page'],$this->page_num)
|
||||
->select();
|
||||
|
||||
foreach ($collect_list as $key => $value) {
|
||||
$collect_list[$key]['is_me_like_it'] = 'yes';
|
||||
|
||||
}
|
||||
|
||||
return $this->msg([
|
||||
'page_now'=>$data['page'],
|
||||
'page_total'=>$page_total,
|
||||
'content_list'=>$collect_list
|
||||
]);
|
||||
}
|
||||
|
||||
public function get_my_cookbook_action($data){
|
||||
// 获取账号下信息以及用户信息
|
||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
|
||||
if($user_data<=0){
|
||||
return $this->msg(10005,'账号信息错误');
|
||||
}
|
||||
|
||||
$search_sql_str = "b.create_user_token = '".$data['token']."' AND b.is_del = 0";
|
||||
if(!array_key_exists('search_data', $data)){
|
||||
$data['search_data'] = "";
|
||||
}else{
|
||||
if($data['search_data'] === ""){
|
||||
$data['search_data'] = "";
|
||||
}else{
|
||||
$data['search_data'] = " AND (b.title LIKE '%".$data['search_data']."%' OR b.describe_data LIKE '%".$data['search_data']."%')";
|
||||
}
|
||||
}
|
||||
$search_sql_str = $search_sql_str.$data['search_data'];
|
||||
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
||||
->alias('b')
|
||||
->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
|
||||
->where($search_sql_str)
|
||||
->count();
|
||||
$page_total = ceil($content_num/$this->page_num);;
|
||||
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
||||
->alias('b')
|
||||
->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
|
||||
->where($search_sql_str)
|
||||
->field("b.id,b.title,b.cover as cover_id,c.pic_url as cover_url,b.likes_num,b.create_user_token,b.create_user_head_pic,b.create_user_nickname")
|
||||
->page($data['page'],$this->page_num)
|
||||
->select();
|
||||
|
||||
// 获取用户收藏列表
|
||||
$my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
|
||||
->where(['token'=>$data['token'],'is_del'=>0])
|
||||
->column('cookbook_id');
|
||||
// dump($my_collect_list);
|
||||
// 处理菜谱收藏信息
|
||||
foreach ($content_list as $key => $value) {
|
||||
// if(in_array($value['id'],$my_collect_list)){
|
||||
if(array_key_exists($value['id'],$my_collect_list)){
|
||||
$content_list[$key]['is_me_like_it'] = 'yes';
|
||||
}else{
|
||||
$content_list[$key]['is_me_like_it'] = 'no';
|
||||
}
|
||||
// if($value['cover'] == null){
|
||||
// $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
||||
// }
|
||||
unset($content_list[$key]['ROW_NUMBER']);
|
||||
}
|
||||
|
||||
// foreach ($collect_list as $key => $value) {
|
||||
// $collect_list[$key]['is_me_like_it'] = 'yes';
|
||||
|
||||
// }
|
||||
|
||||
return $this->msg([
|
||||
'page_now'=>$data['page'],
|
||||
'page_total'=>$page_total,
|
||||
'content_list'=>$content_list
|
||||
]);
|
||||
}
|
||||
|
||||
public function del_my_cookbook_action($data){
|
||||
// 获取账号下信息以及用户信息
|
||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
|
||||
if($user_data<=0){
|
||||
return $this->msg(10005,'账号信息错误');
|
||||
}
|
||||
|
||||
$cfc = Db::connect('cfc_db');
|
||||
|
||||
$cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id'],'create_user_token'=>$data['token']])->find();
|
||||
|
||||
if($cookbook_data){
|
||||
|
||||
// 启动事务
|
||||
$cfc->startTrans();
|
||||
try{
|
||||
$cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->update(['is_del'=>1]);
|
||||
$result_banner = $cfc->table($this->kitchenscale_db_msg['banner'])->where(['cookbook_id'=>$cookbook_data['id']])->count();
|
||||
if($result_banner > 0){
|
||||
$cfc->table($this->kitchenscale_db_msg['banner'])->where(['cookbook_id'=>$cookbook_data['id']])->update(['is_del'=>1]);
|
||||
}
|
||||
// 提交事务
|
||||
$cfc->commit();
|
||||
return $this->msg([]);
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
$cfc->rollback();
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}else{
|
||||
return $this->msg(10003);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function del_search_history_action($data){
|
||||
|
||||
// $data['del_arr'] = strval($data['del_arr']);
|
||||
// $data['del_arr'] = trim($data['del_arr']);
|
||||
|
||||
// // 正确的判断逻辑:如果不是all 并且 不是ID列表,就报错
|
||||
// if (strtolower($data['del_arr']) !== 'all' && preg_match('/^\d+(,\d+)*$/', $data['del_arr']) !== 1) {
|
||||
// return $this->msg(10005, 'del_arr type is error');
|
||||
// }
|
||||
|
||||
|
||||
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$user = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token')->find();
|
||||
if(!$user){
|
||||
return $this->msg(20001,'账号信息错误');
|
||||
}
|
||||
if($data['del_arr'] == 'all'){
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['search_history'])
|
||||
->where(['user_id'=>$user['id']])
|
||||
->update(['is_del'=>1]);
|
||||
}else{
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['search_history'])
|
||||
->where("user_id = ".$user['id']." AND id IN (".$data['del_arr'].")")
|
||||
->update(['is_del'=>1]);
|
||||
}
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
|
||||
|
||||
// 获取菜谱分类标签end
|
||||
}
|
||||
|
||||
public function business_cooperation_action(){
|
||||
$data = input();
|
||||
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['business_cooperation'])
|
||||
->insert([
|
||||
'name'=>$data['name'],
|
||||
'tel'=>$data['phone'],
|
||||
'company'=>$data['company'],
|
||||
'intention_data'=> implode(',',$data['selectedValues']),
|
||||
'notes_data'=>$data['remark'],
|
||||
'create_time'=>date('Y-m-s H:i:s'),
|
||||
]);
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function user_that_day_food_count($user_data){
|
||||
$cfc = Db::connect('cfc_db');
|
||||
if($user_data['birthday']){
|
||||
$user_data['age_num'] = $this->calculate_age($user_data['birthday']);
|
||||
}else{
|
||||
$user_data['age_num'] = $user_data['age'];
|
||||
}
|
||||
$nutrition_data = $this->count_user_nutrition_all($user_data);
|
||||
if($user_data['is_use_set_kcal'] == 1){
|
||||
$proportion = bcdiv($user_data['set_kcal'],$nutrition_data['kcal'],20);
|
||||
$nutrition_data['kcal'] = $user_data['set_kcal'];
|
||||
$nutrition_data['carbohydrate'] = bcmul($nutrition_data['carbohydrate'],$proportion,2);
|
||||
$nutrition_data['protein'] = bcmul($nutrition_data['protein'],$proportion,2);
|
||||
$nutrition_data['fat'] = bcmul($nutrition_data['fat'],$proportion,2);
|
||||
|
||||
}
|
||||
$day_time = date('Y-m-d');
|
||||
$return_data = [
|
||||
'date'=>$day_time, //时间
|
||||
'suggestion'=>[ //建议
|
||||
'kcal'=>$nutrition_data['kcal'], //建议摄入卡路里量
|
||||
'carbohydrate'=>$nutrition_data['carbohydrate'], //建议摄入碳水量
|
||||
'protein'=>$nutrition_data['protein'], //建议摄入蛋白质量
|
||||
'fat'=>$nutrition_data['fat'], //建议摄入脂肪量
|
||||
],
|
||||
'today_intake'=>[ //今日已摄入
|
||||
'kcal'=>0, //今日已摄入卡路里量
|
||||
'carbohydrate'=>0, //今日已摄入碳水量
|
||||
'protein'=>0, //今日已摄入蛋白质量
|
||||
'fat'=>0, //今日已摄入脂肪量
|
||||
],
|
||||
'remaining_kcal'=>$nutrition_data['kcal'], //剩下可摄入卡路里量
|
||||
'list'=>[
|
||||
[
|
||||
'name'=>'早餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#0992B4',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png',
|
||||
'icon_home'=>'/static/1.png',
|
||||
'bgimg_home'=>'/static/2.png',
|
||||
'kcal_proportion'=>0,
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'午餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#4F9211',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png',
|
||||
'icon_home'=>'/static/3.png',
|
||||
'bgimg_home'=>'/static/4.png',
|
||||
'kcal_proportion'=>0,
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'晚餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#B354B0',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png',
|
||||
'icon_home'=>'/static/5.png',
|
||||
'bgimg_home'=>'/static/6.png',
|
||||
'kcal_proportion'=>0,
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'加餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#C08433',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png',
|
||||
'icon_home'=>'/static/7.png',
|
||||
'bgimg_home'=>'/static/8.png',
|
||||
'kcal_proportion'=>0,
|
||||
'list'=>[],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// 查询用户今日摄入食物
|
||||
$food_content = $cfc->table($this->kitchenscale_db_msg['eat_log'])
|
||||
->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 = " . $user_data['aud_id'] . " AND CAST(a.create_time AS DATE) = CAST('" . $day_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,a.food_id')
|
||||
->select();
|
||||
|
||||
if(count($food_content) > 0){ //计算营养物质
|
||||
$food_content = $this->calculate_nutrients($food_content);
|
||||
// return $this->msg($food_content);
|
||||
foreach ($food_content as $key => $value) {
|
||||
// dump($value['nutrients_four']);
|
||||
$return_data['today_intake']['kcal'] = bcadd($return_data['today_intake']['kcal'],$value['kcal_val'],2);
|
||||
$return_data['today_intake']['carbohydrate'] = bcadd($return_data['today_intake']['carbohydrate'],$value['carbohydrate_val'],2);
|
||||
$return_data['today_intake']['protein'] = bcadd($return_data['today_intake']['protein'],$value['protein_val'],2);
|
||||
$return_data['today_intake']['fat'] = bcadd($return_data['today_intake']['fat'],$value['fat_val'],2);
|
||||
// 处理各餐
|
||||
if($value['meals_type'] == '早餐'){
|
||||
$return_data['list'][0]['val'] = bcadd($return_data['list'][0]['val'],$value['kcal_val'],2);
|
||||
// $return_data['list'][0]['nutrients_four'][0]['value'] = bcadd($return_data['list'][0]['nutrients_four'][0]['value'],$value['kcal_val'],2);
|
||||
// $return_data['list'][0]['nutrients_four'][1]['value'] = bcadd($return_data['list'][0]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['list'][0]['nutrients_four'][2]['value'] = bcadd($return_data['list'][0]['nutrients_four'][2]['value'],$value['protein_val'],2);
|
||||
// $return_data['list'][0]['nutrients_four'][3]['value'] = bcadd($return_data['list'][0]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][0]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'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);
|
||||
// $return_data['list'][1]['nutrients_four'][0]['value'] = bcadd($return_data['list'][1]['nutrients_four'][0]['value'],$value['kcal_val'],2);
|
||||
// $return_data['list'][1]['nutrients_four'][1]['value'] = bcadd($return_data['list'][1]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['list'][1]['nutrients_four'][2]['value'] = bcadd($return_data['list'][1]['nutrients_four'][2]['value'],$value['protein_val'],2);
|
||||
// $return_data['list'][1]['nutrients_four'][3]['value'] = bcadd($return_data['list'][1]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][1]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'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);
|
||||
// $return_data['list'][2]['nutrients_four'][0]['value'] = bcadd($return_data['list'][2]['nutrients_four'][0]['value'],$value['kcal_val'],2);
|
||||
// $return_data['list'][2]['nutrients_four'][1]['value'] = bcadd($return_data['list'][2]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['list'][2]['nutrients_four'][2]['value'] = bcadd($return_data['list'][2]['nutrients_four'][2]['value'],$value['protein_val'],2);
|
||||
// $return_data['list'][2]['nutrients_four'][3]['value'] = bcadd($return_data['list'][2]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][2]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
// 'nutrients_four' => $value['nutrients_four'],
|
||||
// 'nutrients_list' => $value['nutrients_list']
|
||||
]);
|
||||
}else{
|
||||
$return_data['list'][3]['val'] = bcadd($return_data['list'][3]['val'],$value['kcal_val'],2);
|
||||
// $return_data['list'][3]['nutrients_four'][0]['value'] = bcadd($return_data['list'][3]['nutrients_four'][0]['value'],$value['kcal_val'],2);
|
||||
// $return_data['list'][3]['nutrients_four'][1]['value'] = bcadd($return_data['list'][3]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['list'][3]['nutrients_four'][2]['value'] = bcadd($return_data['list'][3]['nutrients_four'][2]['value'],$value['protein_val'],2);
|
||||
// $return_data['list'][3]['nutrients_four'][3]['value'] = bcadd($return_data['list'][3]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][3]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
// 'nutrients_four' => $value['nutrients_four'],
|
||||
// 'nutrients_list' => $value['nutrients_list']
|
||||
]);
|
||||
}
|
||||
}
|
||||
// dump($return_data['list']);
|
||||
// die;
|
||||
$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;
|
||||
|
||||
$nameMap = [
|
||||
'kcal' => ['卡路里','kcal','https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png','#5180D8'],
|
||||
'carbohydrate' => ['碳水','g','https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','#ED7886'],
|
||||
'protein' => ['蛋白质','g','https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','#FFB169'],
|
||||
'fat' => ['脂肪','g','https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','#3CB383'],
|
||||
];
|
||||
$all_yy_data = bcadd($return_data['suggestion']['fat'],bcadd($return_data['suggestion']['carbohydrate'],$return_data['suggestion']['protein'],20),20);
|
||||
foreach ($return_data['suggestion'] as $key => $value) {
|
||||
$return_data['nutrients_four'][] = [
|
||||
'name'=>$nameMap[$key][0],
|
||||
'unit'=>$nameMap[$key][1],
|
||||
'suggestion'=>$value,
|
||||
'today_intake'=>$return_data['today_intake'][$key],
|
||||
'icon'=>$nameMap[$key][2],
|
||||
'color'=>$nameMap[$key][3],
|
||||
'proportion'=>bcdiv($return_data['today_intake'][$key],$value,2) >= 1?'100':(bcdiv($return_data['today_intake'][$key],$value,2))*100,
|
||||
'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100,
|
||||
];
|
||||
}
|
||||
unset($return_data['suggestion']);
|
||||
unset($return_data['today_intake']);
|
||||
|
||||
|
||||
// // 处理各餐卡路里占比
|
||||
// $return_data = $this->calculate_kcal_proportion($return_data);
|
||||
// // 计算营养物质能量占比
|
||||
// $return_data = $this->calculate_energy_proportion($return_data);
|
||||
// // 排序营养元素食物排行榜
|
||||
// $return_data = $this->energy_food_rank($return_data);
|
||||
// // 微量元素处理全天
|
||||
// $return_data = $this->calculate_trace_elements($return_data);
|
||||
// 处理单餐营养占比
|
||||
// foreach ($return_data['list'] as $key => $value) {
|
||||
// $all_yy_data_0 = bcadd($value['nutrients_four'][3]['value'],bcadd($value['nutrients_four'][1]['value'],$value['nutrients_four'][2]['value'],20),2);
|
||||
// foreach ($value['nutrients_four'] as $k => $v) {
|
||||
// if($k != 0){
|
||||
// if($all_yy_data_0 == 0){
|
||||
// $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = 0;
|
||||
// }else{
|
||||
// $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2) >= 1?'100':(bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2))*100;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
|
||||
|
||||
class Wechat extends Base{
|
||||
// reedaw的小程序信息
|
||||
private $app_id = 'wx1f32af4f93c913f6'; // 轻厨记的微信小程序的AppID
|
||||
private $app_secret = '851f809f6abbbeeeb95d313ada80d025'; // 轻厨记的微信小程序的AppSecret
|
||||
|
||||
// ed7cda5874f0eef3360e782a3db73c80
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
/**
|
||||
* 处理微信登录
|
||||
*
|
||||
* @param string $code 微信登录凭证
|
||||
* @param string $encryptedData 加密的用户信息
|
||||
* @param string $iv 解密算法的初始向量
|
||||
* @return array
|
||||
*/
|
||||
public function handleWechatLogin($code, $encryptedData, $iv)
|
||||
{
|
||||
// try {
|
||||
// 1. 通过code获取openid和session_key
|
||||
$sessionData = $this->getSessionKey($code);
|
||||
|
||||
if (empty($sessionData['openid']) || empty($sessionData['session_key'])) {
|
||||
// throw new Exception('获取openid或session_key失败');
|
||||
// return false;
|
||||
// return $this->msg(10001);
|
||||
return ['code'=>10002,'msg'=>'获取openid或session_key失败'];
|
||||
}
|
||||
|
||||
// 2. 解密用户信息
|
||||
$userInfo = $this->decryptData($encryptedData, $iv, $sessionData['session_key']);
|
||||
|
||||
if(array_key_exists('phoneNumber',$userInfo)){
|
||||
return ['code'=>0,'msg'=>'seccess','data'=>$userInfo];
|
||||
}else{
|
||||
return ['code'=>10002,'msg'=>'解密用户信息失败'];
|
||||
}
|
||||
// if (empty($userInfo['phoneNumber'])) {
|
||||
// // throw new Exception('获取手机号失败');
|
||||
|
||||
// }else{
|
||||
|
||||
// }
|
||||
|
||||
// // 3. 保存或更新用户信息
|
||||
// $user = User::where('openid', $sessionData['openid'])->find();
|
||||
// if (!$user) {
|
||||
// $user = new User();
|
||||
// $user->openid = $sessionData['openid'];
|
||||
// }
|
||||
// $user->phone = $userInfo['phoneNumber'];
|
||||
// $user->save();
|
||||
|
||||
// 返回成功信息
|
||||
// return ['code' => 0, 'msg' => '登录成功', 'data' => $user];
|
||||
// } catch (Exception $e) {
|
||||
// // 返回错误信息
|
||||
// return ['code' => 500, 'msg' => $e->getMessage()];
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* 通过code获取openid和session_key
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getSessionKey($code)
|
||||
{
|
||||
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->app_id}&secret={$this->app_secret}&js_code={$code}&grant_type=authorization_code";
|
||||
$result = file_get_contents($url);
|
||||
$data = json_decode($result, true);
|
||||
|
||||
if (isset($data['openid']) && isset($data['session_key'])) {
|
||||
return $data;
|
||||
} else {
|
||||
return ['code'=>10002,'msg'=>'获取openid或session_key失败'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密用户信息
|
||||
*
|
||||
* @param string $encryptedData
|
||||
* @param string $iv
|
||||
* @param string $sessionKey
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function decryptData($encryptedData, $iv, $sessionKey)
|
||||
{
|
||||
// require_once 'wx_crypt/WXBizDataCrypt.php'; // 引入微信解密类
|
||||
// require_once env('root_path') . 'extend/wx_crypt/WXBizDataCrypt.php';
|
||||
// dump(ROOT_PATH . 'extend\wx_crypt\wxBizDataCrypt.php');
|
||||
require_once ROOT_PATH . 'extend\wx_crypt\wxBizDataCrypt.php';
|
||||
|
||||
$pc = new \WXBizDataCrypt($this->app_id, $sessionKey);
|
||||
$errCode = $pc->decryptData($encryptedData, $iv, $data);
|
||||
|
||||
if ($errCode == 0) {
|
||||
return json_decode($data, true);
|
||||
} else {
|
||||
return ['code'=>10002,'msg'=>'解密用户信息失败('.$errCode.')'];
|
||||
// throw new Exception('解密失败: ' . $errCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 注册
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
<!doctype html>
|
||||
<html class="x-admin-sm">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>图片管理</title>
|
||||
<meta name="renderer" content="webkit|ie-comp|ie-stand">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<meta http-equiv="Cache-Control" content="no-siteapp" />
|
||||
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<style>
|
||||
.content{
|
||||
width: 100%;
|
||||
max-height: 70%;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-content: center;
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
.pic_box_upload{
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
margin: 5px 5px;
|
||||
}
|
||||
.pic_box_upload img{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.pic_box{
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
margin: 5px 5px;
|
||||
}
|
||||
.pic_box:hover {
|
||||
box-shadow: 0px 0px 1px;
|
||||
}
|
||||
.pic_box img{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#fileInput {
|
||||
display: none; /* 隐藏文件输入元素 */
|
||||
}
|
||||
.jz{
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: auto 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="pic_box_upload" onclick="upload_action()"><img src="https://tc.pcxbc.com/tsf/upload_pic.jpg" alt=""></div>
|
||||
{volist name="result" id="vo"}
|
||||
<div class="pic_box" onclick="sendParamToParent('{$vo.id}','{$vo.pic_url}')"><img src="{$vo.pic_url}" alt=""></div>
|
||||
{/volist}
|
||||
</div>
|
||||
<div class="layui-card-body jz">
|
||||
<div id="page" style="text-align: center;">
|
||||
</div>
|
||||
</div>
|
||||
<input type="file" id="fileInput" multiple>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<script>
|
||||
var page_num;
|
||||
var laypage;
|
||||
var all_page = "{$num}";
|
||||
layui.use('laypage', function () {
|
||||
laypage = layui.laypage;
|
||||
laypage.render({
|
||||
elem: 'page',
|
||||
count: all_page, //数据总数,从服务端得到
|
||||
limit: 20,
|
||||
groups:20,
|
||||
jump: function (obj, first) {
|
||||
//首次不执行
|
||||
if (!first) {
|
||||
//obj包含了当前分页的所有参数,比如:
|
||||
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
|
||||
console.log(obj.limit); //得到每页显示的条数
|
||||
page_num = obj.curr;
|
||||
jump_page(page_num)
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
function jump_page(num){
|
||||
load()
|
||||
$.ajax({
|
||||
url: "/k/admin/pic", //请求的url地址s
|
||||
dataType: "json", //返回格式为json
|
||||
async: true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data: {'page': num}, //参数值
|
||||
type: "POST", //请求方式
|
||||
success: function (req) {
|
||||
console.log(req)
|
||||
c_load();
|
||||
if(req['code'] == 0){
|
||||
var str,str_s,str_all="";
|
||||
for (let i = 0; i < req['data']['result'].length; i++) {
|
||||
str = '<div class="pic_box" onclick="sendParamToParent(\''+req['data']['result'][i]['id']+'\',\''+req['data']['result'][i]['url_data']+'\')"><img src="'+req['data']['result'][i]['url_data']+'" alt=""></div>'
|
||||
str_all = str_all+str;
|
||||
}
|
||||
$('.content').each(function() {
|
||||
$(this).find('.pic_box').remove();
|
||||
});
|
||||
$('.content').append(str_all);
|
||||
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
//请求出错处理
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function sendParamToParent(id,data) {
|
||||
var param = [id,data]; // 这是要传递的参数
|
||||
// 调用父窗口的一个函数,并传递参数
|
||||
if (window.parent && window.parent.receiveParamFromIframe) {
|
||||
window.parent.receiveParamFromIframe(param);
|
||||
} else {
|
||||
layer.msg('图片选择失败');
|
||||
}
|
||||
xadmin.close();
|
||||
}
|
||||
function upload_action(){
|
||||
document.getElementById('fileInput').click();
|
||||
}
|
||||
$('#fileInput').on('change', function() {
|
||||
// 获取所有被选择的文件
|
||||
var fileInput = $(this)[0];
|
||||
var files = fileInput.files;
|
||||
// 检查是否有文件被选择
|
||||
if (files.length > 0) {
|
||||
load()
|
||||
var formdata = new FormData();
|
||||
// 添加所有文件到FormData
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
formdata.append('image[]', files[i]); // 注意这里改为数组形式
|
||||
}
|
||||
$.ajax({
|
||||
url:"/k/admin/pic_upload_action", //请求的url地址
|
||||
contentType:false,
|
||||
processData:false,
|
||||
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data:formdata, //参数值
|
||||
type:"POST", //请求方式
|
||||
success:function(req){
|
||||
c_load()
|
||||
//请求成功时处理
|
||||
if(req.code == 0){
|
||||
var content = '<div style="padding:20px;">';
|
||||
content += '<p>成功上传:' + req.data.success + '个文件</p>';
|
||||
if (req.data.error_data && req.data.error_data.length > 0) {
|
||||
content += '<p>失败文件:</p><ul style="margin-left:20px;">';
|
||||
req.data.error_data.forEach(function(item) {
|
||||
content += '<li>' + item.pic_name + ' (' + item.error_msg + ')</li>';
|
||||
});
|
||||
content += '</ul>';
|
||||
}
|
||||
content += '</div>';
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '上传结果',
|
||||
area: ['500px', '300px'], // 宽高
|
||||
content: content,
|
||||
btn: ['确定'],
|
||||
yes: function(index, layero) {
|
||||
window.location.reload();
|
||||
},
|
||||
cancel: function() {
|
||||
window.location.reload(); // 点击右上角关闭也刷新
|
||||
}
|
||||
});
|
||||
}else{
|
||||
layer.msg(req.msg);
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
//请求出错处理
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
//加载提示开启
|
||||
function load() {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
}
|
||||
// 关闭加载提示
|
||||
function c_load() {
|
||||
layer.close(layer.index)
|
||||
}
|
||||
</script>
|
||||
|
|
@ -0,0 +1,420 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="x-admin-sm">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>菜谱管理</title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
|
||||
<style>
|
||||
.step-container {
|
||||
display: flex;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #eee;
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.step-content {
|
||||
flex: 1;
|
||||
padding-right: 15px;
|
||||
}
|
||||
.step-image {
|
||||
width: 200px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.step-preview {
|
||||
max-width: 100%;
|
||||
max-height: 150px;
|
||||
margin-bottom: 10px;
|
||||
display: none;
|
||||
}
|
||||
.step-buttons {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-row">
|
||||
<form class="layui-form layui-form-pane">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" style="width: 120px; text-align: right;">
|
||||
<span class="x-red">☆</span>菜谱标题
|
||||
</label>
|
||||
<div class="layui-input-inline" style="width: 80%;">
|
||||
<input type="text" id="recipe_title" name="recipe_title" required lay-verify="required" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<!-- 图片选择器html部分 -->
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" style="width: 120px; text-align: right;">
|
||||
<span class="x-red">★</span>选择封面
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<div class="layui-btn" onclick="openImageManager('preview_img', 'cove_img')">点击选择</div>
|
||||
<input type="hidden" id="cove_img" name="cove_img">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" style="width: 120px; text-align: right;">
|
||||
<span class="x-red"></span>预览
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<img id="preview_img" style="max-width: 200px; display: none; border: 1px solid #eee; margin-top: 10px;" src="" alt="">
|
||||
</div>
|
||||
</div>
|
||||
<!-- 图片选择器html部分 -->
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" style="width: 120px; text-align: right;">
|
||||
<span class="x-red">☆</span>菜谱类型
|
||||
</label>
|
||||
<div class="layui-input-inline" style="width: 80%;">
|
||||
<select name="recipe_type" lay-verify="required" id="recipe_type">
|
||||
<option value="0">请选择菜谱类型</option>
|
||||
{volist name="result" id="vo"}
|
||||
<option value="{$vo.id}">{$vo.name}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" style="width: 120px; text-align: right;">
|
||||
<span class="x-red">☆</span>菜谱描述
|
||||
</label>
|
||||
<div class="layui-input-inline" style="width: 80%;">
|
||||
<textarea name="recipe_desc" id="recipe_desc" required lay-verify="required" placeholder="请输入菜谱描述" class="layui-textarea"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" style="width: 120px; text-align: right;">
|
||||
<span class="x-red">☆</span>食材
|
||||
</label>
|
||||
<div class="layui-input-inline" style="width: 80%;">
|
||||
<div id="ingredients_container">
|
||||
<div class="layui-form-item ingredient-item" style="margin-bottom: 10px;">
|
||||
<div class="layui-inline">
|
||||
<input type="text" name="ingredient_name[]" placeholder="食材名称" autocomplete="off" class="layui-input ingredient-name" style="width: 150px; display: inline-block;">
|
||||
<div class="ingredient-suggest" style="position: absolute; z-index: 999; display: none; width: 150px; max-height: 200px; overflow-y: auto; border: 1px solid #d2d2d2; background: #fff;"></div>
|
||||
<input type="text" name="ingredient_amount[]" placeholder="用量(g)" autocomplete="off" class="layui-input" style="width: 100px; display: inline-block; margin-left: 10px;">
|
||||
<button type="button" class="layui-btn layui-btn-danger layui-btn-xs remove-ingredient" style="margin-left: 10px;">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" id="add_ingredient" class="layui-btn layui-btn-xs">添加食材</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label" style="width: 120px; text-align: right;">
|
||||
<span class="x-red">☆</span>步骤
|
||||
</label>
|
||||
<div class="layui-input-inline" style="width: 80%;">
|
||||
<div id="steps_container">
|
||||
<div class="step-container">
|
||||
<div class="step-content">
|
||||
<label class="layui-form-label" style="width: auto; padding: 9px 5px; text-align: left;">步骤1</label>
|
||||
<textarea name="step_desc[]" placeholder="请输入步骤描述" class="layui-textarea"></textarea>
|
||||
</div>
|
||||
<div class="step-image">
|
||||
<img class="step-preview" src="" alt="步骤图片预览">
|
||||
<input type="hidden" class="step-image-id" name="step_image[]" value="">
|
||||
<div class="step-buttons">
|
||||
<button type="button" class="layui-btn layui-btn-xs select-step-image">选择图片</button>
|
||||
<button type="button" class="layui-btn layui-btn-danger layui-btn-xs remove-step">删除步骤</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" id="add_step" class="layui-btn layui-btn-xs">添加步骤</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item" style="display: flex;flex-direction: row;justify-content: center;">
|
||||
<button class="layui-btn" lay-filter="add" lay-submit="" style="width: 150px;">增加</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// 图片选择器js部分~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// 全局变量存储当前操作的预览和隐藏字段ID
|
||||
var currentImageSelection = {
|
||||
previewId: '',
|
||||
hiddenFieldId: ''
|
||||
};
|
||||
// 打开图片管理器函数
|
||||
function openImageManager(previewId, hiddenFieldId) {
|
||||
// 存储当前操作的ID
|
||||
currentImageSelection.previewId = previewId;
|
||||
currentImageSelection.hiddenFieldId = hiddenFieldId;
|
||||
|
||||
// 打开图片管理窗口
|
||||
xadmin.open('图片管理', '/k/admin/pic', '80%', '80%');
|
||||
}
|
||||
// 接收从图片管理窗口返回的参数
|
||||
function receiveParamFromIframe(param) {
|
||||
if(param.length > 0 && currentImageSelection.previewId && currentImageSelection.hiddenFieldId){
|
||||
// 更新预览图片
|
||||
var img = document.getElementById(currentImageSelection.previewId);
|
||||
img.src = param[1];
|
||||
img.style.display = 'block';
|
||||
|
||||
// 更新隐藏字段值
|
||||
document.getElementById(currentImageSelection.hiddenFieldId).value = param[0];
|
||||
|
||||
// 重置当前操作的ID
|
||||
currentImageSelection.previewId = '';
|
||||
currentImageSelection.hiddenFieldId = '';
|
||||
} else {
|
||||
layer.msg('图片选择失败');
|
||||
}
|
||||
}
|
||||
// 图片选择器js部分~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
$(document).ready(function(){
|
||||
var stepCounter = 1;
|
||||
var ingredientCounter = 1;
|
||||
|
||||
// 添加食材
|
||||
$('#add_ingredient').on('click', function() {
|
||||
ingredientCounter++;
|
||||
var html = `
|
||||
<div class="layui-form-item ingredient-item" style="margin-bottom: 10px;">
|
||||
<div class="layui-inline">
|
||||
<input type="text" name="ingredient_name[]" placeholder="食材名称" autocomplete="off" class="layui-input ingredient-name" style="width: 150px; display: inline-block;">
|
||||
<div class="ingredient-suggest" style="position: absolute; z-index: 999; display: none; width: 150px; max-height: 200px; overflow-y: auto; border: 1px solid #d2d2d2; background: #fff;"></div>
|
||||
<input type="text" name="ingredient_amount[]" placeholder="用量(g)" autocomplete="off" class="layui-input" style="width: 100px; display: inline-block; margin-left: 10px;">
|
||||
<button type="button" class="layui-btn layui-btn-danger layui-btn-xs remove-ingredient" style="margin-left: 10px;">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
$('#ingredients_container').append(html);
|
||||
});
|
||||
|
||||
// 食材名称输入自动完成
|
||||
$(document).on('input', '.ingredient-name', function() {
|
||||
var input = $(this);
|
||||
var keyword = input.val().trim();
|
||||
var suggestBox = input.next('.ingredient-suggest');
|
||||
|
||||
if (keyword.length < 1) {
|
||||
suggestBox.hide();
|
||||
return;
|
||||
}
|
||||
console.log(keyword)
|
||||
// 发送AJAX请求
|
||||
$.ajax({
|
||||
url: '/k/a/cookbook/find_food_list',
|
||||
dataType:"json", //返回格式为json
|
||||
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data:{"id":"value"}, //参数值
|
||||
data: {'search_data': keyword},
|
||||
type: 'POST',
|
||||
success: function(res) {
|
||||
if (res.code === 0 && res.data && res.data.length > 0) {
|
||||
var html = '';
|
||||
res.data.forEach(function(item) {
|
||||
html += '<div class="suggest-item" style="padding: 5px 10px; cursor: pointer;" data-id="' + item.id + '" data-name="' + item.food_name + '" data-kcal="' + item.Calorie_val + '">' + item.food_name + '</div>';
|
||||
});
|
||||
suggestBox.html(html).show();
|
||||
} else {
|
||||
suggestBox.hide();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
suggestBox.hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 点击建议项填充到输入框
|
||||
$(document).on('click', '.suggest-item', function() {
|
||||
var id = $(this).data('id');
|
||||
var name = $(this).data('name');
|
||||
var kcal = $(this).data('kcal');
|
||||
|
||||
var parentDiv = $(this).closest('.layui-inline');
|
||||
parentDiv.find('.ingredient-name').val(name).data('id', id).data('kcal', kcal);
|
||||
parentDiv.find('.ingredient-suggest').hide();
|
||||
});
|
||||
|
||||
// 点击其他地方隐藏建议框并清空输入框
|
||||
$(document).on('click', function(e) {
|
||||
if (!$(e.target).closest('.ingredient-suggest').length && !$(e.target).hasClass('ingredient-name')) {
|
||||
$('.ingredient-suggest').hide();
|
||||
// 清空未选择食材的输入框
|
||||
$('.ingredient-name').each(function() {
|
||||
if (!$(this).data('id')) { // 如果没有选择过食材(没有data-id)
|
||||
$(this).val(''); // 清空输入框
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 删除食材
|
||||
$(document).on('click', '.remove-ingredient', function() {
|
||||
if($('.ingredient-item').length > 1) {
|
||||
$(this).closest('.ingredient-item').remove();
|
||||
} else {
|
||||
layer.msg('至少保留一个食材');
|
||||
}
|
||||
});
|
||||
|
||||
// 添加步骤
|
||||
$('#add_step').on('click', function() {
|
||||
stepCounter++;
|
||||
var html = `
|
||||
<div class="step-container">
|
||||
<div class="step-content">
|
||||
<label class="layui-form-label" style="width: auto; padding: 9px 5px; text-align: left;">步骤${stepCounter}</label>
|
||||
<textarea name="step_desc[]" placeholder="请输入步骤描述" class="layui-textarea"></textarea>
|
||||
</div>
|
||||
<div class="step-image">
|
||||
<img class="step-preview" src="" alt="步骤图片预览">
|
||||
<input type="hidden" class="step-image-id" name="step_image[]" value="">
|
||||
<div class="step-buttons">
|
||||
<button type="button" class="layui-btn layui-btn-xs select-step-image">选择图片</button>
|
||||
<button type="button" class="layui-btn layui-btn-danger layui-btn-xs remove-step">删除步骤</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
$('#steps_container').append(html);
|
||||
});
|
||||
|
||||
// 为步骤选择图片
|
||||
$(document).on('click', '.select-step-image', function() {
|
||||
var container = $(this).closest('.step-container');
|
||||
var previewImg = container.find('.step-preview');
|
||||
var hiddenInput = container.find('.step-image-id');
|
||||
|
||||
// 为元素设置唯一ID
|
||||
var previewId = 'step-preview-' + Math.random().toString(36).substr(2, 9);
|
||||
var hiddenId = 'step-image-' + Math.random().toString(36).substr(2, 9);
|
||||
|
||||
previewImg.attr('id', previewId);
|
||||
hiddenInput.attr('id', hiddenId);
|
||||
|
||||
// 打开图片管理器
|
||||
openImageManager(previewId, hiddenId);
|
||||
});
|
||||
|
||||
// 删除步骤
|
||||
$(document).on('click', '.remove-step', function() {
|
||||
if($('.step-container').length > 1) {
|
||||
$(this).closest('.step-container').remove();
|
||||
// 重新编号步骤
|
||||
$('.step-container').each(function(index) {
|
||||
$(this).find('.layui-form-label').text('步骤' + (index + 1));
|
||||
});
|
||||
stepCounter--;
|
||||
} else {
|
||||
layer.msg('至少保留一个步骤');
|
||||
}
|
||||
});
|
||||
|
||||
// 表单提交时收集数据
|
||||
layui.use(['form', 'layer'], function() {
|
||||
var form = layui.form,
|
||||
layer = layui.layer;
|
||||
|
||||
// 监听提交
|
||||
form.on('submit(add)', function(data) {
|
||||
// 显示加载中
|
||||
var loadIndex = layer.load(1);
|
||||
|
||||
// 收集表单数据
|
||||
var formData = {
|
||||
cook_label: $('#recipe_type').val(),
|
||||
title: $('#recipe_title').val(),
|
||||
description: $('#recipe_desc').val(),
|
||||
cover: $('#cove_img').val(), // 封面图片ID
|
||||
foodList: [],
|
||||
stepList: []
|
||||
};
|
||||
|
||||
// 收集食材数据
|
||||
$('.ingredient-item').each(function() {
|
||||
var nameInput = $(this).find('.ingredient-name');
|
||||
var amountInput = $(this).find('input[placeholder="用量(g)"]');
|
||||
|
||||
var id = nameInput.data('id');
|
||||
var name = nameInput.val();
|
||||
var weight = amountInput.val();
|
||||
|
||||
if (id && name && weight && weight > 0) {
|
||||
formData.foodList.push({
|
||||
id: id,
|
||||
name: name,
|
||||
weight: weight
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 收集步骤数据
|
||||
$('.step-container').each(function() {
|
||||
var desc = $(this).find('textarea').val();
|
||||
var imageId = $(this).find('.step-image-id').val();
|
||||
|
||||
if (desc && desc.trim() !== '') {
|
||||
formData.stepList.push({
|
||||
pic_list: [imageId] || [],
|
||||
description: desc.trim()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 调试输出
|
||||
console.log('提交数据:', formData);
|
||||
|
||||
// 发送AJAX请求
|
||||
$.ajax({
|
||||
url: "/k/a/cookbook/add_cookbook_action",
|
||||
type: "POST",
|
||||
data: JSON.stringify(formData),
|
||||
contentType: "application/json",
|
||||
success: function(res) {
|
||||
layer.close(loadIndex);
|
||||
if (res.code === 0) {
|
||||
layer.alert("添加成功", {icon: 1}, function() {
|
||||
xadmin.close();
|
||||
xadmin.father_reload();
|
||||
});
|
||||
} else {
|
||||
layer.alert("添加失败:" + res.msg, {icon: 2});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
layer.close(loadIndex);
|
||||
layer.alert("请求失败,请稍后再试", {icon: 2});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
//加载提示开启
|
||||
function load() {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
}
|
||||
// 关闭加载提示
|
||||
function c_load() {
|
||||
layer.close(layer.index)
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="x-admin-sm">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>app版本管理</title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
|
||||
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-row">
|
||||
<form class="layui-form">
|
||||
<div class="layui-form-item">
|
||||
<label for="L_email" class="layui-form-label">
|
||||
<span class="x-red"></span>卡片图标</label>
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<!-- <input type="text" id="L_email" name="email" required="" lay-verify="email" autocomplete="off" class="layui-input"> -->
|
||||
<input type="file" id="upload_file_app" lay-verify="upload_file_app" name="file_data">
|
||||
</div>
|
||||
<!-- <div class="layui-form-mid layui-word-aux">
|
||||
<span class="x-red">*</span>将会成为您唯一的登入名
|
||||
</div> -->
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="card_name" class="layui-form-label">
|
||||
<span class="x-red"></span>卡片名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="card_name" name="card_name" required="" lay-verify="card_name" autocomplete="off" class="layui-input" value="{$result.name}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="page_url_record" class="layui-form-label">
|
||||
<span class="x-red">*</span>手动记录路径</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="page_url_record" name="page_url_record" required="" lay-verify="page_url_record" autocomplete="off" class="layui-input" value="{$result.page_url_record}"></div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="page_url_report" class="layui-form-label">
|
||||
<span class="x-red">*</span>报告页路径</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="page_url_report" name="page_url_report" required="" lay-verify="page_url_report" autocomplete="off" class="layui-input" value="{$result.page_url_report}"></div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="page_url_bluetooth" class="layui-form-label">
|
||||
<span class="x-red">*</span>蓝牙路径</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="page_url_bluetooth" name="page_url_bluetooth" required="" lay-verify="page_url_bluetooth" autocomplete="off" class="layui-input" value="{$result.page_url_bluetooth}"></div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="content" class="layui-form-label">
|
||||
<span class="x-red">*</span>描述</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="content" name="content" required="" lay-verify="content" autocomplete="off" class="layui-input" value="{$result.content}"></div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="L_repass" class="layui-form-label"></label>
|
||||
<!-- <div class="layui-btn" id="add" lay-filter="add" lay-submit="">增加</div>
|
||||
<input value="登录" lay-submit lay-filter="add" type="submit" class="layui-btn"> -->
|
||||
<button class="layui-btn" lay-filter="add" lay-submit="">修改</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="layui-fluid">
|
||||
<div id="official_1" class="layui-row">
|
||||
<div style="margin-left: 8%;margin-top: 5%;font-size: 25px;">请先下载模板文件,信息填写完成并上传该文件后点击生成</div>
|
||||
<img style="width: 90%;margin-left: 3%;"src="/uploads/code_demo.png?v=1.0" alt="">
|
||||
<div class="layui-form-item" style="width: 30%;margin-left: 33%;margin-top: 5%;">
|
||||
<span>步骤1:</span><a href="/uploads/code_demo.xlsx" class="layui-btn" lay-filter="add">下载模板文件</a>
|
||||
</div>
|
||||
<div class="layui-form-item" style="width: 50%;margin-left: 33%;margin-top: 5%;">
|
||||
<span>步骤2:</span><input type="file" id="data_excel" name="data_excel">
|
||||
</div>
|
||||
<div class="layui-form-item" style="width: 30%;margin-left: 33%;margin-top: 5%;">
|
||||
<span>步骤3:</span><button class="layui-btn" lay-filter="add" lay-submit="" onclick="add_data()">生成</button>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
var id = "{$result.id}"
|
||||
var file_name_all = ''
|
||||
var file_name = ''
|
||||
var file_extension = ''
|
||||
var pd = true
|
||||
|
||||
$('#upload_file_app').on('change', function() {
|
||||
// 获取被选择的文件
|
||||
var fileInput = $(this)[0];
|
||||
var file = fileInput.files[0];
|
||||
|
||||
// 检查是否有文件被选择
|
||||
if (file) {
|
||||
// 获取文件的名称
|
||||
file_name_all = file.name;
|
||||
// 使用lastIndexOf和substring来获取文件名(不包括后缀)
|
||||
var lastIndex = file_name_all.lastIndexOf('.');
|
||||
file_name = lastIndex !== -1 ? file_name_all.substring(0, lastIndex) : file_name_all;
|
||||
// 获取文件后缀
|
||||
file_extension = lastIndex !== -1 ? file_name_all.substring(lastIndex + 1) : '';
|
||||
$('#file_name').val(file_name)
|
||||
// console.log($('#upload_file_app')[0].files[0])
|
||||
// formdata.append('apk',$('#upload_file_app')[0].files[0])
|
||||
}
|
||||
});
|
||||
|
||||
function edit_data(){
|
||||
if(pd === false){
|
||||
return
|
||||
}
|
||||
var formdata = new FormData();
|
||||
formdata.append('upload_file_app',$('#upload_file_app')[0].files[0])
|
||||
formdata.append('card_name',$('#card_name').val())
|
||||
formdata.append('page_url_record',$('#page_url_record').val())
|
||||
formdata.append('page_url_report',$('#page_url_report').val())
|
||||
formdata.append('page_url_bluetooth',$('#page_url_bluetooth').val())
|
||||
formdata.append('content',$('#content').val())
|
||||
formdata.append('file_extension',file_extension)
|
||||
formdata.append('id',id)
|
||||
load()
|
||||
pd = false
|
||||
console.log('进来了')
|
||||
$.ajax({
|
||||
url:"/card/card_edit_action", //请求的url地址
|
||||
contentType:false,
|
||||
processData:false,
|
||||
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data:formdata, //参数值
|
||||
type:"POST", //请求方式
|
||||
success:function(req){
|
||||
c_load()
|
||||
pd = true
|
||||
if(req.code == 0){
|
||||
layer.alert("修改成功", {icon: 6},function() {
|
||||
//关闭当前frame
|
||||
xadmin.close();
|
||||
// 可以对父窗口进行刷新
|
||||
xadmin.father_reload();
|
||||
});
|
||||
}else{
|
||||
layer.alert("修改失败"+req.msg, {icon: 6},function() {
|
||||
//关闭当前frame
|
||||
xadmin.close();
|
||||
// 可以对父窗口进行刷新
|
||||
xadmin.father_reload();
|
||||
});
|
||||
}
|
||||
//请求成功时处理
|
||||
|
||||
console.log(req)
|
||||
},
|
||||
error:function(){
|
||||
//请求出错处理
|
||||
pd = true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
layui.use(['form', 'layer','jquery'],function() {
|
||||
$ = layui.jquery;
|
||||
var form = layui.form,
|
||||
layer = layui.layer;
|
||||
|
||||
//自定义验证规则
|
||||
form.verify({
|
||||
|
||||
// upload_file_app: function(value) {
|
||||
// if (value == '') {
|
||||
// return '请先选择文件';
|
||||
// }
|
||||
// },
|
||||
file_name: function(value) {
|
||||
if (value == '') {
|
||||
return '必须填写文件名';
|
||||
}
|
||||
},
|
||||
// version_num: [/[\d.]{0,9}$/, '版本号必须以大写V开头最多10个字符(由数字跟英文"."组成)'],
|
||||
content: function(value) {
|
||||
if (value == '') {
|
||||
return '必须填写描述';
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
//监听提交
|
||||
form.on('submit(add)',function(data) {
|
||||
//发异步,把数据提交给php
|
||||
edit_data()
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
//加载提示开启
|
||||
function load() {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
}
|
||||
// 关闭加载提示
|
||||
function c_load() {
|
||||
layer.close(layer.index)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// });
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -0,0 +1,288 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="x-admin-sm">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>所有卡片管理</title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<style>
|
||||
/* th{
|
||||
min-width:30px;
|
||||
} */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="x-nav">
|
||||
<span class="layui-breadcrumb">
|
||||
<a href="">首页</a>
|
||||
<a href="">演示</a>
|
||||
<a>
|
||||
<cite>导航元素</cite></a>
|
||||
</span>
|
||||
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
|
||||
<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
|
||||
</div>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-row layui-col-space15">
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-card">
|
||||
<!-- <div class="layui-card-body ">
|
||||
<form class="layui-form layui-col-space5">
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="s_time">
|
||||
</div>
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="e_time">
|
||||
</div>
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<input type="text" name="username" placeholder="请输入用户手机" autocomplete="off" class="layui-input" id="tel">
|
||||
</div>
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<input type="text" name="username" placeholder="请输入用户邮箱" autocomplete="off" class="layui-input" id="email">
|
||||
</div>
|
||||
<div class="layui-input-inline layui-show-xs-block">
|
||||
<select name="contrller" id="status_num">
|
||||
<option value="">状态</option>
|
||||
<option value="0">启用</option>
|
||||
<option value="1">停用</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<div class="layui-btn" lay-submit="" lay-filter="sreach" onclick="find('y')"><i class="layui-icon"></i></div>
|
||||
</div>
|
||||
</form>
|
||||
</div> -->
|
||||
<div class="layui-card-header">
|
||||
<!-- <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量停用</button> -->
|
||||
<!-- <button class="layui-btn" onclick="xadmin.open('添加用户','/appversion/app_add','100%','100%')"><i class="layui-icon"></i>添加</button> -->
|
||||
<button class="layui-btn" onclick="xadmin.open('添加版本','/k/a/cookbook/add_cookbook','100%','100%')"><i class="layui-icon"></i>添加</button>
|
||||
</div>
|
||||
<div class="layui-card-body layui-table-body layui-table-main">
|
||||
<table class="layui-table layui-form">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>食谱名称</th>
|
||||
<th>预览图</th>
|
||||
<th>创建人</th>
|
||||
<th>点赞数</th>
|
||||
<th>阅读数</th>
|
||||
<th>创建时间</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody id='content'>
|
||||
{volist name="result" id="vo"}
|
||||
<tr>
|
||||
<td>{$vo.id}</td>
|
||||
<td>{$vo.title}</td>
|
||||
<th><img style="height: 100px;" src="{$vo.pic_url}" alt=""></th>
|
||||
<td>{$vo.create_user_nickname}</td>
|
||||
<td>{$vo.likes_num}</td>
|
||||
<td>{$vo.read_it}</td>
|
||||
<td>{$vo.create_time}</td>
|
||||
<td class="td-status">
|
||||
{if condition="$vo.is_del == 1"}
|
||||
<span onclick="app_stop(this,'{$vo.id}')" class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled" title="停用">已停用</span>
|
||||
{else /}
|
||||
<span onclick="app_stop(this,'{$vo.id}')" class="layui-btn layui-btn-normal layui-btn-mini" title="启用">已启用</span>
|
||||
{/if}
|
||||
</td>
|
||||
<td>
|
||||
<!-- <button class="layui-btn" onclick="xadmin.open('修改','/card/card_edit?id={$vo.id}','80%','60%')">修改</button> -->
|
||||
</td>
|
||||
</tr>
|
||||
{/volist}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="layui-card-body ">
|
||||
<div id="page" style="text-align: center;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
var form
|
||||
layui.use(['laydate','form'], function(){
|
||||
var laydate = layui.laydate;
|
||||
form = layui.form;
|
||||
});
|
||||
var page_num;
|
||||
var laypage;
|
||||
var all_page = "{$num}";
|
||||
layui.use('laypage', function () {
|
||||
laypage = layui.laypage;
|
||||
//执行一个laypage实例
|
||||
laypage.render({
|
||||
elem: 'page',
|
||||
count: all_page, //数据总数,从服务端得到
|
||||
limit: 15,
|
||||
groups:5, //显示几个分页按钮
|
||||
jump: function (obj, first) {
|
||||
//首次不执行
|
||||
if (!first) {
|
||||
//obj包含了当前分页的所有参数,比如:
|
||||
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
|
||||
console.log(obj.limit); //得到每页显示的条数
|
||||
page_num = obj.curr;
|
||||
find("n")
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*用户-停用*/
|
||||
function app_stop(obj,id){
|
||||
|
||||
// return
|
||||
var title = '',status,num
|
||||
if($(obj).attr('title')=='启用'){
|
||||
title = '停用'
|
||||
status = 1
|
||||
num = 5
|
||||
}else{
|
||||
title = '启用'
|
||||
status = 0
|
||||
num = 6
|
||||
}
|
||||
// console.log('点击时'+$(obj).attr('title')+'====='+id+'===传到后台是否删除:'+is_del)
|
||||
layer.confirm('确认要'+ title +'吗?',function(index){
|
||||
load()
|
||||
$.ajax({
|
||||
url:"/k/a/cookbook/stop_and_run", //请求的url地址
|
||||
dataType:"json", //返回格式为json
|
||||
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data:{"id":id,'status':status}, //参数值
|
||||
type:"POST", //请求方式
|
||||
success:function(req){
|
||||
c_load()
|
||||
//请求成功时处理
|
||||
if(req['code'] == 0){
|
||||
//发异步把用户状态进行更改
|
||||
$(obj).attr('title',title)
|
||||
if(status == 1){
|
||||
$(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已'+ title);
|
||||
}else{
|
||||
$(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已'+ title);
|
||||
}
|
||||
layer.msg('已'+ title,{icon: num});
|
||||
}else{
|
||||
layer.msg('操作失败!',{icon: 5});
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
//请求出错处理
|
||||
}});
|
||||
});
|
||||
}
|
||||
|
||||
function find(pd) {
|
||||
if(!page_num || pd == 'y'){
|
||||
page_num = 1;
|
||||
}
|
||||
|
||||
page({
|
||||
"status_num":$('#status_num').val(),
|
||||
"tel":$('#tel').val(),
|
||||
"email":$('#email').val(),
|
||||
"s_time":$('#s_time').val(),
|
||||
"e_time":$('#e_time').val(),
|
||||
"page_num":page_num,
|
||||
"tt":1},pd);
|
||||
}
|
||||
function page(data,pd) {
|
||||
console.log(data)
|
||||
load()
|
||||
$.ajax({
|
||||
url: "/k/a/cookbook/index", //请求的url地址s
|
||||
dataType: "json", //返回格式为json
|
||||
async: true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data: data, //参数值
|
||||
type: "POST", //请求方式
|
||||
success: function (req) {
|
||||
console.log(req)
|
||||
c_load();
|
||||
if (req['code'] == 0) {
|
||||
|
||||
var str,str_s,str_c,str_all="";
|
||||
|
||||
for (let i = 0; i < req['data']['data'].length; i++) {
|
||||
if(req['data']['data'][i]['is_del'] == 1){
|
||||
str = '<span onclick="app_stop(this,\''+req['data']['data'][i]['id']+'\')" class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled" title="停用">已停用</span>'
|
||||
}else{
|
||||
str = '<span onclick="app_stop(this,\''+ req['data']['data'][i]['id'] +'\')" class="layui-btn layui-btn-normal layui-btn-mini" title="启用">已启用</span>'
|
||||
}
|
||||
str_c = '<tr>'+
|
||||
'<td>'+req['data']['data'][i]['id']+'</td>'+
|
||||
'<td>'+req['data']['data'][i]['title']+'</td>'+
|
||||
'<td><img style="height: 100px;" src="'+req['data']['data'][i]['pic_url']+'" alt=""></td>'+
|
||||
'<td>'+req['data']['data'][i]['create_user_nickname']+'</td>'+
|
||||
'<td>'+req['data']['data'][i]['likes_num']+'</td>'+
|
||||
'<td>'+req['data']['data'][i]['read_it']+'</td>'+
|
||||
'<td>'+req['data']['data'][i]['create_time']+'</td>'+
|
||||
'<td class="td-status">'+
|
||||
str+
|
||||
'</td>'+
|
||||
// '<td>'+
|
||||
// '<button class="layui-btn" onclick="xadmin.open(\'修改\',\'/card/card_edit?id={$vo.id}\',\'80%\',\'60%\')">修改</button>'+
|
||||
// '</td>'+
|
||||
'</tr>'
|
||||
str_all = str_all+str_c;
|
||||
}
|
||||
console.log(str_all)
|
||||
$('#content').html(str_all);
|
||||
|
||||
form.render();
|
||||
if(pd == 'y'){
|
||||
$("#page").html("")
|
||||
laypage.render({
|
||||
elem: 'page',
|
||||
count: req['data']['num'], //数据总数,从服务端得到
|
||||
limit: 10,
|
||||
groups:10,
|
||||
jump: function (obj, first) {
|
||||
//首次不执行
|
||||
if (!first) {
|
||||
//obj包含了当前分页的所有参数,比如:
|
||||
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
|
||||
console.log(obj.limit); //得到每页显示的条数
|
||||
page_num = obj.curr;
|
||||
// page({"page":page_num,"tt":1});
|
||||
find("n")
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
layer.msg(req['msg'])
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
//请求出错处理
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//加载提示开启
|
||||
function load() {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
}
|
||||
// 关闭加载提示
|
||||
function c_load() {
|
||||
layer.close(layer.index)
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,230 @@
|
|||
<!doctype html>
|
||||
<html class="x-admin-sm">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>后台登录-X-admin2.2</title>
|
||||
<meta name="renderer" content="webkit|ie-comp|ie-stand">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<meta http-equiv="Cache-Control" content="no-siteapp" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<!-- <link rel="stylesheet" href="./css/theme5.css"> -->
|
||||
<script src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<script>
|
||||
// 是否开启刷新记忆tab功能
|
||||
// var is_remember = false;
|
||||
</script>
|
||||
</head>
|
||||
<body class="index">
|
||||
<!-- 顶部开始 -->
|
||||
<div class="container">
|
||||
<div class="logo">
|
||||
<a href="./index.html">X-admin v2.2</a></div>
|
||||
<div class="left_open">
|
||||
<a><i title="展开左侧栏" class="iconfont"></i></a>
|
||||
</div>
|
||||
|
||||
<ul class="layui-nav right" lay-filter="">
|
||||
<li class="layui-nav-item">
|
||||
<a href="javascript:;">admin</a>
|
||||
<dl class="layui-nav-child">
|
||||
<!-- 二级菜单 -->
|
||||
<dd>
|
||||
<a onclick="xadmin.open('切换帐号','http://www.baidu.com')">切换帐号</a></dd>
|
||||
<dd>
|
||||
<a href="./login.html">退出</a></dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- 顶部结束 -->
|
||||
<!-- 中部开始 -->
|
||||
<!-- 左侧菜单开始 -->
|
||||
<div class="left-nav">
|
||||
<div id="side-nav">
|
||||
<ul id="nav">
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="食谱管理"></i>
|
||||
<cite>食谱管理</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('食谱列表','/k/a/cookbook/index')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>食谱列表</cite></a>
|
||||
</li>
|
||||
<!-- <li>
|
||||
<a onclick="xadmin.add_tab('APP角色数据列表','/member/user_list')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>APP角色数据列表</cite></a>
|
||||
</li>
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('APP角色数据列表','/member/user_list')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>角色使用记录查询</cite></a>
|
||||
</li> -->
|
||||
</ul>
|
||||
</li>
|
||||
<!-- <li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="卡片管理"></i>
|
||||
<cite>卡片管理</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('所有卡片管理','/card/index')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>所有卡片管理</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="设备管理"></i>
|
||||
<cite>设备管理</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('所有设备管理','/device/index')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>设备管理</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="估分功能管理"></i>
|
||||
<cite>估分功能管理</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('地市规则列表','/estimate/index')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>地市规则列表</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="APP版本管理"></i>
|
||||
<cite>APP版本管理</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('APP版本管理','/appversion/index')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>APP版本管理</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="资讯管理"></i>
|
||||
<cite>资讯管理</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('资讯推荐栏管理','/editortext/index')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>资讯推荐栏管理</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="Banner图&公告管理"></i>
|
||||
<cite>Banner图&公告&弹窗</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('操作管理','/notice/banner_index')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>操作管理</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="商业合作"></i>
|
||||
<cite>商业合作</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('操作管理','/business/business_index')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>操作管理</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont left-nav-li" lay-tips="厨房秤"></i>
|
||||
<cite>厨房秤</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont"></i>
|
||||
<cite>食材管理</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('食材列表','/kitchenscale/food_ingredients_index_1')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>食材列表</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a href="javascript:;">
|
||||
<i class="iconfont"></i>
|
||||
<cite>菜谱管理</cite>
|
||||
<i class="iconfont nav_right"></i></a>
|
||||
<ul class="sub-menu">
|
||||
<li>
|
||||
<a onclick="xadmin.add_tab('菜谱列表','member-del.html')">
|
||||
<i class="iconfont"></i>
|
||||
<cite>菜谱列表</cite></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li> -->
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="x-slide_left"></div> -->
|
||||
<!-- 左侧菜单结束 -->
|
||||
<!-- 右侧主体开始 -->
|
||||
<div class="page-content">
|
||||
<div class="layui-tab tab" lay-filter="xbs_tab" lay-allowclose="false">
|
||||
<ul class="layui-tab-title">
|
||||
<li class="home">
|
||||
<i class="layui-icon"></i>我的桌面</li></ul>
|
||||
<div class="layui-unselect layui-form-select layui-form-selected" id="tab_right">
|
||||
<dl>
|
||||
<dd data-type="this">关闭当前</dd>
|
||||
<dd data-type="other">关闭其它</dd>
|
||||
<dd data-type="all">关闭全部</dd></dl>
|
||||
</div>
|
||||
<div class="layui-tab-content">
|
||||
<div class="layui-tab-item layui-show">
|
||||
<iframe src='/admin/welcome' frameborder="0" scrolling="yes" class="x-iframe"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
<div id="tab_show"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="page-content-bg"></div>
|
||||
<style id="theme_style"></style>
|
||||
<!-- 右侧主体结束 -->
|
||||
<!-- 中部结束 -->
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="x-admin-sm">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>欢迎页面-X-admin2.2</title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-row layui-col-space15">
|
||||
|
||||
<div class="layui-col-sm12 layui-col-md6">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">最新一周新增用户</div>
|
||||
<div class="layui-card-body" style="min-height: 280px;">
|
||||
<div id="main1" class="layui-col-sm12" style="height: 300px;"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-col-sm12 layui-col-md6">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">最新一周PV/UV量</div>
|
||||
<div class="layui-card-body" style="min-height: 280px;">
|
||||
<div id="main2" class="layui-col-sm12" style="height: 300px;"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-col-sm12 layui-col-md6">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">用户来源</div>
|
||||
<div class="layui-card-body" style="min-height: 280px;">
|
||||
<div id="main3" class="layui-col-sm12" style="height: 300px;"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-col-sm12 layui-col-md6">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">硬盘使用量</div>
|
||||
<div class="layui-card-body" style="min-height: 280px;">
|
||||
<div id="main4" class="layui-col-sm12" style="height: 300px;"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
// 基于准备好的dom,初始化echarts实例
|
||||
var myChart = echarts.init(document.getElementById('main1'));
|
||||
|
||||
// 指定图表的配置项和数据
|
||||
var option = {
|
||||
grid: {
|
||||
top: '5%',
|
||||
right: '1%',
|
||||
left: '1%',
|
||||
bottom: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis'
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: ['周一','周二','周三','周四','周五','周六','周日']
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value'
|
||||
},
|
||||
series: [{
|
||||
name:'用户量',
|
||||
data: [820, 932, 901, 934, 1290, 1330, 1320],
|
||||
type: 'line',
|
||||
smooth: true
|
||||
}]
|
||||
};
|
||||
|
||||
|
||||
// 使用刚指定的配置项和数据显示图表。
|
||||
myChart.setOption(option);
|
||||
|
||||
// 基于准备好的dom,初始化echarts实例
|
||||
var myChart = echarts.init(document.getElementById('main2'));
|
||||
|
||||
// 指定图表的配置项和数据
|
||||
var option = {
|
||||
tooltip : {
|
||||
trigger: 'axis',
|
||||
axisPointer: {
|
||||
type: 'cross',
|
||||
label: {
|
||||
backgroundColor: '#6a7985'
|
||||
}
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
top: '5%',
|
||||
right: '2%',
|
||||
left: '1%',
|
||||
bottom: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis : [
|
||||
{
|
||||
type : 'category',
|
||||
boundaryGap : false,
|
||||
data : ['周一','周二','周三','周四','周五','周六','周日']
|
||||
}
|
||||
],
|
||||
yAxis : [
|
||||
{
|
||||
type : 'value'
|
||||
}
|
||||
],
|
||||
series : [
|
||||
{
|
||||
name:'PV',
|
||||
type:'line',
|
||||
areaStyle: {normal: {}},
|
||||
data:[120, 132, 101, 134, 90, 230, 210],
|
||||
smooth: true
|
||||
},
|
||||
{
|
||||
name:'UV',
|
||||
type:'line',
|
||||
areaStyle: {normal: {}},
|
||||
data:[45, 182, 191, 234, 290, 330, 310],
|
||||
smooth: true,
|
||||
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
// 使用刚指定的配置项和数据显示图表。
|
||||
myChart.setOption(option);
|
||||
|
||||
|
||||
// 基于准备好的dom,初始化echarts实例
|
||||
var myChart = echarts.init(document.getElementById('main3'));
|
||||
|
||||
// 指定图表的配置项和数据
|
||||
var option = {
|
||||
tooltip : {
|
||||
trigger: 'item',
|
||||
formatter: "{a} <br/>{b} : {c} ({d}%)"
|
||||
},
|
||||
legend: {
|
||||
orient: 'vertical',
|
||||
left: 'left',
|
||||
data: ['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
|
||||
},
|
||||
series : [
|
||||
{
|
||||
name: '访问来源',
|
||||
type: 'pie',
|
||||
radius : '55%',
|
||||
center: ['50%', '60%'],
|
||||
data:[
|
||||
{value:335, name:'直接访问'},
|
||||
{value:310, name:'邮件营销'},
|
||||
{value:234, name:'联盟广告'},
|
||||
{value:135, name:'视频广告'},
|
||||
{value:1548, name:'搜索引擎'}
|
||||
],
|
||||
itemStyle: {
|
||||
emphasis: {
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 0,
|
||||
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 使用刚指定的配置项和数据显示图表。
|
||||
myChart.setOption(option);
|
||||
|
||||
// 基于准备好的dom,初始化echarts实例
|
||||
var myChart = echarts.init(document.getElementById('main4'));
|
||||
|
||||
// 指定图表的配置项和数据
|
||||
var option = {
|
||||
tooltip : {
|
||||
formatter: "{a} <br/>{b} : {c}%"
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '硬盘使用量',
|
||||
type: 'gauge',
|
||||
detail: {formatter:'{value}%'},
|
||||
data: [{value: 88, name: '已使用'}]
|
||||
}
|
||||
]
|
||||
};
|
||||
// 使用刚指定的配置项和数据显示图表。
|
||||
myChart.setOption(option);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
<!doctype html>
|
||||
<html class="x-admin-sm">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>后台登录-X-admin2.2</title>
|
||||
<meta name="renderer" content="webkit|ie-comp|ie-stand">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<meta http-equiv="Cache-Control" content="no-siteapp" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/login.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
|
||||
<script src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
|
||||
</head>
|
||||
<body class="login-bg">
|
||||
|
||||
<div class="login layui-anim layui-anim-up">
|
||||
<div class="message">轻厨记管理后台</div>
|
||||
<div id="darkbannerwrap"></div>
|
||||
<form method="post" class="layui-form" >
|
||||
<input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input" >
|
||||
<hr class="hr15">
|
||||
<input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
|
||||
<hr class="hr15">
|
||||
<input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
|
||||
<hr class="hr20" >
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
var pd = true
|
||||
layui.use('form', function(){
|
||||
var form = layui.form;
|
||||
// layer.msg('玩命卖萌中', function(){
|
||||
// //关闭后的操作
|
||||
// });
|
||||
//监听提交
|
||||
form.on('submit(login)', function(data){
|
||||
if(pd){
|
||||
pd = false
|
||||
console.log('进来了')
|
||||
$.ajax({
|
||||
url:"/k/a/login_action", //请求的url地址
|
||||
dataType:"json", //返回格式为json
|
||||
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data:{"username":data.field.username,"password":data.field.password}, //参数值
|
||||
type:"POST", //请求方式
|
||||
success:function(req){
|
||||
//请求成功时处理
|
||||
|
||||
if(req.code == 0){
|
||||
layer.msg('登录成功,准备跳转',function(){
|
||||
location.href='/k/a/index'
|
||||
},200);
|
||||
}else{
|
||||
layer.msg('登录失败',function(){
|
||||
pd = true
|
||||
});
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
//请求出错处理
|
||||
pd = true
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
})
|
||||
</script>
|
||||
<!-- 底部结束 -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,398 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1,user-scalable=no">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<meta http-equiv="Access-Control-Allow-Origin" content="*">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="format-detection" content="telephone=no, email=no">
|
||||
<meta name="full-screen" content="true">
|
||||
<meta name="screen-orientation" content="portrait">
|
||||
<meta name="x5-fullscreen" content="true">
|
||||
<meta name="360-fullscreen" content="true">
|
||||
<title>商务合作</title>
|
||||
<script src="/x_admin/js/jq.js"></script>
|
||||
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<style>
|
||||
*{
|
||||
padding: 0 0;
|
||||
margin: 0 0;
|
||||
}
|
||||
.big_box{
|
||||
width: 100vw;
|
||||
min-height: 100vh;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background: url(/tsf/business_bg.jpg) no-repeat;
|
||||
background-size: 100% 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
}
|
||||
.content{
|
||||
width: 85vw;
|
||||
max-width: 880px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
border-radius: 1vw;
|
||||
background-color: white;
|
||||
margin: 24px 0;
|
||||
overflow: hidden;
|
||||
align-items: center;
|
||||
}
|
||||
.content img{
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
.content_c{
|
||||
width: 100%;
|
||||
padding: 2% 12%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.title_t{
|
||||
border: none;
|
||||
text-align: center;
|
||||
color: rgba(8, 14, 23, 0.9);
|
||||
font-weight: 600;
|
||||
font-size: 28px;
|
||||
line-height: 40px;
|
||||
word-break: break-all;
|
||||
white-space: pre-wrap;
|
||||
overflow: visible;
|
||||
margin: 4% 0;
|
||||
}
|
||||
.title_c2{
|
||||
font-size: 12px;
|
||||
margin-bottom: 10%;
|
||||
}
|
||||
.title_c2 span{
|
||||
color: rgb(17, 106, 240);
|
||||
}
|
||||
.write_box{
|
||||
width: 100%;
|
||||
font-size: 16px;
|
||||
margin: 10% 0;
|
||||
}
|
||||
.write_box_t{
|
||||
font-weight: 600;
|
||||
}
|
||||
.write_box_r{
|
||||
color: red;
|
||||
}
|
||||
.write_k{
|
||||
padding: 8px 12px;
|
||||
position: relative;
|
||||
border-radius: 6px;
|
||||
border: 1px solid rgba(8, 14, 23, 0.24);
|
||||
display: flex;
|
||||
outline: 0 !important;
|
||||
word-break: break-all;
|
||||
margin: 2% 0;
|
||||
}
|
||||
.write_k textarea{
|
||||
width: 100%;
|
||||
resize: none;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 22px;
|
||||
border: none !important;
|
||||
border-radius: 0;
|
||||
background: transparent !important;
|
||||
box-shadow: none !important;
|
||||
outline: 0 !important;
|
||||
cursor: auto;
|
||||
padding: 0;
|
||||
min-height: 22px;
|
||||
margin: 0 1%;
|
||||
}
|
||||
|
||||
.ksapc-select-write {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ksapc-select-write-tip {
|
||||
margin-bottom: 10px;
|
||||
font-size: 14px;
|
||||
color: #8E9095;
|
||||
}
|
||||
|
||||
.ksapc-select-write-tile {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ksapc-checkboxgroup {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ksapc-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.ksapc-col {
|
||||
flex: 1 1 48%; /* 两列布局 */
|
||||
}
|
||||
|
||||
.ksapc-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.ksapc-checkbox input {
|
||||
margin-right: 8px;
|
||||
}
|
||||
.ksapc-checkbox span{
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#onload{
|
||||
width: 20vw;
|
||||
height: 5vw;
|
||||
min-width: 200px;
|
||||
min-height: 45px;
|
||||
background-color: #0A6CFF;
|
||||
color: white;
|
||||
border-radius: 10px;
|
||||
line-height: 5vw;
|
||||
text-align: center;
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 35px;
|
||||
cursor: pointer; /* 添加小手图标 */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body id="box_k">
|
||||
<div class="big_box">
|
||||
<div class="content">
|
||||
<img src="/tsf/business_title.jpg" alt="">
|
||||
<div class="content_c">
|
||||
<div class="title_t">商务合作意向登记表</div>
|
||||
<div class="title_c2">
|
||||
<!-- 智能设备产品包<span>含身高测量仪、体重体脂秤、宠物秤, 母婴秤,厨房秤,商业秤,身高体重/体脂秤,八电极体脂秤,运动训练设备</span>等;软件包含就智能健康管理系统,智能硬件管理系统等,支持智能设备选购/定制、健康系统对接/定制,行业解决方案等,您也可以直接拨打或微信联系:13590959084,期待与您合作! -->
|
||||
</div>
|
||||
<div class="write_box">
|
||||
<div class="write_box_t">
|
||||
<span class="write_box_r">*</span> 1.姓名
|
||||
</div>
|
||||
<div class="write_k">
|
||||
<textarea placeholder="请输入" rows="1" oninput="autoResize(this)" class="name-input"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="write_box">
|
||||
<div class="write_box_t">
|
||||
<span class="write_box_r">*</span> 2.联系电话
|
||||
</div>
|
||||
<div class="write_k">
|
||||
<textarea placeholder="请输入手机号" rows="1" oninput="autoResize(this)" class="phone-input"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="write_box">
|
||||
<div class="write_box_t">
|
||||
<span class="write_box_r">*</span> 3.行业
|
||||
</div>
|
||||
<div class="write_k">
|
||||
<textarea placeholder="请输入" rows="1" oninput="autoResize(this)" class="company-input"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="write_box">
|
||||
<div class="write_box_t">
|
||||
<span class="write_box_r">*</span> 4.合作意向
|
||||
</div>
|
||||
<div class="write_k" style="border: none;">
|
||||
<div class="ksapc-select-write">
|
||||
<div class="ksapc-select-write-tip" id="selectedCount">此题已选择 0/4 项</div>
|
||||
<div class="ksapc-select-write-tile">
|
||||
<div class="ksapc-checkboxgroup">
|
||||
<div class="ksapc-row">
|
||||
<!-- <div class="ksapc-col">
|
||||
<label class="ksapc-checkbox">
|
||||
<input type="checkbox" class="option-checkbox" value="智能设备">
|
||||
<span>智能设备</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="ksapc-col">
|
||||
<label class="ksapc-checkbox">
|
||||
<input type="checkbox" class="option-checkbox" value="健康软件">
|
||||
<span>健康软件</span>
|
||||
</label>
|
||||
</div> -->
|
||||
<div class="ksapc-col">
|
||||
<label class="ksapc-checkbox">
|
||||
<input type="checkbox" class="option-checkbox" value="解决方案">
|
||||
<span>解决方案</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="ksapc-col">
|
||||
<label class="ksapc-checkbox">
|
||||
<input type="checkbox" class="option-checkbox" value="系统定制">
|
||||
<span>系统定制</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="ksapc-col">
|
||||
<label class="ksapc-checkbox">
|
||||
<input type="checkbox" class="option-checkbox" value="设备定制">
|
||||
<span>设备定制</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="ksapc-col">
|
||||
<label class="ksapc-checkbox">
|
||||
<input type="checkbox" class="option-checkbox" value="其它">
|
||||
<span>其它(可联系商务合作:13590959084)</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="write_box">
|
||||
<div class="write_box_t">
|
||||
<span class="write_box_r">*</span> 5.备注
|
||||
</div>
|
||||
<div class="write_k">
|
||||
<textarea placeholder="请输入" rows="1" oninput="autoResize(this)" class="remark-input"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="write_box" style="color: #8E9095;">
|
||||
商务合作电话/微信:13590959084
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div id="onload">提交</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<script>
|
||||
var selectedValues = [];
|
||||
function autoResize(textarea) {
|
||||
textarea.style.height = 'auto'; // 重置高度
|
||||
textarea.style.height = textarea.scrollHeight + 'px'; // 设置为内容高度
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 获取 #onload 元素
|
||||
const onloadElement = document.getElementById('onload');
|
||||
|
||||
// 计算 #onload 元素的高度
|
||||
const height = onloadElement.offsetHeight;
|
||||
|
||||
// 设置 #onload 元素的行高与高度一致
|
||||
onloadElement.style.lineHeight = height + 'px';
|
||||
|
||||
|
||||
|
||||
|
||||
const checkboxes = document.querySelectorAll('.option-checkbox');
|
||||
const selectedCountElement = document.getElementById('selectedCount');
|
||||
let selectedCount = 0;
|
||||
|
||||
function updateSelectedCount() {
|
||||
selectedCount = 0;
|
||||
selectedValues = [];
|
||||
checkboxes.forEach(checkbox => {
|
||||
if (checkbox.checked) {
|
||||
selectedCount++;
|
||||
selectedValues.push(checkbox.value);
|
||||
}
|
||||
});
|
||||
selectedCountElement.textContent = `此题已选择 ${selectedCount}/4 项`;
|
||||
console.log('Selected Values:', selectedValues);
|
||||
}
|
||||
|
||||
checkboxes.forEach(checkbox => {
|
||||
checkbox.addEventListener('change', updateSelectedCount);
|
||||
});
|
||||
|
||||
$('#onload').on('click', function() {
|
||||
|
||||
// 获取所有需要检查的输入字段
|
||||
const nameInput = document.querySelector('.name-input');
|
||||
const phoneInput = document.querySelector('.phone-input');
|
||||
const companyInput = document.querySelector('.company-input');
|
||||
const remarkInput = document.querySelector('.remark-input');
|
||||
|
||||
// 检查每个字段是否为空
|
||||
let hasError = false;
|
||||
let errorMessage = '';
|
||||
|
||||
if (!nameInput || nameInput.value.trim() === '') {
|
||||
hasError = true;
|
||||
errorMessage += '1. 姓名\n';
|
||||
}
|
||||
|
||||
if (!phoneInput || phoneInput.value.trim() === '') {
|
||||
hasError = true;
|
||||
errorMessage += '2. 联系电话\n';
|
||||
}
|
||||
|
||||
if (!companyInput || companyInput.value.trim() === '') {
|
||||
hasError = true;
|
||||
errorMessage += '3. 行业\n';
|
||||
}
|
||||
|
||||
if (selectedCount === 0) {
|
||||
hasError = true;
|
||||
errorMessage += '4. 合作意向\n';
|
||||
}
|
||||
|
||||
if (!remarkInput || remarkInput.value.trim() === '') {
|
||||
hasError = true;
|
||||
errorMessage += '5. 备注\n';
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
|
||||
layer.msg('以下项目未填写或未选择:\n' + errorMessage, {icon: 2});
|
||||
// alert('以下项目未填写或未选择:\n' + errorMessage);
|
||||
return;
|
||||
}
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
|
||||
// 如果所有字段都填写了,执行提交操作
|
||||
$.ajax({
|
||||
url: "business_cooperation_action", // 请求的url地址
|
||||
dataType: "json", // 返回格式为json
|
||||
async: true, // 请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data: {
|
||||
"name": nameInput.value,
|
||||
"phone": phoneInput.value,
|
||||
"company": companyInput.value,
|
||||
"selectedValues": selectedValues,
|
||||
"remark": remarkInput.value
|
||||
},
|
||||
type: "POST", // 请求方式
|
||||
success: function(req) {
|
||||
layer.close(layer.index)
|
||||
// 请求成功时处理
|
||||
if(req.code == 0){
|
||||
layer.msg(req.msg, {icon: 1});
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
}else{
|
||||
layer.msg(req.msg, {icon: 2});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
layer.close(layer.index)
|
||||
// 请求出错处理
|
||||
layer.msg('网络错误了,请直接联系商务合作电话/微信:13590959084', {icon: 2});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -593,7 +593,9 @@ class Base extends Controller{
|
|||
case 'intnum':
|
||||
// 整数验证 - 必须是整型或纯整数字符串
|
||||
// 使用 filter_var 同时验证整型和整数字符串
|
||||
return filter_var($data, FILTER_VALIDATE_INT) !== false;
|
||||
// 必须是 >0 的整数或字符串整数
|
||||
$filtered = filter_var($data, FILTER_VALIDATE_INT);
|
||||
return $filtered !== false && $filtered > 0;
|
||||
|
||||
case 'datetime':
|
||||
// 日期时间验证 - 保持原有逻辑不变
|
||||
|
|
|
|||
|
|
@ -2,12 +2,9 @@
|
|||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use app\NewReedaw\controller\app\Cardparts;
|
||||
use app\NewReedaw\controller\app\Calculatebody;
|
||||
|
||||
class Body extends Base{
|
||||
|
||||
|
|
@ -30,6 +27,7 @@ class Body extends Base{
|
|||
'list'=>[]
|
||||
];
|
||||
protected $age_limit = 16;
|
||||
protected $pagesize = 15;
|
||||
protected $unit_name = ['score'=>'身体得分','height'=>'身高','weight'=>'体重','bmi'=>'BMI','fat_r'=>'脂肪率','fat_w'=>'脂肪量','muscle'=>'肌肉率','muscleval'=>'肌肉量','water'=>'水分','bone'=>'骨重','protein'=>'蛋白率','proteinval'=>'蛋白量','kcal'=>'基础代谢','visceral'=>'内脏指数','sfr'=>'皮下脂肪','body_level'=>'肥胖等级','body_type'=>'身体类型'];
|
||||
protected $unit_symbol = ['score'=>'分','height'=>'CM','weight'=>'公斤','bmi'=>'','fat_r'=>'%','fat_w'=>'kg','muscle'=>'%','muscleval'=>'kg','water'=>'kg','bone'=>'kg','protein'=>'%','proteinval'=>'kg','kcal'=>'kcal','visceral'=>'','sfr'=>'%',];
|
||||
protected $standard_color = [
|
||||
|
|
@ -85,7 +83,7 @@ class Body extends Base{
|
|||
public function body_report(){
|
||||
// phpinfo();
|
||||
// die;
|
||||
// try {
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
|
||||
return $this->msg(10001);
|
||||
|
|
@ -97,20 +95,243 @@ class Body extends Base{
|
|||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
return $this->body_report_action_detailed($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);
|
||||
// }
|
||||
} 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 manual_record(){
|
||||
try {
|
||||
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['time'],'datetime')){
|
||||
return $this->msg(10005,'time type error');
|
||||
}
|
||||
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
|
||||
if($temporary_data['height_in_cm'] == false){
|
||||
return $this->msg(10005,'身高单位错误');
|
||||
}
|
||||
if($temporary_data['weight_in_kg'] == false){
|
||||
return $this->msg(10005,'体重单位错误');
|
||||
}
|
||||
$data['height'] = $temporary_data['height_in_cm'];
|
||||
$data['weight'] = $temporary_data['weight_in_kg'];
|
||||
if(strlen($data['time']) <= 12){
|
||||
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
|
||||
$data['time'] = $this->addCurrentTimeToDateString($data['time']);
|
||||
}
|
||||
// $data['acd_id'] = '2';
|
||||
return $this->set_user_body_data($data,'by_hand_means');
|
||||
} 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 device_record(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['adc'],'num')){
|
||||
return $this->msg(10005,'adc type error');
|
||||
}
|
||||
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
|
||||
if($temporary_data['height_in_cm'] == false){
|
||||
return $this->msg(10005,'身高单位错误');
|
||||
}
|
||||
if($temporary_data['weight_in_kg'] == false){
|
||||
return $this->msg(10005,'体重单位错误');
|
||||
}
|
||||
// 检测设备传过来的info信息
|
||||
if(array_key_exists('info', $data)){
|
||||
if (!is_array($data['info'])) {
|
||||
return $this->msg(10005,'info参数格式错误');
|
||||
}else{
|
||||
$info_data_arr =['bodyage','fat_r','muscle','kcal','visceral','sfr','water','bone','fatlevlval','protein','bmi'];
|
||||
foreach ($data['info'] as $key => $value) {
|
||||
if (!in_array($key, $info_data_arr)) {
|
||||
return $this->msg(10005,'info参数格式错误-2');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data['height'] = $temporary_data['height_in_cm'];
|
||||
$data['weight'] = $temporary_data['weight_in_kg'];
|
||||
$data['time'] = date('Y-m-d H:i:s');
|
||||
return $this->set_user_body_data($data,'by_device');
|
||||
} 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 record_list_page(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['page'],'intnum')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
return $this->record_list_page_or_group_action($data,'page');
|
||||
} 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 record_list_group(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
return $this->record_list_page_or_group_action($data,'group');
|
||||
} 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 detailed_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005,'id type error');
|
||||
}
|
||||
return $this->get_all_detaile_data_action($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 del_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
unset($data['token']);
|
||||
$user_data = Db::table($this->body_db_name['body_data'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
|
||||
if($user_data){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
} 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################################################################
|
||||
################################################################action################################################################
|
||||
|
|
@ -344,7 +565,318 @@ class Body extends Base{
|
|||
// dump($result_end);
|
||||
|
||||
}
|
||||
// 用户身体数据卡片记录
|
||||
public function set_user_body_data($data,$type){
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
|
||||
// 判断头围数据是否存在是否合理
|
||||
if(array_key_exists('head_data', $data)){
|
||||
if(!$this->verify_data_is_ok($data['head_data'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$data['head_circumference'] = $data['head_data'];
|
||||
}else{
|
||||
$data['head_circumference'] = 0;
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
$user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find();
|
||||
|
||||
if(!$user_data){
|
||||
return $this->msg(10003);
|
||||
}
|
||||
// 如果最初体重设置为null
|
||||
if($user_data['initial_date'] == null){
|
||||
Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]);
|
||||
$target_current = $this->base_target_initial_cumulative_weight([
|
||||
'weight'=>$data['weight'],
|
||||
'target_weight'=>$user_data['target_weight'],
|
||||
'initial_weight'=>$data['weight'],
|
||||
'initial_date'=>$data['time'],
|
||||
]);
|
||||
}else{
|
||||
$target_current = $this->base_target_initial_cumulative_weight([
|
||||
'weight'=>$data['weight'],
|
||||
'target_weight'=>$user_data['target_weight'],
|
||||
'initial_weight'=>$user_data['initial_weight'],
|
||||
'initial_date'=>$user_data['initial_date'],
|
||||
]);
|
||||
}
|
||||
// 设置身高、体重、年龄、性别、阶段称谓、头围、生日、阻抗
|
||||
$result_data['height'] = $data['height'];
|
||||
$result_data['weight'] = $data['weight'];
|
||||
$result_data['age'] = $this->calculate_age($user_data['birthday']);
|
||||
$result_data['gender'] = $user_data['gender'];
|
||||
$result_data['head_circumference'] = $data['head_circumference'];
|
||||
$result_data['birthday'] = $user_data['birthday'];
|
||||
if(array_key_exists('adc', $data)){
|
||||
if($data['adc'] > 0){
|
||||
$result_data['adc'] = $data['adc'];
|
||||
$type = "by_device_adc";
|
||||
}else{
|
||||
$result_data['adc'] = 550;
|
||||
$type = "by_device";
|
||||
}
|
||||
}
|
||||
$calculate_body_formula = new Calculatebody();
|
||||
|
||||
// 计算身体数据
|
||||
$get_body_value = $calculate_body_formula->calculate_body_data_result($result_data);
|
||||
|
||||
if($get_body_value === false){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
|
||||
// 如果年纪小于三岁,处理头围数据star
|
||||
$standardlist = [];
|
||||
if($result_data['age'] < 3){
|
||||
if(array_key_exists('standardlist',$get_body_value)){
|
||||
$standardlist = $get_body_value['standardlist'];
|
||||
foreach ($standardlist as $key => $value) {
|
||||
if($value['name'] == 'head' && count($value['list'] ) > 0){
|
||||
$standardlist = $value;
|
||||
}
|
||||
}
|
||||
$standardlist['list2'] = [];
|
||||
foreach ($standardlist['list'] as $key => $value) {
|
||||
array_push($standardlist['list2'],[
|
||||
'min_val'=>$value['minvalue'],
|
||||
'max_val'=>$value['maxvalue'],
|
||||
'text'=>$value['text'],
|
||||
'color'=>$value['color']
|
||||
]);
|
||||
}
|
||||
unset($standardlist['list']);
|
||||
unset($get_body_value['standardlist']);
|
||||
}
|
||||
}else{
|
||||
if(array_key_exists('standardlist',$get_body_value)){
|
||||
unset($get_body_value['standardlist']);
|
||||
}
|
||||
}
|
||||
// 如果年纪小于三岁,处理头围数据end
|
||||
$get_body_value['gender'] = $user_data['gender'];
|
||||
$get_body_value['birthday'] = $user_data['birthday'];
|
||||
// 添加身高、体重、bmi、头围(如果有)的标尺标准
|
||||
$get_body_value = $this->hwb_standard($get_body_value);
|
||||
|
||||
|
||||
$enumeration_data = [
|
||||
'fat_r'=>'脂肪率',
|
||||
'muscle'=>'肌肉率',
|
||||
'kcal'=>'基础代谢',
|
||||
'visceral'=>'内脏指数',
|
||||
'sfr'=>'皮下脂肪',
|
||||
'water'=>'水分',
|
||||
'bone'=>'骨重',
|
||||
'protein'=>'蛋白率',
|
||||
'bodyage'=>'身体年龄'
|
||||
];
|
||||
|
||||
// return $this->msg($get_body_value);
|
||||
// 根据秤传过来的数据,去处理要存的结果
|
||||
if(array_key_exists('info', $data)){
|
||||
|
||||
|
||||
foreach ($data['info'] as $key => $value) {
|
||||
if($key == 'bmi'){
|
||||
if($value > 0){
|
||||
$get_body_value['BMI'] = $value;
|
||||
$get_body_value['BMI2'] = explode(',',$get_body_value['BMI2']);
|
||||
$get_body_value['BMI2'][0] = $value;
|
||||
$get_body_value['BMI2'] = implode(',',$get_body_value['BMI2']);
|
||||
}
|
||||
}else if($key == 'bodyage'){
|
||||
$get_body_value[$enumeration_data[$key]] = $value;
|
||||
}else if($key == 'fatlevlval'){
|
||||
continue;
|
||||
}else{
|
||||
if($value > 0){
|
||||
$get_body_value[$enumeration_data[$key]][0] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$set_data = [
|
||||
'acd_id'=>2,
|
||||
'aud_id'=>$data['aud_id'],
|
||||
'record_time'=>array_key_exists('time', $data)?$data['time']:date('Y-m-d H:i:s'),
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
'last_update_time'=>date('Y-m-d H:i:s'),
|
||||
'age'=>$get_body_value['age'],
|
||||
'height'=>$get_body_value['身高2'],
|
||||
'height_val'=>$get_body_value['身高'],
|
||||
'weight'=>$get_body_value['体重2'],
|
||||
'weight_val'=>$get_body_value['体重'],
|
||||
'bmi'=>$get_body_value['BMI2'],
|
||||
'bmi_val'=>$get_body_value['BMI'],
|
||||
'score'=>$get_body_value['身体得分'],
|
||||
'fat_r'=> implode(',',$get_body_value['脂肪率']),
|
||||
'fat_w'=>implode(',',$get_body_value['脂肪量']),
|
||||
'muscle'=>implode(',',$get_body_value['肌肉率']),
|
||||
'muscleval'=>implode(',',$get_body_value['肌肉量']),
|
||||
'water'=>implode(',',$get_body_value['水分']),
|
||||
'proteinval'=>implode(',',$get_body_value['蛋白量']),
|
||||
'bone'=>implode(',',$get_body_value['骨重']),
|
||||
'protein'=>implode(',',$get_body_value['蛋白率']),
|
||||
'kcal'=>implode(',',$get_body_value['基础代谢']),
|
||||
'visceral'=>implode(',',$get_body_value['内脏指数']),
|
||||
'sfr'=>implode(',',$get_body_value['皮下脂肪']),
|
||||
'body_level'=>$get_body_value['肥胖等级'],
|
||||
'body_type'=>$get_body_value['身体类型'],
|
||||
'body_age'=>$get_body_value['身体年龄'],
|
||||
'record_type' => $type,
|
||||
'head_circumference' => $result_data['age'] < 3?json_encode($standardlist):"",
|
||||
];
|
||||
if(strlen($set_data['record_time']) <= 12){
|
||||
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
|
||||
$set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']);
|
||||
}
|
||||
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try{
|
||||
$set_user_data = Db::table($this->body_db_name['body_data'])->insert($set_data);
|
||||
$update_arr = [
|
||||
'height'=>$get_body_value['身高'],
|
||||
'weight'=>$get_body_value['体重']
|
||||
];
|
||||
if($data['head_circumference']>0){
|
||||
$update_arr['head_data'] = $data['head_circumference'];
|
||||
}
|
||||
$update_user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update($update_arr);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return $this->msg([
|
||||
'acd_id'=>2,
|
||||
'height'=>$get_body_value['身高'].',CM',
|
||||
'weight'=>$get_body_value['体重'].',公斤',
|
||||
'bmi'=>$get_body_value['BMI'],
|
||||
'target_current'=>$target_current,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
public function record_list_page_or_group_action($data,$type){
|
||||
$return_result = [];
|
||||
|
||||
if($type == 'group'){
|
||||
$data['s_time'] = $data['s_time'].' 00:00:00';
|
||||
$data['e_time'] = $data['e_time'].' 23:59:59';
|
||||
$result = Db::query("
|
||||
select
|
||||
id,
|
||||
CONVERT(varchar(10), record_time, 120) AS r_t,
|
||||
CONVERT(varchar(19), record_time, 120) AS record_time,
|
||||
height_val as v1,
|
||||
weight_val as v2,
|
||||
bmi_val as v3
|
||||
from ".$this->body_db_name['body_data']."
|
||||
where aud_id='".$data['aud_id']."'
|
||||
and record_time between '".$data['s_time']."' and '".$data['e_time']."'
|
||||
and is_del = 0
|
||||
order by record_time desc");
|
||||
foreach ($result as $key => $value) {
|
||||
array_push($return_result, [
|
||||
'id'=>$value['id'],
|
||||
'v1'=>floatval(sprintf("%.2f", $value['v1'])),
|
||||
'v2'=>floatval(sprintf("%.2f", $value['v2'])),
|
||||
'v3'=>floatval(sprintf("%.2f", $value['v3'])),
|
||||
'v1_name'=>'身高',
|
||||
'v2_name'=>'体重',
|
||||
'v3_name'=>'BMI',
|
||||
// 'r_t'=>str_replace('-', '/', $value['r_t'])
|
||||
'r_t'=>$value['r_t']
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
$result = Db::table($this->body_db_name['body_data'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height_val,weight_val,bmi_val")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
|
||||
$return_result['totalrows'] = Db::table($this->body_db_name['body_data'])->where(['aud_id'=>$data['aud_id']])->count();
|
||||
$return_result['rows'] = [];
|
||||
$return_result['pageno'] = $data['page'];
|
||||
$return_result['pagesize'] = $this->pagesize;
|
||||
$return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
|
||||
foreach ($result as $key => $value) {
|
||||
array_push($return_result['rows'],[
|
||||
'id'=>$value['id'],
|
||||
'v1'=>floatval(sprintf("%.2f", $value['height_val'])),
|
||||
'v2'=>floatval(sprintf("%.2f", $value['weight_val'])),
|
||||
'v3'=>floatval(sprintf("%.2f", $value['bmi_val'])),
|
||||
'v1_name'=>'身高',
|
||||
'v2_name'=>'体重',
|
||||
'v3_name'=>'BMI',
|
||||
'record_time'=>$value['b_time'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->msg($return_result);
|
||||
}
|
||||
// 获取详细历史数据信息
|
||||
public function get_all_detaile_data_action($data){
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 设置排除在外的数据类型start
|
||||
$exclude_data_arr = ['height','weight','age','bmi'];
|
||||
// 设置排除在外的数据类型end
|
||||
$result = Db::table($this->body_db_name['body_data'])->where(['id'=>$data['id']])->find();
|
||||
$for_data_arr = ['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI',''],'head'=>['头围',''],'fat_w'=>['脂肪量','kg'],'fat_r'=>['脂肪率','%'],'muscleval'=>['肌肉量','kg'],'muscle'=>['肌肉率','%'],'proteinval'=>['蛋白量','kg'],'protein'=>['蛋白率','%'],'water'=>['水分',''],'bone'=>['骨重','kg'],'visceral'=>['内脏指数',''],'sfr'=>['皮下脂肪','%'],'kcal'=>['基础代谢','kcal'],'un_fat_w_weight'=>['去脂体重','kg'],'body_age'=>['体龄',''],'body_level'=>['肥胖等级',''],'body_type'=>['体型','']];
|
||||
if($result){
|
||||
$result_data = [];
|
||||
foreach ($for_data_arr as $key => $value) {
|
||||
$temporary_arr['key_name'] = $key;
|
||||
$temporary_arr['name'] = $value[0];
|
||||
// 身体数据处理,如果没有阻抗,则只显示四项$exclude_data_arr
|
||||
if($result['record_type'] != 'by_device_adc'){
|
||||
if(!in_array($key, $exclude_data_arr)){
|
||||
continue;
|
||||
}else{
|
||||
$temporary_arr['value'] = explode(',',$result[$key])[0];
|
||||
}
|
||||
}else{
|
||||
|
||||
if($key == 'un_fat_w_weight'){
|
||||
$temporary_arr['value'] = bcsub(explode(',',$result['weight'])[0],explode(',',$result['fat_w'])[0],2);
|
||||
}else{
|
||||
if(array_key_exists($key,$result)){
|
||||
$temporary_arr['value'] = explode(',',$result[$key])[0];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$temporary_arr['unit'] = $value[1];
|
||||
array_push($result_data,$temporary_arr);
|
||||
}
|
||||
//
|
||||
// 添加头围详细start
|
||||
if($result['head_circumference'] != null){
|
||||
array_unshift($result_data,[
|
||||
'key_name'=>'head_circumference',
|
||||
'name'=>'头围',
|
||||
'value'=>json_decode($result['head_circumference'],true)['value'] == 0?"0":json_decode($result['head_circumference'],true)['value'],
|
||||
'unit'=>'cm',
|
||||
]);
|
||||
}
|
||||
// 添加头围详细end
|
||||
return $this->msg($result_data);
|
||||
}else{
|
||||
return $this->msg(10004);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
################################################################内部调用################################################################
|
||||
################################################################内部调用################################################################
|
||||
public function processing_return_data_new($data){
|
||||
$result_end_data = [];
|
||||
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
|
||||
|
|
@ -655,9 +1187,86 @@ class Body extends Base{
|
|||
}
|
||||
return $return_data;
|
||||
}
|
||||
// public function body_report_action_detailed($data){
|
||||
|
||||
// }
|
||||
// 添加身高体重bmi的标准
|
||||
public function hwb_standard($data){
|
||||
$linshi_data = [];
|
||||
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
|
||||
$gender_val = $data['gender'];
|
||||
if($data['age'] < $this->age_limit){
|
||||
foreach ($data as $key => $value) {
|
||||
if($key =='身高'){
|
||||
$linshi_data['身高'] = $this->bhw_list['height'];
|
||||
$bhw_date = Db::table($this->body_db_name['heigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||||
|
||||
if($bhw_date){
|
||||
$linshi_data['身高'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||||
$linshi_data['身高'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||||
$linshi_data['身高'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||||
$linshi_data['身高'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||||
$linshi_data['身高'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||||
$linshi_data['身高'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||||
$linshi_data['身高'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||||
$linshi_data['身高'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||||
$linshi_data['身高'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||||
}
|
||||
|
||||
}else if($key =='体重'){
|
||||
$linshi_data['体重'] = $this->bhw_list['weight'];
|
||||
$bhw_date = Db::table($this->body_db_name['weigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||||
if($bhw_date){
|
||||
$linshi_data['体重'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||||
$linshi_data['体重'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||||
$linshi_data['体重'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||||
$linshi_data['体重'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||||
$linshi_data['体重'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||||
$linshi_data['体重'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||||
$linshi_data['体重'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||||
$linshi_data['体重'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||||
$linshi_data['体重'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||||
}
|
||||
}else if($key =='BMI'){
|
||||
$linshi_data['BMI'] = $this->bhw_list['bmi'];
|
||||
$bhw_date = Db::table($this->body_db_name['bmi'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||||
if($bhw_date){
|
||||
$linshi_data['BMI'][0]['max_val'] = $bhw_date[0]['f1sd'];
|
||||
$linshi_data['BMI'][1]['min_val'] = $bhw_date[0]['f1sd'];
|
||||
$linshi_data['BMI'][1]['max_val'] = $bhw_date[0]['z1sd'];
|
||||
$linshi_data['BMI'][2]['min_val'] = $bhw_date[0]['z1sd'];
|
||||
$linshi_data['BMI'][2]['max_val'] = $bhw_date[0]['z2sd'];
|
||||
$linshi_data['BMI'][3]['min_val'] = $bhw_date[0]['z2sd'];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($linshi_data as $key => $value) {
|
||||
foreach ($value as $k => $v) {
|
||||
if($data[$key] >= $v['min_val'] && $data[$key] < $v['max_val']){
|
||||
// 如果落在区间内
|
||||
$data[$key.'2'] = $data[$key].','.$v['text'].','.$v['color'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 如果$key.'2'没有被设置
|
||||
if(!array_key_exists($key.'2', $data)){
|
||||
if($data[$key] < $value[0]['min_val']){
|
||||
// 如果小于最小值
|
||||
$data[$key.'2'] = $data[$key].','.$value[0]['text'].','.$value[0]['color'];
|
||||
}else if($data[$key] >= $value[count($value)-1]['max_val']){
|
||||
// 如果大于最大值
|
||||
$data[$key.'2'] = $data[$key].','.$value[count($value)-1]['text'].','.$value[count($value)-1]['color'];
|
||||
}
|
||||
}
|
||||
}
|
||||
// die;
|
||||
}else{
|
||||
$data['身高2'] = $data['身高'].',无,无';
|
||||
$data['体重2'] = $data['体重'].',无,无';
|
||||
$data['BMI2'] = $data['BMI'].',无,无';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,641 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
|
||||
|
||||
class Calculatebody extends Base{
|
||||
|
||||
// 默认阻抗值
|
||||
protected $default_adc = 550;
|
||||
// 体重 = weight weight
|
||||
// 身高 = height height
|
||||
// BMI = bmi bmi
|
||||
// age = age age
|
||||
// 身体得分 = cmi cmi
|
||||
// 脂肪量 = fat_w bfrval
|
||||
// 脂肪率 = fat_r bfr
|
||||
// 肌肉量 = muscleval romval
|
||||
// 肌肉率 = muscle rom
|
||||
// 水分 = water vwc
|
||||
// 蛋白量 = proteinval ppval
|
||||
// 蛋白率 = protein pp
|
||||
// 骨重 = bone bm
|
||||
// 基础代谢 = kcal bmr
|
||||
// 内脏指数 = visceral uvi
|
||||
// 皮下脂肪 = sfr sfr
|
||||
// 肥胖等级 = standard_level fatlevel (fatlevelName)
|
||||
// 身体年龄 = bodyage bodyage
|
||||
// 去脂体重 = lbm lbm
|
||||
// 身体类型 = body body
|
||||
|
||||
public function calculate_body_data_result($data = ['weight'=>52.5,'height'=>165,'age'=>30,'gender'=>1]){
|
||||
$data['gender'] = $data['gender'] == 0 ? 1 : $data['gender'];
|
||||
|
||||
$data['adc'] = array_key_exists('adc', $data)?$data['adc']:$this->default_adc;
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
|
||||
// 青测自己写的计算start
|
||||
// $result = $this->calculate_body_data($data['height'],$data['weight'],$data['age'],$data['gender'],$data['adc']);
|
||||
// // $result['fat_w'] = $result['fat_r'] / 100 * $data['weight'];
|
||||
// $result['fat_w'] = bcmul(bcdiv($result['fat_r'],'100',20),$data['weight'],2);
|
||||
// // $result['proteinval'] = $result['protein'] / 100 * $data['weight'];
|
||||
// $result['proteinval'] = bcmul(bcdiv($result['protein'],'100',20),$data['weight'],2);
|
||||
// //肌肉量=体重-脂肪量-骨量
|
||||
// // $result['muscleval'] = $result['weight'] - $result['fat_w'] - $result['bone'];
|
||||
// $result['muscleval'] = bcsub(bcsub($result['weight'],$result['fat_w'],20),$result['bone'],2);
|
||||
// // $result['muscle'] = $result['muscleval'] / $data['weight'] * 100.0;
|
||||
// $result['muscle'] = bcmul(bcdiv($result['muscleval'],$data['weight'],20),'100.0',2);
|
||||
// // 水份=肌肉量-蛋白量
|
||||
// // $result['water'] = $result['muscleval'] - $result['proteinval'];
|
||||
// $result['water'] = bcsub($result['muscleval'],$result['proteinval'],2);
|
||||
// // $result['lbm'] = (1 - $result['fat_r'] / 100) * $data['weight'];
|
||||
// $result['lbm'] = bcmul(bcsub('1',bcdiv($result['fat_r'],'100',20),20),$data['weight'],2);
|
||||
// 青测自己写的计算end
|
||||
|
||||
// 使用接口调用之前的进行计算start
|
||||
$url = 'https://klcz.pcxbc.com/open-api/calc/healthcalc/bodyfat3';
|
||||
if($data['age'] < '3'){
|
||||
$temporary_parameter = [
|
||||
'weight'=>$data['weight'],
|
||||
'height'=>$data['height'],
|
||||
'age'=>round($data['age']),//四舍五入取整
|
||||
'adc'=>round($data['adc']),//四舍五入取整
|
||||
'gender'=>$data['gender'],
|
||||
'head'=>$data['head_circumference'],
|
||||
'hasStandardList'=>true,
|
||||
'birthDay'=>$data['birthday'],
|
||||
];
|
||||
}else{
|
||||
$temporary_parameter = [
|
||||
'weight'=>$data['weight'],
|
||||
'height'=>$data['height'],
|
||||
'age'=>round($data['age']),//四舍五入取整
|
||||
'adc'=>round($data['adc']),//四舍五入取整
|
||||
'gender'=>$data['gender'],
|
||||
];
|
||||
}
|
||||
$request_result = $this->postRequest($url,$temporary_parameter);
|
||||
if($request_result['code'] != 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$result['weight'] = $request_result['data']['weight'];
|
||||
$result['height'] = $request_result['data']['height'];
|
||||
$result['bmi'] = $request_result['data']['bmi'];
|
||||
$result['age'] = $request_result['data']['age'];
|
||||
$result['cmi'] = $request_result['data']['cmi'];
|
||||
$result['fat_w'] = $request_result['data']['bfrval'];
|
||||
$result['fat_r'] = $request_result['data']['bfr'];
|
||||
$result['muscleval'] = $request_result['data']['romval'];
|
||||
$result['muscle'] = $request_result['data']['rom'];
|
||||
$result['water'] = $request_result['data']['vwc'];
|
||||
$result['proteinval'] = $request_result['data']['ppval'];
|
||||
$result['protein'] = $request_result['data']['pp'];
|
||||
$result['bone'] = $request_result['data']['bm'];
|
||||
$result['kcal'] = $request_result['data']['bmr'];
|
||||
$result['visceral'] = $request_result['data']['uvi'];
|
||||
$result['sfr'] = $request_result['data']['sfr'];
|
||||
$result['standard_level'] = $request_result['data']['fatlevelname'];
|
||||
$result['bodyage'] = $request_result['data']['bodyage'];
|
||||
$result['lbm'] = $request_result['data']['lbm'];
|
||||
$result['body'] = $request_result['data']['body'];
|
||||
// 使用接口调用之前的进行计算end
|
||||
|
||||
$return_data['standardlist'] = $request_result['data']['standardlist'];
|
||||
$return_data['体重'] = $data['weight'];
|
||||
$return_data['身高'] = $data['height'];
|
||||
$return_data['BMI'] = $result['bmi'];
|
||||
$return_data['age'] = $result['age'];
|
||||
|
||||
// 身体得分修改start
|
||||
// if($result['bmi']<21.6){
|
||||
// $return_data['身体得分'] = bcmul(bcdiv($result['bmi'],'21.6',20),'100',0);
|
||||
// }else{
|
||||
// $return_data['身体得分'] = bcmul(bcdiv('21.6',$result['bmi'],20),'100',0);
|
||||
// }
|
||||
$return_data['身体得分'] = $result['cmi'];
|
||||
// 身体得分修改end
|
||||
|
||||
$return_data['脂肪量'][0] = $result['fat_w'];
|
||||
$return_data['脂肪率'][0] = $result['fat_r'];
|
||||
if(
|
||||
($data['gender']==1 && $data['age']<30 && $result['fat_r']<10) ||
|
||||
($data['gender']==1 && $data['age']>=30 && $result['fat_r']<11) ||
|
||||
($data['gender']==2 && $data['age']<30 && $result['fat_r']<20) ||
|
||||
($data['gender']==2 && $data['age']>=30 && $result['fat_r']<21)){
|
||||
$return_data['脂肪率'][1] = '偏低';
|
||||
$return_data['脂肪量'][1] = '偏低';
|
||||
}else if(
|
||||
($data['gender']==1 && $data['age']<30 && $result['fat_r']>=10 && $result['fat_r']<21) ||
|
||||
($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=11 && $result['fat_r']<22) ||
|
||||
($data['gender']==2 && $data['age']<30 && $result['fat_r']>=20 && $result['fat_r']<31) ||
|
||||
($data['gender']==2 && $data['age']>=30 && $result['fat_r']>=21 && $result['fat_r']<32)){
|
||||
$return_data['脂肪率'][1] = '标准';
|
||||
$return_data['脂肪量'][1] = '标准';
|
||||
}else if(
|
||||
($data['gender']==1 && $data['age']<30 && $result['fat_r']>=21 && $result['fat_r']<26) ||
|
||||
($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=22 && $result['fat_r']<27) ||
|
||||
($data['gender']==2 && $data['age']<30 && $result['fat_r']>=31 && $result['fat_r']<38) ||
|
||||
($data['gender']==2 && $data['age']>=30 && $result['fat_r']>=32 && $result['fat_r']<39)){
|
||||
$return_data['脂肪率'][1] = '偏高';
|
||||
$return_data['脂肪量'][1] = '偏高';
|
||||
}else if(
|
||||
($data['gender']==1 && $data['age']<30 && $result['fat_r']>=26) ||
|
||||
($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=27) ||
|
||||
($data['gender']==2 && $data['age']<30 && $result['fat_r']<38) ||
|
||||
($data['gender']==2 && $data['age']>=30 && $result['fat_r']<39)){
|
||||
$return_data['脂肪率'][1] = '高';
|
||||
$return_data['脂肪量'][1] = '高';
|
||||
}else{
|
||||
$return_data['脂肪率'][1] = '异常';
|
||||
$return_data['脂肪量'][1] = '异常';
|
||||
}
|
||||
|
||||
$return_data['肌肉量'][0] = $result['muscleval'];
|
||||
$return_data['肌肉率'][0] = $result['muscle'];
|
||||
if(
|
||||
($data['gender']==1 && $result['muscle']<40) ||
|
||||
($data['gender']==2 && $result['muscle']<30)){
|
||||
$return_data['肌肉量'][1] = '不足';
|
||||
$return_data['肌肉率'][1] = '不足';
|
||||
}else if(
|
||||
($data['gender']==1 && $result['muscle']>=40 && $result['muscle']<60) ||
|
||||
($data['gender']==2 && $result['muscle']>=30 && $result['muscle']<50)){
|
||||
$return_data['肌肉量'][1] = '标准';
|
||||
$return_data['肌肉率'][1] = '标准';
|
||||
}else if(
|
||||
($data['gender']==1 && $result['muscle']>=60) ||
|
||||
($data['gender']==2 && $result['muscle']>=50)){
|
||||
$return_data['肌肉量'][1] = '优';
|
||||
$return_data['肌肉率'][1] = '优';
|
||||
}else{
|
||||
$return_data['肌肉量'][1] = '异常';
|
||||
$return_data['肌肉率'][1] = '异常';
|
||||
}
|
||||
|
||||
$return_data['水分'][0] = $result['water'];
|
||||
if(
|
||||
($data['gender']==1 && $result['water']<55) ||
|
||||
($data['gender']==2 && $result['water']<45)){
|
||||
$return_data['水分'][1] = '不足';
|
||||
}else if(
|
||||
($data['gender']==1 && $result['water']>=55 && $result['water']<65) ||
|
||||
($data['gender']==2 && $result['water']>=45 && $result['water']<60)){
|
||||
$return_data['水分'][1] = '标准';
|
||||
}else if(
|
||||
($data['gender']==1 && $result['water']>65) ||
|
||||
($data['gender']==2 && $result['water']>60)){
|
||||
$return_data['水分'][1] = '优';
|
||||
}else{
|
||||
$return_data['水分'][1] = '异常';
|
||||
}
|
||||
|
||||
$return_data['蛋白量'][0] = $result['proteinval'];
|
||||
$return_data['蛋白率'][0] = $result['protein'];
|
||||
if(
|
||||
($data['gender']==1 && $result['protein']<16) ||
|
||||
($data['gender']==2 && $result['protein']<14)){
|
||||
$return_data['蛋白量'][1] = '不足';
|
||||
$return_data['蛋白率'][1] = '不足';
|
||||
}else if(
|
||||
($data['gender']==1 && $result['protein']>=16 && $result['protein']<18) ||
|
||||
($data['gender']==2 && $result['protein']>=14 && $result['protein']<16)){
|
||||
$return_data['蛋白量'][1] = '标准';
|
||||
$return_data['蛋白率'][1] = '标准';
|
||||
}else if(
|
||||
($data['gender']==1 && $result['protein']>18) ||
|
||||
($data['gender']==2 && $result['protein']>16)){
|
||||
$return_data['蛋白量'][1] = '优';
|
||||
$return_data['蛋白率'][1] = '优';
|
||||
}else{
|
||||
$return_data['蛋白量'][1] = '异常';
|
||||
$return_data['蛋白率'][1] = '异常';
|
||||
}
|
||||
|
||||
$return_data['骨重'][0] = $result['bone'];
|
||||
if(
|
||||
($data['gender']==1 && $data['weight']<60 && $result['bone']<2.4) ||
|
||||
($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']<2.8) ||
|
||||
($data['gender']==1 && $data['weight']>=75 && $result['bone']<3.1) ||
|
||||
($data['gender']==2 && $data['weight']<45 && $result['bone']<1.7) ||
|
||||
($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']<2.1) ||
|
||||
($data['gender']==2 && $data['weight']>=60 && $result['bone']<2.4)){
|
||||
$return_data['骨重'][1] = '不足';
|
||||
}else if(
|
||||
($data['gender']==1 && $data['weight']<60 && $result['bone']>=2.4 && $result['bone']<=2.6) ||
|
||||
($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']>=2.8 && $result['bone']<=3) ||
|
||||
($data['gender']==1 && $data['weight']>=75 && $result['bone']>=3.1 && $result['bone']<=3.3) ||
|
||||
($data['gender']==2 && $data['weight']<45 && $result['bone']>=1.7 && $result['bone']<=1.9) ||
|
||||
($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']>=2.1 && $result['bone']<=2.3) ||
|
||||
($data['gender']==2 && $data['weight']>=60 && $result['bone']>=2.4 && $result['bone']<=2.6)){
|
||||
$return_data['骨重'][1] = '标准';
|
||||
}else if(
|
||||
($data['gender']==1 && $data['weight']<60 && $result['bone']>2.6) ||
|
||||
($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']>3) ||
|
||||
($data['gender']==1 && $data['weight']>=75 && $result['bone']<3.3) ||
|
||||
($data['gender']==2 && $data['weight']<45 && $result['bone']>1.9) ||
|
||||
($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']>2.3) ||
|
||||
($data['gender']==2 && $data['weight']>=60 && $result['bone']>2.6)){
|
||||
$return_data['骨重'][1] = '优';
|
||||
}else{
|
||||
$return_data['骨重'][1] = '异常';
|
||||
}
|
||||
|
||||
$return_data['基础代谢'][0] = $result['kcal'];
|
||||
if(
|
||||
($data['gender']==1 && $data['age']>0 && $data['age']<3 && (60.9*$data['weight']-54)>$result['kcal']) ||
|
||||
($data['gender']==1 && $data['age']>=3 && $data['age']<10 && (22.7*$data['weight']+495)>$result['kcal']) ||
|
||||
($data['gender']==1 && $data['age']>=10 && $data['age']<18 && (17.5*$data['weight']+651)>$result['kcal']) ||
|
||||
($data['gender']==1 && $data['age']>=18 && $data['age']<30 && (15.3*$data['weight']+679)>$result['kcal']) ||
|
||||
($data['gender']==1 && $data['age']>=30 && (11.6*$data['weight']+879)>$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>0 && $data['age']<3 && (61*$data['weight']-51)>$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>=3 && $data['age']<10 && (22.5*$data['weight']+499)>$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>=10 && $data['age']<18 && (12.2*$data['weight']+746)>$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>=18 && $data['age']<30 && (14.7*$data['weight']+496)>$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>=30 && (8.7*$data['weight']+820)>$result['kcal'])){
|
||||
$return_data['基础代谢'][1] = '偏低';
|
||||
}else if(
|
||||
($data['gender']==1 && $data['age']>0 && $data['age']<3 && (60.9*$data['weight']-54)<=$result['kcal']) ||
|
||||
($data['gender']==1 && $data['age']>=3 && $data['age']<10 && (22.7*$data['weight']+495)<=$result['kcal']) ||
|
||||
($data['gender']==1 && $data['age']>=10 && $data['age']<18 && (17.5*$data['weight']+651)<=$result['kcal']) ||
|
||||
($data['gender']==1 && $data['age']>=18 && $data['age']<30 && (15.3*$data['weight']+679)<=$result['kcal']) ||
|
||||
($data['gender']==1 && $data['age']>=30 && (11.6*$data['weight']+879)<=$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>0 && $data['age']<3 && (61*$data['weight']-51)<=$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>=3 && $data['age']<10 && (22.5*$data['weight']+499)<=$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>=10 && $data['age']<18 && (12.2*$data['weight']+746)<=$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>=18 && $data['age']<30 && (14.7*$data['weight']+496)<=$result['kcal']) ||
|
||||
($data['gender']==2 && $data['age']>=30 && (8.7*$data['weight']+820)<=$result['kcal'])){
|
||||
$return_data['基础代谢'][1] = '优';
|
||||
}else{
|
||||
$return_data['基础代谢'][1] = '异常';
|
||||
}
|
||||
|
||||
$return_data['内脏指数'][0] = $result['visceral'];
|
||||
if($result['visceral']<9){
|
||||
$return_data['内脏指数'][1] = '标准';
|
||||
}else if($result['visceral']>=9 && $result['visceral']<14){
|
||||
$return_data['内脏指数'][1] = '警惕';
|
||||
}else if($result['visceral']>=14){
|
||||
$return_data['内脏指数'][1] = '危险';
|
||||
}else{
|
||||
$return_data['内脏指数'][1] = '异常';
|
||||
}
|
||||
|
||||
$return_data['皮下脂肪'][0] = $result['sfr'];
|
||||
if(
|
||||
($data['gender']==1 && $result['sfr']<7) ||
|
||||
($data['gender']==2 && $result['sfr']<11)){
|
||||
$return_data['皮下脂肪'][1] = '不足';
|
||||
}else if(
|
||||
($data['gender']==1 && $result['sfr']>=7 && $result['sfr']<15) ||
|
||||
($data['gender']==2 && $result['sfr']>=11 && $result['sfr']<17)){
|
||||
$return_data['皮下脂肪'][1] = '标准';
|
||||
}else if(
|
||||
($data['gender']==1 && $result['sfr']>=15) ||
|
||||
($data['gender']==2 && $result['sfr']>=17)){
|
||||
$return_data['皮下脂肪'][1] = '偏高';
|
||||
}else{
|
||||
$return_data['皮下脂肪'][1] = '异常';
|
||||
}
|
||||
// 脂肪率:偏低 标准 偏高 高
|
||||
// 肌肉率:不足 标准 优
|
||||
|
||||
// 肥胖等级修改start
|
||||
// // if($data['age']>=16){
|
||||
// if($result['standard_level']<-0.2){
|
||||
// $return_data['肥胖等级'] = '体重不足';
|
||||
// }else if($result['standard_level']>=-0.2 && $result['standard_level']<-0.1){
|
||||
// $return_data['肥胖等级'] = '偏瘦';
|
||||
// }else if($result['standard_level']>=-0.1 && $result['standard_level']<=0.1){
|
||||
// $return_data['肥胖等级'] = '标准';
|
||||
// }else if($result['standard_level']>0.1 && $result['standard_level']<=0.2){
|
||||
// $return_data['肥胖等级'] = '偏重';
|
||||
// }else if($result['standard_level']>0.2){
|
||||
// $return_data['肥胖等级'] = '超重';
|
||||
// }else{
|
||||
// $return_data['肥胖等级'] = '暂无数据';
|
||||
// }
|
||||
// // }else{
|
||||
// // $return_data['肥胖等级'] = '儿童';
|
||||
// // }
|
||||
$return_data['肥胖等级'] = $result['standard_level'];
|
||||
// 肥胖等级修改end
|
||||
|
||||
|
||||
// 身体类型修改start
|
||||
// // if($data['age']>=16){
|
||||
// if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '不足'){
|
||||
// $return_data['身体类型'] = '隐形肥胖';
|
||||
// }else if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '标准'){
|
||||
// $return_data['身体类型'] = '偏胖';
|
||||
// }else if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '优'){
|
||||
// $return_data['身体类型'] = '结实型偏胖';
|
||||
// }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '不足'){
|
||||
// $return_data['身体类型'] = '缺乏肌肉型';
|
||||
// }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '标准'){
|
||||
// $return_data['身体类型'] = '标准型';
|
||||
// }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '优'){
|
||||
// $return_data['身体类型'] = '标准肌肉型';
|
||||
// }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '不足'){
|
||||
// $return_data['身体类型'] = '偏瘦';
|
||||
// }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '标准'){
|
||||
// $return_data['身体类型'] = '偏瘦肌肉型';
|
||||
// }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '优'){
|
||||
// $return_data['身体类型'] = '健美肌肉型';
|
||||
// }else{
|
||||
// $return_data['身体类型'] = '暂无数据';
|
||||
// }
|
||||
// // }else{
|
||||
// // $return_data['身体类型'] = '儿童';
|
||||
// // }
|
||||
$return_data['身体类型'] = $result['body'];
|
||||
// 身体类型修改end
|
||||
|
||||
$return_data['身体年龄'] = $result['bodyage'];
|
||||
|
||||
// $result_end['fat_r'] = $result['fat_r'];
|
||||
// $result_end['muscle'] = $result['muscle'];
|
||||
// $result_end['water'] = $result['water'];
|
||||
// $result_end['bone'] = $result['bone'];
|
||||
// $result_end['kcal'] = $result['kcal'];
|
||||
// $result_end['fat_w'] = $result['fat_w'];
|
||||
// $result_end['visceral'] = $result['visceral'];
|
||||
// $result_end['protein'] = $result['protein'];
|
||||
// $result_end['bodyage'] = $result['bodyage'];
|
||||
// $result_end['bmi'] = $result['bmi'];
|
||||
// // $result_end['cmi'] = $result['cmi'];
|
||||
// $result_end['sfr'] = $result['sfr'];
|
||||
// // $result_end['sfrval'] = $result['sfrval'];
|
||||
// $result_end['skeletalmuscle'] = $result['skeletalmuscle'];
|
||||
// $result_end['muscleval'] = $result['muscleval'];
|
||||
// $result_end['proteinval'] = $result['proteinval'];
|
||||
// $result_end['lbm'] = $result['lbm'];
|
||||
// $result_end['weight'] = $result['weight'];
|
||||
// $result_end['height'] = $result['height'];
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
|
||||
// 计算身体数据,BMI、脂肪率、脂肪量、肌肉率、肌肉量....
|
||||
public function calculate_body_data($height,$weight,$age,$gender,$impedance){
|
||||
|
||||
$result_data = [];
|
||||
$mheight = bcdiv($height, '100', 20); // 假设我们保留20位小数
|
||||
$gender = $gender == 0 ? 1 : $gender;
|
||||
|
||||
if (($weight <= 0) || ($weight > 220) || ($height <= 0) || ($height > 270) || ($age <= 0) || ($age > 120) || ($impedance <= 0) || ($impedance > 1000) || !in_array($gender, [1, 2])) {
|
||||
if ($weight != 0 && $height != 0) {
|
||||
// 计算BMI
|
||||
$bmi = bcdiv($weight, bcmul($mheight, $mheight,20), 2);
|
||||
$result_data['bmi'] = $bmi;
|
||||
$result_data['bone'] = 0;
|
||||
$result_data['muscle'] = 0;
|
||||
$result_data['water'] = 0;
|
||||
$result_data['fat_r'] = 0;
|
||||
$result_data['sfr'] = 0;
|
||||
$result_data['skeletalmuscle'] = 0;
|
||||
$result_data['protein'] = 0;
|
||||
$result_data['visceral'] = 0;
|
||||
$result_data['kcal'] = 0;
|
||||
$result_data['bodyage'] = 0;
|
||||
$result_data['weight'] = $weight;
|
||||
$result_data['height'] = $height;
|
||||
$result_data['age'] = $age;
|
||||
$result_data['adc'] = $impedance;
|
||||
$result_data['gender'] = $gender;
|
||||
$result_data['standard_level'] = 0.0;
|
||||
return $result_data;
|
||||
}
|
||||
}
|
||||
$num = intval(bcmul(bcdiv($weight,bcmul($mheight,$mheight,20),20),'10',20))/10;
|
||||
$num2 = 0.0;
|
||||
$num3 = 0.0;
|
||||
$num4 = 0.0;
|
||||
$num5 = 0.0;
|
||||
$num6 = 0.0;
|
||||
$num7 = 0.0;
|
||||
$num8 = 0.0;
|
||||
$num9 = 0.0;
|
||||
$num10 = 0.0;
|
||||
$num11 = 0.0;
|
||||
// 根据男女计算脂肪率、脂肪量、肌肉率、肌肉量等等....
|
||||
$standard_weight = 0.0;
|
||||
$standard_level = 0.0;
|
||||
if ($gender == 1){
|
||||
// $num2 = 0.015 * $weight + (2.0 - 0.00055 * $impedance) * $height / 100 - 1.15;
|
||||
$num2 = bcsub(bcadd(bcmul('0.015',$weight,20),bcdiv(bcmul(bcsub('2.0',bcmul('0.00055',$impedance,20),20),$height,20),'100.0',20),20),'1.15',2);
|
||||
// $num3 = (0.0 - (0.00115 * $impedance + 0.01)) * $weight + (49.64 - 0.031 * $impedance) * $height / 100.0 + $impedance * 0.08 + $age * 0.04 + 15.4;
|
||||
$num3 = bcsub(bcsub(bcsub(bcsub(bcmul(bcsub('0.0',bcadd(bcmul('0.00115',$impedance,20),'0.01',20),20),$weight,20),bcdiv(bcmul(bcsub('49.64',bcmul('0.031',$impedance,20)),$height,20),'100.0',20),20),bcmul($impedance,'0.08'),20),bcmul($age,'0.04'),20),'15.4',2);
|
||||
// $num4 = 1000000.0/($num*(2.688*$impedance-78.28))-(10058/$impedance)-0.22*$age+52.6;
|
||||
$num4 = bcadd(bcsub(bcsub(bcdiv('1000000.0',bcmul($num,bcsub(bcmul('2.688',$impedance,20),'78.28',20),20),20),bcdiv('10058',$impedance,20),20),bcmul('0.22',$age,20),20),'52.6',20);
|
||||
// $num5 = -930000.0 / $num / (1.966 * $impedance - 58.46) + (13176 / $impedance) - 0.06 * $age + 40.0;
|
||||
$num5 = bcadd(bcsub(bcadd(bcdiv(bcdiv('-930000.0',$num,20),bcsub(bcmul('1.966',$impedance,20),'58.46',20),20),bcdiv('13176',$impedance,0),20),bcmul('0.06',$age,20),20),'40.0',20);
|
||||
// $num6 = 0.898 * $num5;
|
||||
$num6 = bcmul('0.898',$num5,1);
|
||||
// $num7 = 0.895 * $num4;
|
||||
$num7 = bcmul('0.895',$num4,20);
|
||||
// $num8 = 0.8 * (100.0 - $num5 - $num4 - $num2 / $weight);
|
||||
$num8 = bcmul('0.8',bcsub(bcsub(bcsub('100.0',$num5,20),$num4,20),bcdiv($num2,$weight,20),20),2);
|
||||
// $num9 = 0.304 * $weight - 25.58 * $height / 100.0 + 0.131 * $age + 0.005 * $impedance + 22.0;
|
||||
$num9 = bcadd(bcadd(bcadd(bcsub(bcmul('0.304',$weight,20),bcdiv(bcmul('25.58',$height,20),'100.0',20),20),bcmul('0.131',$age,20),20),bcmul('0.005',$impedance,20),20),'22.0',0);
|
||||
// $num10 = (9.0 + 0.0015 * $impedance) * $weight + (1350.0 - 0.88 * $impedance) * $height / 100.0 + (188 / $age) + 0.748 * $impedance - 1053.0;
|
||||
$num10 = bcsub(bcadd(bcadd(bcadd(bcmul(bcadd('9.0',bcmul('0.0015',$impedance,20),20),$weight,20),bcdiv(bcmul(bcsub('1350.0',bcmul('0.88',$impedance,20),20),$height,20),'100.0',20),20),bcdiv('188',$age,20),20),bcmul('0.748',$impedance,20),20),'1053.0',0);
|
||||
// $num11 = $age * (1.0 + 0.012 * ($num - 1.0)) - 21.0 + (30 - $age) * 0.35 + ($impedance - 450) * 0.02 + 11.0;
|
||||
$num11 = bcadd(bcadd(bcadd(bcsub(bcmul($age,bcadd('1.0',bcmul('0.012',bcsub($num,'1.0',20),20),20),20),'21.0',20),bcmul(bcsub('30',$age,20),'0.35',20),20),bcmul(bcsub($impedance,'450',20),'0.02',20),20),'11.0',0);
|
||||
|
||||
// $standard_weight = ($height-80)*0.7;
|
||||
$standard_weight = bcmul(bcsub($height,'80',20),'0.7',20);
|
||||
|
||||
}else{
|
||||
// $num2 = 2.2E-05 * $impedance * $weight + (4.99 - 0.00284 * $impedance) * $height / 100.0 + 0.0012 * $impedance - 4.45;
|
||||
$num2 = bcsub(bcadd(bcadd(bcmul(bcmul('0.000022',$impedance,20),$weight,20),bcdiv(bcmul(bcsub('4.99',bcmul('0.00284',$impedance,20),20),$height,20),'100.0',20),20),bcmul('0.0012',$impedance,20),20),'4.45',2);
|
||||
// $num3 = (0.0 - (0.00115 * $impedance + 0.01)) * $weight + (49.64 - 0.031 * $impedance) * $height / 100.0 + $impedance * 0.08 + $age * 0.04 + 6.0;
|
||||
$num3 = bcadd(bcadd(bcadd(bcadd(bcmul(bcsub('0.0',bcadd(bcmul('0.00115',$impedance,20),'0.01',20),20),$weight,20),bcdiv(bcmul(bcsub('49.64',bcmul('0.031',$impedance,20),20),$height,20),'100.0',20),20),bcmul($impedance,'0.08',20),20),bcmul($age,'0.04',20),20),'6.0',2);
|
||||
// $num4 = 1000000.0 / ($num * (2.467 * $impedance - 75.37)) - (14215 / $impedance) - 0.034 * $age + 43.2;
|
||||
$num4 = bcadd(bcsub(bcsub(bcdiv('1000000.0',bcmul($num,bcsub(bcmul('2.467',$impedance,20),'75.37',20),20),20),bcdiv('14215',$impedance,20),20),bcmul('0.034',$age,20),20),'43.2',20);
|
||||
// $num5 = -3030000.0 / ($num + 20.0) / (1.966 * $impedance - 58.46) + (28176 / $impedance) - 0.06 * $age + 51.0;
|
||||
$num5 = bcadd(bcsub(bcadd(bcdiv(bcdiv('-3030000.0',bcadd($num,'20.0',20),20),bcsub(bcmul('1.966',$impedance,20),'58.46',20),20),bcdiv('28176',$impedance,20),20),bcmul('0.06',$age,20),20),'51.0',20);
|
||||
// $num6 = 0.876 * $num5 + 1.66;
|
||||
$num6 = bcadd(bcmul('0.876',$num5,20),'1.66',1);
|
||||
// $num7 = 0.857 * $num4 - 0.36;
|
||||
$num7 = bcsub(bcmul('0.857',$num4,20),'0.36',20);
|
||||
// $num8 = 0.75 * (100.0 - $num5 - $num4 - $num2 / $weight);
|
||||
$num8 = bcmul('0.75',bcsub('100.0',bcsub($num5,bcsub($num4,bcdiv($num2,$weight,20),20),20),20),2);
|
||||
// $num9 = 0.304 * $weight - 25.58 * $height / 100.0 + 0.131 * $age + 0.005 * $impedance + 22.0;
|
||||
$num9 = bcadd(bcadd(bcadd(bcsub(bcmul(0.304,$weight,20),bcdiv(bcmul(25.58,$height,20),'100.0',20),20),bcmul('0.131',$age,20),20),bcmul('0.005',$impedance,20),20),'22.0',0);
|
||||
// $num10 = (0.00307 * $impedance + 1.5) * $weight + (1459.0 - 0.989 * $impedance) * $height / 100.0 + $age * 0.9 + 0.923 * $impedance - 950.0;
|
||||
$num10 = bcsub(bcadd(bcadd(bcadd(bcmul(bcadd(bcmul('0.00307',$impedance,20),'1.5',20),$weight,20),bcdiv(bcmul(bcsub('1459.0',bcmul('0.989',$impedance,20),20),$height,20),'100.0',20),20),bcmul($age,'0.9',20),20),bcmul('0.923',$impedance,20),20),'950.0',0);
|
||||
// $num11 = $age * (0.95 + 0.02 * ($num - 21.2)) + ($impedance - 500) * 0.02;
|
||||
$num11 = bcadd(bcmul($age,bcadd(0.95,bcmul('0.02',bcsub($num,'21.2',20),20),20),20),bcmul(bcsub($impedance,'500',20),'0.02',20),0);
|
||||
|
||||
// $standard_weight = ($height-80)*0.7;
|
||||
$standard_weight = bcmul(bcsub($height,'80',20),'0.6',20);
|
||||
}
|
||||
|
||||
$result_data['bmi'] = $num;
|
||||
// $num2 = (($num2 > $weight * 0.15) ? ($weight * 0.15) : $num2);
|
||||
if(bccomp($num2, bcmul($weight,'0.15',20), 20) === 1){
|
||||
$num2 = bcmul($weight,'0.15',2);
|
||||
}
|
||||
// $result_data['bone'] = ($num2 < $weight * 0.02) ? ($weight * 0.02) : $num2;
|
||||
if(bccomp($num2, bcmul($weight,'0.02',20), 20) === -1){
|
||||
$result_data['bone'] = bcmul($weight,'0.02',2);
|
||||
}else{
|
||||
$result_data['bone'] = $num2;
|
||||
}
|
||||
// $num3 = (($num3 > 75.0) ? 75.0 : $num3);
|
||||
if(bccomp($num3, '75.0', 20) === 1){
|
||||
$num3 = '75.0';
|
||||
}
|
||||
// $result_data['muscle'] = ($num3 < 15.0) ? 15.0 : $num3;
|
||||
if(bccomp($num3, '15.0', 20) === -1){
|
||||
$result_data['muscle'] = '15.00';
|
||||
}else{
|
||||
$result_data['muscle'] = $num3;
|
||||
}
|
||||
// $num4 = (($num4 > 70.0) ? 70.0 : $num4);
|
||||
if(bccomp($num4, '70.0', 20) === 1){
|
||||
$num4 = '70.0';
|
||||
}
|
||||
// $result_data['water'] = ($num4 < 20.0) ? 20.0 : $num4;
|
||||
if(bccomp($num4, '20.0', 20) === -1){
|
||||
$result_data['water'] = '20.00';
|
||||
}else{
|
||||
$result_data['water'] = $num4;
|
||||
}
|
||||
// $num5 = (($num5 > 50.0) ? 50.0 : $num5);
|
||||
if(bccomp($num5, '50.0', 20) === 1){
|
||||
$num5 = '50.0';
|
||||
}
|
||||
// $result_data['fat_r'] = ($num5 < 5.0) ? 5.0 : $num5;
|
||||
|
||||
if(bccomp($num5, '5.0', 20) === -1){
|
||||
$result_data['fat_r'] = '5.00';
|
||||
}else{
|
||||
// $result_data['fat_r'] = $num5;
|
||||
$result_data['fat_r'] = substr($num5, 0, strpos($num5, ".") + 3);
|
||||
}
|
||||
// $result_data['sfr'] = $num6 <= 0 ? "0" : $num6;
|
||||
if(bccomp($num6, '0.0', 20) === -1){
|
||||
$result_data['sfr'] = '0.00';
|
||||
}else{
|
||||
$result_data['sfr'] = $num6;
|
||||
}
|
||||
// $result_data['skeletalmuscle'] = $num7;
|
||||
$result_data['skeletalmuscle'] = substr($num7, 0, strpos($num7, ".") + 3);
|
||||
// $num8 = (($num8 > 50.0) ? 50.0 : $num8);
|
||||
if(bccomp($num8, '50.0', 20) === 1){
|
||||
$num8 = '50.00';
|
||||
}
|
||||
// $result_data['protein'] = ($num8 < 10.0) ? 10.0 : $num8;
|
||||
if(bccomp($num8, '10.0', 20) === -1){
|
||||
$result_data['protein'] = '10.00';
|
||||
}else{
|
||||
$result_data['protein'] = $num8;
|
||||
}
|
||||
// $num9 = (($num9 > 20.0) ? 20.0 : $num9);
|
||||
if(bccomp($num9, '20.0', 20) === 1){
|
||||
$num9 = '20.0';
|
||||
}
|
||||
// $result_data['visceral'] = ($num9 < 1.0) ? 1.0 : $num9;
|
||||
if(bccomp($num9, '1.0', 20) === -1){
|
||||
$result_data['visceral'] = '1.0';
|
||||
}else{
|
||||
$result_data['visceral'] = $num9;
|
||||
}
|
||||
// $result_data['kcal'] = $num10 <= 0 ? "0" : $num10;
|
||||
if(bccomp($num10, '0', 20) !== 1){
|
||||
$result_data['kcal'] = '0';
|
||||
}else{
|
||||
$result_data['kcal'] = $num10;
|
||||
}
|
||||
|
||||
// $standard_level = ($weight-$standard_weight)/$standard_weight;
|
||||
$standard_level = bcdiv(bcsub($weight,$standard_weight,20),$standard_weight,2);
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
if ($age < 18){
|
||||
$num11 = $age;
|
||||
}else{
|
||||
// $num11 = (($num11 > ($age + 10)) ? (($age + 10)) : $num11);
|
||||
if(bccomp($num11, $age + 10, 20) === 1){
|
||||
$num11 = $age + 10;
|
||||
}
|
||||
// $num11 = (($num11 < ($age - 10)) ? (($age - 10)) : $num11);
|
||||
if(bccomp($num11, $age - 10, 20) === -1){
|
||||
$num11 = $age - 10;
|
||||
}
|
||||
}
|
||||
|
||||
$result_data['bodyage'] = $num11;
|
||||
$result_data['weight'] = $weight;
|
||||
$result_data['height'] = $height;
|
||||
$result_data['age'] = $age;
|
||||
$result_data['adc'] = $impedance;
|
||||
$result_data['gender'] = $gender;
|
||||
$result_data['standard_level'] = $standard_level;
|
||||
return $result_data;
|
||||
}
|
||||
// 计算脂肪率
|
||||
function calculate_fat_r(){
|
||||
}
|
||||
// 计算脂肪量
|
||||
function calculate_zhifangliang(){
|
||||
|
||||
}
|
||||
// 计算肌肉率
|
||||
function calculate_jiroulv(){
|
||||
|
||||
}
|
||||
// 计算肌肉量
|
||||
function calculate_jirouliang(){
|
||||
|
||||
}
|
||||
// 计算水分
|
||||
function calculate_shuifen(){
|
||||
|
||||
}
|
||||
// 计算蛋白量
|
||||
function calculate_danbailiang(){
|
||||
|
||||
}
|
||||
// 计算骨重
|
||||
function calculate_guzhong(){
|
||||
|
||||
}
|
||||
// 计算蛋白率
|
||||
function calculate_danbailv(){
|
||||
|
||||
}
|
||||
// 计算基础代谢
|
||||
function calculate_jichudaixie(){
|
||||
|
||||
}
|
||||
// 计算内脏指数
|
||||
function calculate_neizangzhishu(){
|
||||
|
||||
}
|
||||
// 计算皮下脂肪
|
||||
function calculate_pixiazhifang(){
|
||||
|
||||
}
|
||||
// 计算肥胖等级
|
||||
function calculate_feipangdengji(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function msg($code,$msg='',$data=[]){
|
||||
return json(['code'=>$code,'msg'=>$msg,'data'=>$data]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
|
||||
class Card extends Base{
|
||||
|
||||
protected $card_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
'juese'=>'app_user_data',
|
||||
'card'=>'app_card_data'
|
||||
];
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 卡片列表信息
|
||||
public function card_list_msg(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
return $this->card_list_msg_action($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 card_user_order(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('card_data', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
return $this->card_user_order_action($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################################################################
|
||||
################################################################action################################################################
|
||||
public function card_list_msg_action($data){
|
||||
// 检查角色
|
||||
$user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find();
|
||||
if(!$user_data){
|
||||
return $this->msg(10003,'未核实到角色信息');
|
||||
}
|
||||
// 获取卡片信息
|
||||
$card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->cache(86400)->select();
|
||||
// 根据用户处理卡片信息
|
||||
$return_data = [
|
||||
'chosen_yes'=>[],
|
||||
'chosen_no'=>[],
|
||||
];
|
||||
if($user_data['card_order'] != ''){
|
||||
$user_data['card_order'] = explode(',',$user_data['card_order']);
|
||||
}else{
|
||||
$user_data['card_order'] = [];
|
||||
}
|
||||
for ($i=0; $i < count($card_data); $i++) {
|
||||
if(!in_array($card_data[$i]['id'],$user_data['card_order'])){
|
||||
$return_data['chosen_no'][] = $card_data[$i];
|
||||
}else{
|
||||
$key = array_search($card_data[$i]['id'], $user_data['card_order']);
|
||||
$return_data['chosen_yes'][$key] = $card_data[$i];
|
||||
}
|
||||
}
|
||||
ksort($return_data['chosen_yes']);
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
public function card_user_order_action($data){
|
||||
|
||||
if($data['card_data'] != ''){
|
||||
$data['card_data2'] = explode(',',$data['card_data']);
|
||||
}else{
|
||||
$data['card_data2'] = [];
|
||||
}
|
||||
|
||||
foreach ($data['card_data2'] as $key => $value) {
|
||||
if(!$this->verify_data_is_ok($value,'intnum')){
|
||||
return $this->msg(10005,'卡片id错误');
|
||||
}
|
||||
}
|
||||
$user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->count();
|
||||
if($user_data <= 0){
|
||||
return $this->msg(10003,'未核实到角色信息');
|
||||
}
|
||||
$result = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['card_order' => $data['card_data']]);
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
|
||||
class Countfood extends Base{
|
||||
|
||||
protected $card_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
];
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 卡片列表信息
|
||||
public function card_list_msg(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
return $this->card_list_msg_action($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################################################################
|
||||
################################################################action################################################################
|
||||
public function card_list_msg_action($data){
|
||||
// 检查角色
|
||||
$user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find();
|
||||
if(!$user_data){
|
||||
return $this->msg(10003,'未核实到角色信息');
|
||||
}
|
||||
// 获取卡片信息
|
||||
$card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->cache(86400)->select();
|
||||
// 根据用户处理卡片信息
|
||||
$return_data = [
|
||||
'chosen_yes'=>[],
|
||||
'chosen_no'=>[],
|
||||
];
|
||||
if($user_data['card_order'] != ''){
|
||||
$user_data['card_order'] = explode(',',$user_data['card_order']);
|
||||
}else{
|
||||
$user_data['card_order'] = [];
|
||||
}
|
||||
for ($i=0; $i < count($card_data); $i++) {
|
||||
if(!in_array($card_data[$i]['id'],$user_data['card_order'])){
|
||||
$return_data['chosen_no'][] = $card_data[$i];
|
||||
}else{
|
||||
$key = array_search($card_data[$i]['id'], $user_data['card_order']);
|
||||
$return_data['chosen_yes'][$key] = $card_data[$i];
|
||||
}
|
||||
}
|
||||
ksort($return_data['chosen_yes']);
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
|
||||
class Gufen extends Base{
|
||||
|
||||
protected $card_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
'guize'=>'admin_estimate',
|
||||
|
||||
];
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 获取单个类型列表
|
||||
public function get_single_data($data = ['address'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){
|
||||
$return_data = $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['address'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
unset($data['token']);
|
||||
$return_data = $this->sportstesting_get_type_list_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################################################################
|
||||
################################################################action################################################################
|
||||
public function sportstesting_get_type_list_action($data){
|
||||
|
||||
$parameter_data = explode(',',$data['address']);
|
||||
$gender = $data['gender'];
|
||||
// 精准查询地市规则start
|
||||
// if(count($parameter_data) == 1){
|
||||
// $db_condition = "province = '".$parameter_data[0]."'";
|
||||
// }else if(count($parameter_data) == 2){
|
||||
// $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
|
||||
// }else if(count($parameter_data) == 3){
|
||||
// $db_condition = "province = ".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
|
||||
// }else{
|
||||
// return $this->msg(10005);
|
||||
// }
|
||||
// 精准查询地市规则end
|
||||
// 全省地市一个规则start
|
||||
$db_condition = "province = '".$parameter_data[0]."'";
|
||||
// 全省地市一个规则end
|
||||
$data = Db::table($this->card_db_name['guize'])->where($db_condition)->find();
|
||||
$data = json_decode($data['content'],true);
|
||||
$result = $this->handle_default_rule_list_content($data,$gender);
|
||||
return $this->msg($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Controller;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use app\NewReedaw\controller\app\Role;
|
||||
use app\app\controller\Language;
|
||||
|
||||
class Index extends Base{
|
||||
|
||||
|
|
@ -15,7 +16,67 @@ class Index extends Base{
|
|||
'zhanghao'=>'app_account_number',
|
||||
'juese'=>'app_user_data',
|
||||
'body_data'=>'app_card_body_data',
|
||||
|
||||
'banben'=>'app_version_log',
|
||||
'shangwuhezuo'=>'admin_business_cooperation',
|
||||
'diqu'=>'admin_estimate',
|
||||
'banner'=>'admin_notice_banner',
|
||||
'skip'=>'app_card_skip_data',
|
||||
'vitalcapacity'=>'app_card_vitalcapacity_data',
|
||||
];
|
||||
protected $request_result = [
|
||||
'2'=>['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI',''],'head'=>['头围',''],'fat_w'=>['脂肪量','kg'],'fat_r'=>['脂肪率','%'],'muscleval'=>['肌肉量','kg'],'muscle'=>['肌肉率','%'],'proteinval'=>['蛋白量','kg'],'protein'=>['蛋白率','%'],'water'=>['水分',''],'bone'=>['骨重','kg'],'visceral'=>['内脏指数',''],'sfr'=>['皮下脂肪','%'],'kcal'=>['基础代谢','kcal'],'un_fat_w_weight'=>['去脂体重','kg'],'body_age'=>['体龄',''],'body_level'=>['肥胖等级',''],'body_type'=>['体型','']],
|
||||
'6'=>['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']],
|
||||
'8'=>['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']]
|
||||
];
|
||||
protected $identity_list = ['P0'=>'陌生人','P1'=>'爸爸','P2'=>'妈妈','P3'=>'大宝','P4'=>'二宝','P5'=>'三宝','P6'=>'四宝','P7'=>'爷爷','P8'=>'奶奶'];
|
||||
protected $grade_list = [
|
||||
['id'=>'nothing','name'=>'无'],
|
||||
['id'=>'grade_s_1','name'=>'小学一年级'],
|
||||
['id'=>'grade_s_2','name'=>'小学二年级'],
|
||||
['id'=>'grade_s_3','name'=>'小学三年级'],
|
||||
['id'=>'grade_s_4','name'=>'小学四年级'],
|
||||
['id'=>'grade_s_5','name'=>'小学五年级'],
|
||||
['id'=>'grade_s_6','name'=>'小学六年级'],
|
||||
['id'=>'grade_m_1','name'=>'初中一年级'],
|
||||
['id'=>'grade_m_2','name'=>'初中二年级'],
|
||||
['id'=>'grade_m_3','name'=>'初中三年级'],
|
||||
['id'=>'grade_h_1','name'=>'高中一年级'],
|
||||
['id'=>'grade_h_2','name'=>'高中二年级'],
|
||||
['id'=>'grade_h_3','name'=>'高中三年级'],
|
||||
['id'=>'grade_u_12','name'=>'大学一、二年级'],
|
||||
['id'=>'grade_u_34','name'=>'大学三、四年级']
|
||||
];
|
||||
protected $language_country = [
|
||||
'en' => 'English', // 英语(通用)★
|
||||
'zh-Hans' => '中文', // 中文(简体)★
|
||||
// 'es' => 'Español', // 西班牙语(西班牙)★
|
||||
// 'fr' => 'Français', // 法语(法国)★
|
||||
// 'pt' => 'Português', // 葡萄牙语(巴西)★
|
||||
// 'ar' => 'العربية', // 阿拉伯语(标准)★
|
||||
// 'ru' => 'Русский', // 俄语(俄罗斯)★
|
||||
// 'de' => 'Deutsch', // 德语(德国)★
|
||||
// 'ja' => '日本語', // 日语
|
||||
// 'ko' => '한국어', // 韩语
|
||||
// 'it' => 'Italiano', // 意大利语
|
||||
// 'nl' => 'Nederlands', // 荷兰语
|
||||
// 'hi' => 'हिन्दी', // 印地语
|
||||
// 'tr' => 'Türkçe', // 土耳其语
|
||||
// 'vi' => 'Tiếng Việt', // 越南语
|
||||
// 'th' => 'ไทย', // 泰语
|
||||
// 'pl' => 'Polski', // 波兰语
|
||||
// 'sv' => 'Svenska', // 瑞典语
|
||||
// 'fi' => 'Suomi', // 芬兰语
|
||||
// 'da' => 'Dansk', // 丹麦语
|
||||
// 'no' => 'Norsk', // 挪威语
|
||||
// 'he' => 'עברית', // 希伯来语
|
||||
// 'id' => 'Bahasa Indonesia', // 印尼语
|
||||
// 'ms' => 'Bahasa Melayu', // 马来语
|
||||
// 'cs' => 'Čeština', // 捷克语
|
||||
// 'hu' => 'Magyar', // 匈牙利语
|
||||
// 'el' => 'Ελληνικά', // 希腊语
|
||||
// 'ro' => 'Română', // 罗马尼亚语
|
||||
// 'sk' => 'Slovenčina', // 斯洛伐克语
|
||||
// 'uk' => 'Українська', // 乌克兰语
|
||||
];
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
|
|
@ -30,16 +91,7 @@ class Index extends Base{
|
|||
// 配置信息
|
||||
public function config($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$data = input('post.');
|
||||
return $this->config_action($data);
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
|
|
@ -55,25 +107,29 @@ class Index extends Base{
|
|||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
// 遗传身高
|
||||
|
||||
// 身高预测
|
||||
public function genetic_height(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!is_array($data)){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||||
return $this->msg(10005);
|
||||
return $this->msg(10005,'birthday type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['dadHeight'],'num')){
|
||||
return $this->msg(10005);
|
||||
return $this->msg(10005,'dadHeight type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['momHeight'],'num')){
|
||||
return $this->msg(10005);
|
||||
return $this->msg(10005,'momHeight type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['sex'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
return $this->msg(10005,'sex type error');
|
||||
}
|
||||
|
||||
// 直接开始业务,请求外部接口start
|
||||
|
|
@ -85,7 +141,6 @@ class Index extends Base{
|
|||
'sex'=>$data['sex'],
|
||||
];
|
||||
$request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
|
||||
// 直接开始业务,请求外部接口end
|
||||
return json($request_result);
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
|
|
@ -101,41 +156,45 @@ class Index extends Base{
|
|||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
|
||||
// BMI测评
|
||||
public function bmi_evaluation(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
|
||||
$cbe_data = input('post.');
|
||||
if(!is_array($cbe_data)){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!array_key_exists('height', $cbe_data) || !array_key_exists('weight', $cbe_data) || !array_key_exists('birthday', $cbe_data) || !array_key_exists('sex', $cbe_data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||||
return $this->msg(10005);
|
||||
unset($cbe_data['token']);
|
||||
if(!$this->verify_data_is_ok($cbe_data['birthday'],'datetime')){
|
||||
return $this->msg(10005,'birthday type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['height'],'num')){
|
||||
return $this->msg(10005);
|
||||
if(!$this->verify_data_is_ok($cbe_data['height'],'num')){
|
||||
return $this->msg(10005,'height type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['weight'],'num')){
|
||||
return $this->msg(10005);
|
||||
if(!$this->verify_data_is_ok($cbe_data['weight'],'num')){
|
||||
return $this->msg(10005,'weight type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['sex'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
if(!$this->verify_data_is_ok($cbe_data['sex'],'intnum')){
|
||||
return $this->msg(10005,'sex type error');
|
||||
}
|
||||
|
||||
// 直接开始业务,请求外部接口start
|
||||
$url = 'http://ybdevice.pcxbc.com/api/result/calcbmi';
|
||||
$temporary_parameter = [
|
||||
'height'=>$data['height'],
|
||||
'weight'=>$data['weight'],
|
||||
'birthday'=>$data['birthday'],
|
||||
'sex'=>$data['sex'],
|
||||
'height'=>$cbe_data['height'],
|
||||
'weight'=>$cbe_data['weight'],
|
||||
'birthday'=>$cbe_data['birthday'],
|
||||
'sex'=>$cbe_data['sex'],
|
||||
];
|
||||
$request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
|
||||
// 直接开始业务,请求外部接口end
|
||||
|
||||
// 处理进度点
|
||||
$return_result =$this->bmi_evaluation_action($request_result);
|
||||
return $return_result;
|
||||
$request_result =$this->bmi_evaluation_action($request_result);
|
||||
return $request_result;
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
$logContent["flie"] = $e->getFile();
|
||||
|
|
@ -146,24 +205,35 @@ class Index extends Base{
|
|||
$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);
|
||||
$this->record_api_log($cbe_data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
// 获取首页角色信息
|
||||
public function get_user_data_information(){
|
||||
|
||||
// 数据对比(包含身体、跳绳、肺活量)
|
||||
public function all_data_contrast($data = ['before_id'=>'171','after_id'=>'174','type'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
|
||||
if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
if(!$this->verify_data_is_ok($data['before_id'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
if(!$this->verify_data_is_ok($data['after_id'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['type'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
unset($data['token']);
|
||||
if($data['type'] == '2'){
|
||||
return $this->get_body_data_contrast($data);
|
||||
}else if($data['type'] == '6'){
|
||||
return $this->get_skip_data_contrast($data);
|
||||
}else if($data['type'] == '8'){
|
||||
return $this->get_vitalcapacity_data_contrast($data);
|
||||
}
|
||||
return $this->get_user_data_information_action($data);
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
$logContent["flie"] = $e->getFile();
|
||||
|
|
@ -177,7 +247,37 @@ class Index extends Base{
|
|||
$this->record_api_log($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// // 获取首页角色信息
|
||||
// public function get_user_data_information(){
|
||||
// try {
|
||||
// $data = input('post.');
|
||||
// if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
|
||||
// return $this->msg(10001);
|
||||
// }
|
||||
// if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
// return $this->msg(10005,'token type error');
|
||||
// }
|
||||
// if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
// return $this->msg(10005,'aud_id type error');
|
||||
// }
|
||||
// return $this->get_user_data_information_action($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################################################################
|
||||
################################################################action################################################################
|
||||
|
|
@ -207,16 +307,44 @@ class Index extends Base{
|
|||
]
|
||||
],
|
||||
'king_kong_region'=>[
|
||||
['title'=>'增量对比','icon'=>'','jump'=>''],
|
||||
['title'=>'中招估分','icon'=>'','jump'=>''],
|
||||
['title'=>'遗传身高','icon'=>'','jump'=>''],
|
||||
['title'=>'BMI测评','icon'=>'','jump'=>''],
|
||||
['title'=>'减值对比','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/contrast.png','jump'=>'/pageTwo/compk/contrast'],
|
||||
['title'=>'中招估分','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/report.png','jump'=>'/pageTwo/score/report'],
|
||||
['title'=>'遗传身高','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/inheritHeighet.png','jump'=>'/pageTwo/home/inheritHeighet'],
|
||||
['title'=>'BMI测评','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/bmi.png','jump'=>'/pageTwo/home/bmi'],
|
||||
],
|
||||
'role_list'=>[
|
||||
]
|
||||
'version_msg'=>[],
|
||||
'login_status'=>[],
|
||||
'business_cooperation_url'=>[],
|
||||
'area_list'=>[],
|
||||
'identity_list'=>[],
|
||||
'grade_list'=>[],
|
||||
'banner'=>[],
|
||||
|
||||
];
|
||||
$role = new Role;
|
||||
$return_data['role_list'] = $role->role_list_action(['token'=>$data['token'],'type'=>2])->getData()['data'];
|
||||
|
||||
$temporary = $this->login_invalid_version($data);
|
||||
$return_data['version_msg'] = $temporary[1];
|
||||
$return_data['login_status'] = $temporary[0];
|
||||
|
||||
$return_data['business_cooperation_url'] = Db::table($this->index_db_name['shangwuhezuo'])->where(['is_del'=>0])->field('title,data_url as url')->select();
|
||||
|
||||
$address_data = Db::table($this->index_db_name['diqu'])->where(['type' => '2'])->cache(86400)->field('id,content,city,area')->find();
|
||||
$return_data['area_list'] = json_decode($address_data['content'],true);
|
||||
$return_data['identity_list'] = [];
|
||||
foreach ($this->identity_list as $key => $value) {
|
||||
array_push($return_data['identity_list'],['id'=>$key,'name'=>$value]);
|
||||
}
|
||||
$return_data['grade_list'] = $this->grade_list;
|
||||
|
||||
$return_data['banner'] = Db::table($this->index_db_name['banner'])->where(['scene_data' => '3','is_del'=>0])->cache(3600)->order('sort_num desc')->field('id,type,pic,jump_url,parameter_data,sort_num')->select();
|
||||
|
||||
for ($i=0; $i < count($return_data['banner']); $i++) {
|
||||
if($return_data['banner'][$i]['type'] != 1){
|
||||
$return_data['banner'][$i]['parameter_data'] = '';
|
||||
}
|
||||
unset($return_data['banner'][$i]['sort_num']);
|
||||
unset($return_data['banner'][$i]['ROW_NUMBER']);
|
||||
}
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
public function bmi_evaluation_action($data){
|
||||
|
|
@ -281,18 +409,396 @@ class Index extends Base{
|
|||
// 处理key名称一致end
|
||||
return $this->msg($data);
|
||||
}
|
||||
public function get_user_data_information_action($data){
|
||||
$return_result = [
|
||||
'body_data'=>[],
|
||||
'kcal_data'=>[],
|
||||
'card_data'=>[]
|
||||
];
|
||||
$aud_data = Db::table($this->index_db_name['juese'])->where(['id'=>$data['aud_id']])->find();
|
||||
|
||||
$body_data = Db::table($this->index_db_name['body_data'])->where(['id'=>$data['aud_id']])->find();
|
||||
// 数据对比(身体)
|
||||
public function get_body_data_contrast($data){
|
||||
$data2 = [$data['before_id'],$data['after_id']];
|
||||
$data3 = implode(',',$data2);
|
||||
$calculate_arr = [];
|
||||
$result = Db::query("
|
||||
select
|
||||
acbd.id,
|
||||
acbd.height,
|
||||
acbd.weight,
|
||||
acbd.bmi,
|
||||
acbd.fat_r,
|
||||
acbd.fat_w,
|
||||
acbd.muscle,
|
||||
acbd.muscleval,
|
||||
acbd.water,
|
||||
acbd.proteinval,
|
||||
acbd.bone,
|
||||
acbd.protein,
|
||||
acbd.kcal,
|
||||
acbd.visceral,
|
||||
acbd.sfr,
|
||||
acbd.record_time,
|
||||
acbd.record_type,
|
||||
acbd.head_circumference,
|
||||
REPLACE(CONVERT(varchar(10), acbd.record_time, 23), '-', '-') AS b_time,
|
||||
aud.nickname,
|
||||
aud.gender,
|
||||
aud.birthday,
|
||||
aud.head_pic
|
||||
from ".$this->index_db_name['body_data']." as acbd
|
||||
left join ".$this->index_db_name['juese']." as aud on acbd.aud_id=aud.id
|
||||
where acbd.id in ($data3)
|
||||
and acbd.is_del = 0
|
||||
");
|
||||
|
||||
if(!$result || count($result)<2){
|
||||
return $this->msg(10004);
|
||||
}
|
||||
// 调整顺序
|
||||
foreach ($result as $key => $value) {
|
||||
if($value['id'] == $data2[0]){
|
||||
$calculate_arr['before'] = $value;
|
||||
}else{
|
||||
$calculate_arr['after'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$return_data['time'] = $calculate_arr['before']['b_time'].'与'.$calculate_arr['after']['b_time'];
|
||||
$return_data['headimg'] = $calculate_arr['before']['head_pic'];
|
||||
$return_data['name'] = $calculate_arr['before']['nickname'];
|
||||
$return_data['gender'] = $calculate_arr['before']['gender'];
|
||||
$return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
|
||||
$return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
|
||||
$return_data['list'] = [];
|
||||
// 处理如果没有阻抗的数据为0,显示异常start;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息
|
||||
if($calculate_arr['before']['record_type'] != 'by_device_adc' && $calculate_arr['after']['record_type'] != 'by_device_adc'){
|
||||
foreach ($calculate_arr['before'] as $key => $value) {
|
||||
if(!in_array($key, ['height','weight','bmi','head_circumference'])){
|
||||
unset($calculate_arr['before'][$key]);
|
||||
unset($calculate_arr['after'][$key]);
|
||||
}
|
||||
}
|
||||
if($return_data['age']>=3){
|
||||
unset($calculate_arr['before']['head_circumference']);
|
||||
unset($calculate_arr['after']['head_circumference']);
|
||||
}else{
|
||||
$calculate_arr['before']['head_circumference'] = json_decode($calculate_arr['before']['head_circumference'],true);
|
||||
$calculate_arr['after']['head_circumference'] = json_decode($calculate_arr['after']['head_circumference'],true);
|
||||
foreach ($calculate_arr as $key => $value) {
|
||||
if(array_key_exists('value',$value['head_circumference'])){
|
||||
$calculate_arr[$key]['head'][0] = $value['head_circumference']['value'];
|
||||
}else{
|
||||
$calculate_arr[$key]['head'][0] = 0;
|
||||
}
|
||||
if(array_key_exists('level',$value['head_circumference'])){
|
||||
$calculate_arr[$key]['head'][1] = $value['head_circumference']['level'];
|
||||
}else{
|
||||
$calculate_arr[$key]['head'][1] = '异常';
|
||||
}
|
||||
if(array_key_exists('color',$value['head_circumference'])){
|
||||
$calculate_arr[$key]['head'][2] = $value['head_circumference']['color'];
|
||||
}else{
|
||||
$calculate_arr[$key]['head'][2] = '';
|
||||
}
|
||||
$calculate_arr[$key]['head'] = implode(',',$calculate_arr[$key]['head']);
|
||||
unset($calculate_arr['before']['head_circumference']);
|
||||
unset($calculate_arr['after']['head_circumference']);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($calculate_arr as $key => $value) {
|
||||
if($value['record_type'] != 'by_device_adc'){
|
||||
$calculate_arr[$key]['fat_r'] = "0,异常";
|
||||
$calculate_arr[$key]['fat_w'] = "0,异常";
|
||||
$calculate_arr[$key]['muscle'] = "0,异常";
|
||||
$calculate_arr[$key]['muscleval'] = "0,异常";
|
||||
$calculate_arr[$key]['water'] = "0,异常";
|
||||
$calculate_arr[$key]['proteinval'] = "0,异常";
|
||||
$calculate_arr[$key]['bone'] = "0,异常";
|
||||
$calculate_arr[$key]['protein'] = "0,异常";
|
||||
$calculate_arr[$key]['kcal'] = "0,异常";
|
||||
$calculate_arr[$key]['visceral'] = "0,异常";
|
||||
$calculate_arr[$key]['sfr'] = "0,异常";
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理如果没有阻抗的数据为0,显示异常end;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息
|
||||
foreach ($calculate_arr['before'] as $key => $value) {
|
||||
if(in_array($key, ['height','weight','bmi','head','fat_r','fat_w','muscle','muscleval','water','proteinval','bone','protein','kcal','visceral','sfr'])){
|
||||
$before_arr = explode(',', $value);
|
||||
$after_arr = explode(',', $calculate_arr['after'][$key]);
|
||||
array_push($return_data['list'], [
|
||||
'firstresult'=>[
|
||||
'color'=>'',
|
||||
'level'=>$before_arr[1],
|
||||
'value'=>$before_arr[0],
|
||||
'title'=>$this->request_result['2'][$key][0],
|
||||
'unit'=>$this->request_result['2'][$key][1],
|
||||
'name'=>$key,
|
||||
],
|
||||
'secondresult'=>[
|
||||
'color'=>'',
|
||||
'level'=>$after_arr[1],
|
||||
'value'=>$after_arr[0],
|
||||
'title'=>$this->request_result['2'][$key][0],
|
||||
'unit'=>$this->request_result['2'][$key][1],
|
||||
'name'=>$key,
|
||||
],
|
||||
'diffval'=>bcsub($after_arr[0],$before_arr[0],2),
|
||||
]);
|
||||
}
|
||||
}
|
||||
// 添加头围数据(如果需要的话)end
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
// 数据对比(跳绳)
|
||||
public function get_skip_data_contrast($data){
|
||||
$data2 = [$data['before_id'],$data['after_id']];
|
||||
$data3 = implode(',',$data2);
|
||||
$calculate_arr = [];
|
||||
$result = Db::query("
|
||||
select
|
||||
acsd.id,
|
||||
acsd.jump_num,
|
||||
acsd.jump_time,
|
||||
acsd.jump_kcal,
|
||||
acsd.record_time,
|
||||
REPLACE(CONVERT(varchar(10), acsd.record_time, 23), '-', '-') AS b_time,
|
||||
aud.nickname,
|
||||
aud.gender,
|
||||
aud.birthday,
|
||||
aud.head_pic
|
||||
from ".$this->index_db_name['skip']." as acsd
|
||||
left join ".$this->index_db_name['juese']." as aud on acsd.aud_id=aud.id
|
||||
where acsd.id in ($data3)
|
||||
and acsd.is_del = 0
|
||||
");
|
||||
|
||||
if(!$result || count($result)<2){
|
||||
return $this->msg(10004);
|
||||
}
|
||||
// 调整顺序
|
||||
foreach ($result as $key => $value) {
|
||||
if($value['id'] == $data2[0]){
|
||||
$calculate_arr['before'] = $value;
|
||||
}else{
|
||||
$calculate_arr['after'] = $value;
|
||||
}
|
||||
}
|
||||
$return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time'];
|
||||
$return_data['headimg'] = $calculate_arr['before']['head_pic'];
|
||||
$return_data['name'] = $calculate_arr['before']['nickname'];
|
||||
$return_data['gender'] = $calculate_arr['before']['gender'];
|
||||
$return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
|
||||
$return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
|
||||
|
||||
$return_data['list'] = [];
|
||||
foreach ($calculate_arr['before'] as $key => $value) {
|
||||
if(in_array($key, ['jump_num','jump_time','jump_kcal'])){
|
||||
$before_arr = $value;
|
||||
$after_arr = $calculate_arr['after'][$key];
|
||||
$temporary_arr = [
|
||||
'firstresult'=>[
|
||||
'color'=>'',
|
||||
'level'=>'',
|
||||
'value'=>$key=='jump_time'?implode(':',$this->handle_hour_branch_second($before_arr)):$before_arr,
|
||||
'title'=>$this->request_result['6'][$key][0],
|
||||
'unit'=>$this->request_result['6'][$key][1],
|
||||
'name'=>$key,
|
||||
],
|
||||
'secondresult'=>[
|
||||
'color'=>'',
|
||||
'level'=>'',
|
||||
'value'=>$key=='jump_time'?implode(':',$this->handle_hour_branch_second($after_arr)):$after_arr,
|
||||
'title'=>$this->request_result['6'][$key][0],
|
||||
'unit'=>$this->request_result['6'][$key][1],
|
||||
'name'=>$key,
|
||||
],
|
||||
'diffval'=>bcsub($after_arr,$before_arr,2)
|
||||
];
|
||||
if($key=='jump_time'){
|
||||
$temporary_arr['diffval'] = $temporary_arr['diffval'] >= 0?implode(':',$this->handle_hour_branch_second($temporary_arr['diffval'])):'-'.implode(':',$this->handle_hour_branch_second($temporary_arr['diffval']));
|
||||
}
|
||||
array_push($return_data['list'], $temporary_arr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
// 数据对比(肺活)
|
||||
public function get_vitalcapacity_data_contrast($data){
|
||||
$data2 = [$data['before_id'],$data['after_id']];
|
||||
$data3 = implode(',',$data2);
|
||||
$calculate_arr = [];
|
||||
$result = Db::query("
|
||||
select
|
||||
acsd.id,
|
||||
acsd.one_val,
|
||||
acsd.two_val,
|
||||
acsd.three_val,
|
||||
acsd.average_val,
|
||||
acsd.score_val as score,
|
||||
acsd.record_time,
|
||||
REPLACE(CONVERT(varchar(10), acsd.record_time, 23), '-', '-') AS b_time,
|
||||
aud.nickname,
|
||||
aud.gender,
|
||||
aud.birthday,
|
||||
aud.head_pic
|
||||
from ".$this->index_db_name['vitalcapacity']." as acsd
|
||||
left join ".$this->index_db_name['juese']." as aud on acsd.aud_id=aud.id
|
||||
where acsd.id in ($data3)
|
||||
and acsd.is_del = 0
|
||||
");
|
||||
|
||||
if(!$result || count($result)<2){
|
||||
return $this->msg(10004);
|
||||
}
|
||||
// 调整顺序
|
||||
foreach ($result as $key => $value) {
|
||||
if($value['id'] == $data2[0]){
|
||||
$calculate_arr['before'] = $value;
|
||||
}else{
|
||||
$calculate_arr['after'] = $value;
|
||||
}
|
||||
}
|
||||
$return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time'];
|
||||
$return_data['headimg'] = $calculate_arr['before']['head_pic'];
|
||||
$return_data['name'] = $calculate_arr['before']['nickname'];
|
||||
$return_data['gender'] = $calculate_arr['before']['gender'];
|
||||
$return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
|
||||
$return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
|
||||
|
||||
$return_data['list'] = [];
|
||||
foreach ($calculate_arr['before'] as $key => $value) {
|
||||
if(in_array($key, ['one_val','two_val','three_val','average_val','score_val'])){
|
||||
$before_arr = $value;
|
||||
$after_arr = $calculate_arr['after'][$key];
|
||||
$temporary_arr = [
|
||||
'firstresult'=>[
|
||||
'color'=>'',
|
||||
'level'=>'',
|
||||
'value'=>$before_arr,
|
||||
'title'=>$this->request_result['8'][$key][0],
|
||||
'unit'=>$this->request_result['8'][$key][1],
|
||||
'name'=>$key,
|
||||
],
|
||||
'secondresult'=>[
|
||||
'color'=>'',
|
||||
'level'=>'',
|
||||
'value'=>$after_arr,
|
||||
'title'=>$this->request_result['8'][$key][0],
|
||||
'unit'=>$this->request_result['8'][$key][1],
|
||||
'name'=>$key,
|
||||
],
|
||||
'diffval'=>bcsub($after_arr,$before_arr,2)
|
||||
];
|
||||
array_push($return_data['list'], $temporary_arr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
|
||||
|
||||
################################################################内部调用################################################################
|
||||
################################################################内部调用################################################################
|
||||
// 检测版本及判断是否登录失效
|
||||
public function login_invalid_version($data){
|
||||
// 获取客户端IP
|
||||
$ip = request()->ip();
|
||||
// 调用IP识别方法
|
||||
$region = $this->getIpInfo($ip);
|
||||
// 解析地区信息
|
||||
$regionParts = explode('|', $region);
|
||||
$country = $regionParts[0] ?? '';
|
||||
// 判断国家是否在支持的语言列表中
|
||||
$language = '';
|
||||
if ($country && $country !== '0') {
|
||||
$languageMap = [
|
||||
'中国' => 'zh-Hans',
|
||||
'美国' => 'en',
|
||||
'英国' => 'en',
|
||||
'西班牙' => 'es',
|
||||
'法国' => 'fr',
|
||||
'葡萄牙' => 'pt',
|
||||
'阿拉伯联合酋长国' => 'ar',
|
||||
'俄罗斯' => 'ru',
|
||||
'德国' => 'de'
|
||||
];
|
||||
$language = $languageMap[$country] ?? '';
|
||||
}
|
||||
// 检查语言是否在支持列表中
|
||||
$language_all = new Language();
|
||||
$isSupportedLanguage = array_key_exists($language, $language_all->getSupportedLanguages());
|
||||
|
||||
$result = Db::table($this->index_db_name['banben'])->order('is_del,id desc')->find();
|
||||
if($result){
|
||||
$version = $result['version_num_original'];
|
||||
$url = $result['download_url'];
|
||||
}else{
|
||||
$version = '';
|
||||
$url = '';
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return [['code'=>-1,'description'=>'已过期'],['version'=>$version,'url'=>$url,'language'=>'zh-Hans','language_arr'=>$this->process_Language()]];
|
||||
}else{
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$user_token_state = $this->token_time_validate($data['token']);
|
||||
$language_data = $this->pd_language($user_token_state['language'],$isSupportedLanguage,$language);
|
||||
if($user_token_state['state'] === false){
|
||||
return [['code'=>-1,'description'=>'已过期'],['version'=>$version,'url'=>$url,'language'=>$language_data,'language_arr'=>$this->process_Language()]];
|
||||
}else{
|
||||
return [['code'=>0,'description'=>'未过期'],['version'=>$version,'url'=>$url,'language'=>$language_data,'language_arr'=>$this->process_Language()]];
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加IP信息获取方法
|
||||
protected function getIpInfo($ip) {
|
||||
// 默认IP
|
||||
$ip = $ip ?: request()->ip();
|
||||
try {
|
||||
$ip2region = new \Ip2Region();
|
||||
$info = $ip2region->memorySearch($ip);
|
||||
// 返回国家信息
|
||||
return $info['region'] ?: '未知';
|
||||
} catch (\Exception $e) {
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
public function pd_language($user_language,$isSupportedLanguage,$language){
|
||||
if(!$user_language){
|
||||
if($isSupportedLanguage){
|
||||
$result = $language;
|
||||
}else{
|
||||
$result = 'zh-Hans'; // 默认语言为中文
|
||||
}
|
||||
}else{
|
||||
$result = $user_language;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
// 处理返回的语言数组
|
||||
protected function process_Language(){
|
||||
$temporary_arr = [];
|
||||
foreach ($this->language_country as $key => $value) {
|
||||
array_push($temporary_arr,['key'=>$key,'value'=>$value]);
|
||||
}
|
||||
return $temporary_arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public function get_user_data_information_action($data){
|
||||
// $return_result = [
|
||||
// 'body_data'=>[],
|
||||
// 'kcal_data'=>[],
|
||||
// 'card_data'=>[]
|
||||
// ];
|
||||
// $aud_data = Db::table($this->index_db_name['juese'])->where(['id'=>$data['aud_id']])->find();
|
||||
|
||||
// $body_data = Db::table($this->index_db_name['body_data'])->where(['id'=>$data['aud_id']])->find();
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
<?php
|
||||
|
||||
namespace app\app\controller;
|
||||
|
||||
class Language extends Base
|
||||
{
|
||||
// 支持的语言列表
|
||||
protected $supportedLanguages = [
|
||||
'en' => 'English',
|
||||
'zh-Hans' => 'Chinese',
|
||||
'es' => 'Spanish',
|
||||
'fr' => 'French',
|
||||
'pt' => 'Portuguese',
|
||||
'ar' => 'Arabic',
|
||||
'ru' => 'Russian',
|
||||
'de' => 'German'
|
||||
];
|
||||
|
||||
// 语言映射表
|
||||
protected $languageMap = [
|
||||
'en' => [
|
||||
'操作成功' => 'Success',
|
||||
'体重' => 'Weight',
|
||||
'身高' => 'Height',
|
||||
'消瘦' => 'Slim',
|
||||
'正常' => 'Normal',
|
||||
'偏重' => 'Overweight',
|
||||
'肥胖' => 'Obesity',
|
||||
'反映和衡量一个人健康状况的重要标志之一' => "One of the important indicators reflecting and measuring a person's health status",
|
||||
'人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大' => "The length of the longitudinal part of the human body is derived from its longitudinal growth and is greatly influenced by genetic factors",
|
||||
'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。' => "BMI is the body mass index, which is currently a commonly used international standard for measuring the degree of body fat, thinness, and health.",
|
||||
'公斤' => "kg",
|
||||
'CM' => "cm",
|
||||
'年' => "-",
|
||||
'月' => "-",
|
||||
'日' => "",
|
||||
'身体得分' => "Physical score",
|
||||
'分' => "score",
|
||||
'身体类型' => "body type",
|
||||
'健美肌肉型' => "Bodybuilding muscle type",
|
||||
'低' => "Low",
|
||||
'偏低' => "Slightly low",
|
||||
'标准' => "Standard",
|
||||
'偏高' => "Slightly high",
|
||||
'高' => "High",
|
||||
'矮' => "Short",
|
||||
'偏矮' => "Slightly short",
|
||||
'脂肪率' => "Body Fat Percentage",
|
||||
'体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。' => "Body fat percentage refers to the proportion of fat tissue in body composition. Measuring it provides a more accurate reflection of body fat levels (degree of obesity) than weight measurement alone.",
|
||||
'脂肪量' => "Fat Mass",
|
||||
'人体脂肪的重量' => "Body Fat Weight",
|
||||
'肌肉率' => "Muscle Percentage",
|
||||
'优' => "Excellent",
|
||||
'根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。' => "Muscle percentage is a ratio derived from total muscle mass, body weight, height, etc. Its range determines a person's health status and strength level.",
|
||||
'肌肉量' => "Muscle Mass",
|
||||
'不足' => "Insufficient",
|
||||
'肌肉量=实际体重*肌肉率' => "Muscle Mass = Actual Weight × Muscle Percentage",
|
||||
'水分' => "Body Water",
|
||||
'指人体内水分比例。' => "Refers to the proportion of water in the human body.",
|
||||
'蛋白量' => "Protein Mass",
|
||||
'蛋白量=实际体重*蛋白率' => "Protein Mass = Actual Weight × Protein Percentage",
|
||||
'骨重' => "Bone Mass",
|
||||
'单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。' => "Bone mass refers to the content of bone tissue, minerals (calcium, phosphorus, etc.), and bone matrix (collagen, proteins, inorganic salts, etc.) per unit volume, reflecting skeletal health.",
|
||||
'蛋白率' => "Protein Percentage",
|
||||
'人体内蛋白率含量。' => "The proportion of protein in the human body.",
|
||||
'基础代谢' => "Basal Metabolic Rate (BMR)",
|
||||
'指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率' => "The energy expenditure rate when the body is awake, completely at rest, and unaffected by muscle activity, ambient temperature, food intake, or mental stress.",
|
||||
'内脏指数' => "Visceral Fat Index",
|
||||
'警惕' => "Caution",
|
||||
'危险' => "Danger",
|
||||
'内脏脂肪指数' => "Visceral Fat Level",
|
||||
'皮下脂肪' => "Subcutaneous Fat",
|
||||
'皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织' => "Subcutaneous fat refers to adipose tissue stored under the skin. About two-thirds of body fat is stored subcutaneously.",
|
||||
'肥胖等级' => "Obesity Level",
|
||||
'体重不足' => "Underweight",
|
||||
'肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。' => "Obesity level indicates the disparity between actual and ideal weight, serving as a diagnostic criterion for obesity.",
|
||||
'孩子可能存在营养不良:对于处在生长发育期的孩子而言,蛋白质、碳水化合物、维生素和矿物质这四类营养素非常重要。建议补充足够的蛋白质、锌、钙、铁、维生素D、赖氨酸等营养。建议补充含鸡内金山楂膏健脾开胃类药食同源食物。' => "The child may be malnourished: For growing children, protein, carbohydrates, vitamins, and minerals are critical. Ensure adequate intake of protein, zinc, calcium, iron, vitamin D, lysine, etc. Consider herbal foods like chicken gizzard-hawthorn paste to improve digestion and appetite.",
|
||||
'孩子可能存在营养不良:对于处在生长发育期的孩子而言,最有利于长高的营养素是蛋白质、碳水化合物、维生素和矿物质四类。建议补充足够的蛋白质、锌、铁、钙、维生素D、赖氨酸等营养。' => "The child may be malnourished: For children in their growth and development stage, the most beneficial nutrients for height growth are proteins, carbohydrates, vitamins, and minerals. It is recommended to ensure adequate intake of nutrients such as protein, zinc, iron, calcium, vitamin D, and lysine.",
|
||||
'坚持适当、科学的跳跃运动能够科学地增加学生体重,能够改善学 生体重过低的情况;同时运动会消耗能量并加速胃肠蠕动,这会使孩子的食欲大开,再配合均衡的营养有利于孩子增重。' => "Moderate, scientifically designed jumping exercises can help underweight students gain weight by boosting energy expenditure and gastrointestinal motility, thereby increasing appetite. Combined with balanced nutrition, this supports healthy weight gain.",
|
||||
'3-7岁的孩子:骑两轮车、拍踢球、打篮球、游泳、爬山,每天高强度运动不超过30分钟。' => "Ages 3–7: Bicycling, ball games, basketball, swimming, hiking. Limit high-intensity exercise to 30 minutes daily.",
|
||||
'该年龄段睡眠时间建议:9-11小时' => "Recommended sleep duration for this age group: 9–11 hours.",
|
||||
'孩子开始对于赞赏、鼓励、认同和肯定有需求,而且此阶段父亲在孩子的性格塑造、情绪控制以及责任感培养方面扮演着重要的角色,必须告诉孩子什么事应该做、什么事不应该做,并经常性地给孩子一些积极地暗示。例如,可以时常向孩子表达“我会一直在你身边,不要害怕””我对你的进步都看在眼里等类似的话语。' => "Children begin to crave praise, encouragement, and validation. Fathers play a key role in shaping character, emotional regulation, and responsibility during this phase. Clearly define boundaries while offering positive affirmations (e.g., 'I’m always here for you,' 'I see your progress').",
|
||||
'《中华人民共和国卫生行业标准WS 423-2013》' => "《Chinese Health Industry Standard WS 423-2013》",
|
||||
'《中华人民共和国卫生行业标准WS/T 612-2018》' => "《Chinese Health Industry Standard WS/T 612-2018》",
|
||||
'《中华人民共和国卫生行业标准WS/T1586-2018》' => "《Chinese Health Industry Standard WS/T 1586-2018》",
|
||||
'《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (5–19 Years)》",
|
||||
'头围' => "Head Circumference",
|
||||
'头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "Head circumference refers to the maximum length around the head. Its measurement is closely related to brain development.",
|
||||
|
||||
],
|
||||
// 可以添加更多语言映射
|
||||
];
|
||||
|
||||
/**
|
||||
* 处理多国语言翻译
|
||||
*
|
||||
* @param string $language 目标语言代码
|
||||
* @param mixed $data 要翻译的数据(字符串或数组)
|
||||
* @return mixed 翻译后的数据
|
||||
*/
|
||||
public function handling_languages_from_multiple_countries($language, $data)
|
||||
{
|
||||
|
||||
// dump($data);
|
||||
// 验证语言是否支持
|
||||
if (!$this->isLanguageSupported($language)) {
|
||||
return $this->msg($data['data']);
|
||||
}
|
||||
|
||||
// 如果是数组,递归处理每个元素
|
||||
if (is_array($data)) {
|
||||
// dump(2);
|
||||
$data = $this->translateArray($language, $data);
|
||||
return $this->msg($data['data']);
|
||||
}
|
||||
|
||||
// 如果是字符串,直接翻译
|
||||
if (is_string($data)) {
|
||||
// dump(3);
|
||||
return $this->translateString($language, $data);
|
||||
}
|
||||
|
||||
// dump($data);
|
||||
// 其他类型直接返回
|
||||
return $this->msg($data['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查语言是否支持
|
||||
*
|
||||
* @param string $language 语言代码
|
||||
* @return bool
|
||||
*/
|
||||
protected function isLanguageSupported($language)
|
||||
{
|
||||
return isset($this->supportedLanguages[$language]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 翻译数组
|
||||
*
|
||||
* @param string $language 目标语言
|
||||
* @param array $array 要翻译的数组
|
||||
* @return array 翻译后的数组
|
||||
*/
|
||||
protected function translateArray($language, array $array)
|
||||
{
|
||||
$result = [];
|
||||
foreach ($array as $key => $value) {
|
||||
// 保持键不变,只翻译值
|
||||
$result[$key] = is_array($value)
|
||||
? $this->translateArray($language, $value)
|
||||
: $this->translateString($language, $value);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 翻译字符串
|
||||
*
|
||||
* @param string $language 目标语言
|
||||
* @param string $string 要翻译的字符串
|
||||
* @return string 翻译后的字符串
|
||||
*/
|
||||
protected function translateString($language, $string)
|
||||
{
|
||||
// dump($string);
|
||||
// 检查是否有该语言的映射表
|
||||
if (!isset($this->languageMap[$language])) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
// 检查是否有对应的翻译
|
||||
return $this->languageMap[$language][$string] ?? $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支持的语言列表
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSupportedLanguages()
|
||||
{
|
||||
return $this->supportedLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新的语言翻译
|
||||
*
|
||||
* @param string $language 语言代码
|
||||
* @param array $translations 翻译映射数组
|
||||
* @return bool
|
||||
*/
|
||||
public function addTranslations($language, array $translations)
|
||||
{
|
||||
if (!$this->isLanguageSupported($language)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($this->languageMap[$language])) {
|
||||
$this->languageMap[$language] = [];
|
||||
}
|
||||
|
||||
$this->languageMap[$language] = array_merge(
|
||||
$this->languageMap[$language],
|
||||
$translations
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -112,7 +112,7 @@ class Role extends Base{
|
|||
try {
|
||||
// 你的业务逻辑
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('measure_model', $data)){
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('id', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('measure_model', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if($data['measure_model'] != '1' && $data['measure_model'] != '2'){
|
||||
|
|
@ -121,8 +121,8 @@ class Role extends Base{
|
|||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005,'id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||||
return $this->msg(10005,'birthday type error');
|
||||
|
|
@ -273,7 +273,7 @@ class Role extends Base{
|
|||
$parameter['card_order'] = $address_data['recommend_cards'];
|
||||
}
|
||||
|
||||
$return_result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['aud_id']])->update($parameter);
|
||||
$return_result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['id']])->update($parameter);
|
||||
if($return_result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,582 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
|
||||
class Skip extends Base{
|
||||
|
||||
protected $skip_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
'juese'=>'app_user_data',
|
||||
'body'=>'app_card_body_data',
|
||||
'skip'=>'app_card_skip_data',
|
||||
|
||||
];
|
||||
protected $curve_data_format = ['jump_num'=>['跳绳个数','个','#009DFF'],'jump_time'=>['跳绳时长','分钟','#009DFF'],'jump_kcal'=>['消耗卡路里','kcal','#009DFF']];
|
||||
// protected $skip_use_db_name = [
|
||||
// '1'=>'app_card_skip_data',
|
||||
// '2'=>'app_user_data',
|
||||
// '3'=>'app_card_body_data',
|
||||
// ];
|
||||
protected $pagesize = 15;
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 手动记录
|
||||
public function manual_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){
|
||||
$return_data = $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['r_time'],'datetime')){
|
||||
return $this->msg(10005,'r_time type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['type'],'str')){
|
||||
return $this->msg(10005,'type type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['num'],'intnum') || !$this->verify_data_is_ok($data['time_m'],'intnum') || !$this->verify_data_is_ok($data['time_s'],'intnum')){
|
||||
return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
|
||||
}
|
||||
if($data['num'] <= 0){
|
||||
return $this->msg(10005,'跳绳数不能小于等于0');
|
||||
}
|
||||
if(abs($data['time_s']) >= 60){
|
||||
return $this->msg(10005,'秒钟值不能大于60');
|
||||
}
|
||||
unset($data['token']);
|
||||
if($this->validate_user_identity($data['aud_id']) === false){
|
||||
return $this->msg(10003);
|
||||
}
|
||||
return $this->manual_record_action($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 device_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('kcal', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){
|
||||
$return_data = $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['kcal'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['type'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){
|
||||
$return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
|
||||
}
|
||||
if($data['num'] <= 0){
|
||||
$return_data = $this->msg(10005,'跳绳数不能小于等于0');
|
||||
}
|
||||
if(abs($data['time_s']) >= 60){
|
||||
$return_data = $this->msg(10005,'秒钟值不能大于60');
|
||||
}
|
||||
unset($data['token']);
|
||||
if($this->validate_user_identity($data['aud_id']) === false){
|
||||
$return_data = $this->msg(10003);
|
||||
}
|
||||
$return_data = $this->manual_record_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 data_report(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
unset($data['token']);
|
||||
return $this->data_report_action($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 curve_chart(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
unset($data['token']);
|
||||
return $this->curve_chart_action($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 record_list_page(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['page'],'intnum')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
return $this->record_list_page_or_group_action($data,'page');
|
||||
} 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 record_list_group(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
return $this->record_list_page_or_group_action($data,'group');
|
||||
} 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 detailed_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005,'id type error');
|
||||
}
|
||||
return $this->get_all_detaile_data_action($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 del_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
unset($data['token']);
|
||||
$user_data = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
|
||||
if($user_data){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
} 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################################################################
|
||||
################################################################action################################################################
|
||||
public function manual_record_action($data){
|
||||
// 分秒转换为秒
|
||||
$data['time'] = abs($data['time_m'])*60+abs($data['time_s']);
|
||||
$user_msg_content = Db::table($this->skip_db_name['juese'])->where(['id'=>$data['aud_id']])->count();
|
||||
if($user_msg_content<=0){
|
||||
return $this->msg(10004);
|
||||
}
|
||||
if(!array_key_exists('kcal', $data)){
|
||||
$last_data_body = Db::table($this->skip_db_name['body'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc,id desc')->field('id,weight_val,record_time')->find();
|
||||
if(!$last_data_body){
|
||||
$last_data_body = Db::table($this->skip_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,weight as weight_val')->find();
|
||||
if(!$last_data_body){
|
||||
return $this->msg(10004);
|
||||
}
|
||||
}
|
||||
$kcal_data = $this->skip_kcal_calculate($data['num'],$data['time'],$last_data_body['weight_val']);
|
||||
}else{
|
||||
// 将时间从秒转换为分钟
|
||||
$minutes = bcdiv($data['time'],60,20);
|
||||
// 计算每分钟的跳绳次数
|
||||
$jumpsPerMinute = bcdiv($data['num'],$minutes,2);
|
||||
$kcal_data['totalCalories'] = $data['kcal'];
|
||||
$kcal_data['averageAchievement'] = $jumpsPerMinute;
|
||||
$kcal_data['caloriesPerMinute'] = bcdiv($kcal_data['totalCalories'],$minutes,2);
|
||||
}
|
||||
|
||||
|
||||
$data_set = [
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
'last_update_time'=>date('Y-m-d H:i:s'),
|
||||
'jump_num'=>$data['num'],
|
||||
|
||||
'jump_time'=>$data['time'],
|
||||
'jump_kcal'=>$kcal_data['totalCalories'],
|
||||
'average_num'=>$kcal_data['averageAchievement'],
|
||||
'average_kcal'=>$kcal_data['caloriesPerMinute'],
|
||||
'aud_id'=>$data['aud_id'],
|
||||
'record_time'=>array_key_exists('r_time', $data)?$data['r_time']:date('Y-m-d H:i:s'),
|
||||
'jump_type'=>$data['type']
|
||||
];
|
||||
if(strlen($data_set['record_time']) <= 12){
|
||||
$data_set['record_time'] = $this->addCurrentTimeToDateString($data_set['record_time']);
|
||||
}
|
||||
$last_data_body = Db::table($this->skip_db_name['skip'])->insert($data_set);
|
||||
$result = [
|
||||
'today_jump_num'=>0,
|
||||
'today_jump_time'=>0,
|
||||
'today_jump_kcal'=>0,
|
||||
];
|
||||
$all_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select();
|
||||
foreach ($all_data as $key => $value) {
|
||||
$result['today_jump_num'] = $result['today_jump_num']+$value['jump_num'];
|
||||
$result['today_jump_time'] = $result['today_jump_time']+$value['jump_time'];
|
||||
$result['today_jump_kcal'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
|
||||
}
|
||||
$result['last_jump_num'] = $data['num'];
|
||||
$result['last_jump_time'] = $data['time'];
|
||||
$result['last_jump_kcal'] = $data_set['jump_kcal'];
|
||||
// $result['last_record_time'] = str_replace('-', '/', $data_set['record_time']);
|
||||
$result['last_record_time'] = $data_set['record_time'];
|
||||
$time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
|
||||
$result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
|
||||
$time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
|
||||
$result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
|
||||
return $this->msg($result);
|
||||
}
|
||||
public function data_report_action($data){
|
||||
$all_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select();
|
||||
$last_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc,id desc')->field('id,jump_num,jump_time,jump_kcal,record_time')->find();
|
||||
$result = [
|
||||
'today_jump_num'=>0,
|
||||
'today_jump_time'=>0,
|
||||
'today_jump_kcal'=>0,
|
||||
];
|
||||
foreach ($all_data as $key => $value) {
|
||||
$result['today_jump_num'] = $result['today_jump_num']+$value['jump_num'];
|
||||
$result['today_jump_time'] = $result['today_jump_time']+$value['jump_time'];
|
||||
$result['today_jump_kcal'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
|
||||
}
|
||||
if($last_data){
|
||||
$result['last_jump_num'] = $last_data['jump_num'];
|
||||
$result['last_jump_time'] = $last_data['jump_time'];
|
||||
$result['last_jump_kcal'] = $last_data['jump_kcal'];
|
||||
$result['last_record_time'] = $last_data['record_time'];
|
||||
}else{
|
||||
$result['last_jump_num'] = 0;
|
||||
$result['last_jump_time'] = 0;
|
||||
$result['last_jump_kcal'] = 0;
|
||||
$result['last_record_time'] = '';
|
||||
}
|
||||
$time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
|
||||
$result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
|
||||
$time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
|
||||
$result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
|
||||
return $this->msg($result);
|
||||
}
|
||||
public function curve_chart_action($data){
|
||||
$audid = $data['aud_id'];
|
||||
$timeData = explode('-', $data['time']);
|
||||
// 根据$timeData的长度构建不同的查询条件
|
||||
$map = ['aud_id' => $audid,'is_del'=>0];
|
||||
switch (count($timeData)) {
|
||||
case 3: // 年月日
|
||||
$map['record_time'] = ['between', [date('Y-m-d 00:00:00', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2])), date('Y-m-d 23:59:59', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2]))]];
|
||||
break;
|
||||
case 2: // 年月
|
||||
$map['record_time'] = ['between', [date('Y-m-01 00:00:00', strtotime($timeData[0] . '-' . $timeData[1])), date('Y-m-t 23:59:59', strtotime($timeData[0] . '-' . $timeData[1]))]];
|
||||
break;
|
||||
case 1: // 年
|
||||
$map['record_time'] = ['between', [date('Y-01-01 00:00:00', strtotime($timeData[0])), date('Y-12-31 23:59:59', strtotime($timeData[0]))]];
|
||||
break;
|
||||
default:
|
||||
return $this->msg(10005); // 无效的时间数据格式
|
||||
}
|
||||
|
||||
// 使用查询构造器进行查询
|
||||
$result = Db::name($this->skip_db_name['skip'])->where($map)->field('jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select();
|
||||
$return_data = [];
|
||||
if(count($timeData) == 3){
|
||||
$key_condition = 'hour';
|
||||
}else if(count($timeData) == 2){
|
||||
$key_condition = 'day';
|
||||
}else if(count($timeData) == 1){
|
||||
$key_condition = 'month';
|
||||
}
|
||||
foreach ($this->curve_data_format as $key => $value) {
|
||||
$temporary_arr['title'] = $value[0].'('.$value[1].')';
|
||||
$temporary_arr['key'] = $key;
|
||||
$temporary_arr['line']['categories'] = [];
|
||||
$temporary_arr['line']['series'][0]['color'] = $value[2];
|
||||
$temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')';
|
||||
$temporary_arr['line']['series'][0]['data'] = [];
|
||||
foreach ($result as $k => $v) {
|
||||
if($key_condition == 'hour'){
|
||||
// 每一次的记录都添加进去
|
||||
array_push($temporary_arr['line']['categories'],$result[$k]['hour'].':'.$result[$k]['minute']);
|
||||
array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
|
||||
}else if($key_condition == 'day'){
|
||||
// 根据天分组
|
||||
if(in_array($result[$k]['month'].'/'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){
|
||||
$num = array_search($result[$k]['month'].'/'.$result[$k][$key_condition], $temporary_arr['line']['categories']);
|
||||
$temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
|
||||
}else{
|
||||
array_push($temporary_arr['line']['categories'],$result[$k]['month'].'/'.$result[$k][$key_condition]);
|
||||
array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
|
||||
}
|
||||
|
||||
}else{
|
||||
// 根据年分组
|
||||
if(in_array($result[$k]['month'].'月',$temporary_arr['line']['categories'])){
|
||||
$num = array_search($result[$k]['month'].'月', $temporary_arr['line']['categories']);
|
||||
$temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
|
||||
}else{
|
||||
array_push($temporary_arr['line']['categories'],$result[$k]['month'].'月');
|
||||
array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
array_push($return_data,$temporary_arr);
|
||||
}
|
||||
foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) {
|
||||
$return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2);
|
||||
}
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
public function record_list_page_or_group_action($data,$type){
|
||||
$return_result = [];
|
||||
|
||||
if($type == 'group'){
|
||||
$data['s_time'] = $data['s_time'].' 00:00:00';
|
||||
$data['e_time'] = $data['e_time'].' 23:59:59';
|
||||
$result = Db::query("
|
||||
select
|
||||
id,
|
||||
CONVERT(varchar(10), record_time, 120) AS r_t,
|
||||
CONVERT(varchar(19), record_time, 120) AS record_time,
|
||||
jump_num as v1,
|
||||
jump_time as v2,
|
||||
jump_kcal as v3
|
||||
from ".$this->skip_db_name['skip']."
|
||||
where aud_id='".$data['aud_id']."'
|
||||
and record_time between '".$data['s_time']."' and '".$data['e_time']."'
|
||||
and is_del = 0
|
||||
order by record_time desc");
|
||||
foreach ($result as $key => $value) {
|
||||
$time_t = $this->handle_hour_branch_second($value['v2']);
|
||||
array_push($return_result, [
|
||||
'id'=>$value['id'],
|
||||
'v1'=>$value['v1'],
|
||||
'v2'=>$time_t['h'].':'.$time_t['m'].':'.$time_t['s'],
|
||||
'v3'=>$value['v3'],
|
||||
'v1_name'=>'个数',
|
||||
'v2_name'=>'时长',
|
||||
'v3_name'=>'卡路里',
|
||||
// 'r_t'=>str_replace('-', '/', $value['r_t'])
|
||||
'r_t'=>$value['r_t']
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
$result = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,jump_num,jump_time,jump_kcal")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
|
||||
$return_result['totalrows'] = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->count();
|
||||
$return_result['rows'] = [];
|
||||
$return_result['pageno'] = $data['page'];
|
||||
$return_result['pagesize'] = $this->pagesize;
|
||||
$return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
|
||||
foreach ($result as $key => $value) {
|
||||
$time_t = $this->handle_hour_branch_second($value['jump_time']);
|
||||
array_push($return_result['rows'],[
|
||||
'id'=>$value['id'],
|
||||
'v1'=>$value['jump_num'],
|
||||
'v2'=>$time_t['h'].':'.$time_t['m'].':'.$time_t['s'],
|
||||
'v3'=>$value['jump_kcal'],
|
||||
'v1_name'=>'个数',
|
||||
'v2_name'=>'时长',
|
||||
'v3_name'=>'卡路里',
|
||||
'record_time'=>$value['b_time'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->msg($return_result);
|
||||
}
|
||||
public function get_all_detaile_data_action($data){
|
||||
|
||||
$result = $result = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id'],'is_del'=>0])->find();
|
||||
$for_data_arr = ['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']];
|
||||
if($result){
|
||||
$result_data = [];
|
||||
foreach ($for_data_arr as $key => $value) {
|
||||
$temporary_arr['key_name'] = $key;
|
||||
$temporary_arr['name'] = $value[0];
|
||||
$temporary_arr['value'] = explode(',',$result[$key])[0];
|
||||
$temporary_arr['unit'] = $value[1];
|
||||
array_push($result_data,$temporary_arr);
|
||||
}
|
||||
return $this->msg($result_data);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
################################################################内部调用################################################################
|
||||
################################################################内部调用################################################################
|
||||
// 跳绳卡路里计算
|
||||
public function skip_kcal_calculate($num=143, $time=222, $weight=70) {
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 将时间从秒转换为分钟
|
||||
$minutes = bcdiv($time,60,20);
|
||||
// 计算每分钟的跳绳次数
|
||||
$jumpsPerMinute = bcdiv($num,$minutes,2);
|
||||
// 根据跳绳次数确定MET值
|
||||
// $met = 11.8;
|
||||
if ($jumpsPerMinute < 100) {
|
||||
$met = 8.8;
|
||||
} else if ($jumpsPerMinute >= 100 && $jumpsPerMinute < 120) {
|
||||
$met = 11.8;
|
||||
} else {
|
||||
$met = 12.3;
|
||||
}
|
||||
// 计算每分钟燃烧的卡路里
|
||||
$caloriesPerMinute = bcdiv(bcmul(bcmul($met,$weight,20),3.5,20),200,2);
|
||||
// 计算总卡路里消耗
|
||||
$totalCalories = bcmul($caloriesPerMinute,$minutes,2);
|
||||
// 返回结果
|
||||
return [
|
||||
'averageAchievement' => $jumpsPerMinute,
|
||||
'caloriesPerMinute' => $caloriesPerMinute,
|
||||
'totalCalories' => $totalCalories
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,639 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
|
||||
class Vitalcapacity extends Base{
|
||||
|
||||
protected $vitalcapacity_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
'juese'=>'app_user_data',
|
||||
'vitalcapacity'=>'app_card_vitalcapacity_data',
|
||||
'biaozhun'=>'pc_vitalcapacity_standard',
|
||||
|
||||
];
|
||||
protected $color = ['无效'=>'#FF5656','不及格'=>'#FF5656','及格'=>'#FFAB00','良好'=>'#5AD06D','优秀'=>'#6492F6','牛逼'=>'#3967D6'];
|
||||
protected $curve_data_format = ['one_val'=>['第一次','容积/ml','#009DFF'],'two_val'=>['第二次','容积/ml','#009DFF'],'three_val'=>['第三次','容积/ml','#009DFF'],'average_val'=>['平均','容积/ml','#009DFF']];
|
||||
protected $pagesize = 15;
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 手动记录
|
||||
public function manual_record(){
|
||||
try {
|
||||
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('one', $data) || !array_key_exists('two', $data) || !array_key_exists('three', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['one'],'intnum')){
|
||||
return $this->msg(10005,'one type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['two'],'intnum')){
|
||||
return $this->msg(10005,'two type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['three'],'intnum')){
|
||||
return $this->msg(10005,'three type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['time'],'datetime')){
|
||||
return $this->msg(10005,'time type error');
|
||||
}
|
||||
if(strlen($data['time']) <= 12){
|
||||
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
|
||||
$data['time'] = $this->addCurrentTimeToDateString($data['time']);
|
||||
}
|
||||
return $this->manual_record_action($data,'by_hand_means');
|
||||
} 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 device_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('one', $data) || !array_key_exists('two', $data) || !array_key_exists('three', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['one'],'intnum')){
|
||||
return $this->msg(10005,'one type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['two'],'intnum')){
|
||||
return $this->msg(10005,'two type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['three'],'intnum')){
|
||||
return $this->msg(10005,'three type error');
|
||||
}
|
||||
$data['time'] = date('Y-m-d H:i:s');
|
||||
return $this->manual_record_action($data,'by_device');
|
||||
} 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 data_report(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
|
||||
$return_data = $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
return $this->data_report_action($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 curve_chart(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){
|
||||
$return_data = $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['time'],'datetime')){
|
||||
return $this->msg(10005,'time type error');
|
||||
}
|
||||
return $this->curve_chart_action($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 record_list_page(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['page'],'intnum')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
return $this->record_list_page_or_group_action($data,'page');
|
||||
} 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 record_list_group(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
|
||||
return $this->msg(10005,'page type error');
|
||||
}
|
||||
return $this->record_list_page_or_group_action($data,'group');
|
||||
} 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 detailed_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005,'id type error');
|
||||
}
|
||||
return $this->get_all_detaile_data_action($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 del_record(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
unset($data['token']);
|
||||
$user_data = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
|
||||
if($user_data){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
} 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################################################################
|
||||
################################################################action################################################################
|
||||
public function manual_record_action($data,$type){
|
||||
$temporary_arr['aud_id'] = $data['aud_id'];
|
||||
$temporary_arr['record_time'] = $data['time'];
|
||||
$temporary_arr['one'] = $data['one'];
|
||||
$temporary_arr['two'] = $data['two'];
|
||||
$temporary_arr['three'] = $data['three'];
|
||||
$temporary_arr['average'] = bcdiv(bcadd(bcadd($data['one'],$data['two'],2),$data['three'],2),3,2);
|
||||
$temporary_arr['create_time'] = date('Y-m-d H:i:s');
|
||||
$temporary_arr['one_val'] = $data['one'];
|
||||
$temporary_arr['two_val'] = $data['two'];
|
||||
$temporary_arr['three_val'] = $data['three'];
|
||||
$temporary_arr['average_val'] = $temporary_arr['average'];
|
||||
$temporary_arr['flow_val'] = array_key_exists('flow', $data)?$data['flow']:'0.00';//流速
|
||||
$temporary_arr['record_type'] = $type;//流速
|
||||
// die;
|
||||
// 处理记录时间
|
||||
|
||||
$user_msg = Db::name($this->vitalcapacity_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,grade,gender,birthday')->find();
|
||||
// die;
|
||||
if($user_msg){
|
||||
// 根据性别&年级&年龄查规则
|
||||
if($user_msg['grade'] == 'nothing'){
|
||||
// 计算年龄判断是属于哪个年级
|
||||
$user_age = $this->calculate_age($user_msg['birthday']);
|
||||
if($user_age <= 7){
|
||||
$user_msg['grade'] = 'grade_s_1';
|
||||
}else if($user_age == 8){
|
||||
$user_msg['grade'] = 'grade_s_2';
|
||||
}else if($user_age == 9){
|
||||
$user_msg['grade'] = 'grade_s_3';
|
||||
}else if($user_age == 10){
|
||||
$user_msg['grade'] = 'grade_s_4';
|
||||
}else if($user_age == 11){
|
||||
$user_msg['grade'] = 'grade_s_5';
|
||||
}else if($user_age == 12){
|
||||
$user_msg['grade'] = 'grade_s_6';
|
||||
}else if($user_age == 13){
|
||||
$user_msg['grade'] = 'grade_m_1';
|
||||
}else if($user_age == 14){
|
||||
$user_msg['grade'] = 'grade_m_2';
|
||||
}else if($user_age == 15){
|
||||
$user_msg['grade'] = 'grade_m_3';
|
||||
}else if($user_age == 16){
|
||||
$user_msg['grade'] = 'grade_h_1';
|
||||
}else if($user_age == 17){
|
||||
$user_msg['grade'] = 'grade_h_2';
|
||||
}else if($user_age == 18){
|
||||
$user_msg['grade'] = 'grade_h_3';
|
||||
}else if($user_age == 19 || $user_age == 20){
|
||||
$user_msg['grade'] = 'grade_u_12';
|
||||
}else if($user_age >= 21){
|
||||
$user_msg['grade'] = 'grade_u_34';
|
||||
}
|
||||
}
|
||||
$sql_str = "sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$temporary_arr['average_val'];
|
||||
$user_achievement = Db::name($this->vitalcapacity_db_name['biaozhun'])->where($sql_str)->order($user_msg['grade'] .' desc')->field('level,score,'.$user_msg['grade'])->limit(1)->cache(86400)->select();
|
||||
if(count($user_achievement)<=0){
|
||||
$user_achievement[0] = ['level'=>'无效','score'=>'0'];
|
||||
}
|
||||
$temporary_arr['score'] = $user_achievement[0]['score'].','.$user_achievement[0]['level'].','.$this->color[$user_achievement[0]['level']];
|
||||
$temporary_arr['score_val'] = $user_achievement[0]['score'];
|
||||
|
||||
}else{
|
||||
return $this->msg(10004,'未找到有效数据');
|
||||
}
|
||||
$standard_data = $this->get_vitalcapacity_data($data['aud_id']);
|
||||
$temporary_arr['standard_data'] = json_encode($standard_data);
|
||||
$result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->insert($temporary_arr);
|
||||
|
||||
if($result){
|
||||
$time = $result[0]['record_time'];
|
||||
$time = strtotime($time);
|
||||
$time = date('Y年m月d日 H:i:s', $time);
|
||||
return $this->msg([
|
||||
'average'=>$temporary_arr['average'].'ml',
|
||||
'level'=>$user_achievement[0]['level'],
|
||||
'time'=>$time,
|
||||
'flow_val'=>$temporary_arr['flow_val'],
|
||||
'list'=>$standard_data,
|
||||
'offset'=>$this->vitalcapacity_standard_interval($temporary_arr['average'],$standard_data)
|
||||
]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
public function data_report_action($data){
|
||||
$result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('record_time,score,average,flow_val,standard_data')->limit(1)->select();
|
||||
|
||||
if(count($result) <= 0){
|
||||
// return $this->msg(10004);
|
||||
return $this->msg([
|
||||
'average'=>'',
|
||||
'level'=>'',
|
||||
'time'=>'',
|
||||
'flow_val'=>'',
|
||||
'list'=>'',
|
||||
'offset'=>''
|
||||
]);
|
||||
|
||||
}else{
|
||||
|
||||
$time = $result[0]['record_time'];
|
||||
$time = strtotime($time);
|
||||
$time = date('Y年m月d日 H:i:s', $time);
|
||||
$o_l = explode(',',$result[0]['score']);
|
||||
// $standard_data = $this->get_vitalcapacity_data($data['aud_id']);
|
||||
$standard_data = json_decode($result[0]['standard_data'],true);
|
||||
|
||||
return $this->msg([
|
||||
'average'=>$result[0]['average'].'ml',
|
||||
'level'=>$o_l[1],
|
||||
'time'=>$time,
|
||||
'flow_val'=>$result[0]['flow_val'] == '.00'?'0.00':$result[0]['flow_val'],
|
||||
'list'=>$standard_data,
|
||||
'offset'=>$this->vitalcapacity_standard_interval($result[0]['average'],$standard_data)
|
||||
]);
|
||||
}
|
||||
}
|
||||
public function curve_chart_action($data){
|
||||
$audid = $data['aud_id'];
|
||||
$timeData = explode('-', $data['time']);
|
||||
|
||||
// 根据$timeData的长度构建不同的查询条件
|
||||
$map = ['aud_id' => $audid];
|
||||
switch (count($timeData)) {
|
||||
case 3: // 年月日
|
||||
$map['record_time'] = ['between', [date('Y-m-d 00:00:00', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2])), date('Y-m-d 23:59:59', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2]))]];
|
||||
break;
|
||||
case 2: // 年月
|
||||
$map['record_time'] = ['between', [date('Y-m-01 00:00:00', strtotime($timeData[0] . '-' . $timeData[1])), date('Y-m-t 23:59:59', strtotime($timeData[0] . '-' . $timeData[1]))]];
|
||||
break;
|
||||
case 1: // 年
|
||||
$map['record_time'] = ['between', [date('Y-01-01 00:00:00', strtotime($timeData[0])), date('Y-12-31 23:59:59', strtotime($timeData[0]))]];
|
||||
break;
|
||||
default:
|
||||
return $this->msg(10005); // 无效的时间数据格式
|
||||
}
|
||||
// 使用查询构造器进行查询
|
||||
$result = Db::name($this->vitalcapacity_db_name['vitalcapacity'])->where($map)->field('id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select();
|
||||
$return_data = [];
|
||||
if(count($timeData) == 3){
|
||||
$key_condition = 'hour';
|
||||
}else if(count($timeData) == 2){
|
||||
$key_condition = 'day';
|
||||
}else if(count($timeData) == 1){
|
||||
$key_condition = 'month';
|
||||
}
|
||||
foreach ($this->curve_data_format as $key => $value) {
|
||||
$temporary_arr['title'] = $value[0].'('.$value[1].')';
|
||||
$temporary_arr['key'] = $key;
|
||||
$temporary_arr['line']['categories'] = [];
|
||||
$temporary_arr['line']['series'][0]['color'] = $value[2];
|
||||
$temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')';
|
||||
$temporary_arr['line']['series'][0]['data'] = [];
|
||||
foreach ($result as $k => $v) {
|
||||
if($key_condition == 'hour'){
|
||||
if(in_array($result[$k][$key_condition].'时',$temporary_arr['line']['categories'])){
|
||||
|
||||
$num = array_search($result[$k][$key_condition].'时', $temporary_arr['line']['categories']);
|
||||
// $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
|
||||
$temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
|
||||
|
||||
}else{
|
||||
array_push($temporary_arr['line']['categories'],$result[$k][$key_condition].'时');
|
||||
array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
|
||||
}
|
||||
}else if($key_condition == 'day'){
|
||||
if(in_array($result[$k]['month'].'-'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){
|
||||
$num = array_search($result[$k]['month'].'-'.$result[$k][$key_condition], $temporary_arr['line']['categories']);
|
||||
// $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
|
||||
$temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
|
||||
}else{
|
||||
array_push($temporary_arr['line']['categories'],$result[$k]['month'].'-'.$result[$k][$key_condition]);
|
||||
array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
|
||||
}
|
||||
}else{
|
||||
if(in_array($result[$k]['month'].'月',$temporary_arr['line']['categories'])){
|
||||
$num = array_search($result[$k]['month'].'月', $temporary_arr['line']['categories']);
|
||||
// $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
|
||||
$temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
|
||||
}else{
|
||||
array_push($temporary_arr['line']['categories'],$result[$k]['month'].'月');
|
||||
array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
array_push($return_data,$temporary_arr);
|
||||
}
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
public function record_list_page_or_group_action($data,$type){
|
||||
$return_result = [];
|
||||
|
||||
if($type == 'group'){
|
||||
$data['s_time'] = $data['s_time'].' 00:00:00';
|
||||
$data['e_time'] = $data['e_time'].' 23:59:59';
|
||||
$result = Db::query("
|
||||
select
|
||||
id,
|
||||
CONVERT(varchar(10), record_time, 120) AS r_t,
|
||||
CONVERT(varchar(19), record_time, 120) AS record_time,
|
||||
one_val as v1,
|
||||
two_val as v2,
|
||||
three_val as v3,
|
||||
average_val as v4,
|
||||
score as v5
|
||||
from ".$this->vitalcapacity_db_name['vitalcapacity']."
|
||||
where aud_id='".$data['aud_id']."'
|
||||
and record_time between '".$data['s_time']."' and '".$data['e_time']."'
|
||||
and is_del = 0
|
||||
order by record_time desc");
|
||||
foreach ($result as $key => $value) {
|
||||
// $time_t = $this->handle_hour_branch_second($value['v2']);
|
||||
array_push($return_result, [
|
||||
'id'=>$value['id'],
|
||||
'v1'=>$value['v1'] == '.00'?'0':$value['v1'],
|
||||
'v2'=>$value['v2'] == '.00'?'0':$value['v2'],
|
||||
'v3'=>$value['v3'] == '.00'?'0':$value['v3'],
|
||||
'v4'=>$value['v4'] == '.00'?'0':$value['v4'],
|
||||
'v5'=>explode(',',$value['v5'])[0],
|
||||
'v1_name'=>'第一次',
|
||||
'v2_name'=>'第二次',
|
||||
'v3_name'=>'第三次',
|
||||
'v4_name'=>'平均',
|
||||
'v5_name'=>'成绩',
|
||||
// 'r_t'=>str_replace('-', '/', $value['r_t'])
|
||||
'r_t'=>$value['r_t']
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
$result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,one_val,two_val,three_val,average_val,score")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
|
||||
$return_result['totalrows'] = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['aud_id'=>$data['aud_id']])->count();
|
||||
$return_result['rows'] = [];
|
||||
$return_result['pageno'] = $data['page'];
|
||||
$return_result['pagesize'] = $this->pagesize;
|
||||
$return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
|
||||
foreach ($result as $key => $value) {
|
||||
// $time_t = $this->handle_hour_branch_second($value['jump_time']);
|
||||
array_push($return_result['rows'],[
|
||||
'id'=>$value['id'],
|
||||
'v1'=>$value['one_val'] == '.00'?'0':$value['one_val'],
|
||||
'v2'=>$value['two_val'] == '.00'?'0':$value['two_val'],
|
||||
'v3'=>$value['three_val'] == '.00'?'0':$value['three_val'],
|
||||
'v4'=>$value['average_val'] == '.00'?'0':$value['average_val'],
|
||||
'v5'=>explode(',',$value['score'])[0],
|
||||
'v1_name'=>'第一次',
|
||||
'v2_name'=>'第二次',
|
||||
'v3_name'=>'第三次',
|
||||
'v4_name'=>'平均',
|
||||
'v5_name'=>'成绩',
|
||||
'record_time'=>$value['b_time']
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->msg($return_result);
|
||||
}
|
||||
public function get_all_detaile_data_action($data){
|
||||
|
||||
$result = $result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['id'=>$data['id'],'is_del'=>0])->find();
|
||||
$for_data_arr = ['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']];
|
||||
if($result){
|
||||
$result_data = [];
|
||||
foreach ($for_data_arr as $key => $value) {
|
||||
$temporary_arr['key_name'] = $key;
|
||||
$temporary_arr['name'] = $value[0];
|
||||
$temporary_arr['value'] = explode(',',$result[$key])[0];
|
||||
$temporary_arr['unit'] = $value[1];
|
||||
array_push($result_data,$temporary_arr);
|
||||
}
|
||||
return $this->msg($result_data);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
################################################################内部调用################################################################
|
||||
################################################################内部调用################################################################
|
||||
// 肺活量判断区间
|
||||
public function vitalcapacity_standard_interval($val,$data){
|
||||
// 缓存一周
|
||||
$result = '';
|
||||
if(!$data || count($data) <= 0){
|
||||
return $result;
|
||||
}
|
||||
$temporary_qj = $data;
|
||||
$max = 0;
|
||||
$min = 0;
|
||||
$num = 0;
|
||||
foreach ($temporary_qj as $key => $value) {
|
||||
if($val >= $value['min_val'] && $val <= $value['max_val']){
|
||||
$max = $value['max_val'];
|
||||
$min = $value['min_val'];
|
||||
$num = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$num = count($temporary_qj)-1-$num;
|
||||
|
||||
if($max == 0){
|
||||
if($val >= $temporary_qj[0]['max_val']){
|
||||
$result = 100;
|
||||
}
|
||||
}else{
|
||||
$temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2);
|
||||
$result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
// 肺活量判断区间(根据得分)
|
||||
public function vitalcapacity_standard_interval2($val,$data){
|
||||
// 缓存一周
|
||||
$result = '';
|
||||
if(count($data) <= 0){
|
||||
return $result;
|
||||
}
|
||||
$temporary_qj = $data;
|
||||
$max = 0;
|
||||
$min = 0;
|
||||
$num = 0;
|
||||
foreach ($temporary_qj as $key => $value) {
|
||||
if($val >= $value['min_val'] && $val <= $value['max_val']){
|
||||
$max = $value['max_val'];
|
||||
$min = $value['min_val'];
|
||||
$num = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 计算每份占比
|
||||
$share_value = bcdiv($temporary_qj[0]['max_val'],count($temporary_qj),1);
|
||||
// 计算在这一段中占多少
|
||||
$result = bcsub($val,$min,1);
|
||||
$result = bcdiv($result,bcsub($max,$min,1),1);
|
||||
$num = count($temporary_qj)-1-$num;
|
||||
$num = bcmul($num,$share_value,1);
|
||||
$result = bcadd($num,$result,1);
|
||||
// $num = count($temporary_qj)-1-$num;
|
||||
// $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2);
|
||||
// $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,742 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class Base extends Controller{
|
||||
|
||||
protected $base_use_db_name = [
|
||||
'1'=>'app_data_log',
|
||||
'2'=>'app_card_data',
|
||||
'3'=>'app_user_data',
|
||||
'4'=>'pc_vitalcapacity_standard',
|
||||
'5'=>'admin_estimate',
|
||||
'6'=>'app_account_number'
|
||||
];
|
||||
|
||||
public $test_token = ['57bd45e3a963b372ea2d873e4bd8d1f8','e0966788d02cc93290d9d674921d9715'];
|
||||
protected $base_call_method = ['内部'];
|
||||
protected $token_time = 30;//30天的秒数
|
||||
protected $return_data_all = [
|
||||
// '0' => ['success',[]],
|
||||
'10001'=>'关键参数缺失',
|
||||
'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){
|
||||
$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'=>'新Reedaw接口报错','from_user_name'=>'Reedaw-API','content'=>$logContent]);
|
||||
}
|
||||
}
|
||||
if ($response) {
|
||||
$logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL;
|
||||
}
|
||||
// 使用ThinkPHP的日志记录方法
|
||||
Log::record($logContent, 'api_log');
|
||||
|
||||
}
|
||||
// 检查变量是否是一个只有数字的一维数组
|
||||
public function is_num_array($array = [1,2,3]) {
|
||||
if (!is_array($array)) {
|
||||
return false; // 变量不是数组
|
||||
}
|
||||
foreach ($array as $value) {
|
||||
if (!is_numeric($value)) {
|
||||
return false; // 数组中包含非数字元素
|
||||
}
|
||||
}
|
||||
|
||||
$result = Db::table($this->base_use_db_name['2'])->where(['is_del'=>0])->cache(true,600)->select();//查询结果缓存3600秒
|
||||
if(empty(array_diff($array, array_column($result, 'id')))){
|
||||
return true;// 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效
|
||||
}else{
|
||||
return false;//跟数据库比对过,存在无效数值
|
||||
}
|
||||
}
|
||||
public function validate_user_identity($data) {
|
||||
$validate_user = Db::table($this->base_use_db_name['3'])->where(['id'=>$data])->count();
|
||||
if($validate_user<=0){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// 判断字符串是手机还是邮箱
|
||||
public function is_tel_email($str) {
|
||||
// 手机号码的正则表达式(中国大陆格式)(下面正则实际判断的是是否为11位数字)
|
||||
$mobilePattern = '/^\d{11}$/';
|
||||
// 电子邮件地址的正则表达式
|
||||
$emailPattern = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';
|
||||
// 判断是否为手机号码
|
||||
if (preg_match($mobilePattern, $str)) {
|
||||
return 'tel';
|
||||
}
|
||||
// 判断是否为电子邮件地址
|
||||
if (preg_match($emailPattern, $str)) {
|
||||
return 'email';
|
||||
}
|
||||
// 如果都不是,返回其他
|
||||
return false;
|
||||
}
|
||||
|
||||
// 计算年龄
|
||||
public function calculate_age($data = '1991-04-20'){
|
||||
$today = time(); // 获取当前时间的 Unix 时间戳
|
||||
$birthDate = strtotime($data); // 将出生日期字符串转换为 Unix 时间戳
|
||||
if ($birthDate !== false) {
|
||||
$age = date('Y', $today) - date('Y', $birthDate);
|
||||
// 如果当前年份的月份和日期小于出生年份的月份和日期,那么年龄减一
|
||||
if (date('m-d', $today) < date('m-d', $birthDate)) {
|
||||
$age--;
|
||||
}
|
||||
return $age;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 秒转化格式,00:00:00
|
||||
public function handle_hour_branch_second($data = '2000'){
|
||||
$data = abs($data);
|
||||
$hours = intval($data / 3600);
|
||||
$minutes = intval(($data % 3600) / 60);
|
||||
$remainingSeconds = $data % 60;
|
||||
return [
|
||||
'h' => str_pad($hours, 2, '0', STR_PAD_LEFT),
|
||||
'm' => str_pad($minutes, 2, '0', STR_PAD_LEFT),
|
||||
's' => str_pad($remainingSeconds, 2, '0', STR_PAD_LEFT)
|
||||
];
|
||||
}
|
||||
|
||||
// 判断token是否过期
|
||||
public function token_time_validate($token){
|
||||
// 591b70e0d80b5fa6d77e6e1384453ab9
|
||||
if(is_string($token)){
|
||||
$length = strlen($token);
|
||||
if ($length < 10 ) {
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,字符串长度小于10', 'token_log');
|
||||
return ['state'=>false,'language'=>null];
|
||||
}
|
||||
}else{
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log');
|
||||
return ['state'=>false,'language'=>null];
|
||||
}
|
||||
|
||||
$user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->field('id,login_time,language')->find();
|
||||
if(!$user_login){
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log');
|
||||
return ['state'=>false,'language'=>null];
|
||||
}
|
||||
|
||||
// 创建 DateTime 对象来表示指定的日期和时间
|
||||
$specifiedDateTime = new \DateTime($user_login['login_time']);
|
||||
|
||||
// 获取当前时间的 DateTime 对象
|
||||
$currentDateTime = new \DateTime();
|
||||
|
||||
// 计算两个日期之间的差异(以秒为单位)
|
||||
$interval = $currentDateTime->diff($specifiedDateTime);
|
||||
|
||||
// 将差异转换为天数(注意:这里的天数可能不是整数,因为差异可能包括小时、分钟等)
|
||||
$daysDifference = $interval->days;
|
||||
|
||||
// 如果需要更精确的计算(包括小时、分钟等转换成的天数),可以使用以下方式:
|
||||
// $totalSecondsDifference = $interval->format('%a') * 86400 + $interval->format('%h') * 3600 + $interval->format('%i') * 60 + $interval->format('%s');
|
||||
// $daysDifference = floor($totalSecondsDifference / 86400); // 将总秒数转换为天数并取整
|
||||
|
||||
// 判断差异是否超过指定的天数
|
||||
if ($daysDifference > $this->token_time) {
|
||||
// echo "超过 {$specifiedDays} 天";
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token,或该token已经超过30天', 'token_log');
|
||||
return ['state'=>false,'language'=>$user_login['language']];
|
||||
} else {
|
||||
// echo "未超过 {$specifiedDays} 天";
|
||||
$user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
if($user_login){
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log');
|
||||
return ['state'=>true,'language'=>$user_login['language']];
|
||||
}else{
|
||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,数据库更新时间未成功', 'token_log');
|
||||
return ['state'=>true,'language'=>$user_login['language']];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 计算天数
|
||||
public function daysSince($pastDate,$now = false)
|
||||
{
|
||||
// 创建一个表示过去日期的 DateTime 对象
|
||||
$past = new \DateTime($pastDate);
|
||||
if($now === false){
|
||||
// 创建一个表示当前日期的 DateTime 对象
|
||||
$now = new \DateTime();
|
||||
}else{
|
||||
$now = new \DateTime($now);
|
||||
}
|
||||
// 使用 DateTime::diff() 方法计算两个日期之间的差值
|
||||
$interval = $past->diff($now);
|
||||
// 返回相差的天数
|
||||
return $interval->format('%a');
|
||||
}
|
||||
|
||||
// 计算月龄
|
||||
public function calculateAgeInMonthsWithPrecision($birthDateStr) {
|
||||
// 获取当前日期
|
||||
$now = new \DateTime();
|
||||
// 将出生日期字符串转换为 DateTime 对象
|
||||
$birthDate = \DateTime::createFromFormat('Y-m-d', $birthDateStr);
|
||||
// 计算两者之间的差距(以月为单位,包含部分月份的小数)
|
||||
$interval = $now->diff($birthDate);
|
||||
$ageInMonths = $interval->y * 12 + $interval->m; // 年份乘以12加上月份
|
||||
$remainingDays = $interval->d; // 当前月内的剩余天数
|
||||
// 将剩余天数转换为小数月份(假设一个月为30天,进行近似计算)
|
||||
$partialMonth = $remainingDays / 30;
|
||||
// 结果精确到小数点后两位
|
||||
// $ageInMonthsPrecise = round($ageInMonths + $partialMonth, 2);
|
||||
// 整月+剩余月取整
|
||||
$ageInMonthsPrecise = intval($ageInMonths + $partialMonth);
|
||||
return $ageInMonthsPrecise;
|
||||
}
|
||||
// 曲线页面-底部统计动作
|
||||
public function base_target_initial_cumulative_weight($data = []){
|
||||
// 第一种:用户详情(所有数据都有)
|
||||
// 第二种:手动记录(只有最新体重)
|
||||
// 第三种:修改原始体重(只有原始体重)
|
||||
// $result_data['target_weight'] 目标体重
|
||||
// $result_data['initial_weight'] 最初体重
|
||||
// $result_data['weight'] 最近一次测量重量
|
||||
// $result_data['initial_date'] 初始体重日期
|
||||
if(count($data) > 0){
|
||||
$result_data['target_weight'] = $data['target_weight'];
|
||||
$result_data['initial_weight'] = $data['initial_weight'];
|
||||
$result_data['cumulative_weight'] = bcsub($data['weight'],$data['initial_weight'],2);
|
||||
$result_data['cumulative_day'] = $data['initial_date'] == 0?0:$this->daysSince($data['initial_date']);
|
||||
}else{
|
||||
$result_data['target_weight'] = 0;
|
||||
$result_data['initial_weight'] = 0;
|
||||
$result_data['cumulative_weight'] = 0;
|
||||
$result_data['cumulative_day'] = 0;
|
||||
}
|
||||
return $result_data;
|
||||
}
|
||||
|
||||
// 判断一个参数是否为数字且大于等于0
|
||||
public function isPositiveNumber($value) {
|
||||
return is_numeric($value) && $value >= 0;
|
||||
}
|
||||
// 判断是否为整型,或者字符串类型的整型数字
|
||||
public function isValidInteger($var) {
|
||||
// 直接检查是否为整型
|
||||
if (is_int($var)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查是否为字符串且是有效的整数表示
|
||||
if (is_string($var) && filter_var($var, FILTER_VALIDATE_INT) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 其他情况
|
||||
return false;
|
||||
}
|
||||
|
||||
// 判断一个字符串是否为两位以内小数
|
||||
public function isTwoDecimalOrLess($str) {
|
||||
return preg_match('/^\d*(\.\d{1,2})?$/', $str) === 1;
|
||||
}
|
||||
|
||||
// 获取用户肺活量的标准值
|
||||
public function get_vitalcapacity_data($id){
|
||||
$standard_data = [
|
||||
['min_val'=>'90','max_val'=>'100','text'=>'优秀','color'=>'#6492F6'],
|
||||
['min_val'=>'80','max_val'=>'89','text'=>'良好','color'=>'#5AD06D'],
|
||||
['min_val'=>'60','max_val'=>'79','text'=>'及格','color'=>'#FFAB00'],
|
||||
['min_val'=>'10','max_val'=>'59','text'=>'不及格','color'=>'#FF5656'],
|
||||
['min_val'=>'0','max_val'=>'9','text'=>'无效','color'=>'#FF5656'],
|
||||
];
|
||||
$grade = Db::table($this->base_use_db_name['3'])->where(['id'=>$id])->field('id,grade,gender,birthday')->find();
|
||||
if(!$grade){
|
||||
return [];
|
||||
}
|
||||
if($grade['grade'] == 'nothing'){
|
||||
// 计算年龄判断是属于哪个年级
|
||||
$user_age = $this->calculate_age($grade['birthday']);
|
||||
if($user_age <= 7){
|
||||
$grade['grade'] = 'grade_s_1';
|
||||
}else if($user_age == 8){
|
||||
$grade['grade'] = 'grade_s_2';
|
||||
}else if($user_age == 9){
|
||||
$grade['grade'] = 'grade_s_3';
|
||||
}else if($user_age == 10){
|
||||
$grade['grade'] = 'grade_s_4';
|
||||
}else if($user_age == 11){
|
||||
$grade['grade'] = 'grade_s_5';
|
||||
}else if($user_age == 12){
|
||||
$grade['grade'] = 'grade_s_6';
|
||||
}else if($user_age == 13){
|
||||
$grade['grade'] = 'grade_m_1';
|
||||
}else if($user_age == 14){
|
||||
$grade['grade'] = 'grade_m_2';
|
||||
}else if($user_age == 15){
|
||||
$grade['grade'] = 'grade_m_3';
|
||||
}else if($user_age == 16){
|
||||
$grade['grade'] = 'grade_h_1';
|
||||
}else if($user_age == 17){
|
||||
$grade['grade'] = 'grade_h_2';
|
||||
}else if($user_age == 18){
|
||||
$grade['grade'] = 'grade_h_3';
|
||||
}else if($user_age == 19 || $user_age == 20){
|
||||
$grade['grade'] = 'grade_u_12';
|
||||
}else if($user_age >= 21){
|
||||
$grade['grade'] = 'grade_u_34';
|
||||
}
|
||||
}
|
||||
$sql_min = "WITH RankedGrades AS (
|
||||
SELECT
|
||||
id,
|
||||
level,
|
||||
".$grade['grade'].",
|
||||
ROW_NUMBER() OVER(PARTITION BY level ORDER BY ".$grade['grade']." ASC, id ASC) AS rn
|
||||
FROM
|
||||
".$this->base_use_db_name['4']."
|
||||
WHERE
|
||||
sex = ".$grade['gender']."
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
level,
|
||||
".$grade['grade']."
|
||||
FROM
|
||||
RankedGrades
|
||||
WHERE
|
||||
rn = 1";
|
||||
$result_min = Db::query($sql_min);
|
||||
foreach ($result_min as $key => $value) {
|
||||
foreach ($standard_data as $sdk => $sdv) {
|
||||
if($value['level'] == $sdv['text']){
|
||||
$standard_data[$sdk]['min_val'] = $value[$grade['grade']];
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i=count($standard_data)-1; $i >= 1; $i--) {
|
||||
$standard_data[$i]['max_val'] = $standard_data[$i-1]['min_val'];
|
||||
}
|
||||
$standard_data[0]['max_val'] = '5140';
|
||||
return $standard_data;
|
||||
}
|
||||
// 时间日期转换
|
||||
public function addCurrentTimeToDateString($dateStr) {
|
||||
// 将日期字符串转换为DateTime对象
|
||||
$dateTime = new \DateTime($dateStr);
|
||||
|
||||
// 获取当前的时分秒
|
||||
$currentTime = new \DateTime('now');
|
||||
$hours = $currentTime->format('H');
|
||||
$minutes = $currentTime->format('i');
|
||||
$seconds = $currentTime->format('s');
|
||||
|
||||
// 设置DateTime对象的时间部分为当前时间
|
||||
$dateTime->setTime($hours, $minutes, $seconds);
|
||||
|
||||
// 返回格式化为"Y-m-d H:i:s"的字符串
|
||||
return $dateTime->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
// 处理分秒变秒
|
||||
public function convertMinutesSecondsToStringSeconds($timeString) {
|
||||
// 分割字符串获取分钟和秒
|
||||
list($minutes, $seconds) = explode(':', $timeString);
|
||||
// 将分钟和秒转换为秒
|
||||
$totalSeconds = ($minutes * 60) + intval($seconds); // 确保秒是整数
|
||||
return $totalSeconds;
|
||||
}
|
||||
|
||||
// 转换数字"90.00", "88.11", "66.50", ".00"为正常数字
|
||||
public function convertStringToNumber($str) {
|
||||
// 去除字符串两端的空格(如果有的话)
|
||||
$str = trim($str);
|
||||
|
||||
// 检查字符串是否为空或只包含小数点
|
||||
if ($str === '' || $str === '.') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 尝试将字符串转换为浮点数
|
||||
$number = (float)$str;
|
||||
|
||||
// 格式化浮点数,去掉末尾多余的零
|
||||
$formattedNumber = rtrim(rtrim(sprintf('%.2f', $number), '0'), '.');
|
||||
|
||||
// 如果结果为空字符串(比如,原字符串是“.00”),则返回0
|
||||
if ($formattedNumber === '') {
|
||||
return '0';
|
||||
}
|
||||
// 返回结果,转换为整数如果小数点后没有数字
|
||||
if (strpos($formattedNumber, '.') === false) {
|
||||
$formattedNumber = (int)$formattedNumber;
|
||||
return "$formattedNumber";
|
||||
}
|
||||
|
||||
return $formattedNumber;
|
||||
}
|
||||
|
||||
// 时间加一或者减一
|
||||
public function adjustDateTime($datetimeStr, $type) {
|
||||
// 将时间字符串转换为时间戳
|
||||
$timestamp = strtotime($datetimeStr);
|
||||
|
||||
// 检查时间戳是否有效
|
||||
if ($timestamp === false) {
|
||||
return "无效的日期时间格式";
|
||||
}
|
||||
|
||||
// 根据$type参数调整时间戳
|
||||
switch ($type) {
|
||||
case 'add':
|
||||
$newTimestamp = strtotime('+1 day', $timestamp);
|
||||
break;
|
||||
case 'subtract':
|
||||
$newTimestamp = strtotime('-1 day', $timestamp);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
// 将新的时间戳转换回日期时间字符串
|
||||
$newDateTimeStr = date('Y-m-d', $newTimestamp);
|
||||
|
||||
return $newDateTimeStr;
|
||||
}
|
||||
|
||||
// 对于任意浮点字符串的指定位四舍五入
|
||||
public function roundToString($numberStr, $numDecimals) {
|
||||
// 将字符串转换为浮点数
|
||||
$number = floatval($numberStr);
|
||||
|
||||
// 四舍五入到指定的小数位数
|
||||
$roundedNumber = round($number, $numDecimals);
|
||||
|
||||
// 将结果转换回字符串
|
||||
return strval($roundedNumber);
|
||||
}
|
||||
|
||||
|
||||
// 发送一个PSOT请求
|
||||
public function postRequest($url, $data = [], $headers = []) {
|
||||
$ch = curl_init(); // 初始化cURL会话
|
||||
|
||||
if (!$ch) {
|
||||
return [
|
||||
'error' => true,
|
||||
'message' => 'cURL init failed'
|
||||
];
|
||||
}
|
||||
// 设置cURL选项
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 禁用证书验证
|
||||
curl_setopt($ch, CURLOPT_URL, $url); // 要请求的URL
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 将curl_exec()获取的信息以文件流的形式返回,而不是直接输出
|
||||
curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的POST请求
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // POST数据
|
||||
// 设置请求头
|
||||
if (!empty($headers)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
}else{
|
||||
// 如果需要发送JSON数据,可以使用以下设置:
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
||||
}
|
||||
// 执行cURL会话
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if ($response === false) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return [
|
||||
'error' => true,
|
||||
'message' => "cURL Error: $error"
|
||||
];
|
||||
}
|
||||
$decodedResponse = json_decode($response, true);
|
||||
$jsonError = json_last_error();
|
||||
curl_close($ch);
|
||||
|
||||
if ($jsonError !== JSON_ERROR_NONE) {
|
||||
return [
|
||||
'error' => true,
|
||||
'message' => 'Invalid JSON Response',
|
||||
'raw_response' => $response
|
||||
];
|
||||
}
|
||||
return $decodedResponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 接口说明(发邮件)
|
||||
* $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';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证数据是否符合指定类型要求
|
||||
*
|
||||
* @param mixed $data 要验证的数据
|
||||
* @param string $type 验证类型 (str, num, intnum, datetime)
|
||||
* @return bool 验证结果
|
||||
* @throws InvalidArgumentException 当传入未知类型时抛出异常
|
||||
*/
|
||||
public function verify_data_is_ok($data, string $type): bool
|
||||
{
|
||||
switch ($type) {
|
||||
case 'str':
|
||||
// 字符串验证 - 只要数据类型是字符串即可
|
||||
return is_string($data);
|
||||
|
||||
case 'num':
|
||||
// 数字验证 - 接受数字、数字字符串、小数和小数字符串
|
||||
// 注意:布尔值、科学计数法等也会被 is_numeric 认为是数字
|
||||
return is_numeric($data);
|
||||
|
||||
case 'intnum':
|
||||
// 整数验证 - 必须是整型或纯整数字符串
|
||||
// 使用 filter_var 同时验证整型和整数字符串
|
||||
return filter_var($data, FILTER_VALIDATE_INT) !== false;
|
||||
|
||||
case '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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException("未知的验证类型: {$type}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理身高体重的单位,转换它们为cm和kg。
|
||||
public function convertHeightAndWeight($height, $weight) {
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 定义单位转换比例
|
||||
$heightConversion = [
|
||||
'cm' => 1,
|
||||
'inch' => 2.54,
|
||||
'ft-in' => function($value) {
|
||||
list($ft, $in) = explode('-', $value);
|
||||
return $ft * 30.48 + $in * 2.54; // 1 foot = 30.48 cm, 1 inch = 2.54 cm
|
||||
}
|
||||
];
|
||||
$weightConversion = [
|
||||
'kg' => 1,
|
||||
'斤' => 0.5, // 1斤 = 0.5kg
|
||||
'st:lb' => function($value) {
|
||||
list($st, $lb) = explode(':', $value);
|
||||
return $st * 6.35029318 + $lb * 0.45359237; // 1 stone = 6.35029318 kg, 1 lb = 0.45359237 kg
|
||||
},
|
||||
'lb' => 0.45359237 // 1 lb = 0.45359237 kg
|
||||
];
|
||||
// 处理 height
|
||||
if (preg_match('/([\d.]+)(cm|inch|ft-in)/', $height, $matches)) {
|
||||
// $heightValue = floatval($matches[1]);
|
||||
$heightValue = $matches[1];
|
||||
$heightUnit = $matches[2];
|
||||
if($heightUnit == 'ft-in'){
|
||||
// 如果单位为st:lb但是数据格式不对
|
||||
$heightValue = str_replace($heightUnit, "", $height);
|
||||
if(count(explode('-', $heightValue)) < 2){
|
||||
$heightValue = str_replace("-", "", $heightValue);
|
||||
$heightValue = $heightValue."-0";
|
||||
}
|
||||
}
|
||||
if (isset($heightConversion[$heightUnit])) {
|
||||
if (is_callable($heightConversion[$heightUnit])) {
|
||||
$heightInCm = $heightConversion[$heightUnit]($heightValue);
|
||||
} else {
|
||||
$heightInCm = $heightValue * $heightConversion[$heightUnit];
|
||||
}
|
||||
} else {
|
||||
// 未知单位,返回错误
|
||||
$heightInCm = false;
|
||||
}
|
||||
} else {
|
||||
// 未找到指定单位判断是否是数字
|
||||
if (preg_match('/^-?\d+(\.\d+)?$/', $height)) {
|
||||
$heightInCm = $height;
|
||||
} else {
|
||||
$heightInCm = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理 weight
|
||||
if (preg_match('/([\d.:]+)(kg|斤|st:lb|lb)/', $weight, $matches)) {
|
||||
$weightValue = $matches[1];
|
||||
$weightUnit = $matches[2];
|
||||
if($weightUnit == 'st:lb'){
|
||||
// 如果单位为st:lb但是数据格式不对
|
||||
$weightValue = str_replace($weightUnit, "", $weight);
|
||||
if(count(explode(':', $weightValue)) < 2){
|
||||
$weightValue = str_replace(":", "", $weightValue);
|
||||
$weightValue = $weightValue.":0";
|
||||
}
|
||||
}
|
||||
if (isset($weightConversion[$weightUnit])) {
|
||||
if (is_callable($weightConversion[$weightUnit])) {
|
||||
$weightInKg = $weightConversion[$weightUnit]($weightValue);
|
||||
} else {
|
||||
$weightInKg = $weightValue * $weightConversion[$weightUnit];
|
||||
}
|
||||
} else {
|
||||
// 未知单位,返回错误
|
||||
$weightInKg = false;
|
||||
}
|
||||
} else {
|
||||
// 未找到指定单位判断是否是数字
|
||||
if (preg_match('/^-?\d+(\.\d+)?$/', $weight)) {
|
||||
$weightInKg = $weight;
|
||||
} else {
|
||||
$weightInKg = false;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'height_in_cm' => bcmul($heightInCm,1,2),
|
||||
'weight_in_kg' => bcmul($weightInKg,1,2)
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function ceshiyong($aa = 4,$gd = 0.2){
|
||||
|
||||
phpinfo();
|
||||
die;
|
||||
$token = 'cd3f27cf4c4002170ea7bceeb723ac91';
|
||||
|
||||
$data = Db::table('pc_bmistand2')->select();
|
||||
for ($i=0; $i < count($data); $i++) {
|
||||
foreach ($data[$i] as $key => $value) {
|
||||
$data[$i][$key] = str_replace(' ', '',$data[$i][$key]);
|
||||
|
||||
}
|
||||
Db::table('pc_bmistand2')->where(['id'=>$data[$i]['id']])->update([
|
||||
'month'=>$data[$i]['month'],
|
||||
'sex'=>$data[$i]['sex'],
|
||||
// 'f3sd'=>$data[$i]['f3sd'],
|
||||
// 'f2sd'=>$data[$i]['f2sd'],
|
||||
'f1sd'=>$data[$i]['f1sd'],
|
||||
'median'=>$data[$i]['median'],
|
||||
'z1sd'=>$data[$i]['z1sd'],
|
||||
'z2sd'=>$data[$i]['z2sd'],
|
||||
// 'z3sd'=>$data[$i]['z3sd'],
|
||||
]);
|
||||
}
|
||||
die;
|
||||
// $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,667 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use app\NewReedaw\controller\app\Cardparts;
|
||||
|
||||
class Body extends Base{
|
||||
|
||||
protected $body_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
'juese'=>'app_user_data',
|
||||
'body_data'=>'app_card_body_data',
|
||||
'bmi'=>'pc_bmistand',
|
||||
'heigh'=>'pc_heightstand',
|
||||
'weigh'=>'pc_weightstand',
|
||||
'chufang1'=>'pc_childrenprescription',
|
||||
'chufang2'=>'pc_childprescriptionbyage',
|
||||
];
|
||||
protected $result_end_data_mould = [
|
||||
'name'=>'',
|
||||
'value'=>'',
|
||||
'unit'=>'',
|
||||
'standard'=>'',
|
||||
'color'=>'',
|
||||
'list'=>[]
|
||||
];
|
||||
protected $age_limit = 16;
|
||||
protected $unit_name = ['score'=>'身体得分','height'=>'身高','weight'=>'体重','bmi'=>'BMI','fat_r'=>'脂肪率','fat_w'=>'脂肪量','muscle'=>'肌肉率','muscleval'=>'肌肉量','water'=>'水分','bone'=>'骨重','protein'=>'蛋白率','proteinval'=>'蛋白量','kcal'=>'基础代谢','visceral'=>'内脏指数','sfr'=>'皮下脂肪','body_level'=>'肥胖等级','body_type'=>'身体类型'];
|
||||
protected $unit_symbol = ['score'=>'分','height'=>'CM','weight'=>'公斤','bmi'=>'','fat_r'=>'%','fat_w'=>'kg','muscle'=>'%','muscleval'=>'kg','water'=>'kg','bone'=>'kg','protein'=>'%','proteinval'=>'kg','kcal'=>'kcal','visceral'=>'','sfr'=>'%',];
|
||||
protected $standard_color = [
|
||||
'fat_r'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'],
|
||||
'fat_w'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'],
|
||||
'muscle'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'],
|
||||
'muscleval'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'],
|
||||
'water'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
'proteinval'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
'bone'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
'protein'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
'kcal'=>['偏低'=>'#FF5656','优'=>'#3A68D4'],
|
||||
'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'],
|
||||
'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'],
|
||||
];
|
||||
protected $bhw_list = [
|
||||
'bmi'=>[
|
||||
['min_val'=>'0','max_val'=>'','text'=>'消瘦','color'=>'#FDDA6B'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'正常','color'=>'#59D06A'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'偏重','color'=>'#FDAA02'],
|
||||
['min_val'=>'','max_val'=>'50','text'=>'肥胖','color'=>'#FB5755'],
|
||||
],
|
||||
'height'=>[
|
||||
['min_val'=>'0','max_val'=>'','text'=>'矮','color'=>'#FD5759'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'偏矮','color'=>'#FAAD01'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#5BD068'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'偏高','color'=>'#6793F4'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#3D67D3'],
|
||||
],
|
||||
'weight'=>[
|
||||
['min_val'=>'0','max_val'=>'','text'=>'低','color'=>'#F8595D'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'偏低','color'=>'#FFAF04'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#59D168'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'偏高','color'=>'#FFAF04'],
|
||||
['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#F8595D'],
|
||||
]
|
||||
];
|
||||
protected $card_body_level = [
|
||||
'height'=>['value'=>1,'list'=>['矮'=>2,'偏矮'=>3,'标准'=>4,'偏高'=>5,'高'=>5]],
|
||||
'weight'=>['value'=>3,'list'=>['低'=>1,'偏低'=>1,'标准'=>2,'偏高'=>3,'高'=>3]],
|
||||
'bmi'=>['value'=>2,'list'=>['消瘦'=>1,'正常'=>2,'偏重'=>3,'肥胖'=>4]],
|
||||
];
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
// 获取角色报告
|
||||
public function body_report(){
|
||||
// phpinfo();
|
||||
// die;
|
||||
// try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
return $this->body_report_action_detailed($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################################################################
|
||||
################################################################action################################################################
|
||||
public function body_report_action_detailed($data){
|
||||
$result_return = [
|
||||
"score_name"=>"",
|
||||
"score_value"=>"",
|
||||
"score_unit"=>"",
|
||||
"body_type_name"=>"",
|
||||
"body_type_value"=>"",
|
||||
"body_type_unit"=>"",
|
||||
"record_time"=>"",
|
||||
'top_list'=>[
|
||||
[
|
||||
"name"=>"体重",
|
||||
"value"=>"0",
|
||||
"unit"=>"公斤",
|
||||
"standard"=>"",
|
||||
"color"=>"",
|
||||
"list"=>[],
|
||||
"key_name"=>"weight",
|
||||
"desc"=>"反映和衡量一个人健康状况的重要标志之一",
|
||||
"offset"=>"0",
|
||||
"standard_val"=>"",
|
||||
"difference_val"=>"",
|
||||
],
|
||||
[
|
||||
"name"=>"身高",
|
||||
"value"=>"0",
|
||||
"unit"=>"CM",
|
||||
"standard"=>"",
|
||||
"color"=>"",
|
||||
"list"=>[],
|
||||
"key_name"=>"height",
|
||||
"desc"=>"人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大",
|
||||
"offset"=>"0",
|
||||
"standard_val"=>"",
|
||||
"difference_val"=>"",
|
||||
],
|
||||
[
|
||||
"name"=>"BMI",
|
||||
"value"=>"0",
|
||||
"unit"=>"公斤",
|
||||
"standard"=>"",
|
||||
"color"=>"",
|
||||
"list"=>[],
|
||||
"key_name"=>"bmi",
|
||||
"desc"=>"BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。",
|
||||
"offset"=>"0",
|
||||
"standard_val"=>"",
|
||||
"difference_val"=>"",
|
||||
],
|
||||
],
|
||||
'bottom_list' => [],
|
||||
'cplist'=>[
|
||||
'nutritionlist'=>[],
|
||||
'sportlist'=>[],
|
||||
'sleeplist'=>[],
|
||||
'moodlist'=>[],
|
||||
],
|
||||
'target_current'=>[
|
||||
'target_weight'=>'0',
|
||||
'initial_weight'=>'0',
|
||||
'cumulative_weight'=>'0',
|
||||
'cumulative_day'=>'0'
|
||||
],
|
||||
];
|
||||
$body_last_data = Db::query("
|
||||
select
|
||||
Top 1
|
||||
acbd.id,
|
||||
acbd.acd_id,
|
||||
acbd.record_type,
|
||||
acbd.create_time,
|
||||
acbd.last_update_time,
|
||||
acbd.score,
|
||||
acbd.fat_r,
|
||||
acbd.fat_w,
|
||||
acbd.muscle,
|
||||
acbd.muscleval,
|
||||
acbd.water,
|
||||
acbd.proteinval,
|
||||
acbd.bone,
|
||||
acbd.protein,
|
||||
acbd.kcal,
|
||||
acbd.visceral,
|
||||
acbd.sfr,
|
||||
acbd.body_level,
|
||||
acbd.aud_id,
|
||||
acbd.record_time,
|
||||
acbd.body_type,
|
||||
acbd.age,
|
||||
acbd.is_del,
|
||||
acbd.height,
|
||||
acbd.height_val,
|
||||
acbd.weight,
|
||||
acbd.weight_val,
|
||||
acbd.bmi,
|
||||
acbd.body_age,
|
||||
acbd.head_circumference,
|
||||
aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date
|
||||
from ".$this->body_db_name['body_data']." as acbd
|
||||
left join ".$this->body_db_name['juese']." as aud on acbd.aud_id=aud.id
|
||||
where acbd.is_del=0 and acbd.aud_id='".$data['aud_id']."'
|
||||
order by acbd.record_time desc
|
||||
");
|
||||
// return $this->msg($body_last_data);
|
||||
if(count($body_last_data) <= 0){
|
||||
return $this->msg($result_return);
|
||||
}
|
||||
// 暂时存储头围数据
|
||||
$head_circumference = $body_last_data[0]['head_circumference']?json_decode($body_last_data[0]['head_circumference'],true):false;
|
||||
unset($body_last_data[0]['head_circumference']);
|
||||
// 处理返回数据
|
||||
$result_end = $this->processing_return_data_new($body_last_data[0]);
|
||||
|
||||
$cardparts = new Cardparts;
|
||||
$result_end['gender'] = $body_last_data[0]['gender'];
|
||||
$result_end['record_time'] = $body_last_data[0]['record_time'];
|
||||
|
||||
$result_end['score'] = $result_end['score'];
|
||||
$result_end['body_type'] = $result_end['body_type'];
|
||||
$result_end = $cardparts->conversion_interval($result_end);
|
||||
$result_end['cplist'] = $this->grow_up_recommendation([
|
||||
'birthday'=>$body_last_data[0]['birthday'],
|
||||
'body'=>[
|
||||
'height'=>$body_last_data[0]['height'],
|
||||
'weight'=>$body_last_data[0]['weight'],
|
||||
'bmi'=>$body_last_data[0]['bmi']
|
||||
],
|
||||
]);
|
||||
|
||||
// // 加入曲线板块底部的减肥计划数据start
|
||||
// $result_end['target_current'] = $this->base_target_initial_cumulative_weight([
|
||||
// 'weight'=>$body_last_data[0]['weight']>0?$body_last_data[0]['weight']:0,
|
||||
// 'target_weight'=>$body_last_data[0]['target_weight']>0?$body_last_data[0]['target_weight']:0,
|
||||
// 'initial_weight'=>$body_last_data[0]['initial_weight']>0?$body_last_data[0]['initial_weight']:0,
|
||||
// 'initial_date'=>$body_last_data[0]['initial_date']!=null?$body_last_data[0]['initial_date']:0,
|
||||
// ]);
|
||||
// // dump($result_end);
|
||||
// if(count($result_end['top_list'][2]['list']) <= 0){
|
||||
// // 这是16岁以上人群
|
||||
// $data = [
|
||||
// 'height'=>$body_last_data[0]['height_val'],
|
||||
// 'weight'=>$body_last_data[0]['weight_val'],
|
||||
// 'birthday'=>$body_last_data[0]['birthday'],
|
||||
// 'sex'=>$body_last_data[0]['gender']
|
||||
// ];
|
||||
|
||||
// $temporary_arr_bmi_list = $this->card_bmi_evaluation($data,true);
|
||||
// $temporary_arr_bmi_list = $temporary_arr_bmi_list->getData();
|
||||
|
||||
// if($temporary_arr_bmi_list['code'] == 0){
|
||||
// $result_end['top_list'][2]['standard'] = $temporary_arr_bmi_list['data']['bmilevel'];
|
||||
// $result_end['top_list'][2]['color'] = $temporary_arr_bmi_list['data']['bmilevelcolor'];
|
||||
// $result_end['top_list'][2]['list'] = $temporary_arr_bmi_list['data']['bmilevellist'];
|
||||
// $result_end['top_list'][2]['offset'] = $temporary_arr_bmi_list['data']['offset'];
|
||||
// }
|
||||
// // dump($result_end);
|
||||
// // die;
|
||||
// }
|
||||
|
||||
// 添加头围数据(如果有的话)start
|
||||
if($head_circumference !== false && $this->calculate_age($body_last_data[0]['birthday']) < 3){
|
||||
|
||||
if($head_circumference['level'] == '异常' || $head_circumference['value'] == 0){
|
||||
$offset = 0;
|
||||
}else{
|
||||
$offset = $cardparts->calculate_landing_point($head_circumference['list2'],$head_circumference['value'],$head_circumference['level']);
|
||||
}
|
||||
$touwei_array = [
|
||||
'name'=>'头围',
|
||||
'value'=>$head_circumference['value'],
|
||||
'unit'=>'CM',
|
||||
'standard'=>$head_circumference['level'],
|
||||
'color'=>'',
|
||||
'list'=>$head_circumference['list2'],
|
||||
'key_name'=>'head_circumference',
|
||||
'desc'=>'头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关',
|
||||
'offset'=>$offset
|
||||
];
|
||||
$touwei_data = $this->touwei_temporary_use($body_last_data[0]['birthday'],$body_last_data[0]['gender']);
|
||||
if(count($touwei_data)){
|
||||
$touwei_array['standard_val'] = $touwei_data['middle'];
|
||||
$touwei_array['difference_val'] = bcsub($touwei_array['value'],$touwei_data['middle'],2);
|
||||
}else{
|
||||
$touwei_array['standard_val'] = '';
|
||||
$touwei_array['difference_val'] = '';
|
||||
}
|
||||
array_push($result_end['top_list'],$touwei_array);
|
||||
|
||||
}
|
||||
// 添加头围数据(如果有的话)end
|
||||
// 这段业务处理可以删除,是做的临时的,假的start
|
||||
|
||||
$biaozhun_val = $this->body_temporary_use($body_last_data[0]['birthday'],$body_last_data[0]['gender']);
|
||||
// dump($biaozhun_val);
|
||||
// $biaozhun_val_weight = 50;
|
||||
// $biaozhun_val_height = 170;
|
||||
// $biaozhun_val_bmi = 22;
|
||||
foreach ($result_end['top_list'] as $key => $value) {
|
||||
if($value['key_name'] == 'weight'){
|
||||
if($biaozhun_val['weight'] == ''){
|
||||
$result_end['top_list'][$key]['standard_val'] = '';
|
||||
$result_end['top_list'][$key]['difference_val'] = '';
|
||||
}else{
|
||||
$result_end['top_list'][$key]['standard_val'] = $biaozhun_val['weight'];
|
||||
$result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['weight'],2);
|
||||
}
|
||||
}else if($value['key_name'] == 'height'){
|
||||
if($biaozhun_val['height'] == ''){
|
||||
$result_end['top_list'][$key]['standard_val'] = '';
|
||||
$result_end['top_list'][$key]['difference_val'] = '';
|
||||
}else{
|
||||
$result_end['top_list'][$key]['standard_val'] = $biaozhun_val['height'];
|
||||
$result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['height'],2);
|
||||
}
|
||||
}else if($value['key_name'] == 'bmi'){
|
||||
if($biaozhun_val['bmi'] == ''){
|
||||
$result_end['top_list'][$key]['standard_val'] = '';
|
||||
$result_end['top_list'][$key]['difference_val'] = '';
|
||||
}else{
|
||||
$result_end['top_list'][$key]['standard_val'] = $biaozhun_val['bmi'];
|
||||
$result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['bmi'],2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 这段业务处理可以删除,是做的临时的,假的end
|
||||
return $this->msg($result_end);
|
||||
// dump($result_end);
|
||||
|
||||
}
|
||||
|
||||
public function processing_return_data_new($data){
|
||||
$result_end_data = [];
|
||||
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
|
||||
$gender_val = $data['gender'];
|
||||
foreach ($data as $key => $value) {
|
||||
if($key != 'aud_id' && $key != 'id' && $key != 'create_time' && $key != 'last_update_time' && $key != 'acd_id' && $key != 'ROW_NUMBER' && $key != 'record_time' && $key != 'gender' && $key != 'birthday'){
|
||||
// 设置单个数据格式
|
||||
$result_end_data[$key] = $this->result_end_data_mould;
|
||||
// 该项名
|
||||
if(array_key_exists($key, $this->unit_name)){
|
||||
$result_end_data[$key]['name'] = $this->unit_name[$key];
|
||||
}
|
||||
// 该项单位
|
||||
if(array_key_exists($key, $this->unit_symbol)){
|
||||
$result_end_data[$key]['unit'] = $this->unit_symbol[$key];
|
||||
}
|
||||
|
||||
$result_end_data[$key]['value'] = explode(',',$value)[0];
|
||||
|
||||
if(strpos($value, ',')){
|
||||
$result_end_data[$key]['standard'] = explode(',',$value)[1];
|
||||
}
|
||||
if(array_key_exists($key, $this->standard_color)){
|
||||
if($result_end_data[$key]['standard'] != '异常' && $result_end_data[$key]['standard'] != ''){
|
||||
$result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']];
|
||||
}
|
||||
}
|
||||
// 如果小于16岁(儿童)
|
||||
if($data['age'] < $this->age_limit){
|
||||
if(array_key_exists($key, $this->bhw_list)){
|
||||
$result_end_data[$key]['list'] = $this->bhw_list[$key];
|
||||
if($key == 'bmi'){
|
||||
$bhw_date = Db::table($this->body_db_name['bmi'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||||
if($bhw_date){
|
||||
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f1sd'];
|
||||
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f1sd'];
|
||||
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['z1sd'];
|
||||
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['z1sd'];
|
||||
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z2sd'];
|
||||
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z2sd'];
|
||||
}
|
||||
}else if($key == 'height'){
|
||||
$bhw_date = Db::table($this->body_db_name['heigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||||
if($bhw_date){
|
||||
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||||
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||||
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||||
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||||
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||||
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||||
$result_end_data[$key]['list'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||||
$result_end_data[$key]['list'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||||
$result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||||
}
|
||||
}else if($key == 'weight'){
|
||||
$bhw_date = Db::table($this->body_db_name['weigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||||
if($bhw_date){
|
||||
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||||
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||||
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||||
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||||
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||||
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||||
$result_end_data[$key]['list'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||||
$result_end_data[$key]['list'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||||
$result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result_end_data;
|
||||
}
|
||||
public function grow_up_recommendation($data){
|
||||
// card_body_level
|
||||
// die;
|
||||
// $result = [
|
||||
// ['name'=>'营养','key'=>'nutrition','content'=>''],
|
||||
// ['name'=>'睡眠','key'=>'sleep','content'=>''],
|
||||
// ['name'=>'运动','key'=>'motion','content'=>''],
|
||||
// ['name'=>'情绪','key'=>'emotion','content'=>'']
|
||||
// ];
|
||||
$result = [
|
||||
'nutritionlist'=>[],//营养
|
||||
'sportlist'=>[],//运动
|
||||
'sleeplist'=>[],//睡眠
|
||||
'moodlist'=>[],//情绪
|
||||
];
|
||||
|
||||
$temporary_arr = [];
|
||||
foreach ($data['body'] as $key => $value) {
|
||||
if(explode(',',$value)[1] == '无'){
|
||||
$result = [
|
||||
'nutritionlist'=>[],//营养
|
||||
'sportlist'=>[],//运动
|
||||
'sleeplist'=>[],//睡眠
|
||||
'moodlist'=>[],//情绪
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
$temporary_arr[$key] = $this->card_body_level[$key]['list'][explode(',',$value)[1]];
|
||||
}
|
||||
$min_value = min($temporary_arr);
|
||||
$min_key = array_search($min_value,$temporary_arr);
|
||||
$type_num = $this->card_body_level[$min_key]['value'];
|
||||
$temporary_arr2 = Db::table($this->body_db_name['chufang1'])->where(['Type'=>$type_num,'Level'=>$min_value,'IsDeleted'=>0])->field('Nutrition,Sport')->find();
|
||||
// dump($temporary_arr2);
|
||||
array_push($result['nutritionlist'],$temporary_arr2['Nutrition']);
|
||||
array_push($result['sportlist'],$temporary_arr2['Sport']);
|
||||
// $result['nutritionlist'] = $temporary_arr2['Nutrition'];
|
||||
// $result['sportlist'] = $temporary_arr2['Sport'];
|
||||
|
||||
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
|
||||
$temporary_arr2 = Db::table($this->body_db_name['chufang2'])->where(['IsDeleted'=>0])->field('MinAge,MaxAge,Type,Content')->select();
|
||||
$default_sleep = '';
|
||||
$default_emotion = '';
|
||||
foreach ($temporary_arr2 as $key => $value) {
|
||||
if($value['MinAge'] == -1 && $value['Type'] == 2){
|
||||
$default_sleep = $value['Content'];
|
||||
}
|
||||
if($value['MinAge'] == -1 && $value['Type'] == 3){
|
||||
$default_emotion = $value['Content'];
|
||||
}
|
||||
if($month_num>=$value['MinAge'] && $month_num<=$value['MaxAge']){
|
||||
if($value['Type'] == 1){
|
||||
array_push($result['sportlist'],$value['Content']);
|
||||
// $result['sportlist'] = $result['sportlist'].$value['Content'];
|
||||
}else if($value['Type'] == 2){
|
||||
array_push($result['sleeplist'],$value['Content']);
|
||||
// $result['sleeplist'] = $result['sleeplist'].$value['Content'];
|
||||
}else if($value['Type'] == 3){
|
||||
array_push($result['moodlist'],$value['Content']);
|
||||
// $result['moodlist'] = $result['moodlist'].$value['Content'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result['sleeplist'] = count($result['sleeplist']) <= 0?array_push($result['sportlist'],$default_sleep):$result['sleeplist'];
|
||||
$result['moodlist'] = count($result['moodlist']) <= 0?array_push($result['moodlist'],$default_sleep):$result['moodlist'];
|
||||
|
||||
return $result;
|
||||
}
|
||||
public function touwei_temporary_use($age,$gender){
|
||||
$return_data = [
|
||||
|
||||
];
|
||||
if(!in_array($gender,['1','2'])){
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
$age_m = $this->calculateAgeInMonthsWithPrecision($age);
|
||||
|
||||
if($age_m <= 36){
|
||||
// $touwei_date = Db::table('ws_touwei')->where("age <= $age_m and gender = '$gender'")->order('age desc')->limit(1)->field('middle')->fetchSql(true)->select();
|
||||
$touwei_date = Db::query("select * from ws_touwei where age <= $age_m and gender = '$gender' order by age desc");
|
||||
$return_data = $touwei_date[0];
|
||||
}
|
||||
return $return_data;
|
||||
}
|
||||
public function body_temporary_use($age,$gender){
|
||||
$return_data = [
|
||||
'height'=>'',
|
||||
'weight'=>'',
|
||||
'bmi'=>'',
|
||||
];
|
||||
if(!in_array($gender,['1','2'])){
|
||||
return $return_data;
|
||||
}
|
||||
$age_m = $this->calculateAgeInMonthsWithPrecision($age);
|
||||
if($age_m < 228){//月龄小于19岁
|
||||
// dump($age_m);
|
||||
// $height_date = Db::table('ws_height')->where("age <= $age_m and gender = '$gender'")->order('age desc')->limit(1)->field('middle')->select();
|
||||
$height_date = Db::query("select * from ws_height where age <= $age_m and gender = '$gender' order by age desc");
|
||||
// $weight_date = Db::table('ws_weight')->where("age <= $month_num and Sex = '$gender'")->order('age desc')->limit(1)->field('middle')->select();
|
||||
$weight_date = Db::query("select * from ws_weight where age <= $age_m and gender = '$gender' order by age desc");
|
||||
// $bmi_date = Db::table('ws_bmi')->where("age <= $month_num and Sex = '$gender'")->order('age desc')->limit(1)->field('middle')->select();
|
||||
$bmi_date = Db::query("select * from ws_bmi where age <= $age_m and gender = '$gender' order by age desc");
|
||||
$return_data = array(
|
||||
'height' => $height_date[0]['middle'],
|
||||
'weight' => $weight_date[0]['middle'],
|
||||
'bmi' => $bmi_date[0]['middle'],
|
||||
);
|
||||
}else{
|
||||
$bmi_data = [
|
||||
'1' => [ // 男性
|
||||
[
|
||||
'age' => ['min' => 216, 'max' => 299], // 18-24岁(216-299月龄)
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.5', 'max_val' => '20.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '20.5', 'max_val' => '23.9', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '24.0', 'max_val' => '27.9', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '28.0', 'max_val' => '31.9', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '32.0', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
],
|
||||
[
|
||||
'age' => ['min' => 300, 'max' => 419], // 25-34岁(300-419月龄)
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.5', 'max_val' => '20.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '21.0', 'max_val' => '24.4', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '24.5', 'max_val' => '28.4', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '28.5', 'max_val' => '32.4', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '32.5', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
],
|
||||
[
|
||||
'age' => ['min' => 420, 'max' => 539], // 35-44岁(420-539月龄)
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.5', 'max_val' => '21.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '21.5', 'max_val' => '25.0', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '25.1', 'max_val' => '29.0', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '29.1', 'max_val' => '33.0', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '33.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
],
|
||||
[
|
||||
'age' => ['min' => 540, 'max' => 719], // 45-59岁(540-719月龄)
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.5', 'max_val' => '21.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '22.0', 'max_val' => '25.5', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '25.6', 'max_val' => '29.5', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '29.6', 'max_val' => '33.5', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '33.6', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
],
|
||||
[
|
||||
'age' => ['min' => 720, 'max' => '99999'], // ≥60岁(720+月龄)
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.5', 'max_val' => '22.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '22.5', 'max_val' => '26.0', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '26.1', 'max_val' => '29.0', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '29.1', 'max_val' => '33.0', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '33.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
]
|
||||
],
|
||||
'2' => [ // 女性
|
||||
[
|
||||
'age' => ['min' => 216, 'max' => 299], // 18-24岁
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.0', 'max_val' => '19.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '20.0', 'max_val' => '22.9', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '23.0', 'max_val' => '26.9', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '27.0', 'max_val' => '30.9', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '31.0', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
],
|
||||
[
|
||||
'age' => ['min' => 300, 'max' => 419], // 25-34岁
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.0', 'max_val' => '20.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '20.5', 'max_val' => '23.4', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '23.5', 'max_val' => '27.4', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '27.5', 'max_val' => '31.4', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '31.5', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
],
|
||||
[
|
||||
'age' => ['min' => 420, 'max' => 539], // 35-44岁
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.0', 'max_val' => '20.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '21.0', 'max_val' => '24.0', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '24.1', 'max_val' => '28.0', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '28.1', 'max_val' => '32.0', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '32.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
],
|
||||
[
|
||||
'age' => ['min' => 540, 'max' => 719], // 45-59岁
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.0', 'max_val' => '21.4', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '21.5', 'max_val' => '24.5', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '24.6', 'max_val' => '28.5', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '28.6', 'max_val' => '32.5', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '32.6', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
],
|
||||
[
|
||||
'age' => ['min' => 720, 'max' => 99999], // ≥60岁
|
||||
'list'=>[
|
||||
['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'],
|
||||
['min_val' => '18.0', 'max_val' => '21.9', 'text' => '偏瘦', 'color' => '#B4E3FD'],
|
||||
['min_val' => '22.0', 'max_val' => '25.0', 'text' => '正常', 'color' => '#6CD86F'],
|
||||
['min_val' => '25.1', 'max_val' => '28.0', 'text' => '超重', 'color' => '#FFD166'],
|
||||
['min_val' => '28.1', 'max_val' => '32.0', 'text' => '肥胖', 'color' => '#FF9A5A'],
|
||||
['min_val' => '32.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B']
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($bmi_data[$gender] as $group) {
|
||||
if ($age_m >= $group['age']['min'] && $age_m <= $group['age']['max']) {
|
||||
$return_data['bmi'] = bcdiv(bcadd($group['list'][2]['min_val'],$group['list'][2]['max_val'],20),2,1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $return_data;
|
||||
}
|
||||
// public function body_report_action_detailed($data){
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,487 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
|
||||
class Cardparts extends Base{
|
||||
|
||||
protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6'];
|
||||
protected $parameter_aggregate_top = [
|
||||
'weight'=>'反映和衡量一个人健康状况的重要标志之一',
|
||||
'height'=>'人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大',
|
||||
'bmi'=>'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。'
|
||||
];
|
||||
protected $parameter_aggregate_bottom = [
|
||||
'fat_r'=>'体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。',
|
||||
'fat_w'=>'人体脂肪的重量',
|
||||
'muscle'=>'根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。',
|
||||
'muscleval'=>'肌肉量=实际体重*肌肉率',
|
||||
'water'=>'指人体内水分比例。',
|
||||
'proteinval'=>'蛋白量=实际体重*蛋白率',
|
||||
'bone'=>'单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。',
|
||||
'protein'=>'人体内蛋白率含量。',
|
||||
'kcal'=>'指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率',
|
||||
'visceral'=>'内脏脂肪指数',
|
||||
'sfr'=>'皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织',
|
||||
'body_level'=>'肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。'
|
||||
];
|
||||
protected $parameter_aggregate_bottom_out = ['body_level'];
|
||||
protected $parameter_aggregate_bottom_condition = ['body_level'];
|
||||
// 脂肪率&脂肪量
|
||||
protected $fat_r_w = [
|
||||
'man'=>[
|
||||
'29'=>[
|
||||
['min_val'=>'0','max_val'=>'10','text'=>'偏低','color'=>'#FCDB67'],
|
||||
['min_val'=>'10','max_val'=>'21','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'21','max_val'=>'26','text'=>'偏高','color'=>'#FAB000'],
|
||||
['min_val'=>'26','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
|
||||
],
|
||||
'30'=>[
|
||||
['min_val'=>'0','max_val'=>'11','text'=>'偏低','color'=>'#FCDB67'],
|
||||
['min_val'=>'11','max_val'=>'22','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'22','max_val'=>'27','text'=>'偏高','color'=>'#FAB000'],
|
||||
['min_val'=>'27','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
|
||||
],
|
||||
],
|
||||
'woman'=>[
|
||||
'29'=>[
|
||||
['min_val'=>'0','max_val'=>'20','text'=>'偏低','color'=>'#FCDB67'],
|
||||
['min_val'=>'20','max_val'=>'31','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'31','max_val'=>'38','text'=>'偏高','color'=>'#FAB000'],
|
||||
['min_val'=>'38','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
|
||||
],
|
||||
'30'=>[
|
||||
['min_val'=>'0','max_val'=>'21','text'=>'偏低','color'=>'#FCDB67'],
|
||||
['min_val'=>'21','max_val'=>'32','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'32','max_val'=>'39','text'=>'偏高','color'=>'#FAB000'],
|
||||
['min_val'=>'39','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
|
||||
]
|
||||
]
|
||||
];
|
||||
// 肌肉率&肌肉量
|
||||
protected $muscle_muscleval = [
|
||||
'man'=>[
|
||||
['min_val'=>'0','max_val'=>'40','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||||
],
|
||||
'woman'=>[
|
||||
['min_val'=>'0','max_val'=>'30','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'30','max_val'=>'50','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'50','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||||
]
|
||||
];
|
||||
// 水分
|
||||
protected $water = [
|
||||
'man'=>[
|
||||
['min_val'=>'0','max_val'=>'55','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'55','max_val'=>'65','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'65','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||||
],
|
||||
'woman'=>[
|
||||
['min_val'=>'0','max_val'=>'45','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'45','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||||
]
|
||||
];
|
||||
// 蛋白量&蛋白率
|
||||
protected $proteinval_protein = [
|
||||
'man'=>[
|
||||
['min_val'=>'0','max_val'=>'16','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'16','max_val'=>'18','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'18','max_val'=>'50','text'=>'优','color'=>'#3C66D2'], //蓝
|
||||
],
|
||||
'woman'=>[
|
||||
['min_val'=>'0','max_val'=>'14','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'14','max_val'=>'16','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'16','max_val'=>'50','text'=>'优','color'=>'#3C66D2'],
|
||||
]
|
||||
];
|
||||
// 骨重
|
||||
protected $bone = [
|
||||
'man'=>[
|
||||
'60'=>[
|
||||
['min_val'=>'0','max_val'=>'2.4','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'2.4','max_val'=>'2.6','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'2.6','max_val'=>'6','text'=>'优','color'=>'#3C66D2'],
|
||||
],
|
||||
'60_75'=>[
|
||||
['min_val'=>'0','max_val'=>'2.8','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'2.8','max_val'=>'3','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'3','max_val'=>'6','text'=>'优','color'=>'#3C66D2'],
|
||||
],
|
||||
'75'=>[
|
||||
['min_val'=>'0','max_val'=>'3.1','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'3.1','max_val'=>'3.3','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'3.3','max_val'=>'7','text'=>'优','color'=>'#3C66D2'],
|
||||
],
|
||||
],
|
||||
'woman'=>[
|
||||
'45'=>[
|
||||
['min_val'=>'0','max_val'=>'1.7','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'1.7','max_val'=>'1.9','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'1.9','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
|
||||
],
|
||||
'45_60'=>[
|
||||
['min_val'=>'0','max_val'=>'2.1','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'2.1','max_val'=>'2.3','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'2.3','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
|
||||
],
|
||||
'60'=>[
|
||||
['min_val'=>'0','max_val'=>'2.4','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'2.4','max_val'=>'2.6','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'2.6','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
|
||||
],
|
||||
]
|
||||
];
|
||||
// 基础代谢
|
||||
protected $kcal = [
|
||||
['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'],
|
||||
['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#3C66D2'],
|
||||
];
|
||||
// 内脏指数
|
||||
protected $visceral = [
|
||||
'man'=>[
|
||||
['min_val'=>'0','max_val'=>'9','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'9','max_val'=>'14','text'=>'警惕','color'=>'#FAB000'],
|
||||
['min_val'=>'14','max_val'=>'50','text'=>'危险','color'=>'#FA5951'], //红
|
||||
],
|
||||
'woman'=>[
|
||||
['min_val'=>'0','max_val'=>'9','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'9','max_val'=>'14','text'=>'警惕','color'=>'#FAB000'],
|
||||
['min_val'=>'14','max_val'=>'50','text'=>'危险','color'=>'#FA5951'], //红
|
||||
]
|
||||
];
|
||||
// 皮下脂肪
|
||||
protected $sfr = [
|
||||
'man'=>[
|
||||
['min_val'=>'0','max_val'=>'7','text'=>'不足','color'=>'#FCDB67'], //淡黄
|
||||
['min_val'=>'7','max_val'=>'15','text'=>'标准','color'=>'#59D16D'], //绿
|
||||
['min_val'=>'15','max_val'=>'50','text'=>'偏高','color'=>'#FAB000'], //橙
|
||||
],
|
||||
'woman'=>[
|
||||
['min_val'=>'0','max_val'=>'11','text'=>'不足','color'=>'#FCDB67'],
|
||||
['min_val'=>'11','max_val'=>'17','text'=>'标准','color'=>'#59D16D'],
|
||||
['min_val'=>'17','max_val'=>'50','text'=>'偏高','color'=>'#FAB000'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 计算部分内容的横线标准以及说明文字
|
||||
public function conversion_interval($data){
|
||||
// $data['gender'] = $data['gender']==2?'woman':'man';
|
||||
$gender = $data['gender']==2?'woman':'man';
|
||||
$age = $data['age']['value'];
|
||||
$weight = 0;
|
||||
$temporary_arr = [
|
||||
'score_name' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['name']:'',
|
||||
'score_value' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['value']:'',
|
||||
'score_unit' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['unit']:'',
|
||||
'body_type_name' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['name']:'',
|
||||
'body_type_value' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['value']:'',
|
||||
'body_type_unit' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['unit']:'',
|
||||
// 'record_time' =>str_replace('-', '/', $data['record_time']),
|
||||
'record_time' =>$data['record_time'],
|
||||
'top_list'=>[],
|
||||
'bottom_list'=>[],
|
||||
];
|
||||
// die;
|
||||
// $date_temporary = new \DateTime($temporary_arr['record_time']);
|
||||
|
||||
// 使用 format 方法来指定新的日期和时间格式
|
||||
// $temporary_arr['record_time'] = $date_temporary->format('Y年m月d日 H:i:s');
|
||||
// 处理格式(顶部)
|
||||
foreach ($this->parameter_aggregate_top as $key => $value) {
|
||||
$data[$key]['key_name'] = $key;
|
||||
$data[$key]['desc'] = $value;
|
||||
if($key == 'weight'){
|
||||
$weight = $data[$key]['value'];
|
||||
}
|
||||
array_push($temporary_arr['top_list'],$data[$key]);
|
||||
}
|
||||
|
||||
// 处理格式(底部)
|
||||
foreach ($this->parameter_aggregate_bottom as $key => $value) {
|
||||
$data[$key]['key_name'] = $key;
|
||||
$data[$key]['desc'] = $value;
|
||||
array_push($temporary_arr['bottom_list'],$data[$key]);
|
||||
}
|
||||
// 处理顶部list
|
||||
foreach ($temporary_arr['top_list'] as $key => $value) {
|
||||
|
||||
if(count($value['list']) > 0){
|
||||
$temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($value['list'],$value['value'],$value['standard'])[0];
|
||||
}
|
||||
}
|
||||
// 如果是没有阻抗的测试,那么就不要底部的其他数据了
|
||||
if($data['record_type']['value'] != 'by_device_adc'){
|
||||
$temporary_arr['bottom_list'] = [];
|
||||
return $temporary_arr;
|
||||
}
|
||||
// 处理底部list
|
||||
|
||||
|
||||
foreach ($temporary_arr['bottom_list'] as $key => $value) {
|
||||
// dump($value);
|
||||
// 脂肪率&
|
||||
if($value['key_name'] == 'fat_r'){
|
||||
if($age < 30){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['29'];
|
||||
}else{
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['30'];
|
||||
}
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 脂肪量
|
||||
else if($value['key_name'] == 'fat_w'){
|
||||
if($age < 30){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['29'];
|
||||
}else{
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['30'];
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']);
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 肌肉率
|
||||
else if($value['key_name'] == 'muscle'){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender];
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 肌肉量
|
||||
else if($value['key_name'] == 'muscleval'){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender];
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']);
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 水分
|
||||
else if($value['key_name'] == 'water'){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->water[$gender];
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 蛋白量
|
||||
else if($value['key_name'] == 'proteinval'){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->proteinval_protein[$gender];
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']);
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 骨重
|
||||
else if($value['key_name'] == 'bone'){
|
||||
if($gender == 'man'){
|
||||
if($weight < 60){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60'];
|
||||
}else if($weight >= 60 && $weight < 75){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60_75'];
|
||||
}else{
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['75'];
|
||||
}
|
||||
}else{
|
||||
if($weight < 45){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['45'];
|
||||
}else if($weight >= 45 && $weight < 60){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['45_60'];
|
||||
}else{
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60'];
|
||||
}
|
||||
}
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 蛋白率
|
||||
else if($value['key_name'] == 'protein'){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->proteinval_protein[$gender];
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 基础代谢
|
||||
else if($value['key_name'] == 'kcal'){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($this->kcal,$weight,$value['key_name'],$age,$gender);
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 内脏指数
|
||||
else if($value['key_name'] == 'visceral'){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->visceral[$gender];
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
// 皮下脂肪
|
||||
else if($value['key_name'] == 'sfr'){
|
||||
$temporary_arr['bottom_list'][$key]['list'] = $this->sfr[$gender];
|
||||
// 处理异常
|
||||
if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){
|
||||
$temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]);
|
||||
}
|
||||
$temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']);
|
||||
}
|
||||
}
|
||||
return $temporary_arr;
|
||||
}
|
||||
|
||||
|
||||
// 计算落点百分比(区间字典,值,值描述)
|
||||
public function calculate_landing_point($data,$val,$t_val){
|
||||
// 根据字典确认有几个区间
|
||||
$num = count($data);
|
||||
if($num <= 0){
|
||||
return 0;
|
||||
}
|
||||
// 没个区间占比
|
||||
$a_section = bcdiv(100,$num,2);
|
||||
$temporary_data = [];
|
||||
$num_0 = 0;
|
||||
// 看看值是在哪个区间
|
||||
foreach ($data as $key => $value) {
|
||||
if($val>=$value['min_val'] && $val<$value['max_val']){
|
||||
$temporary_data = $value;
|
||||
$num_0 = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(count($temporary_data) <= 0){
|
||||
return 0;
|
||||
}
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
$max_num = trim($temporary_data['max_val']);
|
||||
$min_num = trim($temporary_data['min_val']);
|
||||
if($val < $temporary_data['max_val']){
|
||||
// 这个值比最小值多出来多少
|
||||
$num_1 = bcsub($val,$min_num,2);
|
||||
// 这个区间的值是多少
|
||||
$num_2 = bcsub($max_num,$min_num,2);
|
||||
// 算出这个值在这个区间的占比
|
||||
$num_3 = bcdiv($num_1,$num_2,2);
|
||||
|
||||
$num_4 = bcmul($num_3,$a_section,2);
|
||||
$result = bcadd($num_4,bcmul($a_section,$num_0,2),2);
|
||||
}else{
|
||||
// $num_4 = bcdiv(1,$num,4)*100;
|
||||
$result = bcadd(bcmul($num_0,$a_section,2),$a_section,2);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 计算新标准
|
||||
public function calculate_new_standard($data,$w,$k,$age=0,$gender='man'){
|
||||
$temporary_arr = [];
|
||||
if($k != 'kcal'){
|
||||
foreach ($data as $key => $value) {
|
||||
array_push($temporary_arr,[
|
||||
'min_val'=>bcmul($w,bcdiv($value['min_val'],100,2),2),
|
||||
'max_val'=>bcmul($w,bcdiv($value['max_val'],100,2),2),
|
||||
'text'=>$value['text'],
|
||||
'color'=>$value['color']
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
// BMR标准值(男) BMR标准值(女)
|
||||
// 60.9*体重(kg)-54 61.0*体重(kg)-51
|
||||
// 22.7*体重(kg)+495 22.5*体重(kg)+499
|
||||
// 17.5*体重(kg)+651 12.2*体重(kg)+746
|
||||
// 15.3*体重(kg)+679 14.7*体重(kg)+496
|
||||
// 11.6*体重(kg)+879 8.7*体重(kg)+820
|
||||
$vv_val = 0;
|
||||
if($age < 3){
|
||||
if($gender == 'man'){
|
||||
$vv_val = bcsub(bcmul(60.9,$w,2),54,2);
|
||||
}else{
|
||||
$vv_val = bcsub(bcmul(61.0,$w,2),51,2);
|
||||
}
|
||||
}else if($age >= 3 && $age < 10){
|
||||
if($gender == 'man'){
|
||||
$vv_val = bcadd(bcmul(22.7,$w,2),495,2);
|
||||
}else{
|
||||
$vv_val = bcadd(bcmul(22.5,$w,2),499,2);
|
||||
}
|
||||
}else if($age >= 10 && $age < 18){
|
||||
if($gender == 'man'){
|
||||
$vv_val = bcadd(bcmul(17.5,$w,2),651,2);
|
||||
}else{
|
||||
$vv_val = bcadd(bcmul(12.2,$w,2),746,2);
|
||||
}
|
||||
}else if($age >= 18 && $age < 30){
|
||||
if($gender == 'man'){
|
||||
$vv_val = bcadd(bcmul(15.3,$w,2),679,2);
|
||||
}else{
|
||||
$vv_val = bcadd(bcmul(14.7,$w,2),496,2);
|
||||
}
|
||||
}else{
|
||||
if($gender == 'man'){
|
||||
$vv_val = bcadd(bcmul(11.6,$w,2),879,2);
|
||||
}else{
|
||||
$vv_val = bcadd(bcmul(8.7,$w,2),820,2);
|
||||
}
|
||||
}
|
||||
$data[0]['max_val'] = $vv_val;
|
||||
$data[1]['min_val'] = $vv_val;
|
||||
$temporary_arr = $data;
|
||||
}
|
||||
return $temporary_arr;
|
||||
}
|
||||
|
||||
|
||||
// 处理异常
|
||||
public function handling_exceptions($data){
|
||||
for ($i=0; $i < count($data['list']); $i++) {
|
||||
if($data['value']>=$data['list'][$i]['min_val'] && $data['value']<$data['list'][$i]['max_val']){
|
||||
$data['standard'] = $data['list'][$i]['text'];
|
||||
$data['color'] = $data['list'][$i]['color'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($data['standard'] == '异常'){
|
||||
if($data['value'] <= $data['list'][0]['min_val']){
|
||||
$data['standard'] = $data['list'][0]['text'];
|
||||
$data['color'] = $data['list'][0]['color'];
|
||||
}else if($data['value'] >= $data['list'][count($data['list'])-1]['max_val']){
|
||||
$data['standard'] = $data['list'][count($data['list'])-1]['text'];
|
||||
$data['color'] = $data['list'][count($data['list'])-1]['color'];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,298 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use app\NewReedaw\controller\app\Role;
|
||||
|
||||
class Index extends Base{
|
||||
|
||||
protected $index_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
'juese'=>'app_user_data',
|
||||
'body_data'=>'app_card_body_data',
|
||||
|
||||
];
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 配置信息
|
||||
public function config($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
return $this->config_action($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 genetic_height(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['dadHeight'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['momHeight'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['sex'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
|
||||
// 直接开始业务,请求外部接口start
|
||||
$url = 'https://ybapi.pcxbc.com/api/child/predictheight';
|
||||
$temporary_parameter = [
|
||||
'dadHeight'=>$data['dadHeight'],
|
||||
'momHeight'=>$data['momHeight'],
|
||||
'birthday'=>$data['birthday'],
|
||||
'sex'=>$data['sex'],
|
||||
];
|
||||
$request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
|
||||
// 直接开始业务,请求外部接口end
|
||||
return json($request_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'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
// BMI测评
|
||||
public function bmi_evaluation(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['height'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['weight'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['sex'],'intnum')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
|
||||
// 直接开始业务,请求外部接口start
|
||||
$url = 'http://ybdevice.pcxbc.com/api/result/calcbmi';
|
||||
$temporary_parameter = [
|
||||
'height'=>$data['height'],
|
||||
'weight'=>$data['weight'],
|
||||
'birthday'=>$data['birthday'],
|
||||
'sex'=>$data['sex'],
|
||||
];
|
||||
$request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
|
||||
// 直接开始业务,请求外部接口end
|
||||
|
||||
// 处理进度点
|
||||
$return_result =$this->bmi_evaluation_action($request_result);
|
||||
return $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'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
// 获取首页角色信息
|
||||
public function get_user_data_information(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
return $this->get_user_data_information_action($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################################################################
|
||||
################################################################action################################################################
|
||||
|
||||
public function config_action($data){
|
||||
$return_data = [
|
||||
'literature'=>[
|
||||
'index'=>[
|
||||
'*数据参考:',
|
||||
'《中华人民共和国卫生行业标准WS/T 423-2022》',
|
||||
'《中华人民共和国卫生行业标准WS/T 612-2018》',
|
||||
'《中华人民共和国卫生行业标准WS/T 586-2018》',
|
||||
'《WHO 5~19岁身高/体重判定标准》',
|
||||
],
|
||||
'bmi_evaluation'=>[
|
||||
'*数据参考:',
|
||||
'《WHO 5~19岁身高/体重判定标准》'
|
||||
],
|
||||
'height_prediction'=>[
|
||||
'*数据参考:',
|
||||
'Khamis-Roche方法',
|
||||
'北京积水潭医院儿科临床参考公式',
|
||||
'《中国妇幼保健》等相关学术期刊文献',
|
||||
],
|
||||
'warning'=>[
|
||||
'此测量数据仅供参考,不可替代医学专业测试!'
|
||||
]
|
||||
],
|
||||
'king_kong_region'=>[
|
||||
['title'=>'增量对比','icon'=>'','jump'=>''],
|
||||
['title'=>'中招估分','icon'=>'','jump'=>''],
|
||||
['title'=>'遗传身高','icon'=>'','jump'=>''],
|
||||
['title'=>'BMI测评','icon'=>'','jump'=>''],
|
||||
],
|
||||
'role_list'=>[
|
||||
]
|
||||
];
|
||||
$role = new Role;
|
||||
$return_data['role_list'] = $role->role_list_action(['token'=>$data['token'],'type'=>2])->getData()['data'];
|
||||
return $this->msg($return_data);
|
||||
}
|
||||
public function bmi_evaluation_action($data){
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
if(!array_key_exists('code',$data) || !array_key_exists('data',$data)){
|
||||
return $this->msg(99999,'网络异常,请稍后重试1');
|
||||
}
|
||||
if($data['code'] != 0){
|
||||
return $this->msg(99999,'网络异常,请稍后重试2');
|
||||
}
|
||||
if(!is_array($data['data'])){
|
||||
return $this->msg(99999,'网络异常,请稍后重试3');
|
||||
}
|
||||
if(!array_key_exists('bmi',$data['data']) || !array_key_exists('bmilevel',$data['data']) || !array_key_exists('bmilevelcolor',$data['data']) || !array_key_exists('bmilevellist',$data['data'])){
|
||||
return $this->msg(99999,'网络异常,请稍后重试4');
|
||||
}
|
||||
if(!is_array($data['data']['bmilevellist'])){
|
||||
return $this->msg(99999,'网络异常,请稍后重试5');
|
||||
}
|
||||
$num = 0;
|
||||
$subsection_val = 0;
|
||||
$temporary_subsection_val = null;
|
||||
foreach ($data['data']['bmilevellist'] as $key => $value) {
|
||||
if(!array_key_exists('maxvalue',$value) || !array_key_exists('minvalue',$value)){
|
||||
return $this->msg(99999,'网络异常,请稍后重试6');
|
||||
}
|
||||
// 判断是否可以进行比较,规则是否正确
|
||||
if(is_numeric($value['maxvalue']) && is_numeric($value['minvalue'])){
|
||||
if($data['data']['bmi'] >= $value['minvalue'] && $data['data']['bmi'] < $value['maxvalue']){
|
||||
// 在落点内
|
||||
$subsection_val = bcsub($value['maxvalue'],$value['minvalue'],1);//获取最大最小值差
|
||||
$temporary_subsection_val = bcsub($data['data']['bmi'],$value['minvalue'],1);//获取当前值与最小值差
|
||||
$temporary_subsection_val = bcdiv($temporary_subsection_val,$subsection_val,1);//获取当前值与最小值差与最大最小值差之比
|
||||
$subsection_val = bcdiv(100,count($data['data']['bmilevellist']),1);//每段应该的百分比
|
||||
$temporary_subsection_val = bcmul($subsection_val,$temporary_subsection_val,1);//获取当前值与最小值差与最大最小值差之比与总段数之比
|
||||
$temporary_subsection_val = bcadd($temporary_subsection_val,bcmul($subsection_val,$num,1),1);
|
||||
}else{
|
||||
$num = $num + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($temporary_subsection_val === null){
|
||||
if($data['data']['bmi'] >= $data['data']['bmilevellist'][count($data['data']['bmilevellist'])-1]['maxvalue']){
|
||||
$temporary_subsection_val = 100;
|
||||
}else{
|
||||
return $this->msg(99999,'网络异常,请稍后重试7');
|
||||
}
|
||||
}
|
||||
$data['data']['offset'] = $temporary_subsection_val;
|
||||
$data = $data['data'];
|
||||
// 处理key名称一致start
|
||||
foreach ($data['bmilevellist'] as $key => $value) {
|
||||
$data['bmilevellist'][$key]['max_val'] = $value['maxvalue'];
|
||||
$data['bmilevellist'][$key]['min_val'] = $value['minvalue'];
|
||||
unset($data['bmilevellist'][$key]['minvalue']);
|
||||
unset($data['bmilevellist'][$key]['maxvalue']);
|
||||
}
|
||||
// 处理key名称一致end
|
||||
return $this->msg($data);
|
||||
}
|
||||
public function get_user_data_information_action($data){
|
||||
$return_result = [
|
||||
'body_data'=>[],
|
||||
'kcal_data'=>[],
|
||||
'card_data'=>[]
|
||||
];
|
||||
$aud_data = Db::table($this->index_db_name['juese'])->where(['id'=>$data['aud_id']])->find();
|
||||
|
||||
$body_data = Db::table($this->index_db_name['body_data'])->where(['id'=>$data['aud_id']])->find();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,686 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use app\NewReedaw\controller\app\Wechat;// 引入Wechat服务类
|
||||
use app\NewReedaw\controller\app\Smsaliyun;// 引入Wechat服务类
|
||||
|
||||
class Login extends Base{
|
||||
protected $code_time = 55;
|
||||
// protected $token_time = 2592000;//30天的秒数
|
||||
protected $default_head_pic = 'https://tc.pcxbc.com/tsf/head_pic.png';
|
||||
protected $login_use_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
];
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 注册
|
||||
public function register(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
// 验证数据项是否完整
|
||||
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
// 验证数据值是否合规
|
||||
if(!$data['data'] || !$data['password'] || !$data['code']){
|
||||
return $this->msg(10006);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['password'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['code'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
return $this->register_action($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'] .= "方法: " . __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);
|
||||
}
|
||||
|
||||
}
|
||||
// 登录
|
||||
public function login(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
// 验证数据值是否合规
|
||||
if(!$this->verify_data_is_ok($data['data'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['validate_data'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['validate_type'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
return $this->login_action($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'] .= "方法: " . __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);
|
||||
}
|
||||
}
|
||||
// 重置密码
|
||||
public function reset_password(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
// 验证数据项是否完整
|
||||
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
// 验证数据值是否合规
|
||||
if($data['password'] != $data['c_password']){
|
||||
return $this->msg(10003,'新密码与确认密码不一致');
|
||||
}
|
||||
if($data['password'] == ''){
|
||||
return $this->msg(10003,'密码不能为空');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['password'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['code'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
return $this->reset_password_action($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'] .= "方法: " . __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);
|
||||
}
|
||||
|
||||
}
|
||||
// 微信手机号快捷登录
|
||||
public function wechat_quick_login(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('code', $data)){
|
||||
// return $this->msg(10001,'');
|
||||
return $this->msg(10001,'code is miss');
|
||||
}
|
||||
if(!array_key_exists('encryptedData', $data)){
|
||||
return $this->msg(10001,'encryptedData is miss');
|
||||
}
|
||||
if(!array_key_exists('iv', $data)){
|
||||
return $this->msg(10001,'iv is miss');
|
||||
}
|
||||
// 校验参数
|
||||
if (empty($data['code'])) {
|
||||
return $this->msg(10001,'code is miss.');
|
||||
}
|
||||
if (empty($data['encryptedData'])) {
|
||||
return $this->msg(10001,'encryptedData is miss.');
|
||||
}
|
||||
if (empty($data['iv'])) {
|
||||
return $this->msg(10001,'iv is miss.');
|
||||
}
|
||||
|
||||
// 调用Wechat服务类处理微信登录逻辑
|
||||
$wechatService = new Wechat();
|
||||
$result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']);
|
||||
if($result['code'] == 0){
|
||||
$user_data = Db::table($this->login_use_db_name['zhanghao'])->where(['tel'=>$result['data']['phoneNumber']])->fidle('token,id,is_del')->find();
|
||||
if($user_data){
|
||||
if($user_data['is_del'] == 1){
|
||||
return $this->msg(10002,'该账号已注销');
|
||||
}
|
||||
Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$user_data['token']])->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
$return_data = $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
|
||||
}else{
|
||||
$set_data['password'] = '';
|
||||
$set_data['tel'] = $result['data']['phoneNumber'];
|
||||
$set_data['head_pic'] = $this->default_head_pic;
|
||||
$set_data['nickname'] = '用户'.$result['data']['phoneNumber'];
|
||||
$set_data['create_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['login_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['token'] = md5($result['data']['phoneNumber'].$this->create_random_string(12).time());
|
||||
$set_user_result = Db::table($this->login_use_db_name['zhanghao'])->insertGetId($set_data);
|
||||
if($set_user_result){
|
||||
return $this->msg(['token'=>$set_data['token'],'aan_id'=>$set_user_result],'登录成功');
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return $this->msg($result['code'],$result['msg']);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
// 退出登录操作
|
||||
public function quit_account(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->count();
|
||||
if($result <= 0){
|
||||
return $this->msg(10003,'账号不存在');
|
||||
}
|
||||
$quit_result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']);
|
||||
if($quit_result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
|
||||
}
|
||||
// 账号注销
|
||||
public function delete_account(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->count();
|
||||
if($result <= 0){
|
||||
return $this->msg(10003,'账号不存在');
|
||||
}
|
||||
$quit_result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-08-08 00:00:00']);
|
||||
if($quit_result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
// 发送验证码 手机/邮箱
|
||||
/* 接口说明(发邮件)
|
||||
* $data(手机或者邮箱信息) 字符串
|
||||
* $type(验证类型,是注册用,还是其他用途) 字符串 默认register(注册)(register、login、reset_password)
|
||||
* $road(是手机还是邮箱还是其他) 字符串 默认tel或email
|
||||
*/
|
||||
//18736019909
|
||||
public function send_phone_email_code($data = ['data'=>'18736019909']){
|
||||
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('data', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
|
||||
if(cache($data['data'])){
|
||||
return $this->msg(10002,'60秒仅可发送一次验证码');
|
||||
}
|
||||
$num = mt_rand(100000,999999);
|
||||
// 验证是手机还是邮箱
|
||||
$montage_data = $this->is_tel_email($data['data']);
|
||||
if($montage_data == false){
|
||||
return $this->msg(10005,'账号格式错误,不是手机号或者邮箱');
|
||||
}
|
||||
if($montage_data == 'tel'){
|
||||
// 本公司短信
|
||||
// $result = $this->send_tel_code($data['data'],$num);
|
||||
// 阿里云短信
|
||||
$sms_all = new Smsaliyun;
|
||||
$result = $sms_all->send_sms($data['data'],$num);
|
||||
}else{
|
||||
$result = $this->send_email_code([$data['data']],['title'=>'Reedaw验证码','from_user_name'=>'Reedaw验证码','content'=>$num]);
|
||||
}
|
||||
if(is_array($result) && $result['code'] == 0){
|
||||
cache($data['data'], $num, $this->code_time);
|
||||
// return $this->msg(['code'=>$num]);
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10010,'验证码发送失败');
|
||||
}
|
||||
}
|
||||
###############################################################action################################################################
|
||||
###############################################################action################################################################
|
||||
###############################################################action################################################################
|
||||
public function register_action($data){
|
||||
// 验证是手机还是邮箱
|
||||
$montage_data = $this->is_tel_email($data['data']);
|
||||
if($montage_data == false){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
|
||||
// 查询账号是否已经注册
|
||||
$inspect_repeat = Db::table($this->login_use_db_name['zhanghao'])->where([$montage_data=>$data['data']])->count();
|
||||
if($inspect_repeat > 0){
|
||||
return $this->msg(10002,'注册失败,账号已存在');
|
||||
}
|
||||
// 检查验证码
|
||||
$code_result = $this->check_code($data['data'],$data['code']);
|
||||
if($code_result !== true){
|
||||
return $this->msg(10002,$code_result);
|
||||
}
|
||||
// 验证完之后
|
||||
$set_data = [];
|
||||
if($montage_data == 'tel'){
|
||||
$set_data['tel'] = $data['data'];
|
||||
}else{
|
||||
$set_data['email'] = $data['data'];
|
||||
}
|
||||
$set_data['password'] = $data['password'];
|
||||
$set_data['head_pic'] = $this->default_head_pic;
|
||||
$set_data['nickname'] = '用户'.time();
|
||||
$set_data['create_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['login_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
|
||||
$result = Db::table($this->login_use_db_name['zhanghao'])->insertGetId($set_data);
|
||||
if($result){
|
||||
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]);
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
return $return_data;
|
||||
}
|
||||
public function login_action($data){
|
||||
// 检测是否为手机
|
||||
$montage_data = $this->is_tel_email($data['data']);
|
||||
if($montage_data == false){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$verify_result[$montage_data] = $data['data'];
|
||||
// $verify_result['is_del'] = 0;
|
||||
// 检测校验途径
|
||||
if($data['validate_type'] == 'code'){
|
||||
$code_name = $data['data'];
|
||||
if($this->check_code($code_name,$data['validate_data']) === true){
|
||||
$result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token,is_del')->find();
|
||||
if($result){
|
||||
if($result['is_del'] == 1){
|
||||
return $this->msg(10002,'该账号已注销');
|
||||
}
|
||||
Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]);
|
||||
}else{
|
||||
$set_data['password'] = '';
|
||||
$set_data[$montage_data] = $data['data'];
|
||||
$set_data['head_pic'] = $this->default_head_pic;
|
||||
$set_data['nickname'] = '用户'.$data['data'];
|
||||
$set_data['create_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['login_time'] = date('Y-m-d H:i:s');
|
||||
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
|
||||
$result = Db::table($this->login_use_db_name['zhanghao'])->insertGetId($set_data);
|
||||
if($result){
|
||||
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功');
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$return_data = $this->msg(10002,'登录失败,验证码错误或失效');
|
||||
}
|
||||
}else if($data['validate_type'] == 'password'){
|
||||
// $verify_result['password'] = $data['validate_data'];
|
||||
$result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token,password,is_del')->find();
|
||||
if($result){
|
||||
if($result['is_del'] == 1){
|
||||
return $this->msg(10002,'该账号已注销');
|
||||
}
|
||||
if($result['password'] == ''){
|
||||
$return_data = $this->msg(10002,'该账户未设密码,请用验证码登录');
|
||||
}
|
||||
if($data['validate_data'] != $result['password']){
|
||||
$return_data = $this->msg(10002,'账号或密码错误');
|
||||
}else{
|
||||
Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
|
||||
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功');
|
||||
}
|
||||
}else{
|
||||
$return_data = $this->msg(10003,'账号未注册,请先注册');
|
||||
}
|
||||
}else{
|
||||
$return_data = $this->msg(10003,'校验参数错误');
|
||||
}
|
||||
return $return_data;
|
||||
|
||||
}
|
||||
public function reset_password_action($data){
|
||||
// 检查验证码
|
||||
$code_result = $this->check_code($data['data'],$data['code']);
|
||||
if($code_result !== true){
|
||||
return $this->msg(10003,$code_result);
|
||||
}
|
||||
$t_y = $this->is_tel_email($data['data']);
|
||||
if($t_y === false){
|
||||
return $this->msg(10003,'账号格式错误');
|
||||
}
|
||||
// 检查账号是否存在
|
||||
$find_data = Db::table($this->login_use_db_name['zhanghao'])->where([$t_y=>$data['data']])->field('id,token,password')->find();
|
||||
if(!$find_data){
|
||||
return $this->msg(10003,'未核实到账号信息');
|
||||
}
|
||||
if($find_data['password'] == $data['password']){
|
||||
return $this->msg(10002,'新密码不可与旧密码相同');
|
||||
}
|
||||
$result = Db::table($this->login_use_db_name['zhanghao'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]);
|
||||
if($result){
|
||||
$return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]);
|
||||
}else{
|
||||
$return_data = $this->msg(10002);
|
||||
}
|
||||
return $return_data;
|
||||
}
|
||||
// 发送手机短信(本公司接口)
|
||||
public function send_tel_code($tel,$code){
|
||||
// 初始化cURL会话
|
||||
$ch = curl_init();
|
||||
$headers = [
|
||||
'Accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
];
|
||||
// 设置头部信息
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
// 设置请求的URL
|
||||
$url = "http://sms.ybhdmob.com/Message/Send?token=ybhdmob";
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
// 设置为POST请求
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
// 设置POST数据
|
||||
$postData = array(
|
||||
'phone' => $tel,
|
||||
// 'content' => '【巨天】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||
// 'content' => '【郑州品传科技】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||
// 'content' => '【每日一称】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||
'content' => '【小白健康】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||
);
|
||||
$postData = json_encode($postData);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
||||
// 设置返回结果不直接输出,而是返回到变量中
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// 发送请求并获取响应
|
||||
$response = curl_exec($ch);
|
||||
// dump($response);
|
||||
// 检查是否有错误发生
|
||||
if (curl_errno($ch)) {
|
||||
$error_message = curl_error($ch);
|
||||
return "请求错误: " . $error_message;
|
||||
}
|
||||
// 关闭cURL会话
|
||||
curl_close($ch);
|
||||
// 处理响应
|
||||
// dump(json_decode($response,true));
|
||||
if ($response) {
|
||||
return json_decode($response,true);
|
||||
} else {
|
||||
echo "未收到响应";
|
||||
}
|
||||
}
|
||||
// 手机号区分
|
||||
public function getCarrierByPhone($phone) {
|
||||
// 验证手机号格式(11位数字且以1开头)
|
||||
if (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
|
||||
return '无效手机号';
|
||||
}
|
||||
$prefix3 = substr($phone, 0, 3);
|
||||
// 2025年最新3位号段(排除4位号段)
|
||||
$carriers = [
|
||||
'中国移动' => ['134', '135', '136', '137', '138', '139', '150', '151', '152', '157', '158', '159', '178', '182', '183', '184', '187', '188', '195', '197', '198'],
|
||||
'中国联通' => ['130', '131', '132', '155', '156', '166', '175', '176', '185', '186', '196'],
|
||||
'中国电信' => ['133', '153', '173', '177', '180', '181', '189', '190', '191', '193', '199'],
|
||||
'中国广电' => ['192']
|
||||
];
|
||||
foreach ($carriers as $carrier => $segments) {
|
||||
if (in_array($prefix3, $segments)) {
|
||||
return $carrier;
|
||||
}
|
||||
}
|
||||
return '未知运营商';
|
||||
}
|
||||
/* 接口说明(发邮件)
|
||||
* $address(收件人的邮箱地址) 数组 格式: ['460834639@qq.com','460834639@qq.com'.......]
|
||||
* $content(邮件的主题数据信息) 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123']
|
||||
* $annex(附件路径信息) 字符串
|
||||
*/
|
||||
public function send_email_code($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 = '<div style="margin: 0; padding: 0;">
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background: #f3f3f3; min-width: 350px; font-size: 1px; line-height: normal;">
|
||||
<tbody><tr>
|
||||
<td align="center" valign="top">
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="750" class="table750" style="width: 100%; max-width: 750px; min-width: 350px; background: #f3f3f3;">
|
||||
<tbody><tr>
|
||||
<td class="mob_pad" width="25" style="width: 25px; max-width: 25px; min-width: 25px;"> </td>
|
||||
<td align="center" valign="top" style="background: #ffffff;">
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;">
|
||||
<tbody><tr>
|
||||
<td align="right" valign="top">
|
||||
<div class="top_pad" style="height: 25px; line-height: 25px; font-size: 23px;"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
|
||||
<tbody><tr>
|
||||
<td align="left" valign="top">
|
||||
<div style="height: 39px; line-height: 39px; font-size: 37px;"> </div>
|
||||
<font class="mob_title1" face="\'Source Sans Pro\', sans-serif" color="#1a1a1a" style="font-size: 52px; line-height: 55px; font-weight: 300; letter-spacing: -1.5px;">
|
||||
<span class="mob_title1" style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #fb966e; font-size: 48px; line-height: 55px; font-weight: 700; letter-spacing: -1.5px;">Reedaw!</span>
|
||||
</font>
|
||||
<div style="height: 73px; line-height: 73px; font-size: 71px;"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
|
||||
<tbody><tr>
|
||||
<td align="left" valign="top">
|
||||
<div style="height: 33px; line-height: 33px; font-size: 31px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">感谢您选择锐动产品!</span>
|
||||
</font>
|
||||
<div style="height: 33px; line-height: 33px; font-size: 31px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">以下6位数字是邮箱验证码,请在需要的位置填写以通过验证</span>
|
||||
</font>
|
||||
<div style="height: 18px; line-height: 33px; font-size: 31px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #aaaaaa; font-size: 16px; line-height: 32px;">(如果您从未请求发送邮箱验证码,请忽略此邮件)</span>
|
||||
</font>
|
||||
<div style="height: 33px; line-height: 33px; font-size: 31px;"> </div>
|
||||
<table class="mob_btn" cellpadding="0" cellspacing="0" border="0" style="background: #fb966e; border-radius: 4px;">
|
||||
<tbody><tr>
|
||||
<td align="center" valign="top">
|
||||
<span style="display: block; border: 1px solid #fb966e; border-radius: 0px; padding: 6px 12px; font-family: \'Nunito\', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">
|
||||
<font face="\'Nunito\', sans-serif" color="#ffffff" style="font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">
|
||||
<span style="font-family: \'Nunito\', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">'.$content['content'].'</span>
|
||||
</font>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
<div style="height: 75px; line-height: 75px; font-size: 73px;"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;">
|
||||
<tbody><tr>
|
||||
<td align="center" valign="top">
|
||||
<div style="height: 34px; line-height: 34px; font-size: 32px;"> </div>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
|
||||
<tbody><tr>
|
||||
<td align="center" valign="top">
|
||||
<div style="height:12px; line-height: 34px; font-size: 32px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#868686" style="font-size: 17px; line-height: 20px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #868686; font-size: 17px; line-height: 20px;">© Zhengzhou Pinchuan Technology Co., Ltd. </span>
|
||||
</font>
|
||||
<div style="height: 3px; line-height: 3px; font-size: 1px;"> </div>
|
||||
<font face="\'Nunito\', sans-serif" color="#1a1a1a" style="font-size: 17px; line-height: 20px;">
|
||||
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px;"><a target="_blank" style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px; text-decoration: none;" href="https://paoluz.link/"></a></span>
|
||||
</font>
|
||||
<div style="height: 35px; line-height: 35px; font-size: 33px;"> </div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
</td>
|
||||
<td class="mob_pad" width="25" style="width: 25px; max-width: 25px; min-width: 25px;"> </td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
</div>';
|
||||
|
||||
$mail->Body = $neirong; //邮件主体内容
|
||||
//发送
|
||||
if (!$mail->Send()) {
|
||||
|
||||
return ['code' => 10003,'msg'=>$mail->ErrorInfo];
|
||||
// return $mail->ErrorInfo;
|
||||
} else {
|
||||
return ['code' => 0];
|
||||
// return 'success';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
################################################################other################################################################
|
||||
################################################################other################################################################
|
||||
################################################################other################################################################
|
||||
// 检查验证码
|
||||
public function check_code($data = 18530934717 , $code = 123456){
|
||||
// 默认验证码正确start
|
||||
if($code == 88888888){
|
||||
return true;
|
||||
}
|
||||
// 默认验证码正确end
|
||||
if(cache($data) == false){
|
||||
return '验证码过期';
|
||||
}else{
|
||||
if($code != cache($data)){
|
||||
return '验证码错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create_random_string($length = 12)
|
||||
{
|
||||
//创建随机字符
|
||||
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
$str = "";
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,328 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class Role extends Base{
|
||||
|
||||
protected $role_db_name = [
|
||||
'zhanghao'=>'app_account_number',
|
||||
'juese'=>'app_user_data',
|
||||
'quyu_card'=>'admin_estimate'
|
||||
];
|
||||
protected $identity_list = ['P0'=>'陌生人','P1'=>'爸爸','P2'=>'妈妈','P3'=>'大宝','P4'=>'二宝','P5'=>'三宝','P6'=>'四宝','P7'=>'爷爷','P8'=>'奶奶'];
|
||||
protected $grade_list = [
|
||||
['id'=>'nothing','name'=>'无'],
|
||||
['id'=>'grade_s_1','name'=>'小学一年级'],
|
||||
['id'=>'grade_s_2','name'=>'小学二年级'],
|
||||
['id'=>'grade_s_3','name'=>'小学三年级'],
|
||||
['id'=>'grade_s_4','name'=>'小学四年级'],
|
||||
['id'=>'grade_s_5','name'=>'小学五年级'],
|
||||
['id'=>'grade_s_6','name'=>'小学六年级'],
|
||||
['id'=>'grade_m_1','name'=>'初中一年级'],
|
||||
['id'=>'grade_m_2','name'=>'初中二年级'],
|
||||
['id'=>'grade_m_3','name'=>'初中三年级'],
|
||||
['id'=>'grade_h_1','name'=>'高中一年级'],
|
||||
['id'=>'grade_h_2','name'=>'高中二年级'],
|
||||
['id'=>'grade_h_3','name'=>'高中三年级'],
|
||||
['id'=>'grade_u_12','name'=>'大学一、二年级'],
|
||||
['id'=>'grade_u_34','name'=>'大学三、四年级']
|
||||
];
|
||||
protected $grade_list2 = [
|
||||
'nothing' => '无',
|
||||
'grade_s_1' => '小学一年级',
|
||||
'grade_s_2' => '小学二年级',
|
||||
'grade_s_3' => '小学三年级',
|
||||
'grade_s_4' => '小学四年级',
|
||||
'grade_s_5' => '小学五年级',
|
||||
'grade_s_6' => '小学六年级',
|
||||
'grade_m_1' => '初中一年级',
|
||||
'grade_m_2' => '初中二年级',
|
||||
'grade_m_3' => '初中三年级',
|
||||
'grade_h_1' => '高中一年级',
|
||||
'grade_h_2' => '高中二年级',
|
||||
'grade_h_3' => '高中三年级',
|
||||
'grade_u_12' => '大学一、二年级',
|
||||
'grade_u_34' => '大学三、四年级'
|
||||
];
|
||||
// 阶段性称谓
|
||||
protected $stage_appellation = [
|
||||
['min'=>'0','max'=>'3','value'=>'婴儿'],
|
||||
['min'=>'3','max'=>'16','value'=>'儿童'],
|
||||
['min'=>'16','max'=>'500','value'=>'成人']
|
||||
];
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
|
||||
// 添加角色
|
||||
public function add_member(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('measure_model', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if($data['measure_model'] != '1' && $data['measure_model'] != '2'){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||||
return $this->msg(10005,'birthday type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
|
||||
return $this->msg(10005,'gender type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['height'],'num')){
|
||||
return $this->msg(10005,'height type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['weight'],'num')){
|
||||
return $this->msg(10005,'weight type error');
|
||||
}
|
||||
return $this->add_member_action($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 update_member(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('measure_model', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if($data['measure_model'] != '1' && $data['measure_model'] != '2'){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||||
return $this->msg(10005,'birthday type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
|
||||
return $this->msg(10005,'gender type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['height'],'num')){
|
||||
return $this->msg(10005,'height type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['weight'],'num')){
|
||||
return $this->msg(10005,'weight type error');
|
||||
}
|
||||
return $this->update_member_action($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 role_list(){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type error');
|
||||
}
|
||||
return $this->role_list_action($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################################################################
|
||||
################################################################action################################################################
|
||||
public function add_member_action($data){
|
||||
$aan_id = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token')->find();
|
||||
if(!$aan_id){
|
||||
return $this->msg(10002,'账号信息错误');
|
||||
}
|
||||
$parameter['aan_id'] = $aan_id['id'];
|
||||
$parameter['nickname'] = $data['nickname'];
|
||||
$parameter['birthday'] = $data['birthday'];
|
||||
$parameter['gender'] = $data['gender'];
|
||||
$parameter['height'] = $data['height'];
|
||||
$parameter['weight'] = $data['weight'];
|
||||
$parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png';
|
||||
$parameter['card_order'] = '';
|
||||
$parameter['create_time'] = date('Y-m-d H:i:s');
|
||||
$parameter['last_update_time'] = $parameter['create_time'];
|
||||
$parameter['measure_model'] = $data['measure_model'];
|
||||
$is_nickname_ok = Db::table($this->role_db_name['juese'])->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count();
|
||||
if($is_nickname_ok>0){
|
||||
return $this->msg(10002,'该角色已存在');
|
||||
}
|
||||
if($parameter['measure_model'] == 1){
|
||||
if(!array_key_exists('grade',$data) || !array_key_exists('identity_id',$data) || !array_key_exists('address',$data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!array_key_exists($data['identity_id'],$this->identity_list)){
|
||||
return $this->msg(10005,'身份信息错误');
|
||||
}
|
||||
if(!array_key_exists($data['grade'],$this->grade_list2)){
|
||||
return $this->msg(10005,'年级信息错误');
|
||||
}
|
||||
$parameter['grade'] = $data['grade'];
|
||||
$parameter['identity_id'] = $data['identity_id'];
|
||||
$parameter['identity_name'] = $this->identity_list[$data['identity_id']];
|
||||
$parameter['address'] = $data['address'];
|
||||
$address_data = Db::table($this->role_db_name['quyu_card'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find();
|
||||
$parameter['card_order'] = $address_data['recommend_cards'];
|
||||
}else{
|
||||
$parameter['grade'] = 'nothing';
|
||||
$parameter['identity_id'] = 'P0';
|
||||
$parameter['identity_name'] = '陌生人';
|
||||
$parameter['address'] = '';
|
||||
}
|
||||
if($parameter['identity_id'] != 'P0'){
|
||||
$result = Db::table($this->role_db_name['juese'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count();
|
||||
if($result>0){
|
||||
return $this->msg(10005,'该身份已存在');
|
||||
}
|
||||
}
|
||||
$return_result = Db::table($this->role_db_name['juese'])->insert($parameter);
|
||||
if($return_result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
public function update_member_action($data){
|
||||
$aan_id = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token')->find();
|
||||
if(!$aan_id){
|
||||
return $this->msg(10002,'账号信息错误');
|
||||
}
|
||||
// $parameter['aan_id'] = $aan_id['id'];
|
||||
$parameter['nickname'] = $data['nickname'];
|
||||
$parameter['birthday'] = $data['birthday'];
|
||||
$parameter['gender'] = $data['gender'];
|
||||
$parameter['height'] = $data['height'];
|
||||
$parameter['weight'] = $data['weight'];
|
||||
$parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png';
|
||||
$parameter['last_update_time'] = date('Y-m-d H:i:s');
|
||||
$parameter['measure_model'] = $data['measure_model'];
|
||||
if($parameter['measure_model'] == 1){
|
||||
if(!array_key_exists('grade',$data) || !array_key_exists('identity_id',$data) || !array_key_exists('address',$data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!array_key_exists($data['identity_id'],$this->identity_list)){
|
||||
return $this->msg(10005,'身份信息错误');
|
||||
}
|
||||
if(!array_key_exists($data['grade'],$this->grade_list2)){
|
||||
return $this->msg(10005,'年级信息错误');
|
||||
}
|
||||
$parameter['grade'] = $data['grade'];
|
||||
$parameter['identity_id'] = $data['identity_id'];
|
||||
$parameter['identity_name'] = $this->identity_list[$data['identity_id']];
|
||||
$parameter['address'] = $data['address'];
|
||||
if($parameter['identity_id'] != 'P0'){
|
||||
$result = Db::table($this->role_db_name['juese'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$aan_id['id'],'is_del'=>0])->count();
|
||||
if($result>0){
|
||||
return $this->msg(10005,'该身份已存在');
|
||||
}
|
||||
}
|
||||
$address_data = Db::table($this->role_db_name['quyu_card'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find();
|
||||
$parameter['card_order'] = $address_data['recommend_cards'];
|
||||
}
|
||||
|
||||
$return_result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['aud_id']])->update($parameter);
|
||||
if($return_result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
public function role_list_action($data){
|
||||
if(array_key_exists('type', $data)){
|
||||
if(!$this->verify_data_is_ok($data['type'],'intnum')){
|
||||
return $this->msg(10005,'type type error');
|
||||
}
|
||||
}else{
|
||||
$data['type'] = 1;
|
||||
}
|
||||
$user = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token')->find();
|
||||
if(!$user){
|
||||
return $this->msg(10002,'账号信息错误');
|
||||
}
|
||||
$result = Db::table($this->role_db_name['juese'])
|
||||
->where(['aan_id'=>$user['id'],'is_del'=>0])
|
||||
->field('id,aan_id,nickname,birthday,gender,card_order,target_weight,initial_weight,initial_date,grade,head_pic,weight,height,identity_name,address,identity_id,measure_model')
|
||||
->select();
|
||||
$temporary_data = [];
|
||||
if($data['type'] == 1){
|
||||
for ($i=0; $i < count($result); $i++) {
|
||||
array_push($temporary_data,[
|
||||
'id'=>$result[$i]['id'],
|
||||
'nickname'=>$result[$i]['nickname'],
|
||||
'identity_name'=>$result[$i]['identity_name'],
|
||||
'identity_id'=>$result[$i]['identity_id'],
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
for ($i=0; $i < count($result); $i++) {
|
||||
$result[$i]['age'] = $this->calculate_age($result[$i]['birthday']);
|
||||
// 添加阶段称谓、婴儿、儿童、成人
|
||||
foreach ($this->stage_appellation as $key => $value) {
|
||||
if($result[$i]['age'] >= $value['min'] && $result[$i]['age'] < $value['max']){
|
||||
$result[$i]['stage'] = $value['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$temporary_data = $result;
|
||||
}
|
||||
return $this->msg($temporary_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use think\Controller;
|
||||
|
||||
class Smsaliyun extends Controller
|
||||
{
|
||||
|
||||
// 阿里云短信配置
|
||||
private $smsConfig = [
|
||||
'accessKeyId' => 'LTAI5tQCdWe9Epir3ydXWbzp',
|
||||
'accessKeySecret' => 'JKLzF0b5AXw2ajhwtem2fhPSUZVOZ5',
|
||||
'signName' => '郑州巨天信息',
|
||||
// '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, $code)
|
||||
{
|
||||
try {
|
||||
// 初始化阿里云客户端
|
||||
AlibabaCloud::accessKeyClient(
|
||||
$this->smsConfig['accessKeyId'],
|
||||
$this->smsConfig['accessKeySecret']
|
||||
)
|
||||
->regionId($this->smsConfig['regionId'])
|
||||
->asDefaultClient();
|
||||
|
||||
// 发送短信请求
|
||||
$result = AlibabaCloud::rpc()
|
||||
->product('Dysmsapi')
|
||||
->version('2017-05-25')
|
||||
->action('SendSms')
|
||||
->method('POST')
|
||||
->host('dysmsapi.aliyuncs.com')
|
||||
->options([
|
||||
'query' => [
|
||||
'RegionId' => $this->smsConfig['regionId'],
|
||||
'PhoneNumbers' => $phone,
|
||||
'SignName' => $this->smsConfig['signName'],
|
||||
'TemplateCode' => $this->smsConfig['templateCode'],
|
||||
'TemplateParam' => json_encode(['code' => $code]),
|
||||
],
|
||||
])
|
||||
->request();
|
||||
|
||||
$result = $result->toArray();
|
||||
// return $result;
|
||||
if ($result['Code'] == 'OK') {
|
||||
return [
|
||||
'code' => 0,
|
||||
'message' => '短信发送成功',
|
||||
'data' => $result
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'code' => 99999,
|
||||
'message' => $result['Message'],
|
||||
'error' => $result
|
||||
];
|
||||
}
|
||||
} catch (ClientException $e) {
|
||||
return [
|
||||
'code' => 99998,
|
||||
'message' => '客户端异常: ' . $e->getErrorMessage(),
|
||||
'error' => $e->getMessage()
|
||||
];
|
||||
} catch (ServerException $e) {
|
||||
return [
|
||||
'code' => 99997,
|
||||
'message' => '服务端异常: ' . $e->getErrorMessage(),
|
||||
'error' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace app\NewReedaw\controller\app;
|
||||
|
||||
class Wechat extends Base{
|
||||
// reedaw的小程序信息
|
||||
private $app_id = 'wx9c0b7a436ada6d1e'; // 微信小程序的AppID
|
||||
private $app_secret = 'ed7cda5874f0eef3360e782a3db73c80'; // 微信小程序的AppSecret
|
||||
|
||||
// ed7cda5874f0eef3360e782a3db73c80
|
||||
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
/**
|
||||
* 处理微信登录
|
||||
*
|
||||
* @param string $code 微信登录凭证
|
||||
* @param string $encryptedData 加密的用户信息
|
||||
* @param string $iv 解密算法的初始向量
|
||||
* @return array
|
||||
*/
|
||||
public function handleWechatLogin($code, $encryptedData, $iv)
|
||||
{
|
||||
// try {
|
||||
// 1. 通过code获取openid和session_key
|
||||
$sessionData = $this->getSessionKey($code);
|
||||
|
||||
if (empty($sessionData['openid']) || empty($sessionData['session_key'])) {
|
||||
// throw new Exception('获取openid或session_key失败');
|
||||
// return false;
|
||||
// return $this->msg(10001);
|
||||
return ['code'=>10002,'msg'=>'获取openid或session_key失败'];
|
||||
}
|
||||
|
||||
// 2. 解密用户信息
|
||||
$userInfo = $this->decryptData($encryptedData, $iv, $sessionData['session_key']);
|
||||
|
||||
if(array_key_exists('phoneNumber',$userInfo)){
|
||||
return ['code'=>0,'msg'=>'seccess','data'=>$userInfo];
|
||||
}else{
|
||||
return ['code'=>10002,'msg'=>'解密用户信息失败'];
|
||||
}
|
||||
// if (empty($userInfo['phoneNumber'])) {
|
||||
// // throw new Exception('获取手机号失败');
|
||||
|
||||
// }else{
|
||||
|
||||
// }
|
||||
|
||||
// // 3. 保存或更新用户信息
|
||||
// $user = User::where('openid', $sessionData['openid'])->find();
|
||||
// if (!$user) {
|
||||
// $user = new User();
|
||||
// $user->openid = $sessionData['openid'];
|
||||
// }
|
||||
// $user->phone = $userInfo['phoneNumber'];
|
||||
// $user->save();
|
||||
|
||||
// 返回成功信息
|
||||
// return ['code' => 0, 'msg' => '登录成功', 'data' => $user];
|
||||
// } catch (Exception $e) {
|
||||
// // 返回错误信息
|
||||
// return ['code' => 500, 'msg' => $e->getMessage()];
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* 通过code获取openid和session_key
|
||||
*
|
||||
* @param string $code
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getSessionKey($code)
|
||||
{
|
||||
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->app_id}&secret={$this->app_secret}&js_code={$code}&grant_type=authorization_code";
|
||||
$result = file_get_contents($url);
|
||||
$data = json_decode($result, true);
|
||||
|
||||
if (isset($data['openid']) && isset($data['session_key'])) {
|
||||
return $data;
|
||||
} else {
|
||||
return ['code'=>10002,'msg'=>'获取openid或session_key失败'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密用户信息
|
||||
*
|
||||
* @param string $encryptedData
|
||||
* @param string $iv
|
||||
* @param string $sessionKey
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function decryptData($encryptedData, $iv, $sessionKey)
|
||||
{
|
||||
// require_once 'wx_crypt/WXBizDataCrypt.php'; // 引入微信解密类
|
||||
// require_once env('root_path') . 'extend/wx_crypt/WXBizDataCrypt.php';
|
||||
// dump(ROOT_PATH . 'extend\wx_crypt\wxBizDataCrypt.php');
|
||||
require_once ROOT_PATH . 'extend\wx_crypt\wxBizDataCrypt.php';
|
||||
|
||||
$pc = new \WXBizDataCrypt($this->app_id, $sessionKey);
|
||||
$errCode = $pc->decryptData($encryptedData, $iv, $data);
|
||||
|
||||
if ($errCode == 0) {
|
||||
return json_decode($data, true);
|
||||
} else {
|
||||
return ['code'=>10002,'msg'=>'解密用户信息失败('.$errCode.')'];
|
||||
// throw new Exception('解密失败: ' . $errCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 注册
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,407 @@
|
|||
<?php
|
||||
|
||||
namespace app\OutsideInterface\controller\ZhiZhaoTuan;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class ApiJk extends Base
|
||||
{
|
||||
|
||||
|
||||
|
||||
// 智照团保存表单信息
|
||||
// 添加菜谱(OK)
|
||||
// 根据食材详细查找列表(OK)
|
||||
public function activity_list(){
|
||||
// 尝试捕获异常
|
||||
try {
|
||||
$data = input('post.');
|
||||
$return_data = $this->activity_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' => '系统错误']);
|
||||
}
|
||||
}
|
||||
public function details_data(){
|
||||
// 尝试捕获异常
|
||||
try {
|
||||
$data = input('post.');
|
||||
// $data = ['id'=>3];
|
||||
if(!array_key_exists('id', $data)){
|
||||
return $this->msg(10001,'id is miss');
|
||||
}
|
||||
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005,'id type is error');
|
||||
}
|
||||
$return_data = $this->details_data_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' => '系统错误']);
|
||||
}
|
||||
}
|
||||
|
||||
public function save_activity_data(){
|
||||
// 尝试捕获异常
|
||||
try {
|
||||
$data = input('post.');
|
||||
// $data = '{"id":"3","tel":"13915547489","content":[{"name":"姓名","type":"text","placeholder":"请输入姓名","is_must":"true","value":"大力","error":false},{"name":"电话","type":"text","placeholder":"请输入姓名","is_must":"true","value":"15237988596","error":false},{"name":"性别","type":"select","placeholder":"请选择性别","is_must":"true","options":["男","女"],"value":"男","error":false},{"name":"兴趣","type":"checkbox","placeholder":"请选择兴趣","is_must":"true","options":["跳舞","跳操","跳绳","跳远","跳高"],"value":["跳舞","跳远"],"error":false},{"name":"其他","type":"textarea","placeholder":"","is_must":"false","value":"哈","error":false}],"appid":"wxbbddd1888da43ab0","sessionid":"opv6R67fwcnu7-Rrts_ijylHQLCc"}';
|
||||
// dump($data);
|
||||
// // dump(json_decode($data,true));
|
||||
// die;
|
||||
// $data = json_decode($data,true);
|
||||
if(!array_key_exists('id', $data)){
|
||||
return $this->msg(10001,'id is miss');
|
||||
}
|
||||
if(!array_key_exists('tel', $data)){
|
||||
return $this->msg(10001,'tel is miss');
|
||||
}
|
||||
if(!array_key_exists('content', $data)){
|
||||
return $this->msg(10001,'content is miss');
|
||||
}
|
||||
|
||||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||||
return $this->msg(10005,'id type is error');
|
||||
}
|
||||
// if(!$this->verify_data_is_ok($data['tel'],'intnum')){
|
||||
// return $this->msg(10005,'id type is error');
|
||||
// }
|
||||
$return_data = $this->save_activity_data_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' => '系统错误']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
###########################################################################################################################################################
|
||||
###########################################################################################################################################################
|
||||
###########################################################################################################################################################
|
||||
|
||||
|
||||
public function activity_list_action($data){
|
||||
$page_now = array_key_exists('page',$data)?$data['page']:1;
|
||||
$page_total = $page_now;
|
||||
$page_num = 20;
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
$content_num = $zzt_db->table('pc_activity_registration')
|
||||
->where("is_del = 0")
|
||||
->count(); // 然后获取结果
|
||||
// dump($content_num);
|
||||
$page_total = ceil($content_num/$page_num);
|
||||
|
||||
$content_list = $zzt_db->table('pc_activity_registration')
|
||||
->alias('a')
|
||||
->join('pc_pic_manage b','a.pic = b.id','LEFT')
|
||||
->where("a.is_del = 0")
|
||||
->field('a.id,a.title,a.people_num,a.start_time,a.end_time,b.url_data')
|
||||
->page("$page_now,$page_num")
|
||||
->select();
|
||||
|
||||
return $this->msg([
|
||||
'page_now'=>$page_now,
|
||||
'page_total'=>$page_total,
|
||||
'content_list'=>$content_list
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function details_data_action($data){
|
||||
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
$result = $zzt_db->table('pc_activity_registration')
|
||||
->alias('a')
|
||||
->join('pc_pic_manage b','a.pic = b.id','LEFT')
|
||||
->where(["a.id"=>$data['id']])
|
||||
->field('a.id,a.title,a.people_num,a.people_num_now,a.start_time,a.end_time,a.text_content,a.form_content,b.url_data as pic')
|
||||
->find(); // 然后获取结果
|
||||
// dump($result);
|
||||
|
||||
if($result){
|
||||
$result['status'] = 1;
|
||||
// $people_num = $zzt_db->table('pc_activity_registration_log')
|
||||
// ->where(["par_id"=>$data['id']])
|
||||
// ->count();
|
||||
|
||||
if(date('Y-m-d H:i:s') >= $result['end_time']){
|
||||
$result['status'] = 0;
|
||||
}
|
||||
if($result['people_num_now']>=$result['people_num']){
|
||||
$result['status'] = 0;
|
||||
}
|
||||
$result['form_content'] = json_decode($result['form_content'],true);
|
||||
foreach ($result['form_content'] as $key => $value) {
|
||||
if($value['type'] == 'checkbox'){
|
||||
$result['form_content'][$key]['value'] = [];
|
||||
}else{
|
||||
$result['form_content'][$key]['value'] = "";
|
||||
}
|
||||
}
|
||||
unset($result['people_num_now']);
|
||||
return $this->msg($result);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
|
||||
public function save_activity_data_action($data){
|
||||
|
||||
// $zzt_db = Db::connect('zzt_db');
|
||||
|
||||
// $result = $zzt_db->table('pc_activity_registration')
|
||||
// ->where(["id"=>$data['id']])
|
||||
// ->field('id,people_num,people_num_now,start_time,end_time,form_content')
|
||||
// ->find(); // 然后获取结果
|
||||
// $result['form_content'] = json_decode($result['form_content'],true);
|
||||
// dump($result);
|
||||
// dump($data);
|
||||
// die;
|
||||
// if(!$result){
|
||||
// return $this->msg(10004);
|
||||
// }
|
||||
// if(date('Y-m-d H:i:s') < $result['start_time']){
|
||||
// return $this->msg(10002,'活动还未开始');
|
||||
// }
|
||||
// if(date('Y-m-d H:i:s') > $result['end_time']){
|
||||
// return $this->msg(10002,'活动已经结束');
|
||||
// }
|
||||
// if($result['people_num_now']>=$result['people_num']){
|
||||
// return $this->msg(10002,'名额已报满');
|
||||
// }
|
||||
// $people_log = $zzt_db->table('pc_activity_registration_log')
|
||||
// ->where(["par_id"=>$data['id'],'tel'=>$data['tel']])
|
||||
// ->count(); // 然后获取结果
|
||||
// if($people_log>=1){
|
||||
// return $this->msg(10002,'您已经提交过,请勿重复提交');
|
||||
// }
|
||||
|
||||
// dump();
|
||||
// die;
|
||||
|
||||
if($data['tel'] == ''){
|
||||
$data['tel'] = time();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
|
||||
try {
|
||||
// 开启事务
|
||||
$zzt_db->startTrans();
|
||||
|
||||
// 查询活动基础信息(使用WITH(UPDLOCK)加锁)
|
||||
$result = $zzt_db->table('pc_activity_registration WITH(UPDLOCK)')
|
||||
->where(["id" => $data['id']])
|
||||
->field('id,people_num,people_num_now,start_time,end_time,form_content,is_only_once')
|
||||
->find();
|
||||
|
||||
if (!$result) {
|
||||
return $this->msg(10004);
|
||||
}
|
||||
|
||||
$result['form_content'] = json_decode($result['form_content'], true);
|
||||
|
||||
// 检查活动时间
|
||||
$currentTime = date('Y-m-d H:i:s');
|
||||
if ($currentTime < $result['start_time']) {
|
||||
$zzt_db->rollback();
|
||||
return $this->msg(10002, '活动还未开始');
|
||||
}
|
||||
if ($currentTime > $result['end_time']) {
|
||||
$zzt_db->rollback();
|
||||
return $this->msg(10002, '活动已经结束');
|
||||
}
|
||||
|
||||
// 检查是否可以重复报名
|
||||
if($result['is_only_once'] == 0){ //如果是0不可重复提交
|
||||
$people_log = $zzt_db->table('pc_activity_registration_log')
|
||||
->where(["par_id" => $data['id'], 'tel' => $data['tel']])
|
||||
->count();
|
||||
|
||||
if ($people_log >= 1) {
|
||||
$zzt_db->rollback();
|
||||
return $this->msg(10002, '您已经提交过,请勿重复提交');
|
||||
}
|
||||
}
|
||||
// 检查名额
|
||||
if ($result['people_num_now'] >= $result['people_num']) {
|
||||
$zzt_db->rollback();
|
||||
return $this->msg(10002, '名额已报满');
|
||||
}
|
||||
|
||||
// 更新当前人数(SQL Server 语法)
|
||||
$updateResult = $zzt_db->table('pc_activity_registration')
|
||||
->where(["id" => $data['id']])
|
||||
->update([
|
||||
"people_num_now" => $zzt_db->raw('people_num_now + 1')
|
||||
]);
|
||||
|
||||
// 插入报名记录
|
||||
$insertData = [
|
||||
'par_id' => $data['id'],
|
||||
'tel' => $data['tel'],
|
||||
'content' => [],
|
||||
'create_time' => $currentTime
|
||||
];
|
||||
|
||||
$tm_data = [];
|
||||
foreach ($data['content'] as $key => $value) {
|
||||
if($value['type'] == 'checkbox'){
|
||||
$tm_data[$value['name']] = implode('CH1',$value['value']);
|
||||
}else{
|
||||
$tm_data[$value['name']] = $value['value'];
|
||||
}
|
||||
}
|
||||
|
||||
// 调试点1:检查数据结构
|
||||
// dump($tm_data);
|
||||
// dump($result['form_content']);
|
||||
|
||||
foreach ($result['form_content'] as $key => $value) {
|
||||
|
||||
if($value['is_must'] == 'true'){// 如果是必填的
|
||||
if(array_key_exists($value['name'],$tm_data)){// 如果包含选项
|
||||
// 这里可能有问题:$tm_data[$value['name']] 可能是字符串,不是数组
|
||||
if(isset($tm_data[$value['name']]) && $tm_data[$value['name']] != ''){// 如果选项有值
|
||||
$insertData['content'][] = ['name'=>$value['name'],'type'=>$value['type'],'value'=>$tm_data[$value['name']]];
|
||||
}else{
|
||||
$zzt_db->rollback();
|
||||
return $this->msg(10002, '必填项目未填('.$value['name'].')');
|
||||
}
|
||||
}else{
|
||||
$zzt_db->rollback();
|
||||
return $this->msg(10002, '项目缺失('.$value['name'].')');
|
||||
}
|
||||
|
||||
}else{
|
||||
if(array_key_exists($value['name'],$tm_data)){// 如果包含选项
|
||||
// 这里可能有问题:$tm_data[$value['name']] 可能是字符串,不是数组
|
||||
if(isset($tm_data[$value['name']]) && $tm_data[$value['name']] != ''){// 如果选项有值
|
||||
$insertData['content'][] = ['name'=>$value['name'],'type'=>$value['type'],'value'=>$tm_data[$value['name']]];
|
||||
}else{
|
||||
$insertData['content'][] = ['name'=>$value['name'],'type'=>$value['type'],'value'=>""];
|
||||
}
|
||||
}else{
|
||||
$insertData['content'][] = ['name'=>$value['name'],'type'=>$value['type'],'value'=>""];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 调试点2:检查最终的插入数据
|
||||
// dump($insertData);
|
||||
$insertData['content'] = json_encode($insertData['content']);
|
||||
// 检测表单内容是否重复
|
||||
$people_log2 = $zzt_db->table('pc_activity_registration_log')
|
||||
->where(["content" => $insertData['content']])
|
||||
->count();
|
||||
|
||||
if ($people_log2 >= 1) {
|
||||
$zzt_db->rollback();
|
||||
return $this->msg(10002, '该表单内容已经提交过,请勿重复提交');
|
||||
}
|
||||
|
||||
$insertResult = $zzt_db->table('pc_activity_registration_log')
|
||||
->insert($insertData);
|
||||
|
||||
if ($insertResult) {
|
||||
$zzt_db->commit();
|
||||
return $this->msg([]);
|
||||
} else {
|
||||
$zzt_db->rollback();
|
||||
return $this->msg(10002, '报名失败');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$zzt_db->rollback();
|
||||
|
||||
// // 输出详细错误信息到日志
|
||||
// \think\Log::error('报名系统错误:' . $e->getMessage());
|
||||
// \think\Log::error('错误文件:' . $e->getFile() . ' 行号:' . $e->getLine());
|
||||
// \think\Log::error('错误追踪:' . $e->getTraceAsString());
|
||||
|
||||
// // 如果是开发环境,直接显示错误详情
|
||||
// if (config('app_debug')) {
|
||||
// return $this->msg(10002, '系统错误:' . $e->getMessage() . ' 在文件:' . $e->getFile() . ' 第' . $e->getLine() . '行');
|
||||
// }
|
||||
|
||||
return $this->msg(10002, '系统繁忙,请重试');
|
||||
}
|
||||
|
||||
// foreach ($variable as $key => $value) {
|
||||
// # code...
|
||||
// }
|
||||
// $data = [
|
||||
// "id"=>1,
|
||||
// "tel"=>15588668888,
|
||||
// "content"=>[
|
||||
// [
|
||||
// 'name'=>'姓名',
|
||||
// 'type'=>'text',
|
||||
// 'value'=>'Jerry',
|
||||
// ],
|
||||
// [
|
||||
// 'name'=>'备注',
|
||||
// 'type'=>'textarea',
|
||||
// 'value'=>'xxxxxxxxxxxxxxxxxxxxxxx',
|
||||
// ],
|
||||
// [
|
||||
// 'name'=>'性别',
|
||||
// 'type'=>'select',
|
||||
// 'value'=>'男',
|
||||
// ],
|
||||
// [
|
||||
// 'name'=>'兴趣',
|
||||
// 'type'=>'checkbox',
|
||||
// 'value'=>['选项1','选项2','选项3'],
|
||||
// ],
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// return $this->msg($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
|
||||
namespace app\OutsideInterface\controller\ZhiZhaoTuan;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class Base extends Controller{
|
||||
|
||||
protected $base_use_db_name = [
|
||||
'1'=>'test_app_data_log',
|
||||
];
|
||||
protected $return_data_all = [
|
||||
'10001'=>'关键参数缺失',
|
||||
'10002'=>'操作失败',
|
||||
'10003'=>'信息核实错误',
|
||||
'10004'=>'未找到有效数据',
|
||||
'10005'=>'参数格式错误',
|
||||
'10006'=>'参数不能为空',
|
||||
'10007'=>'参数错误',
|
||||
'10008'=>'',
|
||||
'10009'=>'',
|
||||
'10010'=>'自定义信息',
|
||||
'20001'=>'登录失效',
|
||||
'99999'=>'网络异常,请稍后重试',
|
||||
];
|
||||
protected $file_size = 1024*1024*10;//10M
|
||||
// 加 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'){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
####################################################图片选择上传start##############################################################
|
||||
public function pic_upload($page = 1) {
|
||||
$data = input();
|
||||
$pd = true;
|
||||
if(array_key_exists('page',$data)){
|
||||
$page = $data['page'];
|
||||
$pd = false;
|
||||
}
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
|
||||
$num = $zzt_db->table('pc_pic_manage')->count();
|
||||
$result = $zzt_db->table('pc_pic_manage')->order('id desc')->page($page,20)->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(){
|
||||
// $file1 = request()->file('file');
|
||||
$file = request()->file('cover_image');
|
||||
if($file){
|
||||
$name = $file->getInfo()['name'];
|
||||
// 使用 pathinfo() 函数获取文件名的扩展名
|
||||
$pathinfo = pathinfo($name);
|
||||
$extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
|
||||
$file_name = $pathinfo['filename'];
|
||||
// 判断扩展名是否不是 .png 或 .gif
|
||||
if ($extension !== 'png' && $extension !== 'gif') {
|
||||
// 修改文件名,将扩展名改为 .jpg
|
||||
$new_filename = date('YmdHis').$file_name . '.jpg';
|
||||
} else {
|
||||
$new_filename = date('YmdHis').$name;
|
||||
}
|
||||
$info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'outside_interface' . DS . 'zzt',$new_filename);
|
||||
if($info){
|
||||
$insert_data = [
|
||||
'url_data'=>"https://tc.pcxbc.com/outside_interface/zzt/".$new_filename,
|
||||
'name'=>$new_filename,
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
];
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
$pic_result = $zzt_db->table('pc_pic_manage')->insertGetId($insert_data);
|
||||
if($pic_result){
|
||||
return $this->msg(['url'=>$insert_data['url_data'],'id'=>$pic_result]);
|
||||
}else{
|
||||
return $this->msg(10002,'图片数据保存失败');
|
||||
}
|
||||
}else{
|
||||
return $this->msg(10002,'图片上传失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
####################################################图片选择上传end##############################################################
|
||||
|
||||
####################################################富文本编辑器内start##############################################################
|
||||
// 上传图片动作
|
||||
public function upload_pic_action(){
|
||||
// $file1 = request()->file('file');
|
||||
$file = request()->file('wangeditor-uploaded-image');
|
||||
|
||||
if($file){
|
||||
$name = $file->getInfo()['name'];
|
||||
// 使用 pathinfo() 函数获取文件名的扩展名
|
||||
$pathinfo = pathinfo($name);
|
||||
$extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
|
||||
// 判断扩展名是否不是 .png 或 .gif
|
||||
if ($extension !== 'png' && $extension !== 'gif') {
|
||||
// 修改文件名,将扩展名改为 .jpg
|
||||
$new_filename = time().$pathinfo['filename'] . '.jpg';
|
||||
} else {
|
||||
$new_filename = time().$name;
|
||||
}
|
||||
$info = $file->move(ROOT_PATH . 'public' . DS . 'outside_interface' . DS . 'zzt' . DS . 'wangeditor' . DS . 'pic',$new_filename);
|
||||
if($info){
|
||||
$return_data = [
|
||||
'errno'=>0,
|
||||
'data'=>[
|
||||
'url'=>'https://tc.pcxbc.com/outside_interface/zzt/wangeditor/pic/'.$new_filename,
|
||||
]
|
||||
];
|
||||
return json($return_data);
|
||||
}else{
|
||||
// 上传失败获取错误信息
|
||||
// echo $file->getError();
|
||||
$return_data = [
|
||||
'errno'=>9999,
|
||||
'message'=>$file->getError()
|
||||
];
|
||||
return json($return_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 上传视频动作
|
||||
public function upload_video_action(){
|
||||
// $file1 = request()->file('file');
|
||||
$file = request()->file('wangeditor-uploaded-video');
|
||||
// dump($file);
|
||||
// die;
|
||||
if($file){
|
||||
$name = time().$file->getInfo()['name'];
|
||||
$info = $file->move(ROOT_PATH . 'public' . DS . 'outside_interface' . DS . 'zzt' . DS . 'wangeditor' . DS . 'video',$name);
|
||||
if($info){
|
||||
$return_data = [
|
||||
'errno'=>0,
|
||||
'data'=>[
|
||||
'url'=>'https://tc.pcxbc.com/outside_interface/zzt/wangeditor/video/'.$name,
|
||||
]
|
||||
];
|
||||
return json($return_data);
|
||||
}else{
|
||||
// 上传失败获取错误信息
|
||||
// echo $file->getError();
|
||||
$return_data = [
|
||||
'errno'=>9999,
|
||||
'message'=>$file->getError()
|
||||
];
|
||||
return json($return_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
####################################################富文本编辑器内end##############################################################
|
||||
|
||||
|
||||
|
||||
|
||||
#################################################################其他#################################################################
|
||||
public function msg($data,$str='',$result = []){
|
||||
if(is_array($data)){
|
||||
if($str != ''){
|
||||
return json(['code'=>0,'msg'=>$str,'data'=>$data]);
|
||||
}else{
|
||||
return json(['code'=>0,'msg'=>'操作成功','data'=>$data]);
|
||||
}
|
||||
}else{
|
||||
if($str != ''){
|
||||
return json(['code'=>$data,'msg'=>$str,'data'=>$result]);
|
||||
}
|
||||
return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,242 @@
|
|||
<?php
|
||||
|
||||
namespace app\OutsideInterface\controller\ZhiZhaoTuan;
|
||||
|
||||
use think\Db;
|
||||
use Picqer\Barcode\BarcodeGeneratorPNG;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use Endroid\QrCode\Writer\PngWriter;
|
||||
|
||||
class Index extends Base
|
||||
{
|
||||
protected $page_num = 20;
|
||||
|
||||
|
||||
// 智照团表单列表
|
||||
public function index($page=1)
|
||||
{
|
||||
$data = input();
|
||||
$pd = true;
|
||||
$parameter = [];
|
||||
if(array_key_exists('tt', $data)){
|
||||
$page = $data['page_num'];
|
||||
unset($data['page_num']);
|
||||
unset($data['tt']);
|
||||
$pd = false;
|
||||
}
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
|
||||
$num = $zzt_db->table('pc_activity_registration')->where($parameter)->count();
|
||||
$result = $zzt_db->table('pc_activity_registration')->where($parameter)->order('id desc')->page($page,$this->page_num)->field('id,title,people_num,people_num_now,pic,is_del,start_time,end_time,create_time')->select();
|
||||
|
||||
if(!$pd){
|
||||
$result['num'] = $num;
|
||||
$result['data'] = $result;
|
||||
return $this->msg($result);
|
||||
}
|
||||
$this->assign([
|
||||
'result' => $result,
|
||||
'num' => $num,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
public function del_action()
|
||||
{
|
||||
$data = input('post.');
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
$result = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->update(['is_del'=>$data['is_del']]);
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 智照团添加表单
|
||||
public function add_form2()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
// 智照团添加表单
|
||||
public function add_form_action()
|
||||
{
|
||||
$data = input('post.');
|
||||
|
||||
// dump($data);
|
||||
// die;
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
$result = $zzt_db->table('pc_activity_registration')->insert([
|
||||
'title'=>$data['title'],
|
||||
'people_num'=>$data['people_num'],
|
||||
'start_time'=>$data['s_time'],
|
||||
'end_time'=>$data['e_time'],
|
||||
'text_content'=>$data['content'],
|
||||
'form_content'=>json_encode($data['form_data']),
|
||||
'pic'=>$data['cover_image'],
|
||||
'is_only_once'=>$data['is_only_once'],
|
||||
'create_time'=>date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 智照团修改表单
|
||||
public function edit_form()
|
||||
{
|
||||
$data = input();
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
$result = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,title,people_num,start_time,end_time,text_content,form_content,pic,is_only_once')->find();
|
||||
$pic = $zzt_db->table('pc_pic_manage')->where(['id'=>$result['pic']])->field('id,url_data')->find();
|
||||
$result['pic_url'] = $pic['url_data'];
|
||||
// dump($result);
|
||||
// die;
|
||||
$this->assign([
|
||||
'result' => $result,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
// 智照团修改表单
|
||||
public function edit_form_action()
|
||||
{
|
||||
$data = input('post.');
|
||||
|
||||
// dump($data);
|
||||
// die;
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
|
||||
$people_num = $zzt_db->table('pc_activity_registration_log')->where(['par_id'=>$data['id']])->count();
|
||||
if($people_num>0){
|
||||
$yz_data = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,form_content,people_num')->find();
|
||||
if($yz_data['form_content'] != json_encode($data['form_data'])){
|
||||
return $this->msg(10002,'已有人报名,不可修改表单项目');
|
||||
}
|
||||
if($yz_data['people_num'] > $data['people_num']){
|
||||
return $this->msg(10002,'已有人报名,请不要缩减报名人数');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = $zzt_db->table('pc_activity_registration')
|
||||
->where(['id'=>$data['id']])
|
||||
->update([
|
||||
'title'=>$data['title'],
|
||||
'people_num'=>$data['people_num'],
|
||||
'start_time'=>$data['s_time'],
|
||||
'end_time'=>$data['e_time'],
|
||||
'text_content'=>$data['content'],
|
||||
'form_content'=>json_encode($data['form_data']),
|
||||
'pic'=>$data['cover_image'],
|
||||
'is_only_once'=>$data['is_only_once'],
|
||||
]);
|
||||
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 下载报名人员
|
||||
|
||||
public function down_data_action(){
|
||||
$data = input();
|
||||
$zzt_db = Db::connect('zzt_db');
|
||||
|
||||
$down_data = $zzt_db->table('pc_activity_registration_log')->where(['par_id'=>$data['id']])->select();
|
||||
$activity_registration_data = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,title,form_content')->find();
|
||||
|
||||
if($activity_registration_data){
|
||||
$activity_registration_data['form_content'] = json_decode($activity_registration_data['form_content'],true);
|
||||
}else{
|
||||
return $this->msg(10002,'未找到对应活动');
|
||||
}
|
||||
$config = $activity_registration_data;
|
||||
// 构建表头
|
||||
$header = ['序号', '会员电话'];
|
||||
|
||||
// 添加表单字段名称到表头
|
||||
foreach ($config['form_content'] as $field) {
|
||||
$header[] = $field['name'];
|
||||
}
|
||||
|
||||
if(count($down_data) > 0){
|
||||
foreach ($down_data as $key => $value) {
|
||||
$down_data[$key]['content'] = json_decode($value['content'],true);
|
||||
}
|
||||
$userData = $down_data;
|
||||
|
||||
|
||||
// 初始化结果数组
|
||||
$result = [];
|
||||
$result[] = $header;
|
||||
|
||||
// 处理每条用户数据
|
||||
foreach ($userData as $index => $user) {
|
||||
$row = [];
|
||||
|
||||
// 序号(使用数组索引+1,或者用用户数据中的id)
|
||||
$row[] = $index + 1;
|
||||
|
||||
// 会员电话处理:如果不是手机号格式,显示"非会员用户"
|
||||
$tel = $user['tel'];
|
||||
if (!preg_match('/^1[3-9]\d{9}$/', $tel)) {
|
||||
$row[] = "非会员用户";
|
||||
} else {
|
||||
$row[] = $tel;
|
||||
}
|
||||
|
||||
// 处理每个表单字段的值
|
||||
foreach ($config['form_content'] as $configField) {
|
||||
$fieldName = $configField['name'];
|
||||
$fieldType = $configField['type'];
|
||||
$fieldValue = '';
|
||||
|
||||
// 在用户数据中查找对应的字段值
|
||||
foreach ($user['content'] as $userField) {
|
||||
if ($userField['name'] === $fieldName) {
|
||||
$fieldValue = $userField['value'];
|
||||
|
||||
// 如果是checkbox类型,替换"CH1"为逗号
|
||||
if ($fieldType === 'checkbox') {
|
||||
$fieldValue = str_replace('CH1', ',', $fieldValue);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$row[] = $fieldValue;
|
||||
}
|
||||
|
||||
$result[] = $row;
|
||||
}
|
||||
}else{
|
||||
// 初始化结果数组
|
||||
$result = [];
|
||||
$result[] = $header;
|
||||
}
|
||||
$excel = new \app\download\controller\Excel();
|
||||
$excel->export($result, $activity_registration_data['title']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
|
||||
namespace app\ZengJieCode\controller\app;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Log;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class Base extends Controller{
|
||||
|
||||
protected $return_data_all = [
|
||||
'10001'=>'关键参数缺失',
|
||||
'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 == 'num&letter'){
|
||||
if (preg_match('/^[a-zA-Z0-9]+$/', $data)) {
|
||||
return true;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,420 @@
|
|||
<?php
|
||||
|
||||
namespace app\ZengJieCode\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
|
||||
class Savemsg extends Base{
|
||||
|
||||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||||
protected $max_box_num = 10;
|
||||
protected $name_list = [
|
||||
[
|
||||
'name'=>'LS-2502',
|
||||
'character_uuid'=>'2A25',
|
||||
'service_uuid'=>'180A'
|
||||
],
|
||||
|
||||
];
|
||||
protected $name_default = 0;
|
||||
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
################################################################百度接口################################################################
|
||||
################################################################百度接口################################################################
|
||||
################################################################百度接口################################################################
|
||||
|
||||
// 获取配置信息
|
||||
public function config_msg(){
|
||||
try {
|
||||
$result = $this->config_msg_action();
|
||||
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($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function save_sn_msg($data = ['sn_code'=>'564654564654654','mac_code'=>'ce:sh:yo:ng:d1','bl_name'=>'bl_5520']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('sn_code', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!array_key_exists('bl_name', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!array_key_exists('mac_code', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['sn_code'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['bl_name'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['mac_code'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$result = $this->save_sn_msg_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($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function save_box_msg($data = ['sn_code_all'=>'564654564654654,564654564654654','box_serial_number'=>'996589585']){
|
||||
|
||||
// try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('sn_code_all', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!array_key_exists('box_serial_number', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['sn_code_all'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['box_serial_number'],'num&letter')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$result = $this->save_box_msg_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($data, $logContent, null);
|
||||
// return $this->msg(99999);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public function print_again($data = ['code'=>'564654564654654','type'=>'sn']){
|
||||
try {
|
||||
// 你的业务逻辑
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('code', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!array_key_exists('type', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['code'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['type'],'str')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
|
||||
$result = $this->print_again_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($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
########################################################################action########################################################################
|
||||
########################################################################action########################################################################
|
||||
########################################################################action########################################################################
|
||||
|
||||
public function config_msg_action(){
|
||||
// $length = strlen("0065601800007037");
|
||||
// // 生成200个随机数字字符串
|
||||
// $randomStrings = [];
|
||||
// for ($i = 0; $i < 200; $i++) {
|
||||
// $randomString = '';
|
||||
// for ($j = 0; $j < $length; $j++) {
|
||||
// $randomString .= rand(0, 9); // 生成0-9的随机数字
|
||||
// }
|
||||
// $randomStrings[] = [
|
||||
// 'bluetooth_name'=>'bl_5520',
|
||||
// 'sn_code'=>$randomString,
|
||||
// 'create_time'=>date('Y-m-d H:i:s'),
|
||||
// ];
|
||||
// }
|
||||
// $zengjie = Db::connect('zengjie_db');
|
||||
// $result = $zengjie->table('sn_code_all')->insertAll($randomStrings);
|
||||
// dump($result);
|
||||
// die;
|
||||
$data = [
|
||||
'max_box_num'=>$this->max_box_num,
|
||||
'name_list'=>$this->name_list,
|
||||
'name_default_key'=>$this->name_default,
|
||||
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function save_sn_msg_action($data){
|
||||
$data = $this->chuli_str_kongbai($data);
|
||||
$zengjie = Db::connect('zengjie_db');
|
||||
$sn_code = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['sn_code']])->count();
|
||||
if($sn_code > 0){
|
||||
return $this->msg(10002,'该码已录入');
|
||||
}
|
||||
|
||||
$result = $zengjie->table('sn_code_all')->insert([
|
||||
'sn_code'=>$data['sn_code'],
|
||||
'bluetooth_name'=>$data['bl_name'],
|
||||
'mac_code'=>$data['mac_code'],
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
]);
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002,'录入失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function save_box_msg_action($data) {
|
||||
$data = $this->chuli_str_kongbai($data);
|
||||
$zengjie = Db::connect('zengjie_db');
|
||||
|
||||
// 1. 检查sn_code_all中是否有重复数据
|
||||
$snCodes = explode(',', $data['sn_code_all']);
|
||||
$snCodes = $this->chuli_str_kongbai($snCodes);
|
||||
if (count($snCodes) !== count(array_unique($snCodes))) {
|
||||
return $this->msg(10003, 'SN码列表中存在重复数据');
|
||||
}
|
||||
|
||||
// 2. 检查这些SN码是否都存在于sn_code_all表中
|
||||
$existCount = $zengjie->table('sn_code_all')
|
||||
->where('sn_code', 'in', $snCodes)
|
||||
->count();
|
||||
|
||||
if ($existCount !== count($snCodes)) {
|
||||
return $this->msg(10004, '存在未登记的SN码');
|
||||
}
|
||||
Db::startTrans();
|
||||
try{
|
||||
$count = $zengjie->table('box_code_all')
|
||||
->where(['box_code'=>$data['box_serial_number']])
|
||||
->count();
|
||||
$num = $count + 1;
|
||||
|
||||
$box_id = $zengjie->table('box_code_all')->insertGetId([
|
||||
'box_code' => $data['box_serial_number'],
|
||||
'box_num' => $num,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'content_str' => json_encode($snCodes)
|
||||
]);
|
||||
|
||||
$affectedRows = $zengjie->table('sn_code_all')
|
||||
->where('sn_code', 'in', $snCodes)
|
||||
->update(['batch_id' => $box_id]);
|
||||
|
||||
// 检查更新是否影响了预期的行数
|
||||
if ($affectedRows !== count($snCodes)) {
|
||||
throw new \Exception('更新SN码数量错误,请刷新小程序后重新录入');
|
||||
}
|
||||
Db::commit();
|
||||
return $this->msg(['id'=>$box_id]);
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $this->msg(10002, '录入失败: ' . $e->getMessage());
|
||||
}
|
||||
// // 显式事务控制
|
||||
// $zengjie->startTrans();
|
||||
// try {
|
||||
// $count = $zengjie->table('box_code_all')
|
||||
// ->where(['box_code'=>$data['box_serial_number']])
|
||||
// ->count();
|
||||
// $num = $count + 1;
|
||||
|
||||
// $box_id = $zengjie->table('box_code_all')->insertGetId([
|
||||
// 'box_code' => $data['box_serial_number'],
|
||||
// 'box_num' => $num,
|
||||
// 'create_time' => date('Y-m-d H:i:s'),
|
||||
// 'content_str' => $data['sn_code_all'],
|
||||
// ]);
|
||||
|
||||
// $affectedRows = $zengjie->table('sn_code_all')
|
||||
// ->where('sn_code', 'in', $snCodes)
|
||||
// ->update(['batch_id' => $box_id]);
|
||||
|
||||
// // 检查更新是否影响了预期的行数
|
||||
// if ($affectedRows !== count($snCodes)) {
|
||||
// throw new \Exception('更新SN码数量不匹配');
|
||||
// }
|
||||
|
||||
// $zengjie->commit();
|
||||
// return $this->msg(['id'=>$box_id]);
|
||||
// } catch (\Exception $e) {
|
||||
// if ($zengjie->getPdo()->inTransaction()) {
|
||||
// $zengjie->rollback();
|
||||
// }
|
||||
// trace('保存盒信息失败: ' . $e->getMessage(), 'error');
|
||||
// return $this->msg(10002, '录入失败: ' . $e->getMessage());
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
public function print_again_action($data){
|
||||
$zengjie = Db::connect('zengjie_db');
|
||||
if($data['type'] == 'sn'){
|
||||
$result = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['code']])->count();
|
||||
}else{
|
||||
$result = $zengjie->table('box_code_all')->where(['id'=>$data['code']])->count();
|
||||
}
|
||||
|
||||
if($result <= 0){
|
||||
return $this->msg(10002,'未找到该码录入');
|
||||
}
|
||||
|
||||
if($data['type'] == 'sn'){
|
||||
$result2 = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['code']])->update([
|
||||
'is_print'=>3
|
||||
]);
|
||||
}else{
|
||||
$result2 = $zengjie->table('box_code_all')->where(['id'=>$data['code']])->update([
|
||||
'is_print'=>0
|
||||
]);
|
||||
}
|
||||
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002,'打印失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function chuli_str_kongbai($data){
|
||||
foreach ($data as $key => $value) {
|
||||
// 1. 移除所有空字符和不可见字符
|
||||
$data[$key] = preg_replace('/[\x00-\x1F\x7F]/', '', $value);
|
||||
// 2. 去除首尾空白
|
||||
$data[$key] = trim($value);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
######################################################测试#########################################################
|
||||
######################################################测试#########################################################
|
||||
######################################################测试#########################################################
|
||||
|
||||
public function ceshiyong(){
|
||||
$data = input('post.');
|
||||
dump($data);
|
||||
// // 添加测试一维码数据
|
||||
// $data = [];
|
||||
// for ($i = 0; $i < 500; $i++) {
|
||||
// // 生成15位随机数字作为sn_code
|
||||
// $sn_code = '';
|
||||
// for ($j = 0; $j < 15; $j++) {
|
||||
// $sn_code .= mt_rand(0, 9);
|
||||
// }
|
||||
|
||||
// // 生成随机的MAC地址
|
||||
// $mac_parts = [];
|
||||
// for ($k = 0; $k < 6; $k++) {
|
||||
// $mac_parts[] = sprintf('%02x', mt_rand(0, 255));
|
||||
// }
|
||||
// $mac_code = implode(':', $mac_parts);
|
||||
|
||||
// // 构建数据数组
|
||||
// $data[] = [
|
||||
// 'sn_code' => $sn_code,
|
||||
// 'mac_code' => $mac_code,
|
||||
// 'create_time' => date('Y-m-d H:i:s'),
|
||||
// 'is_print' => 1,
|
||||
// 'bluetooth_name' => 'bl_5520'
|
||||
// ];
|
||||
// }
|
||||
// $zengjie = Db::connect('zengjie_db');
|
||||
// $result = $zengjie->table('sn_code_all')->insertAll($data);
|
||||
// dump($result);
|
||||
// die;
|
||||
// // 添加测试一维码数据
|
||||
|
||||
// 添加测试打包数据
|
||||
// $zengjie = Db::connect('zengjie_db');
|
||||
// $records = $zengjie->table('sn_code_all')
|
||||
// ->where('batch_id', 'null') // 或者使用 ->whereNull('batch_id')
|
||||
// ->orderRaw('NEWID()') // SQL Server的随机排序函数
|
||||
// ->limit(10)
|
||||
// ->select();
|
||||
// $data['sn_code_all'] = [];
|
||||
// $data['box_serial_number'] = '3ST011527003';
|
||||
// for ($i=0; $i < count($records); $i++) {
|
||||
// $data['sn_code_all'][] = $records[$i]['sn_code'];
|
||||
// }
|
||||
// $data['sn_code_all'] = implode(',',$data['sn_code_all']);
|
||||
// $result = $this->save_box_msg_action($data);
|
||||
// dump($result);
|
||||
// dump($data);
|
||||
// 添加测试打包数据
|
||||
// return $data;
|
||||
|
||||
|
||||
|
||||
|
||||
// '0386737300007235,0039376500007203,0059052100007102,0124589700007184,0032838000007113,0170457400007162,0170448500007207,0170466000006965,0426058900007228,0006613600007105'
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>最近一次打印数据</title>
|
||||
<script src="../x_admin/js/jq.js"></script>
|
||||
<style>
|
||||
body {
|
||||
margin: 0 0;
|
||||
padding: 0 0;
|
||||
}
|
||||
.big_box{
|
||||
display: flex;
|
||||
}
|
||||
.down{
|
||||
height: 30px;
|
||||
width: 100px;
|
||||
line-height: 30px;
|
||||
text-align: center;
|
||||
border: 1px solid black;
|
||||
box-shadow: 1px 1px 1px;
|
||||
margin-left: 10px;
|
||||
cursor: pointer
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="big_box">
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<th>MAC地址</th>
|
||||
<th>SN码</th>
|
||||
<th>箱号</th>
|
||||
</tr>
|
||||
{volist name="data" id="item"}
|
||||
<tr>
|
||||
<td>{$item.mac_code|default='未分配'}</td>
|
||||
<td>{$item.sn_code}</td>
|
||||
<td>{$item.box_code}-{$item.box_num}</td>
|
||||
</tr>
|
||||
{/volist}
|
||||
</table>
|
||||
<div class="down">点击下载</div>
|
||||
</div>
|
||||
<script>
|
||||
$('.down').on('click',function(){
|
||||
// $.ajax({
|
||||
// url:"print_device_data_index_action", //请求的url地址
|
||||
// dataType:"json", //返回格式为json
|
||||
// async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
// data:{"id":"value"}, //参数值
|
||||
// type:"POST", //请求方式
|
||||
// beforeSend:function(){
|
||||
// //请求前的处理
|
||||
// },
|
||||
// success:function(req){
|
||||
// //请求成功时处理
|
||||
// },
|
||||
// complete:function(){
|
||||
// //请求完成的处理
|
||||
// },
|
||||
// error:function(){
|
||||
// //请求出错处理
|
||||
// }});
|
||||
// window.open('https://www.example.com', '_blank');
|
||||
window.location.href = 'https://tc.pcxbc.com/z/print_device_data_index?type=down'
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>标签打印系统 - 集成码</title>
|
||||
<script src="../x_admin/js/jq.js"></script>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: white;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#barcodeContainer {
|
||||
margin: 20px auto;
|
||||
padding: 10px;
|
||||
border: 2px dashed black;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* 标签图片容器 - 精确匹配45mm×55mm尺寸 */
|
||||
#labelImageContainer {
|
||||
width: 531px; /* 45mm @ 300dpi */
|
||||
height: 649px; /* 55mm @ 300dpi */
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#labelImage {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#printBtn {
|
||||
display: block;
|
||||
width: 200px;
|
||||
margin: 20px auto;
|
||||
padding: 10px;
|
||||
background-color: #1E88E5;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media print {
|
||||
|
||||
|
||||
/* 方案2:如果需要完全干净的页面,使用这个替代方案1 */
|
||||
|
||||
body {
|
||||
visibility: hidden !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
#labelImageContainer {
|
||||
visibility: visible !important;
|
||||
position: absolute !important;
|
||||
left: 0 !important;
|
||||
top: 0 !important;
|
||||
width: 531px !important;
|
||||
height: 649px !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
#labelImage {
|
||||
visibility: visible !important;
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
object-fit: contain !important;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>标签打印系统 - 集成码</h1>
|
||||
<div class="description">生成包含二维码和条形码的标签</div>
|
||||
|
||||
<div id="barcodeContainer">
|
||||
<div id="labelImageContainer">
|
||||
<img id="labelImage" src="" alt="标签图片">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button id="printBtn">直接打印</button>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
loadCombinedCode();
|
||||
|
||||
$('#printBtn').click(function() {
|
||||
// 确保图片已加载再打印
|
||||
if($('#labelImage').attr('src') && $('#labelImage')[0].complete) {
|
||||
window.print();
|
||||
} else {
|
||||
alert('请等待标签加载完成');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function loadCombinedCode() {
|
||||
$.ajax({
|
||||
url: "/z/print_combined_code",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
if(response.code == 10002) {
|
||||
alert('没有可用的编码,请稍后再试');
|
||||
}
|
||||
else if(response.code == 10003) {
|
||||
alert(response.msg);
|
||||
}
|
||||
else if(response.data && response.data.image) {
|
||||
// 直接显示完整的标签图片
|
||||
$('#labelImage').attr('src', response.data.image);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error("请求出错:", error);
|
||||
alert('加载标签失败,请重试');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
<!doctype html>
|
||||
<html class="x-admin-sm">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>图片管理</title>
|
||||
<meta name="renderer" content="webkit|ie-comp|ie-stand">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<meta http-equiv="Cache-Control" content="no-siteapp" />
|
||||
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<style>
|
||||
.content{
|
||||
width: 100%;
|
||||
max-height: 70%;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-content: center;
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
.pic_box_upload{
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
margin: 5px 5px;
|
||||
}
|
||||
.pic_box_upload img{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.pic_box{
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
margin: 5px 5px;
|
||||
}
|
||||
.pic_box:hover {
|
||||
box-shadow: 0px 0px 1px;
|
||||
}
|
||||
.pic_box img{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#fileInput {
|
||||
display: none; /* 隐藏文件输入元素 */
|
||||
}
|
||||
.jz{
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: auto 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="pic_box_upload" onclick="upload_action()"><img src="https://tc.pcxbc.com/tsf/upload_pic.jpg" alt=""></div>
|
||||
{volist name="result" id="vo"}
|
||||
<div class="pic_box" onclick="sendParamToParent('{$vo.id}','{$vo.url_data}')"><img src="{$vo.url_data}" alt=""></div>
|
||||
{/volist}
|
||||
</div>
|
||||
<div class="layui-card-body jz">
|
||||
<div id="page" style="text-align: center;">
|
||||
</div>
|
||||
</div>
|
||||
<input type="file" id="fileInput">
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<script>
|
||||
var page_num;
|
||||
var laypage;
|
||||
var all_page = "{$num}";
|
||||
layui.use('laypage', function () {
|
||||
laypage = layui.laypage;
|
||||
laypage.render({
|
||||
elem: 'page',
|
||||
count: all_page, //数据总数,从服务端得到
|
||||
limit: 20,
|
||||
groups:20,
|
||||
jump: function (obj, first) {
|
||||
//首次不执行
|
||||
if (!first) {
|
||||
//obj包含了当前分页的所有参数,比如:
|
||||
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
|
||||
console.log(obj.limit); //得到每页显示的条数
|
||||
page_num = obj.curr;
|
||||
jump_page(page_num)
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
function jump_page(num){
|
||||
load()
|
||||
$.ajax({
|
||||
url: "/oi/zzt/pic_upload", //请求的url地址s
|
||||
dataType: "json", //返回格式为json
|
||||
async: true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data: {'page': num}, //参数值
|
||||
type: "POST", //请求方式
|
||||
success: function (req) {
|
||||
console.log(req)
|
||||
c_load();
|
||||
if(req['code'] == 0){
|
||||
var str,str_s,str_all="";
|
||||
for (let i = 0; i < req['data']['result'].length; i++) {
|
||||
str = '<div class="pic_box" onclick="sendParamToParent(\''+req['data']['result'][i]['id']+'\',\''+req['data']['result'][i]['url_data']+'\')"><img src="'+req['data']['result'][i]['url_data']+'" alt=""></div>'
|
||||
str_all = str_all+str;
|
||||
}
|
||||
$('.content').each(function() {
|
||||
$(this).find('.pic_box').remove();
|
||||
});
|
||||
$('.content').append(str_all);
|
||||
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
//请求出错处理
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function sendParamToParent(id,data) {
|
||||
var param = [id,data]; // 这是要传递的参数
|
||||
// 调用父窗口的一个函数,并传递参数
|
||||
if (window.parent && window.parent.receiveParamFromIframe) {
|
||||
window.parent.receiveParamFromIframe(param);
|
||||
} else {
|
||||
layer.msg('图片选择失败');
|
||||
}
|
||||
xadmin.close();
|
||||
}
|
||||
|
||||
function upload_action(){
|
||||
document.getElementById('fileInput').click();
|
||||
}
|
||||
|
||||
$('#fileInput').on('change', function() {
|
||||
// 获取被选择的文件
|
||||
var fileInput = $(this)[0];
|
||||
var file = fileInput.files[0];
|
||||
console.log(file)
|
||||
// return
|
||||
// 检查是否有文件被选择
|
||||
if (file) {
|
||||
load()
|
||||
var formdata = new FormData();
|
||||
formdata.append('cover_image',file)
|
||||
$.ajax({
|
||||
url:"/oi/zzt/pic_upload_action", //请求的url地址
|
||||
contentType:false,
|
||||
processData:false,
|
||||
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data:formdata, //参数值
|
||||
type:"POST", //请求方式
|
||||
success:function(req){
|
||||
c_load()
|
||||
//请求成功时处理
|
||||
if(req.code == 0){
|
||||
var newDiv = $('<div></div>')
|
||||
.addClass('pic_box')
|
||||
.attr('onclick', 'sendParamToParent(\''+req.data.id+'\',\''+req.data.url+'\')')
|
||||
.append($('<img></img>')
|
||||
.attr('src', req.data.url)
|
||||
.attr('alt', '')
|
||||
);
|
||||
$('.content > div:first').after(newDiv);
|
||||
layer.msg(req.msg);
|
||||
}else{
|
||||
layer.msg(req.msg);
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
//请求出错处理
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//加载提示开启
|
||||
function load() {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
}
|
||||
// 关闭加载提示
|
||||
function c_load() {
|
||||
layer.close(layer.index)
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
|
@ -0,0 +1,416 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="x-admin-sm">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>自定义表单收集</title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
|
||||
<style>
|
||||
.form-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
padding: 15px;
|
||||
border: 1px solid #e6e6e6;
|
||||
border-radius: 2px;
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
.form-item .field-name {
|
||||
width: 150px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-type {
|
||||
width: 120px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-placeholder {
|
||||
width: 150px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-required {
|
||||
width: 100px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .options-container {
|
||||
flex: 1;
|
||||
margin-right: 10px;
|
||||
padding: 10px;
|
||||
background-color: #fff;
|
||||
border-radius: 2px;
|
||||
border: 1px solid #e6e6e6;
|
||||
}
|
||||
.option-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.option-item input {
|
||||
flex: 1;
|
||||
margin-right: 5px;
|
||||
}
|
||||
.form-item .actions {
|
||||
display: flex;
|
||||
width: 100px;
|
||||
}
|
||||
.add-option-btn, .remove-field-btn {
|
||||
margin-left: 5px;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
.form-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
.layui-form-label {
|
||||
width: 120px;
|
||||
}
|
||||
.layui-input-inline {
|
||||
width: 300px;
|
||||
}
|
||||
.options-title {
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-row">
|
||||
<form class="layui-form">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">表单标题</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="form_title" name="form_title" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入表单标题">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">选择需要绑定的资讯</label>
|
||||
<div class="layui-input-inline">
|
||||
<select id="zx_data" name="zx_data" required lay-verify="required">
|
||||
<option value="">请选择</option>
|
||||
{volist name="result" id="vo"}
|
||||
<option value="{$vo.Id}">{$vo.Title}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 在现有的 "选择需要绑定的资讯" 表单项后面添加这个 -->
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">收集时间区间</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" class="layui-input" id="time-range" placeholder="请选择时间范围" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div id="fields-container" style="width: 80vw;margin-left: 7vw;">
|
||||
<!-- 动态生成的表单字段将在这里显示 -->
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<!-- <label class="layui-form-label">收集项目</label> -->
|
||||
<div class="layui-input-block">
|
||||
<button type="button" class="layui-btn layui-btn-normal" id="add-field-btn">
|
||||
<i class="layui-icon"></i> 添加收集项目
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-inline">
|
||||
<button class="layui-btn" lay-submit lay-filter="submit-form">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/layui@2.6.8/dist/layui.min.js"></script>
|
||||
<script>
|
||||
layui.use(['form', 'layer', 'laydate'], function(){
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var laydate = layui.laydate;
|
||||
var $ = layui.$;
|
||||
|
||||
// 添加时间范围选择器
|
||||
laydate.render({
|
||||
elem: '#time-range',
|
||||
range: true,
|
||||
format: 'yyyy-MM-dd',
|
||||
done: function(value, date, endDate) {
|
||||
// 实时验证是否选择了完整的时间范围
|
||||
if (value && value.indexOf(' - ') !== -1) {
|
||||
var times = value.split(' - ');
|
||||
if (times.length === 2 && times[0] && times[1]) {
|
||||
// 格式正确,清除错误样式
|
||||
$('#time-range').removeClass('layui-border-red');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 字段计数器
|
||||
var fieldCounter = 0;
|
||||
|
||||
// 添加字段按钮点击事件
|
||||
$('#add-field-btn').on('click', function(){
|
||||
addFormField();
|
||||
});
|
||||
|
||||
// 添加表单字段
|
||||
function addFormField() {
|
||||
fieldCounter++;
|
||||
var fieldId = 'field_' + fieldCounter;
|
||||
|
||||
var fieldHtml = `
|
||||
<div class="form-item" id="${fieldId}">
|
||||
<div class="field-name">
|
||||
<input type="text" class="layui-input field-name-input" placeholder="收集项目名称" value="">
|
||||
</div>
|
||||
<div class="field-placeholder">
|
||||
<input type="text" class="layui-input field-placeholder-input" placeholder="自定义提示文字" value="">
|
||||
</div>
|
||||
<div class="field-type">
|
||||
<select class="field-type-select" lay-filter="field-type-${fieldCounter}">
|
||||
<option value="text">输入框</option>
|
||||
<option value="textarea">多行文本</option>
|
||||
<option value="select">下拉单选</option>
|
||||
<option value="checkbox">多选按钮</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field-required">
|
||||
<select class="field-required-select">
|
||||
<option value="1">该项必填</option>
|
||||
<option value="0">该项非必填</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="options-container hidden">
|
||||
<div class="options-title">选项设置:</div>
|
||||
<div class="options-list"></div>
|
||||
<button type="button" class="layui-btn layui-btn-xs add-option-btn">添加选项</button>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger remove-field-btn">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
$('#fields-container').append(fieldHtml);
|
||||
|
||||
// 重新渲染表单元素
|
||||
form.render('select');
|
||||
|
||||
// 绑定事件
|
||||
bindFieldEvents(fieldId);
|
||||
}
|
||||
|
||||
// 绑定字段事件
|
||||
function bindFieldEvents(fieldId) {
|
||||
var $field = $('#' + fieldId);
|
||||
|
||||
// 使用Layui的方式监听选择框变化
|
||||
form.on('select(field-type-' + fieldCounter + ')', function(data){
|
||||
var fieldType = data.value;
|
||||
var $optionsContainer = $field.find('.options-container');
|
||||
|
||||
console.log('字段类型改变:', fieldType);
|
||||
console.log('选项容器:', $optionsContainer);
|
||||
|
||||
if (fieldType === 'select' || fieldType === 'checkbox') {
|
||||
console.log('显示选项容器');
|
||||
$optionsContainer.removeClass('hidden');
|
||||
// 如果没有选项,默认添加一个空选项
|
||||
if ($optionsContainer.find('.option-item').length === 0) {
|
||||
console.log('添加默认选项');
|
||||
addOption($field);
|
||||
}
|
||||
} else {
|
||||
console.log('隐藏选项容器');
|
||||
$optionsContainer.addClass('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
// 添加选项按钮点击事件
|
||||
$field.find('.add-option-btn').on('click', function(){
|
||||
console.log('点击添加选项按钮');
|
||||
addOption($field);
|
||||
});
|
||||
|
||||
// 删除字段按钮点击事件
|
||||
$field.find('.remove-field-btn').on('click', function(){
|
||||
console.log('删除字段:', fieldId);
|
||||
$field.remove();
|
||||
});
|
||||
}
|
||||
|
||||
// 添加选项函数
|
||||
function addOption($field) {
|
||||
var optionId = 'option_' + Date.now();
|
||||
var optionHtml = `
|
||||
<div class="option-item" id="${optionId}">
|
||||
<input type="text" class="layui-input option-input" placeholder="选项内容">
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger remove-option-btn">删除</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
$field.find('.options-list').append(optionHtml);
|
||||
console.log('添加选项完成,选项ID:', optionId);
|
||||
|
||||
// 绑定选项删除事件
|
||||
$field.find('#' + optionId + ' .remove-option-btn').on('click', function(){
|
||||
console.log('删除选项:', optionId);
|
||||
$(this).closest('.option-item').remove();
|
||||
});
|
||||
}
|
||||
|
||||
// 表单提交事件
|
||||
form.on('submit(submit-form)', function(data){
|
||||
|
||||
var event = window.event || arguments.callee.caller.arguments[0];
|
||||
if (event && event.preventDefault) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
// 获取时间范围值
|
||||
var timeRange = $('#time-range').val();
|
||||
if (!timeRange) {
|
||||
layer.msg('请选择收集时间区间', {icon: 2});
|
||||
$('#time-range').addClass('layui-border-red').focus();
|
||||
return false;
|
||||
}
|
||||
var timeArray = timeRange.split(' - ');
|
||||
if (timeArray.length !== 2 || !timeArray[0] || !timeArray[1]) {
|
||||
layer.msg('请选择完整的时间区间', {icon: 2});
|
||||
$('#time-range').addClass('layui-border-red').focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 收集表单数据
|
||||
var formData = {
|
||||
title: $('#form_title').val(),
|
||||
zx_id: $('#zx_data').val(),
|
||||
s_time: timeArray[0] + ' 00:00:00', // 格式:Y-m-d 00:00:00
|
||||
e_time: timeArray[1] + ' 23:59:59', // 格式:Y-m-d 23:59:59
|
||||
fields: []
|
||||
};
|
||||
|
||||
// 遍历所有字段
|
||||
$('.form-item').each(function(){
|
||||
var $field = $(this);
|
||||
var fieldName = $field.find('.field-name-input').val();
|
||||
var fieldType = $field.find('.field-type-select').val();
|
||||
var placeholder = $field.find('.field-placeholder-input').val();
|
||||
var isMust = $field.find('.field-required-select').val() === '1';
|
||||
|
||||
var fieldData = {
|
||||
name: fieldName,
|
||||
type: fieldType,
|
||||
placeholder: placeholder,
|
||||
is_must: isMust
|
||||
};
|
||||
|
||||
// 如果是选择类型,收集选项
|
||||
if (fieldType === 'select' || fieldType === 'checkbox') {
|
||||
fieldData.options = [];
|
||||
$field.find('.option-item').each(function(){
|
||||
var optionValue = $(this).find('.option-input').val();
|
||||
if (optionValue) {
|
||||
fieldData.options.push(optionValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
formData.fields.push(fieldData);
|
||||
});
|
||||
|
||||
// 检查fields是否为空
|
||||
if (formData.fields.length === 0) {
|
||||
layer.msg('请先添加收集项目', {icon: 2});
|
||||
return false;
|
||||
}
|
||||
|
||||
// 新增:验证每个字段名称不能为空
|
||||
for (var i = 0; i < formData.fields.length; i++) {
|
||||
// 先清除之前的高亮样式
|
||||
$('.form-item').eq(i).find('.field-name-input').removeClass('layui-border-red');
|
||||
|
||||
if (!formData.fields[i].name || formData.fields[i].name.trim() === '') {
|
||||
layer.msg('第 ' + (i + 1) + ' 个收集项目的名称不能为空', {icon: 2});
|
||||
// 高亮显示空的字段名称输入框
|
||||
$('.form-item').eq(i).find('.field-name-input').addClass('layui-border-red').focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 新增:验证选择类型的选项不能为空
|
||||
if ((formData.fields[i].type === 'select' || formData.fields[i].type === 'checkbox') &&
|
||||
(!formData.fields[i].options || formData.fields[i].options.length === 0)) {
|
||||
layer.msg('第 ' + (i + 1) + ' 个收集项目是选择类型,必须至少添加一个选项', {icon: 2});
|
||||
// 高亮显示选项容器
|
||||
$('.form-item').eq(i).find('.options-container').addClass('layui-border-red');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 在控制台打印表单数据
|
||||
console.log('表单数据:', formData);
|
||||
|
||||
// 显示成功消息
|
||||
// layer.msg('表单数据已收集,请查看控制台输出', {icon: 1});
|
||||
|
||||
return tj(formData, event);
|
||||
// tj(formData);
|
||||
|
||||
// return false; // 阻止表单跳转
|
||||
});
|
||||
|
||||
// 初始添加一个字段
|
||||
// addFormField();
|
||||
|
||||
console.log('页面加载完成,初始字段已添加');
|
||||
});
|
||||
|
||||
|
||||
|
||||
function tj(data){
|
||||
if (event && event.preventDefault) {
|
||||
event.preventDefault();
|
||||
}
|
||||
$.ajax({
|
||||
url: "/oi/zzt/add_form_action",
|
||||
dataType: "json",
|
||||
async: true,
|
||||
data: JSON.stringify(data), // 建议使用 JSON 格式
|
||||
contentType: "application/json", // 设置内容类型
|
||||
type: "POST",
|
||||
success: function(req) {
|
||||
if (req.code === 0) {
|
||||
layer.msg('提交成功', {icon: 1, time: 2000}, function(){
|
||||
// 可以在这里进行页面跳转或其他操作
|
||||
// window.location.reload(); // 刷新页面
|
||||
// window.location.href = '/other-page'; // 跳转页面
|
||||
//关闭当前frame
|
||||
xadmin.close();
|
||||
// 可以对父窗口进行刷新
|
||||
xadmin.father_reload();
|
||||
});
|
||||
} else {
|
||||
layer.msg(req.msg || '提交失败', {icon: 2});
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// layer.msg('网络错误,请重试: ' + error, {icon: 2});
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,562 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="x-admin-sm">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>添加活动报名</title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
|
||||
<link href="/rich_text_editor/style.css" rel="stylesheet">
|
||||
<script src="/rich_text_editor/index.js"></script>
|
||||
<style>
|
||||
.form-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
padding: 15px;
|
||||
border: 1px solid #e6e6e6;
|
||||
border-radius: 2px;
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
.form-item .field-name {
|
||||
width: 150px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-type {
|
||||
width: 120px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-placeholder {
|
||||
width: 150px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-required {
|
||||
width: 100px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .options-container {
|
||||
flex: 1;
|
||||
margin-right: 10px;
|
||||
padding: 10px;
|
||||
background-color: #fff;
|
||||
border-radius: 2px;
|
||||
border: 1px solid #e6e6e6;
|
||||
}
|
||||
.option-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.option-item input {
|
||||
flex: 1;
|
||||
margin-right: 5px;
|
||||
}
|
||||
.form-item .actions {
|
||||
display: flex;
|
||||
width: 100px;
|
||||
}
|
||||
.add-option-btn, .remove-field-btn {
|
||||
margin-left: 5px;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
.form-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
.layui-form-label {
|
||||
width: 120px;
|
||||
}
|
||||
.layui-input-inline {
|
||||
width: 300px;
|
||||
}
|
||||
.options-title {
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#editor—wrapper {
|
||||
border: 1px solid #ccc;
|
||||
z-index: 100; /* 按需定义 */
|
||||
}
|
||||
#toolbar-container { border-bottom: 1px solid #ccc; }
|
||||
#editor-container { height: 500px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-row" id="app_all">
|
||||
<form action="" method="post" class="layui-form layui-form-pane">
|
||||
<div class="layui-form-item">
|
||||
<label for="title_v" class="layui-form-label">
|
||||
<span class="x-red">☆</span>活动标题
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="title_v" name="title_v" required="" lay-verify="title_v" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="title_v" class="layui-form-label">
|
||||
<span class="x-red">☆</span>上传封面
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<div class="layui-btn" onclick="xadmin.open('图片管理','/oi/zzt/pic_upload','80%','80%')">点击选择</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="title_v" class="layui-form-label">
|
||||
<span class="x-red"></span>预览
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<img id="preview_img" style="max-width:500px;box-shadow: 0px 0px 1px;" src="" alt="">
|
||||
<input type="hidden" name="banner_img" id="banner_img" lay-verify="banner_img" value=""></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="s_time" class="layui-form-label">
|
||||
<span class="x-red">☆</span>开始时间
|
||||
</label>
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<input class="layui-input" autocomplete="off" placeholder="请选择日期" name="start" lay-verify="s_time" id="s_time">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="e_time" class="layui-form-label">
|
||||
<span class="x-red">☆</span>结束时间
|
||||
</label>
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<input class="layui-input" autocomplete="off" placeholder="请选择日期" name="end" lay-verify="e_time" id="e_time">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label for="people_num" class="layui-form-label">
|
||||
<span class="x-red">☆</span>重复报名
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="" id="is_only_once">
|
||||
<option value="0">否</option>
|
||||
<option value="1">是</option>
|
||||
</select>
|
||||
<!-- <input type="text" id="people_num" name="people_num" required="" lay-verify="people_num" autocomplete="off" class="layui-input"> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="people_num" class="layui-form-label">
|
||||
<span class="x-red">☆</span>报名人数
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="people_num" name="people_num" required="" lay-verify="people_num" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div id="fields-container" style="width: 80vw;margin-left: 7vw;">
|
||||
<!-- 动态生成的表单字段将在这里显示 -->
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button type="button" class="layui-btn layui-btn-normal" id="add-field-btn">
|
||||
<i class="layui-icon"></i> 添加收集项目
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text" style="max-width: 90%;" id="editor_wrapper_box">
|
||||
<label for="desc" class="layui-form-label">
|
||||
<span class="x-red">☆</span>内容编辑
|
||||
</label>
|
||||
<div id="editor—wrapper">
|
||||
<div id="toolbar-container"><!-- 工具栏 --></div>
|
||||
<div id="editor-container"><!-- 编辑器 --></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
|
||||
<button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function receiveParamFromIframe(param) {
|
||||
pic_data = param
|
||||
if(pic_data.length > 0){
|
||||
var img = document.getElementById('preview_img');
|
||||
img.src = pic_data[1]; // 设置图片预览的src属性
|
||||
img.style.display = 'block'; // 显示图片预览
|
||||
$('#banner_img').val(pic_data[0])
|
||||
}
|
||||
}
|
||||
var html
|
||||
const { createEditor, createToolbar } = window.wangEditor
|
||||
|
||||
const editorConfig = {
|
||||
placeholder: 'Type here...',
|
||||
onChange(editor) {
|
||||
html = editor.getHtml()
|
||||
html = html.replace(/\r?\n|\r/g, '');
|
||||
},
|
||||
MENU_CONF: {}
|
||||
}
|
||||
editorConfig.MENU_CONF['uploadImage'] = {
|
||||
server: '/oi/zzt/upload_pic_action',
|
||||
maxNumberOfFiles: 1,
|
||||
maxFileSize: 10 * 1024 * 1024, // 10M
|
||||
onError(file, err, res) {
|
||||
alert(err.message)
|
||||
},
|
||||
}
|
||||
editorConfig.MENU_CONF['uploadVideo'] = {
|
||||
server: '/oi/zzt/upload_video_action',
|
||||
maxFileSize: 100 * 1024 * 1024, // 100M
|
||||
maxNumberOfFiles: 1,
|
||||
onError(file, err, res) {
|
||||
alert(err.message)
|
||||
},
|
||||
}
|
||||
|
||||
const editor = createEditor({
|
||||
selector: '#editor-container',
|
||||
html: '<p><br></p>',
|
||||
config: editorConfig,
|
||||
mode: 'default', // or 'simple'
|
||||
})
|
||||
|
||||
const toolbarConfig = {}
|
||||
|
||||
const toolbar = createToolbar({
|
||||
editor,
|
||||
selector: '#toolbar-container',
|
||||
config: toolbarConfig,
|
||||
mode: 'default', // or 'simple'
|
||||
})
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<script>
|
||||
var form
|
||||
var pd = true
|
||||
layui.use(['form', 'layer', 'laydate'], function () {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var laydate = layui.laydate;
|
||||
var $ = layui.$;
|
||||
//执行一个laydate实例
|
||||
laydate.render({
|
||||
elem: '#s_time', //指定元素
|
||||
type: 'datetime', // 选择日期和时间
|
||||
format: 'yyyy-MM-dd HH:mm:ss', // 格式包含时分秒
|
||||
btns: ['clear', 'now', 'confirm'], // 按钮配置
|
||||
ready: function(date){
|
||||
console.log('控件初始化完成', date);
|
||||
}
|
||||
});
|
||||
//执行一个laydate实例
|
||||
laydate.render({
|
||||
elem: '#e_time', //指定元素
|
||||
type: 'datetime', // 选择日期和时间
|
||||
format: 'yyyy-MM-dd HH:mm:ss', // 格式包含时分秒
|
||||
btns: ['clear', 'now', 'confirm'], // 按钮配置
|
||||
ready: function(date){
|
||||
console.log('控件初始化完成', date);
|
||||
}
|
||||
});
|
||||
// 字段计数器
|
||||
var fieldCounter = 0;
|
||||
|
||||
// 添加字段按钮点击事件
|
||||
$('#add-field-btn').on('click', function(){
|
||||
addFormField();
|
||||
});
|
||||
|
||||
// 添加表单字段
|
||||
function addFormField() {
|
||||
fieldCounter++;
|
||||
var fieldId = 'field_' + fieldCounter;
|
||||
|
||||
var fieldHtml = `
|
||||
<div class="form-item" id="${fieldId}">
|
||||
<div class="field-name">
|
||||
<input type="text" class="layui-input field-name-input" placeholder="收集项目名称" value="">
|
||||
</div>
|
||||
<div class="field-placeholder">
|
||||
<input type="text" class="layui-input field-placeholder-input" placeholder="自定义提示文字" value="">
|
||||
</div>
|
||||
<div class="field-type">
|
||||
<select class="field-type-select" lay-filter="field-type-${fieldCounter}">
|
||||
<option value="text">输入框</option>
|
||||
<option value="textarea">多行文本</option>
|
||||
<option value="radio">单选</option>
|
||||
<option value="checkbox">多选按钮</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field-required">
|
||||
<select class="field-required-select">
|
||||
<option value="1">该项必填</option>
|
||||
<option value="0">该项非必填</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="options-container hidden">
|
||||
<div class="options-title">选项设置:</div>
|
||||
<div class="options-list"></div>
|
||||
<button type="button" class="layui-btn layui-btn-xs add-option-btn">添加选项</button>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger remove-field-btn">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
$('#fields-container').append(fieldHtml);
|
||||
|
||||
// 重新渲染表单元素
|
||||
form.render('select');
|
||||
|
||||
// 绑定事件
|
||||
bindFieldEvents(fieldId);
|
||||
}
|
||||
|
||||
// 绑定字段事件
|
||||
function bindFieldEvents(fieldId) {
|
||||
var $field = $('#' + fieldId);
|
||||
|
||||
// 使用Layui的方式监听选择框变化
|
||||
form.on('select(field-type-' + fieldCounter + ')', function(data){
|
||||
var fieldType = data.value;
|
||||
var $optionsContainer = $field.find('.options-container');
|
||||
|
||||
console.log('字段类型改变:', fieldType);
|
||||
console.log('选项容器:', $optionsContainer);
|
||||
|
||||
if (fieldType === 'radio' || fieldType === 'checkbox') {
|
||||
console.log('显示选项容器');
|
||||
$optionsContainer.removeClass('hidden');
|
||||
// 如果没有选项,默认添加一个空选项
|
||||
if ($optionsContainer.find('.option-item').length === 0) {
|
||||
console.log('添加默认选项');
|
||||
addOption($field);
|
||||
}
|
||||
} else {
|
||||
console.log('隐藏选项容器');
|
||||
$optionsContainer.addClass('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
// 添加选项按钮点击事件
|
||||
$field.find('.add-option-btn').on('click', function(){
|
||||
console.log('点击添加选项按钮');
|
||||
addOption($field);
|
||||
});
|
||||
|
||||
// 删除字段按钮点击事件
|
||||
$field.find('.remove-field-btn').on('click', function(){
|
||||
console.log('删除字段:', fieldId);
|
||||
$field.remove();
|
||||
});
|
||||
}
|
||||
|
||||
// 添加选项函数
|
||||
function addOption($field) {
|
||||
var optionId = 'option_' + Date.now();
|
||||
var optionHtml = `
|
||||
<div class="option-item" id="${optionId}">
|
||||
<input type="text" class="layui-input option-input" placeholder="选项内容">
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger remove-option-btn">删除</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
$field.find('.options-list').append(optionHtml);
|
||||
console.log('添加选项完成,选项ID:', optionId);
|
||||
|
||||
// 绑定选项删除事件
|
||||
$field.find('#' + optionId + ' .remove-option-btn').on('click', function(){
|
||||
console.log('删除选项:', optionId);
|
||||
$(this).closest('.option-item').remove();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
form.verify({
|
||||
title_v: function(value) {
|
||||
if (value == '') {
|
||||
return '请先选择添加标题';
|
||||
}
|
||||
},
|
||||
banner_img: function(value) {
|
||||
if (value == '') {
|
||||
return '请先选择图片';
|
||||
}
|
||||
},
|
||||
s_time: function(value) {
|
||||
if (value == '') {
|
||||
return '请先选择开始时间';
|
||||
}
|
||||
},
|
||||
e_time: function(value) {
|
||||
if (value == '') {
|
||||
return '请先选择结束时间';
|
||||
}
|
||||
},
|
||||
people_num: function(value) {
|
||||
if (value == '') {
|
||||
return '请先输入报名人数';
|
||||
}
|
||||
},
|
||||
});
|
||||
//监听提交
|
||||
form.on('submit(add)',function(data) {
|
||||
// 收集表单数据
|
||||
var formData = {
|
||||
fields: []
|
||||
};
|
||||
|
||||
// 遍历所有字段
|
||||
$('.form-item').each(function(){
|
||||
var $field = $(this);
|
||||
var fieldName = $field.find('.field-name-input').val();
|
||||
var fieldType = $field.find('.field-type-select').val();
|
||||
var placeholder = $field.find('.field-placeholder-input').val();
|
||||
var isMust = $field.find('.field-required-select').val() === '1';
|
||||
|
||||
var fieldData = {
|
||||
name: fieldName,
|
||||
type: fieldType,
|
||||
placeholder: placeholder,
|
||||
is_must: isMust
|
||||
};
|
||||
|
||||
// 如果是选择类型,收集选项
|
||||
if (fieldType === 'radio' || fieldType === 'checkbox') {
|
||||
fieldData.options = [];
|
||||
$field.find('.option-item').each(function(){
|
||||
var optionValue = $(this).find('.option-input').val();
|
||||
if (optionValue) {
|
||||
fieldData.options.push(optionValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
formData.fields.push(fieldData);
|
||||
});
|
||||
|
||||
// 检查fields是否为空
|
||||
if (formData.fields.length === 0) {
|
||||
layer.msg('请先添加收集项目', {icon: 2});
|
||||
return false;
|
||||
}
|
||||
|
||||
// 新增:验证每个字段名称不能为空
|
||||
for (var i = 0; i < formData.fields.length; i++) {
|
||||
// 先清除之前的高亮样式
|
||||
$('.form-item').eq(i).find('.field-name-input').removeClass('layui-border-red');
|
||||
|
||||
if (!formData.fields[i].name || formData.fields[i].name.trim() === '') {
|
||||
layer.msg('第 ' + (i + 1) + ' 个收集项目的名称不能为空', {icon: 2});
|
||||
// 高亮显示空的字段名称输入框
|
||||
$('.form-item').eq(i).find('.field-name-input').addClass('layui-border-red').focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 新增:验证选择类型的选项不能为空
|
||||
if ((formData.fields[i].type === 'radio' || formData.fields[i].type === 'checkbox') &&
|
||||
(!formData.fields[i].options || formData.fields[i].options.length === 0)) {
|
||||
layer.msg('第 ' + (i + 1) + ' 个收集项目是选择类型,必须至少添加一个选项', {icon: 2});
|
||||
// 高亮显示选项容器
|
||||
$('.form-item').eq(i).find('.options-container').addClass('layui-border-red');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 在控制台打印表单数据
|
||||
console.log('表单数据:', formData);
|
||||
add_data(formData)
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
// 功能性~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
function add_data(formData){
|
||||
if(pd === false){
|
||||
return
|
||||
}
|
||||
var data = {
|
||||
'cover_image':$('#banner_img').val(),
|
||||
'title':$('#title_v').val(),
|
||||
'content':html,
|
||||
'form_data':formData.fields,
|
||||
's_time':$('#s_time').val(),
|
||||
'e_time':$('#e_time').val(),
|
||||
'people_num':$('#people_num').val(),
|
||||
'is_only_once':$('#is_only_once').val(),
|
||||
|
||||
}
|
||||
console.log(data);
|
||||
// return
|
||||
pd = false
|
||||
load()
|
||||
$.ajax({
|
||||
url:"/oi/zzt/add_form_action", //请求的url地址
|
||||
dataType: "json", //返回格式为json
|
||||
async: true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data: data, //参数值
|
||||
type: "POST", //请求方式
|
||||
success:function(req){
|
||||
c_load()
|
||||
pd = true
|
||||
console.log()
|
||||
if(req.code == 0){
|
||||
layer.alert("增加成功", {icon: 6},function() {
|
||||
//关闭当前frame
|
||||
xadmin.close();
|
||||
// 可以对父窗口进行刷新
|
||||
xadmin.father_reload();
|
||||
});
|
||||
}else{
|
||||
layer.alert("增加失败"+req.msg, {icon: 6},function() {
|
||||
//关闭当前frame
|
||||
xadmin.close();
|
||||
// 可以对父窗口进行刷新
|
||||
xadmin.father_reload();
|
||||
});
|
||||
}
|
||||
//请求成功时处理
|
||||
|
||||
console.log(req)
|
||||
},
|
||||
error:function(){
|
||||
//请求出错处理
|
||||
pd = true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//加载提示开启
|
||||
function load() {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
}
|
||||
// 关闭加载提示
|
||||
function c_load() {
|
||||
layer.close(layer.index)
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -0,0 +1,584 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="x-admin-sm">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>添加活动报名</title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script type="text/javascript" src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/jq.js"></script>
|
||||
<link href="/rich_text_editor/style.css" rel="stylesheet">
|
||||
<script src="/rich_text_editor/index.js"></script>
|
||||
<style>
|
||||
.form-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
padding: 15px;
|
||||
border: 1px solid #e6e6e6;
|
||||
border-radius: 2px;
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
.form-item .field-name {
|
||||
width: 150px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-type {
|
||||
width: 120px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-placeholder {
|
||||
width: 150px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .field-required {
|
||||
width: 100px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-item .options-container {
|
||||
flex: 1;
|
||||
margin-right: 10px;
|
||||
padding: 10px;
|
||||
background-color: #fff;
|
||||
border-radius: 2px;
|
||||
border: 1px solid #e6e6e6;
|
||||
}
|
||||
.option-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.option-item input {
|
||||
flex: 1;
|
||||
margin-right: 5px;
|
||||
}
|
||||
.form-item .actions {
|
||||
display: flex;
|
||||
width: 100px;
|
||||
}
|
||||
.add-option-btn, .remove-field-btn {
|
||||
margin-left: 5px;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
.form-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
.layui-form-label {
|
||||
width: 120px;
|
||||
}
|
||||
.layui-input-inline {
|
||||
width: 300px;
|
||||
}
|
||||
.options-title {
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#editor—wrapper {
|
||||
border: 1px solid #ccc;
|
||||
z-index: 100;
|
||||
}
|
||||
#toolbar-container { border-bottom: 1px solid #ccc; }
|
||||
#editor-container { height: 500px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-row" id="app_all">
|
||||
<form action="" method="post" class="layui-form layui-form-pane">
|
||||
<div class="layui-form-item">
|
||||
<label for="title_v" class="layui-form-label">
|
||||
<span class="x-red">☆</span>活动标题
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="title_v" name="title_v" required="" lay-verify="title_v" autocomplete="off" class="layui-input" value="{$result['title']}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="title_v" class="layui-form-label">
|
||||
<span class="x-red">☆</span>上传封面
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<div class="layui-btn" onclick="xadmin.open('图片管理','/oi/zzt/pic_upload','80%','80%')">点击选择</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="title_v" class="layui-form-label">
|
||||
<span class="x-red"></span>预览
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<img id="preview_img" style="max-width:500px;box-shadow: 0px 0px 1px;" src="{$result['pic_url']}" alt="">
|
||||
<input type="hidden" name="banner_img" id="banner_img" lay-verify="banner_img" value="{$result['pic']}"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="s_time" class="layui-form-label">
|
||||
<span class="x-red">☆</span>开始时间
|
||||
</label>
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<input class="layui-input" autocomplete="off" placeholder="请选择日期" name="start" lay-verify="s_time" id="s_time" value="{$result['start_time']}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="e_time" class="layui-form-label">
|
||||
<span class="x-red">☆</span>结束时间
|
||||
</label>
|
||||
<div class="layui-inline layui-show-xs-block">
|
||||
<input class="layui-input" autocomplete="off" placeholder="请选择日期" name="end" lay-verify="e_time" id="e_time" value="{$result['end_time']}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="people_num" class="layui-form-label">
|
||||
<span class="x-red">☆</span>重复报名
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="is_only_once" id="is_only_once">
|
||||
<option value="0" {$result["is_only_once"] == 0 ? 'selected' : ''}>否</option>
|
||||
<option value="1" {$result["is_only_once"] == 1 ? 'selected' : ''}>是</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="people_num" class="layui-form-label">
|
||||
<span class="x-red">☆</span>报名人数
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="people_num" name="people_num" required="" lay-verify="people_num" autocomplete="off" class="layui-input" value="{$result['people_num']}">
|
||||
</div>
|
||||
</div>
|
||||
<div id="fields-container" style="width: 80vw;margin-left: 7vw;">
|
||||
<!-- 动态生成的表单字段将在这里显示 -->
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button type="button" class="layui-btn layui-btn-normal" id="add-field-btn">
|
||||
<i class="layui-icon"></i> 添加收集项目
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text" style="max-width: 90%;" id="editor_wrapper_box">
|
||||
<label for="desc" class="layui-form-label">
|
||||
<span class="x-red">☆</span>内容编辑
|
||||
</label>
|
||||
<div id="editor—wrapper">
|
||||
<div id="toolbar-container"><!-- 工具栏 --></div>
|
||||
<div id="editor-container"><!-- 编辑器 --></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<button class="layui-btn" lay-filter="add" lay-submit="">提交修改</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var form_data_id_num = '{$result["id"]}'
|
||||
var result_data = {
|
||||
'content':'{$result["text_content"]}',
|
||||
'form_data':JSON.parse('{$result["form_content"]}'),
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function receiveParamFromIframe(param) {
|
||||
pic_data = param
|
||||
if(pic_data.length > 0){
|
||||
var img = document.getElementById('preview_img');
|
||||
img.src = pic_data[1];
|
||||
img.style.display = 'block';
|
||||
$('#banner_img').val(pic_data[0])
|
||||
}
|
||||
}
|
||||
var html
|
||||
const { createEditor, createToolbar } = window.wangEditor
|
||||
|
||||
const editorConfig = {
|
||||
placeholder: 'Type here...',
|
||||
onChange(editor) {
|
||||
html = editor.getHtml()
|
||||
html = html.replace(/\r?\n|\r/g, '');
|
||||
},
|
||||
MENU_CONF: {}
|
||||
}
|
||||
editorConfig.MENU_CONF['uploadImage'] = {
|
||||
server: '/oi/zzt/upload_pic_action',
|
||||
maxNumberOfFiles: 1,
|
||||
maxFileSize: 10 * 1024 * 1024,
|
||||
onError(file, err, res) {
|
||||
alert(err.message)
|
||||
},
|
||||
}
|
||||
editorConfig.MENU_CONF['uploadVideo'] = {
|
||||
server: '/oi/zzt/upload_video_action',
|
||||
maxFileSize: 100 * 1024 * 1024,
|
||||
maxNumberOfFiles: 1,
|
||||
onError(file, err, res) {
|
||||
alert(err.message)
|
||||
},
|
||||
}
|
||||
|
||||
const editor = createEditor({
|
||||
selector: '#editor-container',
|
||||
html: '<p><br></p>',
|
||||
config: editorConfig,
|
||||
mode: 'default',
|
||||
})
|
||||
|
||||
const toolbarConfig = {}
|
||||
|
||||
const toolbar = createToolbar({
|
||||
editor,
|
||||
selector: '#toolbar-container',
|
||||
config: toolbarConfig,
|
||||
mode: 'default',
|
||||
})
|
||||
|
||||
editor.setHtml(result_data.content)
|
||||
</script>
|
||||
<script>
|
||||
var form
|
||||
var pd = true
|
||||
layui.use(['form', 'layer', 'laydate'], function () {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var laydate = layui.laydate;
|
||||
var $ = layui.$;
|
||||
|
||||
// 页面加载完成后初始化表单字段
|
||||
$(document).ready(function() {
|
||||
if(result_data.form_data && result_data.form_data.length > 0) {
|
||||
initFormFields(result_data.form_data);
|
||||
}
|
||||
});
|
||||
|
||||
// 初始化表单字段的函数
|
||||
function initFormFields(formFields) {
|
||||
$('#fields-container').empty();
|
||||
fieldCounter = 0;
|
||||
|
||||
formFields.forEach(function(field, index) {
|
||||
addFormField();
|
||||
var $field = $('#fields-container .form-item').last();
|
||||
|
||||
// 填充字段数据
|
||||
$field.find('.field-name-input').val(field.name || '');
|
||||
$field.find('.field-placeholder-input').val(field.placeholder || '');
|
||||
$field.find('.field-type-select').val(field.type || 'text');
|
||||
$field.find('.field-required-select').val(field.is_must === "true" ? "1" : "0");
|
||||
|
||||
// 重新渲染select
|
||||
form.render('select');
|
||||
|
||||
// 如果是选择类型,填充选项
|
||||
if((field.type === 'radio' || field.type === 'checkbox') && field.options) {
|
||||
if(Array.isArray(field.options)) {
|
||||
// 先清空可能已有的默认选项
|
||||
$field.find('.options-list').empty();
|
||||
|
||||
// 添加所有选项
|
||||
field.options.forEach(function(option) {
|
||||
addOption($field);
|
||||
var $lastOption = $field.find('.options-list .option-item').last();
|
||||
$lastOption.find('.option-input').val(option);
|
||||
});
|
||||
|
||||
// 显示选项容器
|
||||
$field.find('.options-container').removeClass('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 重新渲染表单
|
||||
form.render('select');
|
||||
}
|
||||
|
||||
//执行一个laydate实例
|
||||
laydate.render({
|
||||
elem: '#s_time',
|
||||
type: 'datetime',
|
||||
format: 'yyyy-MM-dd HH:mm:ss',
|
||||
btns: ['clear', 'now', 'confirm'],
|
||||
ready: function(date){
|
||||
console.log('控件初始化完成', date);
|
||||
}
|
||||
});
|
||||
//执行一个laydate实例
|
||||
laydate.render({
|
||||
elem: '#e_time',
|
||||
type: 'datetime',
|
||||
format: 'yyyy-MM-dd HH:mm:ss',
|
||||
btns: ['clear', 'now', 'confirm'],
|
||||
ready: function(date){
|
||||
console.log('控件初始化完成', date);
|
||||
}
|
||||
});
|
||||
// 字段计数器
|
||||
var fieldCounter = 0;
|
||||
|
||||
// 添加字段按钮点击事件
|
||||
$('#add-field-btn').on('click', function(){
|
||||
addFormField();
|
||||
});
|
||||
|
||||
// 添加表单字段
|
||||
function addFormField() {
|
||||
fieldCounter++;
|
||||
var fieldId = 'field_' + fieldCounter;
|
||||
|
||||
var fieldHtml = `
|
||||
<div class="form-item" id="${fieldId}">
|
||||
<div class="field-name">
|
||||
<input type="text" class="layui-input field-name-input" placeholder="收集项目名称" value="">
|
||||
</div>
|
||||
<div class="field-placeholder">
|
||||
<input type="text" class="layui-input field-placeholder-input" placeholder="自定义提示文字" value="">
|
||||
</div>
|
||||
<div class="field-type">
|
||||
<select class="field-type-select" lay-filter="field-type-${fieldCounter}">
|
||||
<option value="text">输入框</option>
|
||||
<option value="textarea">多行文本</option>
|
||||
<option value="radio">单选</option>
|
||||
<option value="checkbox">多选按钮</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field-required">
|
||||
<select class="field-required-select">
|
||||
<option value="1">该项必填</option>
|
||||
<option value="0">该项非必填</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="options-container hidden">
|
||||
<div class="options-title">选项设置:</div>
|
||||
<div class="options-list"></div>
|
||||
<button type="button" class="layui-btn layui-btn-xs add-option-btn">添加选项</button>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger remove-field-btn">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
$('#fields-container').append(fieldHtml);
|
||||
|
||||
// 重新渲染表单元素
|
||||
form.render('select');
|
||||
|
||||
// 绑定事件
|
||||
bindFieldEvents(fieldId);
|
||||
}
|
||||
|
||||
// 绑定字段事件
|
||||
function bindFieldEvents(fieldId) {
|
||||
var $field = $('#' + fieldId);
|
||||
|
||||
// 使用当前fieldCounter
|
||||
var currentCounter = fieldCounter;
|
||||
|
||||
// 使用Layui的方式监听选择框变化
|
||||
form.on('select(field-type-' + currentCounter + ')', function(data){
|
||||
var fieldType = data.value;
|
||||
var $optionsContainer = $field.find('.options-container');
|
||||
|
||||
if (fieldType === 'radio' || fieldType === 'checkbox') {
|
||||
$optionsContainer.removeClass('hidden');
|
||||
// 如果没有选项,默认添加一个空选项
|
||||
if ($optionsContainer.find('.option-item').length === 0) {
|
||||
addOption($field);
|
||||
}
|
||||
} else {
|
||||
$optionsContainer.addClass('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
// 添加选项按钮点击事件
|
||||
$field.find('.add-option-btn').on('click', function(){
|
||||
addOption($field);
|
||||
});
|
||||
|
||||
// 删除字段按钮点击事件
|
||||
$field.find('.remove-field-btn').on('click', function(){
|
||||
$field.remove();
|
||||
});
|
||||
}
|
||||
|
||||
// 添加选项函数
|
||||
function addOption($field) {
|
||||
var optionId = 'option_' + Date.now();
|
||||
var optionHtml = `
|
||||
<div class="option-item" id="${optionId}">
|
||||
<input type="text" class="layui-input option-input" placeholder="选项内容">
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger remove-option-btn">删除</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
$field.find('.options-list').append(optionHtml);
|
||||
|
||||
// 绑定选项删除事件
|
||||
$field.find('#' + optionId + ' .remove-option-btn').on('click', function(){
|
||||
$(this).closest('.option-item').remove();
|
||||
});
|
||||
}
|
||||
|
||||
form.verify({
|
||||
title_v: function(value) {
|
||||
if (value == '') {
|
||||
return '请先选择添加标题';
|
||||
}
|
||||
},
|
||||
banner_img: function(value) {
|
||||
if (value == '') {
|
||||
return '请先选择图片';
|
||||
}
|
||||
},
|
||||
s_time: function(value) {
|
||||
if (value == '') {
|
||||
return '请先选择开始时间';
|
||||
}
|
||||
},
|
||||
e_time: function(value) {
|
||||
if (value == '') {
|
||||
return '请先选择结束时间';
|
||||
}
|
||||
},
|
||||
people_num: function(value) {
|
||||
if (value == '') {
|
||||
return '请先输入报名人数';
|
||||
}
|
||||
},
|
||||
});
|
||||
//监听提交
|
||||
form.on('submit(add)',function(data) {
|
||||
// 收集表单数据
|
||||
var formData = {
|
||||
fields: []
|
||||
};
|
||||
|
||||
// 遍历所有字段
|
||||
$('.form-item').each(function(){
|
||||
var $field = $(this);
|
||||
var fieldName = $field.find('.field-name-input').val();
|
||||
var fieldType = $field.find('.field-type-select').val();
|
||||
var placeholder = $field.find('.field-placeholder-input').val();
|
||||
var isMust = $field.find('.field-required-select').val() === '1';
|
||||
|
||||
var fieldData = {
|
||||
name: fieldName,
|
||||
type: fieldType,
|
||||
placeholder: placeholder,
|
||||
is_must: isMust
|
||||
};
|
||||
|
||||
// 如果是选择类型,收集选项
|
||||
if (fieldType === 'radio' || fieldType === 'checkbox') {
|
||||
fieldData.options = [];
|
||||
$field.find('.option-item').each(function(){
|
||||
var optionValue = $(this).find('.option-input').val();
|
||||
if (optionValue) {
|
||||
fieldData.options.push(optionValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
formData.fields.push(fieldData);
|
||||
});
|
||||
|
||||
// 检查fields是否为空
|
||||
if (formData.fields.length === 0) {
|
||||
layer.msg('请先添加收集项目', {icon: 2});
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证每个字段名称不能为空
|
||||
for (var i = 0; i < formData.fields.length; i++) {
|
||||
$('.form-item').eq(i).find('.field-name-input').removeClass('layui-border-red');
|
||||
|
||||
if (!formData.fields[i].name || formData.fields[i].name.trim() === '') {
|
||||
layer.msg('第 ' + (i + 1) + ' 个收集项目的名称不能为空', {icon: 2});
|
||||
$('.form-item').eq(i).find('.field-name-input').addClass('layui-border-red').focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证选择类型的选项不能为空
|
||||
if ((formData.fields[i].type === 'radio' || formData.fields[i].type === 'checkbox') &&
|
||||
(!formData.fields[i].options || formData.fields[i].options.length === 0)) {
|
||||
layer.msg('第 ' + (i + 1) + ' 个收集项目是选择类型,必须至少添加一个选项', {icon: 2});
|
||||
$('.form-item').eq(i).find('.options-container').addClass('layui-border-red');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('表单数据:', formData);
|
||||
add_data(formData)
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
function add_data(formData){
|
||||
if(pd === false){
|
||||
return
|
||||
}
|
||||
var data = {
|
||||
'id':form_data_id_num,
|
||||
'cover_image':$('#banner_img').val(),
|
||||
'title':$('#title_v').val(),
|
||||
'content':html,
|
||||
'form_data':formData.fields,
|
||||
's_time':$('#s_time').val(),
|
||||
'e_time':$('#e_time').val(),
|
||||
'people_num':$('#people_num').val(),
|
||||
'is_only_once':$('#is_only_once').val(),
|
||||
|
||||
}
|
||||
console.log(data);
|
||||
// return
|
||||
pd = false
|
||||
load()
|
||||
$.ajax({
|
||||
url:"/oi/zzt/edit_form_action",
|
||||
dataType: "json",
|
||||
async: true,
|
||||
data: data,
|
||||
type: "POST",
|
||||
success:function(req){
|
||||
c_load()
|
||||
pd = true
|
||||
console.log()
|
||||
if(req.code == 0){
|
||||
layer.alert("修改成功", {icon: 6},function() {
|
||||
xadmin.close();
|
||||
xadmin.father_reload();
|
||||
});
|
||||
}else{
|
||||
layer.alert("修改失败"+req.msg, {icon: 6},function() {
|
||||
xadmin.close();
|
||||
xadmin.father_reload();
|
||||
});
|
||||
}
|
||||
console.log(req)
|
||||
},
|
||||
error:function(){
|
||||
pd = true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function load() {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff']
|
||||
});
|
||||
}
|
||||
function c_load() {
|
||||
layer.close(layer.index)
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,285 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="x-admin-sm">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>表单管理</title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
||||
<link rel="stylesheet" href="/x_admin/css/font.css">
|
||||
<link rel="stylesheet" href="/x_admin/css/xadmin.css">
|
||||
<script src="/x_admin/lib/layui/layui.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/x_admin/js/xadmin.js"></script>
|
||||
<style>
|
||||
/* th{
|
||||
min-width:30px;
|
||||
} */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="x-nav">
|
||||
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
|
||||
<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-row layui-col-space15">
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">
|
||||
<!-- <button class="layui-btn" onclick="xadmin.open('添加','/oi/zzt/add_form','90%','80%')"><i class="layui-icon"></i>添加</button> -->
|
||||
<button class="layui-btn" onclick="xadmin.open('添加','/oi/zzt/add_form2','90%','80%')"><i class="layui-icon"></i>添加</button>
|
||||
</div>
|
||||
<div class="layui-card-body layui-table-body layui-table-main">
|
||||
<table class="layui-table layui-form">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>活动标题</th>
|
||||
<!-- <th>活动封面</th> -->
|
||||
<th>报名人数(当前/总计)</th>
|
||||
<th>报名日期</th>
|
||||
<th>创建时间</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id='content'>
|
||||
|
||||
{volist name="result" id="vo"}
|
||||
<tr>
|
||||
<td>{$vo.title}</td>
|
||||
<!-- <td>{$vo.pic}</td> -->
|
||||
<td>{$vo.people_num_now}/{$vo.people_num}</td>
|
||||
<td>{$vo.start_time}至{$vo.end_time}</td>
|
||||
<td>{$vo.create_time}</td>
|
||||
<td class="td-status">
|
||||
{if condition="$vo.is_del == 1"}
|
||||
<span onclick="app_stop(this,'{$vo.id}')" class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled" title="停用">已停用</span>
|
||||
{else /}
|
||||
<span onclick="app_stop(this,'{$vo.id}')" class="layui-btn layui-btn-normal layui-btn-mini" title="启用">已启用</span>
|
||||
{/if}
|
||||
</td>
|
||||
<td>
|
||||
<button class="layui-btn" onclick="xadmin.open('修改','/oi/zzt/edit_form?id={$vo.id}','90%','80%')">修改</button>
|
||||
<button class="layui-btn" onclick="down(this,'{$vo.id}')">下载报名信息</button>
|
||||
</td>
|
||||
</tr>
|
||||
{/volist}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="layui-card-body ">
|
||||
<div id="page" style="text-align: center;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
var form
|
||||
layui.use(['laydate','form'], function(){
|
||||
var laydate = layui.laydate;
|
||||
form = layui.form;
|
||||
});
|
||||
var page_num;
|
||||
var laypage;
|
||||
var all_page = "{$num}";
|
||||
layui.use('laypage', function () {
|
||||
laypage = layui.laypage;
|
||||
|
||||
//执行一个laypage实例
|
||||
laypage.render({
|
||||
elem: 'page',
|
||||
count: all_page, //数据总数,从服务端得到
|
||||
limit: 10,
|
||||
groups:10,
|
||||
jump: function (obj, first) {
|
||||
//首次不执行
|
||||
if (!first) {
|
||||
//obj包含了当前分页的所有参数,比如:
|
||||
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
|
||||
console.log(obj.limit); //得到每页显示的条数
|
||||
page_num = obj.curr;
|
||||
find("n")
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*用户-停用*/
|
||||
function app_stop(obj,id){
|
||||
|
||||
// return
|
||||
var title = '',is_del,num
|
||||
if($(obj).attr('title')=='启用'){
|
||||
title = '停用'
|
||||
is_del = 1
|
||||
num = 5
|
||||
}else{
|
||||
title = '启用'
|
||||
is_del = 0
|
||||
num = 6
|
||||
}
|
||||
// console.log('点击时'+$(obj).attr('title')+'====='+id+'===传到后台是否删除:'+is_del)
|
||||
layer.confirm('确认要'+ title +'吗?',function(index){
|
||||
load()
|
||||
$.ajax({
|
||||
url:"/oi/zzt/del_action", //请求的url地址
|
||||
dataType:"json", //返回格式为json
|
||||
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data:{"id":id,'is_del':is_del}, //参数值
|
||||
type:"POST", //请求方式
|
||||
success:function(req){
|
||||
c_load()
|
||||
//请求成功时处理
|
||||
if(req['code'] == 0){
|
||||
//发异步把用户状态进行更改
|
||||
$(obj).attr('title',title)
|
||||
if(is_del == 1){
|
||||
$(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已'+ title);
|
||||
}else{
|
||||
$(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已'+ title);
|
||||
}
|
||||
layer.msg('已'+ title,{icon: num});
|
||||
}else{
|
||||
layer.msg('操作失败!',{icon: 5});
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
//请求出错处理
|
||||
}});
|
||||
});
|
||||
}
|
||||
|
||||
function find(pd) {
|
||||
if(!page_num || pd == 'y'){
|
||||
page_num = 1;
|
||||
}
|
||||
|
||||
page({
|
||||
"status_num":$('#status_num').val(),
|
||||
"tel":$('#tel').val(),
|
||||
"email":$('#email').val(),
|
||||
"s_time":$('#s_time').val(),
|
||||
"e_time":$('#e_time').val(),
|
||||
"page_num":page_num,
|
||||
"tt":1},pd);
|
||||
}
|
||||
function page(data,pd) {
|
||||
console.log(data)
|
||||
load()
|
||||
$.ajax({
|
||||
url: "/oi/zzt/form_page", //请求的url地址s
|
||||
dataType: "json", //返回格式为json
|
||||
async: true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||
data: data, //参数值
|
||||
type: "POST", //请求方式
|
||||
success: function (req) {
|
||||
console.log(req)
|
||||
c_load();
|
||||
if (req['code'] == 0) {
|
||||
|
||||
var str,str_s,str_c,str_all="";
|
||||
|
||||
for (let i = 0; i < req['data']['data'].length; i++) {
|
||||
if(req['data']['data'][i]['is_del'] == 1){
|
||||
str = '<span onclick="app_stop(this,\''+req['data']['data'][i]['id']+'\')" class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled" title="停用">已停用</span>'
|
||||
}else{
|
||||
str = '<span onclick="app_stop(this,\''+ req['data']['data'][i]['id'] +'\')" class="layui-btn layui-btn-normal layui-btn-mini" title="启用">已启用</span>'
|
||||
}
|
||||
str_c = "<tr>"+
|
||||
'<td>'+req['data']['data'][i]['title']+'</td>'+
|
||||
'<td>'+req['data']['data'][i]['people_num_now']+'/'+req['data']['data'][i]['people_num']+'</td>'+
|
||||
'<td>'+req['data']['data'][i]['start_time']+'至'+req['data']['data'][i]['end_time']+'</td>'+
|
||||
'<td>'+req['data']['data'][i]['create_time']+'</td>'+
|
||||
'<td class="td-status">'+
|
||||
str+
|
||||
'</td>'
|
||||
'</tr>'
|
||||
str_all = str_all+str_c;
|
||||
}
|
||||
$('#content').html(str_all);
|
||||
|
||||
form.render();
|
||||
if(pd == 'y'){
|
||||
$("#page").html("")
|
||||
laypage.render({
|
||||
elem: 'page',
|
||||
count: req['data']['num'], //数据总数,从服务端得到
|
||||
limit: 10,
|
||||
groups:10,
|
||||
jump: function (obj, first) {
|
||||
//首次不执行
|
||||
if (!first) {
|
||||
//obj包含了当前分页的所有参数,比如:
|
||||
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
|
||||
console.log(obj.limit); //得到每页显示的条数
|
||||
page_num = obj.curr;
|
||||
// page({"page":page_num,"tt":1});
|
||||
find("n")
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
layer.msg(req['msg'])
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
//请求出错处理
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function down(obj, id) {
|
||||
// 显示加载状态
|
||||
obj.innerHTML = '下载中...';
|
||||
obj.disabled = true;
|
||||
|
||||
// 先发送HEAD请求检查状态
|
||||
fetch('/oi/zzt/down_data_action?id=' + id, { method: 'HEAD' })
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
// 状态正常,直接下载
|
||||
window.location.href = '/oi/zzt/down_data_action?id=' + id;
|
||||
} else {
|
||||
// 检查是否是JSON错误响应
|
||||
return response.text().then(text => {
|
||||
try {
|
||||
const errorData = JSON.parse(text);
|
||||
if (errorData.code === 10002) {
|
||||
throw new Error('未找到对应活动');
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error('下载失败:' + (errorData?.message || '未知错误'));
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert(error.message);
|
||||
})
|
||||
.finally(() => {
|
||||
// 恢复按钮状态
|
||||
obj.innerHTML = '下载报名人员';
|
||||
obj.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
//加载提示开启
|
||||
function load() {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
}
|
||||
// 关闭加载提示
|
||||
function c_load() {
|
||||
layer.close(layer.index)
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
|
|
@ -446,12 +446,14 @@ class Index extends Base{
|
|||
$result['stage'] = $value['value'];
|
||||
}
|
||||
}
|
||||
|
||||
// 从这里开始进入体脂还是体测的判断
|
||||
$result['card_order'] = $result['card_order'] == ""?[]:explode(',',$result['card_order']);
|
||||
if($result['measure_model'] == 1){// 这里是体测
|
||||
$calculation_results = $this->get_user_card_data_list($result,$result['id']);
|
||||
$result['card_data_list'] = $calculation_results[0];
|
||||
$result['card_order'] = $calculation_results[1];
|
||||
// dump($result);
|
||||
|
||||
}else if($result['measure_model'] == 2){// 这里是体脂
|
||||
$result['card_data_list'] = [];
|
||||
|
|
@ -589,17 +591,18 @@ class Index extends Base{
|
|||
unset($data['token']);
|
||||
if(!$this->is_num_array(explode(',',$data['card_order']))){
|
||||
// 失败
|
||||
// dump($data['card_order']);
|
||||
// dump(explode(',',$data['card_order']));
|
||||
$this->record_api_log($data, null, ['code'=>10001,'msg'=>'数据内参数格式或值错误',[]]);
|
||||
return $this->msg(10005,'数据内参数格式或值错误');
|
||||
}
|
||||
$result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]);
|
||||
if($result){
|
||||
// 成功
|
||||
$this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]);
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
// 失败
|
||||
$this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]);
|
||||
// $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]);
|
||||
return $this->msg(10002);
|
||||
}
|
||||
|
||||
|
|
@ -713,6 +716,7 @@ class Index extends Base{
|
|||
public function get_user_card_data_list($data,$aud_id){
|
||||
$result = [];
|
||||
$db_arr = [];
|
||||
|
||||
foreach ($data['card_order'] as $key => $value) {
|
||||
if(in_array($value,$this->default_card)){
|
||||
// 过滤掉老版本的(268选项卡)
|
||||
|
|
@ -732,6 +736,7 @@ class Index extends Base{
|
|||
}
|
||||
}
|
||||
}
|
||||
// dump($data);
|
||||
$data['card_order'] = array_values($data['card_order']);
|
||||
// 获取卡片背景图,及背景色信息及其他信息
|
||||
$card_all_data = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,page_url_record,page_url_report,page_url_bluetooth,key_word,background_color,background_pic')->select();
|
||||
|
|
|
|||
|
|
@ -341,4 +341,28 @@ return [
|
|||
// 数据库调试模式
|
||||
'debug' => true,
|
||||
],
|
||||
// 第5个数据库配置(设备录入)
|
||||
'zzt_db' => [
|
||||
// 数据库类型
|
||||
'type' => 'sqlsrv',
|
||||
// 服务器地址
|
||||
'hostname' => '123.60.2.99',
|
||||
// 'hostname' => '127.0.0.1',
|
||||
// 数据库名
|
||||
'database' => 'jt_shanghui',
|
||||
// 用户名
|
||||
'username' => 'jutian_user',
|
||||
// 密码
|
||||
'password' => 'jutian1qaz@WSX',
|
||||
// 端口
|
||||
'hostport' => '4331',
|
||||
// 数据库连接参数
|
||||
'params' => [],
|
||||
// 数据库编码默认采用utf8
|
||||
'charset' => 'utf8',
|
||||
// 数据库表前缀
|
||||
'prefix' => '',
|
||||
// 数据库调试模式
|
||||
'debug' => true,
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -458,18 +458,18 @@ 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');
|
||||
Route::any('/kitchenscale2/wechat_quick_login', 'app/kitchenscale2/app.index/wechat_quick_login');
|
||||
|
||||
// 公共内容################################################################
|
||||
// 获取用户上传图片列表
|
||||
Route::any('/kitchenscale/pic_chose_list', 'app/kitchenscale/app.base/pic_chose_list');
|
||||
Route::any('/testedition/kitchenscale/pic_chose_list', 'app/kitchenscale/testapp.base/pic_chose_list');
|
||||
// 用户多图上传接口
|
||||
Route::any('/kitchenscale2/pic_chose_list', 'app/kitchenscale2/app.base/pic_chose_list');
|
||||
// 用户单图上传接口
|
||||
Route::any('/kitchenscale/pic_upload_one_action', 'app/kitchenscale/app.base/pic_upload_one_action');
|
||||
Route::any('/testedition/kitchenscale/pic_upload_one_action', 'app/kitchenscale/testapp.base/pic_upload_one_action');
|
||||
Route::any('/kitchenscale2/pic_upload_one_action', 'app/kitchenscale2/app.base/pic_upload_one_action');
|
||||
// 用户多图上传接口
|
||||
Route::any('/kitchenscale/pic_upload_action', 'app/kitchenscale/app.base/pic_upload_action');
|
||||
Route::any('/testedition/kitchenscale/pic_upload_action', 'app/kitchenscale/testapp.base/pic_upload_action');
|
||||
Route::any('/kitchenscale2/pic_upload_action', 'app/kitchenscale2/app.base/pic_upload_action');
|
||||
|
||||
|
||||
|
||||
|
|
@ -479,92 +479,107 @@ Route::any('/kitchenscale/login_invalid_version', 'app/Kitchenscale/app.Index/lo
|
|||
Route::any('/testedition/kitchenscale/login_invalid_version', 'app/kitchenscale/testapp.index/login_invalid_version');
|
||||
// 获取配置类信息
|
||||
Route::any('/kitchenscale/get_default_config', 'app/Kitchenscale/app.Index/get_default_config');
|
||||
Route::any('/testedition/kitchenscale/get_default_config', 'app/kitchenscale/testapp.index/get_default_config');
|
||||
Route::any('/kitchenscale2/get_default_config', 'app/Kitchenscale2/app.Index/get_default_config');
|
||||
// 获取首页页面展示数据
|
||||
Route::any('/kitchenscale/get_homepage_information', 'app/kitchenscale/app.index/get_homepage_information');
|
||||
Route::any('/testedition/kitchenscale/get_homepage_information', 'app/kitchenscale/testapp.index/get_homepage_information');
|
||||
// 首页搜索接口
|
||||
Route::any('/kitchenscale/search_column', 'app/kitchenscale/app.index/search_column');
|
||||
Route::any('/testedition/kitchenscale/search_column', 'app/kitchenscale/testapp.index/search_column');
|
||||
Route::any('/kitchenscale2/search_column', 'app/kitchenscale2/app.index/search_column');
|
||||
|
||||
|
||||
// 菜谱内容################################################################
|
||||
// 添加菜谱
|
||||
Route::any('/kitchenscale/add_cookbook', 'app/kitchenscale/app.cookbook/add_cookbook');
|
||||
Route::any('/testedition/kitchenscale/add_cookbook', 'app/kitchenscale/testapp.cookbook/add_cookbook');
|
||||
Route::any('/kitchenscale2/add_cookbook', 'app/kitchenscale2/app.cookbook/add_cookbook');
|
||||
// 修改菜谱
|
||||
Route::any('/kitchenscale/update_cookbook', 'app/kitchenscale/app.cookbook/update_cookbook');
|
||||
Route::any('/testedition/kitchenscale/update_cookbook', 'app/kitchenscale/testapp.cookbook/update_cookbook');
|
||||
Route::any('/kitchenscale2/update_cookbook', 'app/kitchenscale2/app.cookbook/update_cookbook');
|
||||
|
||||
// 根据菜谱标签查询列表(首页用)
|
||||
Route::any('/kitchenscale/find_by_cook_label', 'app/kitchenscale/app.cookbook/find_by_cook_label');
|
||||
Route::any('/testedition/kitchenscale/find_by_cook_label', 'app/kitchenscale/testapp.cookbook/find_by_cook_label');
|
||||
Route::any('/kitchenscale2/find_by_cook_label', 'app/kitchenscale2/app.cookbook/find_by_cook_label');
|
||||
// 根据食材详细查找列表
|
||||
Route::any('/kitchenscale/find_by_food', 'app/kitchenscale/app.cookbook/find_by_food');
|
||||
Route::any('/testedition/kitchenscale/find_by_food', 'app/kitchenscale/testapp.cookbook/find_by_food');
|
||||
Route::any('/kitchenscale2/find_by_food', 'app/kitchenscale2/app.cookbook/find_by_food');
|
||||
// 查询食谱的详情
|
||||
Route::any('/kitchenscale/cookbook_details', 'app/kitchenscale/app.cookbook/cookbook_details');
|
||||
Route::any('/testedition/kitchenscale/cookbook_details', 'app/kitchenscale/testapp.cookbook/cookbook_details');
|
||||
Route::any('/kitchenscale2/cookbook_details', 'app/kitchenscale2/app.cookbook/cookbook_details');
|
||||
// 关注菜谱
|
||||
Route::any('/kitchenscale/cookbook_follow', 'app/kitchenscale/app.cookbook/cookbook_follow');
|
||||
Route::any('/testedition/kitchenscale/cookbook_follow', 'app/kitchenscale/testapp.cookbook/cookbook_follow');
|
||||
// 收藏菜谱
|
||||
Route::any('/kitchenscale/cookbook_like', 'app/kitchenscale/app.cookbook/cookbook_like');
|
||||
Route::any('/testedition/kitchenscale/cookbook_like', 'app/kitchenscale/testapp.cookbook/cookbook_like');
|
||||
Route::any('/kitchenscale2/cookbook_like', 'app/kitchenscale2/app.cookbook/cookbook_like');
|
||||
// 获取当前食材重量卡路里
|
||||
Route::any('/kitchenscale/food_count_kcal', 'app/kitchenscale/app.cookbook/food_count_kcal');
|
||||
Route::any('/testedition/kitchenscale/food_count_kcal', 'app/kitchenscale/testapp.cookbook/food_count_kcal');
|
||||
Route::any('/kitchenscale2/food_count_kcal', 'app/kitchenscale2/app.cookbook/food_count_kcal');
|
||||
// 获取当前食材重量卡路里
|
||||
Route::any('/kitchenscale/find_food', 'app/kitchenscale/app.cookbook/find_food');
|
||||
Route::any('/testedition/kitchenscale/find_food', 'app/kitchenscale/testapp.cookbook/find_food');
|
||||
Route::any('/kitchenscale2/find_food', 'app/kitchenscale2/app.cookbook/find_food');
|
||||
// 获取当前食材重量卡路里
|
||||
Route::any('/kitchenscale/get_food_list', 'app/kitchenscale/app.cookbook/get_food_list');
|
||||
Route::any('/testedition/kitchenscale/get_food_list', 'app/kitchenscale/testapp.cookbook/get_food_list');
|
||||
Route::any('/kitchenscale2/get_food_list', 'app/kitchenscale2/app.cookbook/get_food_list');
|
||||
// 获取所有食谱label
|
||||
Route::any('/kitchenscale/get_cookbook_label_list', 'app/kitchenscale/app.cookbook/get_cookbook_label_list');
|
||||
Route::any('/testedition/kitchenscale/get_cookbook_label_list', 'app/kitchenscale/testapp.cookbook/get_cookbook_label_list');
|
||||
// 获取查询页页面导航食材列表
|
||||
Route::any('/kitchenscale/get_search_food_page_list', 'app/kitchenscale/app.cookbook/get_search_food_page_list');
|
||||
Route::any('/testedition/kitchenscale/get_search_food_page_list', 'app/kitchenscale/testapp.cookbook/get_search_food_page_list');
|
||||
Route::any('/kitchenscale2/get_search_food_page_list', 'app/kitchenscale2/app.cookbook/get_search_food_page_list');
|
||||
|
||||
|
||||
// 计食器################################################################
|
||||
// 添加每日摄入记录
|
||||
Route::any('/kitchenscale/add_intake_food', 'app/kitchenscale/app.countfood/add_intake_food');
|
||||
Route::any('/testedition/kitchenscale/add_intake_food', 'app/kitchenscale/testapp.countfood/add_intake_food');
|
||||
Route::any('/kitchenscale2/add_intake_food', 'app/kitchenscale2/app.countfood/add_intake_food');
|
||||
// 获取记食器板块内容
|
||||
Route::any('/kitchenscale/get_countfoot_content', 'app/kitchenscale/app.countfood/get_countfoot_content');
|
||||
Route::any('/testedition/kitchenscale/get_countfoot_content', 'app/kitchenscale/testapp.countfood/get_countfoot_content');
|
||||
Route::any('/kitchenscale2/get_countfoot_content', 'app/kitchenscale2/app.countfood/get_countfoot_content');
|
||||
// 获取记食器记录
|
||||
Route::any('/kitchenscale/get_log_list', 'app/kitchenscale/app.countfood/get_log_list');
|
||||
Route::any('/testedition/kitchenscale/get_log_list', 'app/kitchenscale/testapp.countfood/get_log_list');
|
||||
Route::any('/kitchenscale2/get_log_list', 'app/kitchenscale2/app.countfood/get_log_list');
|
||||
// 计食器板块-设置内容
|
||||
Route::any('/kitchenscale/set_up_content', 'app/kitchenscale/app.countfood/set_up_content');
|
||||
Route::any('/testedition/kitchenscale/set_up_content', 'app/kitchenscale/testapp.countfood/set_up_content');
|
||||
Route::any('/kitchenscale2/set_up_content', 'app/kitchenscale2/app.countfood/set_up_content');
|
||||
// 设置用户的卡路里
|
||||
Route::any('/kitchenscale/set_user_kcal', 'app/kitchenscale/app.countfood/set_user_kcal');
|
||||
Route::any('/testedition/kitchenscale/set_user_kcal', 'app/kitchenscale/testapp.countfood/set_user_kcal');
|
||||
Route::any('/kitchenscale2/set_user_kcal', 'app/kitchenscale2/app.countfood/set_user_kcal');
|
||||
// 删除用户某个饮食记录
|
||||
Route::any('/kitchenscale/del_user_eat_log', 'app/kitchenscale/app.countfood/del_user_eat_log');
|
||||
Route::any('/testedition/kitchenscale/del_user_eat_log', 'app/kitchenscale/testapp.countfood/del_user_eat_log');
|
||||
Route::any('/kitchenscale2/del_user_eat_log', 'app/kitchenscale/app.countfood/del_user_eat_log');
|
||||
// 删除用户某个饮食记录
|
||||
// Route::any('/kitchenscale/del_user_eat_list_log', 'app/kitchenscale/app.countfood/del_user_eat_list_log');
|
||||
Route::any('/kitchenscale2/del_user_eat_list_log', 'app/kitchenscale2/app.countfood/del_user_eat_list_log');
|
||||
|
||||
|
||||
|
||||
|
||||
// 我的################################################################
|
||||
// 获取角色信息
|
||||
Route::any('/kitchenscale/get_user_msg', 'app/kitchenscale/app.usercenter/get_user_msg');
|
||||
Route::any('/testedition/kitchenscale/get_user_msg', 'app/kitchenscale/testapp.usercenter/get_user_msg');
|
||||
Route::any('/kitchenscale2/get_user_msg', 'app/kitchenscale2/app.usercenter/get_user_msg');
|
||||
// 修改角色信息
|
||||
Route::any('/kitchenscale/update_user_msg', 'app/kitchenscale/app.usercenter/update_user_msg');
|
||||
Route::any('/testedition/kitchenscale/update_user_msg', 'app/kitchenscale/testapp.usercenter/update_user_msg');
|
||||
Route::any('/kitchenscale2/update_user_msg', 'app/kitchenscale2/app.usercenter/update_user_msg');
|
||||
// 账号收藏点赞列表
|
||||
Route::any('/kitchenscale/get_user_collect_list', 'app/kitchenscale/app.usercenter/get_user_collect_list');
|
||||
Route::any('/testedition/kitchenscale/get_user_collect_list', 'app/kitchenscale/testapp.usercenter/get_user_collect_list');
|
||||
Route::any('/kitchenscale2/get_user_collect_list', 'app/kitchenscale2/app.usercenter/get_user_collect_list');
|
||||
// 我的菜谱
|
||||
Route::any('/kitchenscale/get_my_cookbook', 'app/kitchenscale/app.usercenter/get_my_cookbook');
|
||||
Route::any('/testedition/kitchenscale/get_my_cookbook', 'app/kitchenscale/testapp.usercenter/get_my_cookbook');
|
||||
Route::any('/kitchenscale2/get_my_cookbook', 'app/kitchenscale2/app.usercenter/get_my_cookbook');
|
||||
// 菜谱删除
|
||||
Route::any('/kitchenscale/del_my_cookbook', 'app/kitchenscale/app.usercenter/del_my_cookbook');
|
||||
Route::any('/testedition/kitchenscale/del_my_cookbook', 'app/kitchenscale/testapp.usercenter/del_my_cookbook');
|
||||
Route::any('/kitchenscale2/del_my_cookbook', 'app/kitchenscale2/app.usercenter/del_my_cookbook');
|
||||
// 删除用户搜索记录
|
||||
Route::any('/kitchenscale/del_search_history', 'app/kitchenscale/app.usercenter/del_search_history');
|
||||
Route::any('/kitchenscale2/del_search_history', 'app/kitchenscale2/app.usercenter/del_search_history');
|
||||
// 商务合作
|
||||
Route::any('/kitchenscale/business_cooperation', 'app/kitchenscale/app.usercenter/business_cooperation');
|
||||
Route::any('/kitchenscale2/business_cooperation', 'app/kitchenscale2/app.usercenter/business_cooperation');
|
||||
// 商务合作提交
|
||||
Route::any('/kitchenscale/business_cooperation_action', 'app/kitchenscale/app.usercenter/business_cooperation_action');
|
||||
Route::any('/kitchenscale2/business_cooperation_action', 'app/kitchenscale2/app.usercenter/business_cooperation_action');
|
||||
|
||||
|
||||
// 百度图片识别接口################################################################
|
||||
// 获取AccessToken
|
||||
|
|
@ -572,6 +587,7 @@ Route::any('/testedition/kitchenscale/del_my_cookbook', 'app/kitchenscale/testap
|
|||
// Route::any('/testedition/kitchenscale/baidu_get_accesstoken', 'app/kitchenscale/testapp.aipart/baidu_get_accesstoken');
|
||||
// 识别食材
|
||||
Route::any('/kitchenscale/baidu_identify_food', 'app/kitchenscale/app.aipart/baidu_identify_food');
|
||||
Route::any('/kitchenscale2/baidu_identify_food', 'app/kitchenscale2/app.aipart/baidu_identify_food');
|
||||
|
||||
|
||||
|
||||
|
|
@ -694,7 +710,43 @@ Route::any('/reedaw/role_list', 'app/NewReedaw/app.role/role_list');
|
|||
Route::any('/reedaw/body_report', 'app/NewReedaw/app.body/body_report');
|
||||
|
||||
|
||||
#######################################################################下面是外部接口#######################################################################
|
||||
#############################################################################################################################################################
|
||||
|
||||
######################################################################智照团(↓)
|
||||
// 智照团选择上传
|
||||
Route::any('/oi/zzt/pic_upload', 'app/OutsideInterface/ZhiZhaoTuan.base/pic_upload');
|
||||
Route::any('/oi/zzt/pic_upload_action', 'app/OutsideInterface/ZhiZhaoTuan.base/pic_upload_action');
|
||||
// 富文本编辑器内上传
|
||||
Route::any('/oi/zzt/upload_pic_action', 'app/OutsideInterface/ZhiZhaoTuan.base/upload_pic_action');
|
||||
Route::any('/oi/zzt/upload_video_action', 'app/OutsideInterface/ZhiZhaoTuan.base/upload_video_action');
|
||||
|
||||
// 智照团form表单列表页
|
||||
Route::any('/oi/zzt/form_page', 'app/OutsideInterface/ZhiZhaoTuan.index/index');
|
||||
// 智照团form表单添加页
|
||||
// Route::any('/oi/zzt/add_form', 'app/OutsideInterface/ZhiZhaoTuan.index/add_form');
|
||||
Route::any('/oi/zzt/add_form2', 'app/OutsideInterface/ZhiZhaoTuan.index/add_form2');
|
||||
// 智照团form表单添加动作
|
||||
Route::any('/oi/zzt/add_form_action', 'app/OutsideInterface/ZhiZhaoTuan.index/add_form_action');
|
||||
// 智照团form表单修改页
|
||||
Route::any('/oi/zzt/edit_form', 'app/OutsideInterface/ZhiZhaoTuan.index/edit_form');
|
||||
// 智照团form表单添加动作
|
||||
Route::any('/oi/zzt/edit_form_action', 'app/OutsideInterface/ZhiZhaoTuan.index/edit_form_action');
|
||||
// 智照团form表单下架/上架动作
|
||||
Route::any('/oi/zzt/del_action', 'app/OutsideInterface/ZhiZhaoTuan.index/del_action');
|
||||
// 智照团form表单下载数据动作
|
||||
Route::any('/oi/zzt/down_data_action', 'app/OutsideInterface/ZhiZhaoTuan.index/down_data_action');
|
||||
|
||||
|
||||
// 智照团活动列表页API
|
||||
Route::any('/oi/zzt/activity_list', 'app/OutsideInterface/ZhiZhaoTuan.ApiJk/activity_list');
|
||||
// 智照团活动详情页API
|
||||
Route::any('/oi/zzt/details_data', 'app/OutsideInterface/ZhiZhaoTuan.ApiJk/details_data');
|
||||
// 智照团活动提交API
|
||||
Route::any('/oi/zzt/save_activity_data', 'app/OutsideInterface/ZhiZhaoTuan.ApiJk/save_activity_data');
|
||||
|
||||
|
||||
######################################################################互抖团(↓)
|
||||
|
||||
|
||||
|
||||
|
|
@ -715,6 +767,7 @@ Route::any('/ceshiyong', 'app/base/ceshiyong');
|
|||
Route::any('/testedition/ceshiyong', 'testapp/base/ceshiyong');
|
||||
|
||||
Route::any('/kitchenscale/chuli_shuju', 'app/kitchenscale/app.cookbook/chuli_shuju');
|
||||
Route::any('/kitchenscale2/chuli_shuju', 'app/kitchenscale2/app.cookbook/chuli_shuju');
|
||||
|
||||
|
||||
// 测试用控制器
|
||||
|
|
|
|||
Loading…
Reference in New Issue