From adc9c7839430e919751f19981d2b39cee9ef36b2 Mon Sep 17 00:00:00 2001 From: zwesy Date: Fri, 4 Dec 2020 18:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E8=81=94=E7=B3=BB?= =?UTF-8?q?=E6=88=91=E4=BB=AC-=E7=95=99=E8=A8=80=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Article.php | 2 +- app/controller/Index.php | 4 +- app/controller/Message.php | 42 ++++++++++++++ app/controller/Page.php | 22 ++++++- app/controller/manager/Message.php | 32 +++++++++++ app/model/Article.php | 11 +++- app/model/Category.php | 7 +++ app/model/Message.php | 25 ++++++-- app/validate/Message.php | 27 +++++++++ public/static/css/style.css | 2 +- public/static/js/script.js | 69 ++++++++++++++++++++-- route/app.php | 3 + view/manager/message/index.html | 13 +++-- view/manager/system/index.html | 20 +++++-- view/page/contact.html | 92 +++++++++++++++++++++++++++++- 15 files changed, 341 insertions(+), 30 deletions(-) create mode 100644 app/controller/Message.php create mode 100644 app/controller/manager/Message.php create mode 100644 app/validate/Message.php diff --git a/app/controller/Article.php b/app/controller/Article.php index ed3e1f6..c399c78 100644 --- a/app/controller/Article.php +++ b/app/controller/Article.php @@ -123,7 +123,7 @@ class Article extends Base $cateList = []; $newsChildrenFlip = array_flip(Category::$CIdList['news_children']); foreach ($categoryChildren as $cate) { - $cate['items'] = MArticle::getLatestByCategory($cate['id'], 4); + $cate['items'] = MArticle::getLatestByCategory($cate['id'], 4, 1); $cateList[$newsChildrenFlip[$cate['id']]] = $cate; } $this->data['cateList'] = $cateList; diff --git a/app/controller/Index.php b/app/controller/Index.php index 77c4e57..9c0b93a 100644 --- a/app/controller/Index.php +++ b/app/controller/Index.php @@ -21,14 +21,14 @@ class Index extends Base // 关联产品中心 $this->data['products'] = [ 'category' => Category::getById(Category::$CIdList['products']), - 'items' => Article::getLatestByCategory(Category::$CIdList['products'], 4) + 'items' => Article::getLatestByCategory(Category::$CIdList['products'], 4, 1) ]; // 关联新闻 $this->data['newsCenter'] = Category::getById(Category::$CIdList['news']); $newsCIdList = [Category::$CIdList['news_children']['enterprise'], Category::$CIdList['news_children']['industry']]; $newsList = Category::getListByIds($newsCIdList); foreach ($newsList as &$cate) { - $cate['items'] = Article::getLatestByCategory($cate['id'], 4); + $cate['items'] = Article::getLatestByCategory($cate['id'], 4, 1); } unset($cate); $this->data['newsList'] = $newsList; diff --git a/app/controller/Message.php b/app/controller/Message.php new file mode 100644 index 0000000..f8598f6 --- /dev/null +++ b/app/controller/Message.php @@ -0,0 +1,42 @@ +isPost()) { + $msgData = [ + 'company_name' => trim(input('post.company_name', '')), + 'name' => trim(input('post.name', '')), + 'phone' => trim(input('post.phone', '')), + 'email' => trim(input('post.email', '')), + 'content' => trim(input('post.content', '')), + ]; + // 安全过滤 + $msgData = array_map('strip_tags', $msgData); + try { + validate(VMessage::class)->check($msgData); + $msgData['ip'] = request()->ip(); + $msgData['create_time'] = time(); + MMessage::create($msgData); + return $this->json(); + } catch (ValidateException $e) { + return $this->json(2, $e->getError()); + } + } else { + return $this->json(1, '非法请求'); + } + } +} + diff --git a/app/controller/Page.php b/app/controller/Page.php index 8a6ff3a..fbcdf5d 100644 --- a/app/controller/Page.php +++ b/app/controller/Page.php @@ -47,7 +47,11 @@ class Page extends Base case 'marketing' : $this->assignMarketing($childCategory); break; + case 'contact' : + $this->assignContact($childCategory); + break; default : + $this->data['blocks'] = Block::getByCategoryId($category['id']); } } @@ -117,9 +121,25 @@ class Page extends Base $achievementCate = Category::getById(Category::$CIdList['achievement_manage']); $achievementList = []; if ($achievementCate) { - $achievementList = Article::getLatestByCategory($achievementCate['id'], $achievementCate['number'] ? $achievementCate['number'] : 10); + $achievementList = Article::getLatestByCategory($achievementCate['id'], $achievementCate['number'] ? $achievementCate['number'] : 10, 1); } $this->data['blocks'] = $blocks; $this->data['achievementList'] = $achievementList; } + + // 联系我们 + private function assignContact($childCategory) + { + $blocks = []; + $blockCateIds = $this->getBlockCateIds($childCategory); + $blockList = Block::getByCategoryIds($blockCateIds); + $contactChildrenFlip = array_flip(Category::$CIdList['contact_children']); + foreach ($childCategory as $cate) { + $blocks[$contactChildrenFlip[$cate['id']]] = $blockList[$cate['id']] ?? []; + } + $jobsCate = Category::getById(Category::$CIdList['jobs_manage']); + $jobList = Article::getLatestByCategory($jobsCate['id'], $jobsCate['number'] ? $jobsCate['number'] : 10, 1); + $this->data['blocks'] = $blocks; + $this->data['jobList'] = $jobList; + } } \ No newline at end of file diff --git a/app/controller/manager/Message.php b/app/controller/manager/Message.php new file mode 100644 index 0000000..d5ff346 --- /dev/null +++ b/app/controller/manager/Message.php @@ -0,0 +1,32 @@ +data['list'] = MMessage::getPaginateList(20, $keyword, false); + $this->data['keyword'] = $keyword; + return $this->view(); + } + + public function del() + { + $id = input('param.id/d', 0); + $msg = MMessage::getById($id); + if(count($msg) == 0) { + return $this->json(1, '该消息不存在'); + } + MMessage::destroy($id); + return $this->json(); + } +} \ No newline at end of file diff --git a/app/model/Article.php b/app/model/Article.php index dd03fef..62a1826 100644 --- a/app/model/Article.php +++ b/app/model/Article.php @@ -15,18 +15,23 @@ class Article extends Base ->toArray(); } //获取栏目下最新记录 - public static function getLatestByCategory($categoryId, $limit = 5, $order = []) + public static function getLatestByCategory($categoryId, $limit = 5, $status = -1, $order = []) { if(empty($categoryId)){ return []; } + $whereMap = []; if($limit <= 0){ $limit = 5; } + if(is_numeric($status) && $status != -1){ + $whereMap[] = ['status', '=', $status]; + } if(empty($order)) { $order = ['create_time' => 'desc']; } return self::where('category_id', $categoryId) + ->where($whereMap) ->order($order) ->limit($limit) ->select() @@ -166,6 +171,10 @@ class Article extends Base } } } + if(is_numeric($status) && $status != -1){ + $whereMap[] = ['status', '=', $status]; + $pageParam['status'] = $status; + } $paginate = [ 'list_rows' => $per, 'query' => $pageParam diff --git a/app/model/Category.php b/app/model/Category.php index 1fa1c78..47e4b7f 100644 --- a/app/model/Category.php +++ b/app/model/Category.php @@ -33,6 +33,13 @@ class Category extends Base 'industry' => 21, // 行业资讯 'dynamics' => 22, // 最新动态 ], + 'contact' => 19, // 联系我们 + 'contact_children' => [ + 'information' => 23, // 联系方式 + 'jobs' => 24, // 行业资讯 + 'message' => 25, // 在线留言 + ], + 'jobs_manage' => 33, // 招聘管理 ]; //获取首页栏目ID diff --git a/app/model/Message.php b/app/model/Message.php index 0116f71..87f5945 100644 --- a/app/model/Message.php +++ b/app/model/Message.php @@ -3,12 +3,25 @@ namespace app\model; class Message extends Base { - /** - * 获取留言列表 - */ - public static function getList($per = 20) + // 获取留言列表 + public static function getPaginateList($per = 20, $keyword = '', $isSimple = false) { - return self::order("create_time desc") - ->paginate($per); + $paginate = [ + 'list_rows' => $per, + 'query' => [ + 'keyword' => $keyword, + ] + ]; + return self::when(!empty($keyword), function ($query) use ($keyword) { + $map = [ + ['company_name', 'like', '%'.$keyword.'%'], + ['name', 'like', '%'.$keyword.'%'], + ['phone', 'like', '%'.$keyword.'%'], + ['email', 'like', '%'.$keyword.'%'], + ]; + $query->whereOr($map); + }) + ->order('create_time', 'desc') + ->paginate($paginate, $isSimple); } } \ No newline at end of file diff --git a/app/validate/Message.php b/app/validate/Message.php new file mode 100644 index 0000000..421a064 --- /dev/null +++ b/app/validate/Message.php @@ -0,0 +1,27 @@ + 'requireWithout:name|length:2,100', + 'name' => 'requireWithout:company_name|length:2,50', + 'content' => 'require|length:4,500', + 'phone' => 'requireWithout:email|mobile', + 'email' => 'requireWithout:phone|email', + ]; + protected $message = [ + 'company_name.requireWithout' => '公司名称和联系人署名至少需要填写一个', + 'company_name.length' => '公司名称长度限制为2~100个字符', + 'name.requireWithout' => '公司名称和联系人署名至少需要填写一个', + 'name.length' => '联系人署名长度限制为2~50个字符', + 'phone.requireWithout' => '联系电话和邮箱至少需要填写一个', + 'phone.mobile' => '请输入正确的联系电话', + 'email.requireWithout' => '联系电话和邮箱至少需要填写一个', + 'email.email' => '请输入正确的邮箱', + 'content.require' => '咨询事项不能为空', + 'content.length' => '咨询事项长度限制为4~500个字符', + ]; +} \ No newline at end of file diff --git a/public/static/css/style.css b/public/static/css/style.css index 967f965..1666915 100644 --- a/public/static/css/style.css +++ b/public/static/css/style.css @@ -334,7 +334,7 @@ input,select,textarea{outline:medium none; resize: none;} .contact-box3 .center-block .text:nth-child(2n){ float: right;} .contact-box3 .center-block textarea{ width: 100%; float: left; height: 110px; border: none; border-bottom: 1px solid #c2c2c2; background: none; font-size: 0.875rem; margin-top: 1.25rem;} .contact-box3 .center-block .btns{ width: 100%; float: left; text-align: center;} -.contact-box3 .center-block .btns input{ width: 10rem; line-height: 2.25rem; background: #00418f; border:none; color: #fff; font-size: 1rem; margin-top: 1.875rem;} +.contact-box3 .center-block .btns button{ width: 10rem; line-height: 2.25rem; background: #00418f; border:none; color: #fff; font-size: 1rem; margin-top: 1.875rem;} .product-box{ padding: 8rem 0 5rem;} .product-box .center-block ul{ margin: 0 -1.25rem;} diff --git a/public/static/js/script.js b/public/static/js/script.js index 0b4786d..dcdf0fb 100644 --- a/public/static/js/script.js +++ b/public/static/js/script.js @@ -5,6 +5,10 @@ function wah() { } +layui.use(['layer', 'form', 'element'], function(){ + var layer = layui.layer,form = layui.form,element = layui.element; +}); + $(window).scroll(function(event) { // if ($(window).scrollTop() > 0) { // $('.head-box').addClass('active'); @@ -104,10 +108,63 @@ $(function() { scrollAnh = 0; scrollNum = 0; }); - - -}); -layui.use(['layer', 'form', 'element'], function(){ - var layer = layui.layer,form = layui.form,element = layui.element; -}); \ No newline at end of file + // 留言提交 + $('#message-submit').click(function () { + var companyName = $("#message-form input[name='company_name']").val(); + var name = $("#message-form input[name='name']").val(); + var phone = $("#message-form input[name='phone']").val(); + var email = $("#message-form input[name='email']").val(); + var content = $("#message-form textarea[name='content']").val(); + var url = $("#message-form").data('action'); + var token = $('#token').attr('content'); + if(companyName.length == 0 && name.length == 0) { + layer.msg('公司名称和联系人署名至少需要填写一个'); + return; + } + if(companyName.length > 0 && (companyName.length < 2 || companyName.length > 100)) { + layer.msg('司名称长度限制为2~100个字符'); + return; + } + if(name.length > 0 && (name.length < 2 || name.length > 100)) { + layer.msg('联系人署名长度限制为2~100个字符'); + return; + } + if(phone.length == 0 && email.length == 0) { + layer.msg('联系电话和邮箱至少需要填写一个'); + return; + } + if(content.length == 0 || (content.length < 6 || content.length > 500)) { + layer.msg('请输入4 ~ 500字符的咨询事项内容'); + return; + } + + $.ajax({ + dataType: "json", + type: "post", + async:true, + url: url, + data: { + 'company_name':companyName, + 'name':name, + 'phone':phone, + 'email':email, + 'content':content, + '_token':token, + }, + success: function(data) { + if(data.code == 0) { + layer.msg('提交成功, 感谢您的反馈!'); + $("#message-form input").val(''); + $("#message-form textarea").val(''); + } else { + layer.msg(data.msg); + } + }, + error: function (data) { + layer.msg('提交失败,请稍后再试'); + } + }); + }); + +}); diff --git a/route/app.php b/route/app.php index db02aaf..bcecbac 100644 --- a/route/app.php +++ b/route/app.php @@ -16,6 +16,9 @@ Route::get('page/:category_id', "page/index"); Route::rule('products', 'article/index')->name('products.search'); // 产品查询 Route::rule('news', 'article/index')->name('news.search'); // 新闻查询 +Route::post('message/add', 'message/add'); + + diff --git a/view/manager/message/index.html b/view/manager/message/index.html index 7d6244e..b004770 100644 --- a/view/manager/message/index.html +++ b/view/manager/message/index.html @@ -3,19 +3,21 @@
- + + - + - - + + + - + @@ -23,6 +25,7 @@ {foreach $list as $item} + diff --git a/view/manager/system/index.html b/view/manager/system/index.html index 5301c58..d7de499 100644 --- a/view/manager/system/index.html +++ b/view/manager/system/index.html @@ -82,18 +82,26 @@
-
- -
- -
-
+
+ +
+ +
+
+
+
+
+ +
+ +
+
SEO信息
diff --git a/view/page/contact.html b/view/page/contact.html index f7589ec..03d5371 100644 --- a/view/page/contact.html +++ b/view/page/contact.html @@ -1 +1,91 @@ -{layout name="layout"} \ No newline at end of file +{layout name="layout"} + + +
+
+
+ {$topCategory.title} +

