Common.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <?php namespace Manage\Lib;
  2. use Dever;
  3. use Dever\Helper\Str;
  4. use Dever\Helper\Env;
  5. use Dever\Helper\Secure;
  6. use Dever\Helper\Date;
  7. class Common
  8. {
  9. public function auth()
  10. {
  11. $auth = Env::header('authorization');
  12. if ($auth) {
  13. $auth = ltrim($auth, 'Bearer ');
  14. Dever::session('auth', $auth);
  15. $info = Secure::checkLogin($auth);
  16. return $info;
  17. }
  18. return false;
  19. }
  20. # 获取当前使用的系统
  21. public function system($key = '')
  22. {
  23. $info = $this->auth();
  24. if (!$info) {
  25. $auth = Dever::session('auth');
  26. if (!$auth) {
  27. return false;
  28. }
  29. $info = Secure::checkLogin($auth);
  30. }
  31. if ($info && isset($info['extend']) && isset($info['extend']['relation_id'])) {
  32. # 这里后续增加从数据库中获取
  33. $value = $info['extend']['system_id'] . '_' . $info['extend']['relation_id'];
  34. if ($key) {
  35. return array($key => $value);
  36. }
  37. return $value;
  38. }
  39. return false;
  40. }
  41. # 生成token
  42. public function token($uid, $mobile, $system_id, $relation_id)
  43. {
  44. $extand['system_id'] = $system_id;
  45. $extand['relation_id'] = $relation_id;
  46. /* 暂时不做到库中
  47. $select['mobile'] = $mobile;
  48. $info = Dever::db('mobile_system')->find($select);
  49. $select += $extand;
  50. if (!$info) {
  51. Dever::db('mobile_system')->insert($select);
  52. } else {
  53. Dever::db('mobile_system')->update($info['id'], $select);
  54. }*/
  55. return array('token' => Secure::login($uid, $extand));
  56. }
  57. # 生成密码
  58. public function createPwd($password)
  59. {
  60. $data['salt'] = Str::salt(8);
  61. $data['password'] = $this->hash($password, $data['salt']);
  62. return $data;
  63. }
  64. # 生成时间
  65. public function crateDate($date)
  66. {
  67. return Date::mktime($date);
  68. }
  69. # hash加密
  70. public function hash($password, $salt)
  71. {
  72. return hash('sha256', $password . $salt);
  73. }
  74. # 根据load获取db
  75. public function db($load)
  76. {
  77. $menu = array();
  78. $load = explode('/', ltrim($load, '/'));
  79. if (isset($load[2])) {
  80. $app = $load[1];
  81. $table = $load[2];
  82. } else {
  83. $app = $load[0];
  84. $table = $load[1];
  85. }
  86. $parent = Dever::db('menu', 'manage')->find(array('key' => $app));
  87. if ($parent) {
  88. $menu = Dever::db('menu', 'manage')->find(array('parent_id' => $parent['id'], 'key' => $table));
  89. if ($menu) {
  90. $app = $menu['app'];
  91. }
  92. }
  93. $set = Dever::project($app);
  94. $manage = $set['path'] . 'table/manage/'.$table.'.php';
  95. if (is_file($manage)) {
  96. $manage = include $manage;
  97. if ($source = Dever::isset($manage, 'source')) {
  98. if (strpos($source, '/')) {
  99. $source = explode('/', $source);
  100. $app = $source[0];
  101. $table = $source[1];
  102. } else {
  103. $table = $source;
  104. }
  105. }
  106. }
  107. $db = Dever::db($table, $app);
  108. $db->config['manage'] = $manage;
  109. return array($db, $menu);
  110. }
  111. # 获取项目
  112. public function project()
  113. {
  114. $result = array();
  115. $app = \Dever\Project::read();
  116. foreach ($app as $k => $v) {
  117. $result[] = array
  118. (
  119. 'id' => $k,
  120. 'name' => $v['lang'] ?? $k,
  121. );
  122. }
  123. return $result;
  124. }
  125. # 仅为测试用
  126. public function out($data)
  127. {
  128. $result = array();
  129. $result['head'] = array('id', '姓名', '时间');
  130. $result['body'] = array();
  131. foreach ($data['body'] as $k => $v) {
  132. $result['body'][$k] = array($v['id'], $v['name'], $v['cdate']);
  133. }
  134. return $result;
  135. }
  136. # 仅为测试用,展示表格更多内容
  137. public function show($data)
  138. {
  139. # 返回类型:string字符串,table表格,card卡片,desc描述,list列表
  140. $result['type'] = 'string';
  141. $result['content'] = 'ddddd';
  142. $result['type'] = 'table';
  143. $result['head'] = array('id' => 'id', 'name' => '姓名');
  144. $result['body'] = array
  145. (
  146. array('id' => '1', 'name' => 'test'),
  147. array('id' => '2', 'name' => 'test2'),
  148. );
  149. $result['type'] = 'card';
  150. $result['content'][] = array
  151. (
  152. 'title' => '订单信息',
  153. 'shadow' => 'never',//always | never | hover
  154. 'content' => array
  155. (
  156. '1111',
  157. '2222',
  158. ),
  159. );
  160. $result['type'] = 'list';
  161. $result['content'] = array
  162. (
  163. array('日志类型', 'test'),
  164. array('姓名', 'test1'),
  165. );
  166. return $result;
  167. }
  168. # 仅为测试用,展示详情
  169. public function view($page)
  170. {
  171. # 这里获取基本信息
  172. //print_r($page->info);die;
  173. $info[] = array
  174. (
  175. # 类型,desc描述 table表格,表格有head和body即可
  176. 'type' => 'desc',
  177. 'name' => '基本信息',
  178. # 每行展示数量
  179. 'column' => 4,
  180. # 是否有边框
  181. 'border' => true,
  182. # 排列方向:horizontal横向 vertical纵向
  183. 'direction' => 'vertical',
  184. # 右侧按钮
  185. 'button' => array
  186. (
  187. array
  188. (
  189. 'name' => '编辑',
  190. # fastedit、fastadd、oper、api四个按钮类型,参数与list里的data_button一致,多了一个load,可以单独设置路由
  191. 'type' => 'fastedit',
  192. 'load' => 'platform/role',
  193. # 增加权限,第三个参数是排序,建议大一些
  194. //'func' => $page->getFunc('view_fastedit', '详情页-编辑角色', 1000),
  195. # 这里是按钮用到的参数数据
  196. 'row' => array
  197. (
  198. 'id' => 1,
  199. ),
  200. ),
  201. ),
  202. # 具体内容
  203. 'content' => array
  204. (
  205. array
  206. (
  207. 'name' => '标题',
  208. # 类型,text普通文本,tag标签,link链接,image图片 progress进度条 stat统计 timeline时间线 table表格
  209. 'type' => 'text',
  210. 'content' => '内容',
  211. # 样式primary success warning danger info exception
  212. 'style' => 'primary',
  213. ),
  214. array
  215. (
  216. 'name' => '标题',
  217. 'type' => 'tag',
  218. 'content' => '内容',
  219. 'style' => 'warning',
  220. ),
  221. array
  222. (
  223. 'name' => '标题',
  224. 'type' => 'link',
  225. 'content' => '内容',
  226. ),
  227. array
  228. (
  229. 'name' => '图片',
  230. 'type' => 'image',
  231. 'content' => 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
  232. # 'fill', 'contain', 'cover', 'none', 'scale-down'
  233. 'fit' => 'fill',
  234. ),
  235. array
  236. (
  237. 'name' => '进度条',
  238. 'type' => 'progress',
  239. 'content' => '10',
  240. 'style' => 'exception',
  241. 'width' => '20',
  242. 'inside' => true,
  243. # line dashboard 仪表盘 circle 圆形
  244. 'show' => 'line',
  245. # 开启条纹
  246. 'striped' => true,
  247. # 开启动画
  248. 'indeterminate' => true,
  249. ),
  250. array
  251. (
  252. 'name' => '统计',
  253. 'type' => 'stat',
  254. 'content' => array
  255. (
  256. array
  257. (
  258. # 一共24
  259. 'span' => '6',
  260. 'name' => '测试',
  261. 'value' => '1000',
  262. ),
  263. array
  264. (
  265. 'span' => '6',
  266. 'name' => '测试1',
  267. 'value' => '1000',
  268. ),
  269. array
  270. (
  271. 'span' => '6',
  272. 'name' => '测试2',
  273. 'value' => '1000',
  274. ),
  275. array
  276. (
  277. 'span' => '6',
  278. 'name' => '测试2',
  279. 'value' => '1000',
  280. ),
  281. ),
  282. ),
  283. array
  284. (
  285. 'name' => '时间线',
  286. 'type' => 'timeline',
  287. 'content' => array
  288. (
  289. array
  290. (
  291. 'time' => '2020-10-11',
  292. 'name' => '测试',
  293. 'color' => '#0bbd87',
  294. 'size' => 'large',
  295. 'type' => 'primary',
  296. 'hollow' => true,
  297. ),
  298. array
  299. (
  300. 'time' => '2020-10-11',
  301. 'name' => '测试',
  302. ),
  303. array
  304. (
  305. 'time' => '2020-10-11',
  306. 'name' => '测试',
  307. ),
  308. array
  309. (
  310. 'time' => '2020-10-11',
  311. 'name' => '测试',
  312. ),
  313. ),
  314. ),
  315. array
  316. (
  317. 'name' => '表格',
  318. 'type' => 'table',
  319. 'border' => true,
  320. 'height' => '200',
  321. 'head' => array
  322. (
  323. array
  324. (
  325. 'key' => 'name',
  326. 'name' => '姓名',
  327. 'fixed' => 'fixed',
  328. ),
  329. array
  330. (
  331. 'key' => 'desc',
  332. 'name' => '描述',
  333. 'fixed' => 'fixed',
  334. ),
  335. ),
  336. 'button' => array
  337. (
  338. array
  339. (
  340. 'name' => '编辑',
  341. 'type' => 'fastedit',
  342. 'load' => 'platform/role',
  343. ),
  344. ),
  345. 'body' => array
  346. (
  347. array
  348. (
  349. 'id' => 1,
  350. 'name' => 'test',
  351. 'desc' => 'dfdf',
  352. ),
  353. ),
  354. ),
  355. ),
  356. );
  357. $info[] = array
  358. (
  359. 'type' => 'table',
  360. 'name' => '表格信息',
  361. 'border' => true,
  362. 'height' => '200',
  363. 'head' => array
  364. (
  365. array
  366. (
  367. 'key' => 'name',
  368. 'name' => '姓名',
  369. 'fixed' => 'fixed',
  370. ),
  371. array
  372. (
  373. 'key' => 'desc',
  374. 'name' => '描述',
  375. 'fixed' => 'fixed',
  376. ),
  377. ),
  378. 'button' => array
  379. (
  380. array
  381. (
  382. 'name' => '编辑',
  383. 'type' => 'fastedit',
  384. 'load' => 'platform/role',
  385. # 增加权限,第三个参数是排序,建议大一些
  386. 'func' => $page->getFunc('view_fastedit', '详情页-编辑角色', 1000),
  387. ),
  388. ),
  389. 'body' => array
  390. (
  391. array
  392. (
  393. 'id' => 1,
  394. 'name' => 'test',
  395. 'desc' => 'dfdf',
  396. ),
  397. ),
  398. );
  399. $tab = array
  400. (
  401. 'active' => 'table1',
  402. 'content' => array
  403. (
  404. 'table1' => array
  405. (
  406. # 这里跟desc一样
  407. 'name' => '标题',
  408. 'type' => 'text',
  409. 'content' => '内容',
  410. 'style' => 'primary',
  411. ),
  412. 'tab2' => array
  413. (
  414. 'name' => '表格',
  415. 'type' => 'table',
  416. 'border' => true,
  417. 'height' => '200',
  418. 'head' => array
  419. (
  420. array
  421. (
  422. 'key' => 'name',
  423. 'name' => '姓名',
  424. 'fixed' => 'fixed',
  425. ),
  426. array
  427. (
  428. 'key' => 'desc',
  429. 'name' => '描述',
  430. 'fixed' => 'fixed',
  431. ),
  432. ),
  433. 'button' => array
  434. (
  435. array
  436. (
  437. 'name' => '编辑',
  438. 'type' => 'fastedit',
  439. 'load' => 'platform/role',
  440. ),
  441. ),
  442. 'body' => array
  443. (
  444. array
  445. (
  446. 'id' => 1,
  447. 'name' => 'test',
  448. 'desc' => 'dfdf',
  449. ),
  450. ),
  451. ),
  452. )
  453. );
  454. return array('info' => $info, 'tab' => $tab);
  455. }
  456. public function stat($where)
  457. {
  458. return array
  459. (
  460. array
  461. (
  462. # 一共24
  463. 'span' => '8',
  464. 'name' => '测试',
  465. 'value' => '1000',
  466. ),
  467. array
  468. (
  469. 'span' => '8',
  470. 'name' => '测试1',
  471. 'value' => '1000',
  472. ),
  473. array
  474. (
  475. 'span' => '8',
  476. 'name' => '测试2',
  477. 'value' => '1000',
  478. ),
  479. );
  480. }
  481. }