User.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\controller\apps\dealer;
  10. use app\store\controller\Controller;
  11. use app\common\service\qrcode\Poster;
  12. use app\store\model\dealer\User as UserModel;
  13. use app\store\model\dealer\Referee as RefereeModel;
  14. use app\store\model\dealer\Setting as SettingModel;
  15. /**
  16. * 分销商管理
  17. * Class User
  18. * @package app\store\controller\apps\dealer
  19. */
  20. class User extends Controller
  21. {
  22. /**
  23. * 构造方法
  24. * @throws \app\common\exception\BaseException
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. * @throws \think\exception\DbException
  28. */
  29. public function _initialize()
  30. {
  31. parent::_initialize();
  32. }
  33. /**
  34. * 分销商用户列表
  35. * @param string $search
  36. * @return mixed
  37. * @throws \think\exception\DbException
  38. */
  39. public function index($search = '')
  40. {
  41. $model = new UserModel;
  42. return $this->fetch('index', [
  43. 'list' => $model->getList($search),
  44. 'basicSetting' => SettingModel::getItem('basic'),
  45. ]);
  46. }
  47. /**
  48. * 分销商用户列表
  49. * @param string $user_id
  50. * @param int $level
  51. * @return mixed
  52. * @throws \think\exception\DbException
  53. */
  54. public function fans($user_id, $level = -1)
  55. {
  56. $model = new RefereeModel;
  57. return $this->fetch('fans', [
  58. 'list' => $model->getList($user_id, $level),
  59. 'basicSetting' => SettingModel::getItem('basic'),
  60. ]);
  61. }
  62. /**
  63. * 编辑分销商
  64. * @param $dealer_id
  65. * @return mixed
  66. * @throws \think\exception\DbException
  67. */
  68. public function edit($dealer_id)
  69. {
  70. $model = UserModel::detail($dealer_id);
  71. if (!$this->request->isAjax()) {
  72. return $this->fetch('edit', compact('model'));
  73. }
  74. if ($model->edit($this->postData('model'))) {
  75. return $this->renderSuccess('更新成功', url('apps.dealer.user/index'));
  76. }
  77. return $this->renderError($model->getError() ?: '更新失败');
  78. }
  79. /**
  80. * 删除分销商
  81. * @param $dealer_id
  82. * @return array|bool
  83. * @throws \think\exception\DbException
  84. */
  85. public function delete($dealer_id)
  86. {
  87. $model = UserModel::detail($dealer_id);
  88. if (!$model->setDelete()) {
  89. return $this->renderError('删除失败');
  90. }
  91. return $this->renderSuccess('删除成功');
  92. }
  93. /**
  94. * 分销商二维码
  95. * @param $dealer_id
  96. * @throws \app\common\exception\BaseException
  97. * @throws \think\exception\DbException
  98. * @throws \Exception
  99. */
  100. public function qrcode($dealer_id)
  101. {
  102. $model = UserModel::detail($dealer_id);
  103. $Qrcode = new Poster($model);
  104. $this->redirect($Qrcode->getImage());
  105. }
  106. }