{:nl2br($topCategory.description ?? '')}

+
+
+
+ + +
+
+
+
+
+
{$blocks['information']['title']['value'] ?? ''}

{$blocks['information']['subtitle']['value'] ?? ''}

+ {if isset($blocks['information']['logo']) && !empty($blocks['information']['logo']['value'])} + + {/if} +
+
+

电话/Tel:{$system['company_tel'] ?? ''}

+

传真/Fax:{$system['company_fax'] ?? ''}

+

邮箱/E-mail:{$system['company_email'] ?? ''}

+

+ {$system['company_addr'] ?? ''} +
{$system['company_addr_detail_en'] ?? ''} +
{$system['company_addr_en'] ?? ''} +

+

+ {$system['company_name'] ?? ''} +
{$system['company_name_en'] ?? ''} +
{$system['company_type_en'] ?? ''} +

+
+ {if isset($blocks['information']['wechat']) && !empty($blocks['information']['wechat'])} +
+

 

+
+ +

微信二维码/Wechant

+
+
+ {/if} +
+
+
+
+
+
+
{$blocks['jobs']['title']['value'] ?? ''}

{$blocks['jobs']['subtitle']['value'] ?? ''}

+
+
+
    + {if isset($jobList) && count($jobList) > 0} + {foreach $jobList as $job} +
  • +
    +
    {$job.summary ?? ''}{$job.title ?? ''}
    +
    展开
    +
    +
    +
    {$job.create_time|date="Y.m.d"}
    +
    {$job.content|raw}
    +
    +
  • + {/foreach} + {/if} +
+
+
+
+
+
+
+
{$blocks['message']['title']['value'] ?? ''}

{$blocks['message']['subtitle']['value'] ?? ''}

+
{:nl2br($blocks['message']['description']['value'] ?? '')}
+
+ + + + + +
+ +
+
+
\ No newline at end of file
姓名电话联系人署名公司名称联系电话 邮箱内容咨询事项 IP 时间 操作
{$item.name}{$item.company_name} {$item.phone} {$item.email} {$item.content}