读取和分配用户合作人角色

main
limu 12 months ago
parent 3019ded56a
commit 638b64f979
  1. 10
      app/common/dao/system/admin/PartnerDao.php
  2. 3
      app/common/repositories/system/admin/PartnerRepository.php
  3. 30
      app/common/repositories/user/UserPartnerRepository.php
  4. 27
      app/controller/admin/user/User.php
  5. 8
      route/admin/user.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]);
}
}

@ -113,7 +113,10 @@ class PartnerRepository extends BaseRepository
public function existsUser(int $id)
{
return $this->dao->existsUser($id);
}
}

@ -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);
}
});
}
}

@ -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;
@ -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

@ -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',

Loading…
Cancel
Save