支付方式插件

This commit is contained in:
devil_gong 2018-09-18 17:35:29 +08:00
parent 2632254669
commit 06ed58413b
11 changed files with 311 additions and 76 deletions

View File

@ -82,6 +82,7 @@ class PaymentController extends CommonController
$temp = $this->DataAnalysis($config);
$temp['id'] = date('YmdHis').GetNumberCode(8);
$temp['payment'] = $payment;
$temp['apply_terminal'] = implode(',', $temp['apply_terminal']);
// 获取数据库配置信息
$db_config = $db->where(['payment'=>$payment])->find();
@ -121,7 +122,7 @@ class PaymentController extends CommonController
'name' => isset($data['base']['name']) ? htmlentities($data['base']['name']) : $payment,
'version' => isset($data['base']['version']) ? htmlentities($data['base']['version']) : '',
'apply_version' => isset($data['base']['apply_version']) ? htmlentities($data['base']['apply_version']) : '',
'desc' => isset($data['base']['desc']) ? htmlentities($data['base']['desc']) : '',
'desc' => isset($data['base']['desc']) ? $data['base']['desc'] : '',
'author' => isset($data['base']['author']) ? htmlentities($data['base']['author']) : '',
'author_url' => isset($data['base']['author_url']) ? htmlentities($data['base']['author_url']) : '',
'element' => isset($data['element']) ? $data['element'] : [],
@ -129,7 +130,7 @@ class PaymentController extends CommonController
'logo' => '',
'is_enable' => 0,
'is_install' => 0,
'apply_terminal'=> implode(',', array_column(L('common_apply_terminal_list'), 'value')),
'apply_terminal'=> array_column(L('common_apply_terminal_list'), 'value'),
'config' => '',
];
}
@ -170,7 +171,8 @@ class PaymentController extends CommonController
$data = empty($_REQUEST['id']) ? array() : M('Payment')->find(I('id'));
$data['apply_terminal'] = empty($data['apply_terminal']) ? [] : json_decode($data['apply_terminal'], true);
$data['element'] = empty($data['element']) ? [] : json_decode($data['element'], true);
//print_r($data);
$data['config'] = empty($data['config']) ? [] : json_decode($data['config'], true);
//print_r($data['config']);
$this->assign('data', $data);
// 适用平台
@ -213,6 +215,10 @@ class PaymentController extends CommonController
$m->upd_time = time();
$m->apply_terminal = empty($_POST['apply_terminal']) ? '' : json_encode(explode(',', I('apply_terminal')));
$m->name = I('name');
$m->sort = intval(I('sort'));
// 插件配置信息处理
$m->config = json_encode($this->GetPlugConfig());
// 移除 id
unset($m->id);
@ -229,6 +235,26 @@ class PaymentController extends CommonController
}
}
/**
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-18
* @desc description
*/
private function GetPlugConfig()
{
$data = [];
foreach($_POST as $k=>$v)
{
if(substr($k, 0, 5) == 'plug_')
{
$data[substr($k, 5)] = $v;
}
}
return $data;
}
/**
* [StatusUpdate 状态更新]
* @author Devil
@ -287,7 +313,7 @@ class PaymentController extends CommonController
$data = $this->DataAnalysis($config);
$data['payment'] = $payment;
$data['element'] = empty($data['element']) ? '' : json_encode($data['element']);
$data['apply_terminal'] = empty($data['apply_terminal']) ? '' : json_encode(explode(',', $data['apply_terminal']));
$data['apply_terminal'] = empty($data['apply_terminal']) ? '' : json_encode($data['apply_terminal']);
$data['add_time'] = time();
// 开始安装

View File

@ -32,5 +32,6 @@ return array(
'payment_upload_ps' => 'PS以上条件不满足则无法查看插件',
'payment_upload_format' => '文件格式有误必须php文件',
'payment_upload_error' => '插件编写有误,请参考文档编写',
'payment_plug_element_tips' => '该区域为插件配置填写项,请按照插件文档填写相应的值。',
);
?>

View File

@ -21,6 +21,7 @@ class PaymentModel extends CommonModel
array('desc', '0,255', '{%payment_desc_format}', 1, 'length', 3),
array('apply_terminal', 'require', '{%payment_apply_terminal_format}', 1, '', 3),
array('is_enable', array(0,1), '{%common_enable_tips}', 1, 'in', 3),
array('sort', 'CheckSort', '{%common_sort_error}', 1, 'function', 3),
);
}
?>

View File

@ -29,7 +29,7 @@
</div>
<div class="am-form-group">
<label>{{:L('article_category_text')}}</label>
<select name="article_category_id" class="am-radius c-p chosen-select" data-validation-message="{{:L('article_category_format')}}" required>
<select name="article_category_id" class="am-radius c-p chosen-select" data-placeholder="{{:L('common_select_can_choose')}}" data-validation-message="{{:L('article_category_format')}}" required>
<option value="">{{:L('common_select_can_choose')}}</option>
<foreach name="article_category_list" item="v">
<option value="{{$v.id}}" <if condition="isset($data['article_category_id']) and $data['article_category_id'] eq $v['id']">selected</if>>{{$v.name}}</option>

View File

@ -46,7 +46,7 @@
</div>
<div class="am-form-group">
<label>{{:L('common_view_sort_title')}}</label>
<input type="number" placeholder="{{:L('common_view_sort_title')}}" name="sort" min="0" max="255" data-validation-message="{{:L('common_sort_error')}}" class="am-radius" value="0" required />
<input type="number" placeholder="{{:L('common_view_sort_title')}}" name="sort" min="0" max="255" data-validation-message="{{:L('common_sort_error')}}" class="am-radius" value="<if condition="isset($data['sort'])">{{$data.sort}}<else />0</if>" required />
</div>
<div class="am-form-group">
<label class="block">{{:L('common_view_enable_title')}}</label>

View File

@ -18,7 +18,7 @@
<th class="am-hide-sm-only">{{:L('payment_apply_version_text')}}</th>
<th>{{:L('payment_apply_terminal_text')}}</th>
<th class="am-hide-sm-only">{{:L('payment_author_text')}}</th>
<th class="am-hide-sm-only">{{:L('payment_desc_text')}}</th>
<th class="am-hide-sm-only th-desc">{{:L('payment_desc_text')}}</th>
<th>{{:L('common_view_enable_title')}}</th>
<th>{{:L('common_operation_name')}}</th>
</tr>
@ -47,7 +47,7 @@
</a>
</if>
</td>
<td class="am-hide-sm-only">{{$v.desc}}</td>
<td class="am-hide-sm-only td-desc">{{$v.desc}}</td>
<td>
<if condition="$v['is_install'] eq 1">
<a href="javascript:;" class="am-icon-btn am-icon-check submit-state <if condition="$v['is_enable'] eq 1">am-success<else />am-default</if>" data-url="{{:U('Admin/Payment/StatusUpdate')}}" data-id="{{$v.payment}}" data-state="{{$v['is_enable']}}" data-is-update-status="1"></a>

View File

@ -16,7 +16,7 @@
</div>
<div class="am-form-group">
<label>{{:L('payment_apply_terminal_text')}}</label>
<select name="apply_terminal" class="am-radius c-p chosen-select" multiple="multiple" data-placeholder="{{:L('common_select_can_choose')}}" data-validation-message="{{:L('payment_apply_terminal_format')}}" required>
<select name="apply_terminal" class="am-radius c-p chosen-select" multiple="multiple" minchecked="1" data-placeholder="{{:L('common_select_can_choose')}}" data-validation-message="{{:L('payment_apply_terminal_format')}}" required>
<foreach name="common_apply_terminal_list" item="v">
<option value="{{$v.value}}" <if condition="isset($data['apply_terminal']) and in_array($v['value'], $data['apply_terminal'])">selected</if>>{{$v.name}}</option>
</foreach>
@ -35,26 +35,77 @@
<!-- plug config start -->
<notempty name="data.element">
<foreach name="data.element" item="element">
<div class="am-form-group am-form-file">
<label class="block">{{$element.title}}</label>
<switch name="element.element">
<case value="input">
<if condition="in_array($element['type'], ['radio', 'checkbox']) and !empty($element['element_data'])">
input - radio or checkbox
<else />
<input type="{{$element.type}}" name="{{$element.name}}" value="{{$element.default}}" placeholder="{{$element.placeholder}}" <if condition="isset($element['is_required']) and $element['is_required'] eq 1">required</if> />
</if>
</case>
<case value="select">
select
</case>
</switch>
</div>
</foreach>
<div class="plug-element">
<p class="tips">{{:L('payment_plug_element_tips')}}</p>
<foreach name="data.element" item="element">
<div class="am-form-group">
<label class="block">{{$element.title}}</label>
<switch name="element.element">
<case value="input">
<if condition="in_array($element['type'], ['radio', 'checkbox']) and !empty($element['element_data']) and is_array($element['element_data'])">
<foreach name="element.element_data" key="element_data_key" item="element_data">
<label class="<if condition="isset($element['is_block']) and $element['is_block'] eq 1">am-{{$element.type}}<else />am-{{$element.type}}-inline</if>">
<input
type="{{$element.type}}"
name="plug_{{$element.name}}"
value="{{$element_data.value}}"
<if condition="(isset($element_data['is_checked']) and $element_data['is_checked'] eq 1) or (isset($data['config'][$element['name']]) and in_array($element_data['value'], explode(',', $data['config'][$element['name']])))">checked</if>
<if condition="isset($element['minchecked']) and $element['type'] eq 'checkbox'">minchecked="{{$element.minchecked}}"</if>
<if condition="isset($element['maxchecked']) and $element['type'] eq 'checkbox'">maxchecked="{{$element.maxchecked}}"</if>
<if condition="isset($element['message'])">data-validation-message="{{$element.message}}"</if>
<if condition="$element_data_key eq 0 and isset($element['is_required']) and $element['is_required'] eq 1">required</if>
data-am-ucheck />{{$element_data.name}}
</label>
</foreach>
<else />
<input
type="{{$element.type}}"
name="plug_{{$element.name}}"
value="<if condition="isset($data['config'][$element['name']])">{{$data['config'][$element['name']]}}<else />{{$element.default}}</if>"
<if condition="isset($element['placeholder'])">placeholder="{{$element.placeholder}}"</if>
<if condition="isset($element['message'])">data-validation-message="{{$element.message}}"</if>
<if condition="isset($element['is_required']) and $element['is_required'] eq 1">required</if>
/>
</if>
</case>
<case value="select">
<if condition="!empty($element['element_data']) and is_array($element['element_data'])">
<select
class="chosen-select"
name="plug_{{$element.name}}"
<if condition="isset($element['message'])">data-validation-message="{{$element.message}}"</if>
<if condition="isset($element['placeholder'])">data-placeholder="{{$element.placeholder}}"<else />{{:L('common_select_can_choose')}}</if>
<if condition="isset($element['is_multiple']) and $element['is_multiple'] eq 1">
multiple
<if condition="isset($element['minchecked'])">minchecked="{{$element.minchecked}}"</if>
<if condition="isset($element['maxchecked'])">maxchecked="{{$element.maxchecked}}"</if>
</if>
<if condition="isset($element['is_required']) and $element['is_required'] eq 1">required</if>
>
<if condition="!isset($element['is_multiple']) or $element['is_multiple'] neq 1">
<option value=""><if condition="isset($element['placeholder'])">{{$element.placeholder}}<else />{{:L('common_select_can_choose')}}</if></option>
</if>
<foreach name="element.element_data" key="element_data_key" item="element_data">
<option
value="{{$element_data.value}}"
<if condition="(isset($element_data['is_selected']) and $element_data['is_selected'] eq 1) or (isset($data['config'][$element['name']]) and in_array($element_data['value'], explode(',', $data['config'][$element['name']])))">selected</if>
>{{$element_data.name}}</option>
</foreach>
</select>
</if>
</case>
</switch>
</div>
</foreach>
</div>
</notempty>
<!-- plug config end -->
<div class="am-form-group">
<label>{{:L('common_view_sort_title')}}</label>
<input type="number" placeholder="{{:L('common_view_sort_title')}}" name="sort" min="0" max="255" data-validation-message="{{:L('common_sort_error')}}" class="am-radius" value="<if condition="isset($data['sort'])">{{$data.sort}}<else />0</if>" required />
</div>
<div class="am-form-group">
<label class="block">{{:L('common_view_enable_title')}}</label>
<input name="is_enable" value="1" type="checkbox" data-off-text="{{:L('common_operation_off_is_text')}}" data-on-text="{{:L('common_operation_on_is_text')}}" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch <if condition="(isset($data['is_enable']) and $data['is_enable'] eq 1) or !isset($data['is_enable'])">checked="true"</if> />
@ -71,4 +122,9 @@
<!-- footer start -->
<include file="Public/Footer" />
<!-- footer end -->
<!-- footer end -->
<script>
$('.select-maxchecked').on('checkedOverflow.selected.amui', function() {
Prompt('最多选择' + this.getAttribute('maxchecked') + '项');
});
</script>

View File

@ -40,7 +40,7 @@ class Alipay
'name' => '支付宝',
'version' => '0.0.1',
'apply_version' => '1.0~1.3',
'desc' => '描述支持html',
'desc' => '即时到帐支付方式,买家的交易资金直接打入卖家支付宝账户,快速回笼交易资金。 <a href="http://www.alipay.com/" target="_blank">立即申请</a>',
'author' => 'Devil',
'author_url' => 'http://gong.gg/'
];
@ -55,6 +55,7 @@ class Alipay
'placeholder' => '支付宝账号',
'title' => '支付宝账号',
'is_required' => 1,
'message' => '请填写支付宝账号',
],
[
'element' => 'input',
@ -64,6 +65,7 @@ class Alipay
'placeholder' => '交易安全校验码 key',
'title' => '交易安全校验码 key',
'is_required' => 1,
'message' => '请填写交易安全校验码 key',
],
[
'element' => 'input',
@ -73,6 +75,81 @@ class Alipay
'placeholder' => '合作者身份 partner ID',
'title' => '合作者身份 partner ID',
'is_required' => 1,
'message' => '请填写合作者身份 partner ID',
],
[
'element' => 'input', // 表单标签
'type' => 'text', // input类型
'default' => '', // 默认值
'name' => 'testinput', // name名称
'placeholder' => '测试输入框不需要验证', // input默认显示文字
'title' => '测试输入框不需要验证', // 展示title名称
'is_required' => 0, // 是否需要强制填写/选择
'message' => '请填写测试输入框不需要验证', // 错误提示is_required=1方可有效
],
[
'element' => 'input',
'type' => 'checkbox',
'element_data' => [
['value'=>1, 'name'=>'选项1'],
['value'=>2, 'name'=>'选项2', 'is_checked'=>1],
['value'=>3, 'name'=>'选项3'],
['value'=>4, 'name'=>'选项4']
],
'is_block' => 1, // 是否每个选项行内展示默认0
'minchecked' => 2, // 最小选项默认以is_required=1至少一项则0
'maxchecked' => 3, // 最大选项
'name' => 'checkbox',
'title' => '多选项测试', // 展示title名称
'is_required' => 1, // 是否需要强制填写/选择
'message' => '请选择多选项测试选择 至少选择2项最多选择3项', // 错误提示信息
],
[
'element' => 'input',
'type' => 'radio',
'element_data' => [
['value'=>1, 'name'=>'选项1', 'is_checked'=>1],
['value'=>2, 'name'=>'选项2'],
['value'=>3, 'name'=>'选项3'],
['value'=>4, 'name'=>'选项4']
],
'is_block' => 1, // 是否每个选项行内展示默认0
'name' => 'radio',
'title' => '单选项测试', // 展示title名称
'is_required' => 1, // 是否需要强制填写/选择
'message' => '请选择单选项测试',
],
[
'element' => 'select',
'placeholder' => '选一个撒1',
'is_multiple' => 0, // 是否开启多选默认0 关闭)
'element_data' => [
['value'=>1, 'name'=>'选项1'],
['value'=>2, 'name'=>'选项2'],
['value'=>3, 'name'=>'选项3'],
['value'=>4, 'name'=>'选项4']
],
'name' => 'select1',
'title' => '下拉单选测试', // 展示title名称
'is_required' => 1, // 是否需要强制填写/选择
'message' => '请选择下拉单选测试',
],
[
'element' => 'select',
'placeholder' => '选一个撒2',
'is_multiple' => 1, // 是否开启多选默认0 关闭)
'element_data' => [
['value'=>1, 'name'=>'选项1'],
['value'=>2, 'name'=>'选项2'],
['value'=>3, 'name'=>'选项3'],
['value'=>4, 'name'=>'选项4']
],
'minchecked' => 2, // 最小选项默认以is_required=1至少一项则0
'maxchecked' => 3, // 最大选项
'name' => 'select2',
'title' => '下拉多选测试', // 展示title名称
'is_required' => 1, // 是否需要强制填写/选择
'message' => '请选择下拉多选测试 至少选择2项最多选择3项',
],
];

View File

@ -1,18 +1,11 @@
/**
* 列表
*/
.form-keyword { width: 55% !important; display: initial !important; }
.more-submit input { display: none; }
.param-where, .param-date input { display: initial !important; }
@media only screen and (max-width: 641px) {
.param-where { width: 100% !important; margin-left: 0px !important; }
.param-date input { width: 47% !important; }
}
@media only screen and (min-width: 641px) {
.param-where { width: 32% !important; float: left; }
.param-date input { width: 45% !important; }
.param-where:nth-child(1), .param-where:nth-child(4) { margin-left: 0px !important; }
}
@media only screen and (max-width: 321px) {
.view-operation button { margin: 2px 0px; }
}
table.am-table .th-desc { width: 20%; }
table.am-table .td-desc { font-size: 12px; }
/**
* 插件部分
*/
.plug-element { border: 1px dotted #FFC107; background: #fffcf2; padding: 10px 10px 0 10px; margin-bottom: 10px; border-radius: 2px; }
.plug-element .tips { color: #FF9800; margin: 0 0 10px 0; font-size: 12px; }

View File

@ -84,12 +84,16 @@ function GetFormVal(element)
var name = $(this).parents('select').attr('name');
if(name != undefined && name != '')
{
if($(this).is(':selected'))
if($(this).is(':selected') && tmp.value != undefined && tmp.value != '')
{
// 多选择
if($(this).parents('select').attr('multiple') != undefined)
{
if(tmp_all[name] == undefined) tmp_all[name] = [];
if(tmp_all[name] == undefined)
{
tmp_all[name] = [];
i = 0;
}
tmp_all[name][i] = tmp.value;
i++;
} else {
@ -268,6 +272,57 @@ function FromInit(form_name)
// 通过验证
if(this.isFormValid())
{
// 多选插件校验
if($form.find('.chosen-select'))
{
var is_success = true;
$form.find('select.chosen-select').each(function(k, v)
{
var required = $(this).attr('required');
if(($(this).attr('required') || null) == 'required')
{
var multiple = $(this).attr('multiple') || null;
var minchecked = parseInt($(this).attr('minchecked')) || 0;
var maxchecked = parseInt($(this).attr('maxchecked')) || 0;
var msg = $(this).attr('data-validation-message');
var value = $(this).val();
if((value || null) == null && value != '0')
{
is_success = false;
Prompt(msg || '请选择项');
$(this).trigger('blur');
return false;
} else {
if(multiple == 'multiple')
{
var count = value.length;
if(minchecked > 0 && count < minchecked)
{
is_success = false;
msg = msg || '至少选择'+minchecked+'项';
}
if(maxchecked > 0 && count > maxchecked)
{
is_success = false;
msg = msg || '最多选择'+maxchecked+'项';
}
if(is_success === false)
{
Prompt(msg);
$(this).trigger('blur');
$(this).parents('.am-form-group').removeClass('am-form-success').addClass('am-form-error');
return false;
}
}
}
}
});
if(is_success === false)
{
return false;
}
}
// button加载
var $button = $form.find('button[type="submit"]');
$button.button('loading');

File diff suppressed because one or more lines are too long