From 638b64f97919939af539a5c4a8fbd156549f650c Mon Sep 17 00:00:00 2001 From: limu Date: Wed, 13 Dec 2023 11:45:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=92=8C=E5=88=86=E9=85=8D?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=88=E4=BD=9C=E4=BA=BA=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/system/admin/PartnerDao.php | 10 +++++ .../system/admin/PartnerRepository.php | 3 ++ .../user/UserPartnerRepository.php | 30 +++++++++++++ app/controller/admin/user/User.php | 43 +++++++++++++++---- route/admin/user.php | 8 ++++ 5 files changed, 86 insertions(+), 8 deletions(-) diff --git a/app/common/dao/system/admin/PartnerDao.php b/app/common/dao/system/admin/PartnerDao.php index 171f476..a633b3c 100644 --- a/app/common/dao/system/admin/PartnerDao.php +++ b/app/common/dao/system/admin/PartnerDao.php @@ -63,5 +63,15 @@ class PartnerDao extends BaseDao ->find(); } + public function getAll() + { + return Partner::getDB()->where('status', 1)->order('id desc')->field('')->select()->toArray(); + } + + public function exists(int $id) + { + return $this->existsWhere(['id' => $id]); + } + } diff --git a/app/common/repositories/system/admin/PartnerRepository.php b/app/common/repositories/system/admin/PartnerRepository.php index 924a3ea..7a96764 100644 --- a/app/common/repositories/system/admin/PartnerRepository.php +++ b/app/common/repositories/system/admin/PartnerRepository.php @@ -113,7 +113,10 @@ class PartnerRepository extends BaseRepository public function existsUser(int $id) { return $this->dao->existsUser($id); + } + + } diff --git a/app/common/repositories/user/UserPartnerRepository.php b/app/common/repositories/user/UserPartnerRepository.php index 5bc51ef..aa8f7ca 100644 --- a/app/common/repositories/user/UserPartnerRepository.php +++ b/app/common/repositories/user/UserPartnerRepository.php @@ -13,8 +13,13 @@ namespace app\common\repositories\user; +use app\common\model\user\UserPartner; use app\common\repositories\BaseRepository; use app\common\dao\user\UserPartnerDao as dao; +use app\common\dao\system\admin\PartnerDao; +use FormBuilder\Factory\Elm; +use think\facade\Db; +use think\facade\Route; /** * Class UserAddressRepository @@ -64,4 +69,29 @@ class UserPartnerRepository extends BaseRepository $list = $this->dao->getAll($uid)->order('id desc')->select(); return compact('list'); } + + public function changePartnerForm($uid) + { + /** @var UserLabelRepository $make */ + $list = $this->dao->getAll($uid)->column('partner_id'); + $partnerForm = new PartnerDao(); + $option = $partnerForm->getAll(); + return compact('list', 'option'); + } + + public function editPartner(int $uid, array $partner_id = []) + { + return Db::transaction(function () use ($uid, $partner_id) { + //先清空 + UserPartner::getInstance()->where('uid', $uid)->delete(); + //再插入 + if (!empty($partner_id)) { + $data = []; + foreach ($partner_id as $k => $v) { + $data[] = ['uid' => $uid, 'partner_id' => $v,'create_time' => date("Y-m-d H:i:s")]; + } + UserPartner::getInstance()->insertAll($data); + } + }); + } } diff --git a/app/controller/admin/user/User.php b/app/controller/admin/user/User.php index 7c286f4..b329f0b 100644 --- a/app/controller/admin/user/User.php +++ b/app/controller/admin/user/User.php @@ -15,9 +15,11 @@ namespace app\controller\admin\user; use app\common\repositories\store\ExcelRepository; +use app\common\repositories\user\UserPartnerRepository; use app\common\repositories\user\UserSpreadLogRepository; use app\common\repositories\user\UserVisitRepository; use crmeb\basic\BaseController; +use app\common\repositories\system\admin\PartnerRepository; use app\common\repositories\store\coupon\StoreCouponRepository; use app\common\repositories\store\coupon\StoreCouponUserRepository; use app\common\repositories\store\order\StoreOrderRepository; @@ -89,7 +91,7 @@ class User extends BaseController 'group_id', 'phone', 'uid', - ]); + ]); [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->getList($where, $page, $limit)); } @@ -140,7 +142,7 @@ class User extends BaseController $data['pwd'] = $this->repository->encodePassword($data['repwd']); unset($data['repwd']); if ($data['is_promoter']) $data['promoter_time'] = date('Y-m-d H:i:s'); - $this->repository->create('h5',$data); + $this->repository->create('h5', $data); return app('json')->success('添加成功'); } @@ -162,7 +164,7 @@ class User extends BaseController return app('json')->fail('密码不一致'); $data['pwd'] = $this->repository->encodePassword($data['repwd']); unset($data['repwd']); - $this->repository->update($id,$data); + $this->repository->update($id, $data); return app('json')->success('修改成功'); } @@ -212,7 +214,7 @@ class User extends BaseController $data['label_id'] = implode(',', $label_id); if ($data['is_promoter']) $data['promoter_time'] = date('Y-m-d H:i:s'); - if(!$data['birthday']) unset($data['birthday']); + if (!$data['birthday']) unset($data['birthday']); $this->repository->update($id, $data); return app('json')->success('编辑成功'); @@ -302,6 +304,31 @@ class User extends BaseController } + //读取用户标签 + public function getPartner(int $id, UserPartnerRepository $partnerRepository) + { + if (!$this->repository->exists($id)) + return app('json')->fail('数据不存在'); + return app('json')->success($partnerRepository->changePartnerForm($id)); + } + + public function changePartner(PartnerRepository $partnerRepository,UserPartnerRepository $userPartnerRepository) + { + $partner_id = (array)$this->request->param('partner_id', []); + $id = (int)$this->request->param('uid', ''); + if (!$this->repository->exists($id)) + return app('json')->fail('数据不存在'); + foreach ($partner_id as $k => $value) { + $partner_id[$k] = (int)$value; + if (!$partnerRepository->exists((int)$value)) + return app('json')->fail('所选合作人角色不存在'); + } + $userPartnerRepository->editPartner($id, $partner_id); + return app('json')->success('修改成功'); + + } + + /** * @return mixed * @throws DataNotFoundException @@ -554,7 +581,7 @@ class User extends BaseController public function memberForm($id) { - return app('json')->success(formToData($this->repository->memberForm($id,1))); + return app('json')->success(formToData($this->repository->memberForm($id, 1))); } public function memberSave($id) @@ -568,7 +595,7 @@ class User extends BaseController public function spreadLevelForm($id) { - return app('json')->success(formToData($this->repository->memberForm($id,0))); + return app('json')->success(formToData($this->repository->memberForm($id, 0))); } public function spreadLevelSave($id) @@ -587,8 +614,8 @@ class User extends BaseController public function svipUpdate($id) { - $data = $this->request->params(['is_svip','add_time','type']); - $this->repository->svipUpdate($id, $data,$this->request->adminId()); + $data = $this->request->params(['is_svip', 'add_time', 'type']); + $this->repository->svipUpdate($id, $data, $this->request->adminId()); return app('json')->success('修改成功'); } } diff --git a/route/admin/user.php b/route/admin/user.php index 2fe54d3..53e8c49 100644 --- a/route/admin/user.php +++ b/route/admin/user.php @@ -176,6 +176,14 @@ Route::group(function () { Route::post('svip/:id', '/svipUpdate')->name('systemUserSvipUpdate')->option([ '_alias' => '用户标签编辑', ]); + //合作人角色 + Route::get('partner/:id', '/getPartner')->name('systemUserGetPartner')->option([ + '_alias' => '获取合作人角色', + ]); + Route::post('partner/edit', '/changePartner')->name('systemUserChangePartner')->option([ + '_alias' => '用户合作人角色编辑', + ]); + })->prefix('admin.user.User')->option([ '_path' => '/user/list',