咔叽游戏

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 187|回复: 0

[PHP编程] thinkPHP商城公告功能开发问题分析

[复制链接]
  • TA的每日心情
    无聊
    2019-5-27 08:20
  • 签到天数: 4 天

    [LV.2]圆转纯熟

    发表于 2020-1-26 21:32:35 | 显示全部楼层 |阅读模式
    本文实例分析了thinkPHP商城公告功能开发问题。分享给大家供大家参考,具体如下:
    效果如下
    thinkPHP商城公告功能开发问题分析-1.jpg

    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') ;
    复制代码
    巧妙的处理了这种逻辑关系。
    更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》、《smarty模板入门基础教程》及《PHP模板技术总结》。
    希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

    QQ|免责声明|小黑屋|手机版|Archiver|咔叽游戏

    GMT+8, 2024-3-29 02:57

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表