admin.php 17 KB

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