Authored by 周少峰

Merge branch 'feature/keywordAdd'

@@ -19,6 +19,7 @@ const singleBrandKeyPre = config.singleBrandKeyPre; @@ -19,6 +19,7 @@ const singleBrandKeyPre = config.singleBrandKeyPre;
19 const singleSortKeyPre = config.singleSortKeyPre; 19 const singleSortKeyPre = config.singleSortKeyPre;
20 const qs = require('querystring'); 20 const qs = require('querystring');
21 const lestGoodsNum = 3; 21 const lestGoodsNum = 3;
  22 +const seoModel = require('../models/seoModel');
22 23
23 const multiAsync=(multi)=>{ 24 const multiAsync=(multi)=>{
24 return multi.execAsync().then(function(res) { 25 return multi.execAsync().then(function(res) {
@@ -539,4 +540,43 @@ r.get('/sendUrl', async(ctx, next) => { @@ -539,4 +540,43 @@ r.get('/sendUrl', async(ctx, next) => {
539 } 540 }
540 ctx.response.body = result; 541 ctx.response.body = result;
541 }); 542 });
  543 +
  544 +r.get('/add', async (ctx) => {
  545 +
  546 + let model = new seoModel(ctx);
  547 + let resData = await model.addRootWordsData();
  548 +
  549 + await ctx.render('action/keywords/add', Object.assign(resData, {
  550 + title: '添加关键词'
  551 + }));
  552 +});
  553 +
  554 +r.post('/add', async (ctx) => {
  555 + let mysql = new Mysql();
  556 + let keyword = ctx.request.body.keywords || '';
  557 + let brand = ctx.request.body.brand || 0;
  558 + let msort = ctx.request.body.msort || 0;
  559 + let misort = ctx.request.body.misort || 0;
  560 + let sort = ctx.request.body.sort || 0;
  561 + let addTime = Date.parse(new Date())/1000;
  562 +
  563 + let result = {code: 400, message: ''};
  564 +
  565 + if (_.isEmpty(keyword)) {
  566 + selectSql.message = '关键词必填';
  567 + return ctx.response.body = result;
  568 + }
  569 +
  570 + let select = await mysql.query(`select id from seo_keywords where keyword='${keyword}' limit 1`);
  571 +
  572 + if (_.get(select, '[0].id', 0) > 0) {
  573 + result.message = '关键词已经存在';
  574 + return ctx.response.body = result;
  575 + }
  576 +
  577 + await mysql.query(`insert into seo_keywords (keyword, brand_id, msort, misort, sort_id, add_time) values ('${keyword}', ${brand}, ${msort}, ${misort}, ${sort}, ${addTime})`);
  578 +
  579 + result.code = 200;
  580 + return ctx.response.body = result;
  581 +})
542 module.exports = r; 582 module.exports = r;
  1 +<style>
  2 +.brand-list {
  3 + max-height: 400px;
  4 + overflow: auto;
  5 +}
  6 +.brand-list a{
  7 + display:inline-block;
  8 + color: #000;
  9 + padding: 5px 10px;
  10 + margin: 3px 0;
  11 +}
  12 +.brand-list a.active{
  13 + color: #fff;
  14 + background: #428bca;
  15 + padding: 5px 10px;
  16 +}
  17 +</style>
  18 +
  19 +<div class="pageheader">
  20 + <div class="media">
  21 + <div class="pageicon pull-left">
  22 + <i class="fa fa-th-list"></i>
  23 + </div>
  24 + <div class="media-body">
  25 + <ul class="breadcrumb">
  26 + <li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
  27 + <li><a href="/seo/tdk">{{title}}</a></li>
  28 + <li>{{typeName}}</li>
  29 + </ul>
  30 + <h4>{{title}}</h4>
  31 + </div>
  32 + </div>
  33 + <!-- media -->
  34 +</div>
  35 +<!-- pageheader -->
  36 +
  37 +<div class="contentpanel seo-root-page" style="padding-bottom:0;">
  38 + <div class="panel panel-default">
  39 + <div class="panel-body">
  40 + <div class="form-group">
  41 + <label for="exampleInputEmail1">关键词</label>
  42 + <input type="text" name="rootWord" class="form-control" value="" >
  43 + </div>
  44 + <div class="form-group">
  45 + <label >品牌</label>
  46 + <ul id="brandTab" class="nav nav-tabs brand-category">
  47 + {{#each brand}}
  48 + <li {{#if @first}}class="active"{{/if}}><a href="#{{@key}}" data-toggle="tab">{{@key}}</a></li>
  49 + {{/each}}
  50 + </ul>
  51 + <div id="brandTabContent" class="tab-content brand-list">
  52 + {{#each brand}}
  53 + <div class="tab-pane fade {{#if @first}}in active{{/if}}" id="{{@key}}">
  54 + {{# .}}<a data-id="{{id}}"> {{brandName}} </a>{{/ .}}
  55 + </div>
  56 + {{/each}}
  57 + </div>
  58 + </div>
  59 + <div class="form-group">
  60 + <label for="exampleInputEmail1">品类</label>
  61 + <div class="row">
  62 + <div class="col-md-3">
  63 + <select id="msort" class="form-control">
  64 + <option class="form-control" value="0">请选择</option>
  65 + {{#each sort}}
  66 + <option data="{{id}}" value="{{id}}" class="form-control">{{sortName}}</option>
  67 + {{/each}}
  68 + </select>
  69 + </div>
  70 + <div class="col-md-3">
  71 + <select id="misort" class="form-control">
  72 + <option class="form-control" value="0" selected>请选择</option>
  73 + </select>
  74 + </div>
  75 + <div class="col-md-3">
  76 + <select id="sort" class="form-control">
  77 + <option class="form-control" value="0" selected>请选择</option>
  78 + </select>
  79 + </div>
  80 + </div>
  81 +
  82 + </div>
  83 + <button type="submit" id="submit" class="btn btn-default">提交</button>
  84 +
  85 + </div>
  86 + </div>
  87 +
  88 +
  89 +</div>
  90 +
  91 +
  92 +<script>
  93 +$(function(){
  94 + var $brand = $('.brand-list a');
  95 + var $msort = $('#msort'), $misort = $('#misort'), $sort = $('#sort');
  96 + var $submit = $('#submit');
  97 + var $rootWord = $('input[name=rootWord]');
  98 + var $filterWord = $('input[name=filterWord]');
  99 + var $isKeyword = $('input[name=isKeyword]');
  100 + var rootWord = '', brand = 0, msort = 0, misort = 0, sort = 0, filterWord = '', formData;
  101 +
  102 + // 选择品牌
  103 + $brand.on('click', function(){
  104 + // $brand.removeClass('active');
  105 +
  106 + if(!$(this).hasClass('active')) {
  107 + $brand.removeClass('active');
  108 + $(this).addClass('active');
  109 + brand = $(this).data('id');
  110 + } else {
  111 + brand = 0;
  112 + $brand.removeClass('active');
  113 + }
  114 +
  115 + })
  116 +
  117 + // 切换大分类
  118 + $msort.on('change',function() {
  119 + selectInit('misort');
  120 + selectInit('sort');
  121 + getSubSorts($(this).val(), 'misort');
  122 + })
  123 +
  124 + // 切换中分类
  125 + $misort.on('change',function() {
  126 + selectInit('sort');
  127 + getSubSorts($(this).val(), 'sort');
  128 + })
  129 +
  130 + // 提交
  131 + $submit.on('click', function(){
  132 + rootWord = $rootWord.val();
  133 + filterWord = $filterWord.val();
  134 + msort = $msort.val();
  135 + misort = $misort.val();
  136 + sort = $sort.val();
  137 +
  138 + if (rootWord == '') {
  139 + alert('关键词必填');
  140 + return;
  141 + }
  142 +
  143 + formData = {
  144 + keywords: rootWord,
  145 + brand: brand,
  146 + msort: msort,
  147 + misort: misort,
  148 + sort: sort,
  149 + }
  150 +
  151 + $.ajax({
  152 + url: '/keywords/add',
  153 + dataType: 'json',
  154 + type: 'POST',
  155 + data: formData,
  156 + success: function(res) {
  157 + if (res.code == 200) {
  158 + location.href = '/keywords/expand';
  159 + } else {
  160 + alert(res.message);
  161 + }
  162 + },
  163 + error: function(err) {
  164 + console.log(err);
  165 + }
  166 +
  167 + });
  168 +
  169 + })
  170 +
  171 +
  172 +
  173 + // 获取子分类数据
  174 + function getSubSorts(sortId, id) {
  175 + $.ajax({
  176 + url: '/seo/rootwords/getsubsorts',
  177 + dataType: 'json',
  178 + type: 'POST',
  179 + data: {
  180 + sortId: sortId
  181 + },
  182 + success: function(data) {
  183 + var option = '';
  184 + $.each(data, function(key, val) {
  185 + option +='<option value="' + val.sort_id + '">' + val.sort_name + '</option>';
  186 + });
  187 + $('#'+id).append(option);
  188 + },
  189 + error: function(err) {
  190 + console.log(err);
  191 + }
  192 +
  193 + });
  194 + }
  195 +
  196 + // 清空子分类
  197 + function selectInit(id) {
  198 + $('#'+id).html('<option class="form-control" value="0">请选择</option>');
  199 + }
  200 +
  201 +})
  202 +</script>
@@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
19 <div class="panel-body"> 19 <div class="panel-body">
20 <label style="margin-right:20px;"><input id="allSelected" type="checkbox" style="margin-right:5px;">全选</label> 20 <label style="margin-right:20px;"><input id="allSelected" type="checkbox" style="margin-right:5px;">全选</label>
21 <a class="btn btn-default deleteAll">删除</a> 21 <a class="btn btn-default deleteAll">删除</a>
  22 + <a class="btn btn-default" href="/keywords/add">增加</a>
22 <a class="btn btn-default" href="javascript:sendUrl();">推送百度</a> 23 <a class="btn btn-default" href="javascript:sendUrl();">推送百度</a>
23 <a class="btn btn-default rand-words" href="javascript:void(0);">关键词随机关联</a> 24 <a class="btn btn-default rand-words" href="javascript:void(0);">关键词随机关联</a>
24 <div class="input-append pull-right"> 25 <div class="input-append pull-right">
This diff could not be displayed because it is too large.