Commit 2cfa66c8 authored by 潘梓豪's avatar 潘梓豪

更新api

parent ef4dc5e8
......@@ -8,6 +8,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\zeus_hub\Util\ValCode;
use Drupal\user\Entity\Role;
class ApiController extends ControllerBase{
......@@ -61,15 +62,17 @@ public function getProductionList(){
$database = \Drupal::database();
//查找订单内容
$rs=$database->query("select node__field_production_name.field_production_name_value as production_name, ".
"node__field_production.field_production_target_id as production_id, node__field_download_url.field_download_url_value as production_download_url, ".
$rs=$database->query("select node__field_production.field_production_target_id as production_id,node__field_production_name.field_production_name_value as production_name, ".
"node__field_scene_name.field_scene_name_value,node_field_data.title,".
"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 {node_field_data} as node_field_data on node_field_data.nid=node__field_production.field_production_target_id ".
"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 ".
......@@ -412,26 +415,114 @@ public function saveProduction(){
public function getOrderListByUser(){
$uid = \Drupal::currentUser()->id();
$database = \Drupal::database();
$productionid=$_GET['productionid'];
$post = json_decode(file_get_contents ( 'php://input' ),TRUE);
$tj="";
$arg=[];
$role=\Drupal::currentUser()->getRoles();
$rs=$database->query("SELECT node__field_production.field_production_target_id ,register_robot_code.computer_num from {node} as node ".
if ($post['productionid']!=null and $post['productionid']!=""){
$tj="AND node__field_production.field_production_target_id= :productionid ";
$arg=[
':userid'=>$uid,
':productionid'=>$post['productionid'],
];
}else{
$tj="AND (node_field_data.title LIKE CONCAT('%','".$post['title_name']."','%') or user__field_call_name.field_call_name_value is null )".
"AND (node__field_production_name.field_production_name_value LIKE CONCAT('%','".$post['production_name']."','%') or node__field_production_name.field_production_name_value is null )".
"AND (user__field_enterprise_name.field_enterprise_name_value LIKE CONCAT('%','".$post['enterprise_name']."','%') or user__field_enterprise_name.field_enterprise_name_value is null )";
$arg=[
':userid'=>$uid,
];
}
$rs=$database->query("SELECT node.nid,node_field_data.title, node__field_production_name.field_production_name_value, node__field_production.field_production_target_id ,".
"user__field_enterprise_name.field_enterprise_name_value,node__field_pass_data.field_pass_data_value,IF(register_robot_code.computer_num IS NULL,0,register_robot_code.computer_num) as computer_num, ".
"TIMESTAMPDIFF(DAY,NOW(),DATE_ADD(FROM_UNIXTIME(node_field_data.created),INTERVAL node__field_pass_data.field_pass_data_value DAY)) AS diff_date, ".
"FROM_UNIXTIME(node_field_data.created) as create_date 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_user} as node__field_user ON node.nid=node__field_user.entity_id ".
"LEFT JOIN {node_field_data} as node_field_data ON node.nid=node_field_data.nid ".
"LEFT JOIN {node__field_pass_data} as node__field_pass_data ON node__field_pass_data.entity_id=node.nid ".
"LEFT JOIN {user__field_enterprise_name} as user__field_enterprise_name ON user__field_enterprise_name.entity_id=node__field_user.field_user_target_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();
"WHERE node.type='production_order' ".$tj." AND node__field_user.field_user_target_id= :userid ".
" LIMIT ".$_GET['min'].",".$_GET['max'],
$arg)->fetchAll();
return new JsonResponse(['code'=>1,'result'=>$rs,'type'=>'ComputerCode']);
return new JsonResponse(['code'=>0,'result'=>$rs,'type'=>'OrderList','role'=>$role]);
}
/*
* 查询企业用户
* */
public function getEnterpriseList(){
$database = \Drupal::database();
$post = json_decode(file_get_contents ( 'php://input' ),TRUE);
$rs=$database->query("SELECT users_field_data.uid,users_field_data.`name`, ".
"user__field_phone.field_phone_value,user__field_call_name.field_call_name_value,user_order.computer_num, ".
"is_bind_computer.bind_computer_num,is_bind_code.bind_code_num ".
"from users_field_data ".
"LEFT JOIN {user__field_phone} as user__field_phone ON user__field_phone.entity_id=users_field_data.uid ".
"LEFT JOIN {user__field_call_name} as user__field_call_name ON user__field_call_name.entity_id=users_field_data.uid ".
"LEFT JOIN {user__field_enterprise_name} as user__field_enterprise_name ON user__field_enterprise_name.entity_id=users_field_data.uid ".
"LEFT JOIN {user__roles} as user__roles ON user__roles.entity_id=users_field_data.uid ".
"LEFT JOIN (SELECT node__field_user.field_user_target_id,count(*) as bind_computer_num FROM {node__field_user} as node__field_user WHERE node__field_user.bundle='compute_bind' GROUP BY node__field_user.field_user_target_id ) as is_bind_computer ON users_field_data.uid=is_bind_computer.field_user_target_id ".
"LEFT JOIN (SELECT node__field_user.field_user_target_id,count(*) as bind_code_num FROM {node__field_user} as node__field_user WHERE node__field_user.bundle='register_robot_code' GROUP BY node__field_user.field_user_target_id ) as is_bind_code ON users_field_data.uid=is_bind_code.field_user_target_id ".
"LEFT JOIN (SELECT SUM(node__field_bind_number.field_bind_number_value) as computer_num,node__field_user.field_user_target_id FROM {node} as node ".
"LEFT JOIN {node__field_bind_number} as node__field_bind_number ON node.nid=node__field_bind_number.entity_id ".
"LEFT JOIN {node__field_user} as node__field_user ON node.nid=node__field_user.entity_id ".
"WHERE node.type='production_order' GROUP BY node__field_user.field_user_target_id ) user_order ON user_order.field_user_target_id=users_field_data.uid ".
"WHERE user__roles.roles_target_id='enterprise' ".
"AND (user__field_call_name.field_call_name_value LIKE CONCAT('%','".$post['call_name']."','%') or user__field_call_name.field_call_name_value is null) ".
"AND (users_field_data.`name` LIKE CONCAT('%','".$post['user_name']."','%') or users_field_data.`name` is null) ".
"AND (user__field_phone.field_phone_value LIKE CONCAT('%','".$post['call_phone']."','%') or user__field_phone.field_phone_value is null) ".
"AND (user__field_enterprise_name.field_enterprise_name_value LIKE CONCAT('%','".$post['enterprise_name']."','%') or user__field_enterprise_name.field_enterprise_name_value is null) ".
" LIMIT ".$post['min'].",".$post['max'])->fetchAll();
return new JsonResponse(['code'=>0,'result'=>$rs,'type'=>'EnterpriseList']);
}
/*
* 查询设备
* */
public function getComputerList(){
$database = \Drupal::database();
$post = json_decode(file_get_contents ( 'php://input' ),TRUE);
$rs=$database->query("SELECT node.nid,node_field_data.title, node__field_computer_name.field_computer_name_value,is_bind_code.bind_num, ".
"node__field_computer_code.field_computer_code_value,FROM_UNIXTIME(node_field_data.created) as create_date ".
"FROM {node} AS node ".
"LEFT JOIN {node_field_data} AS node_field_data ON node.nid=node_field_data.nid ".
"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 ".
"LEFT JOIN {user__field_enterprise_name} AS user__field_enterprise_name ON user__field_enterprise_name.entity_id=node__field_user.field_user_target_id ".
"LEFT JOIN (SELECT node.nid ,count(*) AS bind_num FROM {node} AS node ".
"LEFT JOIN {node__field_computer_code} AS node__field_computer_code ON node.nid=node__field_computer_code.entity_id ".
"WHERE node.type='compute_bind' GROUP BY node.nid ) AS is_bind_code ".
"LEFT JOIN {node__field_computer_code} AS node__field_computer_code ON node__field_computer_code.entity_id=is_bind_code.nid ".
"ON node.nid=node__field_computer_code.entity_id ".
"WHERE node.type='compute_bind' ".
"AND (node_field_data.title LIKE CONCAT('%','".$post['title_name']."','%') or node_field_data.title is null) ".
"AND (node__field_computer_name.field_computer_name_value LIKE CONCAT('%','".$post['computer_name']."','%') or node__field_computer_name.field_computer_name_value is null) ".
"AND (node__field_computer_code.field_computer_code_value LIKE CONCAT('%','".$post['computer_code']."','%') or node__field_computer_code.field_computer_code_value is null) ".
"AND (user__field_enterprise_name.field_enterprise_name_value LIKE CONCAT('%','".$post['enterprise_name']."','%') or user__field_enterprise_name.field_enterprise_name_value is null) ".
" LIMIT ".$post['min'].",".$post['max'])->fetchAll();
return new JsonResponse(['code'=>0,'result'=>$rs,'type'=>'ComputerList']);
}
public function upUsers(){
$post = json_decode(file_get_contents ( 'php://input' ),TRUE);
......
......@@ -97,6 +97,24 @@ zeus_hub.getOrderListByUser:
requirements:
_access: 'TRUE'
# 获取企业列表
zeus_hub.getEnterpriseList:
path: 'zeus/zeushub/getEnterpriseList'
defaults:
_controller: 'Drupal\zeus_hub\Controller\ApiController::getEnterpriseList'
_title: 'getEnterpriseList'
requirements:
_access: 'TRUE'
# 获取设备列表
zeus_hub.getComputerList:
path: 'zeus/zeushub/getComputerList'
defaults:
_controller: 'Drupal\zeus_hub\Controller\ApiController::getComputerList'
_title: 'getComputerList'
requirements:
_access: 'TRUE'
#更新密码
zeus_hub.upUsers:
path: 'zeus/zeushub/upUsers'
......
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