增加:共创股东 - 等级管理
This commit is contained in:
parent
644f2b0c18
commit
cf7282cc5d
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
namespace app\common\dao\system\merchant;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\system\merchant\MerchantShareholderLevel;
|
||||
|
||||
class MerchantShareholderLevelDao extends BaseDao{
|
||||
|
||||
protected function getModel(): string{
|
||||
return MerchantShareholderLevel::class;
|
||||
}
|
||||
/**
|
||||
* Common: 公共查询模型
|
||||
* Author: wu-hui
|
||||
* Time: 2024/06/12 11:28
|
||||
* @param array $params
|
||||
* @return MerchantShareholderLevel
|
||||
*/
|
||||
public function searchModel(array $params){
|
||||
return (new MerchantShareholderLevel())
|
||||
->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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
namespace app\common\model\system\merchant;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
|
||||
class MerchantShareholderLevel extends BaseModel{
|
||||
|
||||
public static function tablePk(): string{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string{
|
||||
return 'merchant_shareholder_level';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
namespace app\common\repositories\system\merchant;
|
||||
|
||||
|
||||
use app\common\dao\system\merchant\MerchantShareholderLevelDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Route;
|
||||
|
||||
class MerchantShareholderLevelRepository extends BaseRepository{
|
||||
|
||||
public function __construct(MerchantShareholderLevelDao $dao){
|
||||
$this->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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
namespace app\controller\admin\system\merchant;
|
||||
|
||||
use app\common\repositories\system\merchant\MerchantShareholderLevelRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
use think\App;
|
||||
|
||||
|
||||
class ShareholderLevel extends BaseController{
|
||||
|
||||
protected $repository;
|
||||
|
||||
public function __construct(App $app, MerchantShareholderLevelRepository $repository){
|
||||
parent::__construct($app);
|
||||
|
||||
$this->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('删除成功');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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');
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue