feat: 联系我们

This commit is contained in:
2025-04-18 14:35:35 +08:00
parent 92675ac6ba
commit 5c6475150b
14 changed files with 323 additions and 2 deletions

View File

@@ -0,0 +1,99 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use app\index\model\LeaveMessageModel;
use app\index\model\SysBannerModel;
use app\index\validate\ContactUsValidate;
use think\facade\View;
/**
* 联系我们控制器
*/
class ContactUs extends Common
{
/**
* 联系我们
*/
public function index()
{
return View::fetch('index');
}
/**
* 留言联系我们
*/
public function message()
{
if (request()->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');
}
}