parent
3b75420414
commit
3f85b8baa6
|
|
@ -59,11 +59,35 @@ class VipExchangeCodeRepository extends BaseRepository{
|
||||||
$form = Elm::createForm($url);
|
$form = Elm::createForm($url);
|
||||||
$rules = [
|
$rules = [
|
||||||
Elm::input('batch_title','当前批次名称')->required()->col(16),
|
Elm::input('batch_title','当前批次名称')->required()->col(16),
|
||||||
Elm::input('create_num','生成数量')->required()->col(16)
|
Elm::radio('type', '生成方式', 0)->options([
|
||||||
->type('number')
|
['value' => 0, 'label' => '随机生成'],
|
||||||
->min('1')
|
['value' => 1, 'label' => '顺序生成'],
|
||||||
->max('999999')
|
])->appendRule('suffix',[
|
||||||
->step('1'),
|
'type' => 'div',
|
||||||
|
'style' => ['color' => '#999999'],
|
||||||
|
'domProps' => [
|
||||||
|
'innerHTML' => '随机生成:使用字母和数字随机生成;顺序生成:根据指定前缀,指定初始值和结束值进行生成',
|
||||||
|
]
|
||||||
|
])->control([
|
||||||
|
[
|
||||||
|
'value' => 0,
|
||||||
|
'rule' => [
|
||||||
|
Elm::input('create_num','生成数量')->required()->col(16)
|
||||||
|
->type('number')
|
||||||
|
->min('1')
|
||||||
|
->max('999999')
|
||||||
|
->step('1'),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 1,
|
||||||
|
'rule' => [
|
||||||
|
Elm::input('prefix','前缀')->required()->col(16),
|
||||||
|
Elm::number('start','初始值')->required()->max(999999)->col(16),
|
||||||
|
Elm::number('end','结束值')->required()->max(999999)->col(16),
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]),
|
||||||
];
|
];
|
||||||
$form->setRule($rules);
|
$form->setRule($rules);
|
||||||
return $form->setTitle( '添加兑换码')->formData($formData);
|
return $form->setTitle( '添加兑换码')->formData($formData);
|
||||||
|
|
@ -77,22 +101,41 @@ class VipExchangeCodeRepository extends BaseRepository{
|
||||||
*/
|
*/
|
||||||
public function createExchangeCode($params){
|
public function createExchangeCode($params){
|
||||||
// 是否允许生成兑换码
|
// 是否允许生成兑换码
|
||||||
if($params['create_num'] <= 0) throw new ValidateException('生成数量必须大于0');
|
|
||||||
$isHas = (int)$this->dao->getSearch(['batch_title'=>$params['batch_title']])->value('id');
|
$isHas = (int)$this->dao->getSearch(['batch_title'=>$params['batch_title']])->value('id');
|
||||||
if($isHas > 0) throw new ValidateException('名称已经存在,请更换名称!');
|
if($isHas > 0) throw new ValidateException('名称已经存在,请更换名称!');
|
||||||
// 生成操作
|
// 生成批次唯一编号
|
||||||
$initial = substr(getFirstCharter($params['batch_title']), 0, 1);
|
$initial = substr(getFirstCharter($params['batch_title']), 0, 1);
|
||||||
$batchUnique = strtoupper(uniqid($initial));// 批次唯一编号
|
$batchUnique = strtoupper(uniqid($initial));// 批次唯一编号
|
||||||
|
// 生成操作
|
||||||
$insertData = [];
|
$insertData = [];
|
||||||
for($i = 0; count($insertData) < $params['create_num']; $i++){
|
if($params['type'] == 1){
|
||||||
// 兑换码生成
|
// 顺序生成
|
||||||
$exchangeCode = strtoupper($initial . substr(uniqid(), -8));
|
if($params['start'] <= 0 || $params['end'] <= 0) throw new ValidateException('初始值和结束值必须大于0');
|
||||||
if(!in_array($exchangeCode, array_column($insertData,'exchange_code'))){
|
if($params['start'] >= $params['end']) throw new ValidateException('初始值必须小于结束值');
|
||||||
$insertData[] = [
|
for($i = $params['start']; $i <= $params['end']; $i++){
|
||||||
'batch_title' => $params['batch_title'],
|
// 兑换码生成
|
||||||
'batch_unique' => $batchUnique,
|
$exchangeCode = strtoupper($initial . substr(uniqid(), -8));
|
||||||
'exchange_code' => strtoupper($initial . substr(uniqid(), -8)),
|
if(!in_array($exchangeCode, array_column($insertData,'exchange_code'))){
|
||||||
];
|
$insertData[] = [
|
||||||
|
'batch_title' => $params['batch_title'],
|
||||||
|
'batch_unique' => $batchUnique,
|
||||||
|
'exchange_code' => $params['prefix'] . str_pad($i, strlen($params['end']), '0', STR_PAD_LEFT),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// 随机生成
|
||||||
|
if($params['create_num'] <= 0) throw new ValidateException('生成数量必须大于0');
|
||||||
|
for($i = 0; count($insertData) < $params['create_num']; $i++){
|
||||||
|
// 兑换码生成
|
||||||
|
$exchangeCode = strtoupper($initial . substr(uniqid(), -8));
|
||||||
|
if(!in_array($exchangeCode, array_column($insertData,'exchange_code'))){
|
||||||
|
$insertData[] = [
|
||||||
|
'batch_title' => $params['batch_title'],
|
||||||
|
'batch_unique' => $batchUnique,
|
||||||
|
'exchange_code' => strtoupper($initial . substr(uniqid(), -8)),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,6 +341,31 @@ class VipExchangeCodeRepository extends BaseRepository{
|
||||||
'status' => 3,
|
'status' => 3,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Common: 修改兑换码
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/03/30 15:44
|
||||||
|
* @param $params
|
||||||
|
* @return UserVipExchangeCode
|
||||||
|
*/
|
||||||
|
public function updateExchangeCode($params){
|
||||||
|
if(empty($params['new_exchange_code'])) throw new ValidateException('请输入新兑换码!');
|
||||||
|
if(strlen($params['new_exchange_code']) > 10) throw new ValidateException('兑换码长度不能超过10个字符!');
|
||||||
|
// 判断:是否存在信息
|
||||||
|
$info = $this->getSearchModel(['id'=>$params['id']])->findOrEmpty();
|
||||||
|
if((int)($info->id ?? 0) <= 0) throw new ValidateException('兑换码不存在!');
|
||||||
|
if((int)($info->status ?? 0) != 0) throw new ValidateException('当前兑换码不允许修改!');
|
||||||
|
// 判断:是否已经存在
|
||||||
|
$isHas = (int)$this->getSearchModel(['exchange_code'=>$params['new_exchange_code']])->value('id');
|
||||||
|
if($isHas > 0) throw new ValidateException('兑换码已经存在!');
|
||||||
|
// 执行修改
|
||||||
|
return UserVipExchangeCode::where('id',$params['id'])
|
||||||
|
->update([
|
||||||
|
'exchange_code' => $params['new_exchange_code'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,14 @@ class ExchangeCode extends BaseController{
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function editInfo(){
|
public function editInfo(){
|
||||||
$params = $this->request->params(['batch_title',['create_num', 0]]);
|
$params = $this->request->params([
|
||||||
|
['type', 0],
|
||||||
|
'prefix',
|
||||||
|
['start', 0],
|
||||||
|
['end', 0],
|
||||||
|
'batch_title',
|
||||||
|
['create_num', 0]
|
||||||
|
]);
|
||||||
$this->repository->createExchangeCode($params);
|
$this->repository->createExchangeCode($params);
|
||||||
|
|
||||||
return app('json')->success('添加成功');
|
return app('json')->success('添加成功');
|
||||||
|
|
@ -201,6 +208,18 @@ class ExchangeCode extends BaseController{
|
||||||
|
|
||||||
return app('json')->success('作废成功');
|
return app('json')->success('作废成功');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Common: 修改兑换码
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/03/30 15:45
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function updateCode(){
|
||||||
|
$params = $this->request->params(['id','new_exchange_code']);
|
||||||
|
$this->repository->updateExchangeCode($params);
|
||||||
|
|
||||||
|
return app('json')->success('修改成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ Route::group(function () {
|
||||||
Route::get('cancelForm', 'admin.user.ExchangeCode/cancelForm')->name('systemUserVipExchangeCodeCancelForm');
|
Route::get('cancelForm', 'admin.user.ExchangeCode/cancelForm')->name('systemUserVipExchangeCodeCancelForm');
|
||||||
// 提交作废表单
|
// 提交作废表单
|
||||||
Route::post('cancelInfo', 'admin.user.ExchangeCode/cancelInfo')->name('systemUserVipExchangeCodeCancelInfo');
|
Route::post('cancelInfo', 'admin.user.ExchangeCode/cancelInfo')->name('systemUserVipExchangeCodeCancelInfo');
|
||||||
|
// 修改兑换码
|
||||||
|
Route::post('updateCode', 'admin.user.ExchangeCode/updateCode')->name('systemUserVipExchangeCodeUpdateCode');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue