提交 f100c4c0 authored 作者: chengye's avatar chengye

修改api接口

上级 94dcaaff
<?php
/**
* 基础信息接口
*/
namespace app\api\controller\v1\common;
use app\api\exception\DbLinkException;
use think\Db;
class BasicInfor
{
//获取区域列表信息
public function getRegions(){
$regions = Db::table('region')
->field('id,region_name,region_state,pid,create_time')
->where('region_state','=',1)
->select();
$regionsdata =self::getRegionsTree($regions);
if(!$regionsdata){
throw new DbLinkException;
}
return json([
'code' => 200,
'message' => 'SUCCESS',
'data' => $regionsdata
]);
}
//获取业务线列表信息
public function getBusiness(){
$business = Db::table('business_line')
->field('business_id,business_name,business_state,create_time')
->where('business_state','=',1)
->select();
if(!$business){
throw new DbLinkException;
}
return json([
'code' => 200,
'message' => 'SUCCESS',
'data' => $business
]);
}
///获取运营商列表信息
public function getOperator(){
$operator = Db::table('operator')
->field('operator_id,operator_name,operator_state,pid,create_time')
->where('operator_state','=',1)
->select();
$operators =self::getOperatorTree($operator);
if(!$operators){
throw new DbLinkException;
}
return json([
'code' => 200,
'message' => 'SUCCESS',
'data' => $operators
]);
}
///获取需求来源列表信息
public function getSource(){
$source = Db::table('demand_source')
->field('sources_id,sources_name,sources_state,create_time')
->where('sources_state','=',1)
->select();
if(!$source){
throw new DbLinkException;
}
return json([
'code' => 200,
'message' => 'SUCCESS',
'data' => $source
]);
}
///获取上游客户列表信息
public function getCustomers(){
$customers = Db::table('upstream_customers')
->field('customers_id,customers_name,customers_state,create_time')
->where('customers_state','=',1)
->select();
if(!$customers){
throw new DbLinkException;
}
return json([
'code' => 200,
'message' => 'SUCCESS',
'data' => $customers
]);
}
//获取基站状态列表信息
public function getBasestate(){
$basestate = Db::table('station_statuscate')
->field('cate_id,cate_name,pid,state,create_time')
->where('state','=',1)
->order("sort asc")
->select();
$basestates =self::getBasestateTree($basestate);
if(!$basestate){
throw new DbLinkException;
}
return json([
'code' => 200,
'message' => 'SUCCESS',
'data' => $basestates
]);
}
static function getBasestateTree($array, $pid =0, $level = 0){
//声明静态数组,避免递归调用时,多次声明导致数组覆盖
static $list = [];
foreach ($array as $key => $value){
//第一次遍历,找到父节点为根节点的节点 也就是pid=0的节点
if ($value['pid'] == $pid){
//父节点为根节点的节点,级别为0,也就是第一级
$value['level'] = $level;
//把数组放到list中
$list[] = $value;
//把这个节点从数组中移除,减少后续递归消耗
unset($array[$key]);
//开始递归,查找父ID为该节点ID的节点,级别则为原级别+1
self::getBasestateTree($array, $value['cate_id'], $level+1);
}
}
return $list;
}
static function getOperatorTree($array, $pid =0, $level = 0){
//声明静态数组,避免递归调用时,多次声明导致数组覆盖
static $list = [];
foreach ($array as $key => $value){
//第一次遍历,找到父节点为根节点的节点 也就是pid=0的节点
if ($value['pid'] == $pid){
//父节点为根节点的节点,级别为0,也就是第一级
$value['level'] = $level;
//把数组放到list中
$list[] = $value;
//把这个节点从数组中移除,减少后续递归消耗
unset($array[$key]);
//开始递归,查找父ID为该节点ID的节点,级别则为原级别+1
self::getOperatorTree($array, $value['operator_id'], $level+1);
}
}
return $list;
}
static function getRegionsTree($array, $pid =0, $level = 0){
//声明静态数组,避免递归调用时,多次声明导致数组覆盖
static $list = [];
foreach ($array as $key => $value){
//第一次遍历,找到父节点为根节点的节点 也就是pid=0的节点
if ($value['pid'] == $pid){
//父节点为根节点的节点,级别为0,也就是第一级
$value['level'] = $level;
//把数组放到list中
$list[] = $value;
//把这个节点从数组中移除,减少后续递归消耗
unset($array[$key]);
//开始递归,查找父ID为该节点ID的节点,级别则为原级别+1
self::getRegionsTree($array, $value['id'], $level+1);
}
}
return $list;
}
}
\ No newline at end of file
......@@ -49,4 +49,33 @@ class Assign
return (new Role)->getRoles();
}
public function getRegions(){
$this->token->check();
return (new BasicInfor)->getRegions();
}
public function getBusiness(){
$this->token->check();
return (new BasicInfor)->getBusiness();
}
public function getOperator(){
$this->token->check();
return (new BasicInfor)->getOperator();
}
public function getSource(){
$this->token->check();
return (new BasicInfor)->getSource();
}
public function getCustomers(){
$this->token->check();
return (new BasicInfor)->getCustomers();
}
public function getBasestate(){
$this->token->check();
return (new BasicInfor)->getBasestate();
}
}
\ No newline at end of file
......@@ -11,4 +11,21 @@ Route::get('/v1/deptrank','api/v1.supplier.Assign/getDepartmentsWithLevel'); //
//角色信息
Route::get('/v1/roles','api/v1.supplier.Assign/getRoles'); //角色列表
Route::get('/v1/token','api/v1.supplier.Assign/createToken'); //获取token
\ No newline at end of file
Route::get('/v1/token','api/v1.supplier.Assign/createToken'); //获取token
//区域信息
Route::get('/v1/regions','api/v1.supplier.Assign/getRegions'); //区域信息
//业务线
Route::get('/v1/business','api/v1.supplier.Assign/getBusiness'); //业务线信息
//运营商
Route::get('/v1/operators','api/v1.supplier.Assign/getOperator'); //运营商信息
//需求来源
Route::get('/v1/source','api/v1.supplier.Assign/getSource'); //需求来源信息
//上游客户
Route::get('/v1/customers','api/v1.supplier.Assign/getCustomers'); //上游客户信息
//基站状态
Route::get('/v1/basestate','api/v1.supplier.Assign/getBasestate'); //基站状态信息
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论