人人商城

fangroup.ctrl.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. uni_user_permission_check('mc_fangroup');
  8. load()->model('mc');
  9. $dos = array('post', 'display', 'del');
  10. $do = !empty($_GPC['do']) && in_array($do, $dos) ? $do : 'display';
  11. if ($do == 'display') {
  12. $tags = mc_fans_groups(true);
  13. }
  14. if ($do == 'post') {
  15. $account = WeAccount::create($_W['acid']);
  16. if (!empty($_GPC['tagname'])) {
  17. foreach ($_GPC['tagname'] as $key => $value) {
  18. $value = trim($value);
  19. if (!empty($value) && trim($_GPC['origin_name'][$key]) != $value) {
  20. $state = $account->fansTagEdit($_GPC['tagid'][$key], $value);
  21. if (is_error($state)) {
  22. message($state['message'], url('mc/fangroup/'), 'error');
  23. }
  24. }
  25. }
  26. }
  27. if (!empty($_GPC['tag_add'])) {
  28. foreach ($_GPC['tag_add'] as $value) {
  29. $value = trim($value);
  30. if (!empty($value)) {
  31. $state = $account->fansTagAdd($value);
  32. if (is_error($state)) {
  33. message($state['message'], url('mc/fangroup/'), 'error');
  34. }
  35. }
  36. }
  37. }
  38. message('保存标签名称成功', url('mc/fangroup/'), 'success');
  39. }
  40. if ($do == 'del') {
  41. $tagid = intval($_GPC['__input']['id']);
  42. $account = WeAccount::create($_W['acid']);
  43. $tags = $account->fansTagDelete($tagid);
  44. if (!is_error($tags)) {
  45. $fans_list = pdo_getall('mc_mapping_fans', array('groupid LIKE' => "%,{$tagid},%"));
  46. $count = count($fans_list);
  47. if (!empty($count)) {
  48. $buffSize = ceil($count / 500);
  49. for ($i = 0; $i < $buffSize; $i++) {
  50. $sql = '';
  51. $buffer = array_slice($fans_list, $i * 500, 500);
  52. foreach ($buffer as $fans) {
  53. $tagids = trim(str_replace(','.$tagid.',', ',', $fans['groupid']), ',');
  54. if ($tagids == ',') {
  55. $tagids = '';
  56. }
  57. $sql .= 'UPDATE ' . tablename('mc_mapping_fans') . " SET `groupid`='" . $tagids . "' WHERE `fanid`={$fans['fanid']};";
  58. }
  59. pdo_query($sql); }
  60. }
  61. pdo_delete('mc_fans_tag_mapping', array('tagid' => $tagid));
  62. message(error(0, 'success'), '', 'ajax');
  63. } else {
  64. message(error(-1, $tags['message']), '', 'ajax');
  65. }
  66. }
  67. template('mc/fansgroup');