fieldtype = ['DECIMAL' => '10,2']; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... ) $this->defaulttype = 'DECIMAL'; // 当用户没有选择字段类型时的缺省值 } /** * 字段相关属性参数 * * @param array $value 值 * @return string */ public function option($option) { !$option['payfile'] && $option['payfile'] = 'buy.html'; $opt = '
'.dr_lang('模板位于./config/pay/模板文件名').'
'; $style = '
'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'
'; return [$opt, $style]; } /** * 字段入库值 * * @param array $field 字段信息 * @return void */ public function insert_value($field) { \Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = (float)\Phpcmf\Service::L('Field')->post[$field['fieldname']]; } /** * 字段表单输入 * * @return string */ public function input($field, $value = '', $html = []) { if (!defined('FC_PAY') && (IS_MEMBER || IS_ADMIN)) { // 字段显示名称 $text = ($field['setting']['validate']['required'] ? ' * ' : '').dr_lang($field['name']); // 表单宽度设置 $width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ((int)$field['setting']['option']['width'] ? $field['setting']['option']['width'] : 250); // 表单附加参数 $attr = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';" '.$field['setting']['validate']['formattr']; // 字段提示信息 $tips = $field['setting']['validate']['tips'] ? ''.$field['setting']['validate']['tips'].'' : ''; // 当字段必填时,加入html5验证标签 $required = $field['setting']['validate']['required'] ? ' required="required"' : ''; // 字段默认值 $value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']); $ipt = ''; return $this->input_format($field['fieldname'], $text, $ipt.$tips); } else { // 付款金额 $html['pay_value'] = $value ? $value : 0; if (!dr_is_app('pay')) { return '没有安装「支付系统」插件'; } // 付款方式 $html['pay_type'] = \Phpcmf\Service::M('pay', 'pay')->get_pay_type(\Phpcmf\Service::C()->member && $field['setting']['option']['is_finecms'] && is_file(ROOTPATH.'api/pay/finecms/config.php')); // 取默认第一个 if ($html['pay_type']) { reset($html['pay_type']); $html['pay_default'] = key($html['pay_type']); } // 付款界面模板 if (isset($html['tpl']) && $html['tpl'] && is_file($html['tpl'])) { $htmlfile = $html['tpl']; // 验证路径合法性 if (!\Phpcmf\Service::V()->_safe_template_path($htmlfile)) { return '支付表单模板文件路径不合法:'.$htmlfile.'
'.(\Phpcmf\Service::V()->_safe_template_error); } } else { $htmlfile = CONFIGPATH.'pay/buy.html'; if ($field['setting']['option']['payfile']) { if (is_file(WEBPATH.'config/pay/'.$field['setting']['option']['payfile'])) { $htmlfile = WEBPATH.'config/pay/'.$field['setting']['option']['payfile']; } elseif (is_file(CONFIGPATH.'pay/'.$field['setting']['option']['payfile'])) { $htmlfile = CONFIGPATH.'pay/'.$field['setting']['option']['payfile']; } } } if (!is_file($htmlfile)) { return '支付表单模板文件不存在:'.$htmlfile; } $member = \Phpcmf\Service::C()->member; $pay_url = \Phpcmf\Service::L('router')->member_url('pay/pay/index'); // 获取付款界面代码 ob_start(); $file = \Phpcmf\Service::V()->code2php(file_get_contents($htmlfile)); require $file; $code = ob_get_clean(); return $code; } } /** * 字段表单显示 * * @param string $field 字段数组 * @param array $value 值 * @return string */ public function show($field, $value = null) { return $this->input_format($field['fieldname'], $field['name'], '
¥'.$value.'元
'); } }