diff --git a/app/common/dao/system/merchant/MerchantBrandDao.php b/app/common/dao/system/merchant/MerchantBrandDao.php new file mode 100644 index 0000000..c75fb33 --- /dev/null +++ b/app/common/dao/system/merchant/MerchantBrandDao.php @@ -0,0 +1,36 @@ +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'); + } + + +} diff --git a/app/common/model/system/merchant/MerchantBrand.php b/app/common/model/system/merchant/MerchantBrand.php new file mode 100644 index 0000000..6eb60e3 --- /dev/null +++ b/app/common/model/system/merchant/MerchantBrand.php @@ -0,0 +1,16 @@ +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) ? '添加商户分类' : '编辑商户分类'); + } + + + + + + + + +} diff --git a/app/controller/admin/system/merchant/MerchantBrand.php b/app/controller/admin/system/merchant/MerchantBrand.php new file mode 100644 index 0000000..81aab5d --- /dev/null +++ b/app/controller/admin/system/merchant/MerchantBrand.php @@ -0,0 +1,114 @@ +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('删除成功'); + } + + + +} diff --git a/route/admin/merchant.php b/route/admin/merchant.php index 60c6f0f..d883261 100644 --- a/route/admin/merchant.php +++ b/route/admin/merchant.php @@ -45,6 +45,30 @@ Route::group(function () { '_path' => '/merchant/classify', '_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 () {