添加:活动相关
This commit is contained in:
parent
825026be42
commit
afc9b69500
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
namespace app\common\dao\marketing\activity;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\marketing\activity\Activity;
|
||||
|
||||
class ActivityDao extends BaseDao{
|
||||
|
||||
protected function getModel(): string{
|
||||
return Activity::class;
|
||||
}
|
||||
/**
|
||||
* Common: 公共搜索模型
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/14 15:51
|
||||
* @param array $params
|
||||
* @return Activity
|
||||
*/
|
||||
public function searchList(array $params){
|
||||
return (new Activity())
|
||||
->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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
namespace app\common\dao\marketing\activity;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\marketing\activity\Cate;
|
||||
|
||||
class CateDao extends BaseDao{
|
||||
|
||||
protected function getModel(): string{
|
||||
return Cate::class;
|
||||
}
|
||||
/**
|
||||
* Common: 公共搜索模型
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/14 15:21
|
||||
* @param array $params
|
||||
* @return Cate
|
||||
*/
|
||||
public function searchList(array $params){
|
||||
return (new Cate())
|
||||
->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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
namespace app\common\model\marketing\activity;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
|
||||
class Activity extends BaseModel{
|
||||
|
||||
|
||||
public static function tablePk():string{
|
||||
return 'id';
|
||||
}
|
||||
public static function tableName():string{
|
||||
return 'activity';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
namespace app\common\model\marketing\activity;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
|
||||
class Cate extends BaseModel{
|
||||
|
||||
|
||||
public static function tablePk():string{
|
||||
return 'id';
|
||||
}
|
||||
public static function tableName():string{
|
||||
return 'activity_cate';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\repositories\marketing\activity;
|
||||
|
||||
use app\common\dao\marketing\activity\ActivityDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Route;
|
||||
|
||||
class ActivityRepository extends BaseRepository{
|
||||
|
||||
protected $dao;
|
||||
|
||||
public function __construct(ActivityDao $dao){
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\repositories\marketing\activity;
|
||||
|
||||
use app\common\dao\marketing\activity\CateDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Route;
|
||||
|
||||
class CateRepository extends BaseRepository{
|
||||
|
||||
protected $dao;
|
||||
|
||||
public function __construct(CateDao $dao){
|
||||
$this->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']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
namespace app\controller\admin\marketing\activity;
|
||||
|
||||
|
||||
use app\common\repositories\marketing\activity\ActivityRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Activity extends BaseController{
|
||||
|
||||
protected $repository;
|
||||
|
||||
public function __construct(App $app, ActivityRepository $repository){
|
||||
parent::__construct($app);
|
||||
$this->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('删除成功');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
namespace app\controller\admin\marketing\activity;
|
||||
|
||||
|
||||
use app\common\repositories\marketing\activity\CateRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Cate extends BaseController{
|
||||
|
||||
protected $repository;
|
||||
|
||||
public function __construct(App $app, CateRepository $repository){
|
||||
parent::__construct($app);
|
||||
$this->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('删除成功');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue