创建角色

main
limu 12 months ago
parent 04fb71596e
commit 59b4cf5af0
  1. 112
      app/common/dao/system/admin/PartnerDao.php
  2. 41
      app/common/model/system/admin/Partner.php
  3. 96
      app/common/repositories/system/admin/PartnerRepository.php
  4. 55
      app/controller/admin/system/admin/Partner.php
  5. 28
      app/validate/admin/PartnerRoleValidate.php
  6. 13
      route/admin/role.php

@ -0,0 +1,112 @@
<?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\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 exists(int $id)
{
$query = ($this->getModel())::getDB()->where($this->getPk(), $id)->where('is_del', 0);
return $query->count() > 0;
}
/**
* @param int $id
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-09
*/
public function get( $id)
{
return Admin::getInstance()->where('is_del', 0)->find($id);
}
/**
* @param $field
* @param $value
* @param int|null $except
* @return bool
* @author xaboy
* @day 2020-03-30
*/
public function fieldExists($field, $value, ?int $except = null): bool
{
$query = ($this->getModel())::getDB()->where($field, $value)->where('is_del', 0);
if (!is_null($except)) $query->where($this->getPk(), '<>', $except);
return $query->count() > 0;
}
/**
* @param string $account
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-09
*/
public function accountByAdmin(string $account)
{
return Admin::getInstance()->where('account', $account)
->where('is_del', 0)
->field(['account', 'pwd', 'real_name', 'login_count', 'admin_id', 'status'])
->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,96 @@
<?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 id
* @param array $data 数组
* @return int
* @throws DbException
* @author 张先生
* @date 2020-03-26
*/
public function update(int $id, array $data)
{
if (isset($data['roles']))
$data['roles'] = implode(',', $data['roles']);
return $this->dao->update($id, $data);
}
}

@ -0,0 +1,55 @@
<?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);
$this->repository->create($data);
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,19 @@ 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' => '添加合作人角色',
]);
})->prefix('admin.system.admin')->option([
'_path' => 'self',
'_auth' => true,
]);
})->middleware(AllowOriginMiddleware::class)
->middleware(AdminTokenMiddleware::class, true)
->middleware(AdminAuthMiddleware::class)

Loading…
Cancel
Save