Auth.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. <?php
  2. namespace Manage\Src;
  3. use Dever;
  4. use Dever\Routing\Uri;
  5. use Dever\Session\Oper;
  6. use Dever\String\Encrypt;
  7. class Auth
  8. {
  9. /**
  10. * 后台的session名
  11. *
  12. * @var string
  13. */
  14. private $name;
  15. /**
  16. * save
  17. *
  18. * @var Dever\Plad\Save
  19. */
  20. private $save;
  21. private $top;
  22. /**
  23. * __construct
  24. *
  25. * @return mixed
  26. */
  27. public function __construct()
  28. {
  29. $this->save = new Oper(false, 'session');
  30. $this->name = 'manage';
  31. }
  32. public function test()
  33. {
  34. return array('name' => 'test', 'check' => false, 'data' => array
  35. (
  36. 0 => array('name' => 'haha1'),
  37. 1 => array('name' => 'haha2'),
  38. ));
  39. }
  40. # 检测功能
  41. public function checkFunc($key, $func, $name)
  42. {
  43. $menu = Dever::db('manage/menu')->one(array('key' => $key));
  44. if ($menu) {
  45. $info = Dever::db('manage/menu_func')->one(array('key' => $func, 'menu_id' => $menu['id']));
  46. if (!$info) {
  47. $func_id = Dever::db('manage/menu_func')->insert(array('name' => $name, 'key' => $func, 'menu_id' => $menu['id']));
  48. } else {
  49. if ($info['name'] != $name) {
  50. Dever::db('manage/menu_func')->update(array('name' => $name, 'where_id' => $info['id']));
  51. }
  52. $func_id = $info['id'];
  53. }
  54. $data = $this->data();
  55. if ($data && isset($data['auth'])) {
  56. if ($data['auth'] == 'all') {
  57. return true;
  58. } elseif (strstr($data['auth'], 'f_' . $func_id)) {
  59. return true;
  60. }
  61. }
  62. }
  63. return false;
  64. }
  65. /**
  66. * 只获取中间的内容部分
  67. *
  68. * @return mixed
  69. */
  70. public function loading()
  71. {
  72. $set = Dever::input('loading');
  73. if ($set) {
  74. Dever::config('base')->url = 'loading=' . $set;
  75. }
  76. return $set;
  77. }
  78. /**
  79. * 获取角色
  80. *
  81. * @return mixed
  82. */
  83. public function role_api()
  84. {
  85. $data = Dever::db('manage/role')->alls(array
  86. (
  87. /* list和all可以自定义参数
  88. 'option' => array
  89. (
  90. 'name' => array('yes', 'like')
  91. ),
  92. */
  93. //'option_name' => '%' . Dever::input('term', 'test') . '%')
  94. 'option_name' => Dever::input('term', 'test'))
  95. );
  96. //Dever::debug($data);
  97. if ($data) {
  98. return $data;
  99. }
  100. return array
  101. (
  102. 0 => array('id' => -1, 'value' => '没有找到您搜索的数据', 'label' => '没有找到您搜索的数据'),
  103. );
  104. }
  105. public function blur()
  106. {
  107. $value = Dever::input('value');
  108. return 'test';
  109. }
  110. /**
  111. * 获取当前登录的管理员信息
  112. *
  113. * @return mixed
  114. */
  115. public function info($state = true)
  116. {
  117. return $this->real($this->data(), $state);
  118. }
  119. /**
  120. * 获取当前登录的管理员信息
  121. *
  122. * @return mixed
  123. */
  124. public function authData($state = true)
  125. {
  126. $data = $this->info($state);
  127. if (isset($data['role_info']['auth_data'])) {
  128. return $data['role_info']['auth_data'];
  129. }
  130. return '';
  131. }
  132. /**
  133. * 实时读取信息
  134. *
  135. * @return mixed
  136. */
  137. public function real($info, $state = true)
  138. {
  139. if ($state == true && Dever::config('base')->getAdmin && $info && isset($info['id'])) {
  140. $admin = Dever::db('manage/admin')->one($info['id']);
  141. if ($admin['top']) {
  142. $info['top'] = $admin['top'];
  143. }
  144. }
  145. if (!$info) {
  146. $info = $this->auth();
  147. if ($info) {
  148. $this->save($info);
  149. Dever::location(Dever::url(''));
  150. }
  151. }
  152. if (isset($info['role']) && $info['role']) {
  153. $info['role_info'] = Dever::db('manage/role')->one($info['role']);
  154. $info['rolename'] = '未分组';
  155. if ($info['role_info']['name']) {
  156. $info['rolename'] = $info['role_info']['name'];
  157. }
  158. $info['self'] = $info['role_info']['self'];
  159. $info['col_update'] = $info['role_info']['col_update'];
  160. $info['col_insert'] = $info['role_info']['col_insert'];
  161. $info['col_select'] = $info['role_info']['col_select'];
  162. }
  163. if (isset($info['group']) && $info['group']) {
  164. $info['group_info'] = Dever::db('manage/group')->one($info['group']);
  165. }
  166. return $info;
  167. }
  168. /**
  169. * 获取当前登录的管理员信息
  170. *
  171. * @return mixed
  172. */
  173. public function data($state = true)
  174. {
  175. return $this->save->get($this->name);
  176. }
  177. private function auth()
  178. {
  179. # 此处可以接入当前的用户系统
  180. /*
  181. $user = \CondeAdminUser::GetAdminInfo('manage', '后台管理');
  182. $info = Dever::load('manage/admin-user', array('where_username' => $user['name']));
  183. //$info = Dever::load('manage/admin-user', array('where_email' => $user['email']));
  184. if(!$info)
  185. {
  186. $id = Dever::load('manage/admin-insert', array('add_role' => 1, 'add_username' => $user['name'], 'add_email' => $user['email']));
  187. $info = Dever::load('manage/admin-one', $id);
  188. }
  189. return $info;
  190. */
  191. return false;
  192. }
  193. /**
  194. * 获取公告
  195. *
  196. * @return mixed
  197. */
  198. public function notice()
  199. {
  200. $admin = $this->info();
  201. if ($admin && $admin['config'] && isset($admin['config']['id']) && $admin['config']['id'] > 0) {
  202. $data = Dever::db('manage/notice')->getAll(array('where_config' => $admin['config']['id']));
  203. return $data;
  204. }
  205. return array();
  206. }
  207. /**
  208. * 获取当前登录的管理员信息
  209. *
  210. * @return mixed
  211. */
  212. public function manage()
  213. {
  214. $admin = $this->info();
  215. if ($admin && $admin['id'] == 1) {
  216. return '';
  217. }
  218. return 'display:none;';
  219. }
  220. /**
  221. * 退出登录
  222. *
  223. * @return mixed
  224. */
  225. public function quit_api()
  226. {
  227. if ($this->info()) {
  228. $this->save->un($this->name);
  229. }
  230. Dever::location('login');
  231. }
  232. /**
  233. * login
  234. *
  235. * @return mixed
  236. */
  237. public function login_api()
  238. {
  239. //$param['where_username'] = Dever::input('username');
  240. $username = Dever::input('username');
  241. if (strstr($username, '@')) {
  242. $param['where_email'] = $username;
  243. $method = 'email';
  244. } else {
  245. $param['where_mobile'] = $username;
  246. $method = 'mobile';
  247. }
  248. $password = hash('sha256', Dever::input('password'));
  249. $user = Dever::db('manage/admin')->$method($param);
  250. if (!$user) {
  251. $total = Dever::db('manage/admin')->total();
  252. if ($total <= 0) {
  253. $insert['username'] = $username;
  254. $insert[$method] = $username;
  255. $insert['password'] = Dever::input('password');
  256. $insert['status'] = $insert['state'] = 1;
  257. $insert['role'] = 1;
  258. Dever::db('manage/admin')->insert($insert);
  259. $param['time'] = 1;
  260. $user = Dever::db('manage/admin')->$method($param);
  261. } else {
  262. Dever::alert('登录失败');
  263. }
  264. }
  265. if ($user && $user['password'] == $password) {
  266. $this->save($user);
  267. $refer = Dever::input('refer');
  268. if ($refer) {
  269. $refer = Encrypt::decode($refer);
  270. Dever::out($refer);
  271. } else {
  272. Dever::out(Dever::url('home'));
  273. }
  274. } else {
  275. Dever::alert('登录失败');
  276. }
  277. }
  278. public function update($id)
  279. {
  280. $id = Dever::input('update_where_id');
  281. $admin = $this->info();
  282. if ($id > 0 && $id == $admin['id']) {
  283. $user = Dever::db('manage/admin')->one($id);
  284. $this->save($user);
  285. }
  286. }
  287. public function save(&$user)
  288. {
  289. if ($user['config']) {
  290. $user['config'] = Dever::db('manage/config')->one($user['config']);
  291. }
  292. if ($user['id'] == 1) {
  293. $user['oper'] = 'all';
  294. $user['auth'] = 'all';
  295. $user['auth_data'] = 'all';
  296. $user['top'] = 'all';
  297. } else {
  298. $user = $this->role($user);
  299. }
  300. $this->save->add($this->name, $user, 3600 * 24 * 7);
  301. }
  302. /**
  303. * get_role
  304. *
  305. * @return mixed
  306. */
  307. private function role($user)
  308. {
  309. $role = Dever::db('manage/role')->get(array('where_id' => $user['role']));
  310. if ($role) {
  311. $user['oper'] = array();
  312. $user['auth'] = array();
  313. $user['auth_data'] = array();
  314. $user['self'] = 2;
  315. $top = array();
  316. foreach ($role as $k => $v) {
  317. if ($v['oper']) {
  318. if (strpos($v['oper'], ',') !== false) {
  319. $user['oper'] += explode(',', $v['oper']);
  320. } else {
  321. $user['oper'][] = $v['oper'];
  322. }
  323. }
  324. if ($v['auth']) {
  325. $user['auth'][] = $v['auth'];
  326. }
  327. if ($v['auth_data']) {
  328. $user['auth_data'][] = $v['auth_data'];
  329. }
  330. if (!$user['top'] && $v['top']) {
  331. $top[] = $v['top'];
  332. }
  333. if ($v['self'] == 1) {
  334. $user['self'] = $v['self'];
  335. }
  336. }
  337. $user['oper'] = implode(',', $user['oper']);
  338. $user['auth'] = implode(',', $user['auth']);
  339. $user['auth_data'] = implode(',', $user['auth_data']);
  340. if (!$user['top'] && $top) {
  341. $user['top'] = implode(',', $top);
  342. }
  343. $user['oper'] = $this->super($user['oper']);
  344. $user['auth'] = $this->super($user['auth']);
  345. $user['auth_data'] = $this->super($user['auth_data']);
  346. $user['top'] = $this->super($user['top']);
  347. if ($user['top'] != 'all') {
  348. # 这块暂时不用
  349. //$top = explode(',', $user['top']);
  350. //Dever::load('manage/top.update_action', $top[0]);
  351. }
  352. /*
  353. if (strpos($user['oper'], 'all') !== false) {
  354. $user['oper'] = 'all';
  355. }
  356. if (strpos($user['auth'], 'all') !== false) {
  357. $user['auth'] = 'all';
  358. }
  359. if (strpos($user['auth_data'], 'all') !== false) {
  360. $user['auth_data'] = 'all';
  361. }
  362. if (strpos($user['top'], 'all') !== false) {
  363. $user['top'] = 'all';
  364. } elseif ($user['top']) {
  365. # 这块暂时不用
  366. //$top = explode(',', $user['top']);
  367. //Dever::load('manage/top.update_action', $top[0]);
  368. }
  369. */
  370. }
  371. return $user;
  372. }
  373. private function super($auth)
  374. {
  375. return $auth;
  376. if ($auth == 'all' || strpos($auth, 'all,') !== false) {
  377. $auth = 'all';
  378. }
  379. return $auth;
  380. }
  381. /**
  382. * location_login
  383. *
  384. * @return mixed
  385. */
  386. public function location_login()
  387. {
  388. $refer = Encrypt::encode(Dever::url());
  389. return Dever::location('manage/login?refer=' . $refer);
  390. }
  391. /**
  392. * init
  393. *
  394. * @return mixed
  395. */
  396. public function init()
  397. {
  398. if (isset($this->load)) {
  399. return;
  400. }
  401. $this->load = true;
  402. $admin = $this->info();
  403. if (!$admin) {
  404. return $this->location_login();
  405. }
  406. if ($admin['id'] == 1) {
  407. return;
  408. }
  409. $menu = Dever::input('menu');
  410. $project = Dever::input('key');
  411. $table = Dever::input('table');
  412. $menu_id = Dever::input('menu_id');
  413. if ($menu_id && $menu_id > 0) {
  414. $menu = Dever::db('manage/menu')->info($menu_id);
  415. if (!$menu) {
  416. Dever::alert('没有该权限');
  417. }
  418. if ($menu) {
  419. if (isset($admin['auth']) && $admin['auth']) {
  420. if ($admin['auth'] == 'all' || $admin['auth'] == '') {
  421. return;
  422. }
  423. $admin['auth'] = explode(',', $admin['auth']);
  424. if (!in_array($menu['id'], $admin['auth'])) {
  425. Dever::alert('您没有操作权限');
  426. }
  427. } else {
  428. Dever::alert('您没有操作权限');
  429. }
  430. } else {
  431. Dever::alert('您没有操作权限');
  432. }
  433. } else {
  434. //Dever::alert('您没有操作权限');
  435. }
  436. }
  437. # 得到当前管理员的权限
  438. public function admin()
  439. {
  440. $admin = $this->info();
  441. return $admin['auth'] == 'all' ? '' : explode(',', $admin['auth']);
  442. }
  443. # 得到当前头部菜单的权限
  444. public function top()
  445. {
  446. $admin = $this->info();
  447. return $admin['top'] == 'all' ? '' : $admin['top'];
  448. return $admin['top'] == 'all' ? '' : explode(',', $admin['top']);
  449. }
  450. # 设置头部菜单的权限
  451. public function _setTop($info)
  452. {
  453. if ($info) {
  454. $info['key'] = explode('_', $info['key']);
  455. $count = count($info['key']);
  456. if ($count > 2) {
  457. foreach ($info['key'] as $k => $v) {
  458. if ($k+1 < $count) {
  459. $key[] = $v;
  460. }
  461. }
  462. $key = implode('_', $key);
  463. } else {
  464. $key = $info['key'][0];
  465. }
  466. $data = $this->data();
  467. $key = str_replace('/', '-', $key);
  468. $this->top = $info;
  469. $this->save->add($this->name . '_topgetv1_' . $key . '_a' . $data['id'], $info, 3600 * 24 * 365);
  470. }
  471. }
  472. # 得到当前头部菜单
  473. public function getTop($key)
  474. {
  475. $state = false;
  476. if (is_array($key)) {
  477. $key = $key[0];
  478. $state = true;
  479. }
  480. $data = $this->data();
  481. $key = str_replace('/', '-', $key);
  482. $data = $this->save->get($this->name . '_topgetv1_' . $key . '_a' . $data['id']);
  483. $top = Dever::input('top');
  484. if ($top) {
  485. $data = Dever::db('manage/top')->one($top);
  486. }
  487. //print_r($data);die;
  488. # 当数据不存在时,先从数据库里取出一个最新的
  489. if (!$data && $state == true) {
  490. $info = Dever::db('manage/top')->key(array('where_key' => $key));
  491. if ($info) {
  492. $data = Dever::db('manage/top')->getOne(array('where_top_id' => $info['id']));
  493. }
  494. } elseif (!$data && $this->top) {
  495. $data = $this->top;
  496. }
  497. return $data;
  498. }
  499. public function config()
  500. {
  501. $admin = $this->info();
  502. if (!$admin && $id = Dever::input('auth', 1)) {
  503. $admin['config']['id'] = $id;
  504. }
  505. if ($admin['config'] && $admin['config']['id'] > 0) {
  506. $admin['config'] = Dever::db('manage/config')->info(array('where_id' => $admin['config']['id']));
  507. }
  508. $state = isset($admin['config']) && $admin['config'];
  509. $admin['config']['title'] = ($state && $admin['config']['title']) ? $admin['config']['title'] : Dever::config('base')->name . '';
  510. $admin['config']['info'] = ($state && $admin['config']['info']) ? $admin['config']['info'] : Dever::config('base')->name . ' 欢迎您';
  511. $admin['config']['content'] = ($state && $admin['config']['content']) ? $admin['config']['content'] : '欢迎您使用' . $admin['config']['title'];
  512. $admin['config']['template'] = ($state && $admin['config']['template']) ? $admin['config']['template'] : 1;
  513. $admin['config']['front_url'] = Dever::config('base')->host;
  514. $admin['config']['front_name'] = '访问' . Dever::config('base')->name;
  515. $admin['config']['front_display'] = $admin['config']['front_url'] ? 'display:' : 'display:none';
  516. $admin['config']['version'] = Dever::config('base')->version;
  517. $admin['config']['refer'] = Dever::input('refer');
  518. $admin['config']['login_url'] = Dever::url("auth.login");
  519. $admin['config']['copyright'] = Dever::config("base")->copyright;
  520. return $admin['config'];
  521. }
  522. /**
  523. * oper的判断
  524. *
  525. * @param uri string
  526. * @return mixed
  527. */
  528. public function oper($type = 1)
  529. {
  530. $oper = '';
  531. $admin = $this->info();
  532. //$role['oper'] = '1,2,3,4,5';
  533. if ($admin && isset($admin['oper']) && $admin['oper'] != 'all') {
  534. if (strpos(',' . $admin['oper'], ',' . $type) !== false) {
  535. return true;
  536. } else {
  537. return false;
  538. }
  539. } else {
  540. return true;
  541. }
  542. }
  543. /**
  544. * 获取当前uri的类型
  545. *
  546. * @param uri string
  547. * @return mixed
  548. */
  549. private function table($table, $project)
  550. {
  551. if ($table == 'other') {
  552. $table = '';
  553. } else {
  554. $path = Dever::load('manage/src/project.path', $project);
  555. $config = Dever::database(DEVER_PATH . $path . 'database/' . $table . '.php');
  556. $table = $config['lang'];
  557. }
  558. return $table;
  559. }
  560. /**
  561. * check
  562. *
  563. * @return mixed
  564. */
  565. public function check($id)
  566. {
  567. $id = Dever::input('update_where_id');
  568. # 先验证email是否已经存在
  569. $email = Dever::input('update_email');
  570. $info = Dever::db('manage/admin')->one(array('option_email' => $email));
  571. if ($id > 0 && $info && $info['id'] != $id) {
  572. Dever::alert('该邮箱已经存在');
  573. } elseif ($id < 0 && $info) {
  574. Dever::alert('该邮箱已经存在');
  575. }
  576. }
  577. /**
  578. * 获取当前uri的类型
  579. *
  580. * @param uri string
  581. * @return mixed
  582. */
  583. public function type($uri)
  584. {
  585. if (strpos($uri, '.') !== false) {
  586. $type = 3;
  587. } elseif (strpos($uri, '-') !== false) {
  588. $type = 2;
  589. } else {
  590. $type = 1;
  591. }
  592. return $type;
  593. }
  594. /**
  595. * 获取所有权限列表,并进行统计处理
  596. *
  597. * @return mixed
  598. */
  599. public function get($state = true)
  600. {
  601. $result = Dever::load('manage/src/menu.left', $state);
  602. $result['state'] = 1;
  603. return $result;
  604. }
  605. /**
  606. * 获取所有数据权限列表,并进行统计处理
  607. *
  608. * @return mixed
  609. */
  610. public function getByData()
  611. {
  612. $key = Dever::config('base')->manageAuthData;
  613. $result = array();
  614. if ($key) {
  615. $result = Dever::load($key);
  616. $result['state'] = 1;
  617. }
  618. return $result;
  619. }
  620. /**
  621. * 修改当前管理员的密码
  622. *
  623. * @return mixed
  624. */
  625. public function password()
  626. {
  627. $admin = $this->info();
  628. $new = Dever::input('new');
  629. $old = Dever::input('old');
  630. if ($admin && $admin['id'] > 0 && $new && $old && $new != $old && hash('sha256', ($old)) == $admin['password']) {
  631. $param['set_password'] = $new;
  632. $param['where_id'] = $admin['id'];
  633. Dever::db('manage/admin')->password($param);
  634. $admin['password'] = hash('sha256', ($new));
  635. $this->save->add($this->name, $admin);
  636. return '修改成功';
  637. } else {
  638. return '修改失败';
  639. }
  640. }
  641. /**
  642. * 更新数据到数据库
  643. *
  644. * @return array
  645. */
  646. public function update_action($param = array())
  647. {
  648. if (isset($param['key'])) {
  649. $info = Dever::db('manage/auth')->key(array('where_key' => $param['key']));
  650. //print_r($info);die;
  651. if (!$info) {
  652. $update['add_project'] = $param['project'];
  653. $update['add_project_name'] = $param['project_name'];
  654. $update['add_key'] = $param['key'];
  655. $update['add_name'] = $param['name'];
  656. $update['add_auth_id'] = isset($param['auth']) ? $param['auth'] : -1;
  657. $update['add_value'] = $param['value'];
  658. $update['add_state'] = isset($param['state']) ? $param['state'] : 1;
  659. $info['id'] = Dever::db('manage/auth')->insert($update);
  660. } else {
  661. $update['set_project'] = $param['project'];
  662. $update['set_project_name'] = $param['project_name'];
  663. $update['set_name'] = $param['name'];
  664. $update['set_value'] = $param['value'];
  665. $update['set_state'] = isset($param['state']) ? $param['state'] : 1;
  666. $update['where_id'] = $info['id'];
  667. Dever::db('manage/auth')->update($update);
  668. }
  669. return $info['id'];
  670. }
  671. return false;
  672. }
  673. /**
  674. * 同步子权限更新到数据库
  675. *
  676. * @return array
  677. */
  678. public function sync($param = array())
  679. {
  680. if (isset($param[0]) && isset($param[1])) {
  681. $key = $param[1]['key'];
  682. $info = Dever::db('manage/auth')->key(array('where_key' => $key));
  683. if ($info) {
  684. $update['value'] = Dever::input('where_id', $param[0]);
  685. $update['name'] = Dever::input('name', '-u');
  686. $update['top'] = $info['id'];
  687. $update['key'] = $key . '_' . $update['value'];
  688. $update['state'] = Dever::input('state', '-u');
  689. $this->update_action($update);
  690. }
  691. }
  692. }
  693. /**
  694. * 获取所有的项目精细权限
  695. *
  696. * @return array
  697. */
  698. public function all()
  699. {
  700. $data = Dever::db('manage/auth')->main;
  701. if ($data) {
  702. $child = Dever::db('manage/auth')->child;
  703. foreach ($data as $t => $d) {
  704. foreach ($d as $k => $v) {
  705. if (isset($child[$v['id']])) {
  706. $c = 0;
  707. foreach ($child[$v['id']] as $i => $j) {
  708. $data[$t][$k]['child'][$i] = $j;
  709. $c++;
  710. }
  711. if (!isset($data[$t][$k]['child'])) {
  712. unset($data[$t][$k]);
  713. }
  714. }
  715. }
  716. $data[$t]['state'] = 1;
  717. }
  718. }
  719. return $data;
  720. }
  721. /**
  722. * opt push
  723. *
  724. * @return mixed
  725. */
  726. public function opt($param = false)
  727. {
  728. $opt = new Opt;
  729. $opt->push($param);
  730. }
  731. /**
  732. * opt push
  733. *
  734. * @return mixed
  735. */
  736. public function opt_api($param = false)
  737. {
  738. $opt = new Opt;
  739. $opt->push($param);
  740. }
  741. /**
  742. * opt push
  743. *
  744. * @return mixed
  745. */
  746. public function api($param = false)
  747. {
  748. $api = new Api;
  749. $api->push($param);
  750. }
  751. /**
  752. * opt push
  753. *
  754. * @return mixed
  755. */
  756. public function api_api($param = false)
  757. {
  758. $api = new Api;
  759. $api->push($param);
  760. }
  761. }