Commit 228dd133 authored by 潘梓豪's avatar 潘梓豪

更新路由 api接口

parent afe50bf4
查找绑定的本机产品
/*if (count($rs)<=0){
$rs=$database->query("select node__field_production_name.field_production_name_value as production_name, ".
"node__field_scene_name.field_scene_name_value as scene_name, node.nid as production_id, node__field_download_url.field_download_url_value as production_download_url, ".
"node__field_belong_computer.computer_code as production_robot_code,node__field_app_name.field_app_name_value as app_name ".
"from {node} as node left join {node__field_production_name} as node__field_production_name on node__field_production_name.entity_id=node.nid ".
"left join {node__field_scene_name} as node__field_scene_name on node__field_scene_name.entity_id=node.nid ".
"left join {node__field_download_url} as node__field_download_url on node__field_download_url.entity_id=node.nid ".
"left join {node__field_app_name} as node__field_app_name on node__field_app_name.entity_id=node.nid ".
// "left join (select node__field_app_path.entity_id,node__field_app_path.field_app_path_value,node__field_production.field_production_target_id ".
// "from {node__field_app_path} as node__field_app_path left join {node__field_user} as node__field_user on node__field_app_path.entity_id=node__field_user.entity_id ".
// "left join {node__field_production} as node__field_production on node__field_app_path.entity_id=node__field_production.entity_id ".
// "where node__field_user.field_user_target_id= :userid and node__field_app_path.bundle='setting_msg') as node__field_app_path on node__field_app_path.field_production_target_id=node.nid ".
"left join ( select node__field_computer_code.field_computer_code_value as computer_code,node__field_user.field_user_target_id,node__field_production.field_production_target_id from {node__field_belong_computer} as node__field_belong_computer ".
"left join {node__field_computer_code} as node__field_computer_code on node__field_belong_computer.field_belong_computer_target_id=node__field_computer_code.entity_id ".
"left join {node__field_user} as node__field_user on node__field_computer_code.entity_id =node__field_user.entity_id ".
"left join {node__field_production} as node__field_production on node__field_production.entity_id=node__field_belong_computer.entity_id ".
"where (node__field_user.field_user_target_id= :userid and node__field_computer_code.field_computer_code_value= :code ) and node__field_belong_computer.bundle='register_robot_code' ) as node__field_belong_computer on node__field_belong_computer.field_production_target_id=node.nid ".
/* "left join (select node__field_robot_code.field_robot_code_value,node__field_production.field_production_target_id,node__field_user.field_user_target_id from {node__field_robot_code} as node__field_robot_code left join {node__field_user} as node__field_user on node__field_robot_code.entity_id=node__field_user.entity_id ".
"left join {node__field_production} as node__field_production on node__field_robot_code.entity_id=node__field_production.entity_id where node__field_user.field_user_target_id= :userid and node__field_robot_code.bundle='register_robot_code' ) as node__field_robot_code on node__field_robot_code.field_production_target_id=node.nid ".
"where node.type='unity_production' and (node__field_belong_computer.field_user_target_id= :userid )and node__field_production_name.field_production_name_value like concat('%', :name ,'%') ",
[
':userid'=>$uid,
':name'=>$_GET['search_txt'],
':code'=>$_GET['code']
])->fetchAll();
}*/
......@@ -60,50 +60,55 @@ public function getProductionList(){
$uid = \Drupal::currentUser()->id();
$database = \Drupal::database();
//先查找订单内容
//查找订单内容
$rs=$database->query("select node__field_production_name.field_production_name_value as production_name, ".
"node__field_scene_name.field_scene_name_value as scene_name, node__field_production.field_production_target_id as production_id, node__field_download_url.field_download_url_value as production_download_url, ".
"node__field_app_name.field_app_name_value as app_name ".
"node__field_production.field_production_target_id as production_id, node__field_download_url.field_download_url_value as production_download_url, ".
"node__field_app_name.field_app_name_value as app_name,node__field_belong_computer.computer_code ".
"from {node} as node left join {node__field_production} as node__field_production on node.nid=node__field_production.entity_id ".
"left join {node__field_production_name} as node__field_production_name on node__field_production_name.entity_id=node__field_production.field_production_target_id ".
"left join {node__field_scene_name} as node__field_scene_name on node__field_scene_name.entity_id=node__field_production.field_production_target_id ".
//"left join {node__field_scene_name} as node__field_scene_name on node__field_scene_name.entity_id=node__field_production.field_production_target_id ".
"left join {node__field_download_url} as node__field_download_url on node__field_download_url.entity_id=node__field_production.field_production_target_id ".
"left join {node__field_app_name} as node__field_app_name on node__field_app_name.entity_id=node__field_production.field_production_target_id ".
"left join {node__field_user} as node__field_user on node__field_user.entity_id=node.nid ".
"left join ( select node__field_computer_code.field_computer_code_value as computer_code,node__field_user.field_user_target_id,node__field_production.field_production_target_id from {node__field_belong_computer} as node__field_belong_computer ".
"left join {node__field_computer_code} as node__field_computer_code on node__field_belong_computer.field_belong_computer_target_id=node__field_computer_code.entity_id ".
"left join {node__field_user} as node__field_user on node__field_computer_code.entity_id =node__field_user.entity_id ".
"left join {node__field_production} as node__field_production on node__field_production.entity_id=node__field_belong_computer.entity_id ".
"where (node__field_user.field_user_target_id= :userid and node__field_computer_code.field_computer_code_value= :code ) and node__field_belong_computer.bundle='register_robot_code' ) as node__field_belong_computer on node__field_belong_computer.field_production_target_id=node__field_production.field_production_target_id ".
"where node.type='production_order' and node__field_user.field_user_target_id= :userid and node__field_production_name.field_production_name_value like concat('%', :name ,'%') ",
[
':userid'=>$uid,
':name'=>$_GET['search_txt'],
':code'=>$_GET['code']
])->fetchAll();
if (count($rs)<=0){
$rs=$database->query("select node__field_production_name.field_production_name_value as production_name, ".
"node__field_scene_name.field_scene_name_value as scene_name, node.nid as production_id, node__field_download_url.field_download_url_value as production_download_url, ".
"node__field_belong_computer.computer_code as production_robot_code,node__field_app_name.field_app_name_value as app_name ".
"from {node} as node left join {node__field_production_name} as node__field_production_name on node__field_production_name.entity_id=node.nid ".
"left join {node__field_scene_name} as node__field_scene_name on node__field_scene_name.entity_id=node.nid ".
"left join {node__field_download_url} as node__field_download_url on node__field_download_url.entity_id=node.nid ".
"left join {node__field_app_name} as node__field_app_name on node__field_app_name.entity_id=node.nid ".
// "left join (select node__field_app_path.entity_id,node__field_app_path.field_app_path_value,node__field_production.field_production_target_id ".
// "from {node__field_app_path} as node__field_app_path left join {node__field_user} as node__field_user on node__field_app_path.entity_id=node__field_user.entity_id ".
// "left join {node__field_production} as node__field_production on node__field_app_path.entity_id=node__field_production.entity_id ".
// "where node__field_user.field_user_target_id= :userid and node__field_app_path.bundle='setting_msg') as node__field_app_path on node__field_app_path.field_production_target_id=node.nid ".
"left join ( select node__field_computer_code.field_computer_code_value as computer_code,node__field_user.field_user_target_id,node__field_production.field_production_target_id from {node__field_belong_computer} as node__field_belong_computer ".
"left join {node__field_computer_code} as node__field_computer_code on node__field_belong_computer.field_belong_computer_target_id=node__field_computer_code.entity_id ".
"left join {node__field_user} as node__field_user on node__field_computer_code.entity_id =node__field_user.entity_id ".
"left join {node__field_production} as node__field_production on node__field_production.entity_id=node__field_belong_computer.entity_id ".
"where (node__field_user.field_user_target_id= :userid and node__field_computer_code.field_computer_code_value= :code ) and node__field_belong_computer.bundle='register_robot_code' ) as node__field_belong_computer on node__field_belong_computer.field_production_target_id=node.nid ".
/* "left join (select node__field_robot_code.field_robot_code_value,node__field_production.field_production_target_id,node__field_user.field_user_target_id from {node__field_robot_code} as node__field_robot_code left join {node__field_user} as node__field_user on node__field_robot_code.entity_id=node__field_user.entity_id ".
"left join {node__field_production} as node__field_production on node__field_robot_code.entity_id=node__field_production.entity_id where node__field_user.field_user_target_id= :userid and node__field_robot_code.bundle='register_robot_code' ) as node__field_robot_code on node__field_robot_code.field_production_target_id=node.nid ".*/
"where node.type='unity_production' and (node__field_belong_computer.field_user_target_id= :userid )and node__field_production_name.field_production_name_value like concat('%', :name ,'%') ",
[
':userid'=>$uid,
':name'=>$_GET['search_txt'],
':code'=>$_GET['code']
])->fetchAll();
}
//用户查找不出,根据code查找
// if(count($rs)<=0){
// $rs=$database->query("select node__field_production_name.field_production_name_value as production_name, ".
// "node__field_scene_name.field_scene_name_value as scene_name, node.nid as production_id, node__field_download_url.field_download_url_value as production_download_url, ".
// "node__field_belong_computer.computer_code as production_robot_code,node__field_app_name.field_app_name_value as app_name ".
// "from {node} as node left join {node__field_production_name} as node__field_production_name on node__field_production_name.entity_id=node.nid ".
// "left join {node__field_scene_name} as node__field_scene_name on node__field_scene_name.entity_id=node.nid ".
// "left join {node__field_download_url} as node__field_download_url on node__field_download_url.entity_id=node.nid ".
// "left join {node__field_app_name} as node__field_app_name on node__field_app_name.entity_id=node.nid ".
//// "left join (select node__field_app_path.entity_id,node__field_app_path.field_app_path_value,node__field_production.field_production_target_id ".
//// "from {node__field_app_path} as node__field_app_path left join {node__field_user} as node__field_user on node__field_app_path.entity_id=node__field_user.entity_id ".
//// "left join {node__field_production} as node__field_production on node__field_app_path.entity_id=node__field_production.entity_id ".
//// "where node__field_user.field_user_target_id= :userid and node__field_app_path.bundle='setting_msg') as node__field_app_path on node__field_app_path.field_production_target_id=node.nid ".
// "left join ( select node__field_computer_code.field_computer_code_value as computer_code,node__field_user.field_user_target_id,node__field_production.field_production_target_id from {node__field_belong_computer} as node__field_belong_computer ".
// "left join {node__field_computer_code} as node__field_computer_code on node__field_belong_computer.field_belong_computer_target_id=node__field_computer_code.entity_id ".
// "left join {node__field_user} as node__field_user on node__field_computer_code.entity_id =node__field_user.entity_id ".
// "left join {node__field_production} as node__field_production on node__field_production.entity_id=node__field_belong_computer.entity_id ".
// "where node__field_computer_code.field_computer_code_value= :code and node__field_belong_computer.bundle='register_robot_code' ) as node__field_belong_computer on node__field_belong_computer.field_production_target_id=node.nid ".
//
// /* "left join (select node__field_robot_code.field_robot_code_value,node__field_production.field_production_target_id,node__field_user.field_user_target_id from {node__field_robot_code} as node__field_robot_code left join {node__field_user} as node__field_user on node__field_robot_code.entity_id=node__field_user.entity_id ".
// "left join {node__field_production} as node__field_production on node__field_robot_code.entity_id=node__field_production.entity_id where node__field_user.field_user_target_id= :userid and node__field_robot_code.bundle='register_robot_code' ) as node__field_robot_code on node__field_robot_code.field_production_target_id=node.nid ".*/
// "where node.type='unity_production' and node__field_production_name.field_production_name_value like concat('%', :name ,'%') and node__field_belong_computer.computer_code= :code ",
// [
// ':name'=>$_GET['search_txt'],
// ':code'=>$_GET['code']
// ])->fetchAll();
// }
return new JsonResponse(['result'=>$rs]);
}
......@@ -146,44 +151,71 @@ public function saveRobotCode(){
$code=$post['code'];
$productionid=$post['productionid'];
$computer_code=\Drupal::entityTypeManager()
//获取用户该产品订单
$get_order=\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'field_user'=>$uid,
'field_computer_code'=>$code,
'type'=>'compute_bind'
'field_production'=>$productionid,
'type'=>'production_order'
]);
//判断是否为绑定计算机
if (count($computer_code)<=0){
return new JsonResponse(['code'=>1,'result'=>'nocomputer_code','type'=>'RobotCode']);
}else{
$computer_code=array_shift($computer_code);
//判断是否注册
$codepro=\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'field_user'=>$uid,
'field_production'=>$productionid,
'field_belong_computer'=>$computer_code->id(),
'type'=>'register_robot_code'
]);
if (count($codepro)<=0){
$robotcode = \Drupal::entityTypeManager()
->getStorage('node')
->create([
'title'=>$productionid.'-'.($computer_code->field_computer_name[0]->value),
'field_user'=>[['target_id'=>$uid]],
'field_belong_computer'=>[['target_id'=>$computer_code->id()]],
'field_production'=>[['target_id'=>$productionid]],
'type'=>'register_robot_code'
]);
$robotcode->save();
return new JsonResponse(['code'=>0,'result'=>$code,'type'=>'RobotCode']);
}else{
return new JsonResponse(['code'=>1,'result'=>'ishas','type'=>'RobotCode']);
}
}
if(count($get_order)>0){
$get_order=array_shift($get_order);
}
foreach ($code as $item){
//判断是否为绑定计算机
$computer_code=ValCode::getComputerCode($uid,$item);
/*$computer_code=\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'field_user'=>$uid,
'field_computer_code'=>$code,
'type'=>'compute_bind'
]);*/
if (count($computer_code)<=0){
return new JsonResponse(['code'=>1,'result'=>'nocomputer_code','type'=>'RobotCode']);
}else{
$computer_code=array_shift($computer_code);
//判断是否已机器绑定
$codepro=\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'field_user'=>$uid,
'field_production'=>$productionid,
'field_belong_computer'=>$computer_code->id(),
'type'=>'register_robot_code'
]);
//获取产品已绑定注册码
$robocode=ValCode::getRobotCode($uid,$productionid);
if (count($codepro)<=0 && (count($get_order)>0 && (count($robocode)<$get_order->field_bind_number[0]->value))){
$robotcode = \Drupal::entityTypeManager()
->getStorage('node')
->create([
'title'=>$productionid.'-'.($computer_code->field_computer_name[0]->value),
'field_user'=>[['target_id'=>$uid]],
'field_belong_computer'=>[['target_id'=>$computer_code->id()]],
'field_production'=>[['target_id'=>$productionid]],
'type'=>'register_robot_code'
]);
$robotcode->save();
}else{
if (count($codepro)>0){
return new JsonResponse(['code'=>1,'result'=>'ishas','type'=>'RobotCode']);
}else{
return new JsonResponse(['code'=>1,'result'=>'no_order_num','type'=>'RobotCode']);
}
}
}
}
return new JsonResponse(['code'=>0,'result'=>$code,'type'=>'RobotCode']);
}
/*
......@@ -197,13 +229,17 @@ public function saveComputerCode(){
$computer_name=$post['computer_name'];
//判断是否已存在
$codepro=\Drupal::entityTypeManager()
$codepro=ValCode::getComputerCode($uid,$code);
/*$codepro=\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'field_user'=>$uid,
'field_computer_code'=>$code,
'type'=>'compute_bind'
]);
]);*/
if (count($codepro)<=0){
$robotcode = \Drupal::entityTypeManager()
->getStorage('node')
......@@ -228,7 +264,7 @@ public function saveComputerCode(){
[
':userid'=>$uid,
])->fetchAll();
return new JsonResponse(['code'=>4,'result'=>count($rs),'type'=>'ComputerCode']);
if(count($rs)>0){
foreach ($rs as $item){
$get_save_robot=\Drupal::entityTypeManager()
......@@ -291,6 +327,111 @@ public function getComputerCode(){
}
}
/*
* 查询该用户产品已绑定和未绑定的计算机
* */
public function getComputerCodeListByOrder(){
$uid = \Drupal::currentUser()->id();
$database = \Drupal::database();
$productionid=$_GET['productionid'];
$rs=$database->query("SELECT node__field_computer_name.field_computer_name_value as computer_name,node.nid as computer_id,has_robot_code.production_id ".
"FROM {node} as node LEFT JOIN ".
"(select node__field_belong_computer.field_belong_computer_target_id as computer_id , ".
"node__field_production.field_production_target_id as production_id ".
"from {node} as node ".
"left join {node__field_production} as node__field_production on node.nid=node__field_production.entity_id ".
"left join {node__field_belong_computer} as node__field_belong_computer on node.nid=node__field_belong_computer.entity_id ".
"where node.type='register_robot_code' and node__field_production.field_production_target_id= :productionid ) AS has_robot_code ".
"ON node.nid=has_robot_code.computer_id ".
"left join {node__field_computer_name} as node__field_computer_name on node__field_computer_name.entity_id=node.nid ".
"left join {node__field_user} as node__field_user on node__field_user.entity_id=node.nid ".
"where node.type='compute_bind' and node__field_user.field_user_target_id= :userid ",
[
':userid'=>$uid,
':productionid'=>$productionid
])->fetchAll();
return new JsonResponse(['code'=>1,'result'=>$rs,'type'=>'ComputerCode']);
}
/*
* 添加产品接口
* */
public function saveProduction(){
$post = json_decode(file_get_contents ( 'php://input' ),TRUE);
$uid = \Drupal::currentUser()->id();
$production_id=$post["productionid"];
$pass_data=$post["pass_data"];
$getproduction=Node::load($production_id);
/*
* 保存订单
* */
$save_order = \Drupal::entityTypeManager()
->getStorage('node')
->create([
'title'=>$getproduction->field_production_name,
'field_production'=>[['target_id'=>$production_id]],
'field_pass_data'=>$pass_data,
'field_user'=>[['target_id'=>$uid]],
'type'=>'production_order'
]);
$save_order->save();
//获取该用户绑定电脑信息
/* $comp_code_list=\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'field_user'=>$uid,
'type'=>'compute_bind'
]);
//如果绑定电脑大于0,对每台电脑进行绑定软件信息添加
if(count($comp_code_list)>0){
foreach ($comp_code_list as $item){
$save_robot = \Drupal::entityTypeManager()
->getStorage('node')
->create([
'title'=>$production_id.'-'.$item->field_computer_name,
'field_user'=>[['target_id'=>$uid]],
'field_belong_computer'=>[['target_id'=>$item->id()]],
'field_production'=>[['target_id'=>$production_id]],
'type'=>'register_robot_code'
]);
$save_robot->save();
}
}*/
return new JsonResponse(['code'=>0,'result'=>$save_order->id(),'type'=>'SaveOrder']);
}
/*
* 查询用户订单
* */
public function getOrderListByUser(){
$uid = \Drupal::currentUser()->id();
$database = \Drupal::database();
$productionid=$_GET['productionid'];
$rs=$database->query("SELECT node__field_production.field_production_target_id ,register_robot_code.computer_num from {node} as node ".
"LEFT JOIN {node__field_production} as node__field_production ON node.nid=node__field_production.entity_id ".
"LEFT JOIN {node__field_user} as node__field_user ON node.nid=node__field_user.entity_id ".
"LEFT JOIN (select node__field_production.field_production_target_id,count(*) as computer_num ".
"FROM {node} as node ".
"LEFT JOIN {node__field_production} as node__field_production on node.nid=node__field_production.entity_id ".
"LEFT JOIN {node__field_belong_computer} as node__field_belong_computer on node.nid=node__field_belong_computer.entity_id ".
"WHERE node.type='register_robot_code' GROUP BY node__field_production.field_production_target_id ) as register_robot_code ".
"ON register_robot_code.field_production_target_id=node__field_production.field_production_target_id ".
"WHERE node.type='production_order' AND node__field_user.field_user_target_id= :userid AND node__field_production.field_production_target_id= :productionid ",
[
':userid'=>$uid,
':productionid'=>$productionid
])->fetchAll();
return new JsonResponse(['code'=>1,'result'=>$rs,'type'=>'ComputerCode']);
}
public function upUsers(){
$post = json_decode(file_get_contents ( 'php://input' ),TRUE);
......
......@@ -7,7 +7,7 @@
class ValCode{
//返回电脑绑定
public static function getComputerCode($uid,$code){
//先查询用户跟电脑是否绑定
//查询用户跟电脑是否绑定
$computer_code=\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
......@@ -17,4 +17,17 @@ public static function getComputerCode($uid,$code){
]);
return $computer_code;
}
//返回产品注册码
public static function getRobotCode($uid,$productionid){
//查询软件已经绑定电脑的注册码数量
$robot_code=\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'field_user'=>$uid,
'field_production'=>$productionid,
'type'=>'register_robot_code'
]);
return $robot_code;
}
}
......@@ -25,6 +25,15 @@ zeus_hub.getProductionList:
requirements:
_access: 'TRUE'
#获取订单相关绑定电脑信息
zeus_hub.getComputerCodeListByOrder:
path: 'zeus/zeushub/getComputerCodeListByOrder'
defaults:
_controller: 'Drupal\zeus_hub\Controller\ApiController::getComputerCodeListByOrder'
_title: 'getComputerCodeListByOrder'
requirements:
_access: 'TRUE'
#获取产品
zeus_hub.getAllProductionList:
path: 'zeus/zeushub/getAllProductionList'
......@@ -79,15 +88,32 @@ zeus_hub.getSetting:
requirements:
_access: 'TRUE'
# 获取企业订单
zeus_hub.getOrderListByUser:
path: 'zeus/zeushub/getOrderListByUser'
defaults:
_controller: 'Drupal\zeus_hub\Controller\ApiController::getOrderListByUser'
_title: 'getOrderListByUser'
requirements:
_access: 'TRUE'
#更新密码
zeus_hub.upUsers:
path: 'zeus/zeushub/upUsers'
defaults:
_controller: 'Drupal\zeus_hub\Controller\ApiController::upUsers'
_title: 'getSetting'
_title: 'upUsers'
requirements:
_access: 'TRUE'
#管理后台页面
zeus_hub.admin_page:
path: '/hub/admin'
defaults:
_controller: 'Drupal\zeus_hub\Controller\PageController::hub_view'
_title: '管理后台'
requirements:
_permission: 'access content'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment