From cf7282cc5d06b322b9a7122ff047f2dcc8966d63 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Wed, 12 Jun 2024 15:52:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E5=85=B1=E5=88=9B?= =?UTF-8?q?=E8=82=A1=E4=B8=9C=20-=20=E7=AD=89=E7=BA=A7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../merchant/MerchantShareholderLevelDao.php | 46 ++++++ .../merchant/MerchantShareholderLevel.php | 21 +++ .../MerchantShareholderLevelRepository.php | 143 ++++++++++++++++++ .../system/merchant/ShareholderLevel.php | 90 +++++++++++ route/admin/merchant.php | 6 + 5 files changed, 306 insertions(+) create mode 100644 app/common/dao/system/merchant/MerchantShareholderLevelDao.php create mode 100644 app/common/model/system/merchant/MerchantShareholderLevel.php create mode 100644 app/common/repositories/system/merchant/MerchantShareholderLevelRepository.php create mode 100644 app/controller/admin/system/merchant/ShareholderLevel.php diff --git a/app/common/dao/system/merchant/MerchantShareholderLevelDao.php b/app/common/dao/system/merchant/MerchantShareholderLevelDao.php new file mode 100644 index 0000000..a029184 --- /dev/null +++ b/app/common/dao/system/merchant/MerchantShareholderLevelDao.php @@ -0,0 +1,46 @@ +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['merchant_type']) && $params['merchant_type'] !== '',function($query) use ($params){ + $query->where('merchant_type', (int)$params['merchant_type']); + }) + ->when(isset($params['weight']) && $params['weight'] !== '',function($query) use ($params){ + $query->where('weight', (int)$params['weight']); + }) + ->order('weight DESC,id DESC'); + } + + + + + + + + + +} diff --git a/app/common/model/system/merchant/MerchantShareholderLevel.php b/app/common/model/system/merchant/MerchantShareholderLevel.php new file mode 100644 index 0000000..caeef32 --- /dev/null +++ b/app/common/model/system/merchant/MerchantShareholderLevel.php @@ -0,0 +1,21 @@ +dao = $dao; + } + + /** + * Common: 公共查询模型 + * Author: wu-hui + * Time: 2024/06/12 11:29 + * @param $search + * @return mixed + */ + public function getSearchModel($search){ + return $this->dao->searchModel($search); + } + + /** + * Common: 根据条件获取列表 + * Author: wu-hui + * Time: 2024/06/12 13:42 + * @param array $params + * @param int $page + * @param int $limit + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(array $params,int $page,int $limit):array{ + $query = $this->dao->searchModel($params); + $count = $query->count(); + $list = $query->page($page,$limit)->select()->toArray(); + + return compact('count','list'); + } + /** + * Common: 生成创建表单 + * Author: wu-hui + * Time: 2024/06/12 13:30 + * @param $id + * @param $merchantType + * @return \FormBuilder\Form + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function getEditFormData($id, $merchantType){ + $info = []; + if($id > 0) { + $info = $this->getSearchModel(['id'=>$id])->findOrEmpty()->toArray(); + $info['coupon_ids'] = $info['coupon_ids'] ? array_map(function($couponId){ return (int)$couponId;},explode(',', $info['coupon_ids'])) : []; + } + // 获取默认权重 + $defaultWeight = (int)$this->getSearchModel(['merchant_type' => $merchantType])->max('weight'); + $defaultWeight = $defaultWeight + 1; + // 表单生成 + $url = Route::buildUrl('systemMerchantShareholderLevelSetForm', ['id' => $id,'merchant_type' => $merchantType])->build(); + $form = Elm::createForm($url); + $rules = [ + Elm::input('title','等级名称')->required(), + Elm::number('weight','等级权重', $defaultWeight)->required()->col(12)->min(1), + Elm::number('price','支付金额')->required()->col(12)->min(0), + Elm::number('mer_quota','名额限制')->required()->col(24)->min(0)->appendRule('suffix',[ + 'type' => 'div', + 'style' => ['color' => '#999999'], + 'domProps' => [ + 'innerHTML' => '每个商户最大可绑定多少该等级的共创股东,为0时则不限制!', + ] + ]), + Elm::number('quota','赠送瓶装酒额度')->required()->col(12)->min(0), + Elm::number('vegetable_quota','赠送菜卡额度')->required()->col(12)->min(0), + Elm::number('oil_quota','赠送油卡额度')->required()->col(12)->min(0), + Elm::number('wine_quota','赠送封坛酒额度')->required()->col(12)->min(0), + Elm::select('coupon_ids', '赠送优惠券')->options(function () { + return app()->make(StoreCouponRepository::class) + ->getSearch(['mer_id' => request()->merId(), 'status' => 1, 'is_del' => 0]) + ->column('title as label,coupon_id as value'); + })->col(24)->multiple(true)->filterable(true), + ]; + $form->setRule($rules); + + return $form->setTitle( $id > 0 ? '编辑活动' : '添加活动')->formData($info); + } + /** + * Common: 信息添加 or 编辑 + * Author: wu-hui + * Time: 2024/06/12 13:40 + * @param $params + * @return \app\common\dao\BaseDao|int|\think\Model + * @throws \think\db\exception\DbException + */ + public function submitEditFormData($params){ + $id = $params['id'] ?? 0; + // 是否允许编辑 + if(empty($params['title'])) throw new ValidateException('请输入分类名称!'); + if($params['weight'] <= 0) throw new ValidateException('等级权重必须大于0!'); + // 数据生成 + $data = [ + 'title' => $params['title'], + 'weight' => $params['weight'], + 'mer_quota' => $params['mer_quota'] ?? 0, + 'price' => $params['price'] ?? 0, + 'quota' => $params['quota'], + 'vegetable_quota' => $params['vegetable_quota'], + 'oil_quota' => $params['oil_quota'], + 'wine_quota' => $params['wine_quota'], + 'coupon_ids' => is_array($params['coupon_ids']) ? implode(',',$params['coupon_ids']) : $params['coupon_ids'], + 'merchant_type' => $params['merchant_type'], + ]; + // 判断:权重值是否已经存在 + $isHas = $this->getSearchModel(['merchant_type' => $params['merchant_type'],'weight' => $params['weight']]) + ->when($id > 0,function($query) use ($id){ + $query->where('id','<>',$id); + }) + ->value('id'); + if($isHas > 0) throw new ValidateException('权重已经存在!'); + // 判断:名称是否已经存在 + $titleIsHas = $this->getSearchModel(['merchant_type' => $params['merchant_type']]) + ->where('title', $params['title']) + ->when($id > 0, function($query) use ($id){ + $query->where('id', '<>', $id); + }) + ->value('id'); + if($titleIsHas) throw new ValidateException('等级名称已经存在!'); + // 编辑操作 + if($id > 0) return $this->dao->update($params['id'],$data); + else return $this->dao->create($data); + } + + + + +} diff --git a/app/controller/admin/system/merchant/ShareholderLevel.php b/app/controller/admin/system/merchant/ShareholderLevel.php new file mode 100644 index 0000000..84ced3f --- /dev/null +++ b/app/controller/admin/system/merchant/ShareholderLevel.php @@ -0,0 +1,90 @@ +repository = $repository; + } + + /** + * Common: 信息列表 + * Author: wu-hui + * Time: 2024/06/12 13:46 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params(['title', 'merchant_type']); + $data = $this->repository->getList((array)$params,(int)$page,(int)$limit); + + return app('json')->success($data); + } + /** + * Common: 生成编辑表单 + * Author: wu-hui + * Time: 2024/06/12 13:31 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function getEditForm(){ + $id = (int)$this->request->param('id'); + $merchantType = (int)$this->request->param('merchant_type'); + $data = $this->repository->getEditFormData($id, $merchantType); + + return app('json')->success(formToData($data)); + } + /** + * Common: 接收编辑表单提交信息并且处理 + * Author: wu-hui + * Time: 2024/06/12 13:41 + * @return mixed + * @throws \think\db\exception\DbException + */ + public function setEditForm(){ + $params = $this->request->params([ + ['id',0], + ['merchant_type', 0], + 'title', + 'weight', + 'mer_quota', + 'price', + 'quota', + 'vegetable_quota', + 'oil_quota', + 'wine_quota', + 'coupon_ids', + 'merchant_type', + ]); + $this->repository->submitEditFormData($params); + + return app('json')->success('编辑成功'); + } + /** + * Common: 生成信息 + * Author: wu-hui + * Time: 2024/06/12 14:44 + * @param $id + * @return mixed + */ + public function delInfo($id){ + $this->repository->update($id,['is_del' => 1]); + + return app('json')->success('删除成功'); + } + + + +} diff --git a/route/admin/merchant.php b/route/admin/merchant.php index d610bbd..0c62939 100644 --- a/route/admin/merchant.php +++ b/route/admin/merchant.php @@ -163,6 +163,12 @@ Route::group(function () { Route::post('quota/list', '.Quota/quotaList')->name('systemMerchantQuotaList'); Route::post('quota/change', '.Quota/quotaChange')->name('systemMerchantQuotaChange'); Route::post('quota/change_record', '.Quota/quotaChangeRecord')->name('systemMerchantQuotaChange'); + // 共创股东 + Route::get('shareholder_level/list','.ShareholderLevel/getList')->name('systemMerchantShareholderLevelGetList'); + Route::post('shareholder_level/get_form','.ShareholderLevel/getEditForm')->name('systemMerchantShareholderLevelGetForm'); + Route::post('shareholder_level/set_form','.ShareholderLevel/setEditForm')->name('systemMerchantShareholderLevelSetForm'); + Route::post('shareholder_level/del_info/:id','.ShareholderLevel/delInfo')->name('systemMerchantShareholderLevelDelInfo'); +