UserGroup.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. *
  4. * @author: wuhaotian<442384644@qq.com>
  5. * @day: 2019/12/07
  6. */
  7. namespace app\admin\controller\user;
  8. use app\admin\controller\AuthController;
  9. use app\admin\model\user\UserGroup as GroupModel;
  10. use crmeb\services\JsonService;
  11. use crmeb\services\UtilService;
  12. use crmeb\services\FormBuilder as Form;
  13. use think\facade\Route as Url;
  14. /**
  15. * Class UserGroup
  16. * @package app\admin\controller\user
  17. */
  18. class UserGroup extends AuthController
  19. {
  20. /**
  21. * 会员分组页面
  22. * @return string
  23. */
  24. public function index()
  25. {
  26. return $this->fetch();
  27. }
  28. /**
  29. * 分组列表
  30. */
  31. public function groupList()
  32. {
  33. $where = UtilService::getMore([
  34. ['page', 1],
  35. ['limit', 20],
  36. ]);
  37. return JsonService::successlayui(GroupModel::getList($where));
  38. }
  39. /**
  40. * 添加/修改分组页面
  41. * @param int $id
  42. * @return string
  43. */
  44. public function addGroup($id = 0)
  45. {
  46. $group = GroupModel::get($id);
  47. $f = array();
  48. if (!$group) {
  49. $f[] = Form::input('group_name', '分组名称', '');
  50. } else {
  51. $f[] = Form::input('group_name', '分组名称', $group->getData('group_name'));
  52. }
  53. $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('saveGroup', array('id' => $id)));
  54. $this->assign(compact('form'));
  55. return $this->fetch('public/form-builder');
  56. }
  57. /**
  58. * 添加/修改
  59. * @param int $id
  60. */
  61. public function saveGroup($id = 0)
  62. {
  63. $data = UtilService::postMore([
  64. ['group_name', ''],
  65. ]);
  66. if ($id) {
  67. if (GroupModel::where('id', $id)->update($data)) {
  68. return JsonService::success('修改成功');
  69. } else {
  70. return JsonService::fail('修改失败或者您没有修改什么!');
  71. }
  72. } else {
  73. if ($res = GroupModel::create($data)) {
  74. return JsonService::success('保存成功', ['id' => $res->id]);
  75. } else {
  76. return JsonService::fail('保存失败!');
  77. }
  78. }
  79. }
  80. /**
  81. * 删除
  82. * @param $id
  83. * @throws \Exception
  84. */
  85. public function delete($id)
  86. {
  87. if (!$id) return $this->failed('数据不存在');
  88. if (!GroupModel::be(['id' => $id])) return $this->failed('产品数据不存在');
  89. if (!GroupModel::where('id', $id)->delete())
  90. return JsonService::fail(GroupModel::getErrorInfo('恢复失败,请稍候再试!'));
  91. else
  92. return JsonService::successful('恢复门店成功!');
  93. }
  94. }