diff --git a/app/index/controller/ContactUs.php b/app/index/controller/ContactUs.php new file mode 100644 index 00000000..56a3e8ec --- /dev/null +++ b/app/index/controller/ContactUs.php @@ -0,0 +1,99 @@ +isPost()) { + // 提交留言处理 + $form_data = request()->post([ + 'name', + 'email', + 'content' + ]); + + // 数据校验 + $validate = new ContactUsValidate; + if (!$validate->check($form_data)) { + return error($validate->getError()); + } + + // 保存留言 + $msg = LeaveMessageModel::create([ + 'language_id' => $this->lang_id, + 'name' => $form_data['name'], + 'email' => $form_data['email'], + 'content' => $form_data['content'], + 'ip' => request()->ip(), + 'user_agent' => request()->header('user-agent'), + ]); + if ($msg->isEmpty()) { + return error(lang('contact_message.send_fail')); + } + + return success(lang('contact_message.send_success')); + } + + $focus_image = []; + $our_information = []; + // 获取我的信息banner + $banner = SysBannerModel::with(['items' => function($query) { + $query->withoutField(['status', 'created_at', 'updated_at', 'deleted_at']) + ->where('status', '=', 1) + ->order(['sort' => 'asc', 'id' => 'desc']); + }]) + ->uniqueLabel([ + 'BANNER_6801be1e7d686', + 'BANNER_6801c053ce12e', + ]) + ->language($this->lang_id) + ->enabled(true) + ->select(); + if (!$banner->isEmpty()) { + $banner_map = []; + foreach ($banner as $v) { + $banner_map[$v->unique_label] = $v; + } + $focus_image = data_get($banner_map, 'BANNER_6801be1e7d686')?->items->first()?->toArray(); + $our_information = data_get($banner_map, 'BANNER_6801c053ce12e')?->items->toArray(); + } + View::assign('focus_image', $focus_image); + View::assign('our_information', $our_information); + + return View::fetch('message'); + } + + /** + * 留言成为分销商 + */ + public function distributor() + { + if (request()->isPost()) { + // 提交留言处理 + } + + return View::fetch('distributor'); + } +} diff --git a/app/index/lang/en-us.php b/app/index/lang/en-us.php index b4d3c7dd..1f212294 100644 --- a/app/index/lang/en-us.php +++ b/app/index/lang/en-us.php @@ -46,4 +46,28 @@ return [ 'events' => 'Brand Events', 'development' => 'Tech Development', ], + 'contact_message' => [ + 'title' => 'contact us', + 'our_information' => 'Our Information', + 'send_question' => 'Send Us Your Question', + 'form_name' => 'Yuor Name', + 'form_name_placeholder' => 'This is your placeholder text', + 'form_email' => 'Your Email', + 'form_email_placeholder' => 'This is your placeholder text', + 'form_question' => 'Your Message', + 'form_question_placeholder' => 'This is your placeholder text', + 'form_submit' => 'SEND', + 'become_a_distributor' => 'Become a Distributor', + // 验证器中文本 + 'validate_name_required' => 'Name is required', + 'validate_name_max' => 'Name cannot exceed 64 characters', + 'validate_email_required' => 'Email is required', + 'validate_email_email' => 'Email format is incorrect', + 'validate_email_max' => 'Email cannot exceed 128 characters', + 'validate_content_required' => 'Message is required', + 'validate_content_max' => 'Message cannot exceed 1024 characters', + // 返回文本 + 'send_success' => 'success', + 'send_fail' => 'fail', + ], ]; \ No newline at end of file diff --git a/app/index/lang/zh-cn.php b/app/index/lang/zh-cn.php index 7d05af86..646b714d 100644 --- a/app/index/lang/zh-cn.php +++ b/app/index/lang/zh-cn.php @@ -46,4 +46,28 @@ return [ 'events' => '品牌里程', 'development' => '品牌活动', ], + 'contact_message' => [ + 'title' => '联系我们', + 'our_information' => '我们的信息', + 'send_question' => '提交您的问题', + 'form_name' => '姓名', + 'form_name_placeholder' => '请输入你的姓名', + 'form_email' => '电子邮箱', + 'form_email_placeholder' => '请输入你的邮箱', + 'form_question' => '您的问题', + 'form_question_placeholder' => '请输入你的问题', + 'form_submit' => '发送', + 'become_a_distributor' => '成为经销商', + // 验证器中文本 + 'validate_name_required' => '姓名不能为空', + 'validate_name_max' => '姓名不能超过64个字符', + 'validate_email_required' => '邮箱不能为空', + 'validate_email_email' => '邮箱格式不正确', + 'validate_email_max' => '邮箱不能超过128个字符', + 'validate_content_required' => '问题不能为空', + 'validate_content_max' => '问题不能超过1024个字符', + // 返回文本 + 'send_success' => '提交成功', + 'send_fail' => '提交失败', + ], ]; \ No newline at end of file diff --git a/app/index/model/LeaveMessageModel.php b/app/index/model/LeaveMessageModel.php new file mode 100644 index 00000000..6077b52f --- /dev/null +++ b/app/index/model/LeaveMessageModel.php @@ -0,0 +1,15 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = [ + 'name' => 'require|max:64', + 'email' => 'require|email|max:128', + 'content' => 'require|max:1024' + ]; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = [ + 'name.require' => 'contact_message.validate_name_required', + 'name.max' => 'contact_message.validate_name_max', + 'email.require' => 'contact_message.validate_email_required', + 'email.email' => 'contact_message.validate_email_email', + 'email.max' => 'contact_message.validate_email_max', + 'content.require' => 'contact_message.validate_content_required', + 'content.max' => 'contact_message.validate_content_max' + ]; +} diff --git a/app/index/view/contact_us/distributor.html b/app/index/view/contact_us/distributor.html new file mode 100644 index 00000000..e69de29b diff --git a/app/index/view/contact_us/index.html b/app/index/view/contact_us/index.html new file mode 100644 index 00000000..e69de29b diff --git a/app/index/view/contact_us/message.html b/app/index/view/contact_us/message.html new file mode 100644 index 00000000..ef7d48ff --- /dev/null +++ b/app/index/view/contact_us/message.html @@ -0,0 +1,108 @@ +{extend name="public/base" /} +{block name="title"}