admin.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | admin.php 管理员表
  5. |--------------------------------------------------------------------------
  6. */
  7. # 定义几个常用的选项
  8. $status = array
  9. (
  10. 1 => '普通',
  11. 2 => '封禁',
  12. );
  13. $cur = Dever::load('manage/auth.data', false);
  14. $desc = '';
  15. if($cur['role'] > 1)
  16. {
  17. $desc = $cur['username'] . ',你好,你可以在此管理你的下属账号';
  18. $child = array_keys(Dever::db('manage/role')->all());
  19. $admin = Dever::db('manage/admin_role')->list(array
  20. (
  21. 'col' => 'admin_id|admin_id',
  22. 'option' => array
  23. (
  24. 'role_id' => array('yes', 'in'),
  25. ),
  26. 'option_role_id' => implode(',', $child),
  27. ));
  28. # 配置当前列表页的参数 只能查看自己下属的管理员
  29. Dever::$global['model']['manage/admin-list'] = array
  30. (
  31. 'option' => array
  32. (
  33. 'id' => array('yes', 'in'),
  34. ),
  35. 'option_id' => $admin ? array_keys($admin) : -1,
  36. );
  37. }
  38. $role = function()
  39. {
  40. return Dever::load('manage/role-all');
  41. };
  42. $group = function()
  43. {
  44. return Dever::load('manage/group-all');
  45. };
  46. $config = function()
  47. {
  48. return Dever::load('manage/config-all');
  49. };
  50. # 获取头部菜单list 建议这里使用匿名函数
  51. $top = function()
  52. {
  53. $data = Dever::load('manage/top.all');
  54. $data['state'] = 1;
  55. return $data;
  56. };
  57. return array
  58. (
  59. # 表名
  60. 'name' => 'admin',
  61. # 显示给用户看的名称
  62. 'lang' => '管理账户设置',
  63. 'desc' => $desc,
  64. /* 设置上级菜单,当config里设置menu后,这里将失效
  65. 'parent' => array
  66. (
  67. 'key' => 'kefu',
  68. 'order' => 1,
  69. 'name' => '客服设置',
  70. ),
  71. */
  72. # 这个表不使用cache功能
  73. //'cache' => false,
  74. /*
  75. # 用到哪个后台菜单上,对应项目的key
  76. 'menu' => 'project_niuyou_main',
  77. # 后台菜单排序
  78. 'order' => 10,
  79. # 显示到后台快捷发布中,值为排序
  80. 'fast' => 1,
  81. */
  82. 'order' => 9,
  83. # 检测email必须唯一
  84. 'check' => 'email',
  85. # 同步更新另外一个或多个表的多条关联数据,以逗号隔开
  86. 'sync' => array
  87. (
  88. 'manage/admin_role' => array
  89. (
  90. # 更新时的条件,另外一个表的字段 => 本表的字段
  91. 'where' => array('admin_id' => 'id'),
  92. # 要更新的数据
  93. 'update' => array('role_id' => 'role'),
  94. # 同步更新的类型,delete为先删再插入,update为先查询是否存在,存在直接更新,不存在则插入, only为仅更新
  95. 'type' => 'delete',
  96. )
  97. ),
  98. /*
  99. # 查询出数据时,填充默认数据
  100. 'fill' => array
  101. (
  102. # 从哪个表填充
  103. 'cover/hot_service' => array
  104. (
  105. # 条件,另外一个表的字段 => 本表的字段
  106. 'where' => array('id' => 'service_id', 'seller_id' => '-1'),
  107. # 要填充的数据,另外一个表的字段 => 本表的字段,如果不填写就是所有的
  108. //'update' => array('name', 'title', 'desc', 'desc', 'back_color', 'pic', 'min_pic1', 'min_pic2', 'top', 'top_name', 'top_cover', 'hot_pic', 'case_pic', 'gradient', 'share_name', 'share_desc', 'share_pic', 'content', 'reorder'),
  109. # 不需要填充的字段 与update互斥
  110. 'no' => array('id', 'seller_id', 'service_id', 'chose', 'state', 'cdate')
  111. )
  112. ),
  113. */
  114. # 同步更新另外一个或多个表的一条关联数据
  115. /*
  116. 'syncone' => array
  117. (
  118. 'manage/admin_role' => array
  119. (
  120. # 更新另外一个表的字段 => 本表的字段
  121. 'where' => array('admin_id' => 'id'),
  122. # 要更新的数据
  123. 'update' => array('role_id' => 'role'),
  124. )
  125. ),
  126. */
  127. /*该方法用check替代
  128. 'start' => array
  129. (
  130. 'update' => 'manage/auth.check',
  131. 'insert' => 'manage/auth.check',
  132. ),
  133. */
  134. 'end' => array
  135. (
  136. 'update' => 'manage/auth.update',
  137. ),
  138. # 数据结构
  139. 'struct' => array
  140. (
  141. 'id' => array
  142. (
  143. 'type' => 'int-11',
  144. 'name' => '管理员ID',
  145. 'default' => '',
  146. 'desc' => '',
  147. 'match' => 'is_numeric',
  148. 'search' => 'order',
  149. 'list' => true,
  150. ),
  151. 'username' => array
  152. (
  153. 'type' => 'varchar-24',
  154. 'name' => '管理员名',
  155. 'default' => '',
  156. 'desc' => '请输入管理员名',
  157. 'match' => 'is_string',
  158. 'update' => 'text',
  159. # 自动完成功能,第一个参数是请求的地址,请自行实现,第二个参数是要使用的字段,共有id和value两个选择,id会特殊处理,value则直接把当前值写入,第三个参数是直接替换当前的值,第四个参数是当前表里的字段名,一般为分类的id
  160. //'autocomplete' => array('auth.role?json=1', 'value', 'manage/role-check#name', 'cate_id'),
  161. //'autocomplete' => array('auth.role?json=1'),
  162. 'search' => 'order,fulltext',
  163. 'list' => true,
  164. # 绑定js脚本,更新时使用,第一个参数是执行的方式,第二个参数执行的方法,第三个参数是传值。
  165. //'bind' => array('onblur', 'loading', array('url' => Dever::url("auth.blur"))),
  166. ),
  167. #多级联动
  168. //'update' => 'linkage',//多级联动 option参数:请求地址(返回参数为level_num当前联动级数,level_id当前选择的id),参考area组件:dever package area
  169. //'option' => Dever::url('api.get', 'area'),
  170. 'email' => array
  171. (
  172. 'type' => 'varchar-150',
  173. 'name' => '邮箱-可用于登录,请准确填写,不允许重复',
  174. 'default' => '',
  175. 'desc' => '请输入邮箱',
  176. 'match' => Dever::rule('email'),
  177. 'update' => 'text',
  178. /*
  179. * 列表页搜索选项,这里的search或者update的值为
  180. * fulltext:全文检索,模糊匹配
  181. * text:精确匹配
  182. * exp:大小判断,仅能选择一项
  183. * select:选择器,需要option项
  184. * group:组选择器,需要option项
  185. * linkage:多级联动选择器,需要option项,值为联动数据接口地址,参考area组件 'option' => Dever::url('api.get', 'area'), 'list' => 'Dever::load("area/api.string", "{area}")',
  186. * exist:是否存在,需要exist项,基本配置为
  187. $source_id = array
  188. (
  189. 'yes' => '有值',
  190. 'no' => '没有值',
  191. 'no|2832' => '没有值或者有值为2832',
  192. 'yes|2832' => '有值并且过滤值为2829',
  193. '2832' => '查找',
  194. );
  195. * 如果search的值为数组,则认为是接口,需要从接口获取数据后再进行查找
  196. * 如'search' => array
  197. (
  198. 'api' => 'passport/user-all',//接口地址,最好是获取多条数据的地址
  199. 'col' => 'name',//要查询的字段
  200. 'result' => 'id',//返回的字段
  201. 'search' => 'uid',//本表的字段,默认为当前的字段
  202. ),
  203. * 就是将本字段email当做passport/user-one的name字段来查找id
  204. */
  205. 'search' => 'fulltext',
  206. 'list' => true,
  207. # 在手机版或者小屏幕下,列表页的表格是否展示,1为展示,2、3、4、5、6均为在一定宽度下展示,详细参考:https://github.com/nadangergeo/RWD-Table-Patterns
  208. 'level' => 1,
  209. //直接上传到云端
  210. //'upload' => 'qiniu',
  211. //上传大数据
  212. //'large' => true,
  213. ),
  214. # 比较特殊的一些设置,不断添加中:
  215. /*
  216. 'cate' => array
  217. (
  218. 'type' => 'varchar-300',
  219. 'name' => '标签分类',
  220. 'default' => '1',
  221. 'desc' => '标签分类',
  222. 'match' => 'is_string',
  223. 'update' => 'select',
  224. 'option' => $cate,
  225. 'search' => 'fulltext',
  226. //'list' => true,
  227. 'control' => 'cate',
  228. ),
  229. # 标签,根据分类变化的标签
  230. 'tag' => array
  231. (
  232. 'type' => 'varchar-300',
  233. 'name' => '标签',
  234. 'default' => '',
  235. 'desc' => '标签',
  236. 'match' => 'is_string',
  237. 'update' => 'checkbox',
  238. # 新增接口 暂未实现
  239. 'adding' => 'tag/manage.getByCate?cate=',
  240. # 开启这个,需要将update更换为text类型,输入文字即可选择标签
  241. //'autocomplete' => array('tag/manage.getByName', 'id', 'tag/info-one#name'),
  242. 'search' => 'fulltext',
  243. //'list' => true,
  244. # 与上边的cate联动(ajax)
  245. 'show' => 'cate=tag/manage.getByCate?cate=',
  246. ),
  247. # 加载地图
  248. 'map' => array
  249. (
  250. 'type' => 'varchar-300',
  251. 'name' => '地理位置',
  252. 'default' => '',
  253. 'desc' => '地理位置',
  254. 'match' => 'is_string',
  255. # 如果是map,必须在config的base.php中设置map信息
  256. //'update' => 'map',
  257. 'search' => 'fulltext',
  258. //'list' => true,
  259. //自定义编辑器右侧按钮
  260. 'editor' => array
  261. (
  262. 'name' => '选择插入模块',
  263. 'button' => array
  264. (
  265. array
  266. (
  267. # 名称
  268. 'name' => '图片',
  269. # 资源库id
  270. 'key' => 1,
  271. # 类型
  272. 'type' => 'image',
  273. ),
  274. array
  275. (
  276. 'name' => '音频',
  277. 'key' => 2,
  278. 'type' => 'media',
  279. ),
  280. array
  281. (
  282. 'name' => '视频',
  283. 'key' => 'video/lib/core.vod',
  284. ),
  285. array
  286. (
  287. 'name' => '直播',
  288. 'key' => 'video/lib/core.live',
  289. ),
  290. ),
  291. ),
  292. ),
  293. # 三级地区联动
  294. 'area' => array
  295. (
  296. 'type' => 'varchar-100',
  297. 'name' => '地区',
  298. 'default' => '',
  299. 'desc' => '地区',
  300. 'match' => 'is_string',
  301. 'search' => 'linkage',
  302. 'update' => 'linkage',//多级联动 option参数:请求地址(参数为level_num当前联动级数,level_id当前选择的id)
  303. 'option' => Dever::url('api.get', 'area'),
  304. 'list' => 'Dever::load("area/api.string", "{area}")',
  305. ),
  306. # 无限级联动
  307. 'category' => array
  308. (
  309. 'type' => 'varchar-500',
  310. 'name' => '分类',
  311. 'default' => '',
  312. 'desc' => '分类',
  313. 'match' => 'is_string',
  314. 'search' => 'linkage',
  315. //'update' => 'linkage',
  316. 'option' => Dever::url('api.get', 'category'),
  317. 'list' => 'Dever::load("category/api.string", "{category}")',
  318. ),
  319. # 属性管理
  320. 'attr' => array
  321. (
  322. 'type' => 'varchar-800',
  323. 'name' => '属性设置',
  324. 'default' => '',
  325. 'desc' => '属性设置',
  326. 'match' => 'option',
  327. 'update' => 'checkbox',
  328. 'option' => $attr,
  329. 'update_input' => '',
  330. 'update_input_default' => '',
  331. 'update_parent' => 'checkbox',
  332. ),
  333. # 属性管理 需要用这个来设置值
  334. 'attr_input' => array
  335. (
  336. 'type' => 'text-255',
  337. 'name' => '属性值设置',
  338. 'default' => '',
  339. 'desc' => '属性值设置',
  340. 'match' => 'option',
  341. ),
  342. */
  343. 'mobile' => array
  344. (
  345. 'type' => 'varchar-32',
  346. 'name' => '手机号',
  347. 'default' => '',
  348. 'desc' => '请输入手机号',
  349. 'match' => Dever::rule('mobile'),
  350. 'update' => 'text',
  351. 'search' => 'fulltext',
  352. 'list' => true,
  353. 'level' => 1,
  354. # 显示在table中
  355. //'list_table'=> '111',
  356. ),
  357. 'password' => array
  358. (
  359. 'type' => 'varchar-64',
  360. 'name' => '管理员密码',
  361. 'default' => '',
  362. 'desc' => '请输入管理员密码',
  363. 'match' => 'option',
  364. 'update' => 'password',
  365. 'callback' => 'hash.sha256',
  366. ),
  367. 'config' => array
  368. (
  369. 'type' => 'int-11',
  370. 'name' => '后台配置',
  371. 'default' => '1',
  372. 'desc' => '请选择后台配置',
  373. 'match' => 'is_numeric',
  374. 'option' => $config,
  375. 'update' => 'select',
  376. 'list' => true,
  377. ),
  378. 'role' => array
  379. (
  380. 'type' => 'varchar-100',
  381. 'name' => '角色',
  382. 'default' => '1',
  383. 'desc' => '请选择角色',
  384. 'match' => 'is_string',
  385. 'option' => $role,
  386. 'update' => 'checkbox',
  387. //'list' => true,
  388. ),
  389. 'group' => array
  390. (
  391. 'type' => 'int-11',
  392. 'name' => '分组',
  393. 'default' => '1',
  394. 'desc' => '请选择分组',
  395. 'match' => 'is_numeric',
  396. 'option' => $group,
  397. 'update' => 'select',
  398. //'list' => true,
  399. ),
  400. 'top' => array
  401. (
  402. 'type' => 'text-255',
  403. 'name' => '头部菜单-这里的头部菜单如果设置,则会覆盖角色中的头部菜单',
  404. 'default' => '',
  405. 'desc' => '请选择头部菜单',
  406. 'match' => 'option',
  407. 'update' => 'checkbox',
  408. 'option' => $top,
  409. ),
  410. 'state' => array
  411. (
  412. 'type' => 'tinyint-1',
  413. 'name' => '数据状态',
  414. 'default' => '1',
  415. 'desc' => '请选择状态',
  416. 'match' => 'is_numeric',
  417. //'option' => $option,
  418. //'update' => 'radio',
  419. //'list' => true,
  420. //'extend' => true,//扩展功能,该字段为虚拟字段,只在数据库中建立extend字段来保存 后续实现
  421. ),
  422. /*
  423. 提供冲突检测机制(乐观锁),保证高并发下的数据安全
  424. 这是模仿自 php 的 Memcached 扩展 后续实现
  425. 'token' => array
  426. (
  427. 'type' => 'int-11',
  428. 'name' => 'token',
  429. 'default' => '1',
  430. 'desc' => 'token',
  431. 'match' => 'is_numeric',
  432. ),
  433. */
  434. 'status' => array
  435. (
  436. 'type' => 'tinyint-1',
  437. 'name' => '状态',
  438. 'default' => '1',
  439. 'desc' => '请选择状态',
  440. 'match' => 'is_numeric',
  441. 'option' => $status,
  442. 'update' => 'radio',
  443. 'list' => true,
  444. 'edit' => true,
  445. ),
  446. 'cdate' => array
  447. (
  448. 'type' => 'int-11',
  449. 'name' => '录入时间',
  450. 'match' => array('is_numeric', DEVER_TIME),
  451. 'desc' => '',
  452. # 只有insert时才生效
  453. 'insert' => true,
  454. 'list' => 'date("Y-m-d H:i:s", {cdate})',
  455. ),
  456. ),
  457. 'manage' => array
  458. (
  459. 'delete' => false,
  460. // 载入自定义资源
  461. 'res' => array
  462. (
  463. 'js' => 'demo',
  464. 'css' => 'demo',
  465. ),
  466. # 快捷更新
  467. /*
  468. 'list_button' => array
  469. (
  470. 'edit' => array('审核', 'name'),
  471. ),
  472. */
  473. /*
  474. 'insert' => false,
  475. 'edit' => false,
  476. //'delete' => false,
  477. # 自定义快捷新增和编辑
  478. 'button' => array
  479. (
  480. '新增' => array('fast', 'name,reorder'),
  481. ),
  482. # 快捷更新
  483. 'list_button' => array
  484. (
  485. 'edit' => array('编辑', 'name,reorder'),
  486. ),
  487. */
  488. ),
  489. # 更新表结构
  490. 'alter' => array
  491. (
  492. 2 => array
  493. (
  494. //array('update', 'role', 'role', 'varchar-100 1 角色'),
  495. //array('add', 'config', 'config', 'int-11 1 配置'),
  496. ),
  497. 'version' => 2,
  498. ),
  499. # 默认值
  500. /*
  501. 'default' => array
  502. (
  503. 'col' => 'username,email,password,role,state,cdate',
  504. 'value' => array
  505. (
  506. //'"DMC","DMC@dever.cc","'. md5('admin_' . date('Y_m_d_H')) . '",1, 1,' . time(),
  507. '"admin","DMC@dever.cc","'. hash('sha256', 'admin_123') . '",1, 1,' . DEVER_TIME,
  508. ),
  509. ),
  510. */
  511. # 索引
  512. 'index' => array
  513. (
  514. # 索引名 => 索引id
  515. //'id' => 'id,state',
  516. ),
  517. # request 请求接口定义
  518. 'request' => array
  519. (
  520. # one 根据用户名和密码取一条数据
  521. 'user' => array
  522. (
  523. # 匹配的正则或函数 必填项
  524. 'where' => array
  525. (
  526. //'username' => '/^([A-Za-z0-9])/',
  527. //'username' => 'yes',
  528. 'email' => 'yes',
  529. 'status' => 1,
  530. 'state' => 1,
  531. //'password' => 'is_string',
  532. ),
  533. 'type' => 'one',
  534. # 为这个接口独立设置缓存
  535. 'cache' => true,
  536. ),
  537. # one 根据用户名和密码取一条数据
  538. 'email' => array
  539. (
  540. # 匹配的正则或函数 必填项
  541. 'where' => array
  542. (
  543. //'username' => '/^([A-Za-z0-9])/',
  544. //'username' => 'yes',
  545. 'email' => 'yes',
  546. 'status' => 1,
  547. 'state' => 1,
  548. //'password' => 'is_string',
  549. ),
  550. 'type' => 'one',
  551. # 为这个接口独立设置缓存
  552. 'cache' => true,
  553. ),
  554. # one 根据用户名和密码取一条数据
  555. 'mobile' => array
  556. (
  557. # 匹配的正则或函数 必填项
  558. 'where' => array
  559. (
  560. //'username' => '/^([A-Za-z0-9])/',
  561. //'username' => 'yes',
  562. 'mobile' => 'yes',
  563. 'status' => 1,
  564. 'state' => 1,
  565. //'password' => 'is_string',
  566. ),
  567. 'type' => 'one',
  568. # 为这个接口独立设置缓存
  569. 'cache' => true,
  570. ),
  571. # 更新密码
  572. 'password' => array
  573. (
  574. 'type' => 'update',
  575. 'where' => array
  576. (
  577. 'id' => 'yes',
  578. ),
  579. 'set' => array
  580. (
  581. 'password' => 'yes',
  582. ),
  583. ),
  584. ),
  585. );