1748153932 1 year ago
commit a7ae2b7f1a
  1. 67
      app/common/dao/system/admin/PartnerDao.php
  2. 41
      app/common/model/system/admin/Partner.php
  3. 42
      app/common/model/user/UserPartner.php
  4. 119
      app/common/repositories/system/admin/PartnerRepository.php
  5. 100
      app/controller/admin/system/admin/Partner.php
  6. 28
      app/validate/admin/PartnerRoleValidate.php
  7. 22
      route/admin/role.php

@ -0,0 +1,67 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\admin;
use app\common\dao\BaseDao;
use app\common\model\BaseModel;
use app\common\model\system\admin\Partner;
use app\common\model\user\UserPartner;
use app\common\model\system\admin\Admin;
use think\db\BaseQuery;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
class PartnerDao extends BaseDao
{
/**
* @return BaseModel
* @author xaboy
* @day 2020-03-30
*/
protected function getModel(): string
{
return Partner::class;
}
/**
* @param array $where
* @return BaseQuery
* @author xaboy
* @day 2020-04-09
*/
public function search(array $where = [])
{
$query = Partner::getDB();
if (isset($where['keyword']) && $where['keyword'] !== '') {
$query = $query->whereLike('name', '%' . $where['keyword'] . '%');
}
if (isset($where['status']) && $where['status'] !== '') {
$query = $query->where('status', intval($where['status']));
}
return $query;
}
public function existsUser(int $id)
{
return UserPartner::getInstance()->where('partner_id', $id)
->field(['id'])
->find();
}
}

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\system\admin;
use app\common\model\BaseModel;
use app\common\model\system\auth\Role;
class Partner extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'system_partner_role';
}
}

@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\user;
use app\common\model\BaseModel;
class UserPartner extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'user_partner';
}
}

@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system\admin;
//附件
use app\common\dao\system\admin\PartnerDao;
use app\common\model\system\admin\Partner;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\auth\RoleRepository;
use crmeb\exceptions\AuthException;
use crmeb\services\JwtTokenService;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
use FormBuilder\Form;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Route;
use think\Model;
/**
* Class BaseRepository
* @package common\repositories
* @mixin AdminDao
*/
class PartnerRepository extends BaseRepository
{
public function __construct(PartnerDao $dao)
{
/**
* @var AdminDao
*/
$this->dao = $dao;
}
/**
* @param array $where
* @param $page
* @param $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getList(array $where, $page, $limit)
{
$query = $this->dao->search($where);
$count = $query->count();
$list = $query->page($page, $limit)->select();
return compact('list', 'count');
}
public function create(array $data)
{
return $this->dao->create($data);
}
/**
* @param int $id
* @return Form
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-09
*/
public function getDetail(int $id)
{
return $this->dao->get($id)->toArray();
}
/**
*
* 更新
* @param int $id id
* @param array $data 数组
* @return int
* @throws DbException
* @author 张先生
* @date 2020-03-26
*/
public function update(int $id, array $data)
{
return $this->dao->update($id, $data);
}
//删除
public function delete(int $id)
{
return $this->dao->delete($id);
}
//检测角色绑定用户
public function existsUser(int $id)
{
return $this->dao->existsUser($id);
}
}

@ -0,0 +1,100 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\admin;
use app\common\repositories\system\admin\PartnerRepository;
use crmeb\basic\BaseController;
use app\validate\admin\PartnerRoleValidate;
use app\validate\admin\AdminValidate;
use Exception;
use FormBuilder\Exception\FormBuilderException;
use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
class Partner extends BaseController
{
protected $repository;
public function __construct(App $app, PartnerRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function list()
{
$where = $this->request->params(['keyword', 'date', 'status']);
[$page, $limit] = $this->getPage();
return app('json')->success($this->repository->getList($where, $page, $limit));
}
public function add(PartnerRoleValidate $validate)
{
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level', 'area_id', ['status', 1]]);
$validate->check($data);
if ($this->repository->fieldExists('area_id', $data['area_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]]);
$validate->check($data);
if ($data['is_area'] == 1) {
if (empty($data['area_id']) && empty($data['area_level'])) {
return app('json')->fail('请选择所属区域');
}
if ($this->repository->fieldExists('area_id', $data['area_id'], $data['id'])) {
return app('json')->fail('该区域已经有了代理角色,请勿重复添加');
}
} else {
$data['area_level'] = 0;
$data['area_id'] = 0;
}
$this->repository->update($data['id'], $data);
return app('json')->success('编辑成功');
}
public function detail($id)
{
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
return app('json')->success($this->repository->getDetail($id));
}
public function delete($id)
{
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
if ($this->repository->existsUser($id))
return app('json')->fail('该角色下存在绑定用,请先取消绑定');
$this->repository->delete($id);
return app('json')->success('删除成功');
}
}

@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\validate\admin;
use think\Validate;
class PartnerRoleValidate extends Validate
{
protected $failException = true;
protected $rule = [
'name|角色名称' => 'require|max:20',
'ratio|比例' => 'require',
'status|启用状态' => 'require|in:0,1',
];
}

@ -135,6 +135,28 @@ Route::group(function () {
'_auth' => true,
]);
//合伙人角色
Route::group('partner/role', function () {
Route::get('list', '.Partner/list')->name('systemPartnerList')->option([
'_alias' => '合作人角色列表',
]);
Route::post('add', '.Partner/add')->name('systemPartnerAdd')->option([
'_alias' => '添加合作人角色',
]);
Route::post('update', '.Partner/update')->name('systemPartnerUpdate')->option([
'_alias' => '编辑合作人角色',
]);
Route::get('detail/:id', '.Partner/detail')->name('systemPartnerDetail')->option([
'_alias' => '读取合作人角色详情',
]);
Route::get('delete/:id', '.Partner/delete')->name('systemPartnerDel')->option([
'_alias' => '删除合作人角色',
]);
})->prefix('admin.system.admin')->option([
'_path' => 'self',
'_auth' => true,
]);
})->middleware(AllowOriginMiddleware::class)
->middleware(AdminTokenMiddleware::class, true)
->middleware(AdminAuthMiddleware::class)

Loading…
Cancel
Save