添加:品牌管理

This commit is contained in:
wuhui_zzw 2024-02-04 16:13:30 +08:00
parent 6b375eacec
commit 8295aca637
5 changed files with 270 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
namespace app\common\dao\system\merchant;
use app\common\dao\BaseDao;
use app\common\model\system\merchant\MerchantBrand;
class MerchantBrandDao extends BaseDao{
protected function getModel():string{
return MerchantBrand::class;
}
/**
* Common: 公共查询模型
* Author: wu-hui
* Time: 2024/02/04 15:32
* @param array $params
* @return MerchantBrand
*/
public function searchModel(array $params){
return (new MerchantBrand())
->where('is_del', 0)
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
$query->where('id', (int)$params['id']);
})
->when(isset($params['title']) && $params['title'] !== '',function($query) use ($params){
$query->where('title', 'like', "%${$params['title']}%");
})
->when(isset($params['equivalent_to_title']) && $params['equivalent_to_title'] !== '',function($query) use ($params){
$query->where('title', $params['equivalent_to_title']);
})
->order('create_time DESC,id DESC');
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace app\common\model\system\merchant;
use app\common\model\BaseModel;
class MerchantBrand extends BaseModel{
public static function tablePk():string{
return 'id';
}
public static function tableName():string{
return 'merchant_brand';
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace app\common\repositories\system\merchant;
use app\common\dao\system\merchant\MerchantBrandDao;
use app\common\repositories\BaseRepository;
use FormBuilder\Factory\Elm;
use think\facade\Route;
class MerchantBrandRepository extends BaseRepository{
protected $dao;
public function __construct(MerchantBrandDao $dao)
{
$this->dao = $dao;
}
/**
* Common: 获取公共查询模型
* Author: wu-hui
* Time: 2024/02/04 15:32
* @param $params
* @return \app\common\model\system\merchant\MerchantBrand
*/
public function getSearchModel($params){
return $this->dao->searchModel($params);
}
/**
* Common: 列表获取
* Author: wu-hui
* Time: 2024/02/04 15:33
* @param array $where
* @param $page
* @param $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, $page, $limit){
$query = $this->getSearchModel($where);
$count = $query->count();
$list = $query->page($page, $limit)->select()->toArray();
return compact('count', 'list');
}
/**
* Common: 表单信息
* Author: wu-hui
* Time: 2024/02/04 16:02
* @param int $id
* @return \FormBuilder\Form
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function form($id = 0){
$url = $id > 0 ? 'systemMerchantBrandUpdate' : 'systemMerchantBrandCreate';
$vars = $id > 0 ? compact('id') : [];
$action = Route::buildUrl($url, $vars)->build();
$form = Elm::createForm($action, [
Elm::input('title', '品牌名称')->required(),
]);
$formData = [];
if($id > 0) $formData = $this->dao->get($id)->toArray();
return $form->formData($formData)->setTitle(is_null($id) ? '添加商户分类' : '编辑商户分类');
}
}

View File

@ -0,0 +1,114 @@
<?php
namespace app\controller\admin\system\merchant;
use app\common\repositories\system\merchant\MerchantBrandRepository;
use crmeb\basic\BaseController;
use think\App;
use think\exception\ValidateException;
class MerchantBrand extends BaseController{
protected $repository;
public function __construct(App $app, MerchantBrandRepository $repository){
parent::__construct($app);
$this->repository = $repository;
}
/**
* Common: 列表获取
* Author: wu-hui
* Time: 2024/02/04 15:36
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function lst(){
[$page, $limit] = $this->getPage();
$params = $this->request->params(['title']);
$data = $this->repository->getList($params, $page, $limit);
return app('json')->success($data);
}
/**
* Common: 参数获取
* Author: wu-hui
* Time: 2024/02/04 15:57
* @return array
*/
public function checkParams():array{
$id = $this->request->param('id', 0);
$data = $this->request->params(['title']);
if(empty($data['title'])) throw new ValidateException('请输入品牌名称!');
// 查询是否存在
$isHas = (int)$this->repository
->getSearchModel(['equivalent_to_title'=>$data['title']])
->when($id > 0,function($query) use ($id){
$query->where('id','<>', $id);
})
->count();
if($isHas > 0) throw new ValidateException('品牌已经存在,请勿重复添加!');
return $data;
}
/**
* Common: 表单生成
* Author: wu-hui
* Time: 2024/02/04 16:04
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function editForm(){
$id = $this->request->param('id',0);
$data = formToData($this->repository->form($id));
return app('json')->success($data);
}
/**
* Common: 添加品牌
* Author: wu-hui
* Time: 2024/02/04 15:45
* @return mixed
*/
public function create(){
$data = $this->checkParams();
$this->repository->create($data);
return app('json')->success('添加成功');
}
/**
* Common: 编辑信息
* Author: wu-hui
* Time: 2024/02/04 16:01
* @param $id
* @return mixed
*/
public function update($id){
$data = $this->checkParams();
if (!$this->repository->exists($id)) return app('json')->fail('数据不存在');
$this->repository->update($id, $data);
return app('json')->success('编辑成功');
}
/**
* Common: 删除数据
* Author: wu-hui
* Time: 2024/02/04 16:09
* @param $id
* @return mixed
*/
public function delete($id){
if (!$this->repository->exists($id)) return app('json')->fail('数据不存在');
$this->repository->update($id, ['is_del'=>1]);
return app('json')->success('删除成功');
}
}

View File

@ -45,6 +45,30 @@ Route::group(function () {
'_path' => '/merchant/classify', '_path' => '/merchant/classify',
'_auth' => true, '_auth' => true,
]); ]);
//商户品牌
Route::group('system/merchant', function () {
Route::get('brand/lst', '/lst')->name('systemMerchantBrandLst')->option([
'_alias' => '品牌列表',
]);
Route::get('brand/form', '/editForm')->name('systemMerchantBrandCreateForm')->option([
'_alias' => '品牌编辑表单',
'_auth' => false,
'_form' => 'systemMerchantBrandCreate',
]);
Route::post('brand', '/create')->name('systemMerchantBrandCreate')->option([
'_alias' => '品牌添加',
]);
Route::post('brand/:id', '/update')->name('systemMerchantBrandUpdate')->option([
'_alias' => '品牌编辑',
]);
Route::delete('brand/:id', '/delete')->name('systemMerchantBrandDelete')->option([
'_alias' => '品牌删除',
]);
})->prefix('admin.system.merchant.MerchantBrand')->option([
'_path' => '/merchant/classify',
'_auth' => true,
]);
//申请列表 //申请列表
Route::group('merchant/intention', function () { Route::group('merchant/intention', function () {