当前位置:Gxlcms > PHP教程 > thinkPHP商城公告功能开发问题详解

thinkPHP商城公告功能开发问题详解

时间:2021-07-01 10:21:17 帮助过:2人阅读

这篇文章主要介绍了thinkPHP商城公告功能开发问题,结合实例形式分析了基于thinkPHP实现商城公告功能所涉及的ajax交互及数据库操作相关技巧,需要的朋友可以参考下

效果如下

1.定在头部

  1. position: fixed;
  2. z-index: 999;
  3. top: 0;
  4. opacity:1;

2.ajax处理json数据

  1. // 获取商城公告
  2. function getNotice() { // 获取公告函数
  3. var res;
  4. $.ajax({
  5. type: "POST",
  6. url: "{sh::U('Store/Mall/ajaxGetNotice',array('mid'=>$mid))}",
  7. dataType:'json', // 设为json之后,就能够很好的处理获取的json数据,json.status
  8. async: false,
  9. success: function(json){
  10. res = json;
  11. }
  12. });
  13. return res;
  14. }

设置dataType:'json'之后,json数据就直接可以通过json.的方式处理了。

3.最后加载,页面更好看。

  1. $(document).ready(function(e) { // 主函数
  2. // 获取公告
  3. var action_name = "{sh::ACTION_NAME}"; // 页面使用thinkphp常量
  4. var json = getNotice();
  5. if ( action_name == 'index' && json.status == 1) { // 首页并且公告存在
  6. $(".top").css("margin-top", "70px"); // jquery设置css
  7. $(".main-sidebar").css("top" ,"70px");
  8. var html = '';
  9. $.each(json.info, function(i, n){ // n为文本内容
  10. html += "<li><strong>"+n.content+"</strong></li>"
  11. });
  12. $(".top-notice").show();
  13. $('#notice ul').html(""+html);
  14. $('#notice').unslider(); // 轮播
  15. }
  16. });

4.获取sql语句的thinkphp处理

  1. // 获取公告
  2. function ajaxGetNotice() {
  3. if (IS_AJAX) {
  4. $this->mid;
  5. // 获取有效的,且结束时间大于当前时间的,或者日期等于0的公告
  6. $mallNoticeModel = M('Mall_notice');
  7. $where['mall_id'] = $this->mid;
  8. $where['status'] = 1;
  9. $where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;
  10. //SELECT * from sh_mall_notice where mall_id = 9 and status = 1 and (endtime = 0 or endtime>1458354366);
  11. $notice = $mallNoticeModel->where($where)->order('sort desc')->select();
  12. if (!empty($notice)) {
  13. $this->ajaxReturn(array('status'=>'1','info'=>$notice,'msg'=>"获取成功"),'JSON');
  14. } else {
  15. $this->ajaxReturn(array('status'=>'2','info'=>$notice,'msg'=>"公告不存在"),'JSON');
  16. }
  17. }
  18. }

  1. $where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;

巧妙的处理了这种逻辑关系。

以上就是本文的全部内容,希望对大家的学习有所帮助。


相关推荐:

php中登录超时检测功能实例详解

php base64 编码与解码实例详解

php实现连接mysql数据库的方法

以上就是thinkPHP商城公告功能开发问题详解的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行