From 59b4cf5af09cfddb2e66edb9589db74cf6d5983b Mon Sep 17 00:00:00 2001 From: limu Date: Tue, 12 Dec 2023 15:13:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/system/admin/PartnerDao.php | 112 ++++++++++++++++++ app/common/model/system/admin/Partner.php | 41 +++++++ .../system/admin/PartnerRepository.php | 96 +++++++++++++++ app/controller/admin/system/admin/Partner.php | 55 +++++++++ app/validate/admin/PartnerRoleValidate.php | 28 +++++ route/admin/role.php | 13 ++ 6 files changed, 345 insertions(+) create mode 100644 app/common/dao/system/admin/PartnerDao.php create mode 100644 app/common/model/system/admin/Partner.php create mode 100644 app/common/repositories/system/admin/PartnerRepository.php create mode 100644 app/controller/admin/system/admin/Partner.php create mode 100644 app/validate/admin/PartnerRoleValidate.php diff --git a/app/common/dao/system/admin/PartnerDao.php b/app/common/dao/system/admin/PartnerDao.php new file mode 100644 index 0000000..ba7f240 --- /dev/null +++ b/app/common/dao/system/admin/PartnerDao.php @@ -0,0 +1,112 @@ + +// +---------------------------------------------------------------------- + + +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(); + } +} + diff --git a/app/common/model/system/admin/Partner.php b/app/common/model/system/admin/Partner.php new file mode 100644 index 0000000..4cc579d --- /dev/null +++ b/app/common/model/system/admin/Partner.php @@ -0,0 +1,41 @@ + +// +---------------------------------------------------------------------- + + +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'; + } + +} diff --git a/app/common/repositories/system/admin/PartnerRepository.php b/app/common/repositories/system/admin/PartnerRepository.php new file mode 100644 index 0000000..00f4170 --- /dev/null +++ b/app/common/repositories/system/admin/PartnerRepository.php @@ -0,0 +1,96 @@ + +// +---------------------------------------------------------------------- + + +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); + } + + + + + + +} diff --git a/app/controller/admin/system/admin/Partner.php b/app/controller/admin/system/admin/Partner.php new file mode 100644 index 0000000..88275bc --- /dev/null +++ b/app/controller/admin/system/admin/Partner.php @@ -0,0 +1,55 @@ + +// +---------------------------------------------------------------------- + + +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('添加成功'); + } +} diff --git a/app/validate/admin/PartnerRoleValidate.php b/app/validate/admin/PartnerRoleValidate.php new file mode 100644 index 0000000..abfb786 --- /dev/null +++ b/app/validate/admin/PartnerRoleValidate.php @@ -0,0 +1,28 @@ + +// +---------------------------------------------------------------------- + + +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', + ]; +} diff --git a/route/admin/role.php b/route/admin/role.php index 4115599..372fed6 100644 --- a/route/admin/role.php +++ b/route/admin/role.php @@ -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)