关于ecshop基于评论做简单咨询功能

2016-09-11 20:38 来源:www.chinab4c.com 作者:ecshop专家

ecshop商品及文档都有评论的功能,而现在我们需要做一个咨询功能,这样比较正式的渠道来服务客户,参考现有的评论功能简单实现,后期继续扩展。

增加前台展示以及提交表单

1:goods.dwt增加以下代码,以引用咨询相关的模板

<!– #BeginLibraryItem “/library/comments1.lbi” –><!– #EndLibraryItem –>

2.复制/library/comments.lbi更名为comments1.lbi,内容稍微修改下

1 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2 {insert_scripts files='transport.js,utils.js'}
3 <div id="ECS_COMMENT1"> {* ECSHOP 提醒您:动态载入comments_list1.lbi,显示评论列表和评论表单 *}{insert name='comments1' type=2 id=$id}</div>

3./include/lib_insert.php增加函数

1 /*购买前咨询*/
2  
3 function insert_comments1($arr)
4 {
5     $need_cache = $GLOBALS['smarty']->caching;
6     $need_compile = $GLOBALS['smarty']->force_compile;
7  
8     $GLOBALS['smarty']->caching = false;
9     $GLOBALS['smarty']->force_compile = true;
10  
11     /* 验证码相关设置 */
12     if ((intval($GLOBALS['_CFG']['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
13     {
14         $GLOBALS['smarty']->assign('enabled_captcha', 1);
15         $GLOBALS['smarty']->assign('rand', mt_rand());
16     }
17     $GLOBALS['smarty']->assign('username',    stripslashes($_SESSION['user_name']));
18     $GLOBALS['smarty']->assign('email',        $_SESSION['email']);
19     $GLOBALS['smarty']->assign('comment_type', 2);
20     $GLOBALS['smarty']->assign('id',           $arr['id']);
21     $cmt = assign_comment($arr['id'],          $arr['type']);
22     $GLOBALS['smarty']->assign('comments',     $cmt['comments']);
23     $GLOBALS['smarty']->assign('pager',        $cmt['pager']);
24  
25     $val = $GLOBALS['smarty']->fetch('library/comments_list1.lbi');
26  
27     $GLOBALS['smarty']->caching = $need_cache;
28     $GLOBALS['smarty']->force_compile = $need_compile;
29  
30     return $val;
31 }

4.复制/library/comment_list.lbi更名为comment_list1.lbi,内容稍微修改

1 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2 <!--用户咨询 START-->
3      <div class="box">
4 <div class="box_1">
5 <h3><span class="text">用户咨询</span>({$lang.total}<font class="f1">{$pager.record_count}</font>用户咨询)</h3>
6  
7 <div class="boxCenterList clearfix" style="height:1%;">
8        <ul class="comments">
9        <!-- {if $comments} -->
10        <!-- {foreach from=$comments item=comment} -->
11         <li class="word">
12         <font class="f2"><!-- {if $comment.username} -->{$comment.username|escape:html}<!-- {else} -->{$lang.anonymous}<!-- {/if} --></font> <font class="f3">( {$comment.add_time} )</font><br />
13         <img src="../images/stars{$comment.rank}.gif" alt="{$comment.comment_rank}"/>
14         <p>{$comment.content}</p>
15     <!-- {if $comment.re_content} -->
16         <p><font class="f1">{$lang.admin_username}</font>{$comment.re_content}</p>
17     <!-- {/if} -->
18         </li>
19         <!-- {/foreach} -->
20         <!--{else}-->
21         <li>目前没有任何用户咨询</li>
22         <!--{/if}-->
23        </ul>
24        <!--翻页 start-->
25        <div id="pagebar" class="f_r">
26         <form name="sel ectPageForm" action="{$smarty.server.PHP_SELF}" method="get">
27         <!-- {if $pager.styleid eq 0 } -->
28         <div id="pager">
29           {$lang.pager_1}{$pager.record_count}{$lang.pager_2}{$lang.pager_3}{$pager.page_count}{$lang.pager_4} <span> <a href="{$pager.page_first}">{$lang.page_first}</a> <a href="{$pager.page_prev}">{$lang.page_prev}</a> <a href="{$pager.page_next}">{$lang.page_next}</a> <a href="{$pager.page_last}">{$lang.page_last}</a> </span>
30             <!--{foreach from=$pager.search key=key item=item}-->
31             <input type="hidden" name="{$key}" value="{$item}" />
32             <!--{/foreach}-->
33         </div>
34         <!--{else}-->
35         <!--翻页 start-->
36          <div id="pager" class="pagebar">
37           <span class="f_l f6" style="margin-right:10px;">{$lang.total} <b>{$pager.record_count}</b> {$lang.user_comment_num}</span>
38           <!-- {if $pager.page_first} --><a href="{$pager.page_first}">1 ...</a><!-- {/if} -->
39           <!-- {if $pager.page_prev} --><a class="prev" href="{$pager.page_prev}">{$lang.page_prev}</a><!-- {/if} -->
40           <!--{foreach from=$pager.page_number key=key item=item}-->
41                 <!-- {if $pager.page eq $key} -->
42                 <span class="page_now">{$key}</span>
43                 <!-- {else} -->
44                 <a href="{$item}">[{$key}]</a>
45                 <!-- {/if} -->
46             <!--{/foreach}-->
47           <!-- {if $pager.page_next} --><a class="next" href="{$pager.page_next}">{$lang.page_next}</a><!-- {/if} -->
48           <!-- {if $pager.page_last} --><a class="last" href="{$pager.page_last}">...{$pager.page_count}</a><!-- {/if} -->
49           <!-- {if $pager.page_kbd} -->
50             <!--{foreach from=$pager.search key=key item=item}-->
51             <input type="hidden" name="{$key}" value="{$item}" />
52             <!--{/foreach}-->
53             <kbd style="float:left; margin-left:8px; position:relative; bottom:3px;"><input type="text" name="page" size="3" class="B_blue" /></kbd>
54             <!-- {/if} -->
55         </div>
56         <!--翻页 END-->
57         <!-- {/if} -->
58         </form>
59         <script type="Text/Javascript" language="JavaScript">
60         <!--
61         {literal}
62         function sel ectPage(sel)
63         {
64           sel.form.submit();
65         }
66         {/literal}
67         //-->
68         </script>
69       </div>
70       <!--翻页 END-->
71       <div class="blank5"></div>
72       <!--咨询表单 start-->
73       <div class="commentsList">
74       <form action="javascript:;" onsubmit="submitComment1(this)" method="post"name="commentForm1" id="commentForm1">
75        <table width="700" border="0" cellspacing="5" cellpadding="0">
76  
77         <tr>
78           <td align="right">E-mail:</td>
79           <td>
80           <input type="text" name="email" id="email"  maxlength="100" value="{$smarty.session.email|escape}" class="inputBorder"/>
81           </td>
82         </tr>
83  
84         <tr>
85           <td align="right" valign="top">{$lang.comment_content}:</td>
86           <td>
87           <textarea name="content" class="inputBorder" style="height:50px; width:560px;"></textarea>
88           <input type="hidden" name="cmt_type" value="2" />
89           <input type="hidden" name="id" value="{$id}" />
90           </td>
91         </tr>
92         <tr>
93           <td colspan="2">
94           <!-- 判断是否启用验证码{if $enabled_captcha} -->
95           <div style="padding-left:15px; text-align:left; float:left;">
96           {$lang.comment_captcha}:<input type="text" name="captcha" class="inputBorder" style="width:50px; margin-left:5px;"/>
97           <img src="captcha.php?{$rand}" alt="captcha" class="captcha"onClick="this.src='captcha.php?'+Math.random()">
98           </div>
99           <!-- {/if} -->
100           <input name="" type="submit"  value=" " class="f_r" style="border:none; background:url(../images/commentsBnt.gif); width:75px; height:21px; margin-right:8px;">
101           </td>
102         </tr>
103       </table>
104       </form>
105       </div>
106       <!--咨询表单 end-->
107       </div>
108      </div>
109     </div>
110     <div class="blank5"></div>
111   <!--用户咨询 END-->
112 <script type="text/javascript">
113 //<![CDATA[
114 {foreach from=$lang.cmt_lang item=item key=key}
115 var {$key} = "{$item}";
116 {/foreach}
117 {literal}
118 /**
119 * 提交咨询信息
120 */
121 function submitComment1(frm)
122 {
123   var cmt = new Object;
124  
125   cmt.email           = frm.elements['email'].value;
126   cmt.content         = frm.elements['content'].value;
127   cmt.type            = frm.elements['cmt_type'].value;
128   cmt.id              = frm.elements['id'].value;
129   cmt.enabled_captcha = frm.elements['enabled_captcha'] ? frm.elements['enabled_captcha'].value : '0';
130   cmt.captcha         = frm.elements['captcha'] ? frm.elements['captcha'].value : '';
131   cmt.rank            = 5;
132  
133   if (cmt.email.length > 0)
134   {
135      if (!(Utils.isEmail(cmt.email)))
136      {
137         alert(cmt_error_email);
138         return false;
139       }
140    }
141    else
142    {
143         alert(cmt_empty_email);
144         return false;
145    }
146    if (cmt.content.length == 0)
147    {
148       alert(cmt_empty_content);
149       return false;
150    }
151    if (cmt.enabled_captcha > 0 && cmt.captcha.length == 0 )
152    {
153       alert(captcha_not_null);
154       return false;
155    }
156    Ajax.call('comment1.php', 'cmt=' + cmt.toJSONString(), commentRespone1, 'POST', 'JSON');
157    return false;
158 }
159 /**
160 * 处理提交咨询的反馈信息
161 */
162   function commentRespone1(result)
163   {
164     if (result.message)
165     {
166       alert(result.message);
167     }
168     if (result.error == 0)
169     {
170       var layer = document.getElementById('ECS_COMMENT1');
171       if (layer)
172       {
173         layer.innerHTML = result.content;
174       }
175     }
176   }
177 {/literal}
178 //]]>
179 </script>

5.复制/comment.php重命名为comment1.php,内容稍作修改

1 <?php
2  
3 /**
4  * ECSHOP 提交用户评论
5  * ============================================================================
6  * 版权所有 2005-2010 上海商派网络科技有限公司,并保留所有权利。
7  * 网站地址: http://www.ecshop.com;
8  * ----------------------------------------------------------------------------
9  * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
10  * 使用;不允许对程序代码以任何形式任何目的的再发布。
11  * ============================================================================
12  * $Author: liuhui $
13  * $Id: comment.php 17063 2010-03-25 06:35:46Z liuhui $
14 */
15  
16 define('IN_ECS', true);
17  
18 require(dirname(__FILE__) . '/includes/init.php');
19 require(ROOT_PATH . 'includes/cls_json.php');
20  
21 if (!isset($_REQUEST['cmt']) && !isset($_REQUEST['act']))
22 {
23     /* 只有在没有提交评论内容以及没有act的情况下才跳转 */
24     ecs_header("Location: ./\\n");
25     exit;
26 }
27 $_REQUEST['cmt'] = isset($_REQUEST['cmt']) ? json_str_iconv($_REQUEST['cmt']) : '';
28  
29 $json   = new JSON;
30 $result = array('error' => 0, 'message' => '', 'content' => '');
31  
32 if (empty($_REQUEST['act']))
33 {
34     /*
35      * act 参数为空
36      * 默认为添加评论内容
37      */
38     $cmt  = $json->decode($_REQUEST['cmt']);
39     $cmt->page = 1;
40     $cmt->id   = !empty($cmt->id)   ? intval($cmt->id) : 0;
41     $cmt->type = !empty($cmt->type) ? intval($cmt->type) : 0;
42  
43     if (empty($cmt) || !isset($cmt->type) || !isset($cmt->id))
44     {
45         $result['error']   = 1;
46         $result['message'] = $_LANG['invalid_comments'];
47     }
48     elseif (!is_email($cmt->email))
49     {
50         $result['error']   = 1;
51         $result['message'] = $_LANG['error_email'];
52     }
53     else
54     {
55         if ((intval($_CFG['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
56         {
57             /* 检查验证码 */
58             include_once('includes/cls_captcha.php');
59  
60             $validator = new captcha();
61             if (!$validator->check_word($cmt->captcha))
62             {
63                 $result['error']   = 1;
64                 $result['message'] = $_LANG['invalid_captcha'];
65             }
66             else
67             {
68                 $factor = intval($_CFG['comment_factor']);
69                 if ($cmt->type == 0 && $factor > 0)
70                 {
71                     /* 只有商品才检查评论条件 */
72                     switch ($factor)
73                     {
74                         case COMMENT_LOGIN :
75                             if ($_SESSION['user_id'] == 0)
76                             {
77                                 $result['error']   = 1;
78                                 $result['message'] = $_LANG['comment_login'];
79                             }
80                             break;
81  
82                         case COMMENT_CUSTOM :
83                             if ($_SESSION['user_id'] > 0)
84                             {
85                                 $sql = "SELECT o.order_id FROM " . $ecs->table('order_info') . " AS o ".
86                                        " WHERE user_id = '" . $_SESSION['user_id'] . "'".
87                                        " AND o.order_status = '" . OS_CONFIRMED . "' ".
88                                        " AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') ".
89                                        " AND (o.shipping_status = '" . SS_SHIPPED ."' OR o.shipping_status = '" . SS_RECEIVED . "') ".
90                                        " LIMIT 1";
91  
92                                  $tmp = $db->getOne($sql);
93                                  if (empty($tmp))
94                                  {
95                                     $result['error']   = 1;
96                                     $result['message'] = $_LANG['comment_custom'];
97                                  }
98                             }
99                             else
100                             {
101                                 $result['error'] = 1;
102                    

 



最近更新

常用插件