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

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. 43
      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;
@ -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('修改成功');
}
}

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