admin.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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. # 表类型 值为\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. 'cate' => array
  236. (
  237. 'type' => 'varchar-300',
  238. 'name' => '标签分类',
  239. 'default' => '1',
  240. 'desc' => '标签分类',
  241. 'match' => 'is_string',
  242. 'update' => 'select',
  243. 'option' => $cate,
  244. 'search' => 'fulltext',
  245. //'list' => true,
  246. 'control' => 'cate',
  247. ),
  248. # 标签,根据分类变化的标签
  249. 'tag' => array
  250. (
  251. 'type' => 'varchar-300',
  252. 'name' => '标签',
  253. 'default' => '',
  254. 'desc' => '标签',
  255. 'match' => 'is_string',
  256. 'update' => 'checkbox',
  257. # 新增接口 暂未实现
  258. 'adding' => 'tag/manage.getByCate?cate=',
  259. # 开启这个,需要将update更换为text类型,输入文字即可选择标签
  260. //'autocomplete' => array('tag/manage.getByName', 'id', 'tag/info-one#name'),
  261. 'search' => 'fulltext',
  262. //'list' => true,
  263. # 与上边的cate联动(ajax)
  264. 'show' => 'cate=tag/manage.getByCate?cate=',
  265. # 或者加入可选项 待实现
  266. 'option' => $cate,
  267. ),
  268. # 标签,根据分类变化的标签
  269. 'tag' => array
  270. (
  271. 'type' => 'text-255',
  272. 'name' => '标签',
  273. 'default' => '',
  274. 'desc' => '标签',
  275. 'match' => 'is_string',
  276. // 多级联动+多选
  277. 'update' => 'linkage_checkbox',
  278. 'option' => array(Dever::url('api.get', 'area'), '', Dever::url('api.get', 'area')),//先选择多级联动,再选择多选
  279. ),
  280. # 加载地图
  281. 'map' => array
  282. (
  283. 'type' => 'varchar-300',
  284. 'name' => '地理位置',
  285. 'default' => '',
  286. 'desc' => '地理位置',
  287. 'match' => 'is_string',
  288. # 如果是map,必须在config的base.php中设置map信息
  289. //'update' => 'map',
  290. 'search' => 'fulltext',
  291. //'list' => true,
  292. //自定义编辑器右侧按钮
  293. 'editor' => array
  294. (
  295. 'name' => '选择插入模块',
  296. 'button' => array
  297. (
  298. array
  299. (
  300. # 名称
  301. 'name' => '图片',
  302. # 资源库id
  303. 'key' => 1,
  304. # 类型
  305. 'type' => 'image',
  306. ),
  307. array
  308. (
  309. 'name' => '音频',
  310. 'key' => 2,
  311. 'type' => 'media',
  312. ),
  313. array
  314. (
  315. 'name' => '视频',
  316. 'key' => 'video/lib/core.vod',
  317. ),
  318. array
  319. (
  320. 'name' => '直播',
  321. 'key' => 'video/lib/core.live',
  322. ),
  323. ),
  324. ),
  325. ),
  326. # 三级地区联动
  327. 'area' => array
  328. (
  329. 'type' => 'varchar-100',
  330. 'name' => '地区',
  331. 'default' => '',
  332. 'desc' => '地区',
  333. 'match' => 'is_string',
  334. 'search' => 'linkage',
  335. 'update' => 'linkage',//多级联动 option参数:请求地址(参数为level_num当前联动级数,level_id当前选择的id)
  336. 'option' => Dever::url('api.get', 'area'),
  337. 'list' => 'Dever::load("area/api.string", "{area}")',
  338. ),
  339. # 无限级联动
  340. 'category' => array
  341. (
  342. 'type' => 'varchar-500',
  343. 'name' => '分类',
  344. 'default' => '',
  345. 'desc' => '分类',
  346. 'match' => 'is_string',
  347. 'search' => 'linkage',
  348. //'update' => 'linkage',
  349. 'option' => Dever::url('api.get', 'category'),
  350. 'list' => 'Dever::load("category/api.string", "{category}")',
  351. ),
  352. # 属性管理
  353. 'attr' => array
  354. (
  355. 'type' => 'varchar-800',
  356. 'name' => '属性设置',
  357. 'default' => '',
  358. 'desc' => '属性设置',
  359. 'match' => 'option',
  360. 'update' => 'checkbox',
  361. 'option' => $attr,
  362. 'update_input' => '',
  363. 'update_input_default' => '',
  364. 'update_parent' => 'checkbox',
  365. ),
  366. # 属性管理 需要用这个来设置值
  367. 'attr_input' => array
  368. (
  369. 'type' => 'text-255',
  370. 'name' => '属性值设置',
  371. 'default' => '',
  372. 'desc' => '属性值设置',
  373. 'match' => 'option',
  374. ),
  375. */
  376. 'mobile' => array
  377. (
  378. 'type' => 'varchar-32',
  379. 'name' => '手机号',
  380. 'default' => '',
  381. 'desc' => '请输入手机号',
  382. 'match' => Dever::rule('mobile'),
  383. 'update' => 'text',
  384. 'search' => 'fulltext',
  385. 'list' => true,
  386. 'level' => 1,
  387. # 显示在table中
  388. //'list_table'=> '111',
  389. ),
  390. 'password' => array
  391. (
  392. 'type' => 'varchar-64',
  393. 'name' => '管理员密码',
  394. 'default' => '',
  395. 'desc' => '请输入管理员密码',
  396. 'match' => 'option',
  397. 'update' => 'password',
  398. 'callback' => 'hash.sha256',
  399. ),
  400. 'config' => array
  401. (
  402. 'type' => 'int-11',
  403. 'name' => '后台配置',
  404. 'default' => '1',
  405. 'desc' => '请选择后台配置',
  406. 'match' => 'is_numeric',
  407. 'option' => $config,
  408. 'update' => 'select',
  409. 'list' => true,
  410. ),
  411. 'role' => array
  412. (
  413. 'type' => 'varchar-100',
  414. 'name' => '角色',
  415. 'default' => '1',
  416. 'desc' => '请选择角色',
  417. 'match' => 'is_string',
  418. 'option' => $role,
  419. 'update' => 'checkbox',
  420. //'list' => true,
  421. ),
  422. 'group' => array
  423. (
  424. 'type' => 'int-11',
  425. 'name' => '分组',
  426. 'default' => '1',
  427. 'desc' => '请选择分组',
  428. 'match' => 'is_numeric',
  429. 'option' => $group,
  430. 'update' => 'select',
  431. //'list' => true,
  432. # 取代option,从接口里读取选项
  433. //'update_search' => 'goods/lib/manage.search_sku',
  434. ),
  435. 'top' => array
  436. (
  437. 'type' => 'text-255',
  438. 'name' => '头部菜单-这里的头部菜单如果设置,则会覆盖角色中的头部菜单',
  439. 'default' => '',
  440. 'desc' => '请选择头部菜单',
  441. 'match' => 'option',
  442. 'update' => 'checkbox',
  443. 'option' => $top,
  444. ),
  445. 'state' => array
  446. (
  447. 'type' => 'tinyint-1',
  448. 'name' => '数据状态',
  449. 'default' => '1',
  450. 'desc' => '请选择状态',
  451. 'match' => 'is_numeric',
  452. //'option' => $option,
  453. //'update' => 'radio',
  454. //'list' => true,
  455. //'extend' => true,//扩展功能,该字段为虚拟字段,只在数据库中建立extend字段来保存 后续实现
  456. ),
  457. /*
  458. 提供冲突检测机制(乐观锁),保证高并发下的数据安全
  459. 这是模仿自 php 的 Memcached 扩展 后续实现
  460. 'token' => array
  461. (
  462. 'type' => 'int-11',
  463. 'name' => 'token',
  464. 'default' => '1',
  465. 'desc' => 'token',
  466. 'match' => 'is_numeric',
  467. ),
  468. */
  469. 'status' => array
  470. (
  471. 'type' => 'tinyint-1',
  472. 'name' => '状态',
  473. 'default' => '1',
  474. 'desc' => '请选择状态',
  475. 'match' => 'is_numeric',
  476. 'option' => $status,
  477. 'update' => 'radio',
  478. 'list' => true,
  479. 'edit' => true,
  480. ),
  481. 'cdate' => array
  482. (
  483. 'type' => 'int-11',
  484. 'name' => '录入时间',
  485. 'match' => array('is_numeric', DEVER_TIME),
  486. 'desc' => '',
  487. # 只有insert时才生效
  488. 'insert' => true,
  489. 'list' => 'date("Y-m-d H:i:s", {cdate})',
  490. ),
  491. ),
  492. 'manage' => array
  493. (
  494. 'delete' => false,
  495. // 载入自定义资源
  496. 'res' => array
  497. (
  498. 'js' => 'demo',
  499. 'css' => 'demo',
  500. ),
  501. # 快捷更新
  502. /*
  503. 'list_button' => array
  504. (
  505. 'edit' => array('审核', 'name'),
  506. ),
  507. */
  508. /*
  509. 'insert' => false,
  510. 'edit' => false,
  511. //'delete' => false,
  512. # 自定义快捷新增和编辑
  513. 'button' => array
  514. (
  515. '新增' => array('fast', 'name,reorder'),
  516. ),
  517. # 快捷更新
  518. 'list_button' => array
  519. (
  520. 'edit' => array('编辑', 'name,reorder'),
  521. ),
  522. */
  523. ),
  524. # 更新表结构
  525. 'alter' => array
  526. (
  527. 2 => array
  528. (
  529. //array('update', 'role', 'role', 'varchar-100 1 角色'),
  530. //array('add', 'config', 'config', 'int-11 1 配置'),
  531. ),
  532. 'version' => 2,
  533. ),
  534. # 默认值
  535. /*
  536. 'default' => array
  537. (
  538. 'col' => 'username,email,password,role,state,cdate',
  539. 'value' => array
  540. (
  541. //'"DMC","DMC@dever.cc","'. md5('admin_' . date('Y_m_d_H')) . '",1, 1,' . time(),
  542. '"admin","DMC@dever.cc","'. hash('sha256', 'admin_123') . '",1, 1,' . DEVER_TIME,
  543. ),
  544. ),
  545. */
  546. # 索引
  547. 'index' => array
  548. (
  549. # 索引名 => 索引id
  550. //'id' => 'id,state',
  551. ),
  552. # request 请求接口定义
  553. 'request' => array
  554. (
  555. # one 根据用户名和密码取一条数据
  556. 'user' => array
  557. (
  558. # 匹配的正则或函数 必填项
  559. 'where' => array
  560. (
  561. //'username' => '/^([A-Za-z0-9])/',
  562. //'username' => 'yes',
  563. 'email' => 'yes',
  564. 'status' => 1,
  565. 'state' => 1,
  566. //'password' => 'is_string',
  567. ),
  568. 'type' => 'one',
  569. # 为这个接口独立设置缓存
  570. 'cache' => true,
  571. ),
  572. # one 根据用户名和密码取一条数据
  573. 'email' => array
  574. (
  575. # 匹配的正则或函数 必填项
  576. 'where' => array
  577. (
  578. //'username' => '/^([A-Za-z0-9])/',
  579. //'username' => 'yes',
  580. 'email' => 'yes',
  581. 'status' => 1,
  582. 'state' => 1,
  583. //'password' => 'is_string',
  584. ),
  585. 'type' => 'one',
  586. # 为这个接口独立设置缓存
  587. 'cache' => true,
  588. ),
  589. # one 根据用户名和密码取一条数据
  590. 'mobile' => array
  591. (
  592. # 匹配的正则或函数 必填项
  593. 'where' => array
  594. (
  595. //'username' => '/^([A-Za-z0-9])/',
  596. //'username' => 'yes',
  597. 'mobile' => 'yes',
  598. 'status' => 1,
  599. 'state' => 1,
  600. //'password' => 'is_string',
  601. ),
  602. 'type' => 'one',
  603. # 为这个接口独立设置缓存
  604. 'cache' => true,
  605. ),
  606. # 更新密码
  607. 'password' => array
  608. (
  609. 'type' => 'update',
  610. 'where' => array
  611. (
  612. 'id' => 'yes',
  613. ),
  614. 'set' => array
  615. (
  616. 'password' => 'yes',
  617. ),
  618. ),
  619. ),
  620. );