代码恢复

main
limu 1 year ago
parent d39aa1a6f8
commit c72b3fa02d
  1. 15
      app/controller/admin/system/admin/Partner.php
  2. 26
      app/controller/admin/user/User.php
  3. 1
      app/validate/admin/PartnerRoleValidate.php

@ -48,19 +48,23 @@ class Partner extends BaseController
public function add(PartnerRoleValidate $validate)
{
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level', 'area_id', ['status', 1]]);
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level',
'area_id', ['status', 1], ['type', 1], ['max_role_num', 0], 'brand_id', 'trade_id']);
$validate->check($data);
if ($this->repository->fieldExists('area_id', $data['area_id'])) {
if ($data['is_area'] == 1 && $this->repository->fieldExists('area_id', $data['area_id'])) {
return app('json')->fail('该区域已经有了代理角色,请勿重复添加');
}
if (($data['type'] == 3 && empty($data['brand_id']) || ($data['type'] == 4 && empty($data['trade_id'])))) {
return app('json')->fail('请补全对应角色类型的关联数据');
}
$this->repository->create($data);
return app('json')->success('添加成功');
}
public function update(PartnerRoleValidate $validate)
{
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level', 'area_id', 'id', ['status', 1]]);
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level',
'area_id', ['status', 1], ['type', 1], ['max_role_num', 0], 'brand_id', 'trade_id']);
$validate->check($data);
if ($data['is_area'] == 1) {
@ -74,6 +78,9 @@ class Partner extends BaseController
$data['area_level'] = 0;
$data['area_id'] = 0;
}
if (($data['type'] == 3 && empty($data['brand_id']) || ($data['type'] == 4 && empty($data['trade_id'])))) {
return app('json')->fail('请补全对应角色类型的关联数据');
}
$this->repository->update($data['id'], $data);

@ -35,6 +35,8 @@ use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use app\common\repositories\system\admin\PartnerRepository;
use app\common\repositories\user\UserPartnerRepository;
use think\facade\Db;
/**
@ -601,4 +603,28 @@ class User extends BaseController
$this->repository->svipUpdate($id, $data,$this->request->adminId());
return app('json')->success('修改成功');
}
//读取用户标签
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('修改成功');
}
}

@ -24,5 +24,6 @@ class PartnerRoleValidate extends Validate
'name|角色名称' => 'require|max:20',
'ratio|比例' => 'require',
'status|启用状态' => 'require|in:1,2',
'type|角色类型' => 'require|in:1,2,3,4',
];
}

Loading…
Cancel
Save