diff --git a/app/common/dao/marketing/activity/ActivityDao.php b/app/common/dao/marketing/activity/ActivityDao.php new file mode 100644 index 0000000..18d4829 --- /dev/null +++ b/app/common/dao/marketing/activity/ActivityDao.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']}%"); + }) + ->order('create_time DESC,id DESC'); + } + + + + + +} diff --git a/app/common/dao/marketing/activity/CateDao.php b/app/common/dao/marketing/activity/CateDao.php new file mode 100644 index 0000000..3ce8e55 --- /dev/null +++ b/app/common/dao/marketing/activity/CateDao.php @@ -0,0 +1,33 @@ +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']}%"); + }) + ->order('create_time DESC,id DESC'); + } + + + +} diff --git a/app/common/model/marketing/activity/Activity.php b/app/common/model/marketing/activity/Activity.php new file mode 100644 index 0000000..2e60496 --- /dev/null +++ b/app/common/model/marketing/activity/Activity.php @@ -0,0 +1,23 @@ +dao = $dao; + } + /** + * Common: 公共查询模型 + * Author: wu-hui + * Time: 2024/03/14 15:51 + * @param $search + * @return \app\common\model\marketing\activity\Activity + */ + public function getSearchModel($search){ + return $this->dao->searchList($search); + } + /** + * Common: 获取信息列表 + * Author: wu-hui + * Time: 2024/03/14 15:51 + * @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->searchList($params); + $count = $query->count(); + $list = $query->page($page,$limit)->select()->toArray(); + + return compact('count','list'); + } + /** + * Common: 生成创建表单数据 + * Author: wu-hui + * Time: 2024/03/14 16:34 + * @param $id + * @return \FormBuilder\Form + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function getEditFormData($id){ + $info = []; + if($id > 0) { + $info = $this->getSearchModel(['id'=>$id])->findOrEmpty()->toArray(); + $info['mer_id'] = $info['mer_id'] ? array_map(function($merId){ return (int)$merId;},explode(',', $info['mer_id'])) : []; + $info['coupon_ids'] = $info['coupon_ids'] ? array_map(function($couponId){ return (int)$couponId;},explode(',', $info['coupon_ids'])) : []; + } + // 表单生成 + $url = Route::buildUrl('systemMarketingActivityEditInfo', ['id' => $id])->build(); + $form = Elm::createForm($url); + $rules = [ + Elm::input('title','活动名称')->required(), + Elm::select('cate_id', '活动分类')->options(function () { + return app()->make(CateRepository::class) + ->getSearchModel([]) + ->column('title as label,id as value'); + }), + 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('mer_id', '参与烟酒馆')->options(function () { + return app()->make(MerchantRepository::class) + ->getSearch(['mer_state' => 1,'merchant_type' => 3, 'status' => 1, 'is_del' => 0]) + ->column('mer_name as label,mer_id as value'); + })->multiple(true)->filterable(true), + 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'); + })->multiple(true)->filterable(true), + Elm::frameImage('image', '活动主图', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=image&type=1') + ->modal(['modal' => false]) + ->width('900px') + ->height('500px') + ->props(['footer' => false]) + ->required(), + ]; + $form->setRule($rules); + + return $form->setTitle( $id > 0 ? '编辑活动' : '添加活动')->formData($info); + } + /** + * Common: 分类编辑表单提交 + * Author: wu-hui + * Time: 2024/03/14 16:17 + * @param $params + * @return \app\common\dao\BaseDao|int|\think\Model + * @throws \think\db\exception\DbException + */ + public function submitEditFormData($params){ + // 是否允许生成兑换码 + if(empty($params['title'])) throw new ValidateException('请输入分类名称'); + // 数据生成 + $data = [ + 'title' => $params['title'], + 'image' => $params['image'], + 'cate_id' => $params['cate_id'], + 'quota' => $params['quota'], + 'vegetable_quota' => $params['vegetable_quota'], + 'oil_quota' => $params['oil_quota'], + 'wine_quota' => $params['wine_quota'], + 'mer_id' => is_array($params['mer_id']) ? implode(',',$params['mer_id']) : $params['mer_id'], + 'coupon_ids' => is_array($params['coupon_ids']) ? implode(',',$params['coupon_ids']) : $params['coupon_ids'], + ]; + // 生成操作 + if($params['id'] > 0){ + return $this->dao->update($params['id'],$data); + }else{ + return $this->dao->create($data); + } + } + + + + + +} diff --git a/app/common/repositories/marketing/activity/CateRepository.php b/app/common/repositories/marketing/activity/CateRepository.php new file mode 100644 index 0000000..78fe906 --- /dev/null +++ b/app/common/repositories/marketing/activity/CateRepository.php @@ -0,0 +1,91 @@ +dao = $dao; + } + /** + * Common: 公共查询模型 + * Author: wu-hui + * Time: 2024/03/14 15:51 + * @param $search + * @return \app\common\model\marketing\activity\Cate + */ + public function getSearchModel($search){ + return $this->dao->searchList($search); + } + /** + * Common: 获取信息列表 + * Author: wu-hui + * Time: 2024/03/14 15:19 + * @param array $params + * @param int $page + * @param int $limit + * @return array + */ + public function getList(array $params,int $page,int $limit):array{ + $query = $this->dao->searchList($params); + $count = $query->count(); + $list = $query->page($page,$limit)->select()->toArray(); + + return compact('count','list'); + } + /** + * Common: 生成创建表单数据 + * Author: wu-hui + * Time: 2024/03/14 15:06 + * @return \FormBuilder\Form + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function getEditFormData($id){ + $title = ''; + if($id > 0) $title = $this->getSearchModel(['id'=>$id])->value('title'); + // 表单生成 + $formData = []; + $url = Route::buildUrl('systemMarketingActivityCateEditInfo', ['id' => $id])->build(); + $form = Elm::createForm($url); + $rules = [ + Elm::input('title','分类名称',$title)->required(), + ]; + $form->setRule($rules); + + return $form->setTitle( $id > 0 ? '编辑活动分类' : '添加活动分类')->formData($formData); + } + /** + * Common: 分类编辑表单提交 + * Author: wu-hui + * Time: 2024/03/14 15:28 + * @param $params + * @return \app\common\dao\BaseDao|int|\think\Model + * @throws \think\db\exception\DbException + */ + public function submitEditFormData($params){ + // 是否允许生成兑换码 + if(empty($params['title'])) throw new ValidateException('请输入分类名称'); + // 生成操作 + if($params['id'] > 0){ + return $this->dao->update($params['id'],[ + 'title' => $params['title'] + ]); + }else{ + return $this->dao->create([ + 'title' => $params['title'] + ]); + } + } + + + + +} diff --git a/app/controller/admin/marketing/activity/Activity.php b/app/controller/admin/marketing/activity/Activity.php new file mode 100644 index 0000000..379b12f --- /dev/null +++ b/app/controller/admin/marketing/activity/Activity.php @@ -0,0 +1,76 @@ +repository = $repository; + } + /** + * Common: 活动列表 + * Author: wu-hui + * Time: 2024/03/14 15:52 + * @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']); + $data = $this->repository->getList((array)$params,(int)$page,(int)$limit); + + return app('json')->success($data); + } + /** + * Common: 编辑表单 + * Author: wu-hui + * Time: 2024/03/14 16:52 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function editForm(){ + $id = (int)$this->request->param('id'); + $data = $this->repository->getEditFormData($id); + + return app('json')->success(formToData($data)); + } + /** + * Common: 提交编辑表单 + * Author: wu-hui + * Time: 2024/03/14 16:52 + * @return mixed + * @throws \think\db\exception\DbException + */ + public function editInfo(){ + $params = $this->request->params(['title','cate_id','quota','vegetable_quota','oil_quota','wine_quota','mer_id','coupon_ids','image',['id', 0]]); + $this->repository->submitEditFormData($params); + + return app('json')->success('编辑成功'); + } + /** + * Common: 删除 + * Author: wu-hui + * Time: 2024/03/14 16:53 + * @return mixed + */ + public function delInfo(){ + $id = (int)$this->request->param('id'); + + $this->repository->update($id,['is_del' => 1]); + + return app('json')->success('删除成功'); + } + + + + +} diff --git a/app/controller/admin/marketing/activity/Cate.php b/app/controller/admin/marketing/activity/Cate.php new file mode 100644 index 0000000..83b3f27 --- /dev/null +++ b/app/controller/admin/marketing/activity/Cate.php @@ -0,0 +1,73 @@ +repository = $repository; + } + /** + * Common: 分类列表 + * Author: wu-hui + * Time: 2024/03/14 15:20 + * @return mixed + */ + public function getList(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params(['title']); + $data = $this->repository->getList((array)$params,(int)$page,(int)$limit); + + return app('json')->success($data); + } + /** + * Common: 分类编辑表单 + * Author: wu-hui + * Time: 2024/03/14 15:06 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function editForm(){ + $id = (int)$this->request->param('id'); + $data = $this->repository->getEditFormData($id); + + return app('json')->success(formToData($data)); + } + /** + * Common: 分类编辑表单提交 + * Author: wu-hui + * Time: 2024/03/14 15:29 + * @return mixed + * @throws \think\db\exception\DbException + */ + public function editInfo(){ + $params = $this->request->params(['title',['id', 0]]); + $this->repository->submitEditFormData($params); + + return app('json')->success('编辑成功'); + } + /** + * Common: 删除分类 + * Author: wu-hui + * Time: 2024/03/14 15:45 + * @return mixed + */ + public function delInfo(){ + $id = (int)$this->request->param('id'); + + $this->repository->delete($id); + + return app('json')->success('删除成功'); + } + + + + +} diff --git a/route/admin/marketing.php b/route/admin/marketing.php index b859cfa..dbcc40e 100644 --- a/route/admin/marketing.php +++ b/route/admin/marketing.php @@ -482,10 +482,6 @@ Route::group(function () { Route::post('apply_to_examine', '/toExamine')->name('systemMarketingAgentToExamine')->option([ '_alias' => '代理申请审核', ]); - - - - // 代理配置相关 Route::post('config','/setConfig')->name('systemMarketingAgentSetConfig')->option([ '_alias' => '设置配置信息', @@ -497,16 +493,49 @@ Route::group(function () { Route::get('commission_list','/commissionList')->name('systemMarketingAgentCommissionList')->option([ '_alias' => '佣金明细', ]); - - })->prefix('admin.marketing.Agent')->option([ '_path' => '/marketing/agent/list', '_auth' => true, ]); + // 活动相关 + Route::group('marketing/activity', function () { + // 活动分类 + Route::get('cate/list','.Cate/getList')->name('systemMarketingActivityCateList')->option([ + '_alias' => '分类列表', + ]); + Route::post('cate/editForm','.Cate/editForm')->name('systemMarketingActivityCateEditFrom')->option([ + '_alias' => '分类编辑表单', + ]); + Route::post('cate/editInfo','.Cate/editInfo')->name('systemMarketingActivityCateEditInfo')->option([ + '_alias' => '分类编辑表单提交', + ]); + Route::post('cate/delInfo','.Cate/delInfo')->name('systemMarketingActivityCateDel')->option([ + '_alias' => '删除分类', + ]); + // 活动列表 + Route::get('list','.Activity/getList')->name('systemMarketingActivityList')->option([ + '_alias' => '活动列表', + ]); + Route::post('editForm','.Activity/editForm')->name('systemMarketingActivityEditFrom')->option([ + '_alias' => '活动编辑表单', + ]); + Route::post('editInfo','.Activity/editInfo')->name('systemMarketingActivityEditInfo')->option([ + '_alias' => '活动编辑表单提交', + ]); + Route::post('delInfo','.Activity/delInfo')->name('systemMarketingActivityDel')->option([ + '_alias' => '删除活动', + ]); + })->prefix('admin.marketing.activity')->option([ + '_path' => '/marketing/agent/list', + '_auth' => true, + ]); + + + })->middleware(AllowOriginMiddleware::class)