添加:兑换码激活
This commit is contained in:
parent
f8e3932894
commit
d08680f3a9
|
|
@ -40,7 +40,18 @@ class VipExchangeCodeDao extends BaseDao{
|
|||
->when(isset($params['group_data_id']) && $params['group_data_id'] !== '',function($query) use ($params){
|
||||
$query->where('group_data_id', (int)$params['group_data_id']);
|
||||
})
|
||||
// ->with()
|
||||
->with([
|
||||
'mer' => function($query){
|
||||
$query->field(['mer_id','mer_name'])->bind(['mer_name']);
|
||||
},
|
||||
'vipInfo' => function($query){
|
||||
$query->field(['group_data_id','value','value as svip_name'])->withAttr('svip_name', function ($val) {
|
||||
$value = json_decode($val, true);
|
||||
|
||||
return $value['svip_name'] ?? '';
|
||||
})->bind(['svip_name']);
|
||||
}
|
||||
])
|
||||
->order('create_time DESC,id DESC');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
namespace app\common\model\user;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
use app\common\model\system\groupData\SystemGroupData;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
|
||||
class UserVipExchangeCode extends BaseModel{
|
||||
|
||||
|
|
@ -15,6 +16,13 @@ class UserVipExchangeCode extends BaseModel{
|
|||
|
||||
|
||||
|
||||
public function mer(){
|
||||
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
|
||||
}
|
||||
public function vipInfo(){
|
||||
return $this->hasOne(SystemGroupData::class, 'group_data_id', 'group_data_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@
|
|||
namespace app\common\repositories\user;
|
||||
|
||||
use app\common\dao\user\VipExchangeCodeDao;
|
||||
use app\common\model\user\UserVipExchangeCode;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\system\groupData\GroupDataRepository;
|
||||
use app\common\repositories\system\groupData\GroupRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Route;
|
||||
|
|
@ -48,7 +52,7 @@ class VipExchangeCodeRepository extends BaseRepository{
|
|||
* @return \FormBuilder\Form
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function getEditFormData():\FormBuilder\Form{
|
||||
public function getEditFormData(){
|
||||
$formData = [];
|
||||
$url = Route::buildUrl('systemUserVipExchangeCodeEditInfo')->build();
|
||||
$form = Elm::createForm($url);
|
||||
|
|
@ -93,6 +97,96 @@ class VipExchangeCodeRepository extends BaseRepository{
|
|||
|
||||
return $this->dao->insertAll($insertData);
|
||||
}
|
||||
/**
|
||||
* Common: 激活表单
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/02 16:51
|
||||
* @return \FormBuilder\Form
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function getActivateFormData(){
|
||||
$formData = [];
|
||||
// 获取商户列表
|
||||
$merList = app()->make(MerchantRepository::class)
|
||||
->search(['is_del' => 0,'merchant_type' => 0,'status' => 1])
|
||||
->field(['mer_id as value','mer_name as label'])
|
||||
->select()
|
||||
->toArray();
|
||||
// 获取有效的会员卡列表
|
||||
$groupId = app()->make(GroupRepository::class)->getSearch(['group_key' => 'svip_pay'])->value('group_id');
|
||||
$vipList = app()->make(GroupDataRepository::class)
|
||||
->getSearch([])
|
||||
->field(['group_data_id as value','value as label'])
|
||||
->withAttr('label', function ($val) {
|
||||
$value = json_decode($val, true);
|
||||
|
||||
return $value['svip_name'] ?? '';
|
||||
})
|
||||
->where('mer_id', 0)
|
||||
->where('status', 1)
|
||||
->where('group_id', $groupId)
|
||||
->order('sort DESC,group_data_id ASC')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$url = Route::buildUrl('systemUserVipExchangeCodeActivateInfo')->build();
|
||||
$form = Elm::createForm($url);
|
||||
$rules = [
|
||||
Elm::number('start_id','开始ID')->required()->appendRule('suffix',[
|
||||
'type' => 'div',
|
||||
'style' => ['color' => '#999999'],
|
||||
'domProps' => [
|
||||
'innerHTML' => '例:输入 15 则ID大于15 小于等于结束ID的兑换码都会激活',
|
||||
]
|
||||
]),
|
||||
Elm::number('end_id','结束ID')->required()->appendRule('suffix',[
|
||||
'type' => 'div',
|
||||
'style' => ['color' => '#999999'],
|
||||
'domProps' => [
|
||||
'innerHTML' => '例:输入 80 则ID小于等于80 大于开始ID的兑换码都会激活',
|
||||
]
|
||||
]),
|
||||
Elm::select('mer_id','绑定商户')->options($merList),
|
||||
Elm::select('group_data_id','绑定会员卡类型')->options($vipList),
|
||||
];
|
||||
$form->setRule($rules);
|
||||
return $form->setTitle( '激活兑换码')->formData($formData);
|
||||
}
|
||||
/**
|
||||
* Common: 激活兑换码
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/02 17:09
|
||||
* @param $params
|
||||
* @return UserVipExchangeCode
|
||||
*/
|
||||
public function activateExchangeCode($params){
|
||||
// 是否允许生成兑换码
|
||||
if($params['end_id'] <= 0) throw new ValidateException('结束id必须大于0');
|
||||
if($params['end_id'] <= $params['start_id']) throw new ValidateException('结束id必须大于开始id');
|
||||
if($params['mer_id'] <= 0) throw new ValidateException('请绑定商户');
|
||||
if($params['group_data_id'] <= 0) throw new ValidateException('请绑定会员卡类型');
|
||||
|
||||
return UserVipExchangeCode::where('id','>',$params['start_id'])
|
||||
->where('id','<=',$params['end_id'])
|
||||
->where('status',0)
|
||||
->update([
|
||||
'status' => 1,
|
||||
'activate' => date("Y-m-d H:i:s",time()),
|
||||
'mer_id' => $params['mer_id'],
|
||||
'group_data_id' => $params['group_data_id'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,16 +34,17 @@ class ExchangeCode extends BaseController{
|
|||
'兑换码',
|
||||
'生成时间:' . date('Y-m-d H:i:s',time())
|
||||
];
|
||||
$data['header'] = ['批次名称','批次编号','兑换码', '小程序链接'];
|
||||
// $data['header'] = ['批次名称','批次编号','兑换码', '小程序链接'];
|
||||
$data['header'] = ['批次名称','批次编号','兑换码'];
|
||||
$data['filename'] = '兑换码_'.time();
|
||||
// 处理跳转路径
|
||||
$data['list'] = array_map(function($item){
|
||||
$path = '/pages/annex/vip_center/index?ec='.$item['exchange_code'];
|
||||
// $path = '/pages/annex/vip_center/index?ec='.$item['exchange_code'];
|
||||
return [
|
||||
$item['batch_title'] ?? '',
|
||||
$item['batch_unique'] ?? '',
|
||||
$item['exchange_code'],
|
||||
$path,
|
||||
$item['exchange_code']
|
||||
// $path,
|
||||
];
|
||||
}, $data['list']);
|
||||
$data['list'] = array_reverse($data['list']);
|
||||
|
|
@ -84,14 +85,33 @@ class ExchangeCode extends BaseController{
|
|||
$params = $this->request->params(['batch_title',['create_num', 0]]);
|
||||
$this->repository->createExchangeCode($params);
|
||||
|
||||
return app('json')->success();
|
||||
return app('json')->success('添加成功');
|
||||
}
|
||||
/**
|
||||
* Common: 激活表单
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/02 16:51
|
||||
* @return mixed
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function activateForm(){
|
||||
$data = $this->repository->getActivateFormData();
|
||||
|
||||
return app('json')->success(formToData($data));
|
||||
}
|
||||
/**
|
||||
* Common: 提交表单
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/02 16:56
|
||||
* @return mixed
|
||||
*/
|
||||
public function activateInfo(){
|
||||
$params = $this->request->params(['start_id','end_id',['mer_id', 0],['group_data_id',0]]);
|
||||
$this->repository->activateExchangeCode($params);
|
||||
|
||||
return app('json')->success('激活成功');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,15 @@ Route::group(function () {
|
|||
Route::get('editForm', 'admin.user.ExchangeCode/editForm')->name('systemUserVipExchangeCodeEdit');
|
||||
// 提交编辑信息
|
||||
Route::post('editInfo', 'admin.user.ExchangeCode/editInfo')->name('systemUserVipExchangeCodeEditInfo');
|
||||
// 激活表单
|
||||
Route::get('activateForm', 'admin.user.ExchangeCode/activateForm')->name('systemUserVipExchangeCodeActivateForm');
|
||||
// 提交激活表单
|
||||
Route::post('activateInfo', 'admin.user.ExchangeCode/activateInfo')->name('systemUserVipExchangeCodeActivateInfo');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})->append(['type' => 1])->option([
|
||||
'_path' => '/user/member/exchangeCode',
|
||||
'_auth' => true,
|
||||
|
|
|
|||
Loading…
Reference in New Issue