PermController.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class PermController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. }
  19. public function index()
  20. {
  21. $_GPC = I('request.');
  22. $this->gpc = $_GPC;
  23. $pindex = max(1, intval($_GPC['page']));
  24. $psize = 20;
  25. $status = $_GPC['status'];
  26. $condition = ' and deleted=0';
  27. if (!empty($_GPC['keyword'])) {
  28. $_GPC['keyword'] = trim($_GPC['keyword']);
  29. $condition .= ' and rolename like "%'.$_GPC['keyword'].'%" ';
  30. }
  31. if ($_GPC['status'] != '') {
  32. $condition .= ' and status=' . intval($_GPC['status']);
  33. }
  34. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX') . 'lionfish_comshop_perm_role WHERE 1 ' . $condition .
  35. ' ORDER BY id desc LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize);
  36. foreach ($list as &$row) {
  37. $row['usercount'] = M('seller')->where( array('s_role_id' => $row['id'] ) )->count();
  38. }
  39. unset($row);
  40. $total = M('lionfish_comshop_perm_role')->where("1 ". $condition )->count();
  41. $pager = pagination2($total, $pindex, $psize);
  42. $this->pager = $pager;
  43. $this->list = $list;
  44. $this->display();
  45. }
  46. public function rolestatus()
  47. {
  48. $_GPC = I('request.');
  49. $id = intval($_GPC['id']);
  50. if (empty($id)) {
  51. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  52. }
  53. $status = intval($_GPC['status']);
  54. $items = M('lionfish_comshop_perm_role')->field('id,rolename')->where( 'id in( ' . $id . ' )' )->select();
  55. foreach ($items as $item) {
  56. M('lionfish_comshop_perm_role')->where( array('id' => $item['id']) )->save( array('status' => $status) );
  57. }
  58. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  59. }
  60. protected function perm_shop()
  61. {
  62. return array(
  63. 'text' => '商城概况',
  64. 'index' => array(
  65. 'analys' => '统计'
  66. )
  67. );
  68. }
  69. protected function perm_goods()
  70. {
  71. return array(
  72. 'text' => '商品管理',
  73. 'goods' => array(
  74. 'index' => '商品列表',
  75. 'goodscategory' => '商品分类',
  76. 'goodsspec' => '商品规格',
  77. 'goodstag' => '商品标签',
  78. 'config' => '商品设置',
  79. 'settime' => '统一时间',
  80. 'industrial' => '工商资质',
  81. )
  82. );
  83. }
  84. protected function perm_order()
  85. {
  86. return array(
  87. 'text' => '订单管理',
  88. 'order' => array(
  89. 'index' => '订单列表',
  90. 'ordersendall' => '批量发货',
  91. 'orderaftersales' => '售后管理',
  92. 'ordercomment' => '评价列表',
  93. 'ordercomment_config' => '评价设置',
  94. 'config' => '订单设置',
  95. )
  96. );
  97. }
  98. protected function perm_user()
  99. {
  100. return array(
  101. 'text' => '会员管理',
  102. 'user' => array(
  103. 'index' => '会员列表',
  104. 'userjia' => '虚拟会员管理',
  105. 'config' => '会员设置',
  106. 'usergroup' => '会员分组',
  107. 'userlevel' => '会员等级',
  108. )
  109. );
  110. }
  111. protected function perm_distribution()
  112. {
  113. return array(
  114. 'text' => '会员分销',
  115. 'distribution' => array(
  116. 'distribution' => '分销列表',
  117. 'distributionorder' => '订单管理',
  118. 'config' => '分销设置',
  119. 'qrcodeconfig' => '海报设置',
  120. 'withdrawallist' => '提现列表',
  121. 'withdraw_config' => '提现设置',
  122. )
  123. );
  124. }
  125. protected function perm_communityhead()
  126. {
  127. return array(
  128. 'text' => '团长管理',
  129. 'communityhead' => array(
  130. 'index' => '团长列表',
  131. 'usergroup' => '团长分组',
  132. 'headlevel' => '团长等级',
  133. 'config' => '团长设置',
  134. 'distribulist' => '提现列表',
  135. 'distributionpostal' => '提现设置',
  136. )
  137. );
  138. }
  139. protected function perm_supply()
  140. {
  141. return array(
  142. 'text' => '供应商管理',
  143. 'supply' => array(
  144. 'index' => '供应商列表',
  145. 'admintixianlist' => '提现申请',
  146. 'distributionpostal' => '提现设置',
  147. 'baseconfig' => '基本设置',
  148. 'config' => '申请页面内容',
  149. )
  150. );
  151. }
  152. protected function perm_article()
  153. {
  154. return array(
  155. 'text' => '文章列表',
  156. 'article' => array(
  157. 'index' => '文章列表',
  158. )
  159. );
  160. }
  161. //拼团
  162. protected function perm_group()
  163. {
  164. return array(
  165. 'text' => '拼团管理',
  166. 'group' => array(
  167. 'goods' => '商品管理',
  168. 'goodscategory' => '商品分类',
  169. 'goodsspec' => '商品规格',
  170. 'goodstag' => '商品标签',
  171. 'goodsvircomment' => '虚拟评价',
  172. 'pintuan' => '拼团管理',
  173. 'orderlist' => '订单管理',
  174. 'ordersendall' => '批量发货',
  175. 'orderaftersales' => '售后管理',
  176. 'slider' => '幻灯片',
  177. 'config' => '拼团设置',
  178. 'pincommiss' => '拼团佣金',
  179. 'withdrawallist' => '提现列表',
  180. 'withdraw_config' => '提现设置',
  181. )
  182. );
  183. }
  184. protected function perm_delivery()
  185. {
  186. return array(
  187. 'text' => '配送单管理',
  188. 'delivery' => array(
  189. 'delivery' => '配送单管理',
  190. 'get_delivery_list' => '生成配送单',
  191. 'delivery_line' => '配送路线',
  192. 'delivery_clerk' => '配送人员',
  193. 'config' => '设置',
  194. )
  195. );
  196. }
  197. protected function perm_data_static()
  198. {
  199. return array(
  200. 'text' => '数据',
  201. 'reports' => array(
  202. 'index' => '营业数据',
  203. 'datastatics' => '数据统计',
  204. 'communitystatics' => '团长统计',
  205. )
  206. );
  207. }
  208. protected function perm_perm()
  209. {
  210. return array(
  211. 'text' => '角色管理',
  212. 'perm' => array(
  213. 'index' => '角色管理',
  214. 'user' => '后台用户管理',
  215. )
  216. );
  217. }
  218. protected function perm_attachment()
  219. {
  220. return array(
  221. 'text' => '附件管理',
  222. 'attachment' => array(
  223. 'index' => '附件设置',
  224. )
  225. );
  226. }
  227. protected function perm_config()
  228. {
  229. return array(
  230. 'text' => '设置',
  231. 'config' => array(
  232. 'index' => '基本设置',
  233. 'picture' => '图片设置',
  234. ),
  235. 'weprogram' => array(
  236. 'index' => '参数设置',
  237. 'templateconfig' => '模板消息设置',
  238. 'tabbar' => '底部菜单设置',
  239. ),
  240. 'configpay' => array(
  241. 'index' => '支付设置',
  242. ),
  243. 'configindex' => array(
  244. 'slider' => '幻灯片',
  245. 'notice' => '公告',
  246. 'navigat' => '导航图标',
  247. 'noticesetting' => '公告设置',
  248. 'qgtab' => '抢购切换',
  249. 'cube' => '图片魔方',
  250. 'video' => '视频',
  251. ),
  252. 'shipping' => array(
  253. 'templates' => '运费模板',
  254. ),
  255. 'logistics' => array(
  256. 'inface' => '物流接口',
  257. ),
  258. 'express' => array(
  259. 'config' => '快递方式',
  260. 'deconfig' => '配送方式设置',
  261. ),
  262. 'copyright' => array(
  263. 'index' => '版权说明',
  264. 'about' => '关于我们',
  265. 'ordericon' => '关于我们',
  266. 'account' => '后台账户',
  267. ),
  268. );
  269. }
  270. protected function perm_marketing()
  271. {
  272. return array(
  273. 'text' => '营销活动',
  274. 'marketing' => array(
  275. 'coupon' => '优惠券管理',
  276. 'category' => '优惠券分类',
  277. 'couponsend' => '手动发送',
  278. 'fullreduction' => '满减',
  279. 'signinreward' => '积分签到',
  280. 'points' => '积分设置',
  281. 'recharge' => '充值设置',
  282. 'explain' => '充值说明',
  283. 'recharge_diary' => '充值流水',
  284. 'special' => '主题活动',
  285. 'seckill' => '整点秒杀',
  286. ),
  287. 'points' => array(
  288. 'goods' => '积分商品',
  289. 'order' => '兑换订单',
  290. ),
  291. 'solitaire' => array(
  292. 'index' => '群接龙管理',
  293. 'config' => '群接龙设置',
  294. ),
  295. 'recipe' => array(
  296. 'index' => '菜谱',
  297. 'equity' => '菜谱分类',
  298. 'order' => '幻灯片',
  299. 'config' => '菜谱设置',
  300. ),
  301. 'vipcard' => array(
  302. 'index' => '会员卡',
  303. 'equity' => '会员权益',
  304. 'order' => '购买会员订单',
  305. 'config' => '会员卡设置',
  306. ),
  307. );
  308. }
  309. public function allPerms()
  310. {
  311. $perms = array(
  312. 'index' => $this->perm_shop(),
  313. 'goods' => $this->perm_goods(),
  314. 'order' => $this->perm_order(),
  315. 'user' => $this->perm_user(),
  316. 'distribution' => $this->perm_distribution(),
  317. 'communityhead' => $this->perm_communityhead(),
  318. 'supply' => $this->perm_supply(),
  319. 'marketing' => $this->perm_marketing(),
  320. 'article' => $this->perm_article(),
  321. 'delivery' => $this->perm_delivery(),
  322. 'reports' => $this->perm_data_static(),
  323. 'group' => $this->perm_group(),
  324. 'perm' => $this->perm_perm(),
  325. 'attachment' => $this->perm_attachment(),
  326. 'config' => $this->perm_config(),
  327. );
  328. return $perms;
  329. }
  330. public function formatPerms()
  331. {
  332. $perms = $this->allPerms();
  333. $array = array();
  334. foreach ($perms as $key => $value) {
  335. if (is_array($value)) {
  336. foreach ($value as $ke => $val) {
  337. if (!is_array($val)) {
  338. $array['parent'][$key][$ke] = $val;
  339. }
  340. if (is_array($val) && ($ke != 'xxx')) {
  341. foreach ($val as $k => $v) {
  342. if (!is_array($v)) {
  343. $array['son'][$key][$ke][$k] = $v;
  344. }
  345. if (is_array($v) && ($k != 'xxx')) {
  346. foreach ($v as $kk => $vv) {
  347. if (!is_array($vv)) {
  348. $array['grandson'][$key][$ke][$k][$kk] = $vv;
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. return $array;
  358. }
  359. public function addrole()
  360. {
  361. $_GPC = I('request.');
  362. $id = intval($_GPC['id']);
  363. $item = M('lionfish_comshop_perm_role')->where( array('deleted' => 0 , 'id' => $id) )->find();
  364. $perms = $this->formatPerms();
  365. $role_perms = array();
  366. $user_perms = array();
  367. if (!empty($item)) {
  368. $role_perms = explode(',', $item['perms2']);
  369. }
  370. $user_perms = explode(',', $item['perms2']);
  371. $this->item = $item;
  372. $this->perms = $perms;
  373. $this->user_perms = $user_perms;
  374. if (IS_POST) {
  375. $data = array( 'rolename' => trim($_GPC['rolename']), 'status' => intval($_GPC['status']), 'perms2' => is_array($_GPC['perms']) ? implode(',', $_GPC['perms']) : '');
  376. if (!empty($id)) {
  377. M('lionfish_comshop_perm_role')->where( array('id' => $id) )->save( $data );
  378. }
  379. else {
  380. M('lionfish_comshop_perm_role')->add( $data );
  381. }
  382. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  383. }
  384. $this->display();
  385. }
  386. public function roledelete()
  387. {
  388. $_GPC = I('request.');
  389. $id = intval($_GPC['id']);
  390. if (empty($id)) {
  391. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  392. }
  393. $items = M('lionfish_comshop_perm_role')->field('id,rolename')->where('id in( ' . $id . ' )')->select();
  394. foreach ($items as $item) {
  395. M('lionfish_comshop_perm_role')->where( array('id' => $item['id']) )->delete();
  396. }
  397. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  398. }
  399. public function userstatus()
  400. {
  401. $_GPC = I('request.');
  402. $id = intval($_GPC['id']);
  403. if (empty($id)) {
  404. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  405. }
  406. $status = intval($_GPC['s_status']);
  407. //$items = M()->query('SELECT s_id FROM ' . C('DB_PREFIX'). 'seller WHERE s_id in( ' . $id . ' ) ');
  408. $items = M('seller')->field('s_id')->where( 's_id in( ' . $id . ' )' )->select();
  409. foreach ($items as $item) {
  410. M('seller')->where( array('s_id' => $item['s_id']) )->save( array('s_status' => $status) );
  411. }
  412. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  413. }
  414. public function user()
  415. {
  416. $_GPC = I('request.');
  417. $pindex = max(1, intval($_GPC['page']));
  418. $psize = 20;
  419. $status = $_GPC['status'];
  420. $condition = ' and u.deleted=0 ';
  421. $this->gpc = $_GPC;
  422. if (!empty($_GPC['keyword'])) {
  423. $_GPC['keyword'] = trim($_GPC['keyword']);
  424. $condition .= ' and ( u.s_uname like "%'.$_GPC['keyword'].'%" )';
  425. //or u.s_true_name like "%'.$_GPC['keyword'].'%" or u.s_mobile like "%'.$_GPC['keyword'].'%"
  426. }
  427. if ($_GPC['roleid'] != '') {
  428. $condition .= ' and u.s_role_id=' . intval($_GPC['roleid']);
  429. }
  430. if ($_GPC['status'] != '') {
  431. $condition .= ' and u.s_status=' . intval($_GPC['status']);
  432. }
  433. $list = M()->query('SELECT u.*,r.rolename FROM ' . C('DB_PREFIX') . 'seller as u ' .
  434. ' left join ' . C('DB_PREFIX'). 'lionfish_comshop_perm_role as r on u.s_role_id =r.id ' .
  435. ' WHERE 1 ' . $condition . ' ORDER BY s_id desc LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize);
  436. $total_arr = M()->query('SELECT count(*) as count FROM ' . C('DB_PREFIX'). 'seller as u ' .
  437. ' left join ' . C('DB_PREFIX'). 'lionfish_comshop_perm_role as r on u.s_role_id =r.id '
  438. . ' WHERE 1 ' . $condition . ' ', $params);
  439. $total = $total_arr[0]['count'];
  440. $pager = pagination2($total, $pindex, $psize);
  441. $roles = M()->query('select id,rolename from ' . C('DB_PREFIX'). 'lionfish_comshop_perm_role where deleted=0' );
  442. $this->list = $list;
  443. $this->roles = $roles;
  444. $this->pager = $pager;
  445. $this->display();
  446. }
  447. public function rolequery()
  448. {
  449. $_GPC = I('request.');
  450. $this->gpc = $_GPC;
  451. $kwd = trim($_GPC['keyword']);
  452. $this->kwd = $kwd;
  453. $params = array();
  454. $condition = ' and deleted=0';
  455. if (!empty($kwd)) {
  456. $condition .= ' AND `rolename` LIKE "%'.$kwd.'%" ';
  457. }
  458. $ds = M()->query('SELECT id,rolename,perms2 FROM ' . C('DB_PREFIX') . 'lionfish_comshop_perm_role WHERE status=1 ' . $condition . ' order by id asc' );
  459. $this->ds = $ds;
  460. $this->display();
  461. }
  462. /**
  463. * 改变状态
  464. */
  465. public function change()
  466. {
  467. $id = I('request.id');
  468. //ids
  469. if (empty($id)) {
  470. $ids = I('request.ids');
  471. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  472. }
  473. if (empty($id)) {
  474. show_json(0, array('message' => '参数错误'));
  475. }
  476. $type = I('request.type');
  477. $value = I('request.value');
  478. if (!(in_array($type, array('enabled', 'displayorder')))) {
  479. show_json(0, array('message' => '参数错误'));
  480. }
  481. $items = M('lionfish_comshop_article')->where( array('id' => array('in', $id) ) )->select();
  482. foreach ($items as $item) {
  483. M('lionfish_comshop_article')->where( array('id' => $item['id']) )->save( array($type => $value) );
  484. }
  485. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  486. }
  487. public function adduser()
  488. {
  489. $_GPC = I('request.');
  490. $this->gpc = $_GPC;
  491. $id = intval($_GPC['id']);
  492. $item = array();
  493. if( $id >0 )
  494. {
  495. $item = M('seller')->where( array('s_id' => $id ,'deleted' => 0) )->find();
  496. }
  497. $perms = $this->formatPerms();
  498. $this->item = $item;
  499. $this->perms = $perms;
  500. $user_perms = array();
  501. $role_perms = array();
  502. if (!empty($item)) {
  503. $role = M('lionfish_comshop_perm_role')->where( array('id' => $item['s_role_id'],'deleted' => 0 ) )->find();
  504. if (!empty($role)) {
  505. $role_perms = explode(',', $role['perms2']);
  506. }
  507. $user_perms = explode(',', $item['perms2']);
  508. }
  509. $this->user_perms = $user_perms;
  510. $this->role_perms = $role_perms;
  511. $this->role = $role;
  512. if (IS_POST) {
  513. $data = array(
  514. 's_uname' => trim($_GPC['s_uname']),
  515. 's_true_name' => trim($_GPC['s_true_name']),
  516. 's_mobile' => trim($_GPC['s_mobile']),
  517. 's_passwd' => ($_GPC['s_passwd']),
  518. 's_role_id' => ($_GPC['roleid']),
  519. 's_login_count' => '',
  520. 's_last_login_ip' => '',
  521. 's_last_ip_region' => '',
  522. 's_create_time' => time(),
  523. 's_last_login_time' => '',
  524. 's_status' => intval($_GPC['s_status']),
  525. 'perms' => '',
  526. 'deleted' => 0,
  527. );
  528. if (!empty($item['s_id'])) {
  529. unset($data['s_create_time']);
  530. $user = M('seller')->where( array('s_uname' => $data['s_uname']) )->find();
  531. if (!empty($_GPC['s_passwd'])) {
  532. $data['s_passwd'] = think_ucenter_encrypt($data['s_passwd'],C('SELLER_PWD_KEY'));
  533. }else{
  534. unset($data['s_passwd']);
  535. }
  536. M('seller')->where( array('s_id' => $id) )->save($data);
  537. }
  538. else {
  539. $user = M('seller')->where( array('s_uname' => $data['s_uname']) )->find();
  540. $data['s_passwd'] = think_ucenter_encrypt($data['s_passwd'],C('SELLER_PWD_KEY'));
  541. if( !empty($user) )
  542. {
  543. show_json(0, array('msg' => '此用户为系统存在用户,无法添加') );
  544. }
  545. M('seller')->add( $data );
  546. }
  547. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  548. }
  549. $this->display();
  550. }
  551. /**
  552. * 删除公告
  553. */
  554. public function userdelete()
  555. {
  556. $id = I('request.id');
  557. if (empty($id)) {
  558. $ids = I('request.ids');
  559. $id = (is_array($ids) ? implode(',', $ids) : 0);
  560. }
  561. $items = M('seller')->field('s_id')->where( array('s_id' => array('in', $id) ) )->select();
  562. //if (empty($item)) {
  563. // $item = array();
  564. // }
  565. foreach ($items as $item) {
  566. M('seller')->where( array('s_id' => $item['s_id']) )->delete();
  567. }
  568. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  569. }
  570. }
  571. ?